ReactOS 0.4.15-dev-5893-g1bb4167
button.c File Reference
#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
#include "windef.h"
#include "winbase.h"
#include "wingdi.h"
#include "winuser.h"
#include "uxtheme.h"
#include "vssym32.h"
#include "wine/debug.h"
#include "wine/heap.h"
#include "comctl32.h"
Include dependency graph for button.c:

Go to the source code of this file.

Classes

struct  _BUTTON_INFO
 

Macros

#define OEMRESOURCE
 
#define BUTTON_NSTATES   0x0F
 
#define BUTTON_BTNPRESSED   0x40
 
#define BUTTON_UNKNOWN2   0x20
 
#define BUTTON_UNKNOWN3   0x10
 
#define BUTTON_NOTIFY_PARENT(hWnd, code)
 
#define MAX_BTN_TYPE   16
 

Typedefs

typedef struct _BUTTON_INFO BUTTON_INFO
 
typedef void(* pfPaint) (const BUTTON_INFO *infoPtr, HDC hdc, UINT action)
 
typedef void(* pfThemedPaint) (HTHEME theme, const BUTTON_INFO *infoPtr, HDC hdc, ButtonState drawState, UINT dtflags, BOOL focused)
 

Enumerations

enum  ButtonState {
  STATE_NORMAL , STATE_DISABLED , STATE_HOT , STATE_PRESSED ,
  STATE_DEFAULTED
}
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (button)
 
static UINT BUTTON_CalcLabelRect (const BUTTON_INFO *infoPtr, HDC hdc, RECT *rc)
 
static void PB_Paint (const BUTTON_INFO *infoPtr, HDC hDC, UINT action)
 
static void CB_Paint (const BUTTON_INFO *infoPtr, HDC hDC, UINT action)
 
static void GB_Paint (const BUTTON_INFO *infoPtr, HDC hDC, UINT action)
 
static void UB_Paint (const BUTTON_INFO *infoPtr, HDC hDC, UINT action)
 
static void OB_Paint (const BUTTON_INFO *infoPtr, HDC hDC, UINT action)
 
static void BUTTON_CheckAutoRadioButton (HWND hwnd)
 
static void PB_ThemedPaint (HTHEME theme, const BUTTON_INFO *infoPtr, HDC hdc, ButtonState drawState, UINT dtflags, BOOL focused)
 
static void CB_ThemedPaint (HTHEME theme, const BUTTON_INFO *infoPtr, HDC hdc, ButtonState drawState, UINT dtflags, BOOL focused)
 
static void GB_ThemedPaint (HTHEME theme, const BUTTON_INFO *infoPtr, HDC hdc, ButtonState drawState, UINT dtflags, BOOL focused)
 
static UINT get_button_type (LONG window_style)
 
static void paint_button (BUTTON_INFO *infoPtr, LONG style, UINT action)
 
static WCHARget_button_text (const BUTTON_INFO *infoPtr)
 
HRGN set_control_clipping (HDC hdc, const RECT *rect)
 
static UINT BUTTON_BStoDT (DWORD style, DWORD ex_style)
 
static LRESULT CALLBACK BUTTON_WindowProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
static BOOL CALLBACK BUTTON_DrawTextCallback (HDC hdc, LPARAM lp, WPARAM wp, int cx, int cy)
 
static void BUTTON_DrawLabel (const BUTTON_INFO *infoPtr, HDC hdc, UINT dtFlags, const RECT *rc)
 
void BUTTON_Register (void)
 

Variables

static const WORD maxCheckState [MAX_BTN_TYPE]
 
static const pfPaint btnPaintFunc [MAX_BTN_TYPE]
 
static const pfThemedPaint btnThemedPaintFunc [MAX_BTN_TYPE]
 

Macro Definition Documentation

◆ BUTTON_BTNPRESSED

#define BUTTON_BTNPRESSED   0x40

Definition at line 78 of file button.c.

◆ BUTTON_NOTIFY_PARENT

