EnumDisplayModes* returns a static list of modes with all depths
[wine] / controls / button.c
1 /* File: button.c -- Button type widgets
2  *
3  * Copyright (C) 1993 Johannes Ruscheinski
4  * Copyright (C) 1993 David Metcalfe
5  * Copyright (C) 1994 Alexandre Julliard
6  */
7
8 #include "win.h"
9 #include "graphics.h"
10 #include "button.h"
11 #include "windows.h"
12 #include "tweak.h"
13
14 static void PB_Paint( WND *wndPtr, HDC32 hDC, WORD action );
15 static void PB_PaintGrayOnGray(HDC32 hDC,HFONT32 hFont,RECT32 *rc,char *text);
16 static void CB_Paint( WND *wndPtr, HDC32 hDC, WORD action );
17 static void GB_Paint( WND *wndPtr, HDC32 hDC, WORD action );
18 static void UB_Paint( WND *wndPtr, HDC32 hDC, WORD action );
19 static void OB_Paint( WND *wndPtr, HDC32 hDC, WORD action );
20 static void BUTTON_CheckAutoRadioButton( WND *wndPtr );
21
22 #define MAX_BTN_TYPE  12
23
24 static const WORD maxCheckState[MAX_BTN_TYPE] =
25 {
26     BUTTON_UNCHECKED,   /* BS_PUSHBUTTON */
27     BUTTON_UNCHECKED,   /* BS_DEFPUSHBUTTON */
28     BUTTON_CHECKED,     /* BS_CHECKBOX */
29     BUTTON_CHECKED,     /* BS_AUTOCHECKBOX */
30     BUTTON_CHECKED,     /* BS_RADIOBUTTON */
31     BUTTON_3STATE,      /* BS_3STATE */
32     BUTTON_3STATE,      /* BS_AUTO3STATE */
33     BUTTON_UNCHECKED,   /* BS_GROUPBOX */
34     BUTTON_UNCHECKED,   /* BS_USERBUTTON */
35     BUTTON_CHECKED,     /* BS_AUTORADIOBUTTON */
36     BUTTON_UNCHECKED,   /* Not defined */
37     BUTTON_UNCHECKED    /* BS_OWNERDRAW */
38 };
39
40 typedef void (*pfPaint)( WND *wndPtr, HDC32 hdc, WORD action );
41
42 static const pfPaint btnPaintFunc[MAX_BTN_TYPE] =
43 {
44     PB_Paint,    /* BS_PUSHBUTTON */
45     PB_Paint,    /* BS_DEFPUSHBUTTON */
46     CB_Paint,    /* BS_CHECKBOX */
47     CB_Paint,    /* BS_AUTOCHECKBOX */
48     CB_Paint,    /* BS_RADIOBUTTON */
49     CB_Paint,    /* BS_3STATE */
50     CB_Paint,    /* BS_AUTO3STATE */
51     GB_Paint,    /* BS_GROUPBOX */
52     UB_Paint,    /* BS_USERBUTTON */
53     CB_Paint,    /* BS_AUTORADIOBUTTON */
54     NULL,        /* Not defined */
55     OB_Paint     /* BS_OWNERDRAW */
56 };
57
58 #define PAINT_BUTTON(wndPtr,style,action) \
59      if (btnPaintFunc[style]) { \
60          HDC32 hdc = GetDC32( (wndPtr)->hwndSelf ); \
61          (btnPaintFunc[style])(wndPtr,hdc,action); \
62          ReleaseDC32( (wndPtr)->hwndSelf, hdc ); }
63
64 #define BUTTON_SEND_CTLCOLOR(wndPtr,hdc) \
65     SendMessage32A( GetParent32((wndPtr)->hwndSelf), WM_CTLCOLORBTN, \
66                     (hdc), (wndPtr)->hwndSelf )
67
68 static HBITMAP32 hbitmapCheckBoxes = 0;
69 static WORD checkBoxWidth = 0, checkBoxHeight = 0;
70
71
72 /***********************************************************************
73  *           ButtonWndProc
74  */
75 LRESULT WINAPI ButtonWndProc( HWND32 hWnd, UINT32 uMsg,
76                               WPARAM32 wParam, LPARAM lParam )
77 {
78     RECT32 rect;
79     POINT32 pt = { LOWORD(lParam), HIWORD(lParam) };
80     WND *wndPtr = WIN_FindWndPtr(hWnd);
81     BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
82     LONG style = wndPtr->dwStyle & 0x0f;
83
84     switch (uMsg)
85     {
86     case WM_GETDLGCODE:
87         switch(style)
88         {
89         case BS_PUSHBUTTON:      return DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON;
90         case BS_DEFPUSHBUTTON:   return DLGC_BUTTON | DLGC_DEFPUSHBUTTON;
91         case BS_RADIOBUTTON:
92         case BS_AUTORADIOBUTTON: return DLGC_BUTTON | DLGC_RADIOBUTTON;
93         default:                 return DLGC_BUTTON;
94         }
95
96     case WM_ENABLE:
97         PAINT_BUTTON( wndPtr, style, ODA_DRAWENTIRE );
98         break;
99
100     case WM_CREATE:
101         if (!hbitmapCheckBoxes)
102         {
103             BITMAP32 bmp;
104             hbitmapCheckBoxes = LoadBitmap32A(0, MAKEINTRESOURCE32A(OBM_CHECKBOXES));
105             GetObject32A( hbitmapCheckBoxes, sizeof(bmp), &bmp );
106             checkBoxWidth  = bmp.bmWidth / 4;
107             checkBoxHeight = bmp.bmHeight / 3;
108         }
109         if (style < 0L || style >= MAX_BTN_TYPE) return -1; /* abort */
110         infoPtr->state = BUTTON_UNCHECKED;
111         infoPtr->hFont = 0;
112         return 0;
113
114     case WM_ERASEBKGND:
115         return 1;
116
117     case WM_PAINT:
118         if (btnPaintFunc[style])
119         {
120             PAINTSTRUCT32 ps;
121             HDC32 hdc = wParam ? (HDC32)wParam : BeginPaint32( hWnd, &ps );
122             SetBkMode32( hdc, OPAQUE );
123             (btnPaintFunc[style])( wndPtr, hdc, ODA_DRAWENTIRE );
124             if( !wParam ) EndPaint32( hWnd, &ps );
125         }
126         break;
127
128     case WM_LBUTTONDOWN:
129         SendMessage32A( hWnd, BM_SETSTATE32, TRUE, 0 );
130         SetFocus32( hWnd );
131         SetCapture32( hWnd );
132         break;
133
134     case WM_LBUTTONUP:
135         ReleaseCapture();
136         if (!(infoPtr->state & BUTTON_HIGHLIGHTED)) break;
137         SendMessage32A( hWnd, BM_SETSTATE32, FALSE, 0 );
138         GetClientRect32( hWnd, &rect );
139         if (PtInRect32( &rect, pt ))
140         {
141             switch(style)
142             {
143             case BS_AUTOCHECKBOX:
144                 SendMessage32A( hWnd, BM_SETCHECK32,
145                                 !(infoPtr->state & BUTTON_CHECKED), 0 );
146                 break;
147             case BS_AUTORADIOBUTTON:
148                 SendMessage32A( hWnd, BM_SETCHECK32, TRUE, 0 );
149                 break;
150             case BS_AUTO3STATE:
151                 SendMessage32A( hWnd, BM_SETCHECK32,
152                                 (infoPtr->state & BUTTON_3STATE) ? 0 :
153                                 ((infoPtr->state & 3) + 1), 0 );
154                 break;
155             }
156             SendMessage32A( GetParent32(hWnd), WM_COMMAND,
157                             MAKEWPARAM( wndPtr->wIDmenu, BN_CLICKED ), hWnd);
158         }
159         break;
160
161     case WM_MOUSEMOVE:
162         if (GetCapture32() == hWnd)
163         {
164             GetClientRect32( hWnd, &rect );
165             SendMessage32A( hWnd, BM_SETSTATE32, PtInRect32(&rect, pt), 0 );
166         }
167         break;
168
169     case WM_NCHITTEST:
170         if(style == BS_GROUPBOX) return HTTRANSPARENT;
171         return DefWindowProc32A( hWnd, uMsg, wParam, lParam );
172
173     case WM_SETTEXT:
174         DEFWND_SetText( wndPtr, (LPCSTR)lParam );
175         if( wndPtr->dwStyle & WS_VISIBLE )
176             PAINT_BUTTON( wndPtr, style, ODA_DRAWENTIRE );
177         return 0;
178
179     case WM_SETFONT:
180         infoPtr->hFont = (HFONT16)wParam;
181         if (lParam && (wndPtr->dwStyle & WS_VISIBLE)) 
182             PAINT_BUTTON( wndPtr, style, ODA_DRAWENTIRE );
183         break;
184
185     case WM_GETFONT:
186         return infoPtr->hFont;
187
188     case WM_SETFOCUS:
189         infoPtr->state |= BUTTON_HASFOCUS;
190         if (style == BS_AUTORADIOBUTTON)
191         {
192             SendMessage32A( hWnd, BM_SETCHECK32, 1, 0 );
193         }
194         PAINT_BUTTON( wndPtr, style, ODA_FOCUS );
195         break;
196
197     case WM_KILLFOCUS:
198         infoPtr->state &= ~BUTTON_HASFOCUS;
199         PAINT_BUTTON( wndPtr, style, ODA_FOCUS );
200         InvalidateRect32( hWnd, NULL, TRUE );
201         break;
202
203     case WM_SYSCOLORCHANGE:
204         InvalidateRect32( hWnd, NULL, FALSE );
205         break;
206
207     case BM_SETSTYLE16:
208     case BM_SETSTYLE32:
209         if ((wParam & 0x0f) >= MAX_BTN_TYPE) break;
210         wndPtr->dwStyle = (wndPtr->dwStyle & 0xfffffff0) 
211                            | (wParam & 0x0000000f);
212         style = wndPtr->dwStyle & 0x0000000f;
213         PAINT_BUTTON( wndPtr, style, ODA_DRAWENTIRE );
214         break;
215
216     case BM_GETCHECK16:
217     case BM_GETCHECK32:
218         return infoPtr->state & 3;
219
220     case BM_SETCHECK16:
221     case BM_SETCHECK32:
222         if (wParam > maxCheckState[style]) wParam = maxCheckState[style];
223         if ((infoPtr->state & 3) != wParam)
224         {
225             if ((style == BS_RADIOBUTTON) || (style == BS_AUTORADIOBUTTON))
226             {
227                 if (wParam)
228                     wndPtr->dwStyle |= WS_TABSTOP;
229                 else
230                     wndPtr->dwStyle &= ~WS_TABSTOP;
231             }
232             infoPtr->state = (infoPtr->state & ~3) | wParam;
233             PAINT_BUTTON( wndPtr, style, ODA_SELECT );
234         }
235         if ((style == BS_AUTORADIOBUTTON) && (wParam == BUTTON_CHECKED))
236             BUTTON_CheckAutoRadioButton( wndPtr );
237         break;
238
239     case BM_GETSTATE16:
240     case BM_GETSTATE32:
241         return infoPtr->state;
242
243     case BM_SETSTATE16:
244     case BM_SETSTATE32:
245         if (wParam)
246         {
247             if (infoPtr->state & BUTTON_HIGHLIGHTED) break;
248             infoPtr->state |= BUTTON_HIGHLIGHTED;
249         }
250         else
251         {
252             if (!(infoPtr->state & BUTTON_HIGHLIGHTED)) break;
253             infoPtr->state &= ~BUTTON_HIGHLIGHTED;
254         }
255         PAINT_BUTTON( wndPtr, style, ODA_SELECT );
256         break;
257
258     default:
259         return DefWindowProc32A(hWnd, uMsg, wParam, lParam);
260     }
261     return 0;
262 }
263
264
265 /**********************************************************************
266  *       Push Button Functions
267  */
268
269 static void PB_Paint( WND *wndPtr, HDC32 hDC, WORD action )
270 {
271     RECT32 rc;
272     HPEN32 hOldPen;
273     HBRUSH32 hOldBrush;
274     BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
275
276     GetClientRect32( wndPtr->hwndSelf, &rc );
277
278       /* Send WM_CTLCOLOR to allow changing the font (the colors are fixed) */
279     if (infoPtr->hFont) SelectObject32( hDC, infoPtr->hFont );
280     BUTTON_SEND_CTLCOLOR( wndPtr, hDC );
281     hOldPen = (HPEN32)SelectObject32(hDC, GetSysColorPen32(COLOR_WINDOWFRAME));
282     hOldBrush =(HBRUSH32)SelectObject32(hDC,GetSysColorBrush32(COLOR_BTNFACE));
283     SetBkMode32(hDC, TRANSPARENT);
284     Rectangle32(hDC, rc.left, rc.top, rc.right, rc.bottom);
285     if (action == ODA_DRAWENTIRE)
286     {
287         SetPixel32( hDC, rc.left, rc.top, GetSysColor32(COLOR_WINDOW) );
288         SetPixel32( hDC, rc.left, rc.bottom-1, GetSysColor32(COLOR_WINDOW) );
289         SetPixel32( hDC, rc.right-1, rc.top, GetSysColor32(COLOR_WINDOW) );
290         SetPixel32( hDC, rc.right-1, rc.bottom-1, GetSysColor32(COLOR_WINDOW));
291     }
292     InflateRect32( &rc, -1, -1 );
293
294     if ((wndPtr->dwStyle & 0x000f) == BS_DEFPUSHBUTTON)
295     {
296         Rectangle32(hDC, rc.left, rc.top, rc.right, rc.bottom);
297         InflateRect32( &rc, -1, -1 );
298     }
299
300     if (infoPtr->state & BUTTON_HIGHLIGHTED)
301     {
302         /* draw button shadow: */
303         SelectObject32(hDC, GetSysColorBrush32(COLOR_BTNSHADOW));
304         PatBlt32(hDC, rc.left, rc.top, 1, rc.bottom-rc.top, PATCOPY );
305         PatBlt32(hDC, rc.left, rc.top, rc.right-rc.left, 1, PATCOPY );
306         rc.left += 2;  /* To position the text down and right */
307         rc.top  += 2;
308     }
309     else GRAPH_DrawReliefRect( hDC, &rc, 2, 2, FALSE );
310     
311     /* draw button label, if any: */
312     if (wndPtr->text && wndPtr->text[0])
313     {
314         LOGBRUSH32 lb;
315         GetObject32A( GetSysColorBrush32(COLOR_BTNFACE), sizeof(lb), &lb );
316         if (wndPtr->dwStyle & WS_DISABLED &&
317             GetSysColor32(COLOR_GRAYTEXT)==lb.lbColor)
318             /* don't write gray text on gray bkg */
319             PB_PaintGrayOnGray(hDC,infoPtr->hFont,&rc,wndPtr->text);
320         else
321         {
322             SetTextColor32( hDC, (wndPtr->dwStyle & WS_DISABLED) ?
323                                  GetSysColor32(COLOR_GRAYTEXT) :
324                                  GetSysColor32(COLOR_BTNTEXT) );
325             DrawText32A( hDC, wndPtr->text, -1, &rc,
326                          DT_SINGLELINE | DT_CENTER | DT_VCENTER );
327             /* do we have the focus? */
328             if (infoPtr->state & BUTTON_HASFOCUS)
329             {
330                 RECT32 r = { 0, 0, 0, 0 };
331                 INT32 xdelta, ydelta;
332
333                 DrawText32A( hDC, wndPtr->text, -1, &r,
334                              DT_SINGLELINE | DT_CALCRECT );
335                 xdelta = ((rc.right - rc.left) - (r.right - r.left) - 1) / 2;
336                 ydelta = ((rc.bottom - rc.top) - (r.bottom - r.top) - 1) / 2;
337                 if (xdelta < 0) xdelta = 0;
338                 if (ydelta < 0) ydelta = 0;
339                 InflateRect32( &rc, -xdelta, -ydelta );
340                 DrawFocusRect32( hDC, &rc );
341             }
342         }   
343     }
344
345     SelectObject32( hDC, hOldPen );
346     SelectObject32( hDC, hOldBrush );
347 }
348
349
350 /**********************************************************************
351  *   Push Button sub function                               [internal]
352  *   using a raster brush to avoid gray text on gray background
353  */
354
355 void PB_PaintGrayOnGray(HDC32 hDC,HFONT32 hFont,RECT32 *rc,char *text)
356 {
357     static const int Pattern[] = {0xAA,0x55,0xAA,0x55,0xAA,0x55,0xAA,0x55};
358     HBITMAP32 hbm  = CreateBitmap32( 8, 8, 1, 1, Pattern );
359     HDC32 hdcMem = CreateCompatibleDC32(hDC);
360     HBITMAP32 hbmMem;
361     HBRUSH32 hBr;
362     RECT32 rect,rc2;
363
364     rect=*rc;
365     DrawText32A( hDC, text, -1, &rect, DT_SINGLELINE | DT_CALCRECT);
366     rc2=rect;
367     rect.left=(rc->right-rect.right)/2;       /* for centering text bitmap */
368     rect.top=(rc->bottom-rect.bottom)/2;
369     hbmMem = CreateCompatibleBitmap32( hDC,rect.right,rect.bottom );
370     SelectObject32( hdcMem, hbmMem);
371     hBr = SelectObject32( hdcMem, CreatePatternBrush32(hbm) );
372     DeleteObject32( hbm );
373     PatBlt32( hdcMem,0,0,rect.right,rect.bottom,WHITENESS);
374     if (hFont) SelectObject32( hdcMem, hFont);
375     DrawText32A( hdcMem, text, -1, &rc2, DT_SINGLELINE);  
376     PatBlt32( hdcMem,0,0,rect.right,rect.bottom,0xFA0089);
377     DeleteObject32( SelectObject32( hdcMem,hBr) );
378     BitBlt32(hDC,rect.left,rect.top,rect.right,rect.bottom,hdcMem,0,0,0x990000);
379     DeleteDC32( hdcMem);
380     DeleteObject32( hbmMem );
381 }
382
383
384 /**********************************************************************
385  *       Check Box & Radio Button Functions
386  */
387
388 static void CB_Paint( WND *wndPtr, HDC32 hDC, WORD action )
389 {
390     RECT32 rbox, rtext, client;
391     HBRUSH32 hBrush;
392     int textlen, delta;
393     BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
394
395     textlen = 0;
396     GetClientRect32(wndPtr->hwndSelf, &client);
397     rbox = rtext = client;
398
399     if (infoPtr->hFont) SelectObject32( hDC, infoPtr->hFont );
400
401     /* Something is still not right, checkboxes (and edit controls)
402      * in wsping32 have white backgrounds instead of dark grey.
403      * BUTTON_SEND_CTLCOLOR() is even worse since it returns 0 in this
404      * particular case and the background is not painted at all.
405      */
406
407     hBrush = GetControlBrush( wndPtr->hwndSelf, hDC, CTLCOLOR_BTN );
408
409     if (wndPtr->dwStyle & BS_LEFTTEXT) 
410     {
411         /* magic +4 is what CTL3D expects */
412
413         rtext.right -= checkBoxWidth + 4;
414         rbox.left = rbox.right - checkBoxWidth;
415     }
416     else 
417     {
418         rtext.left += checkBoxWidth + 4;
419         rbox.right = checkBoxWidth;
420     }
421
422       /* Draw the check-box bitmap */
423
424     if (wndPtr->text) textlen = strlen( wndPtr->text );
425     if (action == ODA_DRAWENTIRE || action == ODA_SELECT)
426     { 
427         int x = 0, y = 0;
428         delta = (rbox.bottom - rbox.top - checkBoxHeight) >> 1;
429
430         if (action == ODA_SELECT) FillRect32( hDC, &rbox, hBrush );
431         else FillRect32( hDC, &client, hBrush );
432
433         if (infoPtr->state & BUTTON_HIGHLIGHTED) x += 2 * checkBoxWidth;
434         if (infoPtr->state & (BUTTON_CHECKED | BUTTON_3STATE)) x += checkBoxWidth;
435         if (((wndPtr->dwStyle & 0x0f) == BS_RADIOBUTTON) ||
436             ((wndPtr->dwStyle & 0x0f) == BS_AUTORADIOBUTTON)) y += checkBoxHeight;
437         else if (infoPtr->state & BUTTON_3STATE) y += 2 * checkBoxHeight;
438
439         GRAPH_DrawBitmap( hDC, hbitmapCheckBoxes, rbox.left, rbox.top + delta,
440                           x, y, checkBoxWidth, checkBoxHeight, FALSE );
441         if( textlen && action != ODA_SELECT )
442         {
443             if (wndPtr->dwStyle & WS_DISABLED)
444                 SetTextColor32( hDC, GetSysColor32(COLOR_GRAYTEXT) );
445             DrawText32A( hDC, wndPtr->text, textlen, &rtext,
446                          DT_SINGLELINE | DT_VCENTER );
447             textlen = 0; /* skip DrawText() below */
448         }
449     }
450
451     if ((action == ODA_FOCUS) ||
452         ((action == ODA_DRAWENTIRE) && (infoPtr->state & BUTTON_HASFOCUS)))
453     {
454         /* again, this is what CTL3D expects */
455
456         SetRectEmpty32(&rbox);
457         if( textlen )
458             DrawText32A( hDC, wndPtr->text, textlen, &rbox,
459                          DT_SINGLELINE | DT_CALCRECT );
460         textlen = rbox.bottom - rbox.top;
461         delta = ((rtext.bottom - rtext.top) - textlen)/2;
462         rbox.bottom = (rbox.top = rtext.top + delta - 1) + textlen + 2;
463         textlen = rbox.right - rbox.left;
464         rbox.right = (rbox.left += --rtext.left) + textlen + 2;
465         IntersectRect32(&rbox, &rbox, &rtext);
466         DrawFocusRect32( hDC, &rbox );
467     }
468 }
469
470
471 /**********************************************************************
472  *       BUTTON_CheckAutoRadioButton
473  *
474  * wndPtr is checked, uncheck every other auto radio button in group
475  */
476 static void BUTTON_CheckAutoRadioButton( WND *wndPtr )
477 {
478     HWND32 parent, sibling, start;
479     if (!(wndPtr->dwStyle & WS_CHILD)) return;
480     parent = wndPtr->parent->hwndSelf;
481     /* assure that starting control is not disabled or invisible */
482     start = sibling = GetNextDlgGroupItem32( parent, wndPtr->hwndSelf, TRUE );
483     do
484     {
485         if (!sibling) break;
486         if ((wndPtr->hwndSelf != sibling) &&
487             ((WIN_FindWndPtr(sibling)->dwStyle & 0x0f) == BS_AUTORADIOBUTTON))
488             SendMessage32A( sibling, BM_SETCHECK32, BUTTON_UNCHECKED, 0 );
489         sibling = GetNextDlgGroupItem32( parent, sibling, FALSE );
490     } while (sibling != start);
491 }
492
493
494 /**********************************************************************
495  *       Group Box Functions
496  */
497
498 static void GB_Paint( WND *wndPtr, HDC32 hDC, WORD action )
499 {
500     RECT32 rc, rcFrame;
501     BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
502
503     if (action != ODA_DRAWENTIRE) return;
504
505     BUTTON_SEND_CTLCOLOR( wndPtr, hDC );
506
507     GetClientRect32( wndPtr->hwndSelf, &rc);
508     if (TWEAK_WineLook == WIN31_LOOK)
509         GRAPH_DrawRectangle( hDC, rc.left, rc.top + 2, rc.right - 1, rc.bottom - 1,
510                             GetSysColorPen32(COLOR_WINDOWFRAME) );
511     else {
512         TEXTMETRIC32A tm;
513         rcFrame = rc;
514
515         if (infoPtr->hFont)
516             SelectObject32 (hDC, infoPtr->hFont);
517         GetTextMetrics32A (hDC, &tm);
518         rcFrame.top += (tm.tmHeight / 2) - 1;
519         DrawEdge32 (hDC, &rcFrame, EDGE_ETCHED, BF_RECT);
520     }
521
522     if (wndPtr->text)
523     {
524         if (infoPtr->hFont) SelectObject32( hDC, infoPtr->hFont );
525         if (wndPtr->dwStyle & WS_DISABLED)
526             SetTextColor32( hDC, GetSysColor32(COLOR_GRAYTEXT) );
527         rc.left += 10;
528         DrawText32A( hDC, wndPtr->text, -1, &rc, DT_SINGLELINE | DT_NOCLIP );
529     }
530 }
531
532
533 /**********************************************************************
534  *       User Button Functions
535  */
536
537 static void UB_Paint( WND *wndPtr, HDC32 hDC, WORD action )
538 {
539     RECT32 rc;
540     HBRUSH32 hBrush;
541     BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
542
543     if (action == ODA_SELECT) return;
544
545     GetClientRect32( wndPtr->hwndSelf, &rc);
546
547     if (infoPtr->hFont) SelectObject32( hDC, infoPtr->hFont );
548     hBrush = GetControlBrush( wndPtr->hwndSelf, hDC, CTLCOLOR_BTN );
549
550     FillRect32( hDC, &rc, hBrush );
551     if ((action == ODA_FOCUS) ||
552         ((action == ODA_DRAWENTIRE) && (infoPtr->state & BUTTON_HASFOCUS)))
553         DrawFocusRect32( hDC, &rc );
554 }
555
556
557 /**********************************************************************
558  *       Ownerdrawn Button Functions
559  */
560
561 static void OB_Paint( WND *wndPtr, HDC32 hDC, WORD action )
562 {
563     BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
564     DRAWITEMSTRUCT32 dis;
565
566     dis.CtlType    = ODT_BUTTON;
567     dis.CtlID      = wndPtr->wIDmenu;
568     dis.itemID     = 0;
569     dis.itemAction = action;
570     dis.itemState  = ((infoPtr->state & BUTTON_HASFOCUS) ? ODS_FOCUS : 0) |
571                      ((infoPtr->state & BUTTON_HIGHLIGHTED) ? ODS_SELECTED : 0) |
572                      ((wndPtr->dwStyle & WS_DISABLED) ? ODS_DISABLED : 0);
573     dis.hwndItem   = wndPtr->hwndSelf;
574     dis.hDC        = hDC;
575     dis.itemData   = 0;
576     GetClientRect32( wndPtr->hwndSelf, &dis.rcItem );
577     SendMessage32A( GetParent32(wndPtr->hwndSelf), WM_DRAWITEM,
578                     wndPtr->wIDmenu, (LPARAM)&dis );
579 }