comctl32/tooltips: Cut tooltip text at first tab char unless TTS_NOPREFIX is used.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Nikolay Sivov 2016-05-02 20:36:51 +03:00 committed by Alexandre Julliard
parent 9c01d10bc6
commit 75059e9ee1
2 changed files with 105 additions and 76 deletions

View File

@ -288,13 +288,15 @@ static HWND create_parent_window(void)
static void test_gettext(void) static void test_gettext(void)
{ {
static const CHAR testtip2A[] = "testtip\ttest2";
static const CHAR testtipA[] = "testtip";
HWND hwnd, notify; HWND hwnd, notify;
TTTOOLINFOA toolinfoA; TTTOOLINFOA toolinfoA;
TTTOOLINFOW toolinfoW; TTTOOLINFOW toolinfoW;
LRESULT r; LRESULT r;
CHAR bufA[10] = ""; CHAR bufA[10] = "";
WCHAR bufW[10] = { 0 }; WCHAR bufW[10] = { 0 };
static const CHAR testtipA[] = "testtip"; DWORD length, style;
notify = create_parent_window(); notify = create_parent_window();
ok(notify != NULL, "Expected notification window to be created\n"); ok(notify != NULL, "Expected notification window to be created\n");
@ -316,49 +318,48 @@ static void test_gettext(void)
toolinfoA.lParam = 0xdeadbeef; toolinfoA.lParam = 0xdeadbeef;
GetClientRect(hwnd, &toolinfoA.rect); GetClientRect(hwnd, &toolinfoA.rect);
r = SendMessageA(hwnd, TTM_ADDTOOLA, 0, (LPARAM)&toolinfoA); r = SendMessageA(hwnd, TTM_ADDTOOLA, 0, (LPARAM)&toolinfoA);
if (r) ok(r, "got %ld\n", r);
{
toolinfoA.hwnd = NULL;
toolinfoA.uId = 0x1234ABCD;
toolinfoA.lpszText = bufA;
SendMessageA(hwnd, TTM_GETTEXTA, 0, (LPARAM)&toolinfoA);
ok(strcmp(toolinfoA.lpszText, "") == 0, "lpszText should be an empty string\n");
toolinfoA.lpszText = bufA; toolinfoA.hwnd = NULL;
SendMessageA(hwnd, TTM_GETTOOLINFOA, 0, (LPARAM)&toolinfoA); toolinfoA.uId = 0x1234abcd;
ok(toolinfoA.lpszText == NULL, toolinfoA.lpszText = bufA;
"expected NULL, got %p\n", toolinfoA.lpszText); r = SendMessageA(hwnd, TTM_GETTEXTA, 0, (LPARAM)&toolinfoA);
ok(!r, "got %ld\n", r);
ok(!*toolinfoA.lpszText, "lpszText should be empty, got %s\n", toolinfoA.lpszText);
/* NULL hinst, valid resource id for text */ toolinfoA.lpszText = bufA;
toolinfoA.cbSize = sizeof(TTTOOLINFOA); r = SendMessageA(hwnd, TTM_GETTOOLINFOA, 0, (LPARAM)&toolinfoA);
toolinfoA.hwnd = NULL; todo_wine
toolinfoA.hinst = NULL; ok(!r, "got %ld\n", r);
toolinfoA.uFlags = 0; ok(toolinfoA.lpszText == NULL, "expected NULL, got %p\n", toolinfoA.lpszText);
toolinfoA.uId = 0x1233ABCD;
toolinfoA.lpszText = MAKEINTRESOURCEA(IDS_TBADD1);
toolinfoA.lParam = 0xdeadbeef;
GetClientRect(hwnd, &toolinfoA.rect);
r = SendMessageA(hwnd, TTM_ADDTOOLA, 0, (LPARAM)&toolinfoA);
ok(r, "failed to add a tool\n");
toolinfoA.hwnd = NULL; /* NULL hinst, valid resource id for text */
toolinfoA.uId = 0x1233ABCD; toolinfoA.cbSize = sizeof(TTTOOLINFOA);
toolinfoA.lpszText = bufA; toolinfoA.hwnd = NULL;
SendMessageA(hwnd, TTM_GETTEXTA, 0, (LPARAM)&toolinfoA); toolinfoA.hinst = NULL;
ok(strcmp(toolinfoA.lpszText, "abc") == 0, "lpszText should be an empty string\n"); toolinfoA.uFlags = 0;
toolinfoA.uId = 0x1233abcd;
toolinfoA.lpszText = MAKEINTRESOURCEA(IDS_TBADD1);
toolinfoA.lParam = 0xdeadbeef;
GetClientRect(hwnd, &toolinfoA.rect);
r = SendMessageA(hwnd, TTM_ADDTOOLA, 0, (LPARAM)&toolinfoA);
ok(r, "failed to add a tool\n");
toolinfoA.hinst = (HINSTANCE)0xdeadbee; toolinfoA.hwnd = NULL;
SendMessageA(hwnd, TTM_GETTOOLINFOA, 0, (LPARAM)&toolinfoA); toolinfoA.uId = 0x1233abcd;
ok(toolinfoA.hinst == NULL, "expected NULL, got %p\n", toolinfoA.hinst); toolinfoA.lpszText = bufA;
r = SendMessageA(hwnd, TTM_GETTEXTA, 0, (LPARAM)&toolinfoA);
ok(!r, "got %ld\n", r);
ok(!strcmp(toolinfoA.lpszText, "abc"), "got wrong text, %s\n", toolinfoA.lpszText);
SendMessageA(hwnd, TTM_DELTOOLA, 0, (LPARAM)&toolinfoA); toolinfoA.hinst = (HINSTANCE)0xdeadbee;
} r = SendMessageA(hwnd, TTM_GETTOOLINFOA, 0, (LPARAM)&toolinfoA);
else todo_wine
{ ok(!r, "got %ld\n", r);
win_skip( "Old comctl32, not testing NULL text\n" ); ok(toolinfoA.hinst == NULL, "expected NULL, got %p\n", toolinfoA.hinst);
DestroyWindow( hwnd );
return; r = SendMessageA(hwnd, TTM_DELTOOLA, 0, (LPARAM)&toolinfoA);
} ok(!r, "got %ld\n", r);
/* add another tool with text */ /* add another tool with text */
toolinfoA.cbSize = sizeof(TTTOOLINFOA); toolinfoA.cbSize = sizeof(TTTOOLINFOA);
@ -372,28 +373,26 @@ static void test_gettext(void)
GetClientRect(hwnd, &toolinfoA.rect); GetClientRect(hwnd, &toolinfoA.rect);
r = SendMessageA(hwnd, TTM_ADDTOOLA, 0, (LPARAM)&toolinfoA); r = SendMessageA(hwnd, TTM_ADDTOOLA, 0, (LPARAM)&toolinfoA);
ok(r, "Adding the tool to the tooltip failed\n"); ok(r, "Adding the tool to the tooltip failed\n");
if (r)
{
DWORD length;
length = SendMessageA(hwnd, WM_GETTEXTLENGTH, 0, 0); length = SendMessageA(hwnd, WM_GETTEXTLENGTH, 0, 0);
ok(length == 0, "Expected 0, got %d\n", length); ok(length == 0, "Expected 0, got %d\n", length);
toolinfoA.hwnd = NULL; toolinfoA.hwnd = NULL;
toolinfoA.uId = 0x1235ABCD; toolinfoA.uId = 0x1235abcd;
toolinfoA.lpszText = bufA; toolinfoA.lpszText = bufA;
SendMessageA(hwnd, TTM_GETTEXTA, 0, (LPARAM)&toolinfoA); r = SendMessageA(hwnd, TTM_GETTEXTA, 0, (LPARAM)&toolinfoA);
ok(strcmp(toolinfoA.lpszText, testtipA) == 0, "lpszText should be an empty string\n"); ok(!r, "got %ld\n", r);
ok(!strcmp(toolinfoA.lpszText, testtipA), "expected %s, got %p\n", testtipA, toolinfoA.lpszText);
memset(bufA, 0x1f, sizeof(bufA)); memset(bufA, 0x1f, sizeof(bufA));
toolinfoA.lpszText = bufA; toolinfoA.lpszText = bufA;
SendMessageA(hwnd, TTM_GETTOOLINFOA, 0, (LPARAM)&toolinfoA); r = SendMessageA(hwnd, TTM_GETTOOLINFOA, 0, (LPARAM)&toolinfoA);
ok(strcmp(toolinfoA.lpszText, testtipA) == 0, todo_wine
"expected %s, got %p\n", testtipA, toolinfoA.lpszText); ok(!r, "got %ld\n", r);
ok(!strcmp(toolinfoA.lpszText, testtipA), "expected %s, got %p\n", testtipA, toolinfoA.lpszText);
length = SendMessageA(hwnd, WM_GETTEXTLENGTH, 0, 0); length = SendMessageA(hwnd, WM_GETTEXTLENGTH, 0, 0);
ok(length == 0, "Expected 0, got %d\n", length); ok(length == 0, "Expected 0, got %d\n", length);
}
/* add another with callback text */ /* add another with callback text */
toolinfoA.cbSize = sizeof(TTTOOLINFOA); toolinfoA.cbSize = sizeof(TTTOOLINFOA);
@ -406,33 +405,26 @@ static void test_gettext(void)
GetClientRect(hwnd, &toolinfoA.rect); GetClientRect(hwnd, &toolinfoA.rect);
r = SendMessageA(hwnd, TTM_ADDTOOLA, 0, (LPARAM)&toolinfoA); r = SendMessageA(hwnd, TTM_ADDTOOLA, 0, (LPARAM)&toolinfoA);
ok(r, "Adding the tool to the tooltip failed\n"); ok(r, "Adding the tool to the tooltip failed\n");
if (r)
{
toolinfoA.hwnd = notify;
toolinfoA.uId = 0x1236ABCD;
toolinfoA.lpszText = bufA;
SendMessageA(hwnd, TTM_GETTEXTA, 0, (LPARAM)&toolinfoA);
ok(strcmp(toolinfoA.lpszText, testcallbackA) == 0,
"lpszText should be an (%s) string\n", testcallbackA);
toolinfoA.lpszText = bufA; toolinfoA.hwnd = notify;
SendMessageA(hwnd, TTM_GETTOOLINFOA, 0, (LPARAM)&toolinfoA); toolinfoA.uId = 0x1236abcd;
ok(toolinfoA.lpszText == LPSTR_TEXTCALLBACKA, toolinfoA.lpszText = bufA;
"expected LPSTR_TEXTCALLBACKA, got %p\n", toolinfoA.lpszText); r = SendMessageA(hwnd, TTM_GETTEXTA, 0, (LPARAM)&toolinfoA);
} ok(!r, "got %ld\n", r);
ok(!strcmp(toolinfoA.lpszText, testcallbackA), "lpszText should be an (%s) string\n", testcallbackA);
toolinfoA.lpszText = bufA;
r = SendMessageA(hwnd, TTM_GETTOOLINFOA, 0, (LPARAM)&toolinfoA);
todo_wine
ok(!r, "got %ld\n", r);
ok(toolinfoA.lpszText == LPSTR_TEXTCALLBACKA, "expected LPSTR_TEXTCALLBACKA, got %p\n", toolinfoA.lpszText);
DestroyWindow(hwnd); DestroyWindow(hwnd);
DestroyWindow(notify); DestroyWindow(notify);
SetLastError(0xdeadbeef);
hwnd = CreateWindowExW(0, TOOLTIPS_CLASSW, NULL, 0, hwnd = CreateWindowExW(0, TOOLTIPS_CLASSW, NULL, 0,
10, 10, 300, 100, 10, 10, 300, 100,
NULL, NULL, NULL, 0); NULL, NULL, NULL, 0);
if (!hwnd && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) {
win_skip("CreateWindowExW is not implemented\n");
return;
}
ok(hwnd != NULL, "failed to create tooltip wnd\n"); ok(hwnd != NULL, "failed to create tooltip wnd\n");
toolinfoW.cbSize = sizeof(TTTOOLINFOW); toolinfoW.cbSize = sizeof(TTTOOLINFOW);
@ -455,6 +447,37 @@ static void test_gettext(void)
ok(toolinfoW.lpszText[0] == 0, "lpszText should be an empty string\n"); ok(toolinfoW.lpszText[0] == 0, "lpszText should be an empty string\n");
} }
/* text with embedded tabs */
toolinfoA.cbSize = sizeof(TTTOOLINFOA);
toolinfoA.hwnd = NULL;
toolinfoA.hinst = GetModuleHandleA(NULL);
toolinfoA.uFlags = 0;
toolinfoA.uId = 0x1235abce;
strcpy(bufA, testtip2A);
toolinfoA.lpszText = bufA;
toolinfoA.lParam = 0xdeadbeef;
GetClientRect(hwnd, &toolinfoA.rect);
r = SendMessageA(hwnd, TTM_ADDTOOLA, 0, (LPARAM)&toolinfoA);
ok(r, "got %ld\n", r);
toolinfoA.hwnd = NULL;
toolinfoA.uId = 0x1235abce;
toolinfoA.lpszText = bufA;
r = SendMessageA(hwnd, TTM_GETTEXTA, 0, (LPARAM)&toolinfoA);
ok(!r, "got %ld\n", r);
ok(!strcmp(toolinfoA.lpszText, testtipA), "expected %s, got %s\n", testtipA, toolinfoA.lpszText);
/* enable TTS_NOPREFIX, original text is retained */
style = GetWindowLongA(hwnd, GWL_STYLE);
SetWindowLongA(hwnd, GWL_STYLE, style | TTS_NOPREFIX);
toolinfoA.hwnd = NULL;
toolinfoA.uId = 0x1235abce;
toolinfoA.lpszText = bufA;
r = SendMessageA(hwnd, TTM_GETTEXTA, 0, (LPARAM)&toolinfoA);
ok(!r, "got %ld\n", r);
ok(!strcmp(toolinfoA.lpszText, testtip2A), "expected %s, got %s\n", testtipA, toolinfoA.lpszText);
DestroyWindow(hwnd); DestroyWindow(hwnd);
} }

View File

@ -509,6 +509,12 @@ TOOLTIPS_GetTipText (const TOOLTIPS_INFO *infoPtr, INT nTool, WCHAR *buffer)
buffer[0] = '\0'; buffer[0] = '\0';
} }
if (!(GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE) & TTS_NOPREFIX)) {
WCHAR *ptrW;
if ((ptrW = strchrW(buffer, '\t')))
*ptrW = 0;
}
TRACE("%s\n", debugstr_w(buffer)); TRACE("%s\n", debugstr_w(buffer));
} }