#define BUTTON_NOTIFY_PARENT (   hWnd,
  code 
)
Value:
do { /* Notify parent which has created this button control */ \
TRACE("notification " #code " sent to hwnd=%p\n", GetParent(hWnd)); \
SendMessageW(GetParent(hWnd), WM_COMMAND, \
(LPARAM)(hWnd)); \
} while(0)
HWND hWnd
Definition: settings.c:17
Definition: inflate.c:139
LONG_PTR LPARAM
Definition: windef.h:208
#define MAKEWPARAM(l, h)
Definition: winuser.h:3999
#define GetWindowLongPtrW
Definition: winuser.h:4819
#define WM_COMMAND
Definition: winuser.h:1730
HWND WINAPI GetParent(_In_ HWND)
#define GWLP_ID
Definition: winuser.h:854

Definition at line 85 of file button.c.

◆ BUTTON_NSTATES

#define BUTTON_NSTATES   0x0F

Definition at line 77 of file button.c.

◆ BUTTON_UNKNOWN2

#define BUTTON_UNKNOWN2   0x20

Definition at line 79 of file button.c.

◆ BUTTON_UNKNOWN3

#define BUTTON_UNKNOWN3   0x10

Definition at line 80 of file button.c.

◆ MAX_BTN_TYPE

#define MAX_BTN_TYPE   16

Definition at line 120 of file button.c.

◆ OEMRESOURCE

#define OEMRESOURCE

Definition at line 61 of file button.c.

Typedef Documentation

◆ BUTTON_INFO

◆ pfPaint

typedef void(* pfPaint) (const BUTTON_INFO *infoPtr, HDC hdc, UINT action)

Definition at line 152 of file button.c.

◆ pfThemedPaint

typedef void(* pfThemedPaint) (HTHEME theme, const BUTTON_INFO *infoPtr, HDC hdc, ButtonState drawState, UINT dtflags, BOOL focused)

Definition at line 183 of file button.c.

Enumeration Type Documentation

◆ ButtonState

Enumerator
STATE_NORMAL 
STATE_DISABLED 
STATE_HOT 
STATE_PRESSED 
STATE_DEFAULTED 

Definition at line 143 of file button.c.

144{
147 STATE_HOT,
ButtonState
Definition: button.c:144
@ STATE_PRESSED
Definition: button.c:148
@ STATE_DEFAULTED
Definition: button.c:149
@ STATE_DISABLED
Definition: button.c:146
@ STATE_NORMAL
Definition: button.c:145
@ STATE_HOT
Definition: button.c:147

Function Documentation

◆ BUTTON_BStoDT()

static UINT BUTTON_BStoDT ( DWORD  style,
DWORD  ex_style 
)
static

Definition at line 262 of file button.c.

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 */
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}
Arabic default style
Definition: afstyles.h:94
static UINT get_button_type(LONG window_style)
Definition: button.c:211
unsigned int UINT
Definition: ndis.h:50
#define BS_GROUPBOX
Definition: pedump.c:658
#define BS_DEFPUSHBUTTON
Definition: pedump.c:652
#define DT_CENTER
Definition: winuser.h:527
#define BS_RIGHT
Definition: winuser.h:274
#define BS_PUSHLIKE
Definition: winuser.h:272
#define DT_SINGLELINE
Definition: winuser.h:540
#define BS_BOTTOM
Definition: winuser.h:259
#define DT_NOCLIP
Definition: winuser.h:536
#define BS_MULTILINE
Definition: winuser.h:267
#define DT_LEFT
Definition: winuser.h:534
#define BS_LEFT
Definition: winuser.h:265
#define DT_WORDBREAK
Definition: winuser.h:544
#define BS_VCENTER
Definition: winuser.h:279
#define BS_TOP
Definition: winuser.h:277
#define DT_VCENTER
Definition: winuser.h:543
#define DT_BOTTOM
Definition: winuser.h:525
#define DT_RIGHT
Definition: winuser.h:538
#define BS_CENTER
Definition: winuser.h:260
#define WS_EX_RIGHT
Definition: winuser.h:400

Referenced by BUTTON_CalcLabelRect(), and BUTTON_WindowProc().

◆ BUTTON_CalcLabelRect()

static UINT BUTTON_CalcLabelRect ( const BUTTON_INFO infoPtr,
HDC  hdc,
RECT rc 
)
static

Definition at line 1184 of file button.c.

1185{
1186 LONG style = GetWindowLongW( infoPtr->hwnd, GWL_STYLE );
1187 LONG ex_style = GetWindowLongW( infoPtr->hwnd, GWL_EXSTYLE );
1188 WCHAR *text;
1189 ICONINFO iconInfo;
1190 BITMAP bm;
1191 UINT dtStyle = BUTTON_BStoDT( style, ex_style );
1192 RECT r = *rc;
1193 INT n;
1194#ifdef __REACTOS__
1195 BOOL bHasIml = BUTTON_DrawIml(hdc, &infoPtr->imlData, &r, TRUE, 0);
1196#endif
1197
1198 /* Calculate label rectangle according to label type */
1199 switch (style & (BS_ICON|BS_BITMAP))
1200 {
1201 case BS_TEXT:
1202 {
1203 HFONT hFont, hPrevFont = 0;
1204
1205 if (!(text = get_button_text( infoPtr ))) goto empty_rect;
1206 if (!text[0])
1207 {
1208 heap_free( text );
1209 goto empty_rect;
1210 }
1211
1212 if ((hFont = infoPtr->font)) hPrevFont = SelectObject( hdc, hFont );
1213#ifdef __REACTOS__
1214 DrawTextW(hdc, text, -1, &r, ((dtStyle | DT_CALCRECT) & ~(DT_VCENTER | DT_BOTTOM)));
1215#else
1216 DrawTextW(hdc, text, -1, &r, dtStyle | DT_CALCRECT);
1217#endif
1218 if (hPrevFont) SelectObject( hdc, hPrevFont );
1219 heap_free( text );
1220#ifdef __REACTOS__
1221 if (infoPtr->ui_state & UISF_HIDEACCEL)
1222 dtStyle |= DT_HIDEPREFIX;
1223#endif
1224 break;
1225 }
1226
1227 case BS_ICON:
1228 if (!GetIconInfo(infoPtr->u.icon, &iconInfo))
1229 goto empty_rect;
1230
1231 GetObjectW (iconInfo.hbmColor, sizeof(BITMAP), &bm);
1232
1233 r.right = r.left + bm.bmWidth;
1234 r.bottom = r.top + bm.bmHeight;
1235
1236 DeleteObject(iconInfo.hbmColor);
1237 DeleteObject(iconInfo.hbmMask);
1238 break;
1239
1240 case BS_BITMAP:
1241 if (!GetObjectW( infoPtr->u.bitmap, sizeof(BITMAP), &bm))
1242 goto empty_rect;
1243
1244 r.right = r.left + bm.bmWidth;
1245 r.bottom = r.top + bm.bmHeight;
1246 break;
1247
1248 default:
1249 empty_rect:
1250#ifdef __REACTOS__
1251 if (bHasIml)
1252 break;
1253#endif
1254 rc->right = r.left;
1255 rc->bottom = r.top;
1256 return (UINT)-1;
1257 }
1258
1259#ifdef __REACTOS__
1260 if (bHasIml)
1261 {
1262 if (infoPtr->imlData.uAlign == BUTTON_IMAGELIST_ALIGN_LEFT)
1263 r.left = infoPtr->imlData.margin.left;
1264 else if (infoPtr->imlData.uAlign == BUTTON_IMAGELIST_ALIGN_RIGHT)
1265 r.right = infoPtr->imlData.margin.right;
1266 else if (infoPtr->imlData.uAlign == BUTTON_IMAGELIST_ALIGN_TOP)
1267 r.top = infoPtr->imlData.margin.top;
1268 else if (infoPtr->imlData.uAlign == BUTTON_IMAGELIST_ALIGN_BOTTOM)
1269 r.bottom = infoPtr->imlData.margin.bottom;
1270 }
1271#endif
1272
1273 /* Position label inside bounding rectangle according to
1274 * alignment flags. (calculated rect is always left-top aligned).
1275 * If label is aligned to any side - shift label in opposite
1276 * direction to leave extra space for focus rectangle.
1277 */
1278 switch (dtStyle & (DT_CENTER|DT_RIGHT))
1279 {
1280 case DT_LEFT: r.left++; r.right++; break;
1281 case DT_CENTER: n = r.right - r.left;
1282 r.left = rc->left + ((rc->right - rc->left) - n) / 2;
1283 r.right = r.left + n; break;
1284 case DT_RIGHT: n = r.right - r.left;
1285 r.right = rc->right - 1;
1286 r.left = r.right - n;
1287 break;
1288 }
1289
1290 switch (dtStyle & (DT_VCENTER|DT_BOTTOM))
1291 {
1292 case DT_TOP: r.top++; r.bottom++; break;
1293 case DT_VCENTER: n = r.bottom - r.top;
1294#ifdef __REACTOS__
1295 r.top = rc->top + ((rc->bottom - 1 - rc->top) - n) / 2;
1296#else
1297 r.top = rc->top + ((rc->bottom - rc->top) - n) / 2;
1298#endif
1299 r.bottom = r.top + n; break;
1300 case DT_BOTTOM: n = r.bottom - r.top;
1301 r.bottom = rc->bottom - 1;
1302 r.top = r.bottom - n;
1303 break;
1304 }
1305
1306 *rc = r;
1307 return dtStyle;
1308}
static BOOL heap_free(void *mem)
Definition: appwiz.h:75
HFONT hFont
Definition: main.c:53
#define TRUE
Definition: types.h:120
static UINT BUTTON_BStoDT(DWORD style, DWORD ex_style)
Definition: button.c:262
static WCHAR * get_button_text(const BUTTON_INFO *infoPtr)
Definition: button.c:230
const WCHAR * text
Definition: package.c:1799
unsigned int BOOL
Definition: ntddk_ex.h:94
pKey DeleteObject()
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLdouble n
Definition: glext.h:7729
HDC hdc
Definition: main.c:9
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
INT WINAPI DrawTextW(HDC hdc, LPCWSTR str, INT count, LPRECT rect, UINT flags)
Definition: defwnd.c:17
long LONG
Definition: pedump.c:60
#define BUTTON_IMAGELIST_ALIGN_TOP
Definition: commctrl.h:4629
#define BUTTON_IMAGELIST_ALIGN_LEFT
Definition: commctrl.h:4627
#define BUTTON_IMAGELIST_ALIGN_RIGHT
Definition: commctrl.h:4628
#define BUTTON_IMAGELIST_ALIGN_BOTTOM
Definition: commctrl.h:4630
Definition: bl.h:1331
HBITMAP bitmap
Definition: button.c:101
union _BUTTON_INFO::@325 u
HWND hwnd
Definition: button.c:95
HICON icon
Definition: button.c:100
HFONT font
Definition: button.c:97
HBITMAP hbmColor
Definition: winuser.h:3117
HBITMAP hbmMask
Definition: winuser.h:3116
LONG right
Definition: windef.h:308
LONG bottom
Definition: windef.h:309
LONG top
Definition: windef.h:307
LONG left
Definition: windef.h:306
int32_t INT
Definition: typedefs.h:58
int WINAPI GetObjectW(_In_ HANDLE h, _In_ int c, _Out_writes_bytes_opt_(c) LPVOID pv)
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1539
#define BS_BITMAP
Definition: winuser.h:258
BOOL WINAPI GetIconInfo(_In_ HICON, _Out_ PICONINFO)
Definition: cursoricon.c:2014
#define BS_ICON
Definition: winuser.h:264
LONG WINAPI GetWindowLongW(_In_ HWND, _In_ int)
#define DT_TOP
Definition: winuser.h:542
#define BS_TEXT
Definition: winuser.h:276
#define DT_CALCRECT
Definition: winuser.h:526
#define DT_HIDEPREFIX
Definition: winuser.h:547
#define GWL_STYLE
Definition: winuser.h:846
#define GWL_EXSTYLE
Definition: winuser.h:845
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by BUTTON_WindowProc(), ButtonWndProc_common(), CB_Paint(), GB_Paint(), and PB_Paint().

◆ BUTTON_CheckAutoRadioButton()

static void BUTTON_CheckAutoRadioButton ( HWND  hwnd)
static

Definition at line 1655 of file button.c.

1656{
1657 HWND parent, sibling, start;
1658
1660 /* make sure that starting control is not disabled or invisible */
1661#ifdef __REACTOS__
1662 start = sibling = hwnd;
1663#else
1664 start = sibling = GetNextDlgGroupItem( parent, hwnd, TRUE );
1665#endif
1666 do
1667 {
1668 if (!sibling) break;
1669#ifdef __REACTOS__
1670 if (SendMessageW( sibling, WM_GETDLGCODE, 0, 0 ) == (DLGC_BUTTON | DLGC_RADIOBUTTON))
1671 SendMessageW( sibling, BM_SETCHECK, sibling == hwnd ? BST_CHECKED : BST_UNCHECKED, 0 );
1672#else
1673 if ((hwnd != sibling) &&
1675 SendMessageW( sibling, BM_SETCHECK, BST_UNCHECKED, 0 );
1676#endif
1677 sibling = GetNextDlgGroupItem( parent, sibling, FALSE );
1678 } while (sibling != start);
1679}
#define FALSE
Definition: types.h:117
r parent
Definition: btrfs.c:3010
GLuint start
Definition: gl.h:1545
#define BS_AUTORADIOBUTTON
Definition: pedump.c:660
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
#define DLGC_BUTTON
Definition: winuser.h:2610
#define BST_UNCHECKED
Definition: winuser.h:199
#define BS_TYPEMASK
Definition: winuser.h:270
#define BM_SETCHECK
Definition: winuser.h:1911
HWND WINAPI GetNextDlgGroupItem(_In_ HWND, _In_opt_ HWND, _In_ BOOL)
#define DLGC_RADIOBUTTON
Definition: winuser.h:2607
#define WM_GETDLGCODE
Definition: winuser.h:1679
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define BST_CHECKED
Definition: winuser.h:197

Referenced by BUTTON_WindowProc(), and ButtonWndProc_common().

◆ BUTTON_DrawLabel()

static void BUTTON_DrawLabel ( const BUTTON_INFO infoPtr,
HDC  hdc,
UINT  dtFlags,
const RECT rc 
)
static

Definition at line 1331 of file button.c.

1332{
1333 DRAWSTATEPROC lpOutputProc = NULL;
1334 LPARAM lp;
1335 WPARAM wp = 0;
1336 HBRUSH hbr = 0;
1338 LONG state = infoPtr->state;
1339 LONG style = GetWindowLongW( infoPtr->hwnd, GWL_STYLE );
1340 WCHAR *text = NULL;
1341
1342 /* FIXME: To draw disabled label in Win31 look-and-feel, we probably
1343 * must use DSS_MONO flag and COLOR_GRAYTEXT brush (or maybe DSS_UNION).
1344 * I don't have Win31 on hand to verify that, so I leave it as is.
1345 */
1346
1347#ifdef __REACTOS__
1348 RECT rcText = *rc;
1349 BUTTON_DrawIml(hdc, &infoPtr->imlData, &rcText, FALSE, 0);
1350#endif
1351
1353 {
1355 flags |= DSS_MONO;
1356 }
1357
1358 switch (style & (BS_ICON|BS_BITMAP))
1359 {
1360 case BS_TEXT:
1361 /* DST_COMPLEX -- is 0 */
1362 lpOutputProc = BUTTON_DrawTextCallback;
1363 if (!(text = get_button_text( infoPtr ))) return;
1364 lp = (LPARAM)text;
1365 wp = dtFlags;
1366#ifdef __REACTOS__
1367 if (dtFlags & DT_HIDEPREFIX)
1369#endif
1370 break;
1371
1372 case BS_ICON:
1373 flags |= DST_ICON;
1374 lp = (LPARAM)infoPtr->u.icon;
1375 break;
1376
1377 case BS_BITMAP:
1378 flags |= DST_BITMAP;
1379 lp = (LPARAM)infoPtr->u.bitmap;
1380 break;
1381
1382 default:
1383 return;
1384 }
1385
1386#ifdef __REACTOS__
1387 DrawStateW(hdc, hbr, lpOutputProc, lp, wp, rcText.left, rcText.top,
1388 rcText.right - rcText.left, rcText.bottom - rcText.top, flags);
1389#else
1390 DrawStateW(hdc, hbr, lpOutputProc, lp, wp, rc->left, rc->top,
1391 rc->right - rc->left, rc->bottom - rc->top, flags);
1392#endif
1393 heap_free( text );
1394}
static int state
Definition: maze.c:121
#define NULL
Definition: types.h:112
static BOOL CALLBACK BUTTON_DrawTextCallback(HDC hdc, LPARAM lp, WPARAM wp, int cx, int cy)
Definition: button.c:1316
GLbitfield flags
Definition: glext.h:7161
LONG state
Definition: button.c:96
UINT_PTR WPARAM
Definition: windef.h:207
#define BST_INDETERMINATE
Definition: winuser.h:198
#define COLOR_GRAYTEXT
Definition: winuser.h:926
#define DSS_DISABLED
Definition: winuser.h:519
HBRUSH WINAPI GetSysColorBrush(_In_ int)
#define DST_ICON
Definition: winuser.h:515
#define DST_BITMAP
Definition: winuser.h:516
BOOL WINAPI IsWindowEnabled(_In_ HWND)
#define DSS_NORMAL
Definition: winuser.h:517
#define DSS_HIDEPREFIX
Definition: winuser.h:522
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)
BOOL(CALLBACK * DRAWSTATEPROC)(HDC, LPARAM, WPARAM, int, int)
Definition: winuser.h:2897
#define DSS_MONO
Definition: winuser.h:521

Referenced by CB_Paint(), GB_Paint(), and PB_Paint().

◆ BUTTON_DrawTextCallback()

static BOOL CALLBACK BUTTON_DrawTextCallback ( HDC  hdc,
LPARAM  lp,
WPARAM  wp,
int  cx,
int  cy 
)
static

Definition at line 1316 of file button.c.

1317{
1318 RECT rc;
1319
1320 SetRect(&rc, 0, 0, cx, cy);
1321 DrawTextW(hdc, (LPCWSTR)lp, -1, &rc, (UINT)wp);
1322 return TRUE;
1323}
_Out_opt_ int _Out_opt_ int * cy
Definition: commctrl.h:586
_Out_opt_ int * cx
Definition: commctrl.h:585
BOOL WINAPI SetRect(_Out_ LPRECT, _In_ int, _In_ int, _In_ int, _In_ int)
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

Referenced by BUTTON_DrawLabel().

◆ BUTTON_Register()

void BUTTON_Register ( void  )

Definition at line 2129 of file button.c.

2130{
2131 WNDCLASSW wndClass;
2132
2133 memset(&wndClass, 0, sizeof(wndClass));
2135 wndClass.lpfnWndProc = BUTTON_WindowProc;
2136 wndClass.cbClsExtra = 0;
2137 wndClass.cbWndExtra = sizeof(BUTTON_INFO *);
2138 wndClass.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
2139 wndClass.hbrBackground = NULL;
2140 wndClass.lpszClassName = WC_BUTTONW;
2141 RegisterClassW(&wndClass);
2142}
static LRESULT CALLBACK BUTTON_WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: button.c:587
#define WC_BUTTONW
Definition: commctrl.h:4623
#define memset(x, y, z)
Definition: compat.h:39
LPCWSTR lpszClassName
Definition: winuser.h:3175
HBRUSH hbrBackground
Definition: winuser.h:3173
int cbClsExtra
Definition: winuser.h:3168
UINT style
Definition: winuser.h:3166
WNDPROC lpfnWndProc
Definition: winuser.h:3167
int cbWndExtra
Definition: winuser.h:3169
HCURSOR hCursor
Definition: winuser.h:3172
#define CS_VREDRAW
Definition: winuser.h:653
#define CS_HREDRAW
Definition: winuser.h:648
ATOM WINAPI RegisterClassW(_In_ CONST WNDCLASSW *)
#define IDC_ARROW
Definition: winuser.h:682
#define CS_DBLCLKS
Definition: winuser.h:646
HCURSOR WINAPI LoadCursorW(_In_opt_ HINSTANCE, _In_ LPCWSTR)
Definition: cursoricon.c:2074
#define CS_GLOBALCLASS
Definition: winuser.h:647
#define CS_PARENTDC
Definition: winuser.h:651
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by DllMain().

◆ BUTTON_WindowProc()

static LRESULT CALLBACK BUTTON_WindowProc ( HWND  hWnd,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 587 of file button.c.

588{
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:
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 {
655 style = (style & ~BS_TYPEMASK) | BS_PUSHBUTTON;
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 {
776 break;
777 }
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;
788#ifdef __REACTOS__
790#else
792#endif
793 break;
794 case BS_AUTO3STATE:
796 ((infoPtr->state & 3) + 1), 0 );
797 break;
798 }
799#ifdef __REACTOS__
800 // Fix CORE-10194, Notify parent after capture is released.
803#else
806#endif
807 }
808 else
809 {
811 }
812
813 break;
814
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
851 {
852 mouse_event.dwFlags = TME_LEAVE;
853 mouse_event.hwndTrack = hWnd;
854 mouse_event.dwHoverTime = 1;
856 }
857#else
858
859 if (!TrackMouseEvent(&mouse_event) || !(mouse_event.dwFlags & (TME_HOVER | TME_LEAVE)))
860 {
861 mouse_event.dwFlags = TME_HOVER | TME_LEAVE;
862 mouse_event.hwndTrack = hWnd;
863 mouse_event.dwHoverTime = 1;
865 }
866#endif
867
868 if ((wParam & MK_LBUTTON) && GetCapture() == hWnd)
869 {
872 }
873 break;
874 }
875
876#ifndef __REACTOS__
877 case WM_MOUSEHOVER:
878 {
879 infoPtr->state |= BST_HOT;
881 break;
882 }
883#endif
884
885 case WM_MOUSELEAVE:
886 {
887#ifdef __REACTOS__
888 if (infoPtr->state & BST_HOT)
889 {
890 NMBCHOTITEM nmhotitem;
891
892 infoPtr->state &= ~BST_HOT;
893
894 nmhotitem.hdr.hwndFrom = hWnd;
895 nmhotitem.hdr.idFrom = GetWindowLongPtrW (hWnd, GWLP_ID);
896 nmhotitem.hdr.code = BCN_HOTITEMCHANGE;
897 nmhotitem.dwFlags = HICF_LEAVING;
898 SendMessageW(GetParent(hWnd), WM_NOTIFY, nmhotitem.hdr.idFrom, (LPARAM)&nmhotitem);
899
900 theme = GetWindowTheme( hWnd );
901 if (theme)
903 }
904 break;
905#else
906 infoPtr->state &= ~BST_HOT;
908 break;
909#endif
910 }
911
912#ifdef __REACTOS__
914 {
915 RECT* prc = (RECT*)lParam;
916 if (!prc)
917 return FALSE;
918 *prc = infoPtr->rcTextMargin;
919 return TRUE;
920 }
922 {
923 RECT* prc = (RECT*)lParam;
924 if (!prc)
925 return FALSE;
926 infoPtr->rcTextMargin = *prc;
927 return TRUE;
928 }
929 case BCM_SETIMAGELIST:
930 {
932 if (!pimldata || !pimldata->himl)
933 return FALSE;
934 infoPtr->imlData = *pimldata;
935 return TRUE;
936 }
937 case BCM_GETIMAGELIST:
938 {
940 if (!pimldata)
941 return FALSE;
942 *pimldata = infoPtr->imlData;
943 return TRUE;
944 }
945 case BCM_GETIDEALSIZE:
946 {
947 HTHEME theme = GetWindowTheme(hWnd);
948 BOOL ret = FALSE;
949 SIZE* pSize = (SIZE*)lParam;
950
951 if (!pSize)
952 {
953 return FALSE;
954 }
955
956 if (btn_type == BS_PUSHBUTTON ||
957 btn_type == BS_DEFPUSHBUTTON ||
958 btn_type == BS_USERBUTTON)
959 {
960 ret = BUTTON_GetIdealSize(infoPtr, theme, pSize);
961 }
962
963 if (!ret)
964 {
966 pSize->cx = rect.right;
967 pSize->cy = rect.bottom;
968 }
969
970 return TRUE;
971 }
972#endif
973
974 case WM_SETTEXT:
975 {
976 /* Clear an old text here as Windows does */
977#ifdef __REACTOS__
978//
979// ReactOS Note :
980// wine Bug: http://bugs.winehq.org/show_bug.cgi?id=25790
981// Patch: http://source.winehq.org/patches/data/70889
982// By: Alexander LAW, Replicate Windows behavior of WM_SETTEXT handler regarding WM_CTLCOLOR*
983//
984 if (style & WS_VISIBLE)
985#else
987#endif
988 {
989 HDC hdc = GetDC(hWnd);
990 HBRUSH hbrush;
991 RECT client, rc;
993 UINT message = (btn_type == BS_PUSHBUTTON ||
994 btn_type == BS_DEFPUSHBUTTON ||
995 btn_type == BS_USERBUTTON ||
996 btn_type == BS_OWNERDRAW) ?
998
999 if (!parent) parent = hWnd;
1000 hbrush = (HBRUSH)SendMessageW(parent, message,
1001 (WPARAM)hdc, (LPARAM)hWnd);
1002 if (!hbrush) /* did the app forget to call DefWindowProc ? */
1004 (WPARAM)hdc, (LPARAM)hWnd);
1005
1007 rc = client;
1008 /* FIXME: check other BS_* handlers */
1009 if (btn_type == BS_GROUPBOX)
1010 InflateRect(&rc, -7, 1); /* GB_Paint does this */
1011 BUTTON_CalcLabelRect(infoPtr, hdc, &rc);
1012 /* Clip by client rect bounds */
1013 if (rc.right > client.right) rc.right = client.right;
1014 if (rc.bottom > client.bottom) rc.bottom = client.bottom;
1015 FillRect(hdc, &rc, hbrush);
1016 ReleaseDC(hWnd, hdc);
1017 }
1018
1020 if (btn_type == BS_GROUPBOX) /* Yes, only for BS_GROUPBOX */
1022 else
1023 paint_button( infoPtr, btn_type, ODA_DRAWENTIRE );
1024 return 1; /* success. FIXME: check text length */
1025 }
1026
1027 case WM_SETFONT:
1028 infoPtr->font = (HFONT)wParam;
1030 break;
1031
1032 case WM_GETFONT:
1033 return (LRESULT)infoPtr->font;
1034
1035 case WM_SETFOCUS:
1036 TRACE("WM_SETFOCUS %p\n",hWnd);
1037 infoPtr->state |= BST_FOCUS;
1038#ifdef __REACTOS__
1039 if (btn_type != BS_OWNERDRAW)
1041 else
1042#endif
1043 paint_button( infoPtr, btn_type, ODA_FOCUS );
1044 if (style & BS_NOTIFY)
1046 break;
1047
1048 case WM_KILLFOCUS:
1049 TRACE("WM_KILLFOCUS %p\n",hWnd);
1050 infoPtr->state &= ~BST_FOCUS;
1051#ifndef __REACTOS__
1052 paint_button( infoPtr, btn_type, ODA_FOCUS );
1053#endif
1054
1055 if ((infoPtr->state & BUTTON_BTNPRESSED) && GetCapture() == hWnd)
1057 if (style & BS_NOTIFY)
1059
1061 break;
1062
1063 case WM_SYSCOLORCHANGE:
1065 break;
1066
1067 case BM_SETSTYLE:
1068 btn_type = wParam & BS_TYPEMASK;
1069 style = (style & ~BS_TYPEMASK) | btn_type;
1071
1072 /* Only redraw if lParam flag is set.*/
1073 if (lParam)
1075
1076 break;
1077
1078 case BM_CLICK:
1079#ifdef __REACTOS__
1080 /* Fix for core CORE-6024 */
1081 if (infoPtr->state & BUTTON_BMCLICK)
1082 break;
1083 infoPtr->state |= BUTTON_BMCLICK;
1084#endif
1086 SendMessageW( hWnd, WM_LBUTTONUP, 0, 0 );
1087#ifdef __REACTOS__
1088 infoPtr->state &= ~BUTTON_BMCLICK;
1089#endif
1090 break;
1091
1092 case BM_SETIMAGE:
1093 /* Check that image format matches button style */
1094 switch (style & (BS_BITMAP|BS_ICON))
1095 {
1096 case BS_BITMAP:
1097 if (wParam != IMAGE_BITMAP) return 0;
1098 break;
1099 case BS_ICON:
1100 if (wParam != IMAGE_ICON) return 0;
1101 break;
1102 default:
1103 return 0;
1104 }
1105 oldHbitmap = infoPtr->u.image;
1106 infoPtr->u.image = (HANDLE)lParam;
1108 return (LRESULT)oldHbitmap;
1109
1110 case BM_GETIMAGE:
1111 return (LRESULT)infoPtr->u.image;
1112
1113 case BM_GETCHECK:
1114 return infoPtr->state & 3;
1115
1116 case BM_SETCHECK:
1117 if (wParam > maxCheckState[btn_type]) wParam = maxCheckState[btn_type];
1118 if ((btn_type == BS_RADIOBUTTON) || (btn_type == BS_AUTORADIOBUTTON))
1119 {
1120 style = wParam ? style | WS_TABSTOP : style & ~WS_TABSTOP;
1122 }
1123 if ((infoPtr->state & 3) != wParam)
1124 {
1125 infoPtr->state = (infoPtr->state & ~3) | wParam;
1127 }
1128#ifndef __REACTOS__
1129 if ((btn_type == BS_AUTORADIOBUTTON) && (wParam == BST_CHECKED) && (style & WS_CHILD))
1131#endif
1132 break;
1133
1134 case BM_GETSTATE:
1135 return infoPtr->state;
1136
1137 case BM_SETSTATE:
1138 state = infoPtr->state;
1139 new_state = wParam ? BST_PUSHED : 0;
1140
1141 if ((state ^ new_state) & BST_PUSHED)
1142 {
1143 if (wParam)
1144 state |= BST_PUSHED;
1145 else
1146 state &= ~BST_PUSHED;
1147
1148 if (btn_type == BS_USERBUTTON)
1150 infoPtr->state = state;
1151
1153 }
1154 break;
1155
1156#ifdef __REACTOS__
1157 case WM_UPDATEUISTATE:
1159
1160 if (button_update_uistate(infoPtr))
1161 paint_button( infoPtr, btn_type, ODA_DRAWENTIRE );
1162 break;
1163#endif
1164
1165 case WM_NCHITTEST:
1166 if(btn_type == BS_GROUPBOX) return HTTRANSPARENT;
1167 /* fall through */
1168 default:
1169 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
1170 }
1171 return 0;
1172}
static HBRUSH hbrush
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
static const pfThemedPaint btnThemedPaintFunc[MAX_BTN_TYPE]
Definition: button.c:191
#define BUTTON_NSTATES
Definition: button.c:77
#define BUTTON_NOTIFY_PARENT(hWnd, code)
Definition: button.c:85
static const pfPaint btnPaintFunc[MAX_BTN_TYPE]
Definition: button.c:154
static UINT BUTTON_CalcLabelRect(const BUTTON_INFO *infoPtr, HDC hdc, RECT *rc)
Definition: button.c:1184
static void paint_button(BUTTON_INFO *infoPtr, LONG style, UINT action)
Definition: button.c:218
#define BUTTON_BTNPRESSED
Definition: button.c:78
static const WORD maxCheckState[MAX_BTN_TYPE]
Definition: button.c:122
#define MAX_BTN_TYPE
Definition: button.c:120
static void BUTTON_CheckAutoRadioButton(HWND hwnd)
Definition: button.c:1655
HTHEME WINAPI OpenThemeData(HWND hwnd, LPCWSTR classlist)
Definition: system.c:835
HTHEME WINAPI GetWindowTheme(HWND hwnd)
Definition: system.c:851
HRESULT WINAPI CloseThemeData(HTHEME hTheme)
Definition: system.c:950
unsigned short(__cdecl typeof(TIFFCurrentDirectory))(struct tiff *)
Definition: typeof.h:94
#define pt(x, y)
Definition: drawing.c:79
static HDC
Definition: imagelist.c:92
static HTHEME(WINAPI *pOpenThemeDataEx)(HWND
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
_Out_ LPRECT prc
Definition: ntgdi.h:1658
#define LOWORD(l)
Definition: pedump.c:82
#define WS_CHILD
Definition: pedump.c:617
#define BS_USERBUTTON
Definition: pedump.c:659
#define WS_TABSTOP
Definition: pedump.c:634
#define WS_VISIBLE
Definition: pedump.c:620
#define BS_AUTOCHECKBOX
Definition: pedump.c:654
#define BS_OWNERDRAW
Definition: pedump.c:661
#define BS_AUTO3STATE
Definition: pedump.c:657
#define BS_RADIOBUTTON
Definition: pedump.c:655
#define BS_PUSHBUTTON
Definition: pedump.c:651
#define BST_HOT
Definition: commctrl.h:4668
#define TME_LEAVE
Definition: commctrl.h:4981
#define BS_SPLITBUTTON
Definition: commctrl.h:4670
#define BS_DEFCOMMANDLINK
Definition: commctrl.h:4673
#define BCM_GETIDEALSIZE
Definition: commctrl.h:4639
#define BCM_SETIMAGELIST
Definition: commctrl.h:4642
#define BCN_HOTITEMCHANGE
Definition: commctrl.h:260
#define BCM_SETTEXTMARGIN
Definition: commctrl.h:4648
#define WM_MOUSELEAVE
Definition: commctrl.h:4975
#define BS_DEFSPLITBUTTON
Definition: commctrl.h:4671
#define HICF_ENTERING
Definition: commctrl.h:1330
struct tagTRACKMOUSEEVENT TRACKMOUSEEVENT
#define HICF_LEAVING
Definition: commctrl.h:1331
#define WM_MOUSEHOVER
Definition: commctrl.h:4974
#define TME_QUERY
Definition: commctrl.h:4983
#define BS_COMMANDLINK
Definition: commctrl.h:4672
#define TME_HOVER
Definition: commctrl.h:4980
#define BCM_GETTEXTMARGIN
Definition: commctrl.h:4650
#define BCM_GETIMAGELIST
Definition: commctrl.h:4645
#define WM_PRINTCLIENT
Definition: richedit.h:70
#define WM_NOTIFY
Definition: richedit.h:61
static FILE * client
Definition: client.c:41
#define TRACE(s)
Definition: solgame.cpp:4
& rect
Definition: startmenu.cpp:1413
HIMAGELIST himl
Definition: commctrl.h:4634
HANDLE image
Definition: button.c:102
LONG cx
Definition: kdterminal.h:27
LONG cy
Definition: kdterminal.h:28
Definition: tftpd.h:60
UINT_PTR idFrom
Definition: winuser.h:3148
UINT code
Definition: winuser.h:3149
HWND hwndFrom
Definition: winuser.h:3147
PVOID HANDLE
Definition: typedefs.h:73
#define HIWORD(l)
Definition: typedefs.h:247
int ret
LONG_PTR LRESULT
Definition: windef.h:209
#define OPAQUE
Definition: wingdi.h:949
int WINAPI FillRect(HDC, LPCRECT, HBRUSH)
int WINAPI SetBkMode(_In_ HDC, _In_ int)
Definition: dc.c:1056
#define WM_PAINT
Definition: winuser.h:1610
HWND WINAPI SetCapture(_In_ HWND hWnd)
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
#define WM_ERASEBKGND
Definition: winuser.h:1615
BOOL WINAPI IsWindow(_In_opt_ HWND)
#define WM_CTLCOLORSTATIC
Definition: winuser.h:1762
#define BM_GETSTATE
Definition: winuser.h:1910
BOOL WINAPI RedrawWindow(_In_opt_ HWND, _In_opt_ LPCRECT, _In_opt_ HRGN, _In_ UINT)
void WINAPI mouse_event(_In_ DWORD, _In_ DWORD, _In_ DWORD, _In_ DWORD, _In_ ULONG_PTR)
#define IMAGE_BITMAP
Definition: winuser.h:211
#define WM_ENABLE
Definition: winuser.h:1605
#define WM_KEYUP
Definition: winuser.h:1706
BOOL WINAPI ReleaseCapture(void)
Definition: message.c:2890
#define ODA_DRAWENTIRE
Definition: winuser.h:2532
LRESULT WINAPI DefWindowProcW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define BN_DOUBLECLICKED
Definition: winuser.h:1918
#define IMAGE_ICON
Definition: winuser.h:212
#define BN_SETFOCUS
Definition: winuser.h:1923
#define WM_CAPTURECHANGED
Definition: winuser.h:1798
#define WM_CREATE
Definition: winuser.h:1598
#define VK_SPACE
Definition: winuser.h:2209
#define BM_SETSTATE
Definition: winuser.h:1913
LONG WINAPI SetWindowLongW(_In_ HWND, _In_ int, _In_ LONG)
#define WM_LBUTTONDBLCLK
Definition: winuser.h:1768
#define ODA_FOCUS
Definition: winuser.h:2534
#define DLGC_UNDEFPUSHBUTTON
Definition: winuser.h:2606
#define WM_NCHITTEST
Definition: winuser.h:1676
#define BN_KILLFOCUS
Definition: winuser.h:1920
#define WM_SETFOCUS
Definition: winuser.h:1603
#define BN_HILITE
Definition: winuser.h:1919
#define WM_MOUSEMOVE
Definition: winuser.h:1765
#define RDW_UPDATENOW
Definition: winuser.h:1210
HWND WINAPI GetCapture(void)
Definition: message.c:2881
#define BS_NOTIFY
Definition: winuser.h:268
BOOL WINAPI TrackMouseEvent(_Inout_ LPTRACKMOUSEEVENT)
#define WM_LBUTTONDOWN
Definition: winuser.h:1766
#define WM_SYSCOLORCHANGE
Definition: winuser.h:1616
#define DLGC_DEFPUSHBUTTON
Definition: winuser.h:2605
#define WM_GETFONT
Definition: winuser.h:1641
#define WM_NCCREATE
Definition: winuser.h:1673
#define BM_SETIMAGE
Definition: winuser.h:1912
#define BN_UNHILITE
Definition: winuser.h:1924
#define WM_CTLCOLORBTN
Definition: winuser.h:1759
BOOL WINAPI PtInRect(_In_ LPCRECT, _In_ POINT)
#define WM_SETTEXT
Definition: winuser.h:1607
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
HWND WINAPI SetFocus(_In_opt_ HWND)
#define WM_SETFONT
Definition: winuser.h:1640
#define BM_CLICK
Definition: winuser.h:1907
BOOL WINAPI EndPaint(_In_ HWND, _In_ const PAINTSTRUCT *)
#define DLGC_WANTARROWS
Definition: winuser.h:2600
#define BST_PUSHED
Definition: winuser.h:201
#define BM_GETIMAGE
Definition: winuser.h:1909
#define RDW_FRAME
Definition: winuser.h:1202
#define BM_SETSTYLE
Definition: winuser.h:1914
#define BST_FOCUS
Definition: winuser.h:200
HDC WINAPI GetDC(_In_opt_ HWND)
#define DLGC_STATIC
Definition: winuser.h:2609
#define WM_LBUTTONUP
Definition: winuser.h:1767
#define WM_NCDESTROY
Definition: winuser.h:1674
#define HTTRANSPARENT
Definition: winuser.h:2463
#define MK_LBUTTON
Definition: winuser.h:2357
#define BN_CLICKED
Definition: winuser.h:1915
#define WM_DESTROY
Definition: winuser.h:1599
#define WM_KEYDOWN
Definition: winuser.h:1705
BOOL WINAPI InvalidateRect(_In_opt_ HWND, _In_opt_ LPCRECT, _In_ BOOL)
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)
#define SetWindowLongPtrW
Definition: winuser.h:5336
BOOL WINAPI InflateRect(_Inout_ LPRECT, _In_ int, _In_ int)
BOOL WINAPI IsWindowVisible(_In_ HWND)
#define WM_KILLFOCUS
Definition: winuser.h:1604
#define RDW_INVALIDATE
Definition: winuser.h:1204
#define BM_GETCHECK
Definition: winuser.h:1908

