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
11 #include "wine/winuser16.h"
14 static void PaintGrayOnGray( HDC hDC
,HFONT hFont
,RECT
*rc
,
15 char *text
, UINT format
);
17 static void PB_Paint( WND
*wndPtr
, HDC hDC
, WORD action
);
18 static void CB_Paint( WND
*wndPtr
, HDC hDC
, WORD action
);
19 static void GB_Paint( WND
*wndPtr
, HDC hDC
, WORD action
);
20 static void UB_Paint( WND
*wndPtr
, HDC hDC
, WORD action
);
21 static void OB_Paint( WND
*wndPtr
, HDC hDC
, WORD action
);
22 static void BUTTON_CheckAutoRadioButton( WND
*wndPtr
);
23 static void BUTTON_DrawPushButton( WND
*wndPtr
, HDC hDC
, WORD action
, BOOL pushedState
);
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
)
84 HWND hWnd
= wndPtr
->hwndSelf
;
86 BUTTONINFO
*infoPtr
= (BUTTONINFO
*)wndPtr
->wExtra
;
87 LONG style
= wndPtr
->dwStyle
& 0x0f;
90 pt
.x
= LOWORD(lParam
);
91 pt
.y
= HIWORD(lParam
);
98 case BS_PUSHBUTTON
: return DLGC_BUTTON
| DLGC_UNDEFPUSHBUTTON
;
99 case BS_DEFPUSHBUTTON
: return DLGC_BUTTON
| DLGC_DEFPUSHBUTTON
;
101 case BS_AUTORADIOBUTTON
: return DLGC_BUTTON
| DLGC_RADIOBUTTON
;
102 default: return DLGC_BUTTON
;
106 PAINT_BUTTON( wndPtr
, style
, ODA_DRAWENTIRE
);
110 if (!hbitmapCheckBoxes
)
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
;
122 infoPtr
->hImage
= NULL
;
129 if (btnPaintFunc
[style
])
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
);
139 case WM_LBUTTONDBLCLK
:
140 if(wndPtr
->dwStyle
& BS_NOTIFY
||
141 style
==BS_RADIOBUTTON
||
142 style
==BS_USERBUTTON
||
143 style
==BS_OWNERDRAW
){
144 SendMessageA( GetParent(hWnd
), WM_COMMAND
,
145 MAKEWPARAM( wndPtr
->wIDmenu
, BN_DOUBLECLICKED
), hWnd
);
152 SendMessageA( hWnd
, BM_SETSTATE
, TRUE
, 0 );
156 /* FIXME: real windows uses extra flags in the status for this */
157 if (GetCapture() != hWnd
) break;
159 if (!(infoPtr
->state
& BUTTON_HIGHLIGHTED
)) break;
160 SendMessageA( hWnd
, BM_SETSTATE
, FALSE
, 0 );
161 GetClientRect( hWnd
, &rect
);
162 if (PtInRect( &rect
, pt
))
166 case BS_AUTOCHECKBOX
:
167 SendMessageA( hWnd
, BM_SETCHECK
,
168 !(infoPtr
->state
& BUTTON_CHECKED
), 0 );
170 case BS_AUTORADIOBUTTON
:
171 SendMessageA( hWnd
, BM_SETCHECK
, TRUE
, 0 );
174 SendMessageA( hWnd
, BM_SETCHECK
,
175 (infoPtr
->state
& BUTTON_3STATE
) ? 0 :
176 ((infoPtr
->state
& 3) + 1), 0 );
179 SendMessageA( GetParent(hWnd
), WM_COMMAND
,
180 MAKEWPARAM( wndPtr
->wIDmenu
, BN_CLICKED
), hWnd
);
185 if (GetCapture() == hWnd
)
187 GetClientRect( hWnd
, &rect
);
188 SendMessageA( hWnd
, BM_SETSTATE
, PtInRect(&rect
, pt
), 0 );
193 if(style
== BS_GROUPBOX
) return HTTRANSPARENT
;
194 return DefWindowProcA( hWnd
, uMsg
, wParam
, lParam
);
197 DEFWND_SetText( wndPtr
, (LPCSTR
)lParam
);
198 if( wndPtr
->dwStyle
& WS_VISIBLE
)
199 PAINT_BUTTON( wndPtr
, style
, ODA_DRAWENTIRE
);
203 infoPtr
->hFont
= (HFONT16
)wParam
;
204 if (lParam
&& (wndPtr
->dwStyle
& WS_VISIBLE
))
205 PAINT_BUTTON( wndPtr
, style
, ODA_DRAWENTIRE
);
209 return infoPtr
->hFont
;
212 if ((style
== BS_AUTORADIOBUTTON
) && (GetCapture() != hWnd
) &&
213 !(SendMessageA(hWnd
, BM_GETCHECK
, 0, 0) & BST_CHECKED
))
215 /* The notification is sent when the button (BS_AUTORADIOBUTTON)
216 is unckecked and the focus was not given by a mouse click. */
217 SendMessageA( hWnd
, BM_SETCHECK
, TRUE
, 0 );
218 SendMessageA( GetParent(hWnd
), WM_COMMAND
,
219 MAKEWPARAM( wndPtr
->wIDmenu
, BN_CLICKED
), hWnd
);
221 infoPtr
->state
|= BUTTON_HASFOCUS
;
222 PAINT_BUTTON( wndPtr
, style
, ODA_FOCUS
);
226 infoPtr
->state
&= ~BUTTON_HASFOCUS
;
227 PAINT_BUTTON( wndPtr
, style
, ODA_FOCUS
);
228 InvalidateRect( hWnd
, NULL
, TRUE
);
231 case WM_SYSCOLORCHANGE
:
232 InvalidateRect( hWnd
, NULL
, FALSE
);
237 if ((wParam
& 0x0f) >= MAX_BTN_TYPE
) break;
238 wndPtr
->dwStyle
= (wndPtr
->dwStyle
& 0xfffffff0)
239 | (wParam
& 0x0000000f);
240 style
= wndPtr
->dwStyle
& 0x0000000f;
241 PAINT_BUTTON( wndPtr
, style
, ODA_DRAWENTIRE
);
245 oldHbitmap
= infoPtr
->hImage
;
246 if ((wndPtr
->dwStyle
& BS_BITMAP
) || (wndPtr
->dwStyle
& BS_ICON
))
247 infoPtr
->hImage
= (HANDLE
) lParam
;
251 if (wParam
== IMAGE_BITMAP
)
252 return (HBITMAP
)infoPtr
->hImage
;
253 else if (wParam
== IMAGE_ICON
)
254 return (HICON
)infoPtr
->hImage
;
260 return infoPtr
->state
& 3;
264 if (wParam
> maxCheckState
[style
]) wParam
= maxCheckState
[style
];
265 if ((infoPtr
->state
& 3) != wParam
)
267 if ((style
== BS_RADIOBUTTON
) || (style
== BS_AUTORADIOBUTTON
))
270 wndPtr
->dwStyle
|= WS_TABSTOP
;
272 wndPtr
->dwStyle
&= ~WS_TABSTOP
;
274 infoPtr
->state
= (infoPtr
->state
& ~3) | wParam
;
275 PAINT_BUTTON( wndPtr
, style
, ODA_SELECT
);
277 if ((style
== BS_AUTORADIOBUTTON
) && (wParam
== BUTTON_CHECKED
))
278 BUTTON_CheckAutoRadioButton( wndPtr
);
283 return infoPtr
->state
;
289 if (infoPtr
->state
& BUTTON_HIGHLIGHTED
) break;
290 infoPtr
->state
|= BUTTON_HIGHLIGHTED
;
294 if (!(infoPtr
->state
& BUTTON_HIGHLIGHTED
)) break;
295 infoPtr
->state
&= ~BUTTON_HIGHLIGHTED
;
297 PAINT_BUTTON( wndPtr
, style
, ODA_SELECT
);
301 return DefWindowProcA(hWnd
, uMsg
, wParam
, lParam
);
306 /***********************************************************************
308 * The button window procedure. This is just a wrapper which locks
309 * the passed HWND and calls the real window procedure (with a WND*
310 * pointer pointing to the locked windowstructure).
312 LRESULT WINAPI
ButtonWndProc( HWND hWnd
, UINT uMsg
,
313 WPARAM wParam
, LPARAM lParam
)
316 WND
*wndPtr
= WIN_FindWndPtr(hWnd
);
318 res
= ButtonWndProc_locked(wndPtr
,uMsg
,wParam
,lParam
);
320 WIN_ReleaseWndPtr(wndPtr
);
324 /**********************************************************************
325 * Push Button Functions
327 static void PB_Paint( WND
*wndPtr
, HDC hDC
, WORD action
)
329 BUTTONINFO
*infoPtr
= (BUTTONINFO
*)wndPtr
->wExtra
;
330 BOOL bHighLighted
= (infoPtr
->state
& BUTTON_HIGHLIGHTED
);
333 * Delegate this to the more generic pushbutton painting
336 BUTTON_DrawPushButton(wndPtr
,
342 /**********************************************************************
343 * This method will actually do the drawing of the pushbutton
344 * depending on it's state and the pushedState parameter.
346 static void BUTTON_DrawPushButton(
355 BUTTONINFO
*infoPtr
= (BUTTONINFO
*)wndPtr
->wExtra
;
356 int xBorderOffset
, yBorderOffset
;
357 xBorderOffset
= yBorderOffset
= 0;
359 GetClientRect( wndPtr
->hwndSelf
, &rc
);
361 /* Send WM_CTLCOLOR to allow changing the font (the colors are fixed) */
362 if (infoPtr
->hFont
) SelectObject( hDC
, infoPtr
->hFont
);
363 BUTTON_SEND_CTLCOLOR( wndPtr
, hDC
);
364 hOldPen
= (HPEN
)SelectObject(hDC
, GetSysColorPen(COLOR_WINDOWFRAME
));
365 hOldBrush
=(HBRUSH
)SelectObject(hDC
,GetSysColorBrush(COLOR_BTNFACE
));
366 SetBkMode(hDC
, TRANSPARENT
);
368 if ( TWEAK_WineLook
== WIN31_LOOK
)
370 Rectangle(hDC
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
372 SetPixel( hDC
, rc
.left
, rc
.top
, GetSysColor(COLOR_WINDOW
) );
373 SetPixel( hDC
, rc
.left
, rc
.bottom
-1, GetSysColor(COLOR_WINDOW
) );
374 SetPixel( hDC
, rc
.right
-1, rc
.top
, GetSysColor(COLOR_WINDOW
) );
375 SetPixel( hDC
, rc
.right
-1, rc
.bottom
-1, GetSysColor(COLOR_WINDOW
));
376 InflateRect( &rc
, -1, -1 );
379 if ((wndPtr
->dwStyle
& 0x000f) == BS_DEFPUSHBUTTON
)
381 Rectangle(hDC
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
382 InflateRect( &rc
, -1, -1 );
385 if (TWEAK_WineLook
== WIN31_LOOK
)
389 /* draw button shadow: */
390 SelectObject(hDC
, GetSysColorBrush(COLOR_BTNSHADOW
));
391 PatBlt(hDC
, rc
.left
, rc
.top
, 1, rc
.bottom
-rc
.top
, PATCOPY
);
392 PatBlt(hDC
, rc
.left
, rc
.top
, rc
.right
-rc
.left
, 1, PATCOPY
);
393 rc
.left
+= 2; /* To position the text down and right */
396 rc
.right
++, rc
.bottom
++;
397 DrawEdge( hDC
, &rc
, EDGE_RAISED
, BF_RECT
);
399 /* To place de bitmap correctly */
400 xBorderOffset
+= GetSystemMetrics(SM_CXEDGE
);
401 yBorderOffset
+= GetSystemMetrics(SM_CYEDGE
);
403 rc
.right
--, rc
.bottom
--;
408 UINT uState
= DFCS_BUTTONPUSH
;
412 if ( (wndPtr
->dwStyle
& 0x000f) == BS_DEFPUSHBUTTON
)
415 uState
|= DFCS_PUSHED
;
418 DrawFrameControl( hDC
, &rc
, DFC_BUTTON
, uState
);
419 InflateRect( &rc
, -2, -2 );
425 rc
.left
+= 2; /* To position the text down and right */
430 /* draw button label, if any:
432 * In win9x we don't show text if there is a bitmap or icon.
433 * I don't know about win31 so I leave it as it was for win31.
434 * Dennis Björklund 12 Jul, 99
436 if ( wndPtr
->text
&& wndPtr
->text
[0]
437 && (TWEAK_WineLook
== WIN31_LOOK
|| !(wndPtr
->dwStyle
& (BS_ICON
|BS_BITMAP
))) )
440 GetObjectA( GetSysColorBrush(COLOR_BTNFACE
), sizeof(lb
), &lb
);
441 if (wndPtr
->dwStyle
& WS_DISABLED
&&
442 GetSysColor(COLOR_GRAYTEXT
)==lb
.lbColor
)
443 /* don't write gray text on gray background */
444 PaintGrayOnGray( hDC
,infoPtr
->hFont
,&rc
,wndPtr
->text
,
445 DT_CENTER
| DT_VCENTER
);
448 SetTextColor( hDC
, (wndPtr
->dwStyle
& WS_DISABLED
) ?
449 GetSysColor(COLOR_GRAYTEXT
) :
450 GetSysColor(COLOR_BTNTEXT
) );
451 DrawTextA( hDC
, wndPtr
->text
, -1, &rc
,
452 DT_SINGLELINE
| DT_CENTER
| DT_VCENTER
);
453 /* do we have the focus?
454 * Win9x draws focus last with a size prop. to the button
456 if (TWEAK_WineLook
== WIN31_LOOK
457 && infoPtr
->state
& BUTTON_HASFOCUS
)
459 RECT r
= { 0, 0, 0, 0 };
462 DrawTextA( hDC
, wndPtr
->text
, -1, &r
,
463 DT_SINGLELINE
| DT_CALCRECT
);
464 xdelta
= ((rc
.right
- rc
.left
) - (r
.right
- r
.left
) - 1) / 2;
465 ydelta
= ((rc
.bottom
- rc
.top
) - (r
.bottom
- r
.top
) - 1) / 2;
466 if (xdelta
< 0) xdelta
= 0;
467 if (ydelta
< 0) ydelta
= 0;
468 InflateRect( &rc
, -xdelta
, -ydelta
);
469 DrawFocusRect( hDC
, &rc
);
473 if ( ((wndPtr
->dwStyle
& BS_ICON
) || (wndPtr
->dwStyle
& BS_BITMAP
) ) &&
474 (infoPtr
->hImage
!= NULL
) )
476 int yOffset
, xOffset
;
477 int imageWidth
, imageHeight
;
480 * We extract the size of the image from the handle.
482 if (wndPtr
->dwStyle
& BS_ICON
)
487 GetIconInfo((HICON
)infoPtr
->hImage
, &iconInfo
);
488 GetObjectA (iconInfo
.hbmColor
, sizeof(BITMAP
), &bm
);
490 imageWidth
= bm
.bmWidth
;
491 imageHeight
= bm
.bmHeight
;
493 DeleteObject(iconInfo
.hbmColor
);
494 DeleteObject(iconInfo
.hbmMask
);
501 GetObjectA (infoPtr
->hImage
, sizeof(BITMAP
), &bm
);
503 imageWidth
= bm
.bmWidth
;
504 imageHeight
= bm
.bmHeight
;
507 /* Center the bitmap */
508 xOffset
= (((rc
.right
- rc
.left
) - 2*xBorderOffset
) - imageWidth
) / 2;
509 yOffset
= (((rc
.bottom
- rc
.top
) - 2*yBorderOffset
) - imageHeight
) / 2;
511 /* If the image is too big for the button then create a region*/
512 if(xOffset
< 0 || yOffset
< 0)
514 HRGN hBitmapRgn
= NULL
;
515 hBitmapRgn
= CreateRectRgn(
516 rc
.left
+ xBorderOffset
, rc
.top
+yBorderOffset
,
517 rc
.right
- xBorderOffset
, rc
.bottom
- yBorderOffset
);
518 SelectClipRgn(hDC
, hBitmapRgn
);
519 DeleteObject(hBitmapRgn
);
522 /* Let minimum 1 space from border */
523 xOffset
++, yOffset
++;
526 * Draw the image now.
528 if (wndPtr
->dwStyle
& BS_ICON
)
531 rc
.left
+ xOffset
, rc
.top
+ yOffset
,
532 (HICON
)infoPtr
->hImage
);
538 hdcMem
= CreateCompatibleDC (hDC
);
539 SelectObject (hdcMem
, (HBITMAP
)infoPtr
->hImage
);
543 imageWidth
, imageHeight
,
544 hdcMem
, 0, 0, SRCCOPY
);
549 if(xOffset
< 0 || yOffset
< 0)
551 SelectClipRgn(hDC
, NULL
);
555 if (TWEAK_WineLook
!= WIN31_LOOK
556 && infoPtr
->state
& BUTTON_HASFOCUS
)
558 InflateRect( &focus_rect
, -1, -1 );
559 DrawFocusRect( hDC
, &focus_rect
);
563 SelectObject( hDC
, hOldPen
);
564 SelectObject( hDC
, hOldBrush
);
568 /**********************************************************************
569 * PB_Paint & CB_Paint sub function [internal]
570 * Paint text using a raster brush to avoid gray text on gray
571 * background. 'format' can be a combination of DT_CENTER and
572 * DT_VCENTER to use this function in both PB_PAINT and
573 * CB_PAINT. - Dirk Thierbach
575 * FIXME: This and TEXT_GrayString should be eventually combined,
576 * so calling one common function from PB_Paint, CB_Paint and
577 * TEXT_GrayString will be enough. Also note that this
578 * function ignores the CACHE_GetPattern funcs.
581 void PaintGrayOnGray(HDC hDC
,HFONT hFont
,RECT
*rc
,char *text
,
584 /* This is the standard gray on gray pattern:
585 static const WORD Pattern[] = {0xAA,0x55,0xAA,0x55,0xAA,0x55,0xAA,0x55};
587 /* This pattern gives better readability with X Fonts.
588 FIXME: Maybe the user should be allowed to decide which he wants. */
589 static const WORD Pattern
[] = {0x55,0xFF,0xAA,0xFF,0x55,0xFF,0xAA,0xFF};
591 HBITMAP hbm
= CreateBitmap( 8, 8, 1, 1, Pattern
);
592 HDC hdcMem
= CreateCompatibleDC(hDC
);
598 DrawTextA( hDC
, text
, -1, &rect
, DT_SINGLELINE
| DT_CALCRECT
);
599 /* now text width and height are in rect.right and rect.bottom */
601 rect
.left
= rect
.top
= 0; /* drawing pos in hdcMem */
602 if (format
& DT_CENTER
) rect
.left
=(rc
->right
-rect
.right
)/2;
603 if (format
& DT_VCENTER
) rect
.top
=(rc
->bottom
-rect
.bottom
)/2;
604 hbmMem
= CreateCompatibleBitmap( hDC
,rect
.right
,rect
.bottom
);
605 SelectObject( hdcMem
, hbmMem
);
606 PatBlt( hdcMem
,0,0,rect
.right
,rect
.bottom
,WHITENESS
);
607 /* will be overwritten by DrawText, but just in case */
608 if (hFont
) SelectObject( hdcMem
, hFont
);
609 DrawTextA( hdcMem
, text
, -1, &rc2
, DT_SINGLELINE
);
610 /* After draw: foreground = 0 bits, background = 1 bits */
611 hBr
= SelectObject( hdcMem
, CreatePatternBrush(hbm
) );
613 PatBlt( hdcMem
,0,0,rect
.right
,rect
.bottom
,0xAF0229);
614 /* only keep the foreground bits where pattern is 1 */
615 DeleteObject( SelectObject( hdcMem
,hBr
) );
616 BitBlt(hDC
,rect
.left
,rect
.top
,rect
.right
,rect
.bottom
,hdcMem
,0,0,SRCAND
);
617 /* keep the background of the dest */
619 DeleteObject( hbmMem
);
623 /**********************************************************************
624 * Check Box & Radio Button Functions
627 static void CB_Paint( WND
*wndPtr
, HDC hDC
, WORD action
)
629 RECT rbox
, rtext
, client
;
632 BUTTONINFO
*infoPtr
= (BUTTONINFO
*)wndPtr
->wExtra
;
635 * if the button has a bitmap/icon, draw a normal pushbutton
636 * instead of a radion button.
638 if (infoPtr
->hImage
!=NULL
)
640 BOOL bHighLighted
= ((infoPtr
->state
& BUTTON_HIGHLIGHTED
) ||
641 (infoPtr
->state
& BUTTON_CHECKED
));
643 BUTTON_DrawPushButton(wndPtr
,
651 GetClientRect(wndPtr
->hwndSelf
, &client
);
652 rbox
= rtext
= client
;
654 if (infoPtr
->hFont
) SelectObject( hDC
, infoPtr
->hFont
);
656 /* Something is still not right, checkboxes (and edit controls)
657 * in wsping32 have white backgrounds instead of dark grey.
658 * BUTTON_SEND_CTLCOLOR() is even worse since it returns 0 in this
659 * particular case and the background is not painted at all.
662 hBrush
= GetControlBrush16( wndPtr
->hwndSelf
, hDC
, CTLCOLOR_BTN
);
664 if (wndPtr
->dwStyle
& BS_LEFTTEXT
)
666 /* magic +4 is what CTL3D expects */
668 rtext
.right
-= checkBoxWidth
+ 4;
669 rbox
.left
= rbox
.right
- checkBoxWidth
;
673 rtext
.left
+= checkBoxWidth
+ 4;
674 rbox
.right
= checkBoxWidth
;
677 /* Draw the check-box bitmap */
679 if (wndPtr
->text
) textlen
= strlen( wndPtr
->text
);
680 if (action
== ODA_DRAWENTIRE
|| action
== ODA_SELECT
)
682 if( TWEAK_WineLook
== WIN31_LOOK
)
684 HDC hMemDC
= CreateCompatibleDC( hDC
);
686 delta
= (rbox
.bottom
- rbox
.top
- checkBoxHeight
) / 2;
688 /* Check in case the client area is smaller than the checkbox bitmap */
689 if (delta
< 0) delta
= 0;
691 if (action
== ODA_SELECT
) FillRect( hDC
, &rbox
, hBrush
);
692 else FillRect( hDC
, &client
, hBrush
);
694 if (infoPtr
->state
& BUTTON_HIGHLIGHTED
) x
+= 2 * checkBoxWidth
;
695 if (infoPtr
->state
& (BUTTON_CHECKED
| BUTTON_3STATE
)) x
+= checkBoxWidth
;
696 if (((wndPtr
->dwStyle
& 0x0f) == BS_RADIOBUTTON
) ||
697 ((wndPtr
->dwStyle
& 0x0f) == BS_AUTORADIOBUTTON
)) y
+= checkBoxHeight
;
698 else if (infoPtr
->state
& BUTTON_3STATE
) y
+= 2 * checkBoxHeight
;
700 /* The bitmap for the radio button is not aligned with the
701 * left of the window, it is 1 pixel off. */
702 if (((wndPtr
->dwStyle
& 0x0f) == BS_RADIOBUTTON
) ||
703 ((wndPtr
->dwStyle
& 0x0f) == BS_AUTORADIOBUTTON
))
706 SelectObject( hMemDC
, hbitmapCheckBoxes
);
707 BitBlt( hDC
, rbox
.left
, rbox
.top
+ delta
, checkBoxWidth
,
708 checkBoxHeight
, hMemDC
, x
, y
, SRCCOPY
);
715 if (((wndPtr
->dwStyle
& 0x0f) == BS_RADIOBUTTON
) ||
716 ((wndPtr
->dwStyle
& 0x0f) == BS_AUTORADIOBUTTON
)) state
= DFCS_BUTTONRADIO
;
717 else if (infoPtr
->state
& BUTTON_3STATE
) state
= DFCS_BUTTON3STATE
;
718 else state
= DFCS_BUTTONCHECK
;
720 if (infoPtr
->state
& (BUTTON_CHECKED
| BUTTON_3STATE
)) state
|= DFCS_CHECKED
;
722 if (infoPtr
->state
& BUTTON_HIGHLIGHTED
) state
|= DFCS_PUSHED
;
724 if (wndPtr
->dwStyle
& WS_DISABLED
) state
|= DFCS_INACTIVE
;
726 DrawFrameControl( hDC
, &rbox
, DFC_BUTTON
, state
);
730 if( textlen
&& action
!= ODA_SELECT
)
732 if (wndPtr
->dwStyle
& WS_DISABLED
&&
733 GetSysColor(COLOR_GRAYTEXT
)==GetBkColor(hDC
)) {
734 /* don't write gray text on gray background */
735 PaintGrayOnGray( hDC
, infoPtr
->hFont
, &rtext
, wndPtr
->text
,
738 if (wndPtr
->dwStyle
& WS_DISABLED
)
739 SetTextColor( hDC
, GetSysColor(COLOR_GRAYTEXT
) );
740 DrawTextA( hDC
, wndPtr
->text
, textlen
, &rtext
,
741 DT_SINGLELINE
| DT_VCENTER
);
746 if ((action
== ODA_FOCUS
) ||
747 ((action
== ODA_DRAWENTIRE
) && (infoPtr
->state
& BUTTON_HASFOCUS
)))
749 /* again, this is what CTL3D expects */
753 DrawTextA( hDC
, wndPtr
->text
, textlen
, &rbox
,
754 DT_SINGLELINE
| DT_CALCRECT
);
755 textlen
= rbox
.bottom
- rbox
.top
;
756 delta
= ((rtext
.bottom
- rtext
.top
) - textlen
)/2;
757 rbox
.bottom
= (rbox
.top
= rtext
.top
+ delta
- 1) + textlen
+ 2;
758 textlen
= rbox
.right
- rbox
.left
;
759 rbox
.right
= (rbox
.left
+= --rtext
.left
) + textlen
+ 2;
760 IntersectRect(&rbox
, &rbox
, &rtext
);
761 DrawFocusRect( hDC
, &rbox
);
766 /**********************************************************************
767 * BUTTON_CheckAutoRadioButton
769 * wndPtr is checked, uncheck every other auto radio button in group
771 static void BUTTON_CheckAutoRadioButton( WND
*wndPtr
)
773 HWND parent
, sibling
, start
;
774 if (!(wndPtr
->dwStyle
& WS_CHILD
)) return;
775 parent
= wndPtr
->parent
->hwndSelf
;
776 /* assure that starting control is not disabled or invisible */
777 start
= sibling
= GetNextDlgGroupItem( parent
, wndPtr
->hwndSelf
, TRUE
);
782 tmpWnd
= WIN_FindWndPtr(sibling
);
783 if ((wndPtr
->hwndSelf
!= sibling
) &&
784 ((tmpWnd
->dwStyle
& 0x0f) == BS_AUTORADIOBUTTON
))
785 SendMessageA( sibling
, BM_SETCHECK
, BUTTON_UNCHECKED
, 0 );
786 sibling
= GetNextDlgGroupItem( parent
, sibling
, FALSE
);
787 WIN_ReleaseWndPtr(tmpWnd
);
788 } while (sibling
!= start
);
792 /**********************************************************************
793 * Group Box Functions
796 static void GB_Paint( WND
*wndPtr
, HDC hDC
, WORD action
)
799 BUTTONINFO
*infoPtr
= (BUTTONINFO
*)wndPtr
->wExtra
;
801 if (action
!= ODA_DRAWENTIRE
) return;
803 BUTTON_SEND_CTLCOLOR( wndPtr
, hDC
);
805 GetClientRect( wndPtr
->hwndSelf
, &rc
);
806 if (TWEAK_WineLook
== WIN31_LOOK
) {
807 HPEN hPrevPen
= SelectObject( hDC
,
808 GetSysColorPen(COLOR_WINDOWFRAME
));
809 HBRUSH hPrevBrush
= SelectObject( hDC
,
810 GetStockObject(NULL_BRUSH
) );
812 Rectangle( hDC
, rc
.left
, rc
.top
+ 2, rc
.right
- 1, rc
.bottom
- 1 );
813 SelectObject( hDC
, hPrevBrush
);
814 SelectObject( hDC
, hPrevPen
);
820 SelectObject (hDC
, infoPtr
->hFont
);
821 GetTextMetricsA (hDC
, &tm
);
822 rcFrame
.top
+= (tm
.tmHeight
/ 2) - 1;
823 DrawEdge (hDC
, &rcFrame
, EDGE_ETCHED
, BF_RECT
);
828 if (infoPtr
->hFont
) SelectObject( hDC
, infoPtr
->hFont
);
829 if (wndPtr
->dwStyle
& WS_DISABLED
)
830 SetTextColor( hDC
, GetSysColor(COLOR_GRAYTEXT
) );
832 DrawTextA( hDC
, wndPtr
->text
, -1, &rc
, DT_SINGLELINE
| DT_NOCLIP
);
837 /**********************************************************************
838 * User Button Functions
841 static void UB_Paint( WND
*wndPtr
, HDC hDC
, WORD action
)
845 BUTTONINFO
*infoPtr
= (BUTTONINFO
*)wndPtr
->wExtra
;
847 if (action
== ODA_SELECT
) return;
849 GetClientRect( wndPtr
->hwndSelf
, &rc
);
851 if (infoPtr
->hFont
) SelectObject( hDC
, infoPtr
->hFont
);
852 hBrush
= GetControlBrush16( wndPtr
->hwndSelf
, hDC
, CTLCOLOR_BTN
);
854 FillRect( hDC
, &rc
, hBrush
);
855 if ((action
== ODA_FOCUS
) ||
856 ((action
== ODA_DRAWENTIRE
) && (infoPtr
->state
& BUTTON_HASFOCUS
)))
857 DrawFocusRect( hDC
, &rc
);
861 /**********************************************************************
862 * Ownerdrawn Button Functions
865 static void OB_Paint( WND
*wndPtr
, HDC hDC
, WORD action
)
867 BUTTONINFO
*infoPtr
= (BUTTONINFO
*)wndPtr
->wExtra
;
870 dis
.CtlType
= ODT_BUTTON
;
871 dis
.CtlID
= wndPtr
->wIDmenu
;
873 dis
.itemAction
= action
;
874 dis
.itemState
= ((infoPtr
->state
& BUTTON_HASFOCUS
) ? ODS_FOCUS
: 0) |
875 ((infoPtr
->state
& BUTTON_HIGHLIGHTED
) ? ODS_SELECTED
: 0) |
876 ((wndPtr
->dwStyle
& WS_DISABLED
) ? ODS_DISABLED
: 0);
877 dis
.hwndItem
= wndPtr
->hwndSelf
;
880 GetClientRect( wndPtr
->hwndSelf
, &dis
.rcItem
);
882 SetBkColor( hDC
, GetSysColor( COLOR_BTNFACE
) );
883 FillRect( hDC
, &dis
.rcItem
, GetSysColorBrush( COLOR_BTNFACE
) );
885 SendMessageA( GetParent(wndPtr
->hwndSelf
), WM_DRAWITEM
,
886 wndPtr
->wIDmenu
, (LPARAM
)&dis
);