diff --git a/dlls/comctl32/button.c b/dlls/comctl32/button.c index 1c6fd62fa8f..1b187e38348 100644 --- a/dlls/comctl32/button.c +++ b/dlls/comctl32/button.c @@ -29,8 +29,6 @@ * - WM_NCCREATE: Turns any BS_OWNERDRAW button into a BS_PUSHBUTTON button. * - WM_SYSKEYUP * - BCM_GETIDEALSIZE - * - BCM_GETTEXTMARGIN - * - BCM_SETTEXTMARGIN * * Notifications * - BCN_HOTITEMCHANGE @@ -45,8 +43,6 @@ * Structures/Macros/Definitions * - NMBCHOTITEM * - Button_GetIdealSize - * - Button_GetTextMargin - * - Button_SetTextMargin */ #include @@ -93,6 +89,7 @@ typedef struct _BUTTON_INFO INT note_length; DWORD image_type; /* IMAGE_BITMAP or IMAGE_ICON */ BUTTON_IMAGELIST imagelist; + RECT text_margin; union { HICON icon; @@ -785,6 +782,26 @@ static LRESULT CALLBACK BUTTON_WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, L } break; + case BCM_SETTEXTMARGIN: + { + RECT *text_margin = (RECT *)lParam; + + if (!text_margin) return FALSE; + + infoPtr->text_margin = *text_margin; + return TRUE; + } + + case BCM_GETTEXTMARGIN: + { + RECT *text_margin = (RECT *)lParam; + + if (!text_margin) return FALSE; + + *text_margin = infoPtr->text_margin; + return TRUE; + } + case WM_NCHITTEST: if(btn_type == BS_GROUPBOX) return HTTRANSPARENT; /* fall through */ diff --git a/dlls/comctl32/tests/button.c b/dlls/comctl32/tests/button.c index d8489db5e18..b9d2663ba4a 100644 --- a/dlls/comctl32/tests/button.c +++ b/dlls/comctl32/tests/button.c @@ -1355,6 +1355,54 @@ static void test_get_set_imagelist(void) } } +static void test_get_set_textmargin(void) +{ + HWND hwnd; + RECT margin_in; + RECT margin_out; + BOOL ret; + DWORD type; + + margin_in.top = 1; + margin_in.left = 2; + margin_in.right = 3; + margin_in.bottom = 4; + for (type = BS_PUSHBUTTON; type <= BS_DEFCOMMANDLINK; type++) + { + hwnd = create_button(type, NULL); + ok(hwnd != NULL, "Expect hwnd not null\n"); + + /* Get text margin when it is unset */ + ret = SendMessageA(hwnd, BCM_GETTEXTMARGIN, 0, (LPARAM)&margin_out); + ok(ret, "Expect ret to be true\n"); + ok(IsRectEmpty(&margin_out), "Expect margin empty\n"); + + /* Successful get and set text margin */ + ret = SendMessageA(hwnd, BCM_SETTEXTMARGIN, 0, (LPARAM)&margin_in); + ok(ret, "Expect ret to be true\n"); + SetRectEmpty(&margin_out); + ret = SendMessageA(hwnd, BCM_GETTEXTMARGIN, 0, (LPARAM)&margin_out); + ok(ret, "Expect ret to be true\n"); + ok(EqualRect(&margin_in, &margin_out), "Expect margins to be equal\n"); + + /* BCM_SETTEXTMARGIN null pointer handling */ + ret = SendMessageA(hwnd, BCM_SETTEXTMARGIN, 0, 0); + ok(!ret, "Expect ret to be false\n"); + SetRectEmpty(&margin_out); + ret = SendMessageA(hwnd, BCM_GETTEXTMARGIN, 0, (LPARAM)&margin_out); + ok(ret, "Expect ret to be true\n"); + ok(EqualRect(&margin_in, &margin_out), "Expect margins to be equal\n"); + + /* BCM_GETTEXTMARGIN null pointer handling */ + ret = SendMessageA(hwnd, BCM_SETTEXTMARGIN, 0, (LPARAM)&margin_in); + ok(ret, "Expect ret to be true\n"); + ret = SendMessageA(hwnd, BCM_GETTEXTMARGIN, 0, 0); + ok(!ret, "Expect ret to be true\n"); + + DestroyWindow(hwnd); + } +} + START_TEST(button) { ULONG_PTR ctx_cookie; @@ -1374,6 +1422,7 @@ START_TEST(button) test_button_data(); test_bm_get_set_image(); test_get_set_imagelist(); + test_get_set_textmargin(); unload_v6_module(ctx_cookie, hCtx); } diff --git a/include/commctrl.h b/include/commctrl.h index a0e0ecafa52..b9e3ae6c8cc 100644 --- a/include/commctrl.h +++ b/include/commctrl.h @@ -1104,6 +1104,10 @@ typedef struct tagNMBCHOTITEM (BOOL)SNDMSG(button, BCM_GETIMAGELIST, 0, (LPARAM)(image_list)) #define Button_SetImageList(button, image_list) \ (BOOL)SNDMSG(button, BCM_SETIMAGELIST, 0, (LPARAM)(image_list)) +#define Button_GetTextMargin(button, margin) \ + (BOOL)SNDMSG(button, BCM_GETTEXTMARGIN, 0, (LPARAM)(margin)) +#define Button_SetTextMargin(button, margin) \ + (BOOL)SNDMSG(button, BCM_SETTEXTMARGIN, 0, (LPARAM)(margin)) /* Toolbar */