Referenced by BUTTON_Register().

◆ CB_Paint()

static void CB_Paint ( const BUTTON_INFO infoPtr,
HDC  hDC,
UINT  action 
)
static

Definition at line 1522 of file button.c.

1523{
1524 RECT rbox, rtext, client;
1525 HBRUSH hBrush;
1526 int delta, text_offset, checkBoxWidth, checkBoxHeight;
1527 UINT dtFlags;
1528 HFONT hFont;
1529 LONG state = infoPtr->state;
1530 LONG style = GetWindowLongW( infoPtr->hwnd, GWL_STYLE );
1531 LONG ex_style = GetWindowLongW( infoPtr->hwnd, GWL_EXSTYLE );
1532 HWND parent;
1533 HRGN hrgn;
1534
1535 if (style & BS_PUSHLIKE)
1536 {
1537 PB_Paint( infoPtr, hDC, action );
1538 return;
1539 }
1540
1541 GetClientRect(infoPtr->hwnd, &client);
1542 rbox = rtext = client;
1543
1544 checkBoxWidth = 12 * GetDeviceCaps( hDC, LOGPIXELSX ) / 96 + 1;
1545 checkBoxHeight = 12 * GetDeviceCaps( hDC, LOGPIXELSY ) / 96 + 1;
1546
1547 if ((hFont = infoPtr->font)) SelectObject( hDC, hFont );
1548 GetCharWidthW( hDC, '0', '0', &text_offset );
1549 text_offset /= 2;
1550
1551 parent = GetParent(infoPtr->hwnd);
1552 if (!parent) parent = infoPtr->hwnd;
1553 hBrush = (HBRUSH)SendMessageW(parent, WM_CTLCOLORSTATIC, (WPARAM)hDC, (LPARAM)infoPtr->hwnd);
1554 if (!hBrush) /* did the app forget to call defwindowproc ? */
1555 hBrush = (HBRUSH)DefWindowProcW(parent, WM_CTLCOLORSTATIC, (WPARAM)hDC, (LPARAM)infoPtr->hwnd);
1557
1558 if (style & BS_LEFTTEXT || ex_style & WS_EX_RIGHT)
1559 {
1560 rtext.right -= checkBoxWidth + text_offset;
1561 rbox.left = rbox.right - checkBoxWidth;
1562 }
1563 else
1564 {
1565 rtext.left += checkBoxWidth + text_offset;
1566 rbox.right = checkBoxWidth;
1567 }
1568
1569 /* Since WM_ERASEBKGND does nothing, first prepare background */
1570 if (action == ODA_SELECT) FillRect( hDC, &rbox, hBrush );
1571 if (action == ODA_DRAWENTIRE) FillRect( hDC, &client, hBrush );
1572
1573 /* Draw label */
1574 client = rtext;
1575 dtFlags = BUTTON_CalcLabelRect(infoPtr, hDC, &rtext);
1576
1577 /* Only adjust rbox when rtext is valid */
1578 if (dtFlags != (UINT)-1L)
1579 {
1580 rbox.top = rtext.top;
1581 rbox.bottom = rtext.bottom;
1582 }
1583
1584 /* Draw the check-box bitmap */
1586 {
1587 UINT flags;
1588
1592 else flags = DFCS_BUTTONCHECK;
1593
1596
1598
1599 /* rbox must have the correct height */
1600 delta = rbox.bottom - rbox.top - checkBoxHeight;
1601
1602 if (style & BS_TOP) {
1603 if (delta > 0) {
1604 rbox.bottom = rbox.top + checkBoxHeight;
1605 } else {
1606 rbox.top -= -delta/2 + 1;
1607 rbox.bottom = rbox.top + checkBoxHeight;
1608 }
1609 } else if (style & BS_BOTTOM) {
1610 if (delta > 0) {
1611 rbox.top = rbox.bottom - checkBoxHeight;
1612 } else {
1613 rbox.bottom += -delta/2 + 1;
1614 rbox.top = rbox.bottom - checkBoxHeight;
1615 }
1616 } else { /* Default */
1617 if (delta > 0) {
1618 int ofs = (delta / 2);
1619 rbox.bottom -= ofs + 1;
1620 rbox.top = rbox.bottom - checkBoxHeight;
1621 } else if (delta < 0) {
1622 int ofs = (-delta / 2);
1623 rbox.top -= ofs + 1;
1624 rbox.bottom = rbox.top + checkBoxHeight;
1625 }
1626 }
1627
1629 }
1630
1631 if (dtFlags == (UINT)-1L) /* Noting to draw */
1632 return;
1633
1634 if (action == ODA_DRAWENTIRE)
1635 BUTTON_DrawLabel(infoPtr, hDC, dtFlags, &rtext);
1636
1637 /* ... and focus */
1638 if (action == ODA_FOCUS || (state & BST_FOCUS))
1639 {
1640 rtext.left--;
1641 rtext.right++;
1642 IntersectRect(&rtext, &rtext, &client);
1643 DrawFocusRect( hDC, &rtext );
1644 }
1646 if (hrgn) DeleteObject( hrgn );
1647}
static HDC hDC
Definition: 3dtext.c:33
static HRGN hrgn
HRGN set_control_clipping(HDC hdc, const RECT *rect)
Definition: button.c:239
static void BUTTON_DrawLabel(const BUTTON_INFO *infoPtr, HDC hdc, UINT dtFlags, const RECT *rc)
Definition: button.c:1331
static void PB_Paint(const BUTTON_INFO *infoPtr, HDC hDC, UINT action)
Definition: button.c:1399
const WCHAR * action
Definition: action.c:7479
#define BS_LEFTTEXT
Definition: pedump.c:662
#define WS_DISABLED
Definition: pedump.c:621
int WINAPI GetDeviceCaps(_In_opt_ HDC, _In_ int)
BOOL WINAPI GetCharWidthW(_In_ HDC hdc, _In_ UINT iFirst, _In_ UINT iLast, _Out_writes_(iLast+1 - iFirst) LPINT lpBuffer)
#define LOGPIXELSY
Definition: wingdi.h:719
#define LOGPIXELSX
Definition: wingdi.h:718
int WINAPI SelectClipRgn(_In_ HDC, _In_opt_ HRGN)
BOOL WINAPI DrawFrameControl(_In_ HDC, _Inout_ LPRECT, _In_ UINT, _In_ UINT)
#define DFCS_BUTTONCHECK
Definition: winuser.h:496
#define DFCS_INACTIVE
Definition: winuser.h:502
#define DFC_BUTTON
Definition: winuser.h:476
#define DFCS_BUTTON3STATE
Definition: winuser.h:500
BOOL WINAPI IntersectRect(_Out_ LPRECT, _In_ LPCRECT, _In_ LPCRECT)
#define DFCS_BUTTONRADIO
Definition: winuser.h:499
#define ODA_SELECT
Definition: winuser.h:2533
#define DFCS_CHECKED
Definition: winuser.h:504
BOOL WINAPI DrawFocusRect(_In_ HDC, _In_ LPCRECT)
#define DFCS_PUSHED
Definition: winuser.h:503

