GetLongPathName rewrite.
[wine.git] / controls / button.c
blobd51d190295c9c32e8fb4697e6fd5a54db0aba0a1
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 "windef.h"
12 #include "wingdi.h"
13 #include "wine/winuser16.h"
14 #include "tweak.h"
16 static void PaintGrayOnGray( HDC hDC,HFONT hFont,RECT *rc,
17 char *text, UINT format );
19 static void PB_Paint( WND *wndPtr, HDC hDC, WORD action );
20 static void CB_Paint( WND *wndPtr, HDC hDC, WORD action );
21 static void GB_Paint( WND *wndPtr, HDC hDC, WORD action );
22 static void UB_Paint( WND *wndPtr, HDC hDC, WORD action );
23 static void OB_Paint( WND *wndPtr, HDC hDC, WORD action );
24 static void BUTTON_CheckAutoRadioButton( WND *wndPtr );
25 static void BUTTON_DrawPushButton( WND *wndPtr, HDC hDC, WORD action, BOOL pushedState);
27 #define MAX_BTN_TYPE 12
29 static const WORD maxCheckState[MAX_BTN_TYPE] =
31 BUTTON_UNCHECKED, /* BS_PUSHBUTTON */
32 BUTTON_UNCHECKED, /* BS_DEFPUSHBUTTON */
33 BUTTON_CHECKED, /* BS_CHECKBOX */
34 BUTTON_CHECKED, /* BS_AUTOCHECKBOX */
35 BUTTON_CHECKED, /* BS_RADIOBUTTON */
36 BUTTON_3STATE, /* BS_3STATE */
37 BUTTON_3STATE, /* BS_AUTO3STATE */
38 BUTTON_UNCHECKED, /* BS_GROUPBOX */
39 BUTTON_UNCHECKED, /* BS_USERBUTTON */
40 BUTTON_CHECKED, /* BS_AUTORADIOBUTTON */
41 BUTTON_UNCHECKED, /* Not defined */
42 BUTTON_UNCHECKED /* BS_OWNERDRAW */
45 typedef void (*pfPaint)( WND *wndPtr, HDC hdc, WORD action );
47 static const pfPaint btnPaintFunc[MAX_BTN_TYPE] =
49 PB_Paint, /* BS_PUSHBUTTON */
50 PB_Paint, /* BS_DEFPUSHBUTTON */
51 CB_Paint, /* BS_CHECKBOX */
52 CB_Paint, /* BS_AUTOCHECKBOX */
53 CB_Paint, /* BS_RADIOBUTTON */
54 CB_Paint, /* BS_3STATE */
55 CB_Paint, /* BS_AUTO3STATE */
56 GB_Paint, /* BS_GROUPBOX */
57 UB_Paint, /* BS_USERBUTTON */
58 CB_Paint, /* BS_AUTORADIOBUTTON */
59 NULL, /* Not defined */
60 OB_Paint /* BS_OWNERDRAW */
63 #define PAINT_BUTTON(wndPtr,style,action) \
64 if (btnPaintFunc[style]) { \
65 HDC hdc = GetDC( (wndPtr)->hwndSelf ); \
66 (btnPaintFunc[style])(wndPtr,hdc,action); \
67 ReleaseDC( (wndPtr)->hwndSelf, hdc ); }
69 #define BUTTON_SEND_CTLCOLOR(wndPtr,hdc) \
70 SendMessageA( GetParent((wndPtr)->hwndSelf), WM_CTLCOLORBTN, \
71 (hdc), (wndPtr)->hwndSelf )
73 static HBITMAP hbitmapCheckBoxes = 0;
74 static WORD checkBoxWidth = 0, checkBoxHeight = 0;
77 /***********************************************************************
78 * ButtonWndProc_locked
80 * Called with window lock held.
82 static inline LRESULT WINAPI ButtonWndProc_locked(WND* wndPtr, UINT uMsg,
83 WPARAM wParam, LPARAM lParam )
85 RECT rect;
86 HWND hWnd = wndPtr->hwndSelf;
87 POINT pt;
88 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
89 LONG style = wndPtr->dwStyle & 0x0f;
90 HANDLE oldHbitmap;
92 pt.x = LOWORD(lParam);
93 pt.y = HIWORD(lParam);
95 switch (uMsg)
97 case WM_GETDLGCODE:
98 switch(style)
100 case BS_PUSHBUTTON: return DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON;
101 case BS_DEFPUSHBUTTON: return DLGC_BUTTON | DLGC_DEFPUSHBUTTON;
102 case BS_RADIOBUTTON:
103 case BS_AUTORADIOBUTTON: return DLGC_BUTTON | DLGC_RADIOBUTTON;
104 default: return DLGC_BUTTON;
107 case WM_ENABLE:
108 PAINT_BUTTON( wndPtr, style, ODA_DRAWENTIRE );
109 break;
111 case WM_CREATE:
112 if (!hbitmapCheckBoxes)
114 BITMAP bmp;
115 hbitmapCheckBoxes = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_CHECKBOXES));
116 GetObjectA( hbitmapCheckBoxes, sizeof(bmp), &bmp );
117 checkBoxWidth = bmp.bmWidth / 4;
118 checkBoxHeight = bmp.bmHeight / 3;
120 if (style < 0L || style >= MAX_BTN_TYPE)
121 return -1; /* abort */
122 infoPtr->state = BUTTON_UNCHECKED;
123 infoPtr->hFont = 0;
124 infoPtr->hImage = 0;
125 return 0;
127 case WM_ERASEBKGND:
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_KEYDOWN:
142 if (wParam == VK_SPACE)
144 SendMessageA( hWnd, BM_SETSTATE, TRUE, 0 );
145 infoPtr->state |= BUTTON_BTNPRESSED;
147 break;
149 case WM_LBUTTONDBLCLK:
150 if(wndPtr->dwStyle & BS_NOTIFY ||
151 style==BS_RADIOBUTTON ||
152 style==BS_USERBUTTON ||
153 style==BS_OWNERDRAW) {
154 SendMessageA( GetParent(hWnd), WM_COMMAND,
155 MAKEWPARAM( wndPtr->wIDmenu, BN_DOUBLECLICKED ), hWnd);
156 break;
158 /* fall through */
159 case WM_LBUTTONDOWN:
160 SetCapture( hWnd );
161 SetFocus( hWnd );
162 SendMessageA( hWnd, BM_SETSTATE, TRUE, 0 );
163 infoPtr->state |= BUTTON_BTNPRESSED;
164 break;
166 case WM_KEYUP:
167 if (wParam != VK_SPACE)
168 break;
169 /* fall through */
170 case WM_LBUTTONUP:
171 if (!(infoPtr->state & BUTTON_BTNPRESSED)) break;
172 infoPtr->state &= BUTTON_NSTATES;
173 if (!(infoPtr->state & BUTTON_HIGHLIGHTED)) {
174 ReleaseCapture();
175 break;
177 SendMessageA( hWnd, BM_SETSTATE, FALSE, 0 );
178 ReleaseCapture();
179 GetClientRect( hWnd, &rect );
180 if (uMsg == WM_KEYUP || PtInRect( &rect, pt ))
182 switch(style)
184 case BS_AUTOCHECKBOX:
185 SendMessageA( hWnd, BM_SETCHECK,
186 !(infoPtr->state & BUTTON_CHECKED), 0 );
187 break;
188 case BS_AUTORADIOBUTTON:
189 SendMessageA( hWnd, BM_SETCHECK, TRUE, 0 );
190 break;
191 case BS_AUTO3STATE:
192 SendMessageA( hWnd, BM_SETCHECK,
193 (infoPtr->state & BUTTON_3STATE) ? 0 :
194 ((infoPtr->state & 3) + 1), 0 );
195 break;
197 SendMessageA( GetParent(hWnd), WM_COMMAND,
198 MAKEWPARAM( wndPtr->wIDmenu, BN_CLICKED ), hWnd);
200 break;
202 case WM_CAPTURECHANGED:
203 if (infoPtr->state & BUTTON_BTNPRESSED) {
204 infoPtr->state &= BUTTON_NSTATES;
205 if (infoPtr->state & BUTTON_HIGHLIGHTED)
206 SendMessageA( hWnd, BM_SETSTATE, FALSE, 0 );
208 break;
210 case WM_MOUSEMOVE:
211 if (GetCapture() == hWnd)
213 GetClientRect( hWnd, &rect );
214 SendMessageA( hWnd, BM_SETSTATE, PtInRect(&rect, pt), 0 );
216 break;
218 case WM_NCHITTEST:
219 if(style == BS_GROUPBOX) return HTTRANSPARENT;
220 return DefWindowProcA( hWnd, uMsg, wParam, lParam );
222 case WM_SETTEXT:
223 DEFWND_SetText( wndPtr, (LPCSTR)lParam );
224 if( wndPtr->dwStyle & WS_VISIBLE )
225 PAINT_BUTTON( wndPtr, style, ODA_DRAWENTIRE );
226 return 0;
228 case WM_SETFONT:
229 infoPtr->hFont = (HFONT16)wParam;
230 if (lParam && (wndPtr->dwStyle & WS_VISIBLE))
231 PAINT_BUTTON( wndPtr, style, ODA_DRAWENTIRE );
232 break;
234 case WM_GETFONT:
235 return infoPtr->hFont;
237 case WM_SETFOCUS:
238 if ((style == BS_AUTORADIOBUTTON) && (GetCapture() != hWnd) &&
239 !(SendMessageA(hWnd, BM_GETCHECK, 0, 0) & BST_CHECKED))
241 /* The notification is sent when the button (BS_AUTORADIOBUTTON)
242 is unckecked and the focus was not given by a mouse click. */
243 SendMessageA( hWnd, BM_SETCHECK, TRUE, 0 );
244 SendMessageA( GetParent(hWnd), WM_COMMAND,
245 MAKEWPARAM( wndPtr->wIDmenu, BN_CLICKED ), hWnd);
247 infoPtr->state |= BUTTON_HASFOCUS;
248 PAINT_BUTTON( wndPtr, style, ODA_FOCUS );
249 break;
251 case WM_KILLFOCUS:
252 infoPtr->state &= ~BUTTON_HASFOCUS;
253 PAINT_BUTTON( wndPtr, style, ODA_FOCUS );
254 InvalidateRect( hWnd, NULL, TRUE );
255 break;
257 case WM_SYSCOLORCHANGE:
258 InvalidateRect( hWnd, NULL, FALSE );
259 break;
261 case BM_SETSTYLE16:
262 case BM_SETSTYLE:
263 if ((wParam & 0x0f) >= MAX_BTN_TYPE) break;
264 wndPtr->dwStyle = (wndPtr->dwStyle & 0xfffffff0)
265 | (wParam & 0x0000000f);
266 style = wndPtr->dwStyle & 0x0000000f;
267 PAINT_BUTTON( wndPtr, style, ODA_DRAWENTIRE );
268 break;
270 case BM_CLICK:
271 SendMessageA( hWnd, WM_LBUTTONDOWN, 0, 0 );
272 SendMessageA( hWnd, WM_LBUTTONUP, 0, 0 );
273 break;
275 case BM_SETIMAGE:
276 oldHbitmap = infoPtr->hImage;
277 if ((wndPtr->dwStyle & BS_BITMAP) || (wndPtr->dwStyle & BS_ICON))
278 infoPtr->hImage = (HANDLE) lParam;
279 return oldHbitmap;
281 case BM_GETIMAGE:
282 if (wParam == IMAGE_BITMAP)
283 return (HBITMAP)infoPtr->hImage;
284 else if (wParam == IMAGE_ICON)
285 return (HICON)infoPtr->hImage;
286 else
287 return (HICON)0;
289 case BM_GETCHECK16:
290 case BM_GETCHECK:
291 return infoPtr->state & 3;
293 case BM_SETCHECK16:
294 case BM_SETCHECK:
295 if (wParam > maxCheckState[style]) wParam = maxCheckState[style];
296 if ((infoPtr->state & 3) != wParam)
298 if ((style == BS_RADIOBUTTON) || (style == BS_AUTORADIOBUTTON))
300 if (wParam)
301 wndPtr->dwStyle |= WS_TABSTOP;
302 else
303 wndPtr->dwStyle &= ~WS_TABSTOP;
305 infoPtr->state = (infoPtr->state & ~3) | wParam;
306 PAINT_BUTTON( wndPtr, style, ODA_SELECT );
308 if ((style == BS_AUTORADIOBUTTON) && (wParam == BUTTON_CHECKED))
309 BUTTON_CheckAutoRadioButton( wndPtr );
310 break;
312 case BM_GETSTATE16:
313 case BM_GETSTATE:
314 return infoPtr->state;
316 case BM_SETSTATE16:
317 case BM_SETSTATE:
318 if (wParam)
320 if (infoPtr->state & BUTTON_HIGHLIGHTED) break;
321 infoPtr->state |= BUTTON_HIGHLIGHTED;
323 else
325 if (!(infoPtr->state & BUTTON_HIGHLIGHTED)) break;
326 infoPtr->state &= ~BUTTON_HIGHLIGHTED;
328 PAINT_BUTTON( wndPtr, style, ODA_SELECT );
329 break;
331 default:
332 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
334 return 0;
337 /***********************************************************************
338 * ButtonWndProc
339 * The button window procedure. This is just a wrapper which locks
340 * the passed HWND and calls the real window procedure (with a WND*
341 * pointer pointing to the locked windowstructure).
343 LRESULT WINAPI ButtonWndProc( HWND hWnd, UINT uMsg,
344 WPARAM wParam, LPARAM lParam )
346 LRESULT res;
347 WND *wndPtr = WIN_FindWndPtr(hWnd);
349 res = ButtonWndProc_locked(wndPtr,uMsg,wParam,lParam);
351 WIN_ReleaseWndPtr(wndPtr);
352 return res;
355 /**********************************************************************
356 * Push Button Functions
358 static void PB_Paint( WND *wndPtr, HDC hDC, WORD action )
360 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
361 BOOL bHighLighted = (infoPtr->state & BUTTON_HIGHLIGHTED);
364 * Delegate this to the more generic pushbutton painting
365 * method.
367 BUTTON_DrawPushButton(wndPtr,
368 hDC,
369 action,
370 bHighLighted);
373 /**********************************************************************
374 * This method will actually do the drawing of the pushbutton
375 * depending on it's state and the pushedState parameter.
377 static void BUTTON_DrawPushButton(
378 WND* wndPtr,
379 HDC hDC,
380 WORD action,
381 BOOL pushedState )
383 RECT rc, focus_rect;
384 HPEN hOldPen;
385 HBRUSH hOldBrush;
386 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
387 int xBorderOffset, yBorderOffset;
388 xBorderOffset = yBorderOffset = 0;
390 GetClientRect( wndPtr->hwndSelf, &rc );
392 /* Send WM_CTLCOLOR to allow changing the font (the colors are fixed) */
393 if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
394 BUTTON_SEND_CTLCOLOR( wndPtr, hDC );
395 hOldPen = (HPEN)SelectObject(hDC, GetSysColorPen(COLOR_WINDOWFRAME));
396 hOldBrush =(HBRUSH)SelectObject(hDC,GetSysColorBrush(COLOR_BTNFACE));
397 SetBkMode(hDC, TRANSPARENT);
399 if ( TWEAK_WineLook == WIN31_LOOK)
401 Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom);
403 SetPixel( hDC, rc.left, rc.top, GetSysColor(COLOR_WINDOW) );
404 SetPixel( hDC, rc.left, rc.bottom-1, GetSysColor(COLOR_WINDOW) );
405 SetPixel( hDC, rc.right-1, rc.top, GetSysColor(COLOR_WINDOW) );
406 SetPixel( hDC, rc.right-1, rc.bottom-1, GetSysColor(COLOR_WINDOW));
407 InflateRect( &rc, -1, -1 );
410 if ((wndPtr->dwStyle & 0x000f) == BS_DEFPUSHBUTTON)
412 Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom);
413 InflateRect( &rc, -1, -1 );
416 if (TWEAK_WineLook == WIN31_LOOK)
418 if (pushedState)
420 /* draw button shadow: */
421 SelectObject(hDC, GetSysColorBrush(COLOR_BTNSHADOW));
422 PatBlt(hDC, rc.left, rc.top, 1, rc.bottom-rc.top, PATCOPY );
423 PatBlt(hDC, rc.left, rc.top, rc.right-rc.left, 1, PATCOPY );
424 rc.left += 2; /* To position the text down and right */
425 rc.top += 2;
426 } else {
427 rc.right++, rc.bottom++;
428 DrawEdge( hDC, &rc, EDGE_RAISED, BF_RECT );
430 /* To place de bitmap correctly */
431 xBorderOffset += GetSystemMetrics(SM_CXEDGE);
432 yBorderOffset += GetSystemMetrics(SM_CYEDGE);
434 rc.right--, rc.bottom--;
437 else
439 UINT uState = DFCS_BUTTONPUSH;
441 if (pushedState)
443 if ( (wndPtr->dwStyle & 0x000f) == BS_DEFPUSHBUTTON )
444 uState |= DFCS_FLAT;
445 else
446 uState |= DFCS_PUSHED;
449 DrawFrameControl( hDC, &rc, DFC_BUTTON, uState );
450 InflateRect( &rc, -2, -2 );
452 focus_rect = rc;
454 if (pushedState)
456 rc.left += 2; /* To position the text down and right */
457 rc.top += 2;
461 /* draw button label, if any:
463 * In win9x we don't show text if there is a bitmap or icon.
464 * I don't know about win31 so I leave it as it was for win31.
465 * Dennis Björklund 12 Jul, 99
467 if ( wndPtr->text && wndPtr->text[0]
468 && (TWEAK_WineLook == WIN31_LOOK || !(wndPtr->dwStyle & (BS_ICON|BS_BITMAP))) )
470 LOGBRUSH lb;
471 GetObjectA( GetSysColorBrush(COLOR_BTNFACE), sizeof(lb), &lb );
472 if (wndPtr->dwStyle & WS_DISABLED &&
473 GetSysColor(COLOR_GRAYTEXT)==lb.lbColor)
474 /* don't write gray text on gray background */
475 PaintGrayOnGray( hDC,infoPtr->hFont,&rc,wndPtr->text,
476 DT_CENTER | DT_VCENTER );
477 else
479 SetTextColor( hDC, (wndPtr->dwStyle & WS_DISABLED) ?
480 GetSysColor(COLOR_GRAYTEXT) :
481 GetSysColor(COLOR_BTNTEXT) );
482 DrawTextA( hDC, wndPtr->text, -1, &rc,
483 DT_SINGLELINE | DT_CENTER | DT_VCENTER );
484 /* do we have the focus?
485 * Win9x draws focus last with a size prop. to the button
487 if (TWEAK_WineLook == WIN31_LOOK
488 && infoPtr->state & BUTTON_HASFOCUS)
490 RECT r = { 0, 0, 0, 0 };
491 INT xdelta, ydelta;
493 DrawTextA( hDC, wndPtr->text, -1, &r,
494 DT_SINGLELINE | DT_CALCRECT );
495 xdelta = ((rc.right - rc.left) - (r.right - r.left) - 1) / 2;
496 ydelta = ((rc.bottom - rc.top) - (r.bottom - r.top) - 1) / 2;
497 if (xdelta < 0) xdelta = 0;
498 if (ydelta < 0) ydelta = 0;
499 InflateRect( &rc, -xdelta, -ydelta );
500 DrawFocusRect( hDC, &rc );
504 if ( ((wndPtr->dwStyle & BS_ICON) || (wndPtr->dwStyle & BS_BITMAP) ) &&
505 (infoPtr->hImage != 0) )
507 int yOffset, xOffset;
508 int imageWidth, imageHeight;
511 * We extract the size of the image from the handle.
513 if (wndPtr->dwStyle & BS_ICON)
515 ICONINFO iconInfo;
516 BITMAP bm;
518 GetIconInfo((HICON)infoPtr->hImage, &iconInfo);
519 GetObjectA (iconInfo.hbmColor, sizeof(BITMAP), &bm);
521 imageWidth = bm.bmWidth;
522 imageHeight = bm.bmHeight;
524 DeleteObject(iconInfo.hbmColor);
525 DeleteObject(iconInfo.hbmMask);
528 else
530 BITMAP bm;
532 GetObjectA (infoPtr->hImage, sizeof(BITMAP), &bm);
534 imageWidth = bm.bmWidth;
535 imageHeight = bm.bmHeight;
538 /* Center the bitmap */
539 xOffset = (((rc.right - rc.left) - 2*xBorderOffset) - imageWidth ) / 2;
540 yOffset = (((rc.bottom - rc.top) - 2*yBorderOffset) - imageHeight) / 2;
542 /* If the image is too big for the button then create a region*/
543 if(xOffset < 0 || yOffset < 0)
545 HRGN hBitmapRgn = 0;
546 hBitmapRgn = CreateRectRgn(
547 rc.left + xBorderOffset, rc.top +yBorderOffset,
548 rc.right - xBorderOffset, rc.bottom - yBorderOffset);
549 SelectClipRgn(hDC, hBitmapRgn);
550 DeleteObject(hBitmapRgn);
553 /* Let minimum 1 space from border */
554 xOffset++, yOffset++;
557 * Draw the image now.
559 if (wndPtr->dwStyle & BS_ICON)
561 DrawIcon(hDC,
562 rc.left + xOffset, rc.top + yOffset,
563 (HICON)infoPtr->hImage);
565 else
567 HDC hdcMem;
569 hdcMem = CreateCompatibleDC (hDC);
570 SelectObject (hdcMem, (HBITMAP)infoPtr->hImage);
571 BitBlt(hDC,
572 rc.left + xOffset,
573 rc.top + yOffset,
574 imageWidth, imageHeight,
575 hdcMem, 0, 0, SRCCOPY);
577 DeleteDC (hdcMem);
580 if(xOffset < 0 || yOffset < 0)
582 SelectClipRgn(hDC, 0);
586 if (TWEAK_WineLook != WIN31_LOOK
587 && infoPtr->state & BUTTON_HASFOCUS)
589 InflateRect( &focus_rect, -1, -1 );
590 DrawFocusRect( hDC, &focus_rect );
594 SelectObject( hDC, hOldPen );
595 SelectObject( hDC, hOldBrush );
599 /**********************************************************************
600 * PB_Paint & CB_Paint sub function [internal]
601 * Paint text using a raster brush to avoid gray text on gray
602 * background. 'format' can be a combination of DT_CENTER and
603 * DT_VCENTER to use this function in both PB_PAINT and
604 * CB_PAINT. - Dirk Thierbach
606 * FIXME: This and TEXT_GrayString should be eventually combined,
607 * so calling one common function from PB_Paint, CB_Paint and
608 * TEXT_GrayString will be enough. Also note that this
609 * function ignores the CACHE_GetPattern funcs.
612 void PaintGrayOnGray(HDC hDC,HFONT hFont,RECT *rc,char *text,
613 UINT format)
615 /* This is the standard gray on gray pattern:
616 static const WORD Pattern[] = {0xAA,0x55,0xAA,0x55,0xAA,0x55,0xAA,0x55};
618 /* This pattern gives better readability with X Fonts.
619 FIXME: Maybe the user should be allowed to decide which he wants. */
620 static const WORD Pattern[] = {0x55,0xFF,0xAA,0xFF,0x55,0xFF,0xAA,0xFF};
622 HBITMAP hbm = CreateBitmap( 8, 8, 1, 1, Pattern );
623 HDC hdcMem = CreateCompatibleDC(hDC);
624 HBITMAP hbmMem;
625 HBRUSH hBr;
626 RECT rect,rc2;
628 rect=*rc;
629 DrawTextA( hDC, text, -1, &rect, DT_SINGLELINE | DT_CALCRECT);
630 /* now text width and height are in rect.right and rect.bottom */
631 rc2=rect;
632 rect.left = rect.top = 0; /* drawing pos in hdcMem */
633 if (format & DT_CENTER) rect.left=(rc->right-rect.right)/2;
634 if (format & DT_VCENTER) rect.top=(rc->bottom-rect.bottom)/2;
635 hbmMem = CreateCompatibleBitmap( hDC,rect.right,rect.bottom );
636 SelectObject( hdcMem, hbmMem);
637 PatBlt( hdcMem,0,0,rect.right,rect.bottom,WHITENESS);
638 /* will be overwritten by DrawText, but just in case */
639 if (hFont) SelectObject( hdcMem, hFont);
640 DrawTextA( hdcMem, text, -1, &rc2, DT_SINGLELINE);
641 /* After draw: foreground = 0 bits, background = 1 bits */
642 hBr = SelectObject( hdcMem, CreatePatternBrush(hbm) );
643 DeleteObject( hbm );
644 PatBlt( hdcMem,0,0,rect.right,rect.bottom,0xAF0229);
645 /* only keep the foreground bits where pattern is 1 */
646 DeleteObject( SelectObject( hdcMem,hBr) );
647 BitBlt(hDC,rect.left,rect.top,rect.right,rect.bottom,hdcMem,0,0,SRCAND);
648 /* keep the background of the dest */
649 DeleteDC( hdcMem);
650 DeleteObject( hbmMem );
654 /**********************************************************************
655 * Check Box & Radio Button Functions
658 static void CB_Paint( WND *wndPtr, HDC hDC, WORD action )
660 RECT rbox, rtext, client;
661 HBRUSH hBrush;
662 int textlen, delta;
663 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
666 * if the button has a bitmap/icon, draw a normal pushbutton
667 * instead of a radion button.
669 if (infoPtr->hImage != 0)
671 BOOL bHighLighted = ((infoPtr->state & BUTTON_HIGHLIGHTED) ||
672 (infoPtr->state & BUTTON_CHECKED));
674 BUTTON_DrawPushButton(wndPtr,
675 hDC,
676 action,
677 bHighLighted);
678 return;
681 textlen = 0;
682 GetClientRect(wndPtr->hwndSelf, &client);
683 rbox = rtext = client;
685 if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
687 /* Something is still not right, checkboxes (and edit controls)
688 * in wsping32 have white backgrounds instead of dark grey.
689 * BUTTON_SEND_CTLCOLOR() is even worse since it returns 0 in this
690 * particular case and the background is not painted at all.
693 hBrush = GetControlBrush16( wndPtr->hwndSelf, hDC, CTLCOLOR_BTN );
695 if (wndPtr->dwStyle & BS_LEFTTEXT)
697 /* magic +4 is what CTL3D expects */
699 rtext.right -= checkBoxWidth + 4;
700 rbox.left = rbox.right - checkBoxWidth;
702 else
704 rtext.left += checkBoxWidth + 4;
705 rbox.right = checkBoxWidth;
708 /* Draw the check-box bitmap */
710 if (wndPtr->text) textlen = strlen( wndPtr->text );
711 if (action == ODA_DRAWENTIRE || action == ODA_SELECT)
713 if( TWEAK_WineLook == WIN31_LOOK )
715 HDC hMemDC = CreateCompatibleDC( hDC );
716 int x = 0, y = 0;
717 delta = (rbox.bottom - rbox.top - checkBoxHeight) / 2;
719 /* Check in case the client area is smaller than the checkbox bitmap */
720 if (delta < 0) delta = 0;
722 if (action == ODA_SELECT) FillRect( hDC, &rbox, hBrush );
723 else FillRect( hDC, &client, hBrush );
725 if (infoPtr->state & BUTTON_HIGHLIGHTED) x += 2 * checkBoxWidth;
726 if (infoPtr->state & (BUTTON_CHECKED | BUTTON_3STATE)) x += checkBoxWidth;
727 if (((wndPtr->dwStyle & 0x0f) == BS_RADIOBUTTON) ||
728 ((wndPtr->dwStyle & 0x0f) == BS_AUTORADIOBUTTON)) y += checkBoxHeight;
729 else if (infoPtr->state & BUTTON_3STATE) y += 2 * checkBoxHeight;
731 /* The bitmap for the radio button is not aligned with the
732 * left of the window, it is 1 pixel off. */
733 if (((wndPtr->dwStyle & 0x0f) == BS_RADIOBUTTON) ||
734 ((wndPtr->dwStyle & 0x0f) == BS_AUTORADIOBUTTON))
735 rbox.left += 1;
737 SelectObject( hMemDC, hbitmapCheckBoxes );
738 BitBlt( hDC, rbox.left, rbox.top + delta, checkBoxWidth,
739 checkBoxHeight, hMemDC, x, y, SRCCOPY );
740 DeleteDC( hMemDC );
742 else
744 UINT state;
746 if (((wndPtr->dwStyle & 0x0f) == BS_RADIOBUTTON) ||
747 ((wndPtr->dwStyle & 0x0f) == BS_AUTORADIOBUTTON)) state = DFCS_BUTTONRADIO;
748 else if (infoPtr->state & BUTTON_3STATE) state = DFCS_BUTTON3STATE;
749 else state = DFCS_BUTTONCHECK;
751 if (infoPtr->state & (BUTTON_CHECKED | BUTTON_3STATE)) state |= DFCS_CHECKED;
753 if (infoPtr->state & BUTTON_HIGHLIGHTED) state |= DFCS_PUSHED;
755 if (wndPtr->dwStyle & WS_DISABLED) state |= DFCS_INACTIVE;
757 DrawFrameControl( hDC, &rbox, DFC_BUTTON, state );
761 if( textlen && action != ODA_SELECT )
763 if (wndPtr->dwStyle & WS_DISABLED &&
764 GetSysColor(COLOR_GRAYTEXT)==GetBkColor(hDC)) {
765 /* don't write gray text on gray background */
766 PaintGrayOnGray( hDC, infoPtr->hFont, &rtext, wndPtr->text,
767 DT_VCENTER);
768 } else {
769 if (wndPtr->dwStyle & WS_DISABLED)
770 SetTextColor( hDC, GetSysColor(COLOR_GRAYTEXT) );
771 DrawTextA( hDC, wndPtr->text, textlen, &rtext,
772 DT_SINGLELINE | DT_VCENTER );
777 if ((action == ODA_FOCUS) ||
778 ((action == ODA_DRAWENTIRE) && (infoPtr->state & BUTTON_HASFOCUS)))
780 /* again, this is what CTL3D expects */
782 SetRectEmpty(&rbox);
783 if( textlen )
784 DrawTextA( hDC, wndPtr->text, textlen, &rbox,
785 DT_SINGLELINE | DT_CALCRECT );
786 textlen = rbox.bottom - rbox.top;
787 delta = ((rtext.bottom - rtext.top) - textlen)/2;
788 rbox.bottom = (rbox.top = rtext.top + delta - 1) + textlen + 2;
789 textlen = rbox.right - rbox.left;
790 rbox.right = (rbox.left += --rtext.left) + textlen + 2;
791 IntersectRect(&rbox, &rbox, &rtext);
792 DrawFocusRect( hDC, &rbox );
797 /**********************************************************************
798 * BUTTON_CheckAutoRadioButton
800 * wndPtr is checked, uncheck every other auto radio button in group
802 static void BUTTON_CheckAutoRadioButton( WND *wndPtr )
804 HWND parent, sibling, start;
805 if (!(wndPtr->dwStyle & WS_CHILD)) return;
806 parent = wndPtr->parent->hwndSelf;
807 /* assure that starting control is not disabled or invisible */
808 start = sibling = GetNextDlgGroupItem( parent, wndPtr->hwndSelf, TRUE );
811 WND *tmpWnd;
812 if (!sibling) break;
813 tmpWnd = WIN_FindWndPtr(sibling);
814 if ((wndPtr->hwndSelf != sibling) &&
815 ((tmpWnd->dwStyle & 0x0f) == BS_AUTORADIOBUTTON))
816 SendMessageA( sibling, BM_SETCHECK, BUTTON_UNCHECKED, 0 );
817 sibling = GetNextDlgGroupItem( parent, sibling, FALSE );
818 WIN_ReleaseWndPtr(tmpWnd);
819 } while (sibling != start);
823 /**********************************************************************
824 * Group Box Functions
827 static void GB_Paint( WND *wndPtr, HDC hDC, WORD action )
829 RECT rc, rcFrame;
830 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
832 if (action != ODA_DRAWENTIRE) return;
834 BUTTON_SEND_CTLCOLOR( wndPtr, hDC );
836 GetClientRect( wndPtr->hwndSelf, &rc);
837 if (TWEAK_WineLook == WIN31_LOOK) {
838 HPEN hPrevPen = SelectObject( hDC,
839 GetSysColorPen(COLOR_WINDOWFRAME));
840 HBRUSH hPrevBrush = SelectObject( hDC,
841 GetStockObject(NULL_BRUSH) );
843 Rectangle( hDC, rc.left, rc.top + 2, rc.right - 1, rc.bottom - 1 );
844 SelectObject( hDC, hPrevBrush );
845 SelectObject( hDC, hPrevPen );
846 } else {
847 TEXTMETRICA tm;
848 rcFrame = rc;
850 if (infoPtr->hFont)
851 SelectObject (hDC, infoPtr->hFont);
852 GetTextMetricsA (hDC, &tm);
853 rcFrame.top += (tm.tmHeight / 2) - 1;
854 DrawEdge (hDC, &rcFrame, EDGE_ETCHED, BF_RECT);
857 if (wndPtr->text)
859 if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
860 if (wndPtr->dwStyle & WS_DISABLED)
861 SetTextColor( hDC, GetSysColor(COLOR_GRAYTEXT) );
862 rc.left += 10;
863 DrawTextA( hDC, wndPtr->text, -1, &rc, DT_SINGLELINE | DT_NOCLIP );
868 /**********************************************************************
869 * User Button Functions
872 static void UB_Paint( WND *wndPtr, HDC hDC, WORD action )
874 RECT rc;
875 HBRUSH hBrush;
876 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
878 if (action == ODA_SELECT) return;
880 GetClientRect( wndPtr->hwndSelf, &rc);
882 if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
883 hBrush = GetControlBrush16( wndPtr->hwndSelf, hDC, CTLCOLOR_BTN );
885 FillRect( hDC, &rc, hBrush );
886 if ((action == ODA_FOCUS) ||
887 ((action == ODA_DRAWENTIRE) && (infoPtr->state & BUTTON_HASFOCUS)))
888 DrawFocusRect( hDC, &rc );
892 /**********************************************************************
893 * Ownerdrawn Button Functions
896 static void OB_Paint( WND *wndPtr, HDC hDC, WORD action )
898 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
899 DRAWITEMSTRUCT dis;
901 dis.CtlType = ODT_BUTTON;
902 dis.CtlID = wndPtr->wIDmenu;
903 dis.itemID = 0;
904 dis.itemAction = action;
905 dis.itemState = ((infoPtr->state & BUTTON_HASFOCUS) ? ODS_FOCUS : 0) |
906 ((infoPtr->state & BUTTON_HIGHLIGHTED) ? ODS_SELECTED : 0) |
907 ((wndPtr->dwStyle & WS_DISABLED) ? ODS_DISABLED : 0);
908 dis.hwndItem = wndPtr->hwndSelf;
909 dis.hDC = hDC;
910 dis.itemData = 0;
911 GetClientRect( wndPtr->hwndSelf, &dis.rcItem );
913 SetBkColor( hDC, GetSysColor( COLOR_BTNFACE ) );
915 SendMessageA( GetParent(wndPtr->hwndSelf), WM_DRAWITEM,
916 wndPtr->wIDmenu, (LPARAM)&dis );