a62ef6e789cb7c190ceca64d8ed27a8bc6a07803
[reactos.git] / dll / win32 / comctl32 / 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 "comctl32.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 #ifdef __REACTOS__
83 #define BUTTON_BMCLICK 0x100 // ReactOS Need to up to wine!
84 #endif
85
86 #define BUTTON_NOTIFY_PARENT(hWnd, code) \
87 do { /* Notify parent which has created this button control */ \
88 TRACE("notification " #code " sent to hwnd=%p\n", GetParent(hWnd)); \
89 SendMessageW(GetParent(hWnd), WM_COMMAND, \
90 MAKEWPARAM(GetWindowLongPtrW((hWnd),GWLP_ID), (code)), \
91 (LPARAM)(hWnd)); \
92 } while(0)
93
94 static UINT BUTTON_CalcLabelRect( HWND hwnd, HDC hdc, RECT *rc );
95 static void PB_Paint( HWND hwnd, HDC hDC, UINT action );
96 static void CB_Paint( HWND hwnd, HDC hDC, UINT action );
97 static void GB_Paint( HWND hwnd, HDC hDC, UINT action );
98 static void UB_Paint( HWND hwnd, HDC hDC, UINT action );
99 static void OB_Paint( HWND hwnd, HDC hDC, UINT action );
100 static void BUTTON_CheckAutoRadioButton( HWND hwnd );
101
102 #define MAX_BTN_TYPE 16
103
104 static const WORD maxCheckState[MAX_BTN_TYPE] =
105 {
106 BST_UNCHECKED, /* BS_PUSHBUTTON */
107 BST_UNCHECKED, /* BS_DEFPUSHBUTTON */
108 BST_CHECKED, /* BS_CHECKBOX */
109 BST_CHECKED, /* BS_AUTOCHECKBOX */
110 BST_CHECKED, /* BS_RADIOBUTTON */
111 BST_INDETERMINATE, /* BS_3STATE */
112 BST_INDETERMINATE, /* BS_AUTO3STATE */
113 BST_UNCHECKED, /* BS_GROUPBOX */
114 BST_UNCHECKED, /* BS_USERBUTTON */
115 BST_CHECKED, /* BS_AUTORADIOBUTTON */
116 BST_UNCHECKED, /* BS_PUSHBOX */
117 BST_UNCHECKED /* BS_OWNERDRAW */
118 };
119
120 typedef void (*pfPaint)( HWND hwnd, HDC hdc, UINT action );
121
122 static const pfPaint btnPaintFunc[MAX_BTN_TYPE] =
123 {
124 PB_Paint, /* BS_PUSHBUTTON */
125 PB_Paint, /* BS_DEFPUSHBUTTON */
126 CB_Paint, /* BS_CHECKBOX */
127 CB_Paint, /* BS_AUTOCHECKBOX */
128 CB_Paint, /* BS_RADIOBUTTON */
129 CB_Paint, /* BS_3STATE */
130 CB_Paint, /* BS_AUTO3STATE */
131 GB_Paint, /* BS_GROUPBOX */
132 UB_Paint, /* BS_USERBUTTON */
133 CB_Paint, /* BS_AUTORADIOBUTTON */
134 NULL, /* BS_PUSHBOX */
135 OB_Paint /* BS_OWNERDRAW */
136 };
137
138 /* The original code from user32 was kept in order to make it easier to bring changes from user32 */
139 #ifdef _USER32_
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 #ifdef __REACTOS__
149 ButtonWndProcA, /* procA */
150 ButtonWndProcW, /* procW */
151 #else
152 WINPROC_BUTTON, /* proc */
153 #endif
154 NB_EXTRA_BYTES, /* extra */
155 IDC_ARROW, /* cursor */
156 0 /* brush */
157 };
158
159
160 static inline LONG get_button_state( HWND hwnd )
161 {
162 return GetWindowLongPtrW( hwnd, STATE_GWL_OFFSET );
163 }
164
165 static inline void set_button_state( HWND hwnd, LONG state )
166 {
167 SetWindowLongPtrW( hwnd, STATE_GWL_OFFSET, state );
168 }
169
170 #ifdef __REACTOS__
171
172 static __inline void set_ui_state( HWND hwnd, LONG flags )
173 {
174 SetWindowLongPtrW( hwnd, UISTATE_GWL_OFFSET, flags );
175 }
176
177 static __inline LONG get_ui_state( HWND hwnd )
178 {
179 return GetWindowLongPtrW( hwnd, UISTATE_GWL_OFFSET );
180 }
181
182 #endif /* __REACTOS__ */
183
184 static inline HFONT get_button_font( HWND hwnd )
185 {
186 return (HFONT)GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET );
187 }
188
189 static inline void set_button_font( HWND hwnd, HFONT font )
190 {
191 SetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET, (LONG_PTR)font );
192 }
193
194 static inline UINT get_button_type( LONG window_style )
195 {
196 return (window_style & BS_TYPEMASK);
197 }
198
199 /* paint a button of any type */
200 static inline void paint_button( HWND hwnd, LONG style, UINT action )
201 {
202 if (btnPaintFunc[style] && IsWindowVisible(hwnd))
203 {
204 HDC hdc = GetDC( hwnd );
205 btnPaintFunc[style]( hwnd, hdc, action );
206 ReleaseDC( hwnd, hdc );
207 }
208 }
209
210 #else
211
212 #define NtUserAlterWindowStyle SetWindowLongPtrW
213
214 static inline void _SetButtonData(HWND hwnd, PBUTTON_DATA data)
215 {
216 SetWindowLongPtrW( hwnd, 0, (LONG)data );
217 }
218
219 HRGN set_control_clipping( HDC hdc, const RECT *rect )
220 {
221 RECT rc = *rect;
222 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
223
224 if (GetClipRgn( hdc, hrgn ) != 1)
225 {
226 DeleteObject( hrgn );
227 hrgn = 0;
228 }
229 DPtoLP( hdc, (POINT *)&rc, 2 );
230 if (GetLayout( hdc ) & LAYOUT_RTL) /* compensate for the shifting done by IntersectClipRect */
231 {
232 rc.left++;
233 rc.right++;
234 }
235 IntersectClipRect( hdc, rc.left, rc.top, rc.right, rc.bottom );
236 return hrgn;
237 }
238
239 BOOL BUTTON_PaintWithTheme(HTHEME theme, HWND hwnd, HDC hParamDC, LPARAM prfFlag);
240 WCHAR *get_button_text( HWND hwnd );
241
242 static inline LONG_PTR get_button_image(HWND hwnd)
243 {
244 return _GetButtonData(hwnd)->image;
245 }
246
247 static inline LONG_PTR set_button_image(HWND hwnd, LONG_PTR image)
248 {
249 PBUTTON_DATA data = _GetButtonData(hwnd);
250 LONG_PTR ret = data->image;
251 data->image = image;
252 return ret;
253 }
254
255 static inline LONG get_button_state( HWND hwnd )
256 {
257 return _GetButtonData(hwnd)->state;
258 }
259
260 static inline void set_button_state( HWND hwnd, LONG state )
261 {
262 _GetButtonData(hwnd)->state = state;
263 }
264
265 static __inline void set_ui_state( HWND hwnd, LONG flags )
266 {
267 _GetButtonData(hwnd)->ui_state = flags;
268 }
269
270 static __inline LONG get_ui_state( HWND hwnd )
271 {
272 return _GetButtonData(hwnd)->ui_state;
273 }
274
275 static inline HFONT get_button_font( HWND hwnd )
276 {
277 return (HFONT)_GetButtonData(hwnd)->font;
278 }
279
280 static inline void set_button_font( HWND hwnd, HFONT font )
281 {
282 _GetButtonData(hwnd)->font = font;
283 }
284
285 static inline UINT get_button_type( LONG window_style )
286 {
287 return (window_style & BS_TYPEMASK);
288 }
289
290 /* paint a button of any type */
291 static inline void paint_button( HWND hwnd, LONG style, UINT action )
292 {
293 HTHEME theme = GetWindowTheme(hwnd);
294 RECT rc;
295 HDC hdc = GetDC( hwnd );
296 /* GetDC appears to give a dc with a clip rect that includes the whoe parent, not sure if it is correct or not. */
297 GetClientRect(hwnd, &rc);
298 IntersectClipRect (hdc, rc.left, rc. top, rc.right, rc.bottom);
299 if (theme && BUTTON_PaintWithTheme(theme, hwnd, hdc, 0))
300 {
301 ReleaseDC( hwnd, hdc );
302 return;
303 }
304 if (btnPaintFunc[style] && IsWindowVisible(hwnd))
305 {
306 btnPaintFunc[style]( hwnd, hdc, action );
307 }
308 ReleaseDC( hwnd, hdc );
309 }
310
311 BOOL BUTTON_GetIdealSize(HTHEME theme, HWND hwnd, SIZE* psize)
312 {
313 PBUTTON_DATA pdata;
314 HDC hdc;
315 WCHAR *text;
316 HFONT hFont = 0, hPrevFont = 0;
317 SIZE TextSize, ImageSize, ButtonSize;
318 BOOL ret = FALSE;
319 LOGFONTW logfont = {0};
320
321 pdata = _GetButtonData(hwnd);
322 text = get_button_text( hwnd );
323 hdc = GetDC(hwnd);
324 if (!pdata || !text || !hdc || !text[0])
325 goto cleanup;
326
327 /* FIXME : Should use GetThemeTextExtent but unfortunately uses DrawTextW which is broken */
328 if (theme)
329 {
330 HRESULT hr = GetThemeFont(theme, hdc, BP_PUSHBUTTON, PBS_NORMAL, TMT_FONT, &logfont);
331 if(SUCCEEDED(hr))
332 {
333 hFont = CreateFontIndirectW(&logfont);
334 if(hFont)
335 hPrevFont = SelectObject( hdc, hFont );
336 }
337 }
338 else
339 {
340 if (pdata->font)
341 hPrevFont = SelectObject( hdc, pdata->font );
342 }
343
344 GetTextExtentPoint32W(hdc, text, wcslen(text), &TextSize);
345
346 if (logfont.lfHeight == -1 && logfont.lfWidth == 0 && wcscmp(logfont.lfFaceName, L"Arial") == 0 && wcsicmp(text, L"Start") == 0)
347 {
348 TextSize.cx = 5;
349 TextSize.cy = 4;
350 }
351
352 if (hPrevFont)
353 SelectObject( hdc, hPrevFont );
354
355 TextSize.cy += pdata->rcTextMargin.top + pdata->rcTextMargin.bottom;
356 TextSize.cx += pdata->rcTextMargin.left + pdata->rcTextMargin.right;
357
358 if (pdata->imlData.himl && ImageList_GetIconSize(pdata->imlData.himl, &ImageSize.cx, &ImageSize.cy))
359 {
360 ImageSize.cx += pdata->imlData.margin.left + pdata->imlData.margin.right;
361 ImageSize.cy += pdata->imlData.margin.top + pdata->imlData.margin.bottom;
362 }
363 else
364 {
365 ImageSize.cx = ImageSize.cy = 0;
366 }
367
368 if (theme)
369 {
370 RECT rcContents = {0};
371 RECT rcButtonExtent = {0};
372 rcContents.right = ImageSize.cx + TextSize.cx;
373 rcContents.bottom = max(ImageSize.cy, TextSize.cy);
374 GetThemeBackgroundExtent(theme, hdc, BP_PUSHBUTTON, PBS_NORMAL, &rcContents, &rcButtonExtent);
375 ButtonSize.cx = rcButtonExtent.right - rcButtonExtent.left;
376 ButtonSize.cy = rcButtonExtent.bottom - rcButtonExtent.top;
377 }
378 else
379 {
380 ButtonSize.cx = ImageSize.cx + TextSize.cx + 5;
381 ButtonSize.cy = max(ImageSize.cy, TextSize.cy + 7);
382 }
383
384 *psize = ButtonSize;
385 ret = TRUE;
386
387 cleanup:
388 if (hFont)
389 DeleteObject(hFont);
390 if (text)
391 HeapFree( GetProcessHeap(), 0, text );
392 if (hdc)
393 ReleaseDC(hwnd, hdc);
394
395 return ret;
396 }
397
398 BOOL BUTTON_DrawIml(HDC hDC, BUTTON_IMAGELIST *pimlData, RECT *prc, BOOL bOnlyCalc)
399 {
400 SIZE ImageSize;
401 int left, top;
402
403 if (!pimlData->himl)
404 return FALSE;
405
406 if (!ImageList_GetIconSize(pimlData->himl, &ImageSize.cx, &ImageSize.cy))
407 return FALSE;
408
409 if (pimlData->uAlign == BUTTON_IMAGELIST_ALIGN_LEFT)
410 {
411 left = prc->left + pimlData->margin.left;
412 top = prc->top + (prc->bottom - prc->top - ImageSize.cy) / 2;
413 prc->left = left + pimlData->margin.right + ImageSize.cx;
414 }
415 else if (pimlData->uAlign == BUTTON_IMAGELIST_ALIGN_RIGHT)
416 {
417 left = prc->right - pimlData->margin.right - ImageSize.cx;
418 top = prc->top + (prc->bottom - prc->top - ImageSize.cy) / 2;
419 prc->right = left - pimlData->margin.left;
420 }
421 else if (pimlData->uAlign == BUTTON_IMAGELIST_ALIGN_TOP)
422 {
423 left = prc->left + (prc->right - prc->left - ImageSize.cx) / 2;
424 top = prc->top + pimlData->margin.top;
425 prc->top = top + ImageSize.cy + pimlData->margin.bottom;
426 }
427 else if (pimlData->uAlign == BUTTON_IMAGELIST_ALIGN_BOTTOM)
428 {
429 left = prc->left + (prc->right - prc->left - ImageSize.cx) / 2;
430 top = prc->bottom - pimlData->margin.bottom - ImageSize.cy;
431 prc->bottom = top - pimlData->margin.top;
432 }
433 else if (pimlData->uAlign == BUTTON_IMAGELIST_ALIGN_CENTER)
434 {
435 left = prc->left + (prc->right - prc->left - ImageSize.cx) / 2;
436 top = prc->top + (prc->bottom - prc->top - ImageSize.cy) / 2;
437 }
438
439 if (!bOnlyCalc)
440 ImageList_Draw(pimlData->himl, 0, hDC, left, top, 0);
441
442 return TRUE;
443 }
444 #endif
445
446
447 /* retrieve the button text; returned buffer must be freed by caller */
448 inline WCHAR *get_button_text( HWND hwnd )
449 {
450 INT len = 512;
451 WCHAR *buffer = HeapAlloc( GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR) );
452 if (buffer) InternalGetWindowText( hwnd, buffer, len + 1 );
453 return buffer;
454 }
455
456 #ifdef __REACTOS__
457 /* Retrieve the UI state for the control */
458 static BOOL button_update_uistate(HWND hwnd, BOOL unicode)
459 {
460 LONG flags, prevflags;
461
462 if (unicode)
463 flags = DefWindowProcW(hwnd, WM_QUERYUISTATE, 0, 0);
464 else
465 flags = DefWindowProcA(hwnd, WM_QUERYUISTATE, 0, 0);
466
467 prevflags = get_ui_state(hwnd);
468
469 if (prevflags != flags)
470 {
471 set_ui_state(hwnd, flags);
472 return TRUE;
473 }
474
475 return FALSE;
476 }
477 #endif
478
479 /***********************************************************************
480 * ButtonWndProc_common
481 */
482 LRESULT WINAPI ButtonWndProc_common(HWND hWnd, UINT uMsg,
483 WPARAM wParam, LPARAM lParam, BOOL unicode )
484 {
485 RECT rect;
486 POINT pt;
487 LONG style = GetWindowLongPtrW( hWnd, GWL_STYLE );
488 UINT btn_type = get_button_type( style );
489 LONG state;
490 HANDLE oldHbitmap;
491 #if defined(__REACTOS__) && defined(_USER32_)
492 PWND pWnd;
493
494 pWnd = ValidateHwnd(hWnd);
495 if (pWnd)
496 {
497 if (!pWnd->fnid)
498 {
499 NtUserSetWindowFNID(hWnd, FNID_BUTTON);
500 }
501 else
502 {
503 if (pWnd->fnid != FNID_BUTTON)
504 {
505 ERR("Wrong window class for Button! fnId 0x%x\n",pWnd->fnid);
506 return 0;
507 }
508 }
509 }
510 else
511 return 0;
512 #else
513 if (!IsWindow( hWnd )) return 0;
514 #endif
515
516 pt.x = (short)LOWORD(lParam);
517 pt.y = (short)HIWORD(lParam);
518
519 #ifndef _USER32_
520 switch (uMsg)
521 {
522 case WM_NCCREATE:
523 {
524 PBUTTON_DATA data = HeapAlloc( GetProcessHeap(), 0, sizeof(BUTTON_DATA) );
525 if (!data)
526 {
527 ERR("Failed to alloc internal button data\n");
528 return -1;
529 }
530
531 memset(data, 0, sizeof(BUTTON_DATA));
532 SetRect(&data->rcTextMargin, 1,1,1,1);
533
534 _SetButtonData(hWnd, data);
535 break;
536 }
537 case WM_NCDESTROY:
538 {
539 PBUTTON_DATA data = _GetButtonData(hWnd);
540 if (!data)
541 {
542 ERR("No data");
543 return 0;
544 }
545 HeapFree( GetProcessHeap(), 0, data );
546 _SetButtonData(hWnd, NULL);
547 }
548 case WM_CREATE:
549 OpenThemeData(hWnd, WC_BUTTONW);
550 break;
551 case WM_DESTROY:
552 CloseThemeData (GetWindowTheme(hWnd));
553 break;
554 case WM_THEMECHANGED:
555 CloseThemeData (GetWindowTheme(hWnd));
556 OpenThemeData(hWnd, WC_BUTTONW);
557 InvalidateRect(hWnd, NULL, TRUE);
558 break;
559 case WM_MOUSELEAVE:
560 {
561 state = get_button_state( hWnd );
562 if (state & BST_HOT)
563 {
564 NMBCHOTITEM nmhotitem;
565
566 state &= ~BST_HOT;
567 set_button_state(hWnd, state);
568
569 nmhotitem.hdr.hwndFrom = hWnd;
570 nmhotitem.hdr.idFrom = GetWindowLongPtrW (hWnd, GWLP_ID);
571 nmhotitem.hdr.code = BCN_HOTITEMCHANGE;
572 nmhotitem.dwFlags = HICF_LEAVING;
573 SendMessageW(GetParent(hWnd), WM_NOTIFY, nmhotitem.hdr.idFrom, (LPARAM)&nmhotitem);
574
575 InvalidateRect(hWnd, NULL, TRUE);
576 }
577 break;
578 }
579 case WM_MOUSEMOVE:
580 {
581 TRACKMOUSEEVENT mouse_event;
582 state = get_button_state( hWnd );
583 if ((state & BST_HOT) == 0)
584 {
585 NMBCHOTITEM nmhotitem;
586
587 state |= BST_HOT;
588 set_button_state(hWnd, state);
589
590 nmhotitem.hdr.hwndFrom = hWnd;
591 nmhotitem.hdr.idFrom = GetWindowLongPtrW (hWnd, GWLP_ID);
592 nmhotitem.hdr.code = BCN_HOTITEMCHANGE;
593 nmhotitem.dwFlags = HICF_ENTERING;
594 SendMessageW(GetParent(hWnd), WM_NOTIFY, nmhotitem.hdr.idFrom, (LPARAM)&nmhotitem);
595
596 InvalidateRect(hWnd, NULL, TRUE);
597 }
598
599 mouse_event.cbSize = sizeof(TRACKMOUSEEVENT);
600 mouse_event.dwFlags = TME_QUERY;
601 if(!TrackMouseEvent(&mouse_event) || !(mouse_event.dwFlags&TME_LEAVE))
602 {
603 mouse_event.dwFlags = TME_LEAVE;
604 mouse_event.hwndTrack = hWnd;
605 mouse_event.dwHoverTime = 1;
606 TrackMouseEvent(&mouse_event);
607 }
608 break;
609 }
610 case BCM_GETTEXTMARGIN:
611 {
612 RECT* prc = (RECT*)lParam;
613 PBUTTON_DATA data = _GetButtonData(hWnd);
614 if (!prc || !data)
615 return FALSE;
616 *prc = data->rcTextMargin;
617 return TRUE;
618 }
619 case BCM_SETTEXTMARGIN:
620 {
621 RECT* prc = (RECT*)lParam;
622 PBUTTON_DATA data = _GetButtonData(hWnd);
623 if (!prc || !data)
624 return FALSE;
625 data->rcTextMargin = *prc;
626 return TRUE;
627 }
628 case BCM_SETIMAGELIST:
629 {
630 BUTTON_IMAGELIST * pimldata = (BUTTON_IMAGELIST *)lParam;
631 PBUTTON_DATA data = _GetButtonData(hWnd);
632 if (!data || !pimldata || !pimldata->himl)
633 return FALSE;
634 data->imlData = *pimldata;
635 return TRUE;
636 }
637 case BCM_GETIMAGELIST:
638 {
639 BUTTON_IMAGELIST * pimldata = (BUTTON_IMAGELIST *)lParam;
640 PBUTTON_DATA data = _GetButtonData(hWnd);
641 if (!data|| !pimldata)
642 return FALSE;
643 *pimldata = data->imlData;
644 return TRUE;
645 }
646 case BCM_GETIDEALSIZE:
647 {
648 HTHEME theme = GetWindowTheme(hWnd);
649 BOOL ret = FALSE;
650 SIZE* pSize = (SIZE*)lParam;
651
652 if (btn_type == BS_PUSHBUTTON ||
653 btn_type == BS_DEFPUSHBUTTON ||
654 btn_type == BS_USERBUTTON)
655 {
656 ret = BUTTON_GetIdealSize(theme, hWnd, pSize);
657 }
658
659 if (!ret)
660 {
661 GetClientRect(hWnd, &rect);
662 pSize->cx = rect.right;
663 pSize->cy = rect.bottom;
664 }
665
666 return TRUE;
667 }
668 }
669
670 if (!_GetButtonData(hWnd))
671 {
672 ERR("no data!\n");
673 return unicode ? DefWindowProcW(hWnd, uMsg, wParam, lParam) :
674 DefWindowProcA(hWnd, uMsg, wParam, lParam);
675 }
676
677 #endif
678
679 switch (uMsg)
680 {
681 case WM_GETDLGCODE:
682 switch(btn_type)
683 {
684 case BS_USERBUTTON:
685 case BS_PUSHBUTTON: return DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON;
686 case BS_DEFPUSHBUTTON: return DLGC_BUTTON | DLGC_DEFPUSHBUTTON;
687 case BS_RADIOBUTTON:
688 case BS_AUTORADIOBUTTON: return DLGC_BUTTON | DLGC_RADIOBUTTON;
689 case BS_GROUPBOX: return DLGC_STATIC;
690 default: return DLGC_BUTTON;
691 }
692
693 case WM_ENABLE:
694 paint_button( hWnd, btn_type, ODA_DRAWENTIRE );
695 break;
696
697 case WM_CREATE:
698 if (btn_type >= MAX_BTN_TYPE)
699 return -1; /* abort */
700
701 /* XP turns a BS_USERBUTTON into BS_PUSHBUTTON */
702 if (btn_type == BS_USERBUTTON )
703 {
704 style = (style & ~BS_TYPEMASK) | BS_PUSHBUTTON;
705 #ifdef __REACTOS__
706 NtUserAlterWindowStyle(hWnd, GWL_STYLE, style );
707 #else
708 WIN_SetStyle( hWnd, style, BS_TYPEMASK & ~style );
709 #endif
710 }
711 set_button_state( hWnd, BST_UNCHECKED );
712 #ifdef __REACTOS__
713 button_update_uistate( hWnd, unicode );
714 #endif
715 return 0;
716
717 #if defined(__REACTOS__) && defined(_USER32_)
718 case WM_NCDESTROY:
719 NtUserSetWindowFNID(hWnd, FNID_DESTROY);
720 case WM_DESTROY:
721 break;
722 #endif
723 case WM_ERASEBKGND:
724 if (btn_type == BS_OWNERDRAW)
725 {
726 HDC hdc = (HDC)wParam;
727 RECT rc;
728 HBRUSH hBrush;
729 HWND parent = GetParent(hWnd);
730 if (!parent) parent = hWnd;
731 #if defined(__REACTOS__) && defined(_USER32_)
732 hBrush = GetControlColor( parent, hWnd, hdc, WM_CTLCOLORBTN);
733 #else
734 hBrush = (HBRUSH)SendMessageW(parent, WM_CTLCOLORBTN, (WPARAM)hdc, (LPARAM)hWnd);
735 if (!hBrush) /* did the app forget to call defwindowproc ? */
736 hBrush = (HBRUSH)DefWindowProcW(parent, WM_CTLCOLORBTN,
737 (WPARAM)hdc, (LPARAM)hWnd);
738 #endif
739 GetClientRect(hWnd, &rc);
740 FillRect(hdc, &rc, hBrush);
741 }
742 return 1;
743
744 case WM_PRINTCLIENT:
745 case WM_PAINT:
746 {
747 PAINTSTRUCT ps;
748 HDC hdc = wParam ? (HDC)wParam : BeginPaint( hWnd, &ps );
749 #ifndef _USER32_
750 HTHEME theme = GetWindowTheme(hWnd);
751 if (theme && BUTTON_PaintWithTheme(theme, hWnd, hdc, uMsg == WM_PRINTCLIENT ? lParam : 0))
752 {
753 if ( !wParam ) EndPaint( hWnd, &ps );
754 return 0;
755 }
756 #endif
757 if (btnPaintFunc[btn_type])
758 {
759 int nOldMode = SetBkMode( hdc, OPAQUE );
760 (btnPaintFunc[btn_type])( hWnd, hdc, ODA_DRAWENTIRE );
761 SetBkMode(hdc, nOldMode); /* reset painting mode */
762 }
763 if ( !wParam ) EndPaint( hWnd, &ps );
764 break;
765 }
766
767 case WM_KEYDOWN:
768 if (wParam == VK_SPACE)
769 {
770 SendMessageW( hWnd, BM_SETSTATE, TRUE, 0 );
771 set_button_state( hWnd, get_button_state( hWnd ) | BUTTON_BTNPRESSED );
772 SetCapture( hWnd );
773 }
774 break;
775
776 case WM_LBUTTONDBLCLK:
777 if(style & BS_NOTIFY ||
778 btn_type == BS_RADIOBUTTON ||
779 btn_type == BS_USERBUTTON ||
780 btn_type == BS_OWNERDRAW)
781 {
782 BUTTON_NOTIFY_PARENT(hWnd, BN_DOUBLECLICKED);
783 break;
784 }
785 /* fall through */
786 case WM_LBUTTONDOWN:
787 SetCapture( hWnd );
788 SetFocus( hWnd );
789 set_button_state( hWnd, get_button_state( hWnd ) | BUTTON_BTNPRESSED );
790 SendMessageW( hWnd, BM_SETSTATE, TRUE, 0 );
791 break;
792
793 case WM_KEYUP:
794 if (wParam != VK_SPACE)
795 break;
796 /* fall through */
797 case WM_LBUTTONUP:
798 #ifdef _REACTOS_
799 BOOL TellParent = FALSE; //// ReactOS see note below.
800 #endif
801 state = get_button_state( hWnd );
802 if (!(state & BUTTON_BTNPRESSED)) break;
803 state &= BUTTON_NSTATES;
804 set_button_state( hWnd, state );
805 if (!(state & BST_PUSHED))
806 {
807 ReleaseCapture();
808 break;
809 }
810 SendMessageW( hWnd, BM_SETSTATE, FALSE, 0 );
811 GetClientRect( hWnd, &rect );
812 if (uMsg == WM_KEYUP || PtInRect( &rect, pt ))
813 {
814 state = get_button_state( hWnd );
815 switch(btn_type)
816 {
817 case BS_AUTOCHECKBOX:
818 SendMessageW( hWnd, BM_SETCHECK, !(state & BST_CHECKED), 0 );
819 break;
820 case BS_AUTORADIOBUTTON:
821 SendMessageW( hWnd, BM_SETCHECK, TRUE, 0 );
822 break;
823 case BS_AUTO3STATE:
824 SendMessageW( hWnd, BM_SETCHECK,
825 (state & BST_INDETERMINATE) ? 0 : ((state & 3) + 1), 0 );
826 break;
827 }
828 #ifdef _REACTOS_
829 TellParent = TRUE; // <---- Fix CORE-10194, Notify parent after capture is released.
830 #else
831 ReleaseCapture();
832 BUTTON_NOTIFY_PARENT(hWnd, BN_CLICKED);
833 #endif
834 }
835 #ifdef _REACTOS_
836 ReleaseCapture();
837 if (TellParent) BUTTON_NOTIFY_PARENT(hWnd, BN_CLICKED);
838 #else
839 else
840 {
841 ReleaseCapture();
842 }
843 #endif
844 break;
845
846 case WM_CAPTURECHANGED:
847 TRACE("WM_CAPTURECHANGED %p\n", hWnd);
848 if (hWnd == (HWND)lParam) break;
849 state = get_button_state( hWnd );
850 if (state & BUTTON_BTNPRESSED)
851 {
852 state &= BUTTON_NSTATES;
853 set_button_state( hWnd, state );
854 if (state & BST_PUSHED) SendMessageW( hWnd, BM_SETSTATE, FALSE, 0 );
855 }
856 break;
857
858 case WM_MOUSEMOVE:
859 if ((wParam & MK_LBUTTON) && GetCapture() == hWnd)
860 {
861 GetClientRect( hWnd, &rect );
862 SendMessageW( hWnd, BM_SETSTATE, PtInRect(&rect, pt), 0 );
863 }
864 break;
865
866 case WM_SETTEXT:
867 {
868 /* Clear an old text here as Windows does */
869 //
870 // ReactOS Note :
871 // wine Bug: http://bugs.winehq.org/show_bug.cgi?id=25790
872 // Patch: http://source.winehq.org/patches/data/70889
873 // By: Alexander LAW, Replicate Windows behavior of WM_SETTEXT handler regarding WM_CTLCOLOR*
874 //
875 #ifdef __REACTOS__
876 if (style & WS_VISIBLE)
877 #else
878 if (IsWindowVisible(hWnd))
879 #endif
880 {
881 HDC hdc = GetDC(hWnd);
882 HBRUSH hbrush;
883 RECT client, rc;
884 HWND parent = GetParent(hWnd);
885 UINT message = (btn_type == BS_PUSHBUTTON ||
886 btn_type == BS_DEFPUSHBUTTON ||
887 btn_type == BS_PUSHLIKE ||
888 btn_type == BS_USERBUTTON ||
889 btn_type == BS_OWNERDRAW) ?
890 WM_CTLCOLORBTN : WM_CTLCOLORSTATIC;
891
892 if (!parent) parent = hWnd;
893 #if defined(__REACTOS__) && defined(_USER32_)
894 hbrush = GetControlColor(parent, hWnd, hdc, message);
895 #else
896 hbrush = (HBRUSH)SendMessageW(parent, message,
897 (WPARAM)hdc, (LPARAM)hWnd);
898 if (!hbrush) /* did the app forget to call DefWindowProc ? */
899 hbrush = (HBRUSH)DefWindowProcW(parent, message,
900 (WPARAM)hdc, (LPARAM)hWnd);
901 #endif
902
903 GetClientRect(hWnd, &client);
904 rc = client;
905 /* FIXME: check other BS_* handlers */
906 if (btn_type == BS_GROUPBOX)
907 InflateRect(&rc, -7, 1); /* GB_Paint does this */
908 BUTTON_CalcLabelRect(hWnd, hdc, &rc);
909 /* Clip by client rect bounds */
910 if (rc.right > client.right) rc.right = client.right;
911 if (rc.bottom > client.bottom) rc.bottom = client.bottom;
912 FillRect(hdc, &rc, hbrush);
913 ReleaseDC(hWnd, hdc);
914 }
915
916 if (unicode) DefWindowProcW( hWnd, WM_SETTEXT, wParam, lParam );
917 else DefWindowProcA( hWnd, WM_SETTEXT, wParam, lParam );
918 if (btn_type == BS_GROUPBOX) /* Yes, only for BS_GROUPBOX */
919 InvalidateRect( hWnd, NULL, TRUE );
920 else
921 paint_button( hWnd, btn_type, ODA_DRAWENTIRE );
922 return 1; /* success. FIXME: check text length */
923 }
924
925 case WM_SETFONT:
926 set_button_font( hWnd, (HFONT)wParam );
927 if (lParam) InvalidateRect(hWnd, NULL, TRUE);
928 break;
929
930 case WM_GETFONT:
931 return (LRESULT)get_button_font( hWnd );
932
933 case WM_SETFOCUS:
934 TRACE("WM_SETFOCUS %p\n",hWnd);
935 set_button_state( hWnd, get_button_state(hWnd) | BST_FOCUS );
936 #ifndef _USER32_
937 if (btn_type != BS_OWNERDRAW)
938 InvalidateRect(hWnd, NULL, FALSE);
939 else
940 #endif
941 paint_button( hWnd, btn_type, ODA_FOCUS );
942 if (style & BS_NOTIFY)
943 BUTTON_NOTIFY_PARENT(hWnd, BN_SETFOCUS);
944 break;
945
946 case WM_KILLFOCUS:
947 TRACE("WM_KILLFOCUS %p\n",hWnd);
948 state = get_button_state( hWnd );
949 set_button_state( hWnd, state & ~BST_FOCUS );
950 #ifdef _USER32_
951 paint_button( hWnd, btn_type, ODA_FOCUS );
952 #endif
953
954 if ((state & BUTTON_BTNPRESSED) && GetCapture() == hWnd)
955 ReleaseCapture();
956 if (style & BS_NOTIFY)
957 BUTTON_NOTIFY_PARENT(hWnd, BN_KILLFOCUS);
958
959 InvalidateRect( hWnd, NULL, FALSE );
960 break;
961
962 case WM_SYSCOLORCHANGE:
963 InvalidateRect( hWnd, NULL, FALSE );
964 break;
965
966 case BM_SETSTYLE:
967 btn_type = wParam & BS_TYPEMASK;
968 style = (style & ~BS_TYPEMASK) | btn_type;
969 #ifdef __REACTOS__
970 NtUserAlterWindowStyle(hWnd, GWL_STYLE, style);
971 #else
972 WIN_SetStyle( hWnd, style, BS_TYPEMASK & ~style );
973 #endif
974
975 /* Only redraw if lParam flag is set.*/
976 if (lParam)
977 InvalidateRect( hWnd, NULL, TRUE );
978
979 break;
980
981 case BM_CLICK:
982 #ifdef __REACTOS__
983 state = get_button_state(hWnd);
984 if (state & BUTTON_BMCLICK)
985 break;
986 set_button_state(hWnd, state | BUTTON_BMCLICK); // Tracked in STATE_GWL_OFFSET.
987 #endif
988 SendMessageW( hWnd, WM_LBUTTONDOWN, 0, 0 );
989 SendMessageW( hWnd, WM_LBUTTONUP, 0, 0 );
990 #ifdef __REACTOS__
991 state = get_button_state(hWnd);
992 if (!(state & BUTTON_BMCLICK)) break;
993 state &= ~BUTTON_BMCLICK;
994 set_button_state(hWnd, state);
995 #endif
996 break;
997
998 case BM_SETIMAGE:
999 /* Check that image format matches button style */
1000 switch (style & (BS_BITMAP|BS_ICON))
1001 {
1002 case BS_BITMAP:
1003 if (wParam != IMAGE_BITMAP) return 0;
1004 break;
1005 case BS_ICON:
1006 if (wParam != IMAGE_ICON) return 0;
1007 break;
1008 default:
1009 return 0;
1010 }
1011 #ifdef _USER32_
1012 oldHbitmap = (HBITMAP)SetWindowLongPtrW( hWnd, HIMAGE_GWL_OFFSET, lParam );
1013 #else
1014 oldHbitmap = (HBITMAP)set_button_image(hWnd, lParam );
1015 #endif
1016 InvalidateRect( hWnd, NULL, FALSE );
1017 return (LRESULT)oldHbitmap;
1018
1019 case BM_GETIMAGE:
1020 #ifdef _USER32_
1021 return GetWindowLongPtrW( hWnd, HIMAGE_GWL_OFFSET );
1022 #else
1023 return get_button_image(hWnd);
1024 #endif
1025
1026 case BM_GETCHECK:
1027 return get_button_state( hWnd ) & 3;
1028
1029 case BM_SETCHECK:
1030 if (wParam > maxCheckState[btn_type]) wParam = maxCheckState[btn_type];
1031 state = get_button_state( hWnd );
1032 if ((btn_type == BS_RADIOBUTTON) || (btn_type == BS_AUTORADIOBUTTON))
1033 {
1034 #ifdef __REACTOS__
1035 if (wParam) style |= WS_TABSTOP;
1036 else style &= ~WS_TABSTOP;
1037 NtUserAlterWindowStyle(hWnd, GWL_STYLE, style);
1038 #else
1039 if (wParam) WIN_SetStyle( hWnd, WS_TABSTOP, 0 );
1040 else WIN_SetStyle( hWnd, 0, WS_TABSTOP );
1041 #endif
1042 }
1043 if ((state & 3) != wParam)
1044 {
1045 set_button_state( hWnd, (state & ~3) | wParam );
1046 #ifdef _USER32
1047 paint_button( hWnd, btn_type, ODA_SELECT );
1048 #else
1049 InvalidateRect(hWnd, NULL, FALSE);
1050 #endif
1051 }
1052 if ((btn_type == BS_AUTORADIOBUTTON) && (wParam == BST_CHECKED) && (style & WS_CHILD))
1053 BUTTON_CheckAutoRadioButton( hWnd );
1054 break;
1055
1056 case BM_GETSTATE:
1057 return get_button_state( hWnd );
1058
1059 case BM_SETSTATE:
1060 state = get_button_state( hWnd );
1061 if (wParam)
1062 set_button_state( hWnd, state | BST_PUSHED );
1063 else
1064 set_button_state( hWnd, state & ~BST_PUSHED );
1065
1066 #ifdef _USER32_
1067 paint_button( hWnd, btn_type, ODA_SELECT );
1068 #else
1069 InvalidateRect(hWnd, NULL, FALSE);
1070 #endif
1071 break;
1072
1073 #ifdef __REACTOS__
1074 case WM_UPDATEUISTATE:
1075 if (unicode)
1076 DefWindowProcW(hWnd, uMsg, wParam, lParam);
1077 else
1078 DefWindowProcA(hWnd, uMsg, wParam, lParam);
1079
1080 if (button_update_uistate(hWnd, unicode))
1081 paint_button( hWnd, btn_type, ODA_DRAWENTIRE );
1082 break;
1083 #endif
1084
1085 case WM_NCHITTEST:
1086 if(btn_type == BS_GROUPBOX) return HTTRANSPARENT;
1087 /* fall through */
1088 default:
1089 return unicode ? DefWindowProcW(hWnd, uMsg, wParam, lParam) :
1090 DefWindowProcA(hWnd, uMsg, wParam, lParam);
1091 }
1092 return 0;
1093 }
1094
1095 #ifdef __REACTOS__
1096
1097 /***********************************************************************
1098 * ButtonWndProcW
1099 * The button window procedure. This is just a wrapper which locks
1100 * the passed HWND and calls the real window procedure (with a WND*
1101 * pointer pointing to the locked windowstructure).
1102 */
1103 LRESULT WINAPI ButtonWndProcW(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1104 {
1105 if (!IsWindow(hWnd)) return 0;
1106 return ButtonWndProc_common(hWnd, uMsg, wParam, lParam, TRUE);
1107 }
1108
1109 /***********************************************************************
1110 * ButtonWndProcA
1111 */
1112 LRESULT WINAPI ButtonWndProcA(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1113 {
1114 if (!IsWindow(hWnd)) return 0;
1115 return ButtonWndProc_common(hWnd, uMsg, wParam, lParam, FALSE);
1116 }
1117
1118 #endif /* __REACTOS__ */
1119
1120 /**********************************************************************
1121 * Convert button styles to flags used by DrawText.
1122 */
1123 static UINT BUTTON_BStoDT( DWORD style, DWORD ex_style )
1124 {
1125 UINT dtStyle = DT_NOCLIP; /* We use SelectClipRgn to limit output */
1126
1127 /* "Convert" pushlike buttons to pushbuttons */
1128 if (style & BS_PUSHLIKE)
1129 style &= ~BS_TYPEMASK;
1130
1131 if (!(style & BS_MULTILINE))
1132 dtStyle |= DT_SINGLELINE;
1133 else
1134 dtStyle |= DT_WORDBREAK;
1135
1136 switch (style & BS_CENTER)
1137 {
1138 case BS_LEFT: /* DT_LEFT is 0 */ break;
1139 case BS_RIGHT: dtStyle |= DT_RIGHT; break;
1140 case BS_CENTER: dtStyle |= DT_CENTER; break;
1141 default:
1142 /* Pushbutton's text is centered by default */
1143 if (get_button_type(style) <= BS_DEFPUSHBUTTON) dtStyle |= DT_CENTER;
1144 /* all other flavours have left aligned text */
1145 }
1146
1147 if (ex_style & WS_EX_RIGHT) dtStyle = DT_RIGHT | (dtStyle & ~(DT_LEFT | DT_CENTER));
1148
1149 /* DrawText ignores vertical alignment for multiline text,
1150 * but we use these flags to align label manually.
1151 */
1152 if (get_button_type(style) != BS_GROUPBOX)
1153 {
1154 switch (style & BS_VCENTER)
1155 {
1156 case BS_TOP: /* DT_TOP is 0 */ break;
1157 case BS_BOTTOM: dtStyle |= DT_BOTTOM; break;
1158 case BS_VCENTER: /* fall through */
1159 default: dtStyle |= DT_VCENTER; break;
1160 }
1161 }
1162 else
1163 /* GroupBox's text is always single line and is top aligned. */
1164 dtStyle |= DT_SINGLELINE;
1165
1166 return dtStyle;
1167 }
1168
1169 /**********************************************************************
1170 * BUTTON_CalcLabelRect
1171 *
1172 * Calculates label's rectangle depending on button style.
1173 *
1174 * Returns flags to be passed to DrawText.
1175 * Calculated rectangle doesn't take into account button state
1176 * (pushed, etc.). If there is nothing to draw (no text/image) output
1177 * rectangle is empty, and return value is (UINT)-1.
1178 */
1179 static UINT BUTTON_CalcLabelRect(HWND hwnd, HDC hdc, RECT *rc)
1180 {
1181 LONG style = GetWindowLongPtrW( hwnd, GWL_STYLE );
1182 LONG ex_style = GetWindowLongPtrW( hwnd, GWL_EXSTYLE );
1183 WCHAR *text;
1184 ICONINFO iconInfo;
1185 BITMAP bm;
1186 UINT dtStyle = BUTTON_BStoDT( style, ex_style );
1187 RECT r = *rc;
1188 INT n;
1189 #ifdef __REACTOS__
1190 PBUTTON_DATA pdata = _GetButtonData(hwnd);
1191 #endif
1192
1193 /* Calculate label rectangle according to label type */
1194 switch (style & (BS_ICON|BS_BITMAP))
1195 {
1196 case BS_TEXT:
1197 {
1198 HFONT hFont, hPrevFont = 0;
1199 #ifdef __REACTOS__
1200 BOOL bHasIml;
1201
1202 bHasIml = BUTTON_DrawIml(hdc, &pdata->imlData, &r, TRUE);
1203 #endif
1204
1205 if (!(text = get_button_text( hwnd ))) goto empty_rect;
1206 if (!text[0])
1207 {
1208 HeapFree( GetProcessHeap(), 0, text );
1209 goto empty_rect;
1210 }
1211
1212 if ((hFont = get_button_font( hwnd ))) hPrevFont = SelectObject( hdc, hFont );
1213 DrawTextW(hdc, text, -1, &r, dtStyle | DT_CALCRECT);
1214 if (hPrevFont) SelectObject( hdc, hPrevFont );
1215 HeapFree( GetProcessHeap(), 0, text );
1216 #ifdef __REACTOS__
1217 if (get_ui_state(hwnd) & UISF_HIDEACCEL)
1218 dtStyle |= DT_HIDEPREFIX;
1219
1220 if (bHasIml)
1221 {
1222 if (pdata->imlData.uAlign == BUTTON_IMAGELIST_ALIGN_LEFT)
1223 r.left = pdata->imlData.margin.left;
1224 else if (pdata->imlData.uAlign == BUTTON_IMAGELIST_ALIGN_RIGHT)
1225 r.right = pdata->imlData.margin.right;
1226 else if (pdata->imlData.uAlign == BUTTON_IMAGELIST_ALIGN_TOP)
1227 r.top = pdata->imlData.margin.top;
1228 else if (pdata->imlData.uAlign == BUTTON_IMAGELIST_ALIGN_BOTTOM)
1229 r.bottom = pdata->imlData.margin.bottom;
1230 }
1231 #endif
1232 break;
1233 }
1234
1235 case BS_ICON:
1236 #ifdef _USER32_
1237 if (!GetIconInfo((HICON)GetWindowLongPtrW( hwnd, HIMAGE_GWL_OFFSET ), &iconInfo))
1238 #else
1239 if (!GetIconInfo((HICON)get_button_image(hwnd), &iconInfo))
1240 #endif
1241 goto empty_rect;
1242
1243 GetObjectW (iconInfo.hbmColor, sizeof(BITMAP), &bm);
1244
1245 r.right = r.left + bm.bmWidth;
1246 r.bottom = r.top + bm.bmHeight;
1247
1248 DeleteObject(iconInfo.hbmColor);
1249 DeleteObject(iconInfo.hbmMask);
1250 break;
1251
1252 case BS_BITMAP:
1253 #ifdef _USER32_
1254 if (!GetObjectW( (HANDLE)GetWindowLongPtrW( hwnd, HIMAGE_GWL_OFFSET ), sizeof(BITMAP), &bm))
1255 #else
1256 if (!GetObjectW( (HANDLE)get_button_image(hwnd), sizeof(BITMAP), &bm))
1257 #endif
1258 goto empty_rect;
1259
1260 r.right = r.left + bm.bmWidth;
1261 r.bottom = r.top + bm.bmHeight;
1262 break;
1263
1264 default:
1265 empty_rect:
1266 rc->right = r.left;
1267 rc->bottom = r.top;
1268 return (UINT)-1;
1269 }
1270
1271 /* Position label inside bounding rectangle according to
1272 * alignment flags. (calculated rect is always left-top aligned).
1273 * If label is aligned to any side - shift label in opposite
1274 * direction to leave extra space for focus rectangle.
1275 */
1276 switch (dtStyle & (DT_CENTER|DT_RIGHT))
1277 {
1278 case DT_LEFT: r.left++; r.right++; break;
1279 case DT_CENTER: n = r.right - r.left;
1280 r.left = rc->left + ((rc->right - rc->left) - n) / 2;
1281 r.right = r.left + n; break;
1282 case DT_RIGHT: n = r.right - r.left;
1283 r.right = rc->right - 1;
1284 r.left = r.right - n;
1285 break;
1286 }
1287
1288 switch (dtStyle & (DT_VCENTER|DT_BOTTOM))
1289 {
1290 case DT_TOP: r.top++; r.bottom++; break;
1291 case DT_VCENTER: n = r.bottom - r.top;
1292 r.top = rc->top + ((rc->bottom - rc->top) - n) / 2;
1293 r.bottom = r.top + n; break;
1294 case DT_BOTTOM: n = r.bottom - r.top;
1295 r.bottom = rc->bottom - 1;
1296 r.top = r.bottom - n;
1297 break;
1298 }
1299
1300 *rc = r;
1301 return dtStyle;
1302 }
1303
1304
1305 /**********************************************************************
1306 * BUTTON_DrawTextCallback
1307 *
1308 * Callback function used by DrawStateW function.
1309 */
1310 static BOOL CALLBACK BUTTON_DrawTextCallback(HDC hdc, LPARAM lp, WPARAM wp, int cx, int cy)
1311 {
1312 #ifdef _USER32_
1313 RECT rc;
1314
1315 SetRect(&rc, 0, 0, cx, cy);
1316 DrawTextW(hdc, (LPCWSTR)lp, -1, &rc, (UINT)wp);
1317 return TRUE;
1318 #else
1319 HWND hwnd = (HWND)lp;
1320 RECT rc;
1321 PBUTTON_DATA pdata = _GetButtonData(hwnd);
1322 WCHAR *text = NULL;
1323
1324 if (!(text = get_button_text( hwnd ))) return TRUE;
1325
1326 SetRect(&rc, 0, 0, cx, cy);
1327
1328 BUTTON_DrawIml(hdc, &pdata->imlData, &rc, FALSE);
1329
1330 DrawTextW(hdc, text, -1, &rc, (UINT)wp);
1331 HeapFree(GetProcessHeap(), 0, text);
1332 return TRUE;
1333 #endif
1334 }
1335
1336
1337 /**********************************************************************
1338 * BUTTON_DrawLabel
1339 *
1340 * Common function for drawing button label.
1341 */
1342 static void BUTTON_DrawLabel(HWND hwnd, HDC hdc, UINT dtFlags, const RECT *rc)
1343 {
1344 DRAWSTATEPROC lpOutputProc = NULL;
1345 LPARAM lp;
1346 WPARAM wp = 0;
1347 HBRUSH hbr = 0;
1348 UINT flags = IsWindowEnabled(hwnd) ? DSS_NORMAL : DSS_DISABLED;
1349 LONG state = get_button_state( hwnd );
1350 LONG style = GetWindowLongPtrW( hwnd, GWL_STYLE );
1351 WCHAR *text = NULL;
1352
1353 /* FIXME: To draw disabled label in Win31 look-and-feel, we probably
1354 * must use DSS_MONO flag and COLOR_GRAYTEXT brush (or maybe DSS_UNION).
1355 * I don't have Win31 on hand to verify that, so I leave it as is.
1356 */
1357
1358 if ((style & BS_PUSHLIKE) && (state & BST_INDETERMINATE))
1359 {
1360 hbr = GetSysColorBrush(COLOR_GRAYTEXT);
1361 flags |= DSS_MONO;
1362 }
1363
1364 switch (style & (BS_ICON|BS_BITMAP))
1365 {
1366 case BS_TEXT:
1367 /* DST_COMPLEX -- is 0 */
1368 lpOutputProc = BUTTON_DrawTextCallback;
1369 #ifdef _USER32_
1370 if (!(text = get_button_text( hwnd ))) return;
1371 lp = (LPARAM)text;
1372 #else
1373 lp = (LPARAM)hwnd;
1374 #endif
1375
1376 wp = (WPARAM)dtFlags;
1377
1378 #ifdef __REACTOS__
1379 if (dtFlags & DT_HIDEPREFIX)
1380 flags |= DSS_HIDEPREFIX;
1381 #endif
1382 break;
1383
1384 case BS_ICON:
1385 flags |= DST_ICON;
1386 #ifdef _USER32_
1387 lp = GetWindowLongPtrW( hwnd, HIMAGE_GWL_OFFSET );
1388 #else
1389 lp = get_button_image(hwnd);
1390 #endif
1391 break;
1392
1393 case BS_BITMAP:
1394 flags |= DST_BITMAP;
1395 #ifdef _USER32_
1396 lp = GetWindowLongPtrW( hwnd, HIMAGE_GWL_OFFSET );
1397 #else
1398 lp = get_button_image(hwnd);
1399 #endif
1400 break;
1401
1402 default:
1403 return;
1404 }
1405
1406 DrawStateW(hdc, hbr, lpOutputProc, lp, wp, rc->left, rc->top,
1407 rc->right - rc->left, rc->bottom - rc->top, flags);
1408 HeapFree( GetProcessHeap(), 0, text );
1409 }
1410
1411 /**********************************************************************
1412 * Push Button Functions
1413 */
1414 static void PB_Paint( HWND hwnd, HDC hDC, UINT action )
1415 {
1416 RECT rc, r;
1417 UINT dtFlags, uState;
1418 HPEN hOldPen;
1419 HBRUSH hOldBrush;
1420 INT oldBkMode;
1421 COLORREF oldTxtColor;
1422 HFONT hFont;
1423 LONG state = get_button_state( hwnd );
1424 LONG style = GetWindowLongPtrW( hwnd, GWL_STYLE );
1425 BOOL pushedState = (state & BST_PUSHED);
1426 HWND parent;
1427 HRGN hrgn;
1428
1429 GetClientRect( hwnd, &rc );
1430
1431 /* Send WM_CTLCOLOR to allow changing the font (the colors are fixed) */
1432 if ((hFont = get_button_font( hwnd ))) SelectObject( hDC, hFont );
1433 parent = GetParent(hwnd);
1434 if (!parent) parent = hwnd;
1435 #if defined(__REACTOS__) && defined(_USER32_)
1436 GetControlColor( parent, hwnd, hDC, WM_CTLCOLORBTN);
1437 #else
1438 SendMessageW( parent, WM_CTLCOLORBTN, (WPARAM)hDC, (LPARAM)hwnd );
1439 #endif
1440
1441 hrgn = set_control_clipping( hDC, &rc );
1442 #ifdef __REACTOS__
1443 hOldPen = SelectObject(hDC, GetStockObject(DC_PEN));
1444 SetDCPenColor(hDC, GetSysColor(COLOR_WINDOWFRAME));
1445 #else
1446 hOldPen = SelectObject(hDC, SYSCOLOR_GetPen(COLOR_WINDOWFRAME));
1447 #endif
1448 hOldBrush = SelectObject(hDC,GetSysColorBrush(COLOR_BTNFACE));
1449 oldBkMode = SetBkMode(hDC, TRANSPARENT);
1450
1451 if (get_button_type(style) == BS_DEFPUSHBUTTON)
1452 {
1453 if (action != ODA_FOCUS)
1454 Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom);
1455 InflateRect( &rc, -1, -1 );
1456 }
1457
1458 /* completely skip the drawing if only focus has changed */
1459 if (action == ODA_FOCUS) goto draw_focus;
1460
1461 uState = DFCS_BUTTONPUSH;
1462
1463 if (style & BS_FLAT)
1464 uState |= DFCS_MONO;
1465 else if (pushedState)
1466 {
1467 if (get_button_type(style) == BS_DEFPUSHBUTTON )
1468 uState |= DFCS_FLAT;
1469 else
1470 uState |= DFCS_PUSHED;
1471 }
1472
1473 if (state & (BST_CHECKED | BST_INDETERMINATE))
1474 uState |= DFCS_CHECKED;
1475
1476 DrawFrameControl( hDC, &rc, DFC_BUTTON, uState );
1477
1478 /* draw button label */
1479 r = rc;
1480 dtFlags = BUTTON_CalcLabelRect(hwnd, hDC, &r);
1481
1482 if (dtFlags == (UINT)-1L)
1483 goto cleanup;
1484
1485 if (pushedState)
1486 OffsetRect(&r, 1, 1);
1487
1488 oldTxtColor = SetTextColor( hDC, GetSysColor(COLOR_BTNTEXT) );
1489
1490 BUTTON_DrawLabel(hwnd, hDC, dtFlags, &r);
1491
1492 SetTextColor( hDC, oldTxtColor );
1493
1494 draw_focus:
1495 if (action == ODA_FOCUS || (state & BST_FOCUS))
1496 {
1497 #ifdef __REACTOS__
1498 if (!(get_ui_state(hwnd) & UISF_HIDEFOCUS))
1499 {
1500 #endif
1501 InflateRect( &rc, -2, -2 );
1502 DrawFocusRect( hDC, &rc );
1503 #ifdef __REACTOS__
1504 }
1505 #endif
1506 }
1507
1508 cleanup:
1509 SelectObject( hDC, hOldPen );
1510 SelectObject( hDC, hOldBrush );
1511 SetBkMode(hDC, oldBkMode);
1512 SelectClipRgn( hDC, hrgn );
1513 if (hrgn) DeleteObject( hrgn );
1514 }
1515
1516 /**********************************************************************
1517 * Check Box & Radio Button Functions
1518 */
1519
1520 static void CB_Paint( HWND hwnd, HDC hDC, UINT action )
1521 {
1522 RECT rbox, rtext, client;
1523 HBRUSH hBrush;
1524 int delta, text_offset, checkBoxWidth, checkBoxHeight;
1525 UINT dtFlags;
1526 HFONT hFont;
1527 LONG state = get_button_state( hwnd );
1528 LONG style = GetWindowLongPtrW( hwnd, GWL_STYLE );
1529 LONG ex_style = GetWindowLongW( hwnd, GWL_EXSTYLE );
1530 HWND parent;
1531 HRGN hrgn;
1532
1533 if (style & BS_PUSHLIKE)
1534 {
1535 PB_Paint( hwnd, hDC, action );
1536 return;
1537 }
1538
1539 GetClientRect(hwnd, &client);
1540 rbox = rtext = client;
1541
1542 checkBoxWidth = 12 * GetDeviceCaps( hDC, LOGPIXELSX ) / 96 + 1;
1543 checkBoxHeight = 12 * GetDeviceCaps( hDC, LOGPIXELSY ) / 96 + 1;
1544
1545 if ((hFont = get_button_font( hwnd ))) SelectObject( hDC, hFont );
1546 GetCharWidthW( hDC, '0', '0', &text_offset );
1547 text_offset /= 2;
1548
1549 parent = GetParent(hwnd);
1550 if (!parent) parent = hwnd;
1551 #if defined(__REACTOS__) && defined(_USER32_)
1552 hBrush = GetControlColor(parent, hwnd, hDC, WM_CTLCOLORSTATIC);
1553 #else
1554 hBrush = (HBRUSH)SendMessageW(parent, WM_CTLCOLORSTATIC,
1555 (WPARAM)hDC, (LPARAM)hwnd);
1556 if (!hBrush) /* did the app forget to call defwindowproc ? */
1557 hBrush = (HBRUSH)DefWindowProcW(parent, WM_CTLCOLORSTATIC,
1558 (WPARAM)hDC, (LPARAM)hwnd );
1559 #endif
1560 hrgn = set_control_clipping( hDC, &client );
1561
1562 if (style & BS_LEFTTEXT || ex_style & WS_EX_RIGHT)
1563 {
1564 /* magic +4 is what CTL3D expects */
1565
1566 rtext.right -= checkBoxWidth + text_offset;;
1567 rbox.left = rbox.right - checkBoxWidth;
1568 }
1569 else
1570 {
1571 rtext.left += checkBoxWidth + text_offset;;
1572 rbox.right = checkBoxWidth;
1573 }
1574
1575 /* Since WM_ERASEBKGND does nothing, first prepare background */
1576 if (action == ODA_SELECT) FillRect( hDC, &rbox, hBrush );
1577 if (action == ODA_DRAWENTIRE) FillRect( hDC, &client, hBrush );
1578
1579 /* Draw label */
1580 client = rtext;
1581 dtFlags = BUTTON_CalcLabelRect(hwnd, hDC, &rtext);
1582
1583 /* Only adjust rbox when rtext is valid */
1584 if (dtFlags != (UINT)-1L)
1585 {
1586 rbox.top = rtext.top;
1587 rbox.bottom = rtext.bottom;
1588 }
1589
1590 /* Draw the check-box bitmap */
1591 if (action == ODA_DRAWENTIRE || action == ODA_SELECT)
1592 {
1593 UINT flags;
1594
1595 if ((get_button_type(style) == BS_RADIOBUTTON) ||
1596 (get_button_type(style) == BS_AUTORADIOBUTTON)) flags = DFCS_BUTTONRADIO;
1597 else if (state & BST_INDETERMINATE) flags = DFCS_BUTTON3STATE;
1598 else flags = DFCS_BUTTONCHECK;
1599
1600 if (state & (BST_CHECKED | BST_INDETERMINATE)) flags |= DFCS_CHECKED;
1601 if (state & BST_PUSHED) flags |= DFCS_PUSHED;
1602
1603 if (style & WS_DISABLED) flags |= DFCS_INACTIVE;
1604
1605 /* rbox must have the correct height */
1606 delta = rbox.bottom - rbox.top - checkBoxHeight;
1607
1608 if (style & BS_TOP) {
1609 if (delta > 0) {
1610 rbox.bottom = rbox.top + checkBoxHeight;
1611 } else {
1612 rbox.top -= -delta/2 + 1;
1613 rbox.bottom = rbox.top + checkBoxHeight;
1614 }
1615 } else if (style & BS_BOTTOM) {
1616 if (delta > 0) {
1617 rbox.top = rbox.bottom - checkBoxHeight;
1618 } else {
1619 rbox.bottom += -delta/2 + 1;
1620 rbox.top = rbox.bottom - checkBoxHeight;
1621 }
1622 } else { /* Default */
1623 if (delta > 0) {
1624 int ofs = (delta / 2);
1625 rbox.bottom -= ofs + 1;
1626 rbox.top = rbox.bottom - checkBoxHeight;
1627 } else if (delta < 0) {
1628 int ofs = (-delta / 2);
1629 rbox.top -= ofs + 1;
1630 rbox.bottom = rbox.top + checkBoxHeight;
1631 }
1632 }
1633
1634 DrawFrameControl( hDC, &rbox, DFC_BUTTON, flags );
1635 }
1636
1637 if (dtFlags == (UINT)-1L) /* Noting to draw */
1638 return;
1639
1640 if (action == ODA_DRAWENTIRE)
1641 BUTTON_DrawLabel(hwnd, hDC, dtFlags, &rtext);
1642
1643 /* ... and focus */
1644 if (action == ODA_FOCUS || (state & BST_FOCUS))
1645 {
1646 #ifdef __REACTOS__
1647 if (!(get_ui_state(hwnd) & UISF_HIDEFOCUS))
1648 {
1649 #endif
1650 rtext.left--;
1651 rtext.right++;
1652 IntersectRect(&rtext, &rtext, &client);
1653 DrawFocusRect( hDC, &rtext );
1654 #ifdef __REACTOS__
1655 }
1656 #endif
1657 }
1658 SelectClipRgn( hDC, hrgn );
1659 if (hrgn) DeleteObject( hrgn );
1660 }
1661
1662
1663 /**********************************************************************
1664 * BUTTON_CheckAutoRadioButton
1665 *
1666 * hwnd is checked, uncheck every other auto radio button in group
1667 */
1668 static void BUTTON_CheckAutoRadioButton( HWND hwnd )
1669 {
1670 HWND parent, sibling, start;
1671
1672 parent = GetParent(hwnd);
1673 /* make sure that starting control is not disabled or invisible */
1674 start = sibling = GetNextDlgGroupItem( parent, hwnd, TRUE );
1675 do
1676 {
1677 if (!sibling) break;
1678 if ((hwnd != sibling) &&
1679 ((GetWindowLongPtrW( sibling, GWL_STYLE) & BS_TYPEMASK) == BS_AUTORADIOBUTTON))
1680 SendMessageW( sibling, BM_SETCHECK, BST_UNCHECKED, 0 );
1681 sibling = GetNextDlgGroupItem( parent, sibling, FALSE );
1682 } while (sibling != start);
1683 }
1684
1685
1686 /**********************************************************************
1687 * Group Box Functions
1688 */
1689
1690 static void GB_Paint( HWND hwnd, HDC hDC, UINT action )
1691 {
1692 RECT rc, rcFrame;
1693 HBRUSH hbr;
1694 HFONT hFont;
1695 UINT dtFlags;
1696 TEXTMETRICW tm;
1697 LONG style = GetWindowLongPtrW( hwnd, GWL_STYLE );
1698 HWND parent;
1699 HRGN hrgn;
1700
1701 if ((hFont = get_button_font( hwnd ))) SelectObject( hDC, hFont );
1702 /* GroupBox acts like static control, so it sends CTLCOLORSTATIC */
1703 parent = GetParent(hwnd);
1704 if (!parent) parent = hwnd;
1705 #if defined(__REACTOS__) && defined(_USER32_)
1706 hbr = GetControlColor(parent, hwnd, hDC, WM_CTLCOLORSTATIC);
1707 #else
1708 hbr = (HBRUSH)SendMessageW(parent, WM_CTLCOLORSTATIC, (WPARAM)hDC, (LPARAM)hwnd);
1709 if (!hbr) /* did the app forget to call defwindowproc ? */
1710 hbr = (HBRUSH)DefWindowProcW(parent, WM_CTLCOLORSTATIC,
1711 (WPARAM)hDC, (LPARAM)hwnd);
1712 #endif
1713 GetClientRect( hwnd, &rc);
1714 rcFrame = rc;
1715 hrgn = set_control_clipping( hDC, &rc );
1716
1717 GetTextMetricsW (hDC, &tm);
1718 rcFrame.top += (tm.tmHeight / 2) - 1;
1719 DrawEdge (hDC, &rcFrame, EDGE_ETCHED, BF_RECT | ((style & BS_FLAT) ? BF_FLAT : 0));
1720
1721 InflateRect(&rc, -7, 1);
1722 dtFlags = BUTTON_CalcLabelRect(hwnd, hDC, &rc);
1723
1724 if (dtFlags != (UINT)-1L)
1725 {
1726 /* Because buttons have CS_PARENTDC class style, there is a chance
1727 * that label will be drawn out of client rect.
1728 * But Windows doesn't clip label's rect, so do I.
1729 */
1730
1731 /* There is 1-pixel margin at the left, right, and bottom */
1732 rc.left--; rc.right++; rc.bottom++;
1733 FillRect(hDC, &rc, hbr);
1734 rc.left++; rc.right--; rc.bottom--;
1735
1736 BUTTON_DrawLabel(hwnd, hDC, dtFlags, &rc);
1737 }
1738 SelectClipRgn( hDC, hrgn );
1739 if (hrgn) DeleteObject( hrgn );
1740 }
1741
1742
1743 /**********************************************************************
1744 * User Button Functions
1745 */
1746
1747 static void UB_Paint( HWND hwnd, HDC hDC, UINT action )
1748 {
1749 RECT rc;
1750 HBRUSH hBrush;
1751 HFONT hFont;
1752 LONG state = get_button_state( hwnd );
1753 HWND parent;
1754
1755 GetClientRect( hwnd, &rc);
1756
1757 if ((hFont = get_button_font( hwnd ))) SelectObject( hDC, hFont );
1758
1759 parent = GetParent(hwnd);
1760 if (!parent) parent = hwnd;
1761 #if defined(__REACTOS__) && defined(_USER32_)
1762 hBrush = GetControlColor( parent, hwnd, hDC, WM_CTLCOLORBTN);
1763 #else
1764 hBrush = (HBRUSH)SendMessageW(parent, WM_CTLCOLORBTN, (WPARAM)hDC, (LPARAM)hwnd);
1765 if (!hBrush) /* did the app forget to call defwindowproc ? */
1766 hBrush = (HBRUSH)DefWindowProcW(parent, WM_CTLCOLORBTN,
1767 (WPARAM)hDC, (LPARAM)hwnd);
1768 #endif
1769
1770 FillRect( hDC, &rc, hBrush );
1771 if (action == ODA_FOCUS || (state & BST_FOCUS))
1772 #ifdef __REACTOS__
1773 {
1774 if (!(get_ui_state(hwnd) & UISF_HIDEFOCUS))
1775 #endif
1776 DrawFocusRect( hDC, &rc );
1777 #ifdef __REACTOS__
1778 }
1779 #endif
1780
1781 switch (action)
1782 {
1783 case ODA_FOCUS:
1784 BUTTON_NOTIFY_PARENT( hwnd, (state & BST_FOCUS) ? BN_SETFOCUS : BN_KILLFOCUS );
1785 break;
1786
1787 case ODA_SELECT:
1788 BUTTON_NOTIFY_PARENT( hwnd, (state & BST_PUSHED) ? BN_HILITE : BN_UNHILITE );
1789 break;
1790
1791 default:
1792 BUTTON_NOTIFY_PARENT( hwnd, BN_PAINT );
1793 break;
1794 }
1795 }
1796
1797
1798 /**********************************************************************
1799 * Ownerdrawn Button Functions
1800 */
1801
1802 static void OB_Paint( HWND hwnd, HDC hDC, UINT action )
1803 {
1804 LONG state = get_button_state( hwnd );
1805 DRAWITEMSTRUCT dis;
1806 LONG_PTR id = GetWindowLongPtrW( hwnd, GWLP_ID );
1807 HWND parent;
1808 HFONT hFont, hPrevFont = 0;
1809 HRGN hrgn;
1810
1811 dis.CtlType = ODT_BUTTON;
1812 dis.CtlID = id;
1813 dis.itemID = 0;
1814 dis.itemAction = action;
1815 dis.itemState = ((state & BST_FOCUS) ? ODS_FOCUS : 0) |
1816 ((state & BST_PUSHED) ? ODS_SELECTED : 0) |
1817 (IsWindowEnabled(hwnd) ? 0: ODS_DISABLED);
1818 dis.hwndItem = hwnd;
1819 dis.hDC = hDC;
1820 dis.itemData = 0;
1821 GetClientRect( hwnd, &dis.rcItem );
1822
1823 if ((hFont = get_button_font( hwnd ))) hPrevFont = SelectObject( hDC, hFont );
1824 parent = GetParent(hwnd);
1825 if (!parent) parent = hwnd;
1826 #if defined(__REACTOS__) && defined(_USER32_)
1827 GetControlColor( parent, hwnd, hDC, WM_CTLCOLORBTN);
1828 #else
1829 SendMessageW( parent, WM_CTLCOLORBTN, (WPARAM)hDC, (LPARAM)hwnd );
1830 #endif
1831
1832 hrgn = set_control_clipping( hDC, &dis.rcItem );
1833
1834 SendMessageW( GetParent(hwnd), WM_DRAWITEM, id, (LPARAM)&dis );
1835 if (hPrevFont) SelectObject(hDC, hPrevFont);
1836 SelectClipRgn( hDC, hrgn );
1837 if (hrgn) DeleteObject( hrgn );
1838 }
1839
1840 #ifndef _USER32_
1841 void BUTTON_Register()
1842 {
1843 WNDCLASSW wndClass;
1844
1845 ZeroMemory(&wndClass, sizeof(WNDCLASSW));
1846 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW | CS_PARENTDC;
1847 wndClass.lpfnWndProc = ButtonWndProcW;
1848 wndClass.cbClsExtra = 0;
1849 wndClass.cbWndExtra = sizeof(PBUTTON_DATA);
1850 wndClass.hCursor = LoadCursorW(0, (LPCWSTR)IDC_ARROW);
1851 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
1852 wndClass.lpszClassName = WC_BUTTONW;
1853
1854 RegisterClassW(&wndClass);
1855 }
1856
1857 void BUTTON_Unregister()
1858 {
1859 UnregisterClassW(WC_BUTTONW, NULL);
1860 }
1861 #endif