◆ CB_ThemedPaint()

static void CB_ThemedPaint ( HTHEME  theme,
const BUTTON_INFO infoPtr,
HDC  hdc,
ButtonState  drawState,
UINT  dtflags,
BOOL  focused 
)
static

Definition at line 1903 of file button.c.

1905{
1906 static const int cb_states[3][5] =
1907 {
1911 };
1912
1913 static const int rb_states[2][5] =
1914 {
1917 };
1918
1919 SIZE sz;
1920 RECT bgRect, textRect;
1921 HFONT font, hPrevFont = NULL;
1922 int checkState = infoPtr->state & 3;
1923 DWORD dwStyle = GetWindowLongW(infoPtr->hwnd, GWL_STYLE);
1924 UINT btn_type = get_button_type( dwStyle );
1925 int part = (btn_type == BS_RADIOBUTTON) || (btn_type == BS_AUTORADIOBUTTON) ? BP_RADIOBUTTON : BP_CHECKBOX;
1926 int state = (part == BP_CHECKBOX)
1927 ? cb_states[ checkState ][ drawState ]
1928 : rb_states[ checkState ][ drawState ];
1929 WCHAR *text = get_button_text(infoPtr);
1930 LOGFONTW lf;
1931 BOOL created_font = FALSE;
1932#ifdef __REACTOS__
1933 HWND parent;
1934 HBRUSH hBrush;
1935 DWORD cdrf;
1936#endif
1937
1938 HRESULT hr = GetThemeFont(theme, hDC, part, state, TMT_FONT, &lf);
1939 if (SUCCEEDED(hr)) {
1941 if (!font)
1942 TRACE("Failed to create font\n");
1943 else {
1944 TRACE("font = %s\n", debugstr_w(lf.lfFaceName));
1945 hPrevFont = SelectObject(hDC, font);
1946 created_font = TRUE;
1947 }
1948 } else {
1949#ifdef __REACTOS__ /* r73885 */
1950 font = infoPtr->font;
1951#else
1952 font = (HFONT)SendMessageW(infoPtr->hwnd, WM_GETFONT, 0, 0);
1953#endif
1954 hPrevFont = SelectObject(hDC, font);
1955 }
1956
1957 if (FAILED(GetThemePartSize(theme, hDC, part, state, NULL, TS_DRAW, &sz)))
1958 sz.cx = sz.cy = 13;
1959
1960 GetClientRect(infoPtr->hwnd, &bgRect);
1961
1962#ifdef __REACTOS__
1963 if (prfFlag == 0)
1964 {
1966 }
1967
1968 parent = GetParent(infoPtr->hwnd);
1969 if (!parent) parent = infoPtr->hwnd;
1970 hBrush = (HBRUSH)SendMessageW(parent, WM_CTLCOLORSTATIC,
1971 (WPARAM)hDC, (LPARAM)infoPtr->hwnd);
1972 if (!hBrush) /* did the app forget to call defwindowproc ? */
1973 hBrush = (HBRUSH)DefWindowProcW(parent, WM_CTLCOLORSTATIC,
1974 (WPARAM)hDC, (LPARAM)infoPtr->hwnd );
1975 FillRect( hDC, &bgRect, hBrush );
1976
1977 cdrf = BUTTON_SendCustomDraw(infoPtr, hDC, CDDS_PREERASE, &bgRect);
1978 if (cdrf == CDRF_SKIPDEFAULT)
1979 goto cleanup;
1980#endif
1981
1982 GetThemeBackgroundContentRect(theme, hDC, part, state, &bgRect, &textRect);
1983
1984 if (dtFlags & DT_SINGLELINE) /* Center the checkbox / radio button to the text. */
1985 bgRect.top = bgRect.top + (textRect.bottom - textRect.top - sz.cy) / 2;
1986
1987 /* adjust for the check/radio marker */
1988 bgRect.bottom = bgRect.top + sz.cy;
1989 bgRect.right = bgRect.left + sz.cx;
1990 textRect.left = bgRect.right + 6;
1991
1992#ifdef __REACTOS__
1993 DrawThemeBackground(theme, hDC, part, state, &bgRect, NULL);
1994
1995 if (cdrf == CDRF_NOTIFYPOSTERASE)
1996 BUTTON_SendCustomDraw(infoPtr, hDC, CDDS_POSTERASE, &bgRect);
1997
1998 cdrf = BUTTON_SendCustomDraw(infoPtr, hDC, CDDS_PREPAINT, &bgRect);
1999 if (cdrf == CDRF_SKIPDEFAULT)
2000 goto cleanup;
2001
2002#else
2004 DrawThemeBackground(theme, hDC, part, state, &bgRect, NULL);
2005#endif
2006 if (text)
2007 {
2008 DrawThemeText(theme, hDC, part, state, text, lstrlenW(text), dtFlags, 0, &textRect);
2009
2010 if (focused)
2011 {
2012 RECT focusRect;
2013
2014 focusRect = textRect;
2015
2016 DrawTextW(hDC, text, lstrlenW(text), &focusRect, dtFlags | DT_CALCRECT);
2017
2018 if (focusRect.right < textRect.right) focusRect.right++;
2019 focusRect.bottom = textRect.bottom;
2020
2021 DrawFocusRect( hDC, &focusRect );
2022 }
2023
2024 heap_free(text);
2025#ifdef __REACTOS__
2026 text = NULL;
2027#endif
2028 }
2029
2030#ifdef __REACTOS__
2031 if (cdrf == CDRF_NOTIFYPOSTPAINT)
2032 BUTTON_SendCustomDraw(infoPtr, hDC, CDDS_POSTPAINT, &bgRect);
2033cleanup:
2034 if (text) heap_free(text);
2035#endif
2036 if (created_font) DeleteObject(font);
2037 if (hPrevFont) SelectObject(hDC, hPrevFont);
2038}
#define lstrlenW
Definition: compat.h:750
static void cleanup(void)
Definition: main.c:1335
HRESULT WINAPI DrawThemeBackground(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, const RECT *pRect, const RECT *pClipRect)
Definition: draw.c:128
HRESULT WINAPI GetThemePartSize(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, RECT *prc, THEMESIZE eSize, SIZE *psz)
Definition: draw.c:1777
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
HRESULT WINAPI DrawThemeParentBackground(HWND hwnd, HDC hdc, RECT *prc)
Definition: draw.c:72
HRESULT WINAPI GetThemeBackgroundContentRect(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, const RECT *pBoundingRect, RECT *pContentRect)
Definition: draw.c:1479
HRESULT WINAPI GetThemeFont(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, int iPropId, LOGFONTW *pFont)
Definition: property.c:108
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
#define debugstr_w
Definition: kernel32.h:32
Definition: mk_font.cpp:20
#define CDRF_NOTIFYPOSTERASE
Definition: commctrl.h:277
#define CDRF_NOTIFYPOSTPAINT
Definition: commctrl.h:274
#define CDDS_POSTERASE
Definition: commctrl.h:283
#define CDDS_PREPAINT
Definition: commctrl.h:280
#define CDDS_POSTPAINT
Definition: commctrl.h:281
#define CDRF_SKIPDEFAULT
Definition: commctrl.h:270
#define CDDS_PREERASE
Definition: commctrl.h:282
HRESULT hr
Definition: shlfolder.c:183
RECT textRect
Definition: startmenu.cpp:1392
WCHAR lfFaceName[LF_FACESIZE]
Definition: dimm.idl:72
#define CBS_UNCHECKEDNORMAL
Definition: treelist.c:148
#define CBS_CHECKEDNORMAL
Definition: treelist.c:151
#define BP_CHECKBOX
Definition: treelist.c:145
@ CBS_CHECKEDDISABLED
Definition: vsstyle.h:113
@ CBS_UNCHECKEDDISABLED
Definition: vsstyle.h:109
@ CBS_UNCHECKEDHOT
Definition: vsstyle.h:107
@ CBS_MIXEDPRESSED
Definition: vsstyle.h:116
@ CBS_MIXEDNORMAL
Definition: vsstyle.h:114
@ CBS_UNCHECKEDPRESSED
Definition: vsstyle.h:108
@ CBS_CHECKEDPRESSED
Definition: vsstyle.h:112
@ CBS_CHECKEDHOT
Definition: vsstyle.h:111
@ CBS_MIXEDDISABLED
Definition: vsstyle.h:117
@ CBS_MIXEDHOT
Definition: vsstyle.h:115
@ BP_RADIOBUTTON
Definition: vsstyle.h:75
@ RBS_UNCHECKEDHOT
Definition: vsstyle.h:96
@ RBS_CHECKEDPRESSED
Definition: vsstyle.h:101
@ RBS_CHECKEDHOT
Definition: vsstyle.h:100
@ RBS_UNCHECKEDNORMAL
Definition: vsstyle.h:95
@ RBS_CHECKEDDISABLED
Definition: vsstyle.h:102
@ RBS_UNCHECKEDDISABLED
Definition: vsstyle.h:98
@ RBS_CHECKEDNORMAL
Definition: vsstyle.h:99
@ RBS_UNCHECKEDPRESSED
Definition: vsstyle.h:97
#define TMT_FONT
Definition: vssym32.h:144
HFONT WINAPI CreateFontIndirectW(_In_ const LOGFONTW *)

