[PATCH v2 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 -- v2: 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..543bb41684d 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 = ""; + 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
V2: Add test empty string -- https://gitlab.winehq.org/wine/wine/-/merge_requests/10093#note_129682
participants (2)
-
Maotong Zhang -
Maotong Zhang (@xiaotong)