comctl32: Implement treeview edit control text trimming and overwriting.

Signed-off-by: Damjan Jovanovic <damjan.jov@gmail.com>
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Damjan Jovanovic 2019-11-13 05:54:15 +02:00 committed by Alexandre Julliard
parent 59bb622088
commit 80bd7fdd56
2 changed files with 13 additions and 16 deletions

View File

@ -1327,7 +1327,7 @@ static LRESULT CALLBACK parent_wnd_proc(HWND hWnd, UINT message, WPARAM wParam,
NMTVDISPINFOA *disp = (NMTVDISPINFOA *)lParam; NMTVDISPINFOA *disp = (NMTVDISPINFOA *)lParam;
if (disp->item.mask & TVIF_TEXT) if (disp->item.mask & TVIF_TEXT)
{ {
todo_wine ok(disp->item.cchTextMax == MAX_PATH, "cchTextMax is %d\n", disp->item.cchTextMax); ok(disp->item.cchTextMax == MAX_PATH, "cchTextMax is %d\n", disp->item.cchTextMax);
if (g_endedit_overwrite_contents) if (g_endedit_overwrite_contents)
strcpy(disp->item.pszText, g_endedit_overwrite_contents); strcpy(disp->item.pszText, g_endedit_overwrite_contents);
if (g_endedit_overwrite_ptr) if (g_endedit_overwrite_ptr)
@ -1705,7 +1705,7 @@ static void test_itemedit(void)
item.cchTextMax = ARRAY_SIZE(buffA); item.cchTextMax = ARRAY_SIZE(buffA);
r = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item); r = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
expect(TRUE, r); expect(TRUE, r);
todo_wine expect(MAX_PATH - 1, strlen(item.pszText)); expect(MAX_PATH - 1, strlen(item.pszText));
/* We can't get around that MAX_PATH limit by increasing EM_SETLIMITTEXT */ /* We can't get around that MAX_PATH limit by increasing EM_SETLIMITTEXT */
edit = (HWND)SendMessageA(hTree, TVM_EDITLABELA, 0, (LPARAM)hRoot); edit = (HWND)SendMessageA(hTree, TVM_EDITLABELA, 0, (LPARAM)hRoot);
@ -1723,7 +1723,7 @@ static void test_itemedit(void)
item.cchTextMax = ARRAY_SIZE(buffA); item.cchTextMax = ARRAY_SIZE(buffA);
r = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item); r = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
expect(TRUE, r); expect(TRUE, r);
todo_wine expect(MAX_PATH - 1, strlen(item.pszText)); expect(MAX_PATH - 1, strlen(item.pszText));
/* Overwriting of pszText contents in TVN_ENDLABELEDIT */ /* Overwriting of pszText contents in TVN_ENDLABELEDIT */
edit = (HWND)SendMessageA(hTree, TVM_EDITLABELA, 0, (LPARAM)hRoot); edit = (HWND)SendMessageA(hTree, TVM_EDITLABELA, 0, (LPARAM)hRoot);
@ -1757,7 +1757,7 @@ static void test_itemedit(void)
item.cchTextMax = ARRAY_SIZE(buffA); item.cchTextMax = ARRAY_SIZE(buffA);
r = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item); r = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
expect(TRUE, r); expect(TRUE, r);
todo_wine expect(0, strcmp(item.pszText, "<new_ptr>")); expect(0, strcmp(item.pszText, "<new_ptr>"));
DestroyWindow(hTree); DestroyWindow(hTree);
} }

View File

@ -3993,8 +3993,8 @@ TREEVIEW_EndEditLabelNow(TREEVIEW_INFO *infoPtr, BOOL bCancel)
TREEVIEW_ITEM *editedItem = infoPtr->editItem; TREEVIEW_ITEM *editedItem = infoPtr->editItem;
NMTVDISPINFOW tvdi; NMTVDISPINFOW tvdi;
BOOL bCommit; BOOL bCommit;
WCHAR tmpText[1024] = { '\0' }; WCHAR tmpText[MAX_PATH] = { '\0' };
WCHAR *newText = tmpText; WCHAR *newText;
int iLength = 0; int iLength = 0;
if (!IsWindow(infoPtr->hwndEdit)) return FALSE; if (!IsWindow(infoPtr->hwndEdit)) return FALSE;
@ -4007,18 +4007,13 @@ TREEVIEW_EndEditLabelNow(TREEVIEW_INFO *infoPtr, BOOL bCancel)
if (!bCancel) if (!bCancel)
{ {
if (!infoPtr->bNtfUnicode) if (!infoPtr->bNtfUnicode)
iLength = GetWindowTextA(infoPtr->hwndEdit, (LPSTR)tmpText, 1023); iLength = GetWindowTextA(infoPtr->hwndEdit, (LPSTR)tmpText, ARRAY_SIZE(tmpText));
else else
iLength = GetWindowTextW(infoPtr->hwndEdit, tmpText, 1023); iLength = GetWindowTextW(infoPtr->hwndEdit, tmpText, ARRAY_SIZE(tmpText));
if (iLength >= 1023)
{
ERR("Insufficient space to retrieve new item label\n");
}
tvdi.item.mask = TVIF_TEXT; tvdi.item.mask = TVIF_TEXT;
tvdi.item.pszText = tmpText; tvdi.item.pszText = tmpText;
tvdi.item.cchTextMax = iLength + 1; tvdi.item.cchTextMax = ARRAY_SIZE(tmpText);
} }
else else
{ {
@ -4032,11 +4027,13 @@ TREEVIEW_EndEditLabelNow(TREEVIEW_INFO *infoPtr, BOOL bCancel)
{ {
if (!infoPtr->bNtfUnicode) if (!infoPtr->bNtfUnicode)
{ {
DWORD len = MultiByteToWideChar( CP_ACP, 0, (LPSTR)tmpText, -1, NULL, 0 ); DWORD len = MultiByteToWideChar( CP_ACP, 0, (LPSTR)tvdi.item.pszText, -1, NULL, 0 );
newText = heap_alloc(len * sizeof(WCHAR)); newText = heap_alloc(len * sizeof(WCHAR));
MultiByteToWideChar( CP_ACP, 0, (LPSTR)tmpText, -1, newText, len ); MultiByteToWideChar( CP_ACP, 0, (LPSTR)tvdi.item.pszText, -1, newText, len );
iLength = len - 1; iLength = len - 1;
} }
else
newText = tvdi.item.pszText;
if (lstrcmpW(newText, editedItem->pszText) != 0) if (lstrcmpW(newText, editedItem->pszText) != 0)
{ {