◆ GB_Paint()

static void GB_Paint ( const BUTTON_INFO infoPtr,
HDC  hDC,
UINT  action 
)
static

Definition at line 1686 of file button.c.

1687{
1688 RECT rc, rcFrame;
1689 HBRUSH hbr;
1690 HFONT hFont;
1691 UINT dtFlags;
1693 LONG style = GetWindowLongW( infoPtr->hwnd, GWL_STYLE );
1694 HWND parent;
1695 HRGN hrgn;
1696
1697 if ((hFont = infoPtr->font)) SelectObject( hDC, hFont );
1698 /* GroupBox acts like static control, so it sends CTLCOLORSTATIC */
1699 parent = GetParent(infoPtr->hwnd);
1700 if (!parent) parent = infoPtr->hwnd;
1701 hbr = (HBRUSH)SendMessageW(parent, WM_CTLCOLORSTATIC, (WPARAM)hDC, (LPARAM)infoPtr->hwnd);
1702 if (!hbr) /* did the app forget to call defwindowproc ? */
1703 hbr = (HBRUSH)DefWindowProcW(parent, WM_CTLCOLORSTATIC, (WPARAM)hDC, (LPARAM)infoPtr->hwnd);
1704 GetClientRect( infoPtr->hwnd, &rc);
1705 rcFrame = rc;
1706 hrgn = set_control_clipping( hDC, &rc );
1707
1709 rcFrame.top += (tm.tmHeight / 2) - 1;
1710 DrawEdge (hDC, &rcFrame, EDGE_ETCHED, BF_RECT | ((style & BS_FLAT) ? BF_FLAT : 0));
1711
1712 InflateRect(&rc, -7, 1);
1713 dtFlags = BUTTON_CalcLabelRect(infoPtr, hDC, &rc);
1714
1715 if (dtFlags != (UINT)-1)
1716 {
1717 /* Because buttons have CS_PARENTDC class style, there is a chance
1718 * that label will be drawn out of client rect.
1719 * But Windows doesn't clip label's rect, so do I.
1720 */
1721
1722 /* There is 1-pixel margin at the left, right, and bottom */
1723 rc.left--; rc.right++; rc.bottom++;
1724 FillRect(hDC, &rc, hbr);
1725 rc.left++; rc.right--; rc.bottom--;
1726
1727 BUTTON_DrawLabel(infoPtr, hDC, dtFlags, &rc);
1728 }
1730 if (hrgn) DeleteObject( hrgn );
1731}
Definition: time.h:68
BOOL WINAPI GetTextMetricsW(_In_ HDC, _Out_ LPTEXTMETRICW)
Definition: text.c:221
#define EDGE_ETCHED
Definition: winuser.h:452
#define BF_FLAT
Definition: winuser.h:471
BOOL WINAPI DrawEdge(_In_ HDC, _Inout_ LPRECT, _In_ UINT, _In_ UINT)
#define BS_FLAT
Definition: winuser.h:280
#define BF_RECT
Definition: winuser.h:462

