Damjan Jovanovic : comctl32: Implement treeview edit control text trimming and overwriting.

Alexandre Julliard julliard at winehq.org
Wed Nov 13 16:01:11 CST 2019


Module: wine
Branch: master
Commit: 80bd7fdd5629a89dec7ee5e14a05c2ff512301c4
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=80bd7fdd5629a89dec7ee5e14a05c2ff512301c4

Author: Damjan Jovanovic <damjan.jov at gmail.com>
Date:   Wed Nov 13 05:54:15 2019 +0200

comctl32: Implement treeview edit control text trimming and overwriting.

Signed-off-by: Damjan Jovanovic <damjan.jov at gmail.com>
Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/comctl32/tests/treeview.c |  8 ++++----
 dlls/comctl32/treeview.c       | 21 +++++++++------------
 2 files changed, 13 insertions(+), 16 deletions(-)

diff --git a/dlls/comctl32/tests/treeview.c b/dlls/comctl32/tests/treeview.c
index 82db67d5d0..eb63439f0b 100644
--- a/dlls/comctl32/tests/treeview.c
+++ b/dlls/comctl32/tests/treeview.c
@@ -1327,7 +1327,7 @@ static LRESULT CALLBACK parent_wnd_proc(HWND hWnd, UINT message, WPARAM wParam,
                 NMTVDISPINFOA *disp = (NMTVDISPINFOA *)lParam;
                 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)
                         strcpy(disp->item.pszText, g_endedit_overwrite_contents);
                     if (g_endedit_overwrite_ptr)
@@ -1705,7 +1705,7 @@ static void test_itemedit(void)
     item.cchTextMax = ARRAY_SIZE(buffA);
     r = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
     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 */
     edit = (HWND)SendMessageA(hTree, TVM_EDITLABELA, 0, (LPARAM)hRoot);
@@ -1723,7 +1723,7 @@ static void test_itemedit(void)
     item.cchTextMax = ARRAY_SIZE(buffA);
     r = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
     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 */
     edit = (HWND)SendMessageA(hTree, TVM_EDITLABELA, 0, (LPARAM)hRoot);
@@ -1757,7 +1757,7 @@ static void test_itemedit(void)
     item.cchTextMax = ARRAY_SIZE(buffA);
     r = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
     expect(TRUE, r);
-    todo_wine expect(0, strcmp(item.pszText, "<new_ptr>"));
+    expect(0, strcmp(item.pszText, "<new_ptr>"));
 
     DestroyWindow(hTree);
 }
diff --git a/dlls/comctl32/treeview.c b/dlls/comctl32/treeview.c
index 47623e2be2..0d2c825714 100644
--- a/dlls/comctl32/treeview.c
+++ b/dlls/comctl32/treeview.c
@@ -3993,8 +3993,8 @@ TREEVIEW_EndEditLabelNow(TREEVIEW_INFO *infoPtr, BOOL bCancel)
     TREEVIEW_ITEM *editedItem = infoPtr->editItem;
     NMTVDISPINFOW tvdi;
     BOOL bCommit;
-    WCHAR tmpText[1024] = { '\0' };
-    WCHAR *newText = tmpText;
+    WCHAR tmpText[MAX_PATH] = { '\0' };
+    WCHAR *newText;
     int iLength = 0;
 
     if (!IsWindow(infoPtr->hwndEdit)) return FALSE;
@@ -4007,18 +4007,13 @@ TREEVIEW_EndEditLabelNow(TREEVIEW_INFO *infoPtr, BOOL bCancel)
     if (!bCancel)
     {
         if (!infoPtr->bNtfUnicode)
-            iLength = GetWindowTextA(infoPtr->hwndEdit, (LPSTR)tmpText, 1023);
+            iLength = GetWindowTextA(infoPtr->hwndEdit, (LPSTR)tmpText, ARRAY_SIZE(tmpText));
         else
-            iLength = GetWindowTextW(infoPtr->hwndEdit, tmpText, 1023);
-
-	if (iLength >= 1023)
-	{
-	    ERR("Insufficient space to retrieve new item label\n");
-	}
+            iLength = GetWindowTextW(infoPtr->hwndEdit, tmpText, ARRAY_SIZE(tmpText));
 
         tvdi.item.mask = TVIF_TEXT;
 	tvdi.item.pszText = tmpText;
-	tvdi.item.cchTextMax = iLength + 1;
+	tvdi.item.cchTextMax = ARRAY_SIZE(tmpText);
     }
     else
     {
@@ -4032,11 +4027,13 @@ TREEVIEW_EndEditLabelNow(TREEVIEW_INFO *infoPtr, BOOL bCancel)
     {
         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));
-            MultiByteToWideChar( CP_ACP, 0, (LPSTR)tmpText, -1, newText, len );
+            MultiByteToWideChar( CP_ACP, 0, (LPSTR)tvdi.item.pszText, -1, newText, len );
             iLength = len - 1;
         }
+        else
+            newText = tvdi.item.pszText;
 
         if (lstrcmpW(newText, editedItem->pszText) != 0)
         {




More information about the wine-cvs mailing list