Use MESSAGE_RESOURCE_* defines from SDK headers, updated LoadMessage*
[wine/dcerpc.git] / controls / button.c
blob6c591721327b185830531a6a23f854f14958e7a1
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;
88 switch (uMsg)
90 case WM_GETDLGCODE:
91 WIN_ReleaseWndPtr(wndPtr);
92 switch(style)
94 case BS_PUSHBUTTON: return DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON;
95 case BS_DEFPUSHBUTTON: return DLGC_BUTTON | DLGC_DEFPUSHBUTTON;
96 case BS_RADIOBUTTON:
97 case BS_AUTORADIOBUTTON: return DLGC_BUTTON | DLGC_RADIOBUTTON;
98 default: return DLGC_BUTTON;
101 case WM_ENABLE:
102 PAINT_BUTTON( wndPtr, style, ODA_DRAWENTIRE );
103 break;
105 case WM_CREATE:
106 if (!hbitmapCheckBoxes)
108 BITMAP bmp;
109 hbitmapCheckBoxes = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_CHECKBOXES));
110 GetObjectA( hbitmapCheckBoxes, sizeof(bmp), &bmp );
111 checkBoxWidth = bmp.bmWidth / 4;
112 checkBoxHeight = bmp.bmHeight / 3;
114 if (style < 0L || style >= MAX_BTN_TYPE)
116 WIN_ReleaseWndPtr(wndPtr);
117 return -1; /* abort */
119 infoPtr->state = BUTTON_UNCHECKED;
120 infoPtr->hFont = 0;
121 WIN_ReleaseWndPtr(wndPtr);
122 return 0;
124 case WM_ERASEBKGND:
125 WIN_ReleaseWndPtr(wndPtr);
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 WIN_ReleaseWndPtr(wndPtr);
183 if(style == BS_GROUPBOX) return HTTRANSPARENT;
184 return DefWindowProcA( hWnd, uMsg, wParam, lParam );
186 case WM_SETTEXT:
187 DEFWND_SetText( wndPtr, (LPCSTR)lParam );
188 if( wndPtr->dwStyle & WS_VISIBLE )
189 PAINT_BUTTON( wndPtr, style, ODA_DRAWENTIRE );
190 WIN_ReleaseWndPtr(wndPtr);
191 return 0;
193 case WM_SETFONT:
194 infoPtr->hFont = (HFONT16)wParam;
195 if (lParam && (wndPtr->dwStyle & WS_VISIBLE))
196 PAINT_BUTTON( wndPtr, style, ODA_DRAWENTIRE );
197 break;
199 case WM_GETFONT:
200 retvalue = infoPtr->hFont;
201 WIN_ReleaseWndPtr(wndPtr);
202 return retvalue;
204 case WM_SETFOCUS:
205 infoPtr->state |= BUTTON_HASFOCUS;
206 if (style == BS_AUTORADIOBUTTON)
208 SendMessageA( hWnd, BM_SETCHECK, 1, 0 );
210 PAINT_BUTTON( wndPtr, style, ODA_FOCUS );
211 break;
213 case WM_KILLFOCUS:
214 infoPtr->state &= ~BUTTON_HASFOCUS;
215 PAINT_BUTTON( wndPtr, style, ODA_FOCUS );
216 InvalidateRect( hWnd, NULL, TRUE );
217 break;
219 case WM_SYSCOLORCHANGE:
220 InvalidateRect( hWnd, NULL, FALSE );
221 break;
223 case BM_SETSTYLE16:
224 case BM_SETSTYLE:
225 if ((wParam & 0x0f) >= MAX_BTN_TYPE) break;
226 wndPtr->dwStyle = (wndPtr->dwStyle & 0xfffffff0)
227 | (wParam & 0x0000000f);
228 style = wndPtr->dwStyle & 0x0000000f;
229 PAINT_BUTTON( wndPtr, style, ODA_DRAWENTIRE );
230 break;
232 case BM_GETCHECK16:
233 case BM_GETCHECK:
234 retvalue = infoPtr->state & 3;
235 WIN_ReleaseWndPtr(wndPtr);
236 return retvalue;
238 case BM_SETCHECK16:
239 case BM_SETCHECK:
240 if (wParam > maxCheckState[style]) wParam = maxCheckState[style];
241 if ((infoPtr->state & 3) != wParam)
243 if ((style == BS_RADIOBUTTON) || (style == BS_AUTORADIOBUTTON))
245 if (wParam)
246 wndPtr->dwStyle |= WS_TABSTOP;
247 else
248 wndPtr->dwStyle &= ~WS_TABSTOP;
250 infoPtr->state = (infoPtr->state & ~3) | wParam;
251 PAINT_BUTTON( wndPtr, style, ODA_SELECT );
253 if ((style == BS_AUTORADIOBUTTON) && (wParam == BUTTON_CHECKED))
254 BUTTON_CheckAutoRadioButton( wndPtr );
255 break;
257 case BM_GETSTATE16:
258 case BM_GETSTATE:
259 retvalue = infoPtr->state;
260 WIN_ReleaseWndPtr(wndPtr);
261 return retvalue;
263 case BM_SETSTATE16:
264 case BM_SETSTATE:
265 if (wParam)
267 if (infoPtr->state & BUTTON_HIGHLIGHTED) break;
268 infoPtr->state |= BUTTON_HIGHLIGHTED;
270 else
272 if (!(infoPtr->state & BUTTON_HIGHLIGHTED)) break;
273 infoPtr->state &= ~BUTTON_HIGHLIGHTED;
275 PAINT_BUTTON( wndPtr, style, ODA_SELECT );
276 break;
278 default:
279 WIN_ReleaseWndPtr(wndPtr);
280 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
282 WIN_ReleaseWndPtr(wndPtr);
283 return 0;
287 /**********************************************************************
288 * Push Button Functions
291 static void PB_Paint( WND *wndPtr, HDC hDC, WORD action )
293 RECT rc;
294 HPEN hOldPen;
295 HBRUSH hOldBrush;
296 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
298 GetClientRect( wndPtr->hwndSelf, &rc );
300 /* Send WM_CTLCOLOR to allow changing the font (the colors are fixed) */
301 if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
302 BUTTON_SEND_CTLCOLOR( wndPtr, hDC );
303 hOldPen = (HPEN)SelectObject(hDC, GetSysColorPen(COLOR_WINDOWFRAME));
304 hOldBrush =(HBRUSH)SelectObject(hDC,GetSysColorBrush(COLOR_BTNFACE));
305 SetBkMode(hDC, TRANSPARENT);
306 Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom);
307 if (action == ODA_DRAWENTIRE)
309 SetPixel( hDC, rc.left, rc.top, GetSysColor(COLOR_WINDOW) );
310 SetPixel( hDC, rc.left, rc.bottom-1, GetSysColor(COLOR_WINDOW) );
311 SetPixel( hDC, rc.right-1, rc.top, GetSysColor(COLOR_WINDOW) );
312 SetPixel( hDC, rc.right-1, rc.bottom-1, GetSysColor(COLOR_WINDOW));
314 InflateRect( &rc, -1, -1 );
316 if ((wndPtr->dwStyle & 0x000f) == BS_DEFPUSHBUTTON)
318 Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom);
319 InflateRect( &rc, -1, -1 );
322 if (infoPtr->state & BUTTON_HIGHLIGHTED)
324 /* draw button shadow: */
325 SelectObject(hDC, GetSysColorBrush(COLOR_BTNSHADOW));
326 PatBlt(hDC, rc.left, rc.top, 1, rc.bottom-rc.top, PATCOPY );
327 PatBlt(hDC, rc.left, rc.top, rc.right-rc.left, 1, PATCOPY );
328 rc.left += 2; /* To position the text down and right */
329 rc.top += 2;
330 } else {
331 rc.right++, rc.bottom++;
332 DrawEdge( hDC, &rc, EDGE_RAISED, BF_RECT );
333 rc.right--, rc.bottom--;
336 /* draw button label, if any: */
337 if (wndPtr->text && wndPtr->text[0])
339 LOGBRUSH lb;
340 GetObjectA( GetSysColorBrush(COLOR_BTNFACE), sizeof(lb), &lb );
341 if (wndPtr->dwStyle & WS_DISABLED &&
342 GetSysColor(COLOR_GRAYTEXT)==lb.lbColor)
343 /* don't write gray text on gray background */
344 PaintGrayOnGray( hDC,infoPtr->hFont,&rc,wndPtr->text,
345 DT_CENTER | DT_VCENTER );
346 else
348 SetTextColor( hDC, (wndPtr->dwStyle & WS_DISABLED) ?
349 GetSysColor(COLOR_GRAYTEXT) :
350 GetSysColor(COLOR_BTNTEXT) );
351 DrawTextA( hDC, wndPtr->text, -1, &rc,
352 DT_SINGLELINE | DT_CENTER | DT_VCENTER );
353 /* do we have the focus? */
354 if (infoPtr->state & BUTTON_HASFOCUS)
356 RECT r = { 0, 0, 0, 0 };
357 INT xdelta, ydelta;
359 DrawTextA( hDC, wndPtr->text, -1, &r,
360 DT_SINGLELINE | DT_CALCRECT );
361 xdelta = ((rc.right - rc.left) - (r.right - r.left) - 1) / 2;
362 ydelta = ((rc.bottom - rc.top) - (r.bottom - r.top) - 1) / 2;
363 if (xdelta < 0) xdelta = 0;
364 if (ydelta < 0) ydelta = 0;
365 InflateRect( &rc, -xdelta, -ydelta );
366 DrawFocusRect( hDC, &rc );
371 SelectObject( hDC, hOldPen );
372 SelectObject( hDC, hOldBrush );
376 /**********************************************************************
377 * PB_Paint & CB_Paint sub function [internal]
378 * Paint text using a raster brush to avoid gray text on gray
379 * background. 'format' can be a combination of DT_CENTER and
380 * DT_VCENTER to use this function in both PB_PAINT and
381 * CB_PAINT. - Dirk Thierbach
383 * FIXME: This and TEXT_GrayString should be eventually combined,
384 * so calling one common function from PB_Paint, CB_Paint and
385 * TEXT_GrayString will be enough. Also note that this
386 * function ignores the CACHE_GetPattern funcs.
389 void PaintGrayOnGray(HDC hDC,HFONT hFont,RECT *rc,char *text,
390 UINT format)
392 /* This is the standard gray on gray pattern:
393 static const WORD Pattern[] = {0xAA,0x55,0xAA,0x55,0xAA,0x55,0xAA,0x55};
395 /* This pattern gives better readability with X Fonts.
396 FIXME: Maybe the user should be allowed to decide which he wants. */
397 static const WORD Pattern[] = {0x55,0xFF,0xAA,0xFF,0x55,0xFF,0xAA,0xFF};
399 HBITMAP hbm = CreateBitmap( 8, 8, 1, 1, Pattern );
400 HDC hdcMem = CreateCompatibleDC(hDC);
401 HBITMAP hbmMem;
402 HBRUSH hBr;
403 RECT rect,rc2;
405 rect=*rc;
406 DrawTextA( hDC, text, -1, &rect, DT_SINGLELINE | DT_CALCRECT);
407 /* now text width and height are in rect.right and rect.bottom */
408 rc2=rect;
409 rect.left = rect.top = 0; /* drawing pos in hdcMem */
410 if (format & DT_CENTER) rect.left=(rc->right-rect.right)/2;
411 if (format & DT_VCENTER) rect.top=(rc->bottom-rect.bottom)/2;
412 hbmMem = CreateCompatibleBitmap( hDC,rect.right,rect.bottom );
413 SelectObject( hdcMem, hbmMem);
414 PatBlt( hdcMem,0,0,rect.right,rect.bottom,WHITENESS);
415 /* will be overwritten by DrawText, but just in case */
416 if (hFont) SelectObject( hdcMem, hFont);
417 DrawTextA( hdcMem, text, -1, &rc2, DT_SINGLELINE);
418 /* After draw: foreground = 0 bits, background = 1 bits */
419 hBr = SelectObject( hdcMem, CreatePatternBrush(hbm) );
420 DeleteObject( hbm );
421 PatBlt( hdcMem,0,0,rect.right,rect.bottom,0xAF0229);
422 /* only keep the foreground bits where pattern is 1 */
423 DeleteObject( SelectObject( hdcMem,hBr) );
424 BitBlt(hDC,rect.left,rect.top,rect.right,rect.bottom,hdcMem,0,0,SRCAND);
425 /* keep the background of the dest */
426 DeleteDC( hdcMem);
427 DeleteObject( hbmMem );
431 /**********************************************************************
432 * Check Box & Radio Button Functions
435 static void CB_Paint( WND *wndPtr, HDC hDC, WORD action )
437 RECT rbox, rtext, client;
438 HBRUSH hBrush;
439 int textlen, delta;
440 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
442 textlen = 0;
443 GetClientRect(wndPtr->hwndSelf, &client);
444 rbox = rtext = client;
446 if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
448 /* Something is still not right, checkboxes (and edit controls)
449 * in wsping32 have white backgrounds instead of dark grey.
450 * BUTTON_SEND_CTLCOLOR() is even worse since it returns 0 in this
451 * particular case and the background is not painted at all.
454 hBrush = GetControlBrush16( wndPtr->hwndSelf, hDC, CTLCOLOR_BTN );
456 if (wndPtr->dwStyle & BS_LEFTTEXT)
458 /* magic +4 is what CTL3D expects */
460 rtext.right -= checkBoxWidth + 4;
461 rbox.left = rbox.right - checkBoxWidth;
463 else
465 rtext.left += checkBoxWidth + 4;
466 rbox.right = checkBoxWidth;
469 /* Draw the check-box bitmap */
471 if (wndPtr->text) textlen = strlen( wndPtr->text );
472 if (action == ODA_DRAWENTIRE || action == ODA_SELECT)
474 HDC hMemDC = CreateCompatibleDC( hDC );
475 int x = 0, y = 0;
476 delta = (rbox.bottom - rbox.top - checkBoxHeight) >> 1;
478 if (action == ODA_SELECT) FillRect( hDC, &rbox, hBrush );
479 else FillRect( hDC, &client, hBrush );
481 if (infoPtr->state & BUTTON_HIGHLIGHTED) x += 2 * checkBoxWidth;
482 if (infoPtr->state & (BUTTON_CHECKED | BUTTON_3STATE)) x += checkBoxWidth;
483 if (((wndPtr->dwStyle & 0x0f) == BS_RADIOBUTTON) ||
484 ((wndPtr->dwStyle & 0x0f) == BS_AUTORADIOBUTTON)) y += checkBoxHeight;
485 else if (infoPtr->state & BUTTON_3STATE) y += 2 * checkBoxHeight;
487 SelectObject( hMemDC, hbitmapCheckBoxes );
488 BitBlt( hDC, rbox.left, rbox.top + delta, checkBoxWidth,
489 checkBoxHeight, hMemDC, x, y, SRCCOPY );
490 DeleteDC( hMemDC );
492 if( textlen && action != ODA_SELECT )
494 if (wndPtr->dwStyle & WS_DISABLED &&
495 GetSysColor(COLOR_GRAYTEXT)==GetBkColor(hDC)) {
496 /* don't write gray text on gray background */
497 PaintGrayOnGray( hDC, infoPtr->hFont, &rtext, wndPtr->text,
498 DT_VCENTER);
499 } else {
500 if (wndPtr->dwStyle & WS_DISABLED)
501 SetTextColor( hDC, GetSysColor(COLOR_GRAYTEXT) );
502 DrawTextA( hDC, wndPtr->text, textlen, &rtext,
503 DT_SINGLELINE | DT_VCENTER );
504 textlen = 0; /* skip DrawText() below */
509 if ((action == ODA_FOCUS) ||
510 ((action == ODA_DRAWENTIRE) && (infoPtr->state & BUTTON_HASFOCUS)))
512 /* again, this is what CTL3D expects */
514 SetRectEmpty(&rbox);
515 if( textlen )
516 DrawTextA( hDC, wndPtr->text, textlen, &rbox,
517 DT_SINGLELINE | DT_CALCRECT );
518 textlen = rbox.bottom - rbox.top;
519 delta = ((rtext.bottom - rtext.top) - textlen)/2;
520 rbox.bottom = (rbox.top = rtext.top + delta - 1) + textlen + 2;
521 textlen = rbox.right - rbox.left;
522 rbox.right = (rbox.left += --rtext.left) + textlen + 2;
523 IntersectRect(&rbox, &rbox, &rtext);
524 DrawFocusRect( hDC, &rbox );
529 /**********************************************************************
530 * BUTTON_CheckAutoRadioButton
532 * wndPtr is checked, uncheck every other auto radio button in group
534 static void BUTTON_CheckAutoRadioButton( WND *wndPtr )
536 HWND parent, sibling, start;
537 if (!(wndPtr->dwStyle & WS_CHILD)) return;
538 parent = wndPtr->parent->hwndSelf;
539 /* assure that starting control is not disabled or invisible */
540 start = sibling = GetNextDlgGroupItem( parent, wndPtr->hwndSelf, TRUE );
543 WND *tmpWnd;
544 if (!sibling) break;
545 tmpWnd = WIN_FindWndPtr(sibling);
546 if ((wndPtr->hwndSelf != sibling) &&
547 ((tmpWnd->dwStyle & 0x0f) == BS_AUTORADIOBUTTON))
548 SendMessageA( sibling, BM_SETCHECK, BUTTON_UNCHECKED, 0 );
549 sibling = GetNextDlgGroupItem( parent, sibling, FALSE );
550 WIN_ReleaseWndPtr(tmpWnd);
551 } while (sibling != start);
555 /**********************************************************************
556 * Group Box Functions
559 static void GB_Paint( WND *wndPtr, HDC hDC, WORD action )
561 RECT rc, rcFrame;
562 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
564 if (action != ODA_DRAWENTIRE) return;
566 BUTTON_SEND_CTLCOLOR( wndPtr, hDC );
568 GetClientRect( wndPtr->hwndSelf, &rc);
569 if (TWEAK_WineLook == WIN31_LOOK) {
570 HPEN hPrevPen = SelectObject( hDC,
571 GetSysColorPen(COLOR_WINDOWFRAME));
572 HBRUSH hPrevBrush = SelectObject( hDC,
573 GetStockObject(NULL_BRUSH) );
575 Rectangle( hDC, rc.left, rc.top + 2, rc.right - 1, rc.bottom - 1 );
576 SelectObject( hDC, hPrevBrush );
577 SelectObject( hDC, hPrevPen );
578 } else {
579 TEXTMETRICA tm;
580 rcFrame = rc;
582 if (infoPtr->hFont)
583 SelectObject (hDC, infoPtr->hFont);
584 GetTextMetricsA (hDC, &tm);
585 rcFrame.top += (tm.tmHeight / 2) - 1;
586 DrawEdge (hDC, &rcFrame, EDGE_ETCHED, BF_RECT);
589 if (wndPtr->text)
591 if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
592 if (wndPtr->dwStyle & WS_DISABLED)
593 SetTextColor( hDC, GetSysColor(COLOR_GRAYTEXT) );
594 rc.left += 10;
595 DrawTextA( hDC, wndPtr->text, -1, &rc, DT_SINGLELINE | DT_NOCLIP );
600 /**********************************************************************
601 * User Button Functions
604 static void UB_Paint( WND *wndPtr, HDC hDC, WORD action )
606 RECT rc;
607 HBRUSH hBrush;
608 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
610 if (action == ODA_SELECT) return;
612 GetClientRect( wndPtr->hwndSelf, &rc);
614 if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
615 hBrush = GetControlBrush16( wndPtr->hwndSelf, hDC, CTLCOLOR_BTN );
617 FillRect( hDC, &rc, hBrush );
618 if ((action == ODA_FOCUS) ||
619 ((action == ODA_DRAWENTIRE) && (infoPtr->state & BUTTON_HASFOCUS)))
620 DrawFocusRect( hDC, &rc );
624 /**********************************************************************
625 * Ownerdrawn Button Functions
628 static void OB_Paint( WND *wndPtr, HDC hDC, WORD action )
630 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
631 DRAWITEMSTRUCT dis;
633 dis.CtlType = ODT_BUTTON;
634 dis.CtlID = wndPtr->wIDmenu;
635 dis.itemID = 0;
636 dis.itemAction = action;
637 dis.itemState = ((infoPtr->state & BUTTON_HASFOCUS) ? ODS_FOCUS : 0) |
638 ((infoPtr->state & BUTTON_HIGHLIGHTED) ? ODS_SELECTED : 0) |
639 ((wndPtr->dwStyle & WS_DISABLED) ? ODS_DISABLED : 0);
640 dis.hwndItem = wndPtr->hwndSelf;
641 dis.hDC = hDC;
642 dis.itemData = 0;
643 GetClientRect( wndPtr->hwndSelf, &dis.rcItem );
644 SendMessageA( GetParent(wndPtr->hwndSelf), WM_DRAWITEM,
645 wndPtr->wIDmenu, (LPARAM)&dis );