◆ GB_ThemedPaint()

static void GB_ThemedPaint ( HTHEME  theme,
const BUTTON_INFO infoPtr,
HDC  hdc,
ButtonState  drawState,
UINT  dtflags,
BOOL  focused 
)
static

Definition at line 2043 of file button.c.

2045{
2046 static const int states[] = { GBS_NORMAL, GBS_DISABLED, GBS_NORMAL, GBS_NORMAL, GBS_NORMAL };
2047
2048 RECT bgRect, textRect, contentRect;
2049 int state = states[ drawState ];
2050 WCHAR *text = get_button_text(infoPtr);
2051 LOGFONTW lf;
2052 HFONT font, hPrevFont = NULL;
2053 BOOL created_font = FALSE;
2054#ifdef __REACTOS__ /* r74406 */
2055 HWND parent;
2056 HBRUSH hBrush;
2057 RECT clientRect;
2058#endif
2059
2061 if (SUCCEEDED(hr)) {
2063 if (!font)
2064 TRACE("Failed to create font\n");
2065 else {
2066 hPrevFont = SelectObject(hDC, font);
2067 created_font = TRUE;
2068 }
2069 } else {
2070#ifdef __REACTOS__ /* r73885 */
2071 font = infoPtr->font;
2072#else
2073 font = (HFONT)SendMessageW(infoPtr->hwnd, WM_GETFONT, 0, 0);
2074#endif
2075 hPrevFont = SelectObject(hDC, font);
2076 }
2077
2078 GetClientRect(infoPtr->hwnd, &bgRect);
2079 textRect = bgRect;
2080
2081 if (text)
2082 {
2083 SIZE textExtent;
2084 GetTextExtentPoint32W(hDC, text, lstrlenW(text), &textExtent);
2085 bgRect.top += (textExtent.cy / 2);
2086 textRect.left += 10;
2087 textRect.bottom = textRect.top + textExtent.cy;
2088 textRect.right = textRect.left + textExtent.cx + 4;
2089
2091 }
2092
2093 GetThemeBackgroundContentRect(theme, hDC, BP_GROUPBOX, state, &bgRect, &contentRect);
2094 ExcludeClipRect(hDC, contentRect.left, contentRect.top, contentRect.right, contentRect.bottom);
2095
2096#ifdef __REACTOS__ /* r73885 & r74149 */
2097 if (prfFlag == 0)
2098#endif
2101
2102#ifdef __REACTOS__ /* r74406 */
2103 parent = GetParent(infoPtr->hwnd);
2104 if (!parent) parent = infoPtr->hwnd;
2105 hBrush = (HBRUSH)SendMessageW(parent, WM_CTLCOLORSTATIC,
2106 (WPARAM)hDC, (LPARAM)infoPtr->hwnd);
2107 if (!hBrush) /* did the app forget to call defwindowproc ? */
2108 hBrush = (HBRUSH)DefWindowProcW(parent, WM_CTLCOLORSTATIC,
2109 (WPARAM)hDC, (LPARAM)infoPtr->hwnd );
2110 GetClientRect(infoPtr->hwnd, &clientRect);
2111 FillRect( hDC, &clientRect, hBrush );
2112#endif
2113
2114 DrawThemeBackground(theme, hDC, BP_GROUPBOX, state, &bgRect, NULL);
2115
2117
2118 if (text)
2119 {
2120 InflateRect(&textRect, -2, 0);
2122 heap_free(text);
2123 }
2124
2125 if (created_font) DeleteObject(font);
2126 if (hPrevFont) SelectObject(hDC, hPrevFont);
2127}
BOOL WINAPI IsThemeBackgroundPartiallyTransparent(HTHEME hTheme, int iPartId, int iStateId)
Definition: draw.c:1883
@ BP_GROUPBOX
Definition: vsstyle.h:77
@ GBS_NORMAL
Definition: vsstyle.h:129
@ GBS_DISABLED
Definition: vsstyle.h:130
int WINAPI ExcludeClipRect(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int)
BOOL WINAPI GetTextExtentPoint32W(_In_ HDC hdc, _In_reads_(c) LPCWSTR lpString, _In_ int c, _Out_ LPSIZE psizl)

