ReactOS  0.4.14-dev-41-g31d7680
button.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1993 Johannes Ruscheinski
3  * Copyright (C) 1993 David Metcalfe
4  * Copyright (C) 1994 Alexandre Julliard
5  * Copyright (C) 2008 by Reece H. Dunn
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  * TODO
22  * Styles
23  * - BS_NOTIFY: is it complete?
24  * - BS_RIGHTBUTTON: same as BS_LEFTTEXT
25  *
26  * Messages
27  * - WM_CHAR: Checks a (manual or automatic) check box on '+' or '=', clears it on '-' key.
28  * - WM_SETFOCUS: For (manual or automatic) radio buttons, send the parent window BN_CLICKED
29  * - WM_NCCREATE: Turns any BS_OWNERDRAW button into a BS_PUSHBUTTON button.
30  * - WM_SYSKEYUP
31  * - BCM_GETIDEALSIZE
32  * - BCM_GETIMAGELIST
33  * - BCM_GETTEXTMARGIN
34  * - BCM_SETIMAGELIST
35  * - BCM_SETTEXTMARGIN
36  *
37  * Notifications
38  * - BCN_HOTITEMCHANGE
39  * - BN_DISABLE
40  * - BN_PUSHED/BN_HILITE
41  * + BN_KILLFOCUS: is it OK?
42  * - BN_PAINT
43  * + BN_SETFOCUS: is it OK?
44  * - BN_UNPUSHED/BN_UNHILITE
45  * - NM_CUSTOMDRAW
46  *
47  * Structures/Macros/Definitions
48  * - BUTTON_IMAGELIST
49  * - NMBCHOTITEM
50  * - Button_GetIdealSize
51  * - Button_GetImageList
52  * - Button_GetTextMargin
53  * - Button_SetImageList
54  * - Button_SetTextMargin
55  */
56 
57 #include <stdarg.h>
58 #include <string.h>
59 #include <stdlib.h>
60 
61 #define OEMRESOURCE
62 
63 #include "windef.h"
64 #include "winbase.h"
65 #include "wingdi.h"
66 #include "winuser.h"
67 #include "uxtheme.h"
68 #include "vssym32.h"
69 #include "wine/debug.h"
70 #include "wine/heap.h"
71 
72 #include "comctl32.h"
73 
75 
76 /* undocumented flags */
77 #define BUTTON_NSTATES 0x0F
78 #define BUTTON_BTNPRESSED 0x40
79 #define BUTTON_UNKNOWN2 0x20
80 #define BUTTON_UNKNOWN3 0x10
81 #ifdef __REACTOS__
82 #define BUTTON_BMCLICK 0x100 // ReactOS Need to up to wine!
83 #endif
84 
85 #define BUTTON_NOTIFY_PARENT(hWnd, code) \
86  do { /* Notify parent which has created this button control */ \
87  TRACE("notification " #code " sent to hwnd=%p\n", GetParent(hWnd)); \
88  SendMessageW(GetParent(hWnd), WM_COMMAND, \
89  MAKEWPARAM(GetWindowLongPtrW((hWnd),GWLP_ID), (code)), \
90  (LPARAM)(hWnd)); \
91  } while(0)
92 
93 typedef struct _BUTTON_INFO
94 {
98  union
99  {
103  } u;
104 
105 #ifdef __REACTOS__
106  DWORD ui_state;
107  RECT rcTextMargin;
108  BUTTON_IMAGELIST imlData;
109 #endif
110 } BUTTON_INFO;
111 
112 static UINT BUTTON_CalcLabelRect( const BUTTON_INFO *infoPtr, HDC hdc, RECT *rc );
113 static void PB_Paint( const BUTTON_INFO *infoPtr, HDC hDC, UINT action );
114 static void CB_Paint( const BUTTON_INFO *infoPtr, HDC hDC, UINT action );
115 static void GB_Paint( const BUTTON_INFO *infoPtr, HDC hDC, UINT action );
116 static void UB_Paint( const BUTTON_INFO *infoPtr, HDC hDC, UINT action );
117 static void OB_Paint( const BUTTON_INFO *infoPtr, HDC hDC, UINT action );
118 static void BUTTON_CheckAutoRadioButton( HWND hwnd );
119 
120 #define MAX_BTN_TYPE 16
121 
123 {
124  BST_UNCHECKED, /* BS_PUSHBUTTON */
125  BST_UNCHECKED, /* BS_DEFPUSHBUTTON */
126  BST_CHECKED, /* BS_CHECKBOX */
127  BST_CHECKED, /* BS_AUTOCHECKBOX */
128  BST_CHECKED, /* BS_RADIOBUTTON */
129  BST_INDETERMINATE, /* BS_3STATE */
130  BST_INDETERMINATE, /* BS_AUTO3STATE */
131  BST_UNCHECKED, /* BS_GROUPBOX */
132  BST_UNCHECKED, /* BS_USERBUTTON */
133  BST_CHECKED, /* BS_AUTORADIOBUTTON */
134  BST_UNCHECKED, /* BS_PUSHBOX */
135  BST_UNCHECKED, /* BS_OWNERDRAW */
136  BST_UNCHECKED, /* BS_SPLITBUTTON */
137  BST_UNCHECKED, /* BS_DEFSPLITBUTTON */
138  BST_UNCHECKED, /* BS_COMMANDLINK */
139  BST_UNCHECKED /* BS_DEFCOMMANDLINK */
140 };
141 
142 /* These are indices into a states array to determine the theme state for a given theme part. */
143 typedef enum
144 {
150 } ButtonState;
151 
152 typedef void (*pfPaint)( const BUTTON_INFO *infoPtr, HDC hdc, UINT action );
153 
155 {
156  PB_Paint, /* BS_PUSHBUTTON */
157  PB_Paint, /* BS_DEFPUSHBUTTON */
158  CB_Paint, /* BS_CHECKBOX */
159  CB_Paint, /* BS_AUTOCHECKBOX */
160  CB_Paint, /* BS_RADIOBUTTON */
161  CB_Paint, /* BS_3STATE */
162  CB_Paint, /* BS_AUTO3STATE */
163  GB_Paint, /* BS_GROUPBOX */
164  UB_Paint, /* BS_USERBUTTON */
165  CB_Paint, /* BS_AUTORADIOBUTTON */
166  NULL, /* BS_PUSHBOX */
167  OB_Paint, /* BS_OWNERDRAW */
168  PB_Paint, /* BS_SPLITBUTTON */
169  PB_Paint, /* BS_DEFSPLITBUTTON */
170  PB_Paint, /* BS_COMMANDLINK */
171  PB_Paint /* BS_DEFCOMMANDLINK */
172 };
173 
174 
175 #ifdef __REACTOS__ /* r73885 */
176 typedef void (*pfThemedPaint)( HTHEME theme, const BUTTON_INFO *infoPtr, HDC hdc, ButtonState drawState, UINT dtflags, BOOL focused, LPARAM prfFlag);
177 
178 static void PB_ThemedPaint( HTHEME theme, const BUTTON_INFO *infoPtr, HDC hdc, ButtonState drawState, UINT dtflags, BOOL focused, LPARAM prfFlag);
179 static void CB_ThemedPaint( HTHEME theme, const BUTTON_INFO *infoPtr, HDC hdc, ButtonState drawState, UINT dtflags, BOOL focused, LPARAM prfFlag);
180 static void GB_ThemedPaint( HTHEME theme, const BUTTON_INFO *infoPtr, HDC hdc, ButtonState drawState, UINT dtflags, BOOL focused, LPARAM prfFlag);
181 
182 #else
183 typedef void (*pfThemedPaint)( HTHEME theme, const BUTTON_INFO *infoPtr, HDC hdc, ButtonState drawState, UINT dtflags, BOOL focused);
184 
185 static void PB_ThemedPaint( HTHEME theme, const BUTTON_INFO *infoPtr, HDC hdc, ButtonState drawState, UINT dtflags, BOOL focused);
186 static void CB_ThemedPaint( HTHEME theme, const BUTTON_INFO *infoPtr, HDC hdc, ButtonState drawState, UINT dtflags, BOOL focused);
187 static void GB_ThemedPaint( HTHEME theme, const BUTTON_INFO *infoPtr, HDC hdc, ButtonState drawState, UINT dtflags, BOOL focused);
188 
189 #endif
190 
192 {
193  PB_ThemedPaint, /* BS_PUSHBUTTON */
194  PB_ThemedPaint, /* BS_DEFPUSHBUTTON */
195  CB_ThemedPaint, /* BS_CHECKBOX */
196  CB_ThemedPaint, /* BS_AUTOCHECKBOX */
197  CB_ThemedPaint, /* BS_RADIOBUTTON */
198  CB_ThemedPaint, /* BS_3STATE */
199  CB_ThemedPaint, /* BS_AUTO3STATE */
200  GB_ThemedPaint, /* BS_GROUPBOX */
201  NULL, /* BS_USERBUTTON */
202  CB_ThemedPaint, /* BS_AUTORADIOBUTTON */
203  NULL, /* BS_PUSHBOX */
204  NULL, /* BS_OWNERDRAW */
205  NULL, /* BS_SPLITBUTTON */
206  NULL, /* BS_DEFSPLITBUTTON */
207  NULL, /* BS_COMMANDLINK */
208  NULL, /* BS_DEFCOMMANDLINK */
209 };
210 
211 static inline UINT get_button_type( LONG window_style )
212 {
213  return (window_style & BS_TYPEMASK);
214 }
215 
216 #ifndef __REACTOS__
217 /* paint a button of any type */
218 static inline void paint_button( BUTTON_INFO *infoPtr, LONG style, UINT action )
219 {
220  if (btnPaintFunc[style] && IsWindowVisible(infoPtr->hwnd))
221  {
222  HDC hdc = GetDC( infoPtr->hwnd );
223  btnPaintFunc[style]( infoPtr, hdc, action );
224  ReleaseDC( infoPtr->hwnd, hdc );
225  }
226 }
227 #endif
228 
229 /* retrieve the button text; returned buffer must be freed by caller */
230 static inline WCHAR *get_button_text( const BUTTON_INFO *infoPtr )
231 {
232  INT len = GetWindowTextLengthW( infoPtr->hwnd );
233  WCHAR *buffer = heap_alloc( (len + 1) * sizeof(WCHAR) );
234  if (buffer)
235  GetWindowTextW( infoPtr->hwnd, buffer, len + 1 );
236  return buffer;
237 }
238 
240 {
241  RECT rc = *rect;
242  HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
243 
244  if (GetClipRgn( hdc, hrgn ) != 1)
245  {
246  DeleteObject( hrgn );
247  hrgn = 0;
248  }
249  DPtoLP( hdc, (POINT *)&rc, 2 );
250  if (GetLayout( hdc ) & LAYOUT_RTL) /* compensate for the shifting done by IntersectClipRect */
251  {
252  rc.left++;
253  rc.right++;
254  }
255  IntersectClipRect( hdc, rc.left, rc.top, rc.right, rc.bottom );
256  return hrgn;
257 }
258 
259 /**********************************************************************
260  * Convert button styles to flags used by DrawText.
261  */
262 static UINT BUTTON_BStoDT( DWORD style, DWORD ex_style )
263 {
264  UINT dtStyle = DT_NOCLIP; /* We use SelectClipRgn to limit output */
265 
266  /* "Convert" pushlike buttons to pushbuttons */
267  if (style & BS_PUSHLIKE)
268  style &= ~BS_TYPEMASK;
269 
270  if (!(style & BS_MULTILINE))
271  dtStyle |= DT_SINGLELINE;
272  else
273  dtStyle |= DT_WORDBREAK;
274 
275  switch (style & BS_CENTER)
276  {
277  case BS_LEFT: /* DT_LEFT is 0 */ break;
278  case BS_RIGHT: dtStyle |= DT_RIGHT; break;
279  case BS_CENTER: dtStyle |= DT_CENTER; break;
280  default:
281  /* Pushbutton's text is centered by default */
282  if (get_button_type(style) <= BS_DEFPUSHBUTTON) dtStyle |= DT_CENTER;
283  /* all other flavours have left aligned text */
284  }
285 
286  if (ex_style & WS_EX_RIGHT) dtStyle = DT_RIGHT | (dtStyle & ~(DT_LEFT | DT_CENTER));
287 
288  /* DrawText ignores vertical alignment for multiline text,
289  * but we use these flags to align label manually.
290  */
292  {
293  switch (style & BS_VCENTER)
294  {
295  case BS_TOP: /* DT_TOP is 0 */ break;
296  case BS_BOTTOM: dtStyle |= DT_BOTTOM; break;
297  case BS_VCENTER: /* fall through */
298  default: dtStyle |= DT_VCENTER; break;
299  }
300  }
301  else
302  /* GroupBox's text is always single line and is top aligned. */
303  dtStyle |= DT_SINGLELINE;
304 
305  return dtStyle;
306 }
307 
308 
309 #ifdef __REACTOS__
310 BOOL BUTTON_PaintWithTheme(HTHEME theme, const BUTTON_INFO *infoPtr, HDC hParamDC, LPARAM prfFlag)
311 {
312  DWORD dwStyle;
313  DWORD dwStyleEx;
314  DWORD type;
315  UINT dtFlags;
316  ButtonState drawState;
317  pfThemedPaint paint;
318 
319  /* Don't draw with themes on a button with BS_ICON or BS_BITMAP */
320  if (infoPtr->u.image != 0)
321  return FALSE;
322 
323  dwStyle = GetWindowLongW(infoPtr->hwnd, GWL_STYLE);
324  type = get_button_type(dwStyle);
325 
326  if (type != BS_PUSHBUTTON && type != BS_DEFPUSHBUTTON && (dwStyle & BS_PUSHLIKE))
328 
329  paint = btnThemedPaintFunc[type];
330  if (!paint)
331  return FALSE;
332 
333  dwStyleEx = GetWindowLongW(infoPtr->hwnd, GWL_EXSTYLE);
334  dtFlags = BUTTON_BStoDT(dwStyle, dwStyleEx);
335 
336  if(dwStyle & WS_DISABLED)
337  drawState = STATE_DISABLED;
338  else if(infoPtr->state & BST_PUSHED)
339  drawState = STATE_PRESSED;
340  else if ((dwStyle & BS_PUSHLIKE) && (infoPtr->state & (BST_CHECKED|BST_INDETERMINATE)))
341  drawState = STATE_PRESSED;
342  else if(infoPtr->state & BST_HOT)
343  drawState = STATE_HOT;
344  else if((infoPtr->state & BST_FOCUS) || (dwStyle & BS_DEFPUSHBUTTON))
345  drawState = STATE_DEFAULTED;
346  else
347  drawState = STATE_NORMAL;
348 
349  if (paint == PB_ThemedPaint || paint == CB_ThemedPaint)
350  {
351  HDC hdc;
352  HBITMAP hbmp;
353  RECT rc;
354 
355  GetClientRect(infoPtr->hwnd, &rc);
356  hdc = CreateCompatibleDC(hParamDC);
357  hbmp = CreateCompatibleBitmap(hParamDC, rc.right, rc.bottom);
358  if (hdc && hbmp)
359  {
361 
362  paint(theme, infoPtr, hdc, drawState, dtFlags, infoPtr->state & BST_FOCUS, prfFlag);
363 
364  BitBlt(hParamDC, 0, 0, rc.right, rc.bottom, hdc, 0, 0, SRCCOPY);
366  DeleteDC(hdc);
367  return TRUE;
368  }
369  else
370  {
371  ERR("Failed to create DC and bitmap for double buffering\n");
372  if (hbmp)
374  if (hdc)
375  DeleteDC(hdc);
376  }
377  }
378 
379  paint(theme, infoPtr, hParamDC, drawState, dtFlags, infoPtr->state & BST_FOCUS, prfFlag);
380  return TRUE;
381 }
382 
383 /* paint a button of any type */
384 static inline void paint_button( BUTTON_INFO *infoPtr, LONG style, UINT action )
385 {
386  HTHEME theme = GetWindowTheme(infoPtr->hwnd);
387  RECT rc;
388  HDC hdc = GetDC( infoPtr->hwnd );
389  /* GetDC appears to give a dc with a clip rect that includes the whoe parent, not sure if it is correct or not. */
390  GetClientRect(infoPtr->hwnd, &rc);
391  IntersectClipRect (hdc, rc.left, rc. top, rc.right, rc.bottom);
392  if (theme && BUTTON_PaintWithTheme(theme, infoPtr, hdc, 0))
393  {
394  ReleaseDC( infoPtr->hwnd, hdc );
395  return;
396  }
397  if (btnPaintFunc[style] && IsWindowVisible(infoPtr->hwnd))
398  {
399  btnPaintFunc[style]( infoPtr, hdc, action );
400  }
401  ReleaseDC( infoPtr->hwnd, hdc );
402 }
403 
404 BOOL BUTTON_GetIdealSize(BUTTON_INFO *infoPtr, HTHEME theme, SIZE* psize)
405 {
406  HDC hdc;
407  WCHAR *text;
408  HFONT hFont = 0, hPrevFont = 0;
409  SIZE TextSize, ImageSize, ButtonSize;
410  BOOL ret = FALSE;
411  LOGFONTW logfont = {0};
412 
413  text = get_button_text(infoPtr);
414  hdc = GetDC(infoPtr->hwnd);
415  if (!text || !hdc || !text[0])
416  goto cleanup;
417 
418  /* FIXME : Should use GetThemeTextExtent but unfortunately uses DrawTextW which is broken */
419  if (theme)
420  {
421  HRESULT hr = GetThemeFont(theme, hdc, BP_PUSHBUTTON, PBS_NORMAL, TMT_FONT, &logfont);
422  if(SUCCEEDED(hr))
423  {
424  hFont = CreateFontIndirectW(&logfont);
425  if(hFont)
426  hPrevFont = SelectObject( hdc, hFont );
427  }
428  }
429  else
430  {
431  if (infoPtr->font)
432  hPrevFont = SelectObject( hdc, infoPtr->font );
433  }
434 
435  GetTextExtentPoint32W(hdc, text, wcslen(text), &TextSize);
436 
437  if (logfont.lfHeight == -1 && logfont.lfWidth == 0 && wcscmp(logfont.lfFaceName, L"Arial") == 0 && wcsicmp(text, L"Start") == 0)
438  {
439  TextSize.cx = 5;
440  TextSize.cy = 4;
441  }
442 
443  if (hPrevFont)
444  SelectObject( hdc, hPrevFont );
445 
446  TextSize.cy += infoPtr->rcTextMargin.top + infoPtr->rcTextMargin.bottom;
447  TextSize.cx += infoPtr->rcTextMargin.left + infoPtr->rcTextMargin.right;
448 
449  if (infoPtr->imlData.himl && ImageList_GetIconSize(infoPtr->imlData.himl, &ImageSize.cx, &ImageSize.cy))
450  {
451  ImageSize.cx += infoPtr->imlData.margin.left + infoPtr->imlData.margin.right;
452  ImageSize.cy += infoPtr->imlData.margin.top + infoPtr->imlData.margin.bottom;
453  }
454  else
455  {
456  ImageSize.cx = ImageSize.cy = 0;
457  }
458 
459  if (theme)
460  {
461  RECT rcContents = {0};
462  RECT rcButtonExtent = {0};
463  rcContents.right = ImageSize.cx + TextSize.cx;
464  rcContents.bottom = max(ImageSize.cy, TextSize.cy);
465  GetThemeBackgroundExtent(theme, hdc, BP_PUSHBUTTON, PBS_NORMAL, &rcContents, &rcButtonExtent);
466  ButtonSize.cx = rcButtonExtent.right - rcButtonExtent.left;
467  ButtonSize.cy = rcButtonExtent.bottom - rcButtonExtent.top;
468  }
469  else
470  {
471  ButtonSize.cx = ImageSize.cx + TextSize.cx + 5;
472  ButtonSize.cy = max(ImageSize.cy, TextSize.cy + 7);
473  }
474 
475  *psize = ButtonSize;
476  ret = TRUE;
477 
478 cleanup:
479  if (hFont)
481  if (text)
482  HeapFree( GetProcessHeap(), 0, text );
483  if (hdc)
484  ReleaseDC(infoPtr->hwnd, hdc);
485 
486  return ret;
487 }
488 
489 BOOL BUTTON_DrawIml(HDC hDC, const BUTTON_IMAGELIST *pimlData, RECT *prc, BOOL bOnlyCalc, int index)
490 {
491  SIZE ImageSize;
492  int left, top, count;
493 
494  if (!pimlData->himl)
495  return FALSE;
496 
497  if (!ImageList_GetIconSize(pimlData->himl, &ImageSize.cx, &ImageSize.cy))
498  return FALSE;
499 
500  if (pimlData->uAlign == BUTTON_IMAGELIST_ALIGN_LEFT)
501  {
502  left = prc->left + pimlData->margin.left;
503  top = prc->top + (prc->bottom - prc->top - ImageSize.cy) / 2;
504  prc->left = left + pimlData->margin.right + ImageSize.cx;
505  }
506  else if (pimlData->uAlign == BUTTON_IMAGELIST_ALIGN_RIGHT)
507  {
508  left = prc->right - pimlData->margin.right - ImageSize.cx;
509  top = prc->top + (prc->bottom - prc->top - ImageSize.cy) / 2;
510  prc->right = left - pimlData->margin.left;
511  }
512  else if (pimlData->uAlign == BUTTON_IMAGELIST_ALIGN_TOP)
513  {
514  left = prc->left + (prc->right - prc->left - ImageSize.cx) / 2;
515  top = prc->top + pimlData->margin.top;
516  prc->top = top + ImageSize.cy + pimlData->margin.bottom;
517  }
518  else if (pimlData->uAlign == BUTTON_IMAGELIST_ALIGN_BOTTOM)
519  {
520  left = prc->left + (prc->right - prc->left - ImageSize.cx) / 2;
521  top = prc->bottom - pimlData->margin.bottom - ImageSize.cy;
522  prc->bottom = top - pimlData->margin.top;
523  }
524  else if (pimlData->uAlign == BUTTON_IMAGELIST_ALIGN_CENTER)
525  {
526  left = prc->left + (prc->right - prc->left - ImageSize.cx) / 2;
527  top = prc->top + (prc->bottom - prc->top - ImageSize.cy) / 2;
528  }
529 
530  if (bOnlyCalc)
531  return TRUE;
532 
533  count = ImageList_GetImageCount(pimlData->himl);
534 
535  if (count == 1)
536  index = 0;
537  else if (index >= count)
538  return TRUE;
539 
540  ImageList_Draw(pimlData->himl, index, hDC, left, top, 0);
541 
542  return TRUE;
543 }
544 
545 DWORD BUTTON_SendCustomDraw(const BUTTON_INFO *infoPtr, HDC hDC, DWORD dwDrawStage, RECT* prc)
546 {
547  NMCUSTOMDRAW nmcs;
548 
549  nmcs.hdr.hwndFrom = infoPtr->hwnd;
550  nmcs.hdr.idFrom = GetWindowLongPtrW (infoPtr->hwnd, GWLP_ID);
551  nmcs.hdr.code = NM_CUSTOMDRAW ;
552  nmcs.dwDrawStage = dwDrawStage;
553  nmcs.hdc = hDC;
554  nmcs.rc = *prc;
555  nmcs.dwItemSpec = 0;
556  nmcs.uItemState = 0;
557  nmcs.lItemlParam = 0;
558  if(!IsWindowEnabled(infoPtr->hwnd))
559  nmcs.uItemState |= CDIS_DISABLED;
560  if (infoPtr->state & (BST_CHECKED | BST_INDETERMINATE))
561  nmcs.uItemState |= CDIS_CHECKED;
562  if (infoPtr->state & BST_FOCUS)
563  nmcs.uItemState |= CDIS_FOCUS;
564  if (infoPtr->state & BST_PUSHED)
565  nmcs.uItemState |= CDIS_SELECTED;
566  if (!(infoPtr->ui_state & UISF_HIDEACCEL))
568 
569  return SendMessageW(GetParent(infoPtr->hwnd), WM_NOTIFY, nmcs.hdr.idFrom, (LPARAM)&nmcs);
570 }
571 
572 /* Retrieve the UI state for the control */
573 static BOOL button_update_uistate(BUTTON_INFO *infoPtr)
574 {
575  LONG flags = DefWindowProcW(infoPtr->hwnd, WM_QUERYUISTATE, 0, 0);
576 
577  if (infoPtr->ui_state != flags)
578  {
579  infoPtr->ui_state = flags;
580  return TRUE;
581  }
582 
583  return FALSE;
584 }
585 #endif
586 
588 {
589  BUTTON_INFO *infoPtr = (BUTTON_INFO *)GetWindowLongPtrW(hWnd, 0);
590  RECT rect;
591  POINT pt;
593  UINT btn_type = get_button_type( style );
594  LONG state, new_state;
595  HANDLE oldHbitmap;
596  HTHEME theme;
597 
598  if (!IsWindow( hWnd )) return 0;
599 
600  if (!infoPtr && (uMsg != WM_NCCREATE))
601  return DefWindowProcW(hWnd, uMsg, wParam, lParam);
602 
603  pt.x = (short)LOWORD(lParam);
604  pt.y = (short)HIWORD(lParam);
605 
606  switch (uMsg)
607  {
608  case WM_GETDLGCODE:
609  switch(btn_type)
610  {
611  case BS_COMMANDLINK:
612  case BS_USERBUTTON:
614  case BS_DEFCOMMANDLINK:
616  case BS_RADIOBUTTON:
618  case BS_GROUPBOX: return DLGC_STATIC;
621  default: return DLGC_BUTTON;
622  }
623 
624  case WM_ENABLE:
625 #ifndef __REACTOS__
626  theme = GetWindowTheme( hWnd );
627  if (theme)
629  else
630 #endif
631  paint_button( infoPtr, btn_type, ODA_DRAWENTIRE );
632  break;
633 
634  case WM_NCCREATE:
635  infoPtr = heap_alloc_zero( sizeof(*infoPtr) );
636  SetWindowLongPtrW( hWnd, 0, (LONG_PTR)infoPtr );
637  infoPtr->hwnd = hWnd;
638 #ifdef __REACTOS__
639  SetRect(&infoPtr->rcTextMargin, 1,1,1,1);
640 #endif
641  return DefWindowProcW(hWnd, uMsg, wParam, lParam);
642 
643  case WM_NCDESTROY:
644  SetWindowLongPtrW( hWnd, 0, 0 );
645  heap_free(infoPtr);
646  break;
647 
648  case WM_CREATE:
649  if (btn_type >= MAX_BTN_TYPE)
650  return -1; /* abort */
651 
652  /* XP turns a BS_USERBUTTON into BS_PUSHBUTTON */
653  if (btn_type == BS_USERBUTTON )
654  {
657  }
658  infoPtr->state = BST_UNCHECKED;
660  return 0;
661 
662  case WM_DESTROY:
663  theme = GetWindowTheme( hWnd );
664  CloseThemeData( theme );
665  break;
666 
667  case WM_THEMECHANGED:
668  theme = GetWindowTheme( hWnd );
669  CloseThemeData( theme );
671 #ifdef __REACTOS__
673 #endif
674  break;
675 
676  case WM_ERASEBKGND:
677  if (btn_type == BS_OWNERDRAW)
678  {
679  HDC hdc = (HDC)wParam;
680  RECT rc;
681  HBRUSH hBrush;
683  if (!parent) parent = hWnd;
684  hBrush = (HBRUSH)SendMessageW(parent, WM_CTLCOLORBTN, (WPARAM)hdc, (LPARAM)hWnd);
685  if (!hBrush) /* did the app forget to call defwindowproc ? */
686  hBrush = (HBRUSH)DefWindowProcW(parent, WM_CTLCOLORBTN,
687  (WPARAM)hdc, (LPARAM)hWnd);
688  GetClientRect(hWnd, &rc);
689  FillRect(hdc, &rc, hBrush);
690  }
691  return 1;
692 
693  case WM_PRINTCLIENT:
694  case WM_PAINT:
695  {
696  PAINTSTRUCT ps;
697  HDC hdc;
698 
699  theme = GetWindowTheme( hWnd );
700  hdc = wParam ? (HDC)wParam : BeginPaint( hWnd, &ps );
701 
702 #ifdef __REACTOS__
703  if (theme && BUTTON_PaintWithTheme(theme, infoPtr, hdc, uMsg == WM_PRINTCLIENT ? lParam : 0))
704  {
705  if ( !wParam ) EndPaint( hWnd, &ps );
706  return 0;
707  }
708 #else
709  if (theme && btnThemedPaintFunc[btn_type])
710  {
711  ButtonState drawState;
712  UINT dtflags;
713 
714  if (IsWindowEnabled( hWnd ))
715  {
716  if (infoPtr->state & BST_PUSHED) drawState = STATE_PRESSED;
717  else if (infoPtr->state & BST_HOT) drawState = STATE_HOT;
718  else if (infoPtr->state & BST_FOCUS) drawState = STATE_DEFAULTED;
719  else drawState = STATE_NORMAL;
720  }
721  else
722  drawState = STATE_DISABLED;
723 
725  btnThemedPaintFunc[btn_type](theme, infoPtr, hdc, drawState, dtflags, infoPtr->state & BST_FOCUS);
726  }
727 #endif
728  else if (btnPaintFunc[btn_type])
729  {
730  int nOldMode = SetBkMode( hdc, OPAQUE );
731  btnPaintFunc[btn_type]( infoPtr, hdc, ODA_DRAWENTIRE );
732  SetBkMode(hdc, nOldMode); /* reset painting mode */
733  }
734 
735  if ( !wParam ) EndPaint( hWnd, &ps );
736  break;
737  }
738 
739  case WM_KEYDOWN:
740  if (wParam == VK_SPACE)
741  {
743  infoPtr->state |= BUTTON_BTNPRESSED;
744  SetCapture( hWnd );
745  }
746  break;
747 
748  case WM_LBUTTONDBLCLK:
749  if(style & BS_NOTIFY ||
750  btn_type == BS_RADIOBUTTON ||
751  btn_type == BS_USERBUTTON ||
752  btn_type == BS_OWNERDRAW)
753  {
755  break;
756  }
757  /* fall through */
758  case WM_LBUTTONDOWN:
759  SetCapture( hWnd );
760  SetFocus( hWnd );
761  infoPtr->state |= BUTTON_BTNPRESSED;
763  break;
764 
765  case WM_KEYUP:
766  if (wParam != VK_SPACE)
767  break;
768  /* fall through */
769  case WM_LBUTTONUP:
770  state = infoPtr->state;
771  if (!(state & BUTTON_BTNPRESSED)) break;
772  infoPtr->state &= BUTTON_NSTATES;
773  if (!(state & BST_PUSHED))
774  {
775  ReleaseCapture();
776  break;
777  }
779  GetClientRect( hWnd, &rect );
780  if (uMsg == WM_KEYUP || PtInRect( &rect, pt ))
781  {
782  switch(btn_type)
783  {
784  case BS_AUTOCHECKBOX:
785  SendMessageW( hWnd, BM_SETCHECK, !(infoPtr->state & BST_CHECKED), 0 );
786  break;
787  case BS_AUTORADIOBUTTON:
788 #ifdef __REACTOS__
790 #else
792 #endif
793  break;
794  case BS_AUTO3STATE:
795  SendMessageW( hWnd, BM_SETCHECK, (infoPtr->state & BST_INDETERMINATE) ? 0 :
796  ((infoPtr->state & 3) + 1), 0 );
797  break;
798  }
799 #ifdef __REACTOS__
800  // Fix CORE-10194, Notify parent after capture is released.
801  ReleaseCapture();
803 #else
805  ReleaseCapture();
806 #endif
807  }
808  else
809  {
810  ReleaseCapture();
811  }
812 
813  break;
814 
815  case WM_CAPTURECHANGED:
816  TRACE("WM_CAPTURECHANGED %p\n", hWnd);
817  if (hWnd == (HWND)lParam) break;
818  if (infoPtr->state & BUTTON_BTNPRESSED)
819  {
820  infoPtr->state &= BUTTON_NSTATES;
821  if (infoPtr->state & BST_PUSHED)
823  }
824  break;
825 
826  case WM_MOUSEMOVE:
827  {
829  mouse_event.cbSize = sizeof(TRACKMOUSEEVENT);
830  mouse_event.dwFlags = TME_QUERY;
831 
832 #ifdef __REACTOS__
833  if ((infoPtr->state & BST_HOT) == 0)
834  {
835  NMBCHOTITEM nmhotitem;
836 
837  infoPtr->state |= BST_HOT;
838 
839  nmhotitem.hdr.hwndFrom = hWnd;
840  nmhotitem.hdr.idFrom = GetWindowLongPtrW (hWnd, GWLP_ID);
841  nmhotitem.hdr.code = BCN_HOTITEMCHANGE;
842  nmhotitem.dwFlags = HICF_ENTERING;
843  SendMessageW(GetParent(hWnd), WM_NOTIFY, nmhotitem.hdr.idFrom, (LPARAM)&nmhotitem);
844 
845  theme = GetWindowTheme( hWnd );
846  if (theme)
848  }
849 
850  if(!TrackMouseEvent(&mouse_event) || !(mouse_event.dwFlags&TME_LEAVE))
851  {
852  mouse_event.dwFlags = TME_LEAVE;
853  mouse_event.hwndTrack = hWnd;
854  mouse_event.dwHoverTime = 1;
856  }
857  break;
858 #else
859 
860  if (!TrackMouseEvent(&mouse_event) || !(mouse_event.dwFlags & (TME_HOVER | TME_LEAVE)))
861  {
862  mouse_event.dwFlags = TME_HOVER | TME_LEAVE;
863  mouse_event.hwndTrack = hWnd;
864  mouse_event.dwHoverTime = 1;
866  }
867 
868  if ((wParam & MK_LBUTTON) && GetCapture() == hWnd)
869  {
870  GetClientRect( hWnd, &rect );
872  }
873  break;
874 #endif
875  }
876 
877 #ifndef __REACTOS__
878  case WM_MOUSEHOVER:
879  {
880  infoPtr->state |= BST_HOT;
882  break;
883  }
884 #endif
885 
886  case WM_MOUSELEAVE:
887  {
888 #ifdef __REACTOS__
889  if (infoPtr->state & BST_HOT)
890  {
891  NMBCHOTITEM nmhotitem;
892 
893  infoPtr->state &= ~BST_HOT;
894 
895  nmhotitem.hdr.hwndFrom = hWnd;
896  nmhotitem.hdr.idFrom = GetWindowLongPtrW (hWnd, GWLP_ID);
897  nmhotitem.hdr.code = BCN_HOTITEMCHANGE;
898  nmhotitem.dwFlags = HICF_LEAVING;
899  SendMessageW(GetParent(hWnd), WM_NOTIFY, nmhotitem.hdr.idFrom, (LPARAM)&nmhotitem);
900 
901  theme = GetWindowTheme( hWnd );
902  if (theme)
904  }
905  break;
906 #else
907  infoPtr->state &= ~BST_HOT;
909  break;
910 #endif
911  }
912 
913 #ifdef __REACTOS__
914  case BCM_GETTEXTMARGIN:
915  {
916  RECT* prc = (RECT*)lParam;
917  if (!prc)
918  return FALSE;
919  *prc = infoPtr->rcTextMargin;
920  return TRUE;
921  }
922  case BCM_SETTEXTMARGIN:
923  {
924  RECT* prc = (RECT*)lParam;
925  if (!prc)
926  return FALSE;
927  infoPtr->rcTextMargin = *prc;
928  return TRUE;
929  }
930  case BCM_SETIMAGELIST:
931  {
932  BUTTON_IMAGELIST * pimldata = (BUTTON_IMAGELIST *)lParam;
933  if (!pimldata || !pimldata->himl)
934  return FALSE;
935  infoPtr->imlData = *pimldata;
936  return TRUE;
937  }
938  case BCM_GETIMAGELIST:
939  {
940  BUTTON_IMAGELIST * pimldata = (BUTTON_IMAGELIST *)lParam;
941  if (!pimldata)
942  return FALSE;
943  *pimldata = infoPtr->imlData;
944  return TRUE;
945  }
946  case BCM_GETIDEALSIZE:
947  {
948  HTHEME theme = GetWindowTheme(hWnd);
949  BOOL ret = FALSE;
950  SIZE* pSize = (SIZE*)lParam;
951 
952  if (!pSize)
953  {
954  return FALSE;
955  }
956 
957  if (btn_type == BS_PUSHBUTTON ||
958  btn_type == BS_DEFPUSHBUTTON ||
959  btn_type == BS_USERBUTTON)
960  {
961  ret = BUTTON_GetIdealSize(infoPtr, theme, pSize);
962  }
963 
964  if (!ret)
965  {
967  pSize->cx = rect.right;
968  pSize->cy = rect.bottom;
969  }
970 
971  return TRUE;
972  }
973 #endif
974 
975  case WM_SETTEXT:
976  {
977  /* Clear an old text here as Windows does */
978 #ifdef __REACTOS__
979 //
980 // ReactOS Note :
981 // wine Bug: http://bugs.winehq.org/show_bug.cgi?id=25790
982 // Patch: http://source.winehq.org/patches/data/70889
983 // By: Alexander LAW, Replicate Windows behavior of WM_SETTEXT handler regarding WM_CTLCOLOR*
984 //
985  if (style & WS_VISIBLE)
986 #else
987  if (IsWindowVisible(hWnd))
988 #endif
989  {
990  HDC hdc = GetDC(hWnd);
991  HBRUSH hbrush;
992  RECT client, rc;
994  UINT message = (btn_type == BS_PUSHBUTTON ||
995  btn_type == BS_DEFPUSHBUTTON ||
996  btn_type == BS_USERBUTTON ||
997  btn_type == BS_OWNERDRAW) ?
999 
1000  if (!parent) parent = hWnd;
1001  hbrush = (HBRUSH)SendMessageW(parent, message,
1002  (WPARAM)hdc, (LPARAM)hWnd);
1003  if (!hbrush) /* did the app forget to call DefWindowProc ? */
1004  hbrush = (HBRUSH)DefWindowProcW(parent, message,
1005  (WPARAM)hdc, (LPARAM)hWnd);
1006 
1008  rc = client;
1009  /* FIXME: check other BS_* handlers */
1010  if (btn_type == BS_GROUPBOX)
1011  InflateRect(&rc, -7, 1); /* GB_Paint does this */
1012  BUTTON_CalcLabelRect(infoPtr, hdc, &rc);
1013  /* Clip by client rect bounds */
1014  if (rc.right > client.right) rc.right = client.right;
1015  if (rc.bottom > client.bottom) rc.bottom = client.bottom;
1016  FillRect(hdc, &rc, hbrush);
1017  ReleaseDC(hWnd, hdc);
1018  }
1019 
1021  if (btn_type == BS_GROUPBOX) /* Yes, only for BS_GROUPBOX */
1023  else
1024  paint_button( infoPtr, btn_type, ODA_DRAWENTIRE );
1025  return 1; /* success. FIXME: check text length */
1026  }
1027 
1028  case WM_SETFONT:
1029  infoPtr->font = (HFONT)wParam;
1031  break;
1032 
1033  case WM_GETFONT:
1034  return (LRESULT)infoPtr->font;
1035 
1036  case WM_SETFOCUS:
1037  TRACE("WM_SETFOCUS %p\n",hWnd);
1038  infoPtr->state |= BST_FOCUS;
1039 #ifdef __REACTOS__
1040  if (btn_type != BS_OWNERDRAW)
1042  else
1043 #endif
1044  paint_button( infoPtr, btn_type, ODA_FOCUS );
1045  if (style & BS_NOTIFY)
1047  break;
1048 
1049  case WM_KILLFOCUS:
1050  TRACE("WM_KILLFOCUS %p\n",hWnd);
1051  infoPtr->state &= ~BST_FOCUS;
1052 #ifndef __REACTOS__
1053  paint_button( infoPtr, btn_type, ODA_FOCUS );
1054 #endif
1055 
1056  if ((infoPtr->state & BUTTON_BTNPRESSED) && GetCapture() == hWnd)
1057  ReleaseCapture();
1058  if (style & BS_NOTIFY)
1060 
1062  break;
1063 
1064  case WM_SYSCOLORCHANGE:
1066  break;
1067 
1068  case BM_SETSTYLE:
1069  btn_type = wParam & BS_TYPEMASK;
1070  style = (style & ~BS_TYPEMASK) | btn_type;
1072 
1073  /* Only redraw if lParam flag is set.*/
1074  if (lParam)
1076 
1077  break;
1078 
1079  case BM_CLICK:
1080 #ifdef __REACTOS__
1081  /* Fix for core CORE-6024 */
1082  if (infoPtr->state & BUTTON_BMCLICK)
1083  break;
1084  infoPtr->state |= BUTTON_BMCLICK;
1085 #endif
1086  SendMessageW( hWnd, WM_LBUTTONDOWN, 0, 0 );
1087  SendMessageW( hWnd, WM_LBUTTONUP, 0, 0 );
1088 #ifdef __REACTOS__
1089  infoPtr->state &= ~BUTTON_BMCLICK;
1090 #endif
1091  break;
1092 
1093  case BM_SETIMAGE:
1094  /* Check that image format matches button style */
1095  switch (style & (BS_BITMAP|BS_ICON))
1096  {
1097  case BS_BITMAP:
1098  if (wParam != IMAGE_BITMAP) return 0;
1099  break;
1100  case BS_ICON:
1101  if (wParam != IMAGE_ICON) return 0;
1102  break;
1103  default:
1104  return 0;
1105  }
1106  oldHbitmap = infoPtr->u.image;
1107  infoPtr->u.image = (HANDLE)lParam;
1109  return (LRESULT)oldHbitmap;
1110 
1111  case BM_GETIMAGE:
1112  return (LRESULT)infoPtr->u.image;
1113 
1114  case BM_GETCHECK:
1115  return infoPtr->state & 3;
1116 
1117  case BM_SETCHECK:
1118  if (wParam > maxCheckState[btn_type]) wParam = maxCheckState[btn_type];
1119  if ((btn_type == BS_RADIOBUTTON) || (btn_type == BS_AUTORADIOBUTTON))
1120  {
1123  }
1124  if ((infoPtr->state & 3) != wParam)
1125  {
1126  infoPtr->state = (infoPtr->state & ~3) | wParam;
1128  }
1129 #ifndef __REACTOS__
1130  if ((btn_type == BS_AUTORADIOBUTTON) && (wParam == BST_CHECKED) && (style & WS_CHILD))
1132 #endif
1133  break;
1134 
1135  case BM_GETSTATE:
1136  return infoPtr->state;
1137 
1138  case BM_SETSTATE:
1139  state = infoPtr->state;
1140  new_state = wParam ? BST_PUSHED : 0;
1141 
1142  if ((state ^ new_state) & BST_PUSHED)
1143  {
1144  if (wParam)
1145  state |= BST_PUSHED;
1146  else
1147  state &= ~BST_PUSHED;
1148 
1149  if (btn_type == BS_USERBUTTON)
1151  infoPtr->state = state;
1152 
1154  }
1155  break;
1156 
1157 #ifdef __REACTOS__
1158  case WM_UPDATEUISTATE:
1159  DefWindowProcW(hWnd, uMsg, wParam, lParam);
1160 
1161  if (button_update_uistate(infoPtr))
1162  paint_button( infoPtr, btn_type, ODA_DRAWENTIRE );
1163  break;
1164 #endif
1165 
1166  case WM_NCHITTEST:
1167  if(btn_type == BS_GROUPBOX) return HTTRANSPARENT;
1168  /* fall through */
1169  default:
1170  return DefWindowProcW(hWnd, uMsg, wParam, lParam);
1171  }
1172  return 0;
1173 }
1174 
1175 /**********************************************************************
1176  * BUTTON_CalcLabelRect
1177  *
1178  * Calculates label's rectangle depending on button style.
1179  *
1180  * Returns flags to be passed to DrawText.
1181  * Calculated rectangle doesn't take into account button state
1182  * (pushed, etc.). If there is nothing to draw (no text/image) output
1183  * rectangle is empty, and return value is (UINT)-1.
1184  */
1185 static UINT BUTTON_CalcLabelRect(const BUTTON_INFO *infoPtr, HDC hdc, RECT *rc)
1186 {
1187  LONG style = GetWindowLongW( infoPtr->hwnd, GWL_STYLE );
1188  LONG ex_style = GetWindowLongW( infoPtr->hwnd, GWL_EXSTYLE );
1189  WCHAR *text;
1190  ICONINFO iconInfo;
1191  BITMAP bm;
1192  UINT dtStyle = BUTTON_BStoDT( style, ex_style );
1193  RECT r = *rc;
1194  INT n;
1195 #ifdef __REACTOS__
1196  BOOL bHasIml = BUTTON_DrawIml(hdc, &infoPtr->imlData, &r, TRUE, 0);
1197 #endif
1198 
1199  /* Calculate label rectangle according to label type */
1200  switch (style & (BS_ICON|BS_BITMAP))
1201  {
1202  case BS_TEXT:
1203  {
1204  HFONT hFont, hPrevFont = 0;
1205 
1206  if (!(text = get_button_text( infoPtr ))) goto empty_rect;
1207  if (!text[0])
1208  {
1209  heap_free( text );
1210  goto empty_rect;
1211  }
1212 
1213  if ((hFont = infoPtr->font)) hPrevFont = SelectObject( hdc, hFont );
1214  DrawTextW(hdc, text, -1, &r, dtStyle | DT_CALCRECT);
1215  if (hPrevFont) SelectObject( hdc, hPrevFont );
1216  heap_free( text );
1217 #ifdef __REACTOS__
1218  if (infoPtr->ui_state & UISF_HIDEACCEL)
1219  dtStyle |= DT_HIDEPREFIX;
1220 #endif
1221  break;
1222  }
1223 
1224  case BS_ICON:
1225  if (!GetIconInfo(infoPtr->u.icon, &iconInfo))
1226  goto empty_rect;
1227 
1228  GetObjectW (iconInfo.hbmColor, sizeof(BITMAP), &bm);
1229 
1230  r.right = r.left + bm.bmWidth;
1231  r.bottom = r.top + bm.bmHeight;
1232 
1233  DeleteObject(iconInfo.hbmColor);
1234  DeleteObject(iconInfo.hbmMask);
1235  break;
1236 
1237  case BS_BITMAP:
1238  if (!GetObjectW( infoPtr->u.bitmap, sizeof(BITMAP), &bm))
1239  goto empty_rect;
1240 
1241  r.right = r.left + bm.bmWidth;
1242  r.bottom = r.top + bm.bmHeight;
1243  break;
1244 
1245  default:
1246  empty_rect:
1247 #ifdef __REACTOS__
1248  if (bHasIml)
1249  break;
1250 #endif
1251  rc->right = r.left;
1252  rc->bottom = r.top;
1253  return (UINT)-1;
1254  }
1255 
1256 #ifdef __REACTOS__
1257  if (bHasIml)
1258  {
1259  if (infoPtr->imlData.uAlign == BUTTON_IMAGELIST_ALIGN_LEFT)
1260  r.left = infoPtr->imlData.margin.left;
1261  else if (infoPtr->imlData.uAlign == BUTTON_IMAGELIST_ALIGN_RIGHT)
1262  r.right = infoPtr->imlData.margin.right;
1263  else if (infoPtr->imlData.uAlign == BUTTON_IMAGELIST_ALIGN_TOP)
1264  r.top = infoPtr->imlData.margin.top;
1265  else if (infoPtr->imlData.uAlign == BUTTON_IMAGELIST_ALIGN_BOTTOM)
1266  r.bottom = infoPtr->imlData.margin.bottom;
1267  }
1268 #endif
1269 
1270  /* Position label inside bounding rectangle according to
1271  * alignment flags. (calculated rect is always left-top aligned).
1272  * If label is aligned to any side - shift label in opposite
1273  * direction to leave extra space for focus rectangle.
1274  */
1275  switch (dtStyle & (DT_CENTER|DT_RIGHT))
1276  {
1277  case DT_LEFT: r.left++; r.right++; break;
1278  case DT_CENTER: n = r.right - r.left;
1279  r.left = rc->left + ((rc->right - rc->left) - n) / 2;
1280  r.right = r.left + n; break;
1281  case DT_RIGHT: n = r.right - r.left;
1282  r.right = rc->right - 1;
1283  r.left = r.right - n;
1284  break;
1285  }
1286 
1287  switch (dtStyle & (DT_VCENTER|DT_BOTTOM))
1288  {
1289  case DT_TOP: r.top++; r.bottom++; break;
1290  case DT_VCENTER: n = r.bottom - r.top;
1291 #ifdef __REACTOS__
1292  r.top = rc->top + ((rc->bottom - 1 - rc->top) - n) / 2;
1293 #else
1294  r.top = rc->top + ((rc->bottom - rc->top) - n) / 2;
1295 #endif
1296  r.bottom = r.top + n; break;
1297  case DT_BOTTOM: n = r.bottom - r.top;
1298  r.bottom = rc->bottom - 1;
1299  r.top = r.bottom - n;
1300  break;
1301  }
1302 
1303  *rc = r;
1304  return dtStyle;
1305 }
1306 
1307 
1308 /**********************************************************************
1309  * BUTTON_DrawTextCallback
1310  *
1311  * Callback function used by DrawStateW function.
1312  */
1314 {
1315  RECT rc;
1316 
1317  SetRect(&rc, 0, 0, cx, cy);
1318  DrawTextW(hdc, (LPCWSTR)lp, -1, &rc, (UINT)wp);
1319  return TRUE;
1320 }
1321 
1322 
1323 /**********************************************************************
1324  * BUTTON_DrawLabel
1325  *
1326  * Common function for drawing button label.
1327  */
1328 static void BUTTON_DrawLabel(const BUTTON_INFO *infoPtr, HDC hdc, UINT dtFlags, const RECT *rc)
1329 {
1330  DRAWSTATEPROC lpOutputProc = NULL;
1331  LPARAM lp;
1332  WPARAM wp = 0;
1333  HBRUSH hbr = 0;
1335  LONG state = infoPtr->state;
1336  LONG style = GetWindowLongW( infoPtr->hwnd, GWL_STYLE );
1337  WCHAR *text = NULL;
1338 
1339  /* FIXME: To draw disabled label in Win31 look-and-feel, we probably
1340  * must use DSS_MONO flag and COLOR_GRAYTEXT brush (or maybe DSS_UNION).
1341  * I don't have Win31 on hand to verify that, so I leave it as is.
1342  */
1343 
1344 #ifdef __REACTOS__
1345  RECT rcText = *rc;
1346  BUTTON_DrawIml(hdc, &infoPtr->imlData, &rcText, FALSE, 0);
1347 #endif
1348 
1349  if ((style & BS_PUSHLIKE) && (state & BST_INDETERMINATE))
1350  {
1352  flags |= DSS_MONO;
1353  }
1354 
1355  switch (style & (BS_ICON|BS_BITMAP))
1356  {
1357  case BS_TEXT:
1358  /* DST_COMPLEX -- is 0 */
1359  lpOutputProc = BUTTON_DrawTextCallback;
1360  if (!(text = get_button_text( infoPtr ))) return;
1361  lp = (LPARAM)text;
1362  wp = dtFlags;
1363 #ifdef __REACTOS__
1364  if (dtFlags & DT_HIDEPREFIX)
1365  flags |= DSS_HIDEPREFIX;
1366 #endif
1367  break;
1368 
1369  case BS_ICON:
1370  flags |= DST_ICON;
1371  lp = (LPARAM)infoPtr->u.icon;
1372  break;
1373 
1374  case BS_BITMAP:
1375  flags |= DST_BITMAP;
1376  lp = (LPARAM)infoPtr->u.bitmap;
1377  break;
1378 
1379  default:
1380  return;
1381  }
1382 
1383 #ifdef __REACTOS__
1384  DrawStateW(hdc, hbr, lpOutputProc, lp, wp, rcText.left, rcText.top,
1385  rcText.right - rcText.left, rcText.bottom - rcText.top, flags);
1386 #else
1387  DrawStateW(hdc, hbr, lpOutputProc, lp, wp, rc->left, rc->top,
1388  rc->right - rc->left, rc->bottom - rc->top, flags);
1389 #endif
1390  heap_free( text );
1391 }
1392 
1393 /**********************************************************************
1394  * Push Button Functions
1395  */
1396 static void PB_Paint( const BUTTON_INFO *infoPtr, HDC hDC, UINT action )
1397 {
1398  RECT rc, r;
1399  UINT dtFlags, uState;
1400  HPEN hOldPen, hpen;
1401  HBRUSH hOldBrush;
1402  INT oldBkMode;
1403  COLORREF oldTxtColor;
1404  HFONT hFont;
1405  LONG state = infoPtr->state;
1406  LONG style = GetWindowLongW( infoPtr->hwnd, GWL_STYLE );
1407  BOOL pushedState = (state & BST_PUSHED);
1408  HWND parent;
1409  HRGN hrgn;
1410 #ifdef __REACTOS__
1411  DWORD cdrf;
1412 #endif
1413 
1414  GetClientRect( infoPtr->hwnd, &rc );
1415 
1416  /* Send WM_CTLCOLOR to allow changing the font (the colors are fixed) */
1417  if ((hFont = infoPtr->font)) SelectObject( hDC, hFont );
1418  parent = GetParent(infoPtr->hwnd);
1419  if (!parent) parent = infoPtr->hwnd;
1421 
1422  hrgn = set_control_clipping( hDC, &rc );
1423 
1425  hOldPen = SelectObject(hDC, hpen);
1427  oldBkMode = SetBkMode(hDC, TRANSPARENT);
1428 
1429 #ifdef __REACTOS__
1430  cdrf = BUTTON_SendCustomDraw(infoPtr, hDC, CDDS_PREERASE, &rc);
1431  if (cdrf == CDRF_SKIPDEFAULT)
1432  goto cleanup;
1433 #endif
1434 
1436  {
1437  if (action != ODA_FOCUS)
1438  Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom);
1439  InflateRect( &rc, -1, -1 );
1440  }
1441 
1442  /* completely skip the drawing if only focus has changed */
1443  if (action == ODA_FOCUS) goto draw_focus;
1444 
1445  uState = DFCS_BUTTONPUSH;
1446 
1447  if (style & BS_FLAT)
1448  uState |= DFCS_MONO;
1449  else if (pushedState)
1450  {
1452  uState |= DFCS_FLAT;
1453  else
1454  uState |= DFCS_PUSHED;
1455  }
1456 
1458  uState |= DFCS_CHECKED;
1459 
1460  DrawFrameControl( hDC, &rc, DFC_BUTTON, uState );
1461 
1462 #ifdef __REACTOS__
1463  if (cdrf == CDRF_NOTIFYPOSTERASE)
1464  BUTTON_SendCustomDraw(infoPtr, hDC, CDDS_POSTERASE, &rc);
1465 
1466  cdrf = BUTTON_SendCustomDraw(infoPtr, hDC, CDDS_PREPAINT, &rc);
1467  if (cdrf == CDRF_SKIPDEFAULT)
1468  goto cleanup;
1469 #endif
1470 
1471  /* draw button label */
1472  r = rc;
1473  dtFlags = BUTTON_CalcLabelRect(infoPtr, hDC, &r);
1474 
1475  if (dtFlags == (UINT)-1L)
1476  goto cleanup;
1477 
1478  if (pushedState)
1479  OffsetRect(&r, 1, 1);
1480 
1481  oldTxtColor = SetTextColor( hDC, GetSysColor(COLOR_BTNTEXT) );
1482 
1483  BUTTON_DrawLabel(infoPtr, hDC, dtFlags, &r);
1484 
1485  SetTextColor( hDC, oldTxtColor );
1486 
1487 #ifdef __REACTOS__
1488  if (cdrf == CDRF_NOTIFYPOSTPAINT)
1489  BUTTON_SendCustomDraw(infoPtr, hDC, CDDS_POSTPAINT, &rc);
1490 #endif
1491 
1492 draw_focus:
1493  if (action == ODA_FOCUS || (state & BST_FOCUS))
1494  {
1495 #ifdef __REACTOS__
1496  if (!(infoPtr->ui_state & UISF_HIDEFOCUS))
1497  {
1498 #endif
1499  InflateRect( &rc, -2, -2 );
1500  DrawFocusRect( hDC, &rc );
1501 #ifdef __REACTOS__
1502  }
1503 #endif
1504  }
1505 
1506  cleanup:
1507  SelectObject( hDC, hOldPen );
1508  SelectObject( hDC, hOldBrush );
1509  SetBkMode(hDC, oldBkMode);
1510  SelectClipRgn( hDC, hrgn );
1511  if (hrgn) DeleteObject( hrgn );
1512  DeleteObject( hpen );
1513 }
1514 
1515 /**********************************************************************
1516  * Check Box & Radio Button Functions
1517  */
1518 
1519 static void CB_Paint( const BUTTON_INFO *infoPtr, HDC hDC, UINT action )
1520 {
1521  RECT rbox, rtext, client;
1522  HBRUSH hBrush;
1523  int delta, text_offset, checkBoxWidth, checkBoxHeight;
1524  UINT dtFlags;
1525  HFONT hFont;
1526  LONG state = infoPtr->state;
1527  LONG style = GetWindowLongW( infoPtr->hwnd, GWL_STYLE );
1528  LONG ex_style = GetWindowLongW( infoPtr->hwnd, GWL_EXSTYLE );
1529  HWND parent;
1530  HRGN hrgn;
1531 
1532  if (style & BS_PUSHLIKE)
1533  {
1534  PB_Paint( infoPtr, hDC, action );
1535  return;
1536  }
1537 
1538  GetClientRect(infoPtr->hwnd, &client);
1539  rbox = rtext = client;
1540 
1541  checkBoxWidth = 12 * GetDeviceCaps( hDC, LOGPIXELSX ) / 96 + 1;
1542  checkBoxHeight = 12 * GetDeviceCaps( hDC, LOGPIXELSY ) / 96 + 1;
1543 
1544  if ((hFont = infoPtr->font)) SelectObject( hDC, hFont );
1545  GetCharWidthW( hDC, '0', '0', &text_offset );
1546  text_offset /= 2;
1547 
1548  parent = GetParent(infoPtr->hwnd);
1549  if (!parent) parent = infoPtr->hwnd;
1550  hBrush = (HBRUSH)SendMessageW(parent, WM_CTLCOLORSTATIC, (WPARAM)hDC, (LPARAM)infoPtr->hwnd);
1551  if (!hBrush) /* did the app forget to call defwindowproc ? */
1552  hBrush = (HBRUSH)DefWindowProcW(parent, WM_CTLCOLORSTATIC, (WPARAM)hDC, (LPARAM)infoPtr->hwnd);
1554 
1555  if (style & BS_LEFTTEXT || ex_style & WS_EX_RIGHT)
1556  {
1557  rtext.right -= checkBoxWidth + text_offset;
1558  rbox.left = rbox.right - checkBoxWidth;
1559  }
1560  else
1561  {
1562  rtext.left += checkBoxWidth + text_offset;
1563  rbox.right = checkBoxWidth;
1564  }
1565 
1566  /* Since WM_ERASEBKGND does nothing, first prepare background */
1567  if (action == ODA_SELECT) FillRect( hDC, &rbox, hBrush );
1568  if (action == ODA_DRAWENTIRE) FillRect( hDC, &client, hBrush );
1569 
1570  /* Draw label */
1571  client = rtext;
1572  dtFlags = BUTTON_CalcLabelRect(infoPtr, hDC, &rtext);
1573 
1574  /* Only adjust rbox when rtext is valid */
1575  if (dtFlags != (UINT)-1L)
1576  {
1577  rbox.top = rtext.top;
1578  rbox.bottom = rtext.bottom;
1579  }
1580 
1581  /* Draw the check-box bitmap */
1582  if (action == ODA_DRAWENTIRE || action == ODA_SELECT)
1583  {
1584  UINT flags;
1585 
1586  if ((get_button_type(style) == BS_RADIOBUTTON) ||
1589  else flags = DFCS_BUTTONCHECK;
1590 
1592  if (state & BST_PUSHED) flags |= DFCS_PUSHED;
1593 
1595 
1596  /* rbox must have the correct height */
1597  delta = rbox.bottom - rbox.top - checkBoxHeight;
1598 
1599  if (style & BS_TOP) {
1600  if (delta > 0) {
1601  rbox.bottom = rbox.top + checkBoxHeight;
1602  } else {
1603  rbox.top -= -delta/2 + 1;
1604  rbox.bottom = rbox.top + checkBoxHeight;
1605  }
1606  } else if (style & BS_BOTTOM) {
1607  if (delta > 0) {
1608  rbox.top = rbox.bottom - checkBoxHeight;
1609  } else {
1610  rbox.bottom += -delta/2 + 1;
1611  rbox.top = rbox.bottom - checkBoxHeight;
1612  }
1613  } else { /* Default */
1614  if (delta > 0) {
1615  int ofs = (delta / 2);
1616  rbox.bottom -= ofs + 1;
1617  rbox.top = rbox.bottom - checkBoxHeight;
1618  } else if (delta < 0) {
1619  int ofs = (-delta / 2);
1620  rbox.top -= ofs + 1;
1621  rbox.bottom = rbox.top + checkBoxHeight;
1622  }
1623  }
1624 
1625  DrawFrameControl( hDC, &rbox, DFC_BUTTON, flags );
1626  }
1627 
1628  if (dtFlags == (UINT)-1L) /* Noting to draw */
1629  return;
1630 
1631  if (action == ODA_DRAWENTIRE)
1632  BUTTON_DrawLabel(infoPtr, hDC, dtFlags, &rtext);
1633 
1634  /* ... and focus */
1635  if (action == ODA_FOCUS || (state & BST_FOCUS))
1636  {
1637  rtext.left--;
1638  rtext.right++;
1639  IntersectRect(&rtext, &rtext, &client);
1640  DrawFocusRect( hDC, &rtext );
1641  }
1642  SelectClipRgn( hDC, hrgn );
1643  if (hrgn) DeleteObject( hrgn );
1644 }
1645 
1646 
1647 /**********************************************************************
1648  * BUTTON_CheckAutoRadioButton
1649  *
1650  * hwnd is checked, uncheck every other auto radio button in group
1651  */
1653 {
1654  HWND parent, sibling, start;
1655 
1656  parent = GetParent(hwnd);
1657  /* make sure that starting control is not disabled or invisible */
1658 #ifdef __REACTOS__
1659  start = sibling = hwnd;
1660 #else
1661  start = sibling = GetNextDlgGroupItem( parent, hwnd, TRUE );
1662 #endif
1663  do
1664  {
1665  if (!sibling) break;
1666 #ifdef __REACTOS__
1667  if (SendMessageW( sibling, WM_GETDLGCODE, 0, 0 ) == (DLGC_BUTTON | DLGC_RADIOBUTTON))
1668  SendMessageW( sibling, BM_SETCHECK, sibling == hwnd ? BST_CHECKED : BST_UNCHECKED, 0 );
1669 #else
1670  if ((hwnd != sibling) &&
1672  SendMessageW( sibling, BM_SETCHECK, BST_UNCHECKED, 0 );
1673 #endif
1674  sibling = GetNextDlgGroupItem( parent, sibling, FALSE );
1675  } while (sibling != start);
1676 }
1677 
1678 
1679 /**********************************************************************
1680  * Group Box Functions
1681  */
1682 
1683 static void GB_Paint( const BUTTON_INFO *infoPtr, HDC hDC, UINT action )
1684 {
1685  RECT rc, rcFrame;
1686  HBRUSH hbr;
1687  HFONT hFont;
1688  UINT dtFlags;
1689  TEXTMETRICW tm;
1690  LONG style = GetWindowLongW( infoPtr->hwnd, GWL_STYLE );
1691  HWND parent;
1692  HRGN hrgn;
1693 
1694  if ((hFont = infoPtr->font)) SelectObject( hDC, hFont );
1695  /* GroupBox acts like static control, so it sends CTLCOLORSTATIC */
1696  parent = GetParent(infoPtr->hwnd);
1697  if (!parent) parent = infoPtr->hwnd;
1698  hbr = (HBRUSH)SendMessageW(parent, WM_CTLCOLORSTATIC, (WPARAM)hDC, (LPARAM)infoPtr->hwnd);
1699  if (!hbr) /* did the app forget to call defwindowproc ? */
1700  hbr = (HBRUSH)DefWindowProcW(parent, WM_CTLCOLORSTATIC, (WPARAM)hDC, (LPARAM)infoPtr->hwnd);
1701  GetClientRect( infoPtr->hwnd, &rc);
1702  rcFrame = rc;
1703  hrgn = set_control_clipping( hDC, &rc );
1704 
1705  GetTextMetricsW (hDC, &tm);
1706  rcFrame.top += (tm.tmHeight / 2) - 1;
1707  DrawEdge (hDC, &rcFrame, EDGE_ETCHED, BF_RECT | ((style & BS_FLAT) ? BF_FLAT : 0));
1708 
1709  InflateRect(&rc, -7, 1);
1710  dtFlags = BUTTON_CalcLabelRect(infoPtr, hDC, &rc);
1711 
1712  if (dtFlags != (UINT)-1)
1713  {
1714  /* Because buttons have CS_PARENTDC class style, there is a chance
1715  * that label will be drawn out of client rect.
1716  * But Windows doesn't clip label's rect, so do I.
1717  */
1718 
1719  /* There is 1-pixel margin at the left, right, and bottom */
1720  rc.left--; rc.right++; rc.bottom++;
1721  FillRect(hDC, &rc, hbr);
1722  rc.left++; rc.right--; rc.bottom--;
1723 
1724  BUTTON_DrawLabel(infoPtr, hDC, dtFlags, &rc);
1725  }
1726  SelectClipRgn( hDC, hrgn );
1727  if (hrgn) DeleteObject( hrgn );
1728 }
1729 
1730 
1731 /**********************************************************************
1732  * User Button Functions
1733  */
1734 
1735 static void UB_Paint( const BUTTON_INFO *infoPtr, HDC hDC, UINT action )
1736 {
1737  RECT rc;
1738  HBRUSH hBrush;
1739  HFONT hFont;
1740  LONG state = infoPtr->state;
1741  HWND parent;
1742 
1743  GetClientRect( infoPtr->hwnd, &rc);
1744 
1745  if ((hFont = infoPtr->font)) SelectObject( hDC, hFont );
1746 
1747  parent = GetParent(infoPtr->hwnd);
1748  if (!parent) parent = infoPtr->hwnd;
1749  hBrush = (HBRUSH)SendMessageW(parent, WM_CTLCOLORBTN, (WPARAM)hDC, (LPARAM)infoPtr->hwnd);
1750  if (!hBrush) /* did the app forget to call defwindowproc ? */
1751  hBrush = (HBRUSH)DefWindowProcW(parent, WM_CTLCOLORBTN, (WPARAM)hDC, (LPARAM)infoPtr->hwnd);
1752 
1753  FillRect( hDC, &rc, hBrush );
1754  if (action == ODA_FOCUS || (state & BST_FOCUS))
1755  DrawFocusRect( hDC, &rc );
1756 
1757  switch (action)
1758  {
1759  case ODA_FOCUS:
1761  break;
1762 
1763  case ODA_SELECT:
1765  break;
1766 
1767  default:
1768  break;
1769  }
1770 }
1771 
1772 
1773 /**********************************************************************
1774  * Ownerdrawn Button Functions
1775  */
1776 
1777 static void OB_Paint( const BUTTON_INFO *infoPtr, HDC hDC, UINT action )
1778 {
1779  LONG state = infoPtr->state;
1780  DRAWITEMSTRUCT dis;
1781  LONG_PTR id = GetWindowLongPtrW( infoPtr->hwnd, GWLP_ID );
1782  HWND parent;
1783  HFONT hFont;
1784  HRGN hrgn;
1785 
1786  dis.CtlType = ODT_BUTTON;
1787  dis.CtlID = id;
1788  dis.itemID = 0;
1789  dis.itemAction = action;
1790  dis.itemState = ((state & BST_FOCUS) ? ODS_FOCUS : 0) |
1791  ((state & BST_PUSHED) ? ODS_SELECTED : 0) |
1792  (IsWindowEnabled(infoPtr->hwnd) ? 0: ODS_DISABLED);
1793  dis.hwndItem = infoPtr->hwnd;
1794  dis.hDC = hDC;
1795  dis.itemData = 0;
1796  GetClientRect( infoPtr->hwnd, &dis.rcItem );
1797 
1798  if ((hFont = infoPtr->font)) SelectObject( hDC, hFont );
1799  parent = GetParent(infoPtr->hwnd);
1800  if (!parent) parent = infoPtr->hwnd;
1802 
1803  hrgn = set_control_clipping( hDC, &dis.rcItem );
1804 
1805  SendMessageW( GetParent(infoPtr->hwnd), WM_DRAWITEM, id, (LPARAM)&dis );
1806  SelectClipRgn( hDC, hrgn );
1807  if (hrgn) DeleteObject( hrgn );
1808 }
1809 
1810 #ifdef __REACTOS__ /* r73885 */
1811 static void PB_ThemedPaint( HTHEME theme, const BUTTON_INFO *infoPtr, HDC hDC, ButtonState drawState, UINT dtFlags, BOOL focused, LPARAM prfFlag)
1812 #else
1813 static void PB_ThemedPaint(HTHEME theme, const BUTTON_INFO *infoPtr, HDC hDC, ButtonState drawState, UINT dtFlags, BOOL focused)
1814 #endif
1815 {
1816  static const int states[] = { PBS_NORMAL, PBS_DISABLED, PBS_HOT, PBS_PRESSED, PBS_DEFAULTED };
1817 
1818  RECT bgRect, textRect;
1819  HFONT font = infoPtr->font;
1820  HFONT hPrevFont = font ? SelectObject(hDC, font) : NULL;
1821  int state = states[ drawState ];
1822  WCHAR *text = get_button_text(infoPtr);
1823 #ifdef __REACTOS__
1824  HWND parent;
1825  DWORD cdrf;
1826 
1827  GetClientRect(infoPtr->hwnd, &bgRect);
1829 
1830  if (prfFlag == 0)
1831  {
1833  DrawThemeParentBackground(infoPtr->hwnd, hDC, NULL);
1834  }
1835 
1836  parent = GetParent(infoPtr->hwnd);
1837  if (!parent) parent = infoPtr->hwnd;
1839 
1840  cdrf = BUTTON_SendCustomDraw(infoPtr, hDC, CDDS_PREERASE, &bgRect);
1841  if (cdrf == CDRF_SKIPDEFAULT)
1842  goto cleanup;
1843 
1844  DrawThemeBackground(theme, hDC, BP_PUSHBUTTON, state, &bgRect, NULL);
1845 
1846  if (cdrf == CDRF_NOTIFYPOSTERASE)
1847  BUTTON_SendCustomDraw(infoPtr, hDC, CDDS_POSTERASE, &bgRect);
1848 
1849  cdrf = BUTTON_SendCustomDraw(infoPtr, hDC, CDDS_PREPAINT, &bgRect);
1850  if (cdrf == CDRF_SKIPDEFAULT)
1851  goto cleanup;
1852 
1853  BUTTON_DrawIml(hDC, &infoPtr->imlData, &textRect, FALSE, drawState);
1854 #else
1855  GetClientRect(infoPtr->hwnd, &bgRect);
1857 
1859  DrawThemeParentBackground(infoPtr->hwnd, hDC, NULL);
1860 
1861  DrawThemeBackground(theme, hDC, BP_PUSHBUTTON, state, &bgRect, NULL);
1862 #endif
1863 
1864  if (text)
1865  {
1866  DrawThemeText(theme, hDC, BP_PUSHBUTTON, state, text, lstrlenW(text), dtFlags, 0, &textRect);
1867  heap_free(text);
1868 #ifdef __REACTOS__
1869  text = NULL;
1870 #endif
1871  }
1872 
1873  if (focused)
1874  {
1875  MARGINS margins;
1876  RECT focusRect = bgRect;
1877 
1879 
1880  focusRect.left += margins.cxLeftWidth;
1881  focusRect.top += margins.cyTopHeight;
1882  focusRect.right -= margins.cxRightWidth;
1883  focusRect.bottom -= margins.cyBottomHeight;
1884 
1885  DrawFocusRect( hDC, &focusRect );
1886  }
1887 
1888 #ifdef __REACTOS__
1889  if (cdrf == CDRF_NOTIFYPOSTPAINT)
1890  BUTTON_SendCustomDraw(infoPtr, hDC, CDDS_POSTPAINT, &bgRect);
1891 cleanup:
1892  if (text) heap_free(text);
1893 #endif
1894  if (hPrevFont) SelectObject(hDC, hPrevFont);
1895 }
1896 
1897 #ifdef __REACTOS__ /* r73885 */
1898 static void CB_ThemedPaint(HTHEME theme, const BUTTON_INFO *infoPtr, HDC hDC, ButtonState drawState, UINT dtFlags, BOOL focused, LPARAM prfFlag)
1899 #else
1900 static void CB_ThemedPaint(HTHEME theme, const BUTTON_INFO *infoPtr, HDC hDC, ButtonState drawState, UINT dtFlags, BOOL focused)
1901 #endif
1902 {
1903  static const int cb_states[3][5] =
1904  {
1908  };
1909 
1910  static const int rb_states[2][5] =
1911  {
1914  };
1915 
1916  SIZE sz;
1917  RECT bgRect, textRect;
1918  HFONT font, hPrevFont = NULL;
1919  int checkState = infoPtr->state & 3;
1920  DWORD dwStyle = GetWindowLongW(infoPtr->hwnd, GWL_STYLE);
1921  UINT btn_type = get_button_type( dwStyle );
1922  int part = (btn_type == BS_RADIOBUTTON) || (btn_type == BS_AUTORADIOBUTTON) ? BP_RADIOBUTTON : BP_CHECKBOX;
1923  int state = (part == BP_CHECKBOX)
1924  ? cb_states[ checkState ][ drawState ]
1925  : rb_states[ checkState ][ drawState ];
1926  WCHAR *text = get_button_text(infoPtr);
1927  LOGFONTW lf;
1928  BOOL created_font = FALSE;
1929 #ifdef __REACTOS__
1930  HWND parent;
1931  HBRUSH hBrush;
1932  DWORD cdrf;
1933 #endif
1934 
1935  HRESULT hr = GetThemeFont(theme, hDC, part, state, TMT_FONT, &lf);
1936  if (SUCCEEDED(hr)) {
1937  font = CreateFontIndirectW(&lf);
1938  if (!font)
1939  TRACE("Failed to create font\n");
1940  else {
1941  TRACE("font = %s\n", debugstr_w(lf.lfFaceName));
1942  hPrevFont = SelectObject(hDC, font);
1943  created_font = TRUE;
1944  }
1945  } else {
1946 #ifdef __REACTOS__ /* r73885 */
1947  font = infoPtr->font;
1948 #else
1949  font = (HFONT)SendMessageW(infoPtr->hwnd, WM_GETFONT, 0, 0);
1950 #endif
1951  hPrevFont = SelectObject(hDC, font);
1952  }
1953 
1954  if (FAILED(GetThemePartSize(theme, hDC, part, state, NULL, TS_DRAW, &sz)))
1955  sz.cx = sz.cy = 13;
1956 
1957  GetClientRect(infoPtr->hwnd, &bgRect);
1958 
1959 #ifdef __REACTOS__
1960  if (prfFlag == 0)
1961  {
1962  DrawThemeParentBackground(infoPtr->hwnd, hDC, NULL);
1963  }
1964 
1965  parent = GetParent(infoPtr->hwnd);
1966  if (!parent) parent = infoPtr->hwnd;
1967  hBrush = (HBRUSH)SendMessageW(parent, WM_CTLCOLORSTATIC,
1968  (WPARAM)hDC, (LPARAM)infoPtr->hwnd);
1969  if (!hBrush) /* did the app forget to call defwindowproc ? */
1970  hBrush = (HBRUSH)DefWindowProcW(parent, WM_CTLCOLORSTATIC,
1971  (WPARAM)hDC, (LPARAM)infoPtr->hwnd );
1972  FillRect( hDC, &bgRect, hBrush );
1973 
1974  cdrf = BUTTON_SendCustomDraw(infoPtr, hDC, CDDS_PREERASE, &bgRect);
1975  if (cdrf == CDRF_SKIPDEFAULT)
1976  goto cleanup;
1977 #endif
1978 
1979  GetThemeBackgroundContentRect(theme, hDC, part, state, &bgRect, &textRect);
1980 
1981  if (dtFlags & DT_SINGLELINE) /* Center the checkbox / radio button to the text. */
1982  bgRect.top = bgRect.top + (textRect.bottom - textRect.top - sz.cy) / 2;
1983 
1984  /* adjust for the check/radio marker */
1985  bgRect.bottom = bgRect.top + sz.cy;
1986  bgRect.right = bgRect.left + sz.cx;
1987  textRect.left = bgRect.right + 6;
1988 
1989 #ifdef __REACTOS__
1990  DrawThemeBackground(theme, hDC, part, state, &bgRect, NULL);
1991 
1992  if (cdrf == CDRF_NOTIFYPOSTERASE)
1993  BUTTON_SendCustomDraw(infoPtr, hDC, CDDS_POSTERASE, &bgRect);
1994 
1995  cdrf = BUTTON_SendCustomDraw(infoPtr, hDC, CDDS_PREPAINT, &bgRect);
1996  if (cdrf == CDRF_SKIPDEFAULT)
1997  goto cleanup;
1998 
1999 #else
2000  DrawThemeParentBackground(infoPtr->hwnd, hDC, NULL);
2001  DrawThemeBackground(theme, hDC, part, state, &bgRect, NULL);
2002 #endif
2003  if (text)
2004  {
2005  DrawThemeText(theme, hDC, part, state, text, lstrlenW(text), dtFlags, 0, &textRect);
2006 
2007  if (focused)
2008  {
2009  RECT focusRect;
2010 
2011  focusRect = textRect;
2012 
2013  DrawTextW(hDC, text, lstrlenW(text), &focusRect, dtFlags | DT_CALCRECT);
2014 
2015  if (focusRect.right < textRect.right) focusRect.right++;
2016  focusRect.bottom = textRect.bottom;
2017 
2018  DrawFocusRect( hDC, &focusRect );
2019  }
2020 
2021  heap_free(text);
2022 #ifdef __REACTOS__
2023  text = NULL;
2024 #endif
2025  }
2026 
2027 #ifdef __REACTOS__
2028  if (cdrf == CDRF_NOTIFYPOSTPAINT)
2029  BUTTON_SendCustomDraw(infoPtr, hDC, CDDS_POSTPAINT, &bgRect);
2030 cleanup:
2031  if (text) heap_free(text);
2032 #endif
2033  if (created_font) DeleteObject(font);
2034  if (hPrevFont) SelectObject(hDC, hPrevFont);
2035 }
2036 
2037 #ifdef __REACTOS__ /* r73885 */
2038 static void GB_ThemedPaint(HTHEME theme, const BUTTON_INFO *infoPtr, HDC hDC, ButtonState drawState, UINT dtFlags, BOOL focused, LPARAM prfFlag)
2039 #else
2040 static void GB_ThemedPaint(HTHEME theme, const BUTTON_INFO *infoPtr, HDC hDC, ButtonState drawState, UINT dtFlags, BOOL focused)
2041 #endif
2042 {
2043  static const int states[] = { GBS_NORMAL, GBS_DISABLED, GBS_NORMAL, GBS_NORMAL, GBS_NORMAL };
2044 
2045  RECT bgRect, textRect, contentRect;
2046  int state = states[ drawState ];
2047  WCHAR *text = get_button_text(infoPtr);
2048  LOGFONTW lf;
2049  HFONT font, hPrevFont = NULL;
2050  BOOL created_font = FALSE;
2051 #ifdef __REACTOS__ /* r74406 */
2052  HWND parent;
2053  HBRUSH hBrush;
2054  RECT clientRect;
2055 #endif
2056 
2057  HRESULT hr = GetThemeFont(theme, hDC, BP_GROUPBOX, state, TMT_FONT, &lf);
2058  if (SUCCEEDED(hr)) {
2059  font = CreateFontIndirectW(&lf);
2060  if (!font)
2061  TRACE("Failed to create font\n");
2062  else {
2063  hPrevFont = SelectObject(hDC, font);
2064  created_font = TRUE;
2065  }
2066  } else {
2067 #ifdef __REACTOS__ /* r73885 */
2068  font = infoPtr->font;
2069 #else
2070  font = (HFONT)SendMessageW(infoPtr->hwnd, WM_GETFONT, 0, 0);
2071 #endif
2072  hPrevFont = SelectObject(hDC, font);
2073  }
2074 
2075  GetClientRect(infoPtr->hwnd, &bgRect);
2076  textRect = bgRect;
2077 
2078  if (text)
2079  {
2080  SIZE textExtent;
2081  GetTextExtentPoint32W(hDC, text, lstrlenW(text), &textExtent);
2082  bgRect.top += (textExtent.cy / 2);
2083  textRect.left += 10;
2084  textRect.bottom = textRect.top + textExtent.cy;
2085  textRect.right = textRect.left + textExtent.cx + 4;
2086 
2088  }
2089 
2090  GetThemeBackgroundContentRect(theme, hDC, BP_GROUPBOX, state, &bgRect, &contentRect);
2091  ExcludeClipRect(hDC, contentRect.left, contentRect.top, contentRect.right, contentRect.bottom);
2092 
2093 #ifdef __REACTOS__ /* r73885 & r74149 */
2094  if (prfFlag == 0)
2095 #endif
2097  DrawThemeParentBackground(infoPtr->hwnd, hDC, NULL);
2098 
2099 #ifdef __REACTOS__ /* r74406 */
2100  parent = GetParent(infoPtr->hwnd);
2101  if (!parent) parent = infoPtr->hwnd;
2102  hBrush = (HBRUSH)SendMessageW(parent, WM_CTLCOLORSTATIC,
2103  (WPARAM)hDC, (LPARAM)infoPtr->hwnd);
2104  if (!hBrush) /* did the app forget to call defwindowproc ? */
2105  hBrush = (HBRUSH)DefWindowProcW(parent, WM_CTLCOLORSTATIC,
2106  (WPARAM)hDC, (LPARAM)infoPtr->hwnd );
2107  GetClientRect(infoPtr->hwnd, &clientRect);
2108  FillRect( hDC, &clientRect, hBrush );
2109 #endif
2110 
2111  DrawThemeBackground(theme, hDC, BP_GROUPBOX, state, &bgRect, NULL);
2112 
2114 
2115  if (text)
2116  {
2117  InflateRect(&textRect, -2, 0);
2119  heap_free(text);
2120  }
2121 
2122  if (created_font) DeleteObject(font);
2123  if (hPrevFont) SelectObject(hDC, hPrevFont);
2124 }
2125 
2127 {
2128  WNDCLASSW wndClass;
2129 
2130  memset(&wndClass, 0, sizeof(wndClass));
2132  wndClass.lpfnWndProc = BUTTON_WindowProc;
2133  wndClass.cbClsExtra = 0;
2134  wndClass.cbWndExtra = sizeof(BUTTON_INFO *);
2135  wndClass.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
2136  wndClass.hbrBackground = NULL;
2137  wndClass.lpszClassName = WC_BUTTONW;
2138  RegisterClassW(&wndClass);
2139 }
2140 
2141 
2142 #ifdef __REACTOS__
2143 void BUTTON_Unregister(void)
2144 {
2146 }
2147 #endif
#define BF_FLAT
Definition: winuser.h:471
#define BS_NOTIFY
Definition: winuser.h:268
INT WINAPI ImageList_GetImageCount(HIMAGELIST himl)
Definition: imagelist.c:2063
HIMAGELIST himl
Definition: commctrl.h:4606
HRESULT WINAPI GetThemePartSize(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, RECT *prc, THEMESIZE eSize, SIZE *psz)
Definition: draw.c:1777
#define WS_DISABLED
Definition: pedump.c:621
#define BS_LEFT
Definition: winuser.h:265
BOOL WINAPI GetCharWidthW(_In_ HDC hdc, _In_ UINT iFirst, _In_ UINT iLast, _Out_writes_(iLast+1 - iFirst) LPINT lpBuffer)
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
#define DFCS_FLAT
Definition: winuser.h:510
#define BM_SETSTATE
Definition: winuser.h:1905
BOOL WINAPI RedrawWindow(_In_opt_ HWND, _In_opt_ LPCRECT, _In_opt_ HRGN, _In_ UINT)
#define WM_SYSCOLORCHANGE
Definition: winuser.h:1608
WINE_DEFAULT_DEBUG_CHANNEL(button)
#define max(a, b)
Definition: svc.c:63
#define BS_OWNERDRAW
Definition: pedump.c:661
#define LOGPIXELSX
Definition: wingdi.h:717
BOOL WINAPI InflateRect(_Inout_ LPRECT, _In_ int, _In_ int)
Definition: tftpd.h:59
static HICON
Definition: imagelist.c:84
static void BUTTON_DrawLabel(const BUTTON_INFO *infoPtr, HDC hdc, UINT dtFlags, const RECT *rc)
Definition: button.c:1328
#define HTTRANSPARENT
Definition: winuser.h:2448
#define TRUE
Definition: types.h:120
#define DLGC_UNDEFPUSHBUTTON
Definition: winuser.h:2591
HPEN WINAPI CreatePen(_In_ int, _In_ int, _In_ COLORREF)
#define DT_HIDEPREFIX
Definition: winuser.h:547
#define DFC_BUTTON
Definition: winuser.h:476
#define IMAGE_ICON
Definition: winuser.h:212
#define COLOR_WINDOWFRAME
Definition: winuser.h:909
static HBRUSH hbrush
BOOL WINAPI GetTextMetricsW(_In_ HDC, _Out_ LPTEXTMETRICW)
Definition: text.c:221
#define BS_DEFCOMMANDLINK
Definition: commctrl.h:4644
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
_Must_inspect_result_ _Out_ LPSIZE psize
Definition: ntgdi.h:1569
int WINAPI SelectClipRgn(_In_ HDC, _In_opt_ HRGN)
UINT style
Definition: winuser.h:3150
#define WM_GETDLGCODE
Definition: winuser.h:1671
#define LAYOUT_RTL
Definition: wingdi.h:1370
#define WM_LBUTTONDOWN
Definition: winuser.h:1758
HRESULT hr
Definition: shlfolder.c:183
#define BS_LEFTTEXT
Definition: pedump.c:662
void BUTTON_Register(void)
Definition: button.c:2126
BOOL WINAPI OffsetRect(_Inout_ LPRECT, _In_ int, _In_ int)
BOOL WINAPI UnregisterClassW(_In_ LPCWSTR, HINSTANCE)
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
BOOL WINAPI IsWindow(_In_opt_ HWND)
#define CDDS_POSTERASE
Definition: commctrl.h:268
#define BCM_SETTEXTMARGIN
Definition: commctrl.h:4620
#define DFCS_CHECKED
Definition: winuser.h:504
#define BS_DEFSPLITBUTTON
Definition: commctrl.h:4642
#define MK_LBUTTON
Definition: winuser.h:2342
#define CDRF_NOTIFYPOSTPAINT
Definition: commctrl.h:259
BOOL WINAPI Rectangle(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int)
HDC WINAPI GetDC(_In_opt_ HWND)
static void PB_Paint(const BUTTON_INFO *infoPtr, HDC hDC, UINT action)
Definition: button.c:1396
HBITMAP WINAPI CreateCompatibleBitmap(_In_ HDC hdc, _In_ INT cx, _In_ INT cy)
Definition: mk_font.cpp:20
#define BS_RIGHT
Definition: winuser.h:274
#define BS_RADIOBUTTON
Definition: pedump.c:655
static WCHAR * get_button_text(const BUTTON_INFO *infoPtr)
Definition: button.c:230
#define pt(x, y)
Definition: drawing.c:79
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
const WCHAR * text
Definition: package.c:1827
GLuint GLuint GLsizei count
Definition: gl.h:1545
#define WM_MOUSEHOVER
Definition: commctrl.h:4945
#define BM_GETSTATE
Definition: winuser.h:1902
#define WM_CTLCOLORSTATIC
Definition: winuser.h:1754
#define DT_WORDBREAK
Definition: winuser.h:544
#define DFCS_BUTTON3STATE
Definition: winuser.h:500
LONG lfHeight
Definition: dimm.idl:59
#define BCM_GETTEXTMARGIN
Definition: commctrl.h:4622
BOOL WINAPI DrawFocusRect(_In_ HDC, _In_ LPCRECT)
#define BS_TEXT
Definition: winuser.h:276
#define WM_CAPTURECHANGED
Definition: winuser.h:1790
HANDLE image
Definition: button.c:102
static const WORD maxCheckState[MAX_BTN_TYPE]
Definition: button.c:122
static HDC
Definition: imagelist.c:92
#define DLGC_RADIOBUTTON
Definition: winuser.h:2592
#define DFCS_INACTIVE
Definition: winuser.h:502
#define CALLBACK
Definition: compat.h:27
#define BS_DEFPUSHBUTTON
Definition: pedump.c:652
HWND hWnd
Definition: settings.c:17
GLdouble n
Definition: glext.h:7729
ULONG_PTR itemData
Definition: winuser.h:3067
LONG top
Definition: windef.h:292
BOOL(CALLBACK * DRAWSTATEPROC)(HDC, LPARAM, WPARAM, int, int)
Definition: winuser.h:2881
int WINAPI IntersectClipRect(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int)
#define CDDS_POSTPAINT
Definition: commctrl.h:266
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
#define ODS_FOCUS
Definition: winuser.h:2524
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
#define BUTTON_NSTATES
Definition: button.c:77
#define BUTTON_IMAGELIST_ALIGN_TOP
Definition: commctrl.h:4601
static HTHEME(WINAPI *pOpenThemeDataEx)(HWND
#define CS_HREDRAW
Definition: winuser.h:648
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
#define GWL_EXSTYLE
Definition: winuser.h:845
static void CB_Paint(const BUTTON_INFO *infoPtr, HDC hDC, UINT action)
Definition: button.c:1519
GLuint buffer
Definition: glext.h:5915
int cbClsExtra
Definition: winuser.h:3152
HWND WINAPI SetFocus(_In_opt_ HWND)
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
#define WM_NCHITTEST
Definition: winuser.h:1668
BOOL WINAPI DrawFrameControl(_In_ HDC, _Inout_ LPRECT, _In_ UINT, _In_ UINT)
UINT_PTR WPARAM
Definition: windef.h:207
HRESULT WINAPI GetThemeFont(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, int iPropId, LOGFONTW *pFont)
Definition: property.c:108
#define WS_CHILD
Definition: pedump.c:617
static HPEN hpen
#define DT_RIGHT
Definition: winuser.h:538
#define GetWindowLongPtrW
Definition: winuser.h:4730
BOOL WINAPI ImageList_Draw(HIMAGELIST himl, INT i, HDC hdc, INT x, INT y, UINT fStyle)
Definition: imagelist.c:1228
HBITMAP bitmap
Definition: button.c:101
#define RDW_FRAME
Definition: winuser.h:1198
LONG left
Definition: windef.h:291
static void OB_Paint(const BUTTON_INFO *infoPtr, HDC hDC, UINT action)
Definition: button.c:1777
BOOL WINAPI EndPaint(_In_ HWND, _In_ const PAINTSTRUCT *)
#define CDRF_SKIPDEFAULT
Definition: commctrl.h:255
#define BS_CENTER
Definition: winuser.h:260
LONG right
Definition: windef.h:293
#define ODA_FOCUS
Definition: winuser.h:2519
#define lstrlenW
Definition: compat.h:407
#define BM_GETIMAGE
Definition: winuser.h:1901
#define WS_EX_RIGHT
Definition: winuser.h:400
#define WM_NCCREATE
Definition: winuser.h:1665
static LRESULT CALLBACK BUTTON_WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: button.c:587
#define BM_SETIMAGE
Definition: winuser.h:1904
BOOL WINAPI DPtoLP(_In_ HDC hdc, _Inout_updates_(c) LPPOINT lppt, _In_ int c)
HRESULT WINAPI DrawThemeBackground(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, const RECT *pRect, const RECT *pClipRect)
Definition: draw.c:128
struct _BUTTON_INFO BUTTON_INFO
static VOID NTAPI BitBlt(IN ULONG Left, IN ULONG Top, IN ULONG Width, IN ULONG Height, IN PUCHAR Buffer, IN ULONG BitsPerPixel, IN ULONG Delta)
Definition: vga.c:410
HRGN set_control_clipping(HDC hdc, const RECT *rect)
Definition: button.c:239
int32_t INT
Definition: typedefs.h:56
BOOL WINAPI GetIconInfo(_In_ HICON, _Out_ PICONINFO)
Definition: cursoricon.c:2014
#define BS_GROUPBOX
Definition: pedump.c:658
#define BN_UNHILITE
Definition: winuser.h:1916
Definition: misc.c:279
DWORD WINAPI GetSysColor(_In_ int)
& rect
Definition: startmenu.cpp:1413
WPARAM wParam
Definition: combotst.c:138
#define BST_INDETERMINATE
Definition: winuser.h:198
static void GB_Paint(const BUTTON_INFO *infoPtr, HDC hDC, UINT action)
Definition: button.c:1683
HFONT hFont
Definition: main.c:53
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
#define WM_ENABLE
Definition: winuser.h:1597
#define WM_PRINTCLIENT
Definition: richedit.h:70
LRESULT WINAPI DefWindowProcW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
BOOL WINAPI TrackMouseEvent(_Inout_ LPTRACKMOUSEEVENT)
#define DSS_HIDEPREFIX
Definition: winuser.h:522
HWND WINAPI GetNextDlgGroupItem(_In_ HWND, _In_opt_ HWND, _In_ BOOL)
UINT code
Definition: winuser.h:3133
static const pfPaint btnPaintFunc[MAX_BTN_TYPE]
Definition: button.c:154
BOOL WINAPI IsThemeBackgroundPartiallyTransparent(HTHEME hTheme, int iPartId, int iStateId)
Definition: draw.c:1883
ATOM WINAPI RegisterClassW(_In_ CONST WNDCLASSW *)
#define BF_RECT
Definition: winuser.h:462
unsigned short(__cdecl typeof(TIFFCurrentDirectory))(struct tiff *)
Definition: typeof.h:93
#define PS_SOLID
Definition: wingdi.h:585
#define DFCS_PUSHED
Definition: winuser.h:503
#define DFCS_BUTTONRADIO
Definition: winuser.h:499
int WINAPI SetBkMode(_In_ HDC, _In_ int)
Definition: dc.c:1032
#define WM_CTLCOLORBTN
Definition: winuser.h:1751
#define DT_LEFT
Definition: winuser.h:534
#define DT_CALCRECT
Definition: winuser.h:526
#define BST_HOT
Definition: commctrl.h:4639
#define HICF_ENTERING
Definition: commctrl.h:1302
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
#define TMT_CONTENTMARGINS
Definition: vssym32.h:324
LONG WINAPI SetWindowLongW(_In_ HWND, _In_ int, _In_ LONG)
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)
BOOL WINAPI DrawEdge(_In_ HDC, _Inout_ LPRECT, _In_ UINT, _In_ UINT)
UINT_PTR idFrom
Definition: winuser.h:3132
#define BUTTON_IMAGELIST_ALIGN_CENTER
Definition: commctrl.h:4603
#define debugstr_w
Definition: kernel32.h:32
HBITMAP hbmMask
Definition: winuser.h:3100
ButtonState
Definition: button.c:143
WNDPROC lpfnWndProc
Definition: winuser.h:3151
HWND WINAPI GetCapture(void)
Definition: message.c:2879
#define WM_MOUSELEAVE
Definition: commctrl.h:4946
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
#define HICF_LEAVING
Definition: commctrl.h:1303
#define TRANSPARENT
Definition: wingdi.h:949
void WINAPI mouse_event(_In_ DWORD, _In_ DWORD, _In_ DWORD, _In_ DWORD, _In_ ULONG_PTR)
_Out_opt_ int _Out_opt_ int * cy
Definition: commctrl.h:570
static void CB_ThemedPaint(HTHEME theme, const BUTTON_INFO *infoPtr, HDC hdc, ButtonState drawState, UINT dtflags, BOOL focused)
Definition: button.c:1900
LONG WINAPI GetWindowLongW(_In_ HWND, _In_ int)
RECT textRect
Definition: startmenu.cpp:1392
LONG lfWidth
Definition: dimm.idl:60
smooth NULL
Definition: ftsmooth.c:416
HFONT WINAPI CreateFontIndirectW(_In_ const LOGFONTW *)
#define WM_GETFONT
Definition: winuser.h:1633
#define BS_AUTOCHECKBOX
Definition: pedump.c:654
#define CDIS_SELECTED
Definition: commctrl.h:276
#define BS_AUTO3STATE
Definition: pedump.c:657
LONG cx
Definition: windef.h:319
#define TMT_FONT
Definition: vssym32.h:144
#define WM_KEYDOWN
Definition: winuser.h:1697
LPCWSTR lpszClassName
Definition: winuser.h:3159
LONG_PTR LPARAM
Definition: windef.h:208
HBITMAP hbmColor
Definition: winuser.h:3101
#define BM_GETCHECK
Definition: winuser.h:1900
BOOL WINAPI IsWindowEnabled(_In_ HWND)
static UINT BUTTON_CalcLabelRect(const BUTTON_INFO *infoPtr, HDC hdc, RECT *rc)
Definition: button.c:1185
GLuint index
Definition: glext.h:6031
#define BST_FOCUS
Definition: winuser.h:200
#define DT_VCENTER
Definition: winuser.h:543
#define WM_SETTEXT
Definition: winuser.h:1599
#define WM_DESTROY
Definition: winuser.h:1591
#define BN_HILITE
Definition: winuser.h:1911
HRGN WINAPI CreateRectRgn(_In_ int, _In_ int, _In_ int, _In_ int)
HRESULT WINAPI GetThemeBackgroundExtent(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, const RECT *pContentRect, RECT *pExtentRect)
Definition: draw.c:1528
HBITMAP hbmp
#define BUTTON_NOTIFY_PARENT(hWnd, code)
Definition: button.c:85
static void UB_Paint(const BUTTON_INFO *infoPtr, HDC hDC, UINT action)
Definition: button.c:1735
HRESULT WINAPI DrawThemeParentBackground(HWND hwnd, HDC hdc, RECT *prc)
Definition: draw.c:72
#define CS_VREDRAW
Definition: winuser.h:653
#define BM_CLICK
Definition: winuser.h:1899
#define ODA_DRAWENTIRE
Definition: winuser.h:2517
static void PB_ThemedPaint(HTHEME theme, const BUTTON_INFO *infoPtr, HDC hdc, ButtonState drawState, UINT dtflags, BOOL focused)
Definition: button.c:1813
#define DLGC_DEFPUSHBUTTON
Definition: winuser.h:2590
#define BM_SETCHECK
Definition: winuser.h:1903
#define TRACE(s)
Definition: solgame.cpp:4
#define BS_COMMANDLINK
Definition: commctrl.h:4643
#define WM_KILLFOCUS
Definition: winuser.h:1596
#define GetProcessHeap()
Definition: compat.h:395
HWND hwnd
Definition: button.c:95
r parent
Definition: btrfs.c:2897
int cbWndExtra
Definition: winuser.h:3153
#define BS_MULTILINE
Definition: winuser.h:267
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define DSS_MONO
Definition: winuser.h:521
#define BM_SETSTYLE
Definition: winuser.h:1906
#define ODS_DISABLED
Definition: winuser.h:2522
LONG HRESULT
Definition: typedefs.h:77
#define BST_PUSHED
Definition: winuser.h:201
DWORD COLORREF
Definition: windef.h:285
#define DSS_DISABLED
Definition: winuser.h:519
#define CS_GLOBALCLASS
Definition: winuser.h:647
#define WM_NCDESTROY
Definition: winuser.h:1666
#define DFCS_MONO
Definition: winuser.h:511
int WINAPI GetWindowTextLengthW(_In_ HWND)
#define BS_TOP
Definition: winuser.h:277
#define WM_KEYUP
Definition: winuser.h:1698
BOOL WINAPI InvalidateRect(_In_opt_ HWND, _In_opt_ LPCRECT, _In_ BOOL)
static UINT BUTTON_BStoDT(DWORD style, DWORD ex_style)
Definition: button.c:262
#define TME_QUERY
Definition: commctrl.h:4954
static FILE * client
Definition: client.c:41
unsigned short WORD
Definition: ntddk_ex.h:93
#define BN_CLICKED
Definition: winuser.h:1907
PVOID HANDLE
Definition: typedefs.h:71
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint left
Definition: glext.h:7726
#define CDIS_FOCUS
Definition: commctrl.h:280
HCURSOR WINAPI LoadCursorW(_In_opt_ HINSTANCE, _In_ LPCWSTR)
Definition: cursoricon.c:2074
#define CDIS_CHECKED
Definition: commctrl.h:279
HTHEME WINAPI OpenThemeData(HWND hwnd, LPCWSTR classlist)
Definition: system.c:835
#define EDGE_ETCHED
Definition: winuser.h:452
#define MAX_BTN_TYPE
Definition: button.c:120
GLbitfield flags
Definition: glext.h:7161
static LPARAM
Definition: button.c:42
#define BN_KILLFOCUS
Definition: winuser.h:1912
#define WM_PAINT
Definition: winuser.h:1602
#define BS_SPLITBUTTON
Definition: commctrl.h:4641
HTHEME WINAPI GetWindowTheme(HWND hwnd)
Definition: system.c:851
int ret
#define NM_CUSTOMDRAW
Definition: commctrl.h:137
#define CDDS_PREPAINT
Definition: commctrl.h:265
#define BUTTON_IMAGELIST_ALIGN_LEFT
Definition: commctrl.h:4599
#define BS_ICON
Definition: winuser.h:264
#define COLOR_GRAYTEXT
Definition: winuser.h:922
#define BCM_GETIMAGELIST
Definition: commctrl.h:4617
#define OPAQUE
Definition: wingdi.h:948
static const WCHAR L[]
Definition: oid.c:1250
struct tagTRACKMOUSEEVENT TRACKMOUSEEVENT
HDC hdc
Definition: main.c:9
#define COLOR_BTNFACE
Definition: winuser.h:918
BOOL WINAPI DrawStateW(_In_ HDC, _In_opt_ HBRUSH, _In_opt_ DRAWSTATEPROC, _In_ LPARAM, _In_ WPARAM, _In_ int, _In_ int, _In_ int, _In_ int, _In_ UINT)
static HRGN hrgn
Definition: win.c:55
int WINAPI GetDeviceCaps(_In_opt_ HDC, _In_ int)
#define BS_BITMAP
Definition: winuser.h:258
static int state
Definition: maze.c:121
GLenum GLsizei len
Definition: glext.h:6722
#define WM_LBUTTONDBLCLK
Definition: winuser.h:1760
#define CS_DBLCLKS
Definition: winuser.h:646
#define WS_TABSTOP
Definition: pedump.c:634
Definition: time.h:76
HFONT font
Definition: button.c:97
static UINT get_button_type(LONG window_style)
Definition: button.c:211
HWND hwndFrom
Definition: winuser.h:3131
#define BS_VCENTER
Definition: winuser.h:279
#define BST_UNCHECKED
Definition: winuser.h:199
BOOL WINAPI IntersectRect(_Out_ LPRECT, _In_ LPCRECT, _In_ LPCRECT)
static RECT margins
Definition: print.c:55
#define wcsicmp
Definition: string.h:1152
#define BUTTON_BTNPRESSED
Definition: button.c:78
#define BS_PUSHBUTTON
Definition: pedump.c:651
HRESULT WINAPI GetThemeMargins(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, int iPropId, RECT *prc, MARGINS *pMargins)
Definition: property.c:216
union _BUTTON_INFO::@320 u
LONG state
Definition: button.c:96
#define BS_FLAT
Definition: winuser.h:280
HCURSOR hCursor
Definition: winuser.h:3156
#define ERR(fmt,...)
Definition: debug.h:109
#define GWL_STYLE
Definition: winuser.h:846
#define DT_NOCLIP
Definition: winuser.h:536
#define BUTTON_IMAGELIST_ALIGN_BOTTOM
Definition: commctrl.h:4602
#define DFCS_BUTTONCHECK
Definition: winuser.h:496
COLORREF WINAPI SetTextColor(_In_ HDC, _In_ COLORREF)
Definition: text.c:888
static HDC hDC
Definition: 3dtext.c:33
int WINAPI GetObjectW(_In_ HANDLE h, _In_ int c, _Out_writes_bytes_opt_(c) LPVOID pv)
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define BN_SETFOCUS
Definition: winuser.h:1915
#define DT_SINGLELINE
Definition: winuser.h:540
HWND WINAPI GetParent(_In_ HWND)
BOOL WINAPI SetRect(_Out_ LPRECT, _In_ int, _In_ int, _In_ int, _In_ int)
HWND WINAPI SetCapture(_In_ HWND hWnd)
void(* pfThemedPaint)(HTHEME theme, const BUTTON_INFO *infoPtr, HDC hdc, ButtonState drawState, UINT dtflags, BOOL focused)
Definition: button.c:183
#define BS_AUTORADIOBUTTON
Definition: pedump.c:660
DWORD WINAPI GetLayout(_In_ HDC hdc)
Definition: coord.c:741
const WCHAR * action
Definition: action.c:7783
#define TME_HOVER
Definition: commctrl.h:4951
int WINAPI GetWindowTextW(HWND hWnd, LPWSTR lpString, int nMaxCount)
Definition: window.c:1408
BOOL WINAPI DeleteDC(_In_ HDC)
int WINAPI ExcludeClipRect(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int)
GLuint start
Definition: gl.h:1545
#define BS_TYPEMASK
Definition: winuser.h:270
#define WC_BUTTONW
Definition: commctrl.h:4595
DWORD_PTR dwItemSpec
Definition: commctrl.h:292
HBRUSH hbrBackground
Definition: winuser.h:3157
#define DLGC_BUTTON
Definition: winuser.h:2595
#define DFCS_BUTTONPUSH
Definition: winuser.h:501
#define TME_LEAVE
Definition: commctrl.h:4952
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define WM_LBUTTONUP
Definition: winuser.h:1759
Definition: bl.h:1331
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#define DT_TOP
Definition: winuser.h:542
unsigned int UINT
Definition: ndis.h:50
#define WM_MOUSEMOVE
Definition: winuser.h:1757
#define VK_SPACE
Definition: winuser.h:2194
#define BS_BOTTOM
Definition: winuser.h:259
#define IMAGE_BITMAP
Definition: winuser.h:211
#define CDRF_NOTIFYPOSTERASE
Definition: commctrl.h:262
#define CDIS_DISABLED
Definition: commctrl.h:278
static const pfThemedPaint btnThemedPaintFunc[MAX_BTN_TYPE]
Definition: button.c:191
#define WM_SETFONT
Definition: winuser.h:1632
#define BST_CHECKED
Definition: winuser.h:197
#define BUTTON_IMAGELIST_ALIGN_RIGHT
Definition: commctrl.h:4600
#define WM_DRAWITEM
Definition: winuser.h:1627
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
BOOL WINAPI PtInRect(_In_ LPCRECT, _In_ POINT)
#define RDW_UPDATENOW
Definition: winuser.h:1206
#define IDC_ARROW
Definition: winuser.h:682
HRESULT WINAPI GetThemeBackgroundContentRect(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, const RECT *pBoundingRect, RECT *pContentRect)
Definition: draw.c:1479
_Out_opt_ int * cx
Definition: commctrl.h:570
BOOL WINAPI ReleaseCapture(void)
Definition: message.c:2888
static void paint_button(BUTTON_INFO *infoPtr, LONG style, UINT action)
Definition: button.c:218
#define BS_PUSHLIKE
Definition: winuser.h:272
#define DST_BITMAP
Definition: winuser.h:516
#define ODS_SELECTED
Definition: winuser.h:2520
#define WM_CREATE
Definition: winuser.h:1590
#define ODT_BUTTON
Definition: winuser.h:2515
BOOL WINAPI ImageList_GetIconSize(HIMAGELIST himl, INT *cx, INT *cy)
Definition: imagelist.c:2037
#define DSS_NORMAL
Definition: winuser.h:517
static void BUTTON_CheckAutoRadioButton(HWND hwnd)
Definition: button.c:1652
WCHAR lfFaceName[LF_FACESIZE]
Definition: dimm.idl:72
#define HIWORD(l)
Definition: typedefs.h:246
GLenum GLuint id
Definition: glext.h:5579
BOOL WINAPI IsWindowVisible(_In_ HWND)
LONG bottom
Definition: windef.h:294
#define CDIS_SHOWKEYBOARDCUES
Definition: commctrl.h:285
#define DT_CENTER
Definition: winuser.h:527
char * cleanup(char *str)
Definition: wpickclick.c:99
#define LOGPIXELSY
Definition: wingdi.h:718
static BOOL CALLBACK BUTTON_DrawTextCallback(HDC hdc, LPARAM lp, WPARAM wp, int cx, int cy)
Definition: button.c:1313
#define BCM_GETIDEALSIZE
Definition: commctrl.h:4611
#define COLOR_BTNTEXT
Definition: winuser.h:923
#define BN_DOUBLECLICKED
Definition: winuser.h:1910
int WINAPI GetClipRgn(_In_ HDC, _In_ HRGN)
#define SetWindowLongPtrW
Definition: winuser.h:5247
static HBITMAP
Definition: button.c:44
#define DST_ICON
Definition: winuser.h:515
#define BS_USERBUTTON
Definition: pedump.c:659
GLdouble GLdouble GLdouble GLdouble top
Definition: glext.h:10859
#define WM_ERASEBKGND
Definition: winuser.h:1607
#define WM_SETFOCUS
Definition: winuser.h:1595
#define BCN_HOTITEMCHANGE
Definition: commctrl.h:4637
WCHAR * LPWSTR
Definition: xmlstorage.h:184
static void GB_ThemedPaint(HTHEME theme, const BUTTON_INFO *infoPtr, HDC hdc, ButtonState drawState, UINT dtflags, BOOL focused)
Definition: button.c:2040
LONG_PTR LRESULT
Definition: windef.h:209
int WINAPI FillRect(HDC, LPCRECT, HBRUSH)
Arabic default style
Definition: afstyles.h:93
_Out_ LPRECT prc
Definition: ntgdi.h:1658
#define WS_VISIBLE
Definition: pedump.c:620
HBRUSH WINAPI GetSysColorBrush(_In_ int)
#define BCM_SETIMAGELIST
Definition: commctrl.h:4614
#define memset(x, y, z)
Definition: compat.h:39
#define DT_BOTTOM
Definition: winuser.h:525
HICON icon
Definition: button.c:100
LONG cy
Definition: windef.h:320
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define HeapFree(x, y, z)
Definition: compat.h:394
#define GWLP_ID
Definition: winuser.h:854
#define DLGC_WANTARROWS
Definition: winuser.h:2585
#define SRCCOPY
Definition: wingdi.h:332
#define DLGC_STATIC
Definition: winuser.h:2594
#define CS_PARENTDC
Definition: winuser.h:651
#define ODA_SELECT
Definition: winuser.h:2518
HRESULT WINAPI CloseThemeData(HTHEME hTheme)
Definition: system.c:950
BOOL WINAPI GetTextExtentPoint32W(_In_ HDC hdc, _In_reads_(c) LPCWSTR lpString, _In_ int c, _Out_ LPSIZE psizl)
#define WM_NOTIFY
Definition: richedit.h:61
void(* pfPaint)(const BUTTON_INFO *infoPtr, HDC hdc, UINT action)
Definition: button.c:152
HRESULT WINAPI DrawThemeText(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, LPCWSTR pszText, int iCharCount, DWORD dwTextFlags, DWORD dwTextFlags2, const RECT *pRect)
Definition: draw.c:1377
#define SUCCEEDED(hr)
Definition: intsafe.h:57
#define RDW_INVALIDATE
Definition: winuser.h:1200
#define CDDS_PREERASE
Definition: commctrl.h:267
INT WINAPI DrawTextW(HDC hdc, LPCWSTR str, INT count, LPRECT rect, UINT flags)
Definition: defwnd.c:17
static BOOL heap_free(void *mem)
Definition: appwiz.h:75