Sync with trunk r63637.
[reactos.git] / win32ss / user / user32 / 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 * 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.
11 *
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.
16 *
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 *
21 * NOTES
22 *
23 * This code was audited for completeness against the documented features
24 * of Comctl32.dll version 6.0 on Oct. 3, 2004, by Dimitrie O. Paun.
25 *
26 * Unless otherwise noted, we believe this code to be complete, as per
27 * the specification mentioned above.
28 * If you discover missing features, or bugs, please note them below.
29 *
30 * TODO
31 * Styles
32 * - BS_NOTIFY: is it complete?
33 * - BS_RIGHTBUTTON: same as BS_LEFTTEXT
34 *
35 * Messages
36 * - WM_CHAR: Checks a (manual or automatic) check box on '+' or '=', clears it on '-' key.
37 * - WM_SETFOCUS: For (manual or automatic) radio buttons, send the parent window BN_CLICKED
38 * - WM_NCCREATE: Turns any BS_OWNERDRAW button into a BS_PUSHBUTTON button.
39 * - WM_SYSKEYUP
40 * - BCM_GETIDEALSIZE
41 * - BCM_GETIMAGELIST
42 * - BCM_GETTEXTMARGIN
43 * - BCM_SETIMAGELIST
44 * - BCM_SETTEXTMARGIN
45 *
46 * Notifications
47 * - BCN_HOTITEMCHANGE
48 * - BN_DISABLE
49 * - BN_PUSHED/BN_HILITE
50 * + BN_KILLFOCUS: is it OK?
51 * - BN_PAINT
52 * + BN_SETFOCUS: is it OK?
53 * - BN_UNPUSHED/BN_UNHILITE
54 * - NM_CUSTOMDRAW
55 *
56 * Structures/Macros/Definitions
57 * - BUTTON_IMAGELIST
58 * - NMBCHOTITEM
59 * - Button_GetIdealSize
60 * - Button_GetImageList
61 * - Button_GetTextMargin
62 * - Button_SetImageList
63 * - Button_SetTextMargin
64 */
65 #include <user32.h>
66
67 #include <wine/debug.h>
68 WINE_DEFAULT_DEBUG_CHANNEL(button);
69
70 /* GetWindowLong offsets for window extra information */
71 #define STATE_GWL_OFFSET 0
72 #define HFONT_GWL_OFFSET (sizeof(LONG))
73 #define HIMAGE_GWL_OFFSET (HFONT_GWL_OFFSET+sizeof(HFONT))
74 #define UISTATE_GWL_OFFSET (HIMAGE_GWL_OFFSET+sizeof(HFONT))
75 #define NB_EXTRA_BYTES (UISTATE_GWL_OFFSET+sizeof(LONG))
76
77 /* undocumented flags */
78 #define BUTTON_NSTATES 0x0F
79 #define BUTTON_BTNPRESSED 0x40
80 #define BUTTON_UNKNOWN2 0x20
81 #define BUTTON_UNKNOWN3 0x10
82 #define BUTTON_BMCLICK 0x100 // ReactOS Need to up to wine!
83
84 #define BUTTON_NOTIFY_PARENT(hWnd, code) \
85 do { /* Notify parent which has created this button control */ \
86 TRACE("notification " #code " sent to hwnd=%p\n", GetParent(hWnd)); \
87 SendMessageW(GetParent(hWnd), WM_COMMAND, \
88 MAKEWPARAM(GetWindowLongPtrW((hWnd),GWLP_ID), (code)), \
89 (LPARAM)(hWnd)); \
90 } while(0)
91
92 static UINT BUTTON_CalcLabelRect( HWND hwnd, HDC hdc, RECT *rc );
93 static void PB_Paint( HWND hwnd, HDC hDC, UINT action );
94 static void CB_Paint( HWND hwnd, HDC hDC, UINT action );
95 static void GB_Paint( HWND hwnd, HDC hDC, UINT action );
96 static void UB_Paint( HWND hwnd, HDC hDC, UINT action );
97 static void OB_Paint( HWND hwnd, HDC hDC, UINT action );
98 static void BUTTON_CheckAutoRadioButton( HWND hwnd );
99
100 #define MAX_BTN_TYPE 16
101
102 static const WORD maxCheckState[MAX_BTN_TYPE] =
103 {
104 BST_UNCHECKED, /* BS_PUSHBUTTON */
105 BST_UNCHECKED, /* BS_DEFPUSHBUTTON */
106 BST_CHECKED, /* BS_CHECKBOX */
107 BST_CHECKED, /* BS_AUTOCHECKBOX */
108 BST_CHECKED, /* BS_RADIOBUTTON */
109 BST_INDETERMINATE, /* BS_3STATE */
110 BST_INDETERMINATE, /* BS_AUTO3STATE */
111 BST_UNCHECKED, /* BS_GROUPBOX */
112 BST_UNCHECKED, /* BS_USERBUTTON */
113 BST_CHECKED, /* BS_AUTORADIOBUTTON */
114 BST_UNCHECKED, /* BS_PUSHBOX */
115 BST_UNCHECKED /* BS_OWNERDRAW */
116 };
117
118 typedef void (*pfPaint)( HWND hwnd, HDC hdc, UINT action );
119
120 static const pfPaint btnPaintFunc[MAX_BTN_TYPE] =
121 {
122 PB_Paint, /* BS_PUSHBUTTON */
123 PB_Paint, /* BS_DEFPUSHBUTTON */
124 CB_Paint, /* BS_CHECKBOX */
125 CB_Paint, /* BS_AUTOCHECKBOX */
126 CB_Paint, /* BS_RADIOBUTTON */
127 CB_Paint, /* BS_3STATE */
128 CB_Paint, /* BS_AUTO3STATE */
129 GB_Paint, /* BS_GROUPBOX */
130 UB_Paint, /* BS_USERBUTTON */
131 CB_Paint, /* BS_AUTORADIOBUTTON */
132 NULL, /* BS_PUSHBOX */
133 OB_Paint /* BS_OWNERDRAW */
134 };
135
136 static HBITMAP hbitmapCheckBoxes = 0;
137 static WORD checkBoxWidth = 0, checkBoxHeight = 0;
138
139
140 /*********************************************************************
141 * button class descriptor
142 */
143 static const WCHAR buttonW[] = {'B','u','t','t','o','n',0};
144 const struct builtin_class_descr BUTTON_builtin_class =
145 {
146 buttonW, /* name */
147 CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW | CS_PARENTDC, /* style */
148 ButtonWndProcA, /* procA */
149 ButtonWndProcW, /* procW */
150 NB_EXTRA_BYTES, /* extra */
151 IDC_ARROW, /* cursor */
152 0 /* brush */
153 };
154
155
156 static inline LONG get_button_state( HWND hwnd )
157 {
158 return GetWindowLongPtrW( hwnd, STATE_GWL_OFFSET );
159 }
160
161 static inline void set_button_state( HWND hwnd, LONG state )
162 {
163 SetWindowLongPtrW( hwnd, STATE_GWL_OFFSET, state );
164 }
165
166 static __inline void set_ui_state( HWND hwnd, LONG flags )
167 {
168 SetWindowLongPtrW( hwnd, UISTATE_GWL_OFFSET, flags );
169 }
170
171 static __inline LONG get_ui_state( HWND hwnd )
172 {
173 return GetWindowLongPtrW( hwnd, UISTATE_GWL_OFFSET );
174 }
175
176 __inline static HFONT get_button_font( HWND hwnd )
177 {
178 return (HFONT)GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET );
179 }
180
181 static inline void set_button_font( HWND hwnd, HFONT font )
182 {
183 SetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET, (LONG_PTR)font );
184 }
185
186 static inline UINT get_button_type( LONG window_style )
187 {
188 return (window_style & BS_TYPEMASK);
189 }
190
191 /* paint a button of any type */
192 static inline void paint_button( HWND hwnd, LONG style, UINT action )
193 {
194 if (btnPaintFunc[style] && IsWindowVisible(hwnd))
195 {
196 HDC hdc = GetDC( hwnd );
197 btnPaintFunc[style]( hwnd, hdc, action );
198 ReleaseDC( hwnd, hdc );
199 }
200 }
201
202 /* retrieve the button text; returned buffer must be freed by caller */
203 static inline WCHAR *get_button_text( HWND hwnd )
204 {
205 INT len = 512;
206 WCHAR *buffer = HeapAlloc( GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR) );
207 if (buffer) InternalGetWindowText( hwnd, buffer, len + 1 );
208 return buffer;
209 }
210
211 /* Retrieve the UI state for the control */
212 static BOOL button_update_uistate(HWND hwnd, BOOL unicode)
213 {
214 LONG flags, prevflags;
215
216 if (unicode)
217 flags = DefWindowProcW(hwnd, WM_QUERYUISTATE, 0, 0);
218 else
219 flags = DefWindowProcA(hwnd, WM_QUERYUISTATE, 0, 0);
220
221 prevflags = get_ui_state(hwnd);
222
223 if (prevflags != flags)
224 {
225 set_ui_state(hwnd, flags);
226 return TRUE;
227 }
228
229 return FALSE;
230 }
231
232 /***********************************************************************
233 * ButtonWndProc_common
234 */
235 LRESULT WINAPI ButtonWndProc_common(HWND hWnd, UINT uMsg,
236 WPARAM wParam, LPARAM lParam, BOOL unicode )
237 {
238 RECT rect;
239 POINT pt;
240 LONG style = GetWindowLongPtrW( hWnd, GWL_STYLE );
241 UINT btn_type = get_button_type( style );
242 LONG state;
243 HANDLE oldHbitmap;
244 #ifdef __REACTOS__
245 PWND pWnd;
246
247 pWnd = ValidateHwnd(hWnd);
248 if (pWnd)
249 {
250 if (!pWnd->fnid)
251 {
252 NtUserSetWindowFNID(hWnd, FNID_BUTTON);
253 }
254 else
255 {
256 if (pWnd->fnid != FNID_BUTTON)
257 {
258 ERR("Wrong window class for Button! fnId 0x%x\n",pWnd->fnid);
259 return 0;
260 }
261 }
262 }
263 #endif
264
265 pt.x = (short)LOWORD(lParam);
266 pt.y = (short)HIWORD(lParam);
267
268 switch (uMsg)
269 {
270 case WM_GETDLGCODE:
271 switch(btn_type)
272 {
273 case BS_USERBUTTON:
274 case BS_PUSHBUTTON: return DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON;
275 case BS_DEFPUSHBUTTON: return DLGC_BUTTON | DLGC_DEFPUSHBUTTON;
276 case BS_RADIOBUTTON:
277 case BS_AUTORADIOBUTTON: return DLGC_BUTTON | DLGC_RADIOBUTTON;
278 case BS_GROUPBOX: return DLGC_STATIC;
279 default: return DLGC_BUTTON;
280 }
281
282 case WM_ENABLE:
283 paint_button( hWnd, btn_type, ODA_DRAWENTIRE );
284 break;
285
286 case WM_CREATE:
287 if (!hbitmapCheckBoxes)
288 {
289 BITMAP bmp;
290 hbitmapCheckBoxes = LoadBitmapW(0, MAKEINTRESOURCEW(OBM_CHECKBOXES));
291 GetObjectW( hbitmapCheckBoxes, sizeof(bmp), &bmp );
292 checkBoxWidth = bmp.bmWidth / 4;
293 checkBoxHeight = bmp.bmHeight / 3;
294 }
295 if (btn_type >= MAX_BTN_TYPE)
296 return -1; /* abort */
297
298 /* XP turns a BS_USERBUTTON into BS_PUSHBUTTON */
299 if (btn_type == BS_USERBUTTON )
300 {
301 #ifdef __REACTOS__
302 style = (style & ~BS_TYPEMASK) | BS_PUSHBUTTON;
303 SetWindowLongPtrW( hWnd, GWL_STYLE, style );
304 #else
305 style = (style & ~BS_TYPEMASK) | BS_PUSHBUTTON;
306 WIN_SetStyle( hWnd, style, BS_TYPEMASK & ~style );
307 #endif
308 }
309 set_button_state( hWnd, BST_UNCHECKED );
310 button_update_uistate( hWnd, unicode );
311 return 0;
312
313 #ifdef __REACTOS__
314 case WM_NCDESTROY:
315 NtUserSetWindowFNID(hWnd, FNID_DESTROY);
316 case WM_DESTROY:
317 break;
318 #endif
319
320 case WM_ERASEBKGND:
321 if (btn_type == BS_OWNERDRAW)
322 {
323 HDC hdc = (HDC)wParam;
324 RECT rc;
325 HBRUSH hBrush;
326 HWND parent = GetParent(hWnd);
327 if (!parent) parent = hWnd;
328 hBrush = GetControlColor( parent, hWnd, hdc, WM_CTLCOLORBTN);
329 GetClientRect(hWnd, &rc);
330 FillRect(hdc, &rc, hBrush);
331 }
332 return 1;
333
334 case WM_PRINTCLIENT:
335 case WM_PAINT:
336 if (btnPaintFunc[btn_type])
337 {
338 PAINTSTRUCT ps;
339 HDC hdc = wParam ? (HDC)wParam : BeginPaint( hWnd, &ps );
340 int nOldMode = SetBkMode( hdc, OPAQUE );
341 (btnPaintFunc[btn_type])( hWnd, hdc, ODA_DRAWENTIRE );
342 SetBkMode(hdc, nOldMode); /* reset painting mode */
343 if( !wParam ) EndPaint( hWnd, &ps );
344 }
345 break;
346
347 case WM_KEYDOWN:
348 if (wParam == VK_SPACE)
349 {
350 SendMessageW( hWnd, BM_SETSTATE, TRUE, 0 );
351 set_button_state( hWnd, get_button_state( hWnd ) | BUTTON_BTNPRESSED );
352 SetCapture( hWnd );
353 }
354 break;
355
356 case WM_LBUTTONDBLCLK:
357 if(style & BS_NOTIFY ||
358 btn_type == BS_RADIOBUTTON ||
359 btn_type == BS_USERBUTTON ||
360 btn_type == BS_OWNERDRAW)
361 {
362 BUTTON_NOTIFY_PARENT(hWnd, BN_DOUBLECLICKED);
363 break;
364 }
365 /* fall through */
366 case WM_LBUTTONDOWN:
367 SetCapture( hWnd );
368 SetFocus( hWnd );
369 set_button_state( hWnd, get_button_state( hWnd ) | BUTTON_BTNPRESSED );
370 SendMessageW( hWnd, BM_SETSTATE, TRUE, 0 );
371 break;
372
373 case WM_KEYUP:
374 if (wParam != VK_SPACE)
375 break;
376 /* fall through */
377 case WM_LBUTTONUP:
378 state = get_button_state( hWnd );
379 if (!(state & BUTTON_BTNPRESSED)) break;
380 state &= BUTTON_NSTATES;
381 set_button_state( hWnd, state );
382 if (!(state & BST_PUSHED))
383 {
384 ReleaseCapture();
385 break;
386 }
387 SendMessageW( hWnd, BM_SETSTATE, FALSE, 0 );
388 ReleaseCapture();
389 GetClientRect( hWnd, &rect );
390 if (uMsg == WM_KEYUP || PtInRect( &rect, pt ))
391 {
392 state = get_button_state( hWnd );
393 switch(btn_type)
394 {
395 case BS_AUTOCHECKBOX:
396 SendMessageW( hWnd, BM_SETCHECK, !(state & BST_CHECKED), 0 );
397 break;
398 case BS_AUTORADIOBUTTON:
399 SendMessageW( hWnd, BM_SETCHECK, TRUE, 0 );
400 break;
401 case BS_AUTO3STATE:
402 SendMessageW( hWnd, BM_SETCHECK,
403 (state & BST_INDETERMINATE) ? 0 : ((state & 3) + 1), 0 );
404 break;
405 }
406 BUTTON_NOTIFY_PARENT(hWnd, BN_CLICKED);
407 }
408 break;
409
410 case WM_CAPTURECHANGED:
411 TRACE("WM_CAPTURECHANGED %p\n", hWnd);
412 state = get_button_state( hWnd );
413 if (state & BUTTON_BTNPRESSED)
414 {
415 state &= BUTTON_NSTATES;
416 set_button_state( hWnd, state );
417 if (state & BST_PUSHED) SendMessageW( hWnd, BM_SETSTATE, FALSE, 0 );
418 }
419 break;
420
421 case WM_MOUSEMOVE:
422 if ((wParam & MK_LBUTTON) && GetCapture() == hWnd)
423 {
424 GetClientRect( hWnd, &rect );
425 SendMessageW( hWnd, BM_SETSTATE, PtInRect(&rect, pt), 0 );
426 }
427 break;
428
429 case WM_SETTEXT:
430 {
431 /* Clear an old text here as Windows does */
432 //
433 // wine Bug: http://bugs.winehq.org/show_bug.cgi?id=25790
434 // Patch: http://source.winehq.org/patches/data/70889
435 // By: Alexander LAW, Replicate Windows behavior of WM_SETTEXT handler regarding WM_CTLCOLOR*
436 //
437 if (style & WS_VISIBLE)
438 {
439 HDC hdc = GetDC(hWnd);
440 HBRUSH hbrush;
441 RECT client, rc;
442 HWND parent = GetParent(hWnd);
443 UINT ctlMessage=(btn_type == BS_PUSHBUTTON ||
444 btn_type == BS_DEFPUSHBUTTON ||
445 btn_type == BS_PUSHLIKE ||
446 btn_type == BS_USERBUTTON ||
447 btn_type == BS_OWNERDRAW) ?
448 WM_CTLCOLORBTN : WM_CTLCOLORSTATIC;
449
450 if (!parent) parent = hWnd;
451
452 hbrush = GetControlColor( parent, hWnd, hdc, ctlMessage);
453
454 GetClientRect(hWnd, &client);
455 rc = client;
456 BUTTON_CalcLabelRect(hWnd, hdc, &rc);
457 /* Clip by client rect bounds */
458 if (rc.right > client.right) rc.right = client.right;
459 if (rc.bottom > client.bottom) rc.bottom = client.bottom;
460 FillRect(hdc, &rc, hbrush);
461 ReleaseDC(hWnd, hdc);
462 }
463 ////
464 if (unicode) DefWindowProcW( hWnd, WM_SETTEXT, wParam, lParam );
465 else DefWindowProcA( hWnd, WM_SETTEXT, wParam, lParam );
466 if (btn_type == BS_GROUPBOX) /* Yes, only for BS_GROUPBOX */
467 InvalidateRect( hWnd, NULL, TRUE );
468 else
469 paint_button( hWnd, btn_type, ODA_DRAWENTIRE );
470 return 1; /* success. FIXME: check text length */
471 }
472
473 case WM_SETFONT:
474 set_button_font( hWnd, (HFONT)wParam );
475 if (lParam) InvalidateRect(hWnd, NULL, TRUE);
476 break;
477
478 case WM_GETFONT:
479 return (LRESULT)get_button_font( hWnd );
480
481 case WM_SETFOCUS:
482 TRACE("WM_SETFOCUS %p\n",hWnd);
483 set_button_state( hWnd, get_button_state(hWnd) | BST_FOCUS );
484 paint_button( hWnd, btn_type, ODA_FOCUS );
485 if (style & BS_NOTIFY)
486 BUTTON_NOTIFY_PARENT(hWnd, BN_SETFOCUS);
487 break;
488
489 case WM_KILLFOCUS:
490 TRACE("WM_KILLFOCUS %p\n",hWnd);
491 state = get_button_state( hWnd );
492 set_button_state( hWnd, state & ~BST_FOCUS );
493 paint_button( hWnd, btn_type, ODA_FOCUS );
494
495 if ((state & BUTTON_BTNPRESSED) && GetCapture() == hWnd)
496 ReleaseCapture();
497 if (style & BS_NOTIFY)
498 BUTTON_NOTIFY_PARENT(hWnd, BN_KILLFOCUS);
499
500 InvalidateRect( hWnd, NULL, FALSE );
501 break;
502
503 case WM_SYSCOLORCHANGE:
504 InvalidateRect( hWnd, NULL, FALSE );
505 break;
506
507 case BM_SETSTYLE:
508 if ((wParam & BS_TYPEMASK) >= MAX_BTN_TYPE) break;
509 btn_type = wParam & BS_TYPEMASK;
510 style = (style & ~BS_TYPEMASK) | btn_type;
511 SetWindowLongPtrW( hWnd, GWL_STYLE, style );
512 //WIN_SetStyle( hWnd, style, BS_TYPEMASK & ~style );
513
514 /* Only redraw if lParam flag is set.*/
515 if (lParam)
516 InvalidateRect( hWnd, NULL, TRUE );
517
518 break;
519
520 case BM_CLICK:
521 //// ReactOS
522 state = get_button_state( hWnd );
523 if (state & BUTTON_BMCLICK)
524 break;
525 set_button_state( hWnd, state | BUTTON_BMCLICK ); // Tracked in STATE_GWL_OFFSET.
526 ////
527 SendMessageW( hWnd, WM_LBUTTONDOWN, 0, 0 );
528 SendMessageW( hWnd, WM_LBUTTONUP, 0, 0 );
529 ////
530 state = get_button_state( hWnd );
531 if (!(state & BUTTON_BMCLICK)) break;
532 state &= ~BUTTON_BMCLICK;
533 set_button_state( hWnd, state );
534 ////
535 break;
536
537 case BM_SETIMAGE:
538 /* Check that image format matches button style */
539 switch (style & (BS_BITMAP|BS_ICON))
540 {
541 case BS_BITMAP:
542 if (wParam != IMAGE_BITMAP) return 0;
543 break;
544 case BS_ICON:
545 if (wParam != IMAGE_ICON) return 0;
546 break;
547 default:
548 return 0;
549 }
550 oldHbitmap = (HBITMAP)SetWindowLongPtrW( hWnd, HIMAGE_GWL_OFFSET, lParam );
551 InvalidateRect( hWnd, NULL, FALSE );
552 return (LRESULT)oldHbitmap;
553
554 case BM_GETIMAGE:
555 return GetWindowLongPtrW( hWnd, HIMAGE_GWL_OFFSET );
556
557 case BM_GETCHECK:
558 return get_button_state( hWnd ) & 3;
559
560 case BM_SETCHECK:
561 if (wParam > maxCheckState[btn_type]) wParam = maxCheckState[btn_type];
562 state = get_button_state( hWnd );
563 if ((btn_type == BS_RADIOBUTTON) || (btn_type == BS_AUTORADIOBUTTON))
564 {
565 #ifdef __REACTOS__
566 if (wParam) style |= WS_TABSTOP;
567 else style &= ~WS_TABSTOP;
568 SetWindowLongPtrW( hWnd, GWL_STYLE, style );
569 #else
570 if (wParam) WIN_SetStyle( hWnd, WS_TABSTOP, 0 );
571 else WIN_SetStyle( hWnd, 0, WS_TABSTOP );
572 #endif
573 }
574 if ((state & 3) != wParam)
575 {
576 set_button_state( hWnd, (state & ~3) | wParam );
577 paint_button( hWnd, btn_type, ODA_SELECT );
578 }
579 if ((btn_type == BS_AUTORADIOBUTTON) && (wParam == BST_CHECKED) && (style & WS_CHILD))
580 BUTTON_CheckAutoRadioButton( hWnd );
581 break;
582
583 case BM_GETSTATE:
584 return get_button_state( hWnd );
585
586 case BM_SETSTATE:
587 state = get_button_state( hWnd );
588 if (wParam)
589 set_button_state( hWnd, state | BST_PUSHED );
590 else
591 set_button_state( hWnd, state & ~BST_PUSHED );
592
593 paint_button( hWnd, btn_type, ODA_SELECT );
594 break;
595
596 case WM_UPDATEUISTATE:
597 if (unicode)
598 DefWindowProcW(hWnd, uMsg, wParam, lParam);
599 else
600 DefWindowProcA(hWnd, uMsg, wParam, lParam);
601
602 if (button_update_uistate(hWnd, unicode))
603 paint_button( hWnd, btn_type, ODA_DRAWENTIRE );
604 break;
605
606 case WM_NCHITTEST:
607 if(btn_type == BS_GROUPBOX) return HTTRANSPARENT;
608 /* fall through */
609 default:
610 return unicode ? DefWindowProcW(hWnd, uMsg, wParam, lParam) :
611 DefWindowProcA(hWnd, uMsg, wParam, lParam);
612 }
613 return 0;
614 }
615
616 /***********************************************************************
617 * ButtonWndProcW
618 * The button window procedure. This is just a wrapper which locks
619 * the passed HWND and calls the real window procedure (with a WND*
620 * pointer pointing to the locked windowstructure).
621 */
622 LRESULT WINAPI ButtonWndProcW( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
623 {
624 if (!IsWindow( hWnd )) return 0;
625 return ButtonWndProc_common( hWnd, uMsg, wParam, lParam, TRUE );
626 }
627
628
629 /***********************************************************************
630 * ButtonWndProcA
631 */
632 LRESULT WINAPI ButtonWndProcA( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
633 {
634 if (!IsWindow( hWnd )) return 0;
635 return ButtonWndProc_common( hWnd, uMsg, wParam, lParam, FALSE );
636 }
637
638
639 /**********************************************************************
640 * Convert button styles to flags used by DrawText.
641 */
642 static UINT BUTTON_BStoDT( DWORD style, DWORD ex_style )
643 {
644 UINT dtStyle = DT_NOCLIP; /* We use SelectClipRgn to limit output */
645
646 /* "Convert" pushlike buttons to pushbuttons */
647 if (style & BS_PUSHLIKE)
648 style &= ~BS_TYPEMASK;
649
650 if (!(style & BS_MULTILINE))
651 dtStyle |= DT_SINGLELINE;
652 else
653 dtStyle |= DT_WORDBREAK;
654
655 switch (style & BS_CENTER)
656 {
657 case BS_LEFT: /* DT_LEFT is 0 */ break;
658 case BS_RIGHT: dtStyle |= DT_RIGHT; break;
659 case BS_CENTER: dtStyle |= DT_CENTER; break;
660 default:
661 /* Pushbutton's text is centered by default */
662 if (get_button_type(style) <= BS_DEFPUSHBUTTON) dtStyle |= DT_CENTER;
663 /* all other flavours have left aligned text */
664 }
665
666 if (ex_style & WS_EX_RIGHT) dtStyle = DT_RIGHT | (dtStyle & ~(DT_LEFT | DT_CENTER));
667
668 /* DrawText ignores vertical alignment for multiline text,
669 * but we use these flags to align label manually.
670 */
671 if (get_button_type(style) != BS_GROUPBOX)
672 {
673 switch (style & BS_VCENTER)
674 {
675 case BS_TOP: /* DT_TOP is 0 */ break;
676 case BS_BOTTOM: dtStyle |= DT_BOTTOM; break;
677 case BS_VCENTER: /* fall through */
678 default: dtStyle |= DT_VCENTER; break;
679 }
680 }
681 else
682 /* GroupBox's text is always single line and is top aligned. */
683 dtStyle |= DT_SINGLELINE;
684
685 return dtStyle;
686 }
687
688 /**********************************************************************
689 * BUTTON_CalcLabelRect
690 *
691 * Calculates label's rectangle depending on button style.
692 *
693 * Returns flags to be passed to DrawText.
694 * Calculated rectangle doesn't take into account button state
695 * (pushed, etc.). If there is nothing to draw (no text/image) output
696 * rectangle is empty, and return value is (UINT)-1.
697 */
698 static UINT BUTTON_CalcLabelRect(HWND hwnd, HDC hdc, RECT *rc)
699 {
700 LONG style = GetWindowLongPtrW( hwnd, GWL_STYLE );
701 LONG ex_style = GetWindowLongPtrW( hwnd, GWL_EXSTYLE );
702 WCHAR *text;
703 ICONINFO iconInfo;
704 BITMAP bm;
705 UINT dtStyle = BUTTON_BStoDT( style, ex_style );
706 RECT r = *rc;
707 INT n;
708
709 /* Calculate label rectangle according to label type */
710 switch (style & (BS_ICON|BS_BITMAP))
711 {
712 case BS_TEXT:
713 if (!(text = get_button_text( hwnd ))) goto empty_rect;
714 if (!text[0])
715 {
716 HeapFree( GetProcessHeap(), 0, text );
717 goto empty_rect;
718 }
719 DrawTextW(hdc, text, -1, &r, dtStyle | DT_CALCRECT);
720 HeapFree( GetProcessHeap(), 0, text );
721
722 if (get_ui_state( hwnd ) & UISF_HIDEACCEL)
723 dtStyle |= DT_HIDEPREFIX;
724 break;
725
726 case BS_ICON:
727 if (!GetIconInfo((HICON)GetWindowLongPtrW( hwnd, HIMAGE_GWL_OFFSET ), &iconInfo))
728 goto empty_rect;
729
730 GetObjectW (iconInfo.hbmColor, sizeof(BITMAP), &bm);
731
732 r.right = r.left + bm.bmWidth;
733 r.bottom = r.top + bm.bmHeight;
734
735 DeleteObject(iconInfo.hbmColor);
736 DeleteObject(iconInfo.hbmMask);
737 break;
738
739 case BS_BITMAP:
740 if (!GetObjectW( (HANDLE)GetWindowLongPtrW( hwnd, HIMAGE_GWL_OFFSET ), sizeof(BITMAP), &bm))
741 goto empty_rect;
742
743 r.right = r.left + bm.bmWidth;
744 r.bottom = r.top + bm.bmHeight;
745 break;
746
747 default:
748 empty_rect:
749 rc->right = r.left;
750 rc->bottom = r.top;
751 return (UINT)-1;
752 }
753
754 /* Position label inside bounding rectangle according to
755 * alignment flags. (calculated rect is always left-top aligned).
756 * If label is aligned to any side - shift label in opposite
757 * direction to leave extra space for focus rectangle.
758 */
759 switch (dtStyle & (DT_CENTER|DT_RIGHT))
760 {
761 case DT_LEFT: r.left++; r.right++; break;
762 case DT_CENTER: n = r.right - r.left;
763 r.left = rc->left + ((rc->right - rc->left) - n) / 2;
764 r.right = r.left + n; break;
765 case DT_RIGHT: n = r.right - r.left;
766 r.right = rc->right - 1;
767 r.left = r.right - n;
768 break;
769 }
770
771 switch (dtStyle & (DT_VCENTER|DT_BOTTOM))
772 {
773 case DT_TOP: r.top++; r.bottom++; break;
774 case DT_VCENTER: n = r.bottom - r.top;
775 r.top = rc->top + ((rc->bottom - rc->top) - n) / 2;
776 r.bottom = r.top + n; break;
777 case DT_BOTTOM: n = r.bottom - r.top;
778 r.bottom = rc->bottom - 1;
779 r.top = r.bottom - n;
780 break;
781 }
782
783 *rc = r;
784 return dtStyle;
785 }
786
787
788 /**********************************************************************
789 * BUTTON_DrawTextCallback
790 *
791 * Callback function used by DrawStateW function.
792 */
793 static BOOL CALLBACK BUTTON_DrawTextCallback(HDC hdc, LPARAM lp, WPARAM wp, int cx, int cy)
794 {
795 RECT rc;
796 rc.left = 0;
797 rc.top = 0;
798 rc.right = cx;
799 rc.bottom = cy;
800
801 DrawTextW(hdc, (LPCWSTR)lp, -1, &rc, (UINT)wp);
802 return TRUE;
803 }
804
805
806 /**********************************************************************
807 * BUTTON_DrawLabel
808 *
809 * Common function for drawing button label.
810 */
811 static void BUTTON_DrawLabel(HWND hwnd, HDC hdc, UINT dtFlags, const RECT *rc)
812 {
813 DRAWSTATEPROC lpOutputProc = NULL;
814 LPARAM lp;
815 WPARAM wp = 0;
816 HBRUSH hbr = 0;
817 UINT flags = IsWindowEnabled(hwnd) ? DSS_NORMAL : DSS_DISABLED;
818 LONG state = get_button_state( hwnd );
819 LONG style = GetWindowLongPtrW( hwnd, GWL_STYLE );
820 WCHAR *text = NULL;
821
822 /* FIXME: To draw disabled label in Win31 look-and-feel, we probably
823 * must use DSS_MONO flag and COLOR_GRAYTEXT brush (or maybe DSS_UNION).
824 * I don't have Win31 on hand to verify that, so I leave it as is.
825 */
826
827 if ((style & BS_PUSHLIKE) && (state & BST_INDETERMINATE))
828 {
829 hbr = GetSysColorBrush(COLOR_GRAYTEXT);
830 flags |= DSS_MONO;
831 }
832
833 switch (style & (BS_ICON|BS_BITMAP))
834 {
835 case BS_TEXT:
836 /* DST_COMPLEX -- is 0 */
837 lpOutputProc = BUTTON_DrawTextCallback;
838 if (!(text = get_button_text( hwnd ))) return;
839 lp = (LPARAM)text;
840 wp = (WPARAM)dtFlags;
841
842 if (dtFlags & DT_HIDEPREFIX)
843 flags |= DSS_HIDEPREFIX;
844 break;
845
846 case BS_ICON:
847 flags |= DST_ICON;
848 lp = GetWindowLongPtrW( hwnd, HIMAGE_GWL_OFFSET );
849 break;
850
851 case BS_BITMAP:
852 flags |= DST_BITMAP;
853 lp = GetWindowLongPtrW( hwnd, HIMAGE_GWL_OFFSET );
854 break;
855
856 default:
857 return;
858 }
859
860 DrawStateW(hdc, hbr, lpOutputProc, lp, wp, rc->left, rc->top,
861 rc->right - rc->left, rc->bottom - rc->top, flags);
862 HeapFree( GetProcessHeap(), 0, text );
863 }
864
865 /**********************************************************************
866 * Push Button Functions
867 */
868 static void PB_Paint( HWND hwnd, HDC hDC, UINT action )
869 {
870 RECT rc, r;
871 UINT dtFlags, uState;
872 HPEN hOldPen;
873 HBRUSH hOldBrush;
874 INT oldBkMode;
875 COLORREF oldTxtColor;
876 HFONT hFont;
877 LONG state = get_button_state( hwnd );
878 LONG style = GetWindowLongPtrW( hwnd, GWL_STYLE );
879 BOOL pushedState = (state & BST_PUSHED);
880 HWND parent;
881 HRGN hrgn;
882
883 GetClientRect( hwnd, &rc );
884
885 /* Send WM_CTLCOLOR to allow changing the font (the colors are fixed) */
886 if ((hFont = get_button_font( hwnd ))) SelectObject( hDC, hFont );
887 parent = GetParent(hwnd);
888 if (!parent) parent = hwnd;
889 GetControlColor( parent, hwnd, hDC, WM_CTLCOLORBTN);
890
891 hrgn = set_control_clipping( hDC, &rc );
892 #ifdef __REACTOS__
893 hOldPen = SelectObject(hDC, GetStockObject(DC_PEN));
894 SetDCPenColor(hDC, GetSysColor(COLOR_WINDOWFRAME));
895 #else
896 hOldPen = SelectObject(hDC, SYSCOLOR_GetPen(COLOR_WINDOWFRAME));
897 #endif
898 hOldBrush = SelectObject(hDC,GetSysColorBrush(COLOR_BTNFACE));
899 oldBkMode = SetBkMode(hDC, TRANSPARENT);
900
901 if (get_button_type(style) == BS_DEFPUSHBUTTON)
902 {
903 if (action != ODA_FOCUS)
904 Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom);
905 InflateRect( &rc, -1, -1 );
906 }
907
908 /* completely skip the drawing if only focus has changed */
909 if (action == ODA_FOCUS) goto draw_focus;
910
911 uState = DFCS_BUTTONPUSH;
912
913 if (style & BS_FLAT)
914 uState |= DFCS_MONO;
915 else if (pushedState)
916 {
917 if (get_button_type(style) == BS_DEFPUSHBUTTON )
918 uState |= DFCS_FLAT;
919 else
920 uState |= DFCS_PUSHED;
921 }
922
923 if (state & (BST_CHECKED | BST_INDETERMINATE))
924 uState |= DFCS_CHECKED;
925
926 DrawFrameControl( hDC, &rc, DFC_BUTTON, uState );
927
928 /* draw button label */
929 r = rc;
930 dtFlags = BUTTON_CalcLabelRect(hwnd, hDC, &r);
931
932 if (dtFlags == (UINT)-1L)
933 goto cleanup;
934
935 if (pushedState)
936 OffsetRect(&r, 1, 1);
937
938 oldTxtColor = SetTextColor( hDC, GetSysColor(COLOR_BTNTEXT) );
939
940 BUTTON_DrawLabel(hwnd, hDC, dtFlags, &r);
941
942 SetTextColor( hDC, oldTxtColor );
943
944 draw_focus:
945 if (action == ODA_FOCUS || (state & BST_FOCUS))
946 {
947 if (!(get_ui_state(hwnd) & UISF_HIDEFOCUS))
948 {
949 InflateRect( &rc, -2, -2 );
950 DrawFocusRect( hDC, &rc );
951 }
952 }
953
954 cleanup:
955 SelectObject( hDC, hOldPen );
956 SelectObject( hDC, hOldBrush );
957 SetBkMode(hDC, oldBkMode);
958 SelectClipRgn( hDC, hrgn );
959 if (hrgn) DeleteObject( hrgn );
960 }
961
962 /**********************************************************************
963 * Check Box & Radio Button Functions
964 */
965
966 static void CB_Paint( HWND hwnd, HDC hDC, UINT action )
967 {
968 RECT rbox, rtext, client;
969 HBRUSH hBrush;
970 int delta;
971 UINT dtFlags;
972 HFONT hFont;
973 LONG state = get_button_state( hwnd );
974 LONG style = GetWindowLongPtrW( hwnd, GWL_STYLE );
975 HWND parent;
976 HRGN hrgn;
977
978 if (style & BS_PUSHLIKE)
979 {
980 PB_Paint( hwnd, hDC, action );
981 return;
982 }
983
984 GetClientRect(hwnd, &client);
985 rbox = rtext = client;
986
987 if ((hFont = get_button_font( hwnd ))) SelectObject( hDC, hFont );
988
989 parent = GetParent(hwnd);
990 if (!parent) parent = hwnd;
991 hBrush = GetControlColor( parent, hwnd, hDC, WM_CTLCOLORSTATIC);
992 hrgn = set_control_clipping( hDC, &client );
993
994 if (style & BS_LEFTTEXT)
995 {
996 /* magic +4 is what CTL3D expects */
997
998 rtext.right -= checkBoxWidth + 4;
999 rbox.left = rbox.right - checkBoxWidth;
1000 }
1001 else
1002 {
1003 rtext.left += checkBoxWidth + 4;
1004 rbox.right = checkBoxWidth;
1005 }
1006
1007 /* Since WM_ERASEBKGND does nothing, first prepare background */
1008 if (action == ODA_SELECT) FillRect( hDC, &rbox, hBrush );
1009 if (action == ODA_DRAWENTIRE) FillRect( hDC, &client, hBrush );
1010
1011 /* Draw label */
1012 client = rtext;
1013 dtFlags = BUTTON_CalcLabelRect(hwnd, hDC, &rtext);
1014
1015 /* Only adjust rbox when rtext is valid */
1016 if (dtFlags != (UINT)-1L)
1017 {
1018 rbox.top = rtext.top;
1019 rbox.bottom = rtext.bottom;
1020 }
1021
1022 /* Draw the check-box bitmap */
1023 if (action == ODA_DRAWENTIRE || action == ODA_SELECT)
1024 {
1025 UINT flags;
1026
1027 if ((get_button_type(style) == BS_RADIOBUTTON) ||
1028 (get_button_type(style) == BS_AUTORADIOBUTTON)) flags = DFCS_BUTTONRADIO;
1029 else if (state & BST_INDETERMINATE) flags = DFCS_BUTTON3STATE;
1030 else flags = DFCS_BUTTONCHECK;
1031
1032 if (state & (BST_CHECKED | BST_INDETERMINATE)) flags |= DFCS_CHECKED;
1033 if (state & BST_PUSHED) flags |= DFCS_PUSHED;
1034
1035 if (style & WS_DISABLED) flags |= DFCS_INACTIVE;
1036
1037 /* rbox must have the correct height */
1038 delta = rbox.bottom - rbox.top - checkBoxHeight;
1039
1040 if (style & BS_TOP) {
1041 if (delta > 0) {
1042 rbox.bottom = rbox.top + checkBoxHeight;
1043 } else {
1044 rbox.top -= -delta/2 + 1;
1045 rbox.bottom = rbox.top + checkBoxHeight;
1046 }
1047 } else if (style & BS_BOTTOM) {
1048 if (delta > 0) {
1049 rbox.top = rbox.bottom - checkBoxHeight;
1050 } else {
1051 rbox.bottom += -delta/2 + 1;
1052 rbox.top = rbox.bottom - checkBoxHeight;
1053 }
1054 } else { /* Default */
1055 if (delta > 0) {
1056 int ofs = (delta / 2);
1057 rbox.bottom -= ofs + 1;
1058 rbox.top = rbox.bottom - checkBoxHeight;
1059 } else if (delta < 0) {
1060 int ofs = (-delta / 2);
1061 rbox.top -= ofs + 1;
1062 rbox.bottom = rbox.top + checkBoxHeight;
1063 }
1064 }
1065
1066 DrawFrameControl( hDC, &rbox, DFC_BUTTON, flags );
1067 }
1068
1069 if (dtFlags == (UINT)-1L) /* Noting to draw */
1070 return;
1071
1072 if (action == ODA_DRAWENTIRE)
1073 BUTTON_DrawLabel(hwnd, hDC, dtFlags, &rtext);
1074
1075 /* ... and focus */
1076 if (action == ODA_FOCUS || (state & BST_FOCUS))
1077 {
1078 if (!(get_ui_state(hwnd) & UISF_HIDEFOCUS))
1079 {
1080 rtext.left--;
1081 rtext.right++;
1082 IntersectRect(&rtext, &rtext, &client);
1083 DrawFocusRect( hDC, &rtext );
1084 }
1085 }
1086 SelectClipRgn( hDC, hrgn );
1087 if (hrgn) DeleteObject( hrgn );
1088 }
1089
1090
1091 /**********************************************************************
1092 * BUTTON_CheckAutoRadioButton
1093 *
1094 * hwnd is checked, uncheck every other auto radio button in group
1095 */
1096 static void BUTTON_CheckAutoRadioButton( HWND hwnd )
1097 {
1098 HWND parent, sibling, start;
1099
1100 parent = GetParent(hwnd);
1101 /* make sure that starting control is not disabled or invisible */
1102 start = sibling = GetNextDlgGroupItem( parent, hwnd, TRUE );
1103 do
1104 {
1105 if (!sibling) break;
1106 if ((hwnd != sibling) &&
1107 ((GetWindowLongPtrW( sibling, GWL_STYLE) & BS_TYPEMASK) == BS_AUTORADIOBUTTON))
1108 SendMessageW( sibling, BM_SETCHECK, BST_UNCHECKED, 0 );
1109 sibling = GetNextDlgGroupItem( parent, sibling, FALSE );
1110 } while (sibling != start);
1111 }
1112
1113
1114 /**********************************************************************
1115 * Group Box Functions
1116 */
1117
1118 static void GB_Paint( HWND hwnd, HDC hDC, UINT action )
1119 {
1120 RECT rc, rcFrame;
1121 HBRUSH hbr;
1122 HFONT hFont;
1123 UINT dtFlags;
1124 TEXTMETRICW tm;
1125 LONG style = GetWindowLongPtrW( hwnd, GWL_STYLE );
1126 HWND parent;
1127 HRGN hrgn;
1128
1129 if ((hFont = get_button_font( hwnd ))) SelectObject( hDC, hFont );
1130 /* GroupBox acts like static control, so it sends CTLCOLORSTATIC */
1131 parent = GetParent(hwnd);
1132 if (!parent) parent = hwnd;
1133 hbr = GetControlColor( parent, hwnd, hDC, WM_CTLCOLORSTATIC);
1134
1135 GetClientRect( hwnd, &rc);
1136 rcFrame = rc;
1137 hrgn = set_control_clipping( hDC, &rc );
1138
1139 GetTextMetricsW (hDC, &tm);
1140 rcFrame.top += (tm.tmHeight / 2) - 1;
1141 DrawEdge (hDC, &rcFrame, EDGE_ETCHED, BF_RECT | ((style & BS_FLAT) ? BF_FLAT : 0));
1142
1143 InflateRect(&rc, -7, 1);
1144 dtFlags = BUTTON_CalcLabelRect(hwnd, hDC, &rc);
1145
1146 if (dtFlags != (UINT)-1L)
1147 {
1148 /* Because buttons have CS_PARENTDC class style, there is a chance
1149 * that label will be drawn out of client rect.
1150 * But Windows doesn't clip label's rect, so do I.
1151 */
1152
1153 /* There is 1-pixel margin at the left, right, and bottom */
1154 rc.left--; rc.right++; rc.bottom++;
1155 FillRect(hDC, &rc, hbr);
1156 rc.left++; rc.right--; rc.bottom--;
1157
1158 BUTTON_DrawLabel(hwnd, hDC, dtFlags, &rc);
1159 }
1160 SelectClipRgn( hDC, hrgn );
1161 if (hrgn) DeleteObject( hrgn );
1162 }
1163
1164
1165 /**********************************************************************
1166 * User Button Functions
1167 */
1168
1169 static void UB_Paint( HWND hwnd, HDC hDC, UINT action )
1170 {
1171 RECT rc;
1172 HBRUSH hBrush;
1173 HFONT hFont;
1174 LONG state = get_button_state( hwnd );
1175 HWND parent;
1176
1177 GetClientRect( hwnd, &rc);
1178
1179 if ((hFont = get_button_font( hwnd ))) SelectObject( hDC, hFont );
1180
1181 parent = GetParent(hwnd);
1182 if (!parent) parent = hwnd;
1183 hBrush = GetControlColor( parent, hwnd, hDC, WM_CTLCOLORBTN);
1184
1185 FillRect( hDC, &rc, hBrush );
1186 if (action == ODA_FOCUS || (state & BST_FOCUS))
1187 {
1188 if (!(get_ui_state(hwnd) & UISF_HIDEFOCUS))
1189 DrawFocusRect( hDC, &rc );
1190 }
1191
1192 switch (action)
1193 {
1194 case ODA_FOCUS:
1195 BUTTON_NOTIFY_PARENT( hwnd, (state & BST_FOCUS) ? BN_SETFOCUS : BN_KILLFOCUS );
1196 break;
1197
1198 case ODA_SELECT:
1199 BUTTON_NOTIFY_PARENT( hwnd, (state & BST_PUSHED) ? BN_HILITE : BN_UNHILITE );
1200 break;
1201
1202 default:
1203 BUTTON_NOTIFY_PARENT( hwnd, BN_PAINT );
1204 break;
1205 }
1206 }
1207
1208
1209 /**********************************************************************
1210 * Ownerdrawn Button Functions
1211 */
1212
1213 static void OB_Paint( HWND hwnd, HDC hDC, UINT action )
1214 {
1215 LONG state = get_button_state( hwnd );
1216 DRAWITEMSTRUCT dis;
1217 LONG_PTR id = GetWindowLongPtrW( hwnd, GWLP_ID );
1218 HWND parent;
1219 HFONT hFont, hPrevFont = 0;
1220 HRGN hrgn;
1221
1222 dis.CtlType = ODT_BUTTON;
1223 dis.CtlID = id;
1224 dis.itemID = 0;
1225 dis.itemAction = action;
1226 dis.itemState = ((state & BST_FOCUS) ? ODS_FOCUS : 0) |
1227 ((state & BST_PUSHED) ? ODS_SELECTED : 0) |
1228 (IsWindowEnabled(hwnd) ? 0: ODS_DISABLED);
1229 dis.hwndItem = hwnd;
1230 dis.hDC = hDC;
1231 dis.itemData = 0;
1232 GetClientRect( hwnd, &dis.rcItem );
1233
1234 if ((hFont = get_button_font( hwnd ))) hPrevFont = SelectObject( hDC, hFont );
1235 parent = GetParent(hwnd);
1236 if (!parent) parent = hwnd;
1237 GetControlColor( parent, hwnd, hDC, WM_CTLCOLORBTN);
1238
1239 hrgn = set_control_clipping( hDC, &dis.rcItem );
1240
1241 SendMessageW( GetParent(hwnd), WM_DRAWITEM, id, (LPARAM)&dis );
1242 if (hPrevFont) SelectObject(hDC, hPrevFont);
1243 SelectClipRgn( hDC, hrgn );
1244 if (hrgn) DeleteObject( hrgn );
1245 }