◆ get_button_text()

static WCHAR * get_button_text ( const BUTTON_INFO infoPtr)
inlinestatic

Definition at line 230 of file button.c.

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}
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
GLuint buffer
Definition: glext.h:5915
GLenum GLsizei len
Definition: glext.h:6722
int WINAPI GetWindowTextW(HWND hWnd, LPWSTR lpString, int nMaxCount)
Definition: window.c:1412
int WINAPI GetWindowTextLengthW(_In_ HWND)

Referenced by BUTTON_CalcLabelRect(), BUTTON_DrawLabel(), CB_ThemedPaint(), GB_ThemedPaint(), and PB_ThemedPaint().

◆ get_button_type()

static UINT get_button_type ( LONG  window_style)
inlinestatic

Definition at line 211 of file button.c.

212{
213 return (window_style & BS_TYPEMASK);
214}

Referenced by BUTTON_BStoDT(), BUTTON_WindowProc(), ButtonWndProc_common(), CB_Paint(), CB_ThemedPaint(), and PB_Paint().

◆ OB_Paint()

static void OB_Paint ( const BUTTON_INFO infoPtr,
HDC  hDC,
UINT  action 
)
static

Definition at line 1780 of file button.c.

1781{
1782 LONG state = infoPtr->state;
1783 DRAWITEMSTRUCT dis;
1784 LONG_PTR id = GetWindowLongPtrW( infoPtr->hwnd, GWLP_ID );
1785 HWND parent;
1786 HFONT hFont;
1787 HRGN hrgn;
1788
1789 dis.CtlType = ODT_BUTTON;
1790 dis.CtlID = id;
1791 dis.itemID = 0;
1792 dis.itemAction = action;
1793 dis.itemState = ((state & BST_FOCUS) ? ODS_FOCUS : 0) |
1794 ((state & BST_PUSHED) ? ODS_SELECTED : 0) |
1795 (IsWindowEnabled(infoPtr->hwnd) ? 0: ODS_DISABLED);
1796 dis.hwndItem = infoPtr->hwnd;
1797 dis.hDC = hDC;
1798 dis.itemData = 0;
1799 GetClientRect( infoPtr->hwnd, &dis.rcItem );
1800
1801 if ((hFont = infoPtr->font)) SelectObject( hDC, hFont );
1802 parent = GetParent(infoPtr->hwnd);
1803 if (!parent) parent = infoPtr->hwnd;
1805
1807
1808 SendMessageW( GetParent(infoPtr->hwnd), WM_DRAWITEM, id, (LPARAM)&dis );
1810 if (hrgn) DeleteObject( hrgn );
1811}
GLuint id
Definition: glext.h:5910
ULONG_PTR itemData
Definition: winuser.h:3083
#define ODS_DISABLED
Definition: winuser.h:2537
#define ODS_SELECTED
Definition: winuser.h:2535
#define WM_DRAWITEM
Definition: winuser.h:1635
#define ODT_BUTTON
Definition: winuser.h:2530
#define ODS_FOCUS
Definition: winuser.h:2539

◆ paint_button()

static void paint_button ( BUTTON_INFO infoPtr,
LONG  style,
UINT  action 
)
inlinestatic

Definition at line 218 of file button.c.

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}

Referenced by BUTTON_WindowProc(), and ButtonWndProc_common().

◆ PB_Paint()

static void PB_Paint ( const BUTTON_INFO infoPtr,
HDC  hDC,
UINT  action 
)
static

Definition at line 1399 of file button.c.

1400{
1401 RECT rc, r;
1402 UINT dtFlags, uState;
1403 HPEN hOldPen, hpen;
1404 HBRUSH hOldBrush;
1405 INT oldBkMode;
1406 COLORREF oldTxtColor;
1407 HFONT hFont;
1408 LONG state = infoPtr->state;
1409 LONG style = GetWindowLongW( infoPtr->hwnd, GWL_STYLE );
1410 BOOL pushedState = (state & BST_PUSHED);
1411 HWND parent;
1412 HRGN hrgn;
1413#ifdef __REACTOS__
1414 DWORD cdrf;
1415#endif
1416
1417 GetClientRect( infoPtr->hwnd, &rc );
1418
1419 /* Send WM_CTLCOLOR to allow changing the font (the colors are fixed) */
1420 if ((hFont = infoPtr->font)) SelectObject( hDC, hFont );
1421 parent = GetParent(infoPtr->hwnd);
1422 if (!parent) parent = infoPtr->hwnd;
1424
1425 hrgn = set_control_clipping( hDC, &rc );
1426
1428 hOldPen = SelectObject(hDC, hpen);
1430 oldBkMode = SetBkMode(hDC, TRANSPARENT);
1431
1432#ifdef __REACTOS__
1433 cdrf = BUTTON_SendCustomDraw(infoPtr, hDC, CDDS_PREERASE, &rc);
1434 if (cdrf == CDRF_SKIPDEFAULT)
1435 goto cleanup;
1436#endif
1437
1439 {
1440 if (action != ODA_FOCUS)
1441 Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom);
1442 InflateRect( &rc, -1, -1 );
1443 }
1444
1445 /* completely skip the drawing if only focus has changed */
1446 if (action == ODA_FOCUS) goto draw_focus;
1447
1448 uState = DFCS_BUTTONPUSH;
1449
1450 if (style & BS_FLAT)
1451 uState |= DFCS_MONO;
1452 else if (pushedState)
1453 {
1455 uState |= DFCS_FLAT;
1456 else
1457 uState |= DFCS_PUSHED;
1458 }
1459
1461 uState |= DFCS_CHECKED;
1462
1463 DrawFrameControl( hDC, &rc, DFC_BUTTON, uState );
1464
1465#ifdef __REACTOS__
1466 if (cdrf == CDRF_NOTIFYPOSTERASE)
1467 BUTTON_SendCustomDraw(infoPtr, hDC, CDDS_POSTERASE, &rc);
1468
1469 cdrf = BUTTON_SendCustomDraw(infoPtr, hDC, CDDS_PREPAINT, &rc);
1470 if (cdrf == CDRF_SKIPDEFAULT)
1471 goto cleanup;
1472#endif
1473
1474 /* draw button label */
1475 r = rc;
1476 dtFlags = BUTTON_CalcLabelRect(infoPtr, hDC, &r);
1477
1478 if (dtFlags == (UINT)-1L)
1479 goto cleanup;
1480
1481 if (pushedState)
1482 OffsetRect(&r, 1, 1);
1483
1484 oldTxtColor = SetTextColor( hDC, GetSysColor(COLOR_BTNTEXT) );
1485
1486 BUTTON_DrawLabel(infoPtr, hDC, dtFlags, &r);
1487
1488 SetTextColor( hDC, oldTxtColor );
1489
1490#ifdef __REACTOS__
1491 if (cdrf == CDRF_NOTIFYPOSTPAINT)
1492 BUTTON_SendCustomDraw(infoPtr, hDC, CDDS_POSTPAINT, &rc);
1493#endif
1494
1495draw_focus:
1496 if (action == ODA_FOCUS || (state & BST_FOCUS))
1497 {
1498#ifdef __REACTOS__
1499 if (!(infoPtr->ui_state & UISF_HIDEFOCUS))
1500 {
1501#endif
1502 InflateRect( &rc, -2, -2 );
1503 DrawFocusRect( hDC, &rc );
1504#ifdef __REACTOS__
1505 }
1506#endif
1507 }
1508
1509 cleanup:
1510 SelectObject( hDC, hOldPen );
1511 SelectObject( hDC, hOldBrush );
1512 SetBkMode(hDC, oldBkMode);
1514 if (hrgn) DeleteObject( hrgn );
1515 DeleteObject( hpen );
1516}
static HPEN hpen
DWORD COLORREF
Definition: windef.h:300
#define TRANSPARENT
Definition: wingdi.h:950
BOOL WINAPI Rectangle(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int)
COLORREF WINAPI SetTextColor(_In_ HDC, _In_ COLORREF)
Definition: text.c:918
HPEN WINAPI CreatePen(_In_ int, _In_ int, _In_ COLORREF)
#define PS_SOLID
Definition: wingdi.h:586
DWORD WINAPI GetSysColor(_In_ int)
#define COLOR_BTNTEXT
Definition: winuser.h:927
#define COLOR_WINDOWFRAME
Definition: winuser.h:913
#define DFCS_BUTTONPUSH
Definition: winuser.h:501
#define DFCS_FLAT
Definition: winuser.h:510
#define DFCS_MONO
Definition: winuser.h:511
BOOL WINAPI OffsetRect(_Inout_ LPRECT, _In_ int, _In_ int)
#define COLOR_BTNFACE
Definition: winuser.h:922

