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
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include "wine/winuser16.h"
32 /* GetWindowLong offsets for window extra information */
33 #define STATE_GWL_OFFSET 0
34 #define HFONT_GWL_OFFSET (sizeof(LONG))
35 #define HIMAGE_GWL_OFFSET (2*sizeof(LONG))
36 #define NB_EXTRA_BYTES (3*sizeof(LONG))
38 /* Button state values */
39 #define BUTTON_UNCHECKED 0x00
40 #define BUTTON_CHECKED 0x01
41 #define BUTTON_3STATE 0x02
42 #define BUTTON_HIGHLIGHTED 0x04
43 #define BUTTON_HASFOCUS 0x08
44 #define BUTTON_NSTATES 0x0F
45 /* undocumented flags */
46 #define BUTTON_BTNPRESSED 0x40
47 #define BUTTON_UNKNOWN2 0x20
48 #define BUTTON_UNKNOWN3 0x10
50 static void PB_Paint( HWND hwnd
, HDC hDC
, UINT action
);
51 static void CB_Paint( HWND hwnd
, HDC hDC
, UINT action
);
52 static void GB_Paint( HWND hwnd
, HDC hDC
, UINT action
);
53 static void UB_Paint( HWND hwnd
, HDC hDC
, UINT action
);
54 static void OB_Paint( HWND hwnd
, HDC hDC
, UINT action
);
55 static void BUTTON_CheckAutoRadioButton( HWND hwnd
);
56 static LRESULT WINAPI
ButtonWndProcA( HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
57 static LRESULT WINAPI
ButtonWndProcW( HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
59 #define MAX_BTN_TYPE 12
61 static const WORD maxCheckState
[MAX_BTN_TYPE
] =
63 BUTTON_UNCHECKED
, /* BS_PUSHBUTTON */
64 BUTTON_UNCHECKED
, /* BS_DEFPUSHBUTTON */
65 BUTTON_CHECKED
, /* BS_CHECKBOX */
66 BUTTON_CHECKED
, /* BS_AUTOCHECKBOX */
67 BUTTON_CHECKED
, /* BS_RADIOBUTTON */
68 BUTTON_3STATE
, /* BS_3STATE */
69 BUTTON_3STATE
, /* BS_AUTO3STATE */
70 BUTTON_UNCHECKED
, /* BS_GROUPBOX */
71 BUTTON_UNCHECKED
, /* BS_USERBUTTON */
72 BUTTON_CHECKED
, /* BS_AUTORADIOBUTTON */
73 BUTTON_UNCHECKED
, /* Not defined */
74 BUTTON_UNCHECKED
/* BS_OWNERDRAW */
77 typedef void (*pfPaint
)( HWND hwnd
, HDC hdc
, UINT action
);
79 static const pfPaint btnPaintFunc
[MAX_BTN_TYPE
] =
81 PB_Paint
, /* BS_PUSHBUTTON */
82 PB_Paint
, /* BS_DEFPUSHBUTTON */
83 CB_Paint
, /* BS_CHECKBOX */
84 CB_Paint
, /* BS_AUTOCHECKBOX */
85 CB_Paint
, /* BS_RADIOBUTTON */
86 CB_Paint
, /* BS_3STATE */
87 CB_Paint
, /* BS_AUTO3STATE */
88 GB_Paint
, /* BS_GROUPBOX */
89 UB_Paint
, /* BS_USERBUTTON */
90 CB_Paint
, /* BS_AUTORADIOBUTTON */
91 NULL
, /* Not defined */
92 OB_Paint
/* BS_OWNERDRAW */
95 static HBITMAP hbitmapCheckBoxes
= 0;
96 static WORD checkBoxWidth
= 0, checkBoxHeight
= 0;
99 /*********************************************************************
100 * button class descriptor
102 const struct builtin_class_descr BUTTON_builtin_class
=
105 CS_GLOBALCLASS
| CS_DBLCLKS
| CS_VREDRAW
| CS_HREDRAW
| CS_PARENTDC
, /* style */
106 ButtonWndProcA
, /* procA */
107 ButtonWndProcW
, /* procW */
108 NB_EXTRA_BYTES
, /* extra */
109 IDC_ARROWA
, /* cursor */
114 inline static LONG
get_button_state( HWND hwnd
)
116 return GetWindowLongA( hwnd
, STATE_GWL_OFFSET
);
119 inline static void set_button_state( HWND hwnd
, LONG state
)
121 SetWindowLongA( hwnd
, STATE_GWL_OFFSET
, state
);
124 inline static HFONT
get_button_font( HWND hwnd
)
126 return GetWindowLongA( hwnd
, HFONT_GWL_OFFSET
);
129 inline static void set_button_font( HWND hwnd
, HFONT font
)
131 SetWindowLongA( hwnd
, HFONT_GWL_OFFSET
, font
);
134 inline static UINT
get_button_type( LONG window_style
)
136 return (window_style
& 0x0f);
139 /* paint a button of any type */
140 inline static void paint_button( HWND hwnd
, LONG style
, UINT action
)
142 if (btnPaintFunc
[style
] && IsWindowVisible(hwnd
))
144 HDC hdc
= GetDC( hwnd
);
145 btnPaintFunc
[style
]( hwnd
, hdc
, action
);
146 ReleaseDC( hwnd
, hdc
);
150 /* retrieve the button text; returned buffer must be freed by caller */
151 inline static WCHAR
*get_button_text( HWND hwnd
)
153 INT len
= GetWindowTextLengthW( hwnd
);
154 WCHAR
*buffer
= HeapAlloc( GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
) );
155 if (buffer
) GetWindowTextW( hwnd
, buffer
, len
+ 1 );
159 /***********************************************************************
160 * ButtonWndProc_common
162 static LRESULT WINAPI
ButtonWndProc_common(HWND hWnd
, UINT uMsg
,
163 WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
167 LONG style
= GetWindowLongA( hWnd
, GWL_STYLE
);
168 UINT btn_type
= get_button_type( style
);
172 pt
.x
= LOWORD(lParam
);
173 pt
.y
= HIWORD(lParam
);
180 case BS_PUSHBUTTON
: return DLGC_BUTTON
| DLGC_UNDEFPUSHBUTTON
;
181 case BS_DEFPUSHBUTTON
: return DLGC_BUTTON
| DLGC_DEFPUSHBUTTON
;
183 case BS_AUTORADIOBUTTON
: return DLGC_BUTTON
| DLGC_RADIOBUTTON
;
184 default: return DLGC_BUTTON
;
188 paint_button( hWnd
, btn_type
, ODA_DRAWENTIRE
);
192 if (!hbitmapCheckBoxes
)
195 hbitmapCheckBoxes
= LoadBitmapW(0, MAKEINTRESOURCEW(OBM_CHECKBOXES
));
196 GetObjectW( hbitmapCheckBoxes
, sizeof(bmp
), &bmp
);
197 checkBoxWidth
= bmp
.bmWidth
/ 4;
198 checkBoxHeight
= bmp
.bmHeight
/ 3;
200 if (btn_type
< 0L || btn_type
>= MAX_BTN_TYPE
)
201 return -1; /* abort */
202 set_button_state( hWnd
, BUTTON_UNCHECKED
);
209 if (btnPaintFunc
[btn_type
])
212 HDC hdc
= wParam
? (HDC
)wParam
: BeginPaint( hWnd
, &ps
);
213 int nOldMode
= SetBkMode( hdc
, OPAQUE
);
214 (btnPaintFunc
[btn_type
])( hWnd
, hdc
, ODA_DRAWENTIRE
);
215 SetBkMode(hdc
, nOldMode
); /* reset painting mode */
216 if( !wParam
) EndPaint( hWnd
, &ps
);
221 if (wParam
== VK_SPACE
)
223 SendMessageW( hWnd
, BM_SETSTATE
, TRUE
, 0 );
224 set_button_state( hWnd
, get_button_state( hWnd
) | BUTTON_BTNPRESSED
);
228 case WM_LBUTTONDBLCLK
:
229 if(style
& BS_NOTIFY
||
230 btn_type
== BS_RADIOBUTTON
||
231 btn_type
== BS_USERBUTTON
||
232 btn_type
== BS_OWNERDRAW
)
234 SendMessageW( GetParent(hWnd
), WM_COMMAND
,
235 MAKEWPARAM( GetWindowLongA(hWnd
,GWL_ID
), BN_DOUBLECLICKED
),
243 SendMessageW( hWnd
, BM_SETSTATE
, TRUE
, 0 );
244 set_button_state( hWnd
, get_button_state( hWnd
) | BUTTON_BTNPRESSED
);
248 if (wParam
!= VK_SPACE
)
252 state
= get_button_state( hWnd
);
253 if (!(state
& BUTTON_BTNPRESSED
)) break;
254 state
&= BUTTON_NSTATES
;
255 set_button_state( hWnd
, state
);
256 if (!(state
& BUTTON_HIGHLIGHTED
))
261 SendMessageW( hWnd
, BM_SETSTATE
, FALSE
, 0 );
263 GetClientRect( hWnd
, &rect
);
264 if (uMsg
== WM_KEYUP
|| PtInRect( &rect
, pt
))
266 state
= get_button_state( hWnd
);
269 case BS_AUTOCHECKBOX
:
270 SendMessageW( hWnd
, BM_SETCHECK
, !(state
& BUTTON_CHECKED
), 0 );
272 case BS_AUTORADIOBUTTON
:
273 SendMessageW( hWnd
, BM_SETCHECK
, TRUE
, 0 );
276 SendMessageW( hWnd
, BM_SETCHECK
,
277 (state
& BUTTON_3STATE
) ? 0 : ((state
& 3) + 1), 0 );
280 SendMessageW( GetParent(hWnd
), WM_COMMAND
,
281 MAKEWPARAM( GetWindowLongA(hWnd
,GWL_ID
), BN_CLICKED
), (LPARAM
)hWnd
);
285 case WM_CAPTURECHANGED
:
286 state
= get_button_state( hWnd
);
287 if (state
& BUTTON_BTNPRESSED
)
289 state
&= BUTTON_NSTATES
;
290 set_button_state( hWnd
, state
);
291 if (state
& BUTTON_HIGHLIGHTED
) SendMessageW( hWnd
, BM_SETSTATE
, FALSE
, 0 );
296 if ((wParam
& MK_LBUTTON
) && GetCapture() == hWnd
)
298 GetClientRect( hWnd
, &rect
);
299 SendMessageW( hWnd
, BM_SETSTATE
, PtInRect(&rect
, pt
), 0 );
304 if (unicode
) DefWindowProcW( hWnd
, WM_SETTEXT
, wParam
, lParam
);
305 else DefWindowProcA( hWnd
, WM_SETTEXT
, wParam
, lParam
);
306 paint_button( hWnd
, btn_type
, ODA_DRAWENTIRE
);
307 return 1; /* success. FIXME: check text length */
310 set_button_font( hWnd
, wParam
);
311 if (lParam
) paint_button( hWnd
, btn_type
, ODA_DRAWENTIRE
);
315 return get_button_font( hWnd
);
318 if ((btn_type
== BS_RADIOBUTTON
|| btn_type
== BS_AUTORADIOBUTTON
) && (GetCapture() != hWnd
) &&
319 !(SendMessageW(hWnd
, BM_GETCHECK
, 0, 0) & BST_CHECKED
))
321 /* The notification is sent when the button (BS_AUTORADIOBUTTON)
322 is unchecked and the focus was not given by a mouse click. */
323 if (btn_type
== BS_AUTORADIOBUTTON
)
324 SendMessageW( hWnd
, BM_SETCHECK
, BUTTON_CHECKED
, 0 );
325 SendMessageW( GetParent(hWnd
), WM_COMMAND
,
326 MAKEWPARAM( GetWindowLongA(hWnd
,GWL_ID
), BN_CLICKED
), (LPARAM
)hWnd
);
328 set_button_state( hWnd
, get_button_state(hWnd
) | BUTTON_HASFOCUS
);
329 paint_button( hWnd
, btn_type
, ODA_FOCUS
);
333 set_button_state( hWnd
, get_button_state(hWnd
) & ~BUTTON_HASFOCUS
);
334 paint_button( hWnd
, btn_type
, ODA_FOCUS
);
335 InvalidateRect( hWnd
, NULL
, TRUE
);
338 case WM_SYSCOLORCHANGE
:
339 InvalidateRect( hWnd
, NULL
, FALSE
);
344 if ((wParam
& 0x0f) >= MAX_BTN_TYPE
) break;
345 btn_type
= wParam
& 0x0f;
346 style
= (style
& ~0x0f) | btn_type
;
347 SetWindowLongA( hWnd
, GWL_STYLE
, style
);
349 /* Only redraw if lParam flag is set.*/
351 paint_button( hWnd
, btn_type
, ODA_DRAWENTIRE
);
356 SendMessageW( hWnd
, WM_LBUTTONDOWN
, 0, 0 );
357 SendMessageW( hWnd
, WM_LBUTTONUP
, 0, 0 );
361 /* Check that image format matches button style */
362 switch (style
& (BS_BITMAP
|BS_ICON
))
365 if (wParam
!= IMAGE_BITMAP
) return 0;
368 if (wParam
!= IMAGE_ICON
) return 0;
373 oldHbitmap
= SetWindowLongA( hWnd
, HIMAGE_GWL_OFFSET
, lParam
);
374 InvalidateRect( hWnd
, NULL
, FALSE
);
378 return GetWindowLongA( hWnd
, HIMAGE_GWL_OFFSET
);
382 return get_button_state( hWnd
) & 3;
386 if (wParam
> maxCheckState
[btn_type
]) wParam
= maxCheckState
[btn_type
];
387 state
= get_button_state( hWnd
);
388 if ((btn_type
== BS_RADIOBUTTON
) || (btn_type
== BS_AUTORADIOBUTTON
))
390 if (wParam
) style
|= WS_TABSTOP
;
391 else style
&= ~WS_TABSTOP
;
392 SetWindowLongA( hWnd
, GWL_STYLE
, style
);
394 if ((state
& 3) != wParam
)
396 set_button_state( hWnd
, (state
& ~3) | wParam
);
397 paint_button( hWnd
, btn_type
, ODA_SELECT
);
399 if ((btn_type
== BS_AUTORADIOBUTTON
) && (wParam
== BUTTON_CHECKED
) && (style
& WS_CHILD
))
400 BUTTON_CheckAutoRadioButton( hWnd
);
405 return get_button_state( hWnd
);
409 state
= get_button_state( hWnd
);
412 if (state
& BUTTON_HIGHLIGHTED
) break;
413 set_button_state( hWnd
, state
| BUTTON_HIGHLIGHTED
);
417 if (!(state
& BUTTON_HIGHLIGHTED
)) break;
418 set_button_state( hWnd
, state
& ~BUTTON_HIGHLIGHTED
);
420 paint_button( hWnd
, btn_type
, ODA_SELECT
);
424 if(btn_type
== BS_GROUPBOX
) return HTTRANSPARENT
;
427 return unicode
? DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
) :
428 DefWindowProcA(hWnd
, uMsg
, wParam
, lParam
);
433 /***********************************************************************
435 * The button window procedure. This is just a wrapper which locks
436 * the passed HWND and calls the real window procedure (with a WND*
437 * pointer pointing to the locked windowstructure).
439 static LRESULT WINAPI
ButtonWndProcW( HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
441 if (!IsWindow( hWnd
)) return 0;
442 return ButtonWndProc_common( hWnd
, uMsg
, wParam
, lParam
, TRUE
);
446 /***********************************************************************
449 static LRESULT WINAPI
ButtonWndProcA( HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
451 if (!IsWindow( hWnd
)) return 0;
452 return ButtonWndProc_common( hWnd
, uMsg
, wParam
, lParam
, FALSE
);
456 /**********************************************************************
457 * Convert button styles to flags used by DrawText.
458 * TODO: handle WS_EX_RIGHT extended style.
460 static UINT
BUTTON_BStoDT(DWORD style
)
462 UINT dtStyle
= DT_NOCLIP
; /* We use SelectClipRgn to limit output */
464 /* "Convert" pushlike buttons to pushbuttons */
465 if (style
& BS_PUSHLIKE
)
468 if (!(style
& BS_MULTILINE
))
469 dtStyle
|= DT_SINGLELINE
;
471 dtStyle
|= DT_WORDBREAK
;
473 switch (style
& BS_CENTER
)
475 case BS_LEFT
: /* DT_LEFT is 0 */ break;
476 case BS_RIGHT
: dtStyle
|= DT_RIGHT
; break;
477 case BS_CENTER
: dtStyle
|= DT_CENTER
; break;
479 /* Pushbutton's text is centered by default */
480 if (get_button_type(style
) <= BS_DEFPUSHBUTTON
) dtStyle
|= DT_CENTER
;
481 /* all other flavours have left aligned text */
484 /* DrawText ignores vertical alignment for multiline text,
485 * but we use these flags to align label manualy.
487 if (get_button_type(style
) != BS_GROUPBOX
)
489 switch (style
& BS_VCENTER
)
491 case BS_TOP
: /* DT_TOP is 0 */ break;
492 case BS_BOTTOM
: dtStyle
|= DT_BOTTOM
; break;
493 case BS_VCENTER
: /* fall through */
494 default: dtStyle
|= DT_VCENTER
; break;
498 /* GroupBox's text is always single line and is top aligned. */
499 dtStyle
|= DT_SINGLELINE
;
504 /**********************************************************************
505 * BUTTON_CalcLabelRect
507 * Calculates label's rectangle depending on button style.
509 * Returns flags to be passed to DrawText.
510 * Calculated rectangle doesn't take into account button state
511 * (pushed, etc.). If there is nothing to draw (no text/image) output
512 * rectangle is empty, and return value is (UINT)-1.
514 static UINT
BUTTON_CalcLabelRect(HWND hwnd
, HDC hdc
, RECT
*rc
)
516 LONG style
= GetWindowLongA( hwnd
, GWL_STYLE
);
520 UINT dtStyle
= BUTTON_BStoDT(style
);
524 /* Calculate label rectangle according to label type */
525 switch (style
& (BS_ICON
|BS_BITMAP
))
528 if (!(text
= get_button_text( hwnd
))) goto empty_rect
;
531 HeapFree( GetProcessHeap(), 0, text
);
534 DrawTextW(hdc
, text
, -1, &r
, dtStyle
| DT_CALCRECT
);
535 HeapFree( GetProcessHeap(), 0, text
);
539 if (!GetIconInfo((HICON
)GetWindowLongA( hwnd
, HIMAGE_GWL_OFFSET
), &iconInfo
))
542 GetObjectW (iconInfo
.hbmColor
, sizeof(BITMAP
), &bm
);
544 r
.right
= r
.left
+ bm
.bmWidth
;
545 r
.bottom
= r
.top
+ bm
.bmHeight
;
547 DeleteObject(iconInfo
.hbmColor
);
548 DeleteObject(iconInfo
.hbmMask
);
552 if (!GetObjectW( (HANDLE
)GetWindowLongA( hwnd
, HIMAGE_GWL_OFFSET
), sizeof(BITMAP
), &bm
))
555 r
.right
= r
.left
+ bm
.bmWidth
;
556 r
.bottom
= r
.top
+ bm
.bmHeight
;
563 return (UINT
)(LONG
)-1;
566 /* Position label inside bounding rectangle according to
567 * alignment flags. (calculated rect is always left-top aligned).
568 * If label is aligned to any side - shift label in opposite
569 * direction to leave extra space for focus rectangle.
571 switch (dtStyle
& (DT_CENTER
|DT_RIGHT
))
573 case DT_LEFT
: r
.left
++; r
.right
++; break;
574 case DT_CENTER
: n
= r
.right
- r
.left
;
575 r
.left
= rc
->left
+ ((rc
->right
- rc
->left
) - n
) / 2;
576 r
.right
= r
.left
+ n
; break;
577 case DT_RIGHT
: n
= r
.right
- r
.left
;
578 r
.right
= rc
->right
- 1;
579 r
.left
= r
.right
- n
;
583 switch (dtStyle
& (DT_VCENTER
|DT_BOTTOM
))
585 case DT_TOP
: r
.top
++; r
.bottom
++; break;
586 case DT_VCENTER
: n
= r
.bottom
- r
.top
;
587 r
.top
= rc
->top
+ ((rc
->bottom
- rc
->top
) - n
) / 2;
588 r
.bottom
= r
.top
+ n
; break;
589 case DT_BOTTOM
: n
= r
.bottom
- r
.top
;
590 r
.bottom
= rc
->bottom
- 1;
591 r
.top
= r
.bottom
- n
;
600 /**********************************************************************
601 * BUTTON_DrawTextCallback
603 * Callback function used by DrawStateW function.
605 static BOOL CALLBACK
BUTTON_DrawTextCallback(HDC hdc
, LPARAM lp
, WPARAM wp
, int cx
, int cy
)
613 DrawTextW(hdc
, (LPCWSTR
)lp
, -1, &rc
, (UINT
)wp
);
618 /**********************************************************************
621 * Common function for drawing button label.
623 static void BUTTON_DrawLabel(HWND hwnd
, HDC hdc
, UINT dtFlags
, RECT
*rc
)
625 DRAWSTATEPROC lpOutputProc
= NULL
;
629 UINT flags
= IsWindowEnabled(hwnd
) ? DSS_NORMAL
: DSS_DISABLED
;
630 LONG state
= get_button_state( hwnd
);
631 LONG style
= GetWindowLongA( hwnd
, GWL_STYLE
);
634 /* FIXME: To draw disabled label in Win31 look-and-feel, we probably
635 * must use DSS_MONO flag and COLOR_GRAYTEXT brush (or maybe DSS_UNION).
636 * I don't have Win31 on hand to verify that, so I leave it as is.
639 if ((style
& BS_PUSHLIKE
) && (state
& BUTTON_3STATE
))
641 hbr
= GetSysColorBrush(COLOR_GRAYTEXT
);
645 switch (style
& (BS_ICON
|BS_BITMAP
))
648 /* DST_COMPLEX -- is 0 */
649 lpOutputProc
= BUTTON_DrawTextCallback
;
650 if (!(text
= get_button_text( hwnd
))) return;
652 wp
= (WPARAM
)dtFlags
;
657 lp
= GetWindowLongA( hwnd
, HIMAGE_GWL_OFFSET
);
662 lp
= GetWindowLongA( hwnd
, HIMAGE_GWL_OFFSET
);
669 DrawStateW(hdc
, hbr
, lpOutputProc
, lp
, wp
, rc
->left
, rc
->top
,
670 rc
->right
- rc
->left
, rc
->bottom
- rc
->top
, flags
);
671 if (text
) HeapFree( GetProcessHeap(), 0, text
);
674 /**********************************************************************
675 * Push Button Functions
677 static void PB_Paint( HWND hwnd
, HDC hDC
, UINT action
)
679 RECT rc
, focus_rect
, r
;
685 COLORREF oldTxtColor
;
687 LONG state
= get_button_state( hwnd
);
688 LONG style
= GetWindowLongA( hwnd
, GWL_STYLE
);
689 BOOL pushedState
= (state
& BUTTON_HIGHLIGHTED
);
691 GetClientRect( hwnd
, &rc
);
693 /* Send WM_CTLCOLOR to allow changing the font (the colors are fixed) */
694 if ((hFont
= get_button_font( hwnd
))) SelectObject( hDC
, hFont
);
695 SendMessageW( GetParent(hwnd
), WM_CTLCOLORBTN
, hDC
, (LPARAM
)hwnd
);
696 hOldPen
= (HPEN
)SelectObject(hDC
, GetSysColorPen(COLOR_WINDOWFRAME
));
697 hOldBrush
=(HBRUSH
)SelectObject(hDC
,GetSysColorBrush(COLOR_BTNFACE
));
698 oldBkMode
= SetBkMode(hDC
, TRANSPARENT
);
700 if ( TWEAK_WineLook
== WIN31_LOOK
)
702 COLORREF clr_wnd
= GetSysColor(COLOR_WINDOW
);
703 Rectangle(hDC
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
705 SetPixel( hDC
, rc
.left
, rc
.top
, clr_wnd
);
706 SetPixel( hDC
, rc
.left
, rc
.bottom
-1, clr_wnd
);
707 SetPixel( hDC
, rc
.right
-1, rc
.top
, clr_wnd
);
708 SetPixel( hDC
, rc
.right
-1, rc
.bottom
-1, clr_wnd
);
709 InflateRect( &rc
, -1, -1 );
712 if (get_button_type(style
) == BS_DEFPUSHBUTTON
)
714 Rectangle(hDC
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
715 InflateRect( &rc
, -1, -1 );
718 if (TWEAK_WineLook
== WIN31_LOOK
)
722 /* draw button shadow: */
723 SelectObject(hDC
, GetSysColorBrush(COLOR_BTNSHADOW
));
724 PatBlt(hDC
, rc
.left
, rc
.top
, 1, rc
.bottom
-rc
.top
, PATCOPY
);
725 PatBlt(hDC
, rc
.left
, rc
.top
, rc
.right
-rc
.left
, 1, PATCOPY
);
727 rc
.right
++, rc
.bottom
++;
728 DrawEdge( hDC
, &rc
, EDGE_RAISED
, BF_RECT
);
729 rc
.right
--, rc
.bottom
--;
734 UINT uState
= DFCS_BUTTONPUSH
| DFCS_ADJUSTRECT
;
738 else if (pushedState
)
740 if (get_button_type(style
) == BS_DEFPUSHBUTTON
)
743 uState
|= DFCS_PUSHED
;
746 if (state
& (BUTTON_CHECKED
| BUTTON_3STATE
))
747 uState
|= DFCS_CHECKED
;
749 DrawFrameControl( hDC
, &rc
, DFC_BUTTON
, uState
);
754 /* draw button label */
756 dtFlags
= BUTTON_CalcLabelRect(hwnd
, hDC
, &r
);
758 if (dtFlags
== (UINT
)-1L)
762 OffsetRect(&r
, 1, 1);
764 if(TWEAK_WineLook
== WIN31_LOOK
)
767 InflateRect(&focus_rect
, 2, 0);
770 hRgn
= CreateRectRgn(rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
771 SelectClipRgn(hDC
, hRgn
);
773 oldTxtColor
= SetTextColor( hDC
, GetSysColor(COLOR_BTNTEXT
) );
775 BUTTON_DrawLabel(hwnd
, hDC
, dtFlags
, &r
);
777 SetTextColor( hDC
, oldTxtColor
);
778 SelectClipRgn(hDC
, 0);
781 if (state
& BUTTON_HASFOCUS
)
783 InflateRect( &focus_rect
, -1, -1 );
784 IntersectRect(&focus_rect
, &focus_rect
, &rc
);
785 DrawFocusRect( hDC
, &focus_rect
);
789 SelectObject( hDC
, hOldPen
);
790 SelectObject( hDC
, hOldBrush
);
791 SetBkMode(hDC
, oldBkMode
);
794 /**********************************************************************
795 * Check Box & Radio Button Functions
798 static void CB_Paint( HWND hwnd
, HDC hDC
, UINT action
)
800 RECT rbox
, rtext
, client
;
806 LONG state
= get_button_state( hwnd
);
807 LONG style
= GetWindowLongA( hwnd
, GWL_STYLE
);
809 if (style
& BS_PUSHLIKE
)
811 PB_Paint( hwnd
, hDC
, action
);
815 GetClientRect(hwnd
, &client
);
816 rbox
= rtext
= client
;
818 if ((hFont
= get_button_font( hwnd
))) SelectObject( hDC
, hFont
);
820 hBrush
= SendMessageW( GetParent(hwnd
), WM_CTLCOLORSTATIC
, hDC
, (LPARAM
)hwnd
);
821 if (!hBrush
) /* did the app forget to call defwindowproc ? */
822 hBrush
= DefWindowProcW( GetParent(hwnd
), WM_CTLCOLORSTATIC
, hDC
, (LPARAM
)hwnd
);
824 if (style
& BS_LEFTTEXT
)
826 /* magic +4 is what CTL3D expects */
828 rtext
.right
-= checkBoxWidth
+ 4;
829 rbox
.left
= rbox
.right
- checkBoxWidth
;
833 rtext
.left
+= checkBoxWidth
+ 4;
834 rbox
.right
= checkBoxWidth
;
837 /* Draw the check-box bitmap */
838 if (action
== ODA_DRAWENTIRE
|| action
== ODA_SELECT
)
840 /* Since WM_ERASEBKGND does nothing, first prepare background */
841 if (action
== ODA_SELECT
) FillRect( hDC
, &rbox
, hBrush
);
842 else FillRect( hDC
, &client
, hBrush
);
844 if( TWEAK_WineLook
== WIN31_LOOK
)
846 HDC hMemDC
= CreateCompatibleDC( hDC
);
848 delta
= (rbox
.bottom
- rbox
.top
- checkBoxHeight
) / 2;
850 /* Check in case the client area is smaller than the checkbox bitmap */
851 if (delta
< 0) delta
= 0;
853 if (state
& BUTTON_HIGHLIGHTED
) x
+= 2 * checkBoxWidth
;
854 if (state
& (BUTTON_CHECKED
| BUTTON_3STATE
)) x
+= checkBoxWidth
;
855 if ((get_button_type(style
) == BS_RADIOBUTTON
) ||
856 (get_button_type(style
) == BS_AUTORADIOBUTTON
)) y
+= checkBoxHeight
;
857 else if (state
& BUTTON_3STATE
) y
+= 2 * checkBoxHeight
;
859 /* The bitmap for the radio button is not aligned with the
860 * left of the window, it is 1 pixel off. */
861 if ((get_button_type(style
) == BS_RADIOBUTTON
) ||
862 (get_button_type(style
) == BS_AUTORADIOBUTTON
))
865 SelectObject( hMemDC
, hbitmapCheckBoxes
);
866 BitBlt( hDC
, rbox
.left
, rbox
.top
+ delta
, checkBoxWidth
,
867 checkBoxHeight
, hMemDC
, x
, y
, SRCCOPY
);
874 if ((get_button_type(style
) == BS_RADIOBUTTON
) ||
875 (get_button_type(style
) == BS_AUTORADIOBUTTON
)) flags
= DFCS_BUTTONRADIO
;
876 else if (state
& BUTTON_3STATE
) flags
= DFCS_BUTTON3STATE
;
877 else flags
= DFCS_BUTTONCHECK
;
879 if (state
& (BUTTON_CHECKED
| BUTTON_3STATE
)) flags
|= DFCS_CHECKED
;
880 if (state
& BUTTON_HIGHLIGHTED
) flags
|= DFCS_PUSHED
;
882 if (style
& WS_DISABLED
) flags
|= DFCS_INACTIVE
;
884 /* rbox must have the correct height */
885 delta
= rbox
.bottom
- rbox
.top
- checkBoxHeight
;
888 int ofs
= (abs(delta
) / 2);
889 rbox
.bottom
-= ofs
+ 1;
890 rbox
.top
= rbox
.bottom
- checkBoxHeight
;
894 int ofs
= (abs(delta
) / 2);
896 rbox
.bottom
= rbox
.top
+ checkBoxHeight
;
899 DrawFrameControl( hDC
, &rbox
, DFC_BUTTON
, flags
);
905 dtFlags
= BUTTON_CalcLabelRect(hwnd
, hDC
, &rtext
);
907 if (dtFlags
== (UINT
)-1L) /* Noting to draw */
909 hRgn
= CreateRectRgn(client
.left
, client
.top
, client
.right
, client
.bottom
);
910 SelectClipRgn(hDC
, hRgn
);
913 if (action
== ODA_DRAWENTIRE
)
914 BUTTON_DrawLabel(hwnd
, hDC
, dtFlags
, &rtext
);
917 if ((action
== ODA_FOCUS
) ||
918 ((action
== ODA_DRAWENTIRE
) && (state
& BUTTON_HASFOCUS
)))
922 IntersectRect(&rtext
, &rtext
, &client
);
923 DrawFocusRect( hDC
, &rtext
);
925 SelectClipRgn(hDC
, 0);
929 /**********************************************************************
930 * BUTTON_CheckAutoRadioButton
932 * hwnd is checked, uncheck every other auto radio button in group
934 static void BUTTON_CheckAutoRadioButton( HWND hwnd
)
936 HWND parent
, sibling
, start
;
938 parent
= GetParent(hwnd
);
939 /* make sure that starting control is not disabled or invisible */
940 start
= sibling
= GetNextDlgGroupItem( parent
, hwnd
, TRUE
);
944 if ((hwnd
!= sibling
) &&
945 ((GetWindowLongA( sibling
, GWL_STYLE
) & 0x0f) == BS_AUTORADIOBUTTON
))
946 SendMessageW( sibling
, BM_SETCHECK
, BUTTON_UNCHECKED
, 0 );
947 sibling
= GetNextDlgGroupItem( parent
, sibling
, FALSE
);
948 } while (sibling
!= start
);
952 /**********************************************************************
953 * Group Box Functions
956 static void GB_Paint( HWND hwnd
, HDC hDC
, UINT action
)
962 LONG style
= GetWindowLongA( hwnd
, GWL_STYLE
);
964 if (action
!= ODA_DRAWENTIRE
) return;
966 if ((hFont
= get_button_font( hwnd
))) SelectObject( hDC
, hFont
);
967 /* GroupBox acts like static control, so it sends CTLCOLORSTATIC */
968 hbr
= SendMessageW( GetParent(hwnd
), WM_CTLCOLORSTATIC
, hDC
, (LPARAM
)hwnd
);
969 if (!hbr
) /* did the app forget to call defwindowproc ? */
970 hbr
= DefWindowProcW( GetParent(hwnd
), WM_CTLCOLORSTATIC
, hDC
, (LPARAM
)hwnd
);
972 GetClientRect( hwnd
, &rc
);
973 if (TWEAK_WineLook
== WIN31_LOOK
) {
974 HPEN hPrevPen
= SelectObject( hDC
,
975 GetSysColorPen(COLOR_WINDOWFRAME
));
976 HBRUSH hPrevBrush
= SelectObject( hDC
,
977 GetStockObject(NULL_BRUSH
) );
979 Rectangle( hDC
, rc
.left
, rc
.top
+ 2, rc
.right
- 1, rc
.bottom
- 1 );
980 SelectObject( hDC
, hPrevBrush
);
981 SelectObject( hDC
, hPrevPen
);
986 GetTextMetricsW (hDC
, &tm
);
987 rcFrame
.top
+= (tm
.tmHeight
/ 2) - 1;
988 DrawEdge (hDC
, &rcFrame
, EDGE_ETCHED
, BF_RECT
| ((style
& BS_FLAT
) ? BF_FLAT
: 0));
991 InflateRect(&rc
, -7, 1);
992 dtFlags
= BUTTON_CalcLabelRect(hwnd
, hDC
, &rc
);
994 if (dtFlags
== (UINT
)-1L)
997 /* Because buttons have CS_PARENTDC class style, there is a chance
998 * that label will be drawn out of client rect.
999 * But Windows doesn't clip label's rect, so do I.
1002 /* There is 1-pixel marging at the left, right, and bottom */
1003 rc
.left
--; rc
.right
++; rc
.bottom
++;
1004 FillRect(hDC
, &rc
, hbr
);
1005 rc
.left
++; rc
.right
--; rc
.bottom
--;
1007 BUTTON_DrawLabel(hwnd
, hDC
, dtFlags
, &rc
);
1011 /**********************************************************************
1012 * User Button Functions
1015 static void UB_Paint( HWND hwnd
, HDC hDC
, UINT action
)
1020 LONG state
= get_button_state( hwnd
);
1022 if (action
== ODA_SELECT
) return;
1024 GetClientRect( hwnd
, &rc
);
1026 if ((hFont
= get_button_font( hwnd
))) SelectObject( hDC
, hFont
);
1028 hBrush
= SendMessageW( GetParent(hwnd
), WM_CTLCOLORBTN
, hDC
, (LPARAM
)hwnd
);
1029 if (!hBrush
) /* did the app forget to call defwindowproc ? */
1030 hBrush
= DefWindowProcW( GetParent(hwnd
), WM_CTLCOLORBTN
, hDC
, (LPARAM
)hwnd
);
1032 FillRect( hDC
, &rc
, hBrush
);
1033 if ((action
== ODA_FOCUS
) ||
1034 ((action
== ODA_DRAWENTIRE
) && (state
& BUTTON_HASFOCUS
)))
1035 DrawFocusRect( hDC
, &rc
);
1039 /**********************************************************************
1040 * Ownerdrawn Button Functions
1043 static void OB_Paint( HWND hwnd
, HDC hDC
, UINT action
)
1045 LONG state
= get_button_state( hwnd
);
1049 UINT id
= GetWindowLongA( hwnd
, GWL_ID
);
1051 dis
.CtlType
= ODT_BUTTON
;
1054 dis
.itemAction
= action
;
1055 dis
.itemState
= ((state
& BUTTON_HASFOCUS
) ? ODS_FOCUS
: 0) |
1056 ((state
& BUTTON_HIGHLIGHTED
) ? ODS_SELECTED
: 0) |
1057 (IsWindowEnabled(hwnd
) ? 0: ODS_DISABLED
);
1058 dis
.hwndItem
= hwnd
;
1061 GetClientRect( hwnd
, &dis
.rcItem
);
1063 clipRegion
= CreateRectRgnIndirect(&dis
.rcItem
);
1064 if (GetClipRgn(hDC
, clipRegion
) != 1)
1066 DeleteObject(clipRegion
);
1067 clipRegion
=(HRGN
)NULL
;
1069 clipRect
= dis
.rcItem
;
1070 DPtoLP(hDC
, (LPPOINT
) &clipRect
, 2);
1071 IntersectClipRect(hDC
, clipRect
.left
, clipRect
.top
, clipRect
.right
, clipRect
.bottom
);
1073 SetBkColor( hDC
, GetSysColor( COLOR_BTNFACE
) );
1074 SendMessageW( GetParent(hwnd
), WM_DRAWITEM
, id
, (LPARAM
)&dis
);
1075 SelectClipRgn(hDC
, clipRegion
);