Removed superfluous WIN_ReleaseWndPtr.
[wine/multimedia.git] / controls / button.c
blob5f037300a2152cd29efa2c3b501a5c738cd775a0
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_locked
78 * Called with window lock held.
80 static inline LRESULT WINAPI ButtonWndProc_locked(WND* wndPtr, UINT uMsg,
81 WPARAM wParam, LPARAM lParam )
83 RECT rect;
84 HWND hWnd = wndPtr->hwndSelf;
85 POINT pt;
86 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
87 LONG style = wndPtr->dwStyle & 0x0f;
88 HANDLE oldHbitmap;
90 pt.x = LOWORD(lParam);
91 pt.y = HIWORD(lParam);
93 switch (uMsg)
95 case WM_GETDLGCODE:
96 switch(style)
98 case BS_PUSHBUTTON: return DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON;
99 case BS_DEFPUSHBUTTON: return DLGC_BUTTON | DLGC_DEFPUSHBUTTON;
100 case BS_RADIOBUTTON:
101 case BS_AUTORADIOBUTTON: return DLGC_BUTTON | DLGC_RADIOBUTTON;
102 default: return DLGC_BUTTON;
105 case WM_ENABLE:
106 PAINT_BUTTON( wndPtr, style, ODA_DRAWENTIRE );
107 break;
109 case WM_CREATE:
110 if (!hbitmapCheckBoxes)
112 BITMAP bmp;
113 hbitmapCheckBoxes = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_CHECKBOXES));
114 GetObjectA( hbitmapCheckBoxes, sizeof(bmp), &bmp );
115 checkBoxWidth = bmp.bmWidth / 4;
116 checkBoxHeight = bmp.bmHeight / 3;
118 if (style < 0L || style >= MAX_BTN_TYPE)
119 return -1; /* abort */
120 infoPtr->state = BUTTON_UNCHECKED;
121 infoPtr->hFont = 0;
122 infoPtr->hImage = NULL;
123 return 0;
125 case WM_ERASEBKGND:
126 return 1;
128 case WM_PAINT:
129 if (btnPaintFunc[style])
131 PAINTSTRUCT ps;
132 HDC hdc = wParam ? (HDC)wParam : BeginPaint( hWnd, &ps );
133 SetBkMode( hdc, OPAQUE );
134 (btnPaintFunc[style])( wndPtr, hdc, ODA_DRAWENTIRE );
135 if( !wParam ) EndPaint( hWnd, &ps );
137 break;
139 case WM_LBUTTONDOWN:
140 case WM_LBUTTONDBLCLK:
141 SendMessageA( hWnd, BM_SETSTATE, TRUE, 0 );
142 SetFocus( hWnd );
143 SetCapture( hWnd );
144 break;
146 case WM_LBUTTONUP:
147 ReleaseCapture();
148 if (!(infoPtr->state & BUTTON_HIGHLIGHTED)) break;
149 SendMessageA( hWnd, BM_SETSTATE, FALSE, 0 );
150 GetClientRect( hWnd, &rect );
151 if (PtInRect( &rect, pt ))
153 switch(style)
155 case BS_AUTOCHECKBOX:
156 SendMessageA( hWnd, BM_SETCHECK,
157 !(infoPtr->state & BUTTON_CHECKED), 0 );
158 break;
159 case BS_AUTORADIOBUTTON:
160 SendMessageA( hWnd, BM_SETCHECK, TRUE, 0 );
161 break;
162 case BS_AUTO3STATE:
163 SendMessageA( hWnd, BM_SETCHECK,
164 (infoPtr->state & BUTTON_3STATE) ? 0 :
165 ((infoPtr->state & 3) + 1), 0 );
166 break;
168 SendMessageA( GetParent(hWnd), WM_COMMAND,
169 MAKEWPARAM( wndPtr->wIDmenu, BN_CLICKED ), hWnd);
171 break;
173 case WM_MOUSEMOVE:
174 if (GetCapture() == hWnd)
176 GetClientRect( hWnd, &rect );
177 SendMessageA( hWnd, BM_SETSTATE, PtInRect(&rect, pt), 0 );
179 break;
181 case WM_NCHITTEST:
182 if(style == BS_GROUPBOX) return HTTRANSPARENT;
183 return DefWindowProcA( hWnd, uMsg, wParam, lParam );
185 case WM_SETTEXT:
186 DEFWND_SetText( wndPtr, (LPCSTR)lParam );
187 if( wndPtr->dwStyle & WS_VISIBLE )
188 PAINT_BUTTON( wndPtr, style, ODA_DRAWENTIRE );
189 return 0;
191 case WM_SETFONT:
192 infoPtr->hFont = (HFONT16)wParam;
193 if (lParam && (wndPtr->dwStyle & WS_VISIBLE))
194 PAINT_BUTTON( wndPtr, style, ODA_DRAWENTIRE );
195 break;
197 case WM_GETFONT:
198 return infoPtr->hFont;
200 case WM_SETFOCUS:
201 infoPtr->state |= BUTTON_HASFOCUS;
202 if (style == BS_AUTORADIOBUTTON)
203 SendMessageA( hWnd, BM_SETCHECK, 1, 0 );
204 PAINT_BUTTON( wndPtr, style, ODA_FOCUS );
205 break;
207 case WM_KILLFOCUS:
208 infoPtr->state &= ~BUTTON_HASFOCUS;
209 PAINT_BUTTON( wndPtr, style, ODA_FOCUS );
210 InvalidateRect( hWnd, NULL, TRUE );
211 break;
213 case WM_SYSCOLORCHANGE:
214 InvalidateRect( hWnd, NULL, FALSE );
215 break;
217 case BM_SETSTYLE16:
218 case BM_SETSTYLE:
219 if ((wParam & 0x0f) >= MAX_BTN_TYPE) break;
220 wndPtr->dwStyle = (wndPtr->dwStyle & 0xfffffff0)
221 | (wParam & 0x0000000f);
222 style = wndPtr->dwStyle & 0x0000000f;
223 PAINT_BUTTON( wndPtr, style, ODA_DRAWENTIRE );
224 break;
226 case BM_SETIMAGE:
227 oldHbitmap = infoPtr->hImage;
228 if(wndPtr->dwStyle & BS_BITMAP)
229 infoPtr->hImage = (HANDLE) lParam;
230 return oldHbitmap;
232 case BM_GETIMAGE:
233 return infoPtr->hImage;
235 case BM_GETCHECK16:
236 case BM_GETCHECK:
237 return infoPtr->state & 3;
239 case BM_SETCHECK16:
240 case BM_SETCHECK:
241 if (wParam > maxCheckState[style]) wParam = maxCheckState[style];
242 if ((infoPtr->state & 3) != wParam)
244 if ((style == BS_RADIOBUTTON) || (style == BS_AUTORADIOBUTTON))
246 if (wParam)
247 wndPtr->dwStyle |= WS_TABSTOP;
248 else
249 wndPtr->dwStyle &= ~WS_TABSTOP;
251 infoPtr->state = (infoPtr->state & ~3) | wParam;
252 PAINT_BUTTON( wndPtr, style, ODA_SELECT );
254 if ((style == BS_AUTORADIOBUTTON) && (wParam == BUTTON_CHECKED))
255 BUTTON_CheckAutoRadioButton( wndPtr );
256 break;
258 case BM_GETSTATE16:
259 case BM_GETSTATE:
260 return infoPtr->state;
262 case BM_SETSTATE16:
263 case BM_SETSTATE:
264 if (wParam)
266 if (infoPtr->state & BUTTON_HIGHLIGHTED) break;
267 infoPtr->state |= BUTTON_HIGHLIGHTED;
269 else
271 if (!(infoPtr->state & BUTTON_HIGHLIGHTED)) break;
272 infoPtr->state &= ~BUTTON_HIGHLIGHTED;
274 PAINT_BUTTON( wndPtr, style, ODA_SELECT );
275 break;
277 default:
278 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
280 return 0;
283 /***********************************************************************
284 * ButtonWndProc
285 * The button window procedure. This is just a wrapper which locks
286 * the passed HWND and calls the real window procedure (with a WND*
287 * pointer pointing to the locked windowstructure).
289 LRESULT WINAPI ButtonWndProc( HWND hWnd, UINT uMsg,
290 WPARAM wParam, LPARAM lParam )
292 LRESULT res;
293 WND *wndPtr = WIN_FindWndPtr(hWnd);
295 res = ButtonWndProc_locked(wndPtr,uMsg,wParam,lParam);
297 WIN_ReleaseWndPtr(wndPtr);
298 return res;
301 /**********************************************************************
302 * Push Button Functions
305 static void PB_Paint( WND *wndPtr, HDC hDC, WORD action )
307 RECT rc;
308 HPEN hOldPen;
309 HBRUSH hOldBrush;
310 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
311 int xBorderOffset, yBorderOffset;
312 xBorderOffset = yBorderOffset = 0;
314 GetClientRect( wndPtr->hwndSelf, &rc );
316 /* Send WM_CTLCOLOR to allow changing the font (the colors are fixed) */
317 if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
318 BUTTON_SEND_CTLCOLOR( wndPtr, hDC );
319 hOldPen = (HPEN)SelectObject(hDC, GetSysColorPen(COLOR_WINDOWFRAME));
320 hOldBrush =(HBRUSH)SelectObject(hDC,GetSysColorBrush(COLOR_BTNFACE));
321 SetBkMode(hDC, TRANSPARENT);
322 Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom);
323 if (TWEAK_WineLook == WIN31_LOOK)
325 SetPixel( hDC, rc.left, rc.top, GetSysColor(COLOR_WINDOW) );
326 SetPixel( hDC, rc.left, rc.bottom-1, GetSysColor(COLOR_WINDOW) );
327 SetPixel( hDC, rc.right-1, rc.top, GetSysColor(COLOR_WINDOW) );
328 SetPixel( hDC, rc.right-1, rc.bottom-1, GetSysColor(COLOR_WINDOW));
330 InflateRect( &rc, -1, -1 );
332 if ((wndPtr->dwStyle & 0x000f) == BS_DEFPUSHBUTTON)
334 Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom);
335 InflateRect( &rc, -1, -1 );
338 if (infoPtr->state & BUTTON_HIGHLIGHTED)
340 /* draw button shadow: */
341 SelectObject(hDC, GetSysColorBrush(COLOR_BTNSHADOW));
342 PatBlt(hDC, rc.left, rc.top, 1, rc.bottom-rc.top, PATCOPY );
343 PatBlt(hDC, rc.left, rc.top, rc.right-rc.left, 1, PATCOPY );
344 rc.left += 2; /* To position the text down and right */
345 rc.top += 2;
346 } else {
347 rc.right++, rc.bottom++;
348 DrawEdge( hDC, &rc, EDGE_RAISED, BF_RECT );
350 /* To place de bitmap correctly */
351 xBorderOffset += GetSystemMetrics(SM_CXEDGE);
352 yBorderOffset += GetSystemMetrics(SM_CYEDGE);
354 rc.right--, rc.bottom--;
357 /* draw button label, if any: */
358 if (wndPtr->text && wndPtr->text[0])
360 LOGBRUSH lb;
361 GetObjectA( GetSysColorBrush(COLOR_BTNFACE), sizeof(lb), &lb );
362 if (wndPtr->dwStyle & WS_DISABLED &&
363 GetSysColor(COLOR_GRAYTEXT)==lb.lbColor)
364 /* don't write gray text on gray background */
365 PaintGrayOnGray( hDC,infoPtr->hFont,&rc,wndPtr->text,
366 DT_CENTER | DT_VCENTER );
367 else
369 SetTextColor( hDC, (wndPtr->dwStyle & WS_DISABLED) ?
370 GetSysColor(COLOR_GRAYTEXT) :
371 GetSysColor(COLOR_BTNTEXT) );
372 DrawTextA( hDC, wndPtr->text, -1, &rc,
373 DT_SINGLELINE | DT_CENTER | DT_VCENTER );
374 /* do we have the focus? */
375 if (infoPtr->state & BUTTON_HASFOCUS)
377 RECT r = { 0, 0, 0, 0 };
378 INT xdelta, ydelta;
380 DrawTextA( hDC, wndPtr->text, -1, &r,
381 DT_SINGLELINE | DT_CALCRECT );
382 xdelta = ((rc.right - rc.left) - (r.right - r.left) - 1) / 2;
383 ydelta = ((rc.bottom - rc.top) - (r.bottom - r.top) - 1) / 2;
384 if (xdelta < 0) xdelta = 0;
385 if (ydelta < 0) ydelta = 0;
386 InflateRect( &rc, -xdelta, -ydelta );
387 DrawFocusRect( hDC, &rc );
392 if((wndPtr->dwStyle & BS_BITMAP) && (infoPtr->hImage != NULL))
394 BITMAP bm;
395 HDC hdcMem;
396 int yOffset, xOffset, imageWidth, imageHeight;
398 GetObjectA (infoPtr->hImage, sizeof(BITMAP), &bm);
400 /* Center the bitmap */
401 xOffset = (((rc.right - rc.left) - 2*xBorderOffset) - bm.bmWidth ) / 2;
402 yOffset = (((rc.bottom - rc.top) - 2*yBorderOffset) - bm.bmHeight ) / 2;
404 imageWidth = bm.bmWidth;
405 imageHeight = bm.bmHeight;
407 /* If the image is to big for the button */
408 if (xOffset < 0)
410 imageWidth = rc.right - rc.left - 2*xBorderOffset -1;
411 xOffset = xBorderOffset;
414 if (yOffset < 0)
416 imageHeight = rc.bottom - rc.top - 2*yBorderOffset -1;
417 yOffset = yBorderOffset;
420 /* Let minimum 1 space from border */
421 xOffset++, yOffset++;
423 hdcMem = CreateCompatibleDC (hDC);
424 SelectObject (hdcMem, (HBITMAP)infoPtr->hImage);
425 BitBlt(hDC, rc.left + xOffset,
426 rc.top + yOffset,
427 imageWidth, imageHeight,
428 hdcMem, 0, 0, SRCCOPY);
430 DeleteDC (hdcMem);
433 SelectObject( hDC, hOldPen );
434 SelectObject( hDC, hOldBrush );
438 /**********************************************************************
439 * PB_Paint & CB_Paint sub function [internal]
440 * Paint text using a raster brush to avoid gray text on gray
441 * background. 'format' can be a combination of DT_CENTER and
442 * DT_VCENTER to use this function in both PB_PAINT and
443 * CB_PAINT. - Dirk Thierbach
445 * FIXME: This and TEXT_GrayString should be eventually combined,
446 * so calling one common function from PB_Paint, CB_Paint and
447 * TEXT_GrayString will be enough. Also note that this
448 * function ignores the CACHE_GetPattern funcs.
451 void PaintGrayOnGray(HDC hDC,HFONT hFont,RECT *rc,char *text,
452 UINT format)
454 /* This is the standard gray on gray pattern:
455 static const WORD Pattern[] = {0xAA,0x55,0xAA,0x55,0xAA,0x55,0xAA,0x55};
457 /* This pattern gives better readability with X Fonts.
458 FIXME: Maybe the user should be allowed to decide which he wants. */
459 static const WORD Pattern[] = {0x55,0xFF,0xAA,0xFF,0x55,0xFF,0xAA,0xFF};
461 HBITMAP hbm = CreateBitmap( 8, 8, 1, 1, Pattern );
462 HDC hdcMem = CreateCompatibleDC(hDC);
463 HBITMAP hbmMem;
464 HBRUSH hBr;
465 RECT rect,rc2;
467 rect=*rc;
468 DrawTextA( hDC, text, -1, &rect, DT_SINGLELINE | DT_CALCRECT);
469 /* now text width and height are in rect.right and rect.bottom */
470 rc2=rect;
471 rect.left = rect.top = 0; /* drawing pos in hdcMem */
472 if (format & DT_CENTER) rect.left=(rc->right-rect.right)/2;
473 if (format & DT_VCENTER) rect.top=(rc->bottom-rect.bottom)/2;
474 hbmMem = CreateCompatibleBitmap( hDC,rect.right,rect.bottom );
475 SelectObject( hdcMem, hbmMem);
476 PatBlt( hdcMem,0,0,rect.right,rect.bottom,WHITENESS);
477 /* will be overwritten by DrawText, but just in case */
478 if (hFont) SelectObject( hdcMem, hFont);
479 DrawTextA( hdcMem, text, -1, &rc2, DT_SINGLELINE);
480 /* After draw: foreground = 0 bits, background = 1 bits */
481 hBr = SelectObject( hdcMem, CreatePatternBrush(hbm) );
482 DeleteObject( hbm );
483 PatBlt( hdcMem,0,0,rect.right,rect.bottom,0xAF0229);
484 /* only keep the foreground bits where pattern is 1 */
485 DeleteObject( SelectObject( hdcMem,hBr) );
486 BitBlt(hDC,rect.left,rect.top,rect.right,rect.bottom,hdcMem,0,0,SRCAND);
487 /* keep the background of the dest */
488 DeleteDC( hdcMem);
489 DeleteObject( hbmMem );
493 /**********************************************************************
494 * Check Box & Radio Button Functions
497 static void CB_Paint( WND *wndPtr, HDC hDC, WORD action )
499 RECT rbox, rtext, client;
500 HBRUSH hBrush;
501 int textlen, delta;
502 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
504 textlen = 0;
505 GetClientRect(wndPtr->hwndSelf, &client);
506 rbox = rtext = client;
508 if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
510 /* Something is still not right, checkboxes (and edit controls)
511 * in wsping32 have white backgrounds instead of dark grey.
512 * BUTTON_SEND_CTLCOLOR() is even worse since it returns 0 in this
513 * particular case and the background is not painted at all.
516 hBrush = GetControlBrush16( wndPtr->hwndSelf, hDC, CTLCOLOR_BTN );
518 if (wndPtr->dwStyle & BS_LEFTTEXT)
520 /* magic +4 is what CTL3D expects */
522 rtext.right -= checkBoxWidth + 4;
523 rbox.left = rbox.right - checkBoxWidth;
525 else
527 rtext.left += checkBoxWidth + 4;
528 rbox.right = checkBoxWidth;
531 /* Draw the check-box bitmap */
533 if (wndPtr->text) textlen = strlen( wndPtr->text );
534 if (action == ODA_DRAWENTIRE || action == ODA_SELECT)
536 HDC hMemDC = CreateCompatibleDC( hDC );
537 int x = 0, y = 0;
538 delta = (rbox.bottom - rbox.top - checkBoxHeight) >> 1;
540 if (action == ODA_SELECT) FillRect( hDC, &rbox, hBrush );
541 else FillRect( hDC, &client, hBrush );
543 if (infoPtr->state & BUTTON_HIGHLIGHTED) x += 2 * checkBoxWidth;
544 if (infoPtr->state & (BUTTON_CHECKED | BUTTON_3STATE)) x += checkBoxWidth;
545 if (((wndPtr->dwStyle & 0x0f) == BS_RADIOBUTTON) ||
546 ((wndPtr->dwStyle & 0x0f) == BS_AUTORADIOBUTTON)) y += checkBoxHeight;
547 else if (infoPtr->state & BUTTON_3STATE) y += 2 * checkBoxHeight;
549 SelectObject( hMemDC, hbitmapCheckBoxes );
550 BitBlt( hDC, rbox.left, rbox.top + delta, checkBoxWidth,
551 checkBoxHeight, hMemDC, x, y, SRCCOPY );
552 DeleteDC( hMemDC );
554 if( textlen && action != ODA_SELECT )
556 if (wndPtr->dwStyle & WS_DISABLED &&
557 GetSysColor(COLOR_GRAYTEXT)==GetBkColor(hDC)) {
558 /* don't write gray text on gray background */
559 PaintGrayOnGray( hDC, infoPtr->hFont, &rtext, wndPtr->text,
560 DT_VCENTER);
561 } else {
562 if (wndPtr->dwStyle & WS_DISABLED)
563 SetTextColor( hDC, GetSysColor(COLOR_GRAYTEXT) );
564 DrawTextA( hDC, wndPtr->text, textlen, &rtext,
565 DT_SINGLELINE | DT_VCENTER );
566 textlen = 0; /* skip DrawText() below */
571 if ((action == ODA_FOCUS) ||
572 ((action == ODA_DRAWENTIRE) && (infoPtr->state & BUTTON_HASFOCUS)))
574 /* again, this is what CTL3D expects */
576 SetRectEmpty(&rbox);
577 if( textlen )
578 DrawTextA( hDC, wndPtr->text, textlen, &rbox,
579 DT_SINGLELINE | DT_CALCRECT );
580 textlen = rbox.bottom - rbox.top;
581 delta = ((rtext.bottom - rtext.top) - textlen)/2;
582 rbox.bottom = (rbox.top = rtext.top + delta - 1) + textlen + 2;
583 textlen = rbox.right - rbox.left;
584 rbox.right = (rbox.left += --rtext.left) + textlen + 2;
585 IntersectRect(&rbox, &rbox, &rtext);
586 DrawFocusRect( hDC, &rbox );
591 /**********************************************************************
592 * BUTTON_CheckAutoRadioButton
594 * wndPtr is checked, uncheck every other auto radio button in group
596 static void BUTTON_CheckAutoRadioButton( WND *wndPtr )
598 HWND parent, sibling, start;
599 if (!(wndPtr->dwStyle & WS_CHILD)) return;
600 parent = wndPtr->parent->hwndSelf;
601 /* assure that starting control is not disabled or invisible */
602 start = sibling = GetNextDlgGroupItem( parent, wndPtr->hwndSelf, TRUE );
605 WND *tmpWnd;
606 if (!sibling) break;
607 tmpWnd = WIN_FindWndPtr(sibling);
608 if ((wndPtr->hwndSelf != sibling) &&
609 ((tmpWnd->dwStyle & 0x0f) == BS_AUTORADIOBUTTON))
610 SendMessageA( sibling, BM_SETCHECK, BUTTON_UNCHECKED, 0 );
611 sibling = GetNextDlgGroupItem( parent, sibling, FALSE );
612 WIN_ReleaseWndPtr(tmpWnd);
613 } while (sibling != start);
617 /**********************************************************************
618 * Group Box Functions
621 static void GB_Paint( WND *wndPtr, HDC hDC, WORD action )
623 RECT rc, rcFrame;
624 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
626 if (action != ODA_DRAWENTIRE) return;
628 BUTTON_SEND_CTLCOLOR( wndPtr, hDC );
630 GetClientRect( wndPtr->hwndSelf, &rc);
631 if (TWEAK_WineLook == WIN31_LOOK) {
632 HPEN hPrevPen = SelectObject( hDC,
633 GetSysColorPen(COLOR_WINDOWFRAME));
634 HBRUSH hPrevBrush = SelectObject( hDC,
635 GetStockObject(NULL_BRUSH) );
637 Rectangle( hDC, rc.left, rc.top + 2, rc.right - 1, rc.bottom - 1 );
638 SelectObject( hDC, hPrevBrush );
639 SelectObject( hDC, hPrevPen );
640 } else {
641 TEXTMETRICA tm;
642 rcFrame = rc;
644 if (infoPtr->hFont)
645 SelectObject (hDC, infoPtr->hFont);
646 GetTextMetricsA (hDC, &tm);
647 rcFrame.top += (tm.tmHeight / 2) - 1;
648 DrawEdge (hDC, &rcFrame, EDGE_ETCHED, BF_RECT);
651 if (wndPtr->text)
653 if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
654 if (wndPtr->dwStyle & WS_DISABLED)
655 SetTextColor( hDC, GetSysColor(COLOR_GRAYTEXT) );
656 rc.left += 10;
657 DrawTextA( hDC, wndPtr->text, -1, &rc, DT_SINGLELINE | DT_NOCLIP );
662 /**********************************************************************
663 * User Button Functions
666 static void UB_Paint( WND *wndPtr, HDC hDC, WORD action )
668 RECT rc;
669 HBRUSH hBrush;
670 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
672 if (action == ODA_SELECT) return;
674 GetClientRect( wndPtr->hwndSelf, &rc);
676 if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
677 hBrush = GetControlBrush16( wndPtr->hwndSelf, hDC, CTLCOLOR_BTN );
679 FillRect( hDC, &rc, hBrush );
680 if ((action == ODA_FOCUS) ||
681 ((action == ODA_DRAWENTIRE) && (infoPtr->state & BUTTON_HASFOCUS)))
682 DrawFocusRect( hDC, &rc );
686 /**********************************************************************
687 * Ownerdrawn Button Functions
690 static void OB_Paint( WND *wndPtr, HDC hDC, WORD action )
692 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
693 DRAWITEMSTRUCT dis;
695 dis.CtlType = ODT_BUTTON;
696 dis.CtlID = wndPtr->wIDmenu;
697 dis.itemID = 0;
698 dis.itemAction = action;
699 dis.itemState = ((infoPtr->state & BUTTON_HASFOCUS) ? ODS_FOCUS : 0) |
700 ((infoPtr->state & BUTTON_HIGHLIGHTED) ? ODS_SELECTED : 0) |
701 ((wndPtr->dwStyle & WS_DISABLED) ? ODS_DISABLED : 0);
702 dis.hwndItem = wndPtr->hwndSelf;
703 dis.hDC = hDC;
704 dis.itemData = 0;
705 GetClientRect( wndPtr->hwndSelf, &dis.rcItem );
706 SendMessageA( GetParent(wndPtr->hwndSelf), WM_DRAWITEM,
707 wndPtr->wIDmenu, (LPARAM)&dis );