Referenced by CB_Paint().

◆ PB_ThemedPaint()

static void PB_ThemedPaint ( HTHEME  theme,
const BUTTON_INFO infoPtr,
HDC  hdc,
ButtonState  drawState,
UINT  dtflags,
BOOL  focused 
)
static

Definition at line 1816 of file button.c.

1818{
1819 static const int states[] = { PBS_NORMAL, PBS_DISABLED, PBS_HOT, PBS_PRESSED, PBS_DEFAULTED };
1820
1821 RECT bgRect, textRect;
1822 HFONT font = infoPtr->font;
1823 HFONT hPrevFont = font ? SelectObject(hDC, font) : NULL;
1824 int state = states[ drawState ];
1825 WCHAR *text = get_button_text(infoPtr);
1826#ifdef __REACTOS__
1827 HWND parent;
1828 DWORD cdrf;
1829
1830 GetClientRect(infoPtr->hwnd, &bgRect);
1832
1833 if (prfFlag == 0)
1834 {
1837 }
1838
1839 parent = GetParent(infoPtr->hwnd);
1840 if (!parent) parent = infoPtr->hwnd;
1842
1843 cdrf = BUTTON_SendCustomDraw(infoPtr, hDC, CDDS_PREERASE, &bgRect);
1844 if (cdrf == CDRF_SKIPDEFAULT)
1845 goto cleanup;
1846
1847 DrawThemeBackground(theme, hDC, BP_PUSHBUTTON, state, &bgRect, NULL);
1848
1849 if (cdrf == CDRF_NOTIFYPOSTERASE)
1850 BUTTON_SendCustomDraw(infoPtr, hDC, CDDS_POSTERASE, &bgRect);
1851
1852 cdrf = BUTTON_SendCustomDraw(infoPtr, hDC, CDDS_PREPAINT, &bgRect);
1853 if (cdrf == CDRF_SKIPDEFAULT)
1854 goto cleanup;
1855
1856 BUTTON_DrawIml(hDC, &infoPtr->imlData, &textRect, FALSE, drawState);
1857#else
1858 GetClientRect(infoPtr->hwnd, &bgRect);
1860
1863
1864 DrawThemeBackground(theme, hDC, BP_PUSHBUTTON, state, &bgRect, NULL);
1865#endif
1866
1867 if (text)
1868 {
1869 DrawThemeText(theme, hDC, BP_PUSHBUTTON, state, text, lstrlenW(text), dtFlags, 0, &textRect);
1870 heap_free(text);
1871#ifdef __REACTOS__
1872 text = NULL;
1873#endif
1874 }
1875
1876 if (focused)
1877 {
1879 RECT focusRect = bgRect;
1880
1882
1883 focusRect.left += margins.cxLeftWidth;
1884 focusRect.top += margins.cyTopHeight;
1885 focusRect.right -= margins.cxRightWidth;
1886 focusRect.bottom -= margins.cyBottomHeight;
1887
1888 DrawFocusRect( hDC, &focusRect );
1889 }
1890
1891#ifdef __REACTOS__
1892 if (cdrf == CDRF_NOTIFYPOSTPAINT)
1893 BUTTON_SendCustomDraw(infoPtr, hDC, CDDS_POSTPAINT, &bgRect);
1894cleanup:
1895 if (text) heap_free(text);
1896#endif
1897 if (hPrevFont) SelectObject(hDC, hPrevFont);
1898}
static RECT margins
Definition: print.c:55
HRESULT WINAPI GetThemeMargins(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, int iPropId, RECT *prc, MARGINS *pMargins)
Definition: property.c:216
Definition: misc.c:279
@ PBS_DISABLED
Definition: vsstyle.h:89
@ PBS_PRESSED
Definition: vsstyle.h:88
@ PBS_NORMAL
Definition: vsstyle.h:86
@ PBS_HOT
Definition: vsstyle.h:87
@ PBS_DEFAULTED
Definition: vsstyle.h:90
@ BP_PUSHBUTTON
Definition: vsstyle.h:74
#define TMT_CONTENTMARGINS
Definition: vssym32.h:324

◆ set_control_clipping()

HRGN set_control_clipping ( HDC  hdc,
const RECT rect 
)

Definition at line 239 of file button.c.

240{
241 RECT rc = *rect;
242 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
243
244 if (GetClipRgn( hdc, hrgn ) != 1)
245 {
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}
DWORD WINAPI GetLayout(_In_ HDC hdc)
Definition: coord.c:750
HRGN WINAPI CreateRectRgn(_In_ int, _In_ int, _In_ int, _In_ int)
int WINAPI IntersectClipRect(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int)
BOOL WINAPI DPtoLP(_In_ HDC hdc, _Inout_updates_(c) LPPOINT lppt, _In_ int c)
int WINAPI GetClipRgn(_In_ HDC, _In_ HRGN)
#define LAYOUT_RTL
Definition: wingdi.h:1371

Referenced by CB_Paint(), CBPaintText(), GB_Paint(), LISTBOX_PaintItem(), OB_Paint(), PB_Paint(), STATIC_TryPaintFcn(), STATIC_WindowProc(), and StaticWndProc_common().

◆ UB_Paint()

static void UB_Paint ( const BUTTON_INFO infoPtr,
HDC  hDC,
UINT  action 
)
static

Definition at line 1738 of file button.c.

1739{
1740 RECT rc;
1741 HBRUSH hBrush;
1742 HFONT hFont;
1743 LONG state = infoPtr->state;
1744 HWND parent;
1745
1746 GetClientRect( infoPtr->hwnd, &rc);
1747
1748 if ((hFont = infoPtr->font)) SelectObject( hDC, hFont );
1749
1750 parent = GetParent(infoPtr->hwnd);
1751 if (!parent) parent = infoPtr->hwnd;
1752 hBrush = (HBRUSH)SendMessageW(parent, WM_CTLCOLORBTN, (WPARAM)hDC, (LPARAM)infoPtr->hwnd);
1753 if (!hBrush) /* did the app forget to call defwindowproc ? */
1754 hBrush = (HBRUSH)DefWindowProcW(parent, WM_CTLCOLORBTN, (WPARAM)hDC, (LPARAM)infoPtr->hwnd);
1755
1756 FillRect( hDC, &rc, hBrush );
1757 if (action == ODA_FOCUS || (state & BST_FOCUS))
1758 DrawFocusRect( hDC, &rc );
1759
1760 switch (action)
1761 {
1762 case ODA_FOCUS:
1764 break;
1765
1766 case ODA_SELECT:
1768 break;
1769
1770 default:
1771 break;
1772 }
1773}

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( button  )

Variable Documentation

◆ btnPaintFunc

const pfPaint btnPaintFunc[MAX_BTN_TYPE]
static
Initial value:
=
{
NULL,
}
static void GB_Paint(const BUTTON_INFO *infoPtr, HDC hDC, UINT action)
Definition: button.c:1686
static void CB_Paint(const BUTTON_INFO *infoPtr, HDC hDC, UINT action)
Definition: button.c:1522
static void UB_Paint(const BUTTON_INFO *infoPtr, HDC hDC, UINT action)
Definition: button.c:1738
static void OB_Paint(const BUTTON_INFO *infoPtr, HDC hDC, UINT action)
Definition: button.c:1780

Definition at line 154 of file button.c.

Referenced by BUTTON_WindowProc(), ButtonWndProc_common(), and paint_button().

◆ btnThemedPaintFunc

const pfThemedPaint btnThemedPaintFunc[MAX_BTN_TYPE]
static
Initial value:
=
{
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
}
static void GB_ThemedPaint(HTHEME theme, const BUTTON_INFO *infoPtr, HDC hdc, ButtonState drawState, UINT dtflags, BOOL focused)
Definition: button.c:2043
static void CB_ThemedPaint(HTHEME theme, const BUTTON_INFO *infoPtr, HDC hdc, ButtonState drawState, UINT dtflags, BOOL focused)
Definition: button.c:1903
static void PB_ThemedPaint(HTHEME theme, const BUTTON_INFO *infoPtr, HDC hdc, ButtonState drawState, UINT dtflags, BOOL focused)
Definition: button.c:1816

Definition at line 191 of file button.c.

Referenced by BUTTON_WindowProc().

◆ maxCheckState