[PATCH v3 0/2] MR10093: comctl32: Fix zero-sized label for empty text in LISTVIEW_GetItemMetrics.
DrawTextW(..., DT_CALCRECT) returns a zero rectangle for empty strings, resulting in incorrect label size. Faststone Image Viewer does not show file names. Wine-Bug:https://bugs.winehq.org/show_bug.cgi?id=48872 -- v3: comctl32: Fix zero-sized label for empty text in LISTVIEW_GetItemMetrics. comctl32/tests: Test empty string item in icon view. https://gitlab.winehq.org/wine/wine/-/merge_requests/10093
From: Maotong Zhang <zmtong1988@gmail.com> Verify that an item with empty text in LVS_ICON mode returns non-zero LABEL and SELECT rectangles. --- dlls/comctl32/tests/listview.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/dlls/comctl32/tests/listview.c b/dlls/comctl32/tests/listview.c index 951def8fe0f..4c4d4b805dd 100644 --- a/dlls/comctl32/tests/listview.c +++ b/dlls/comctl32/tests/listview.c @@ -4822,6 +4822,28 @@ static void test_getitemrect(void) expect(34, rect.right); DestroyWindow(hwnd); + + hwnd = create_listview_control(LVS_ICON); + ok(hwnd != NULL, "failed to create icon view listview\n"); + + memset(&item, 0, sizeof(item)); + item.mask = LVIF_TEXT; + item.iItem = 0; + item.pszText = (LPSTR)""; + r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item); + expect(0, r); + + SetRect(&rect, LVIR_LABEL, -1, -1, -1); + r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect); + expect(TRUE, r); + ok(rect.right > rect.left,"got left %ld, right %ld\n", rect.left, rect.right); + + SetRect(&rect, LVIR_SELECTBOUNDS, -1, -1, -1); + r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect); + expect(TRUE, r); + ok(rect.right > rect.left,"got left %ld, right %ld\n", rect.left, rect.right); + + DestroyWindow(hwnd); } static void test_editbox(void) -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10093
From: Maotong Zhang <zmtong1988@gmail.com> DrawTextW(..., DT_CALCRECT) returns a zero rectangle for empty strings, resulting in incorrect label size. Faststone Image Viewer does not show file names. Wine-Bug:https://bugs.winehq.org/show_bug.cgi?id=48872 --- dlls/comctl32/listview.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/dlls/comctl32/listview.c b/dlls/comctl32/listview.c index f91e63f1f5b..66da80d70ca 100644 --- a/dlls/comctl32/listview.c +++ b/dlls/comctl32/listview.c @@ -2499,8 +2499,14 @@ static void LISTVIEW_GetItemMetrics(const LISTVIEW_INFO *infoPtr, const LVITEMW uFormat = oversizedBox ? LV_FL_DT_FLAGS : LV_ML_DT_FLAGS; else uFormat = LV_SL_DT_FLAGS; - - DrawTextW (hdc, lpLVItem->pszText, -1, &rcText, uFormat | DT_CALCRECT); + + if (!lpLVItem->pszText || lpLVItem->pszText[0] == L'\0') + { + static WCHAR dummy[] = L" "; + DrawTextW(hdc, dummy, -1, &rcText, uFormat | DT_CALCRECT); + } + else + DrawTextW(hdc, lpLVItem->pszText, -1, &rcText, uFormat | DT_CALCRECT); if (rcText.right != rcText.left) labelSize.cx = min(rcText.right - rcText.left + TRAILING_LABEL_PADDING, infoPtr->nItemWidth); @@ -2560,7 +2566,11 @@ calc_label: SelectBox.bottom = Box.bottom; if (labelSize.cx) - SelectBox.right = min(Label.left + labelSize.cx, Label.right); + { + SelectBox.right = min(Label.left + labelSize.cx, Label.right); + if (!lpLVItem->pszText || lpLVItem->pszText[0] == L'\0') + SelectBox.right = min(Label.left + MAX_EMPTYTEXT_SELECT_WIDTH, Label.right); + } else SelectBox.right = min(Label.left + MAX_EMPTYTEXT_SELECT_WIDTH, Label.right); } -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10093
This does not look right, visually. It will render a blank selection rectangle for empty strings, I don't see the same behavior on Windows. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/10093#note_129697
FSViewer does not show the file name because an empty pszText is passed in, and DrawTextW returns 0, so nothing is drawn. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/10093#note_129709
The added test verifies that LVIR_LABEL returns a non-empty rectangle. On Windows, right > left; on Wine, left == right. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/10093#note_129710
On Sun Feb 15 15:49:54 2026 +0000, Maotong Zhang wrote:
FSViewer does not show the file name because an empty pszText is passed in, and DrawTextW returns 0, so nothing is drawn. I don't see Listview rendering anything for the label on Windows, when it's an empty string. I haven't tried this application.
-- https://gitlab.winehq.org/wine/wine/-/merge_requests/10093#note_129712
On Mon Feb 23 21:14:23 2026 +0000, Maotong Zhang wrote:
The added test verifies that LVIR_LABEL returns a non-empty rectangle. On Windows, right > left; on Wine, left == right. As I said in other comment, this does not match what happens when you have empty item text on Windows. On Windows you don't get filled rectangle for a label.
-- https://gitlab.winehq.org/wine/wine/-/merge_requests/10093#note_130251
On Mon Feb 23 21:14:23 2026 +0000, Nikolay Sivov wrote:
As I said in other comment, this does not match what happens when you have empty item text on Windows. On Windows you don't get filled rectangle for a label. OK, thanks. I'll be analyzing to see where the problem lies.
-- https://gitlab.winehq.org/wine/wine/-/merge_requests/10093#note_130309
participants (3)
-
Maotong Zhang -
Maotong Zhang (@xiaotong) -
Nikolay Sivov (@nsivov)