Commit 6d694d8e authored by Dimitrie O. Paun's avatar Dimitrie O. Paun Committed by Alexandre Julliard

Simplify and fix listview ellipsification of large text labels.

parent 6e5f6d0c
...@@ -3187,22 +3187,17 @@ static VOID LISTVIEW_DrawLargeItem(HWND hwnd, HDC hdc, INT nItem, RECT rcItem, ...@@ -3187,22 +3187,17 @@ static VOID LISTVIEW_DrawLargeItem(HWND hwnd, HDC hdc, INT nItem, RECT rcItem,
rcWidth = max(0, rcItem.right - rcItem.left); rcWidth = max(0, rcItem.right - rcItem.left);
if (nLabelWidth > rcWidth) if (nLabelWidth > rcWidth)
{ {
INT i, len, eos, nCharsFit;
/* give or take a couple, how many average sized chars would fit? */ /* give or take a couple, how many average sized chars would fit? */
nCharsFit = tm.tmAveCharWidth > 0 ? (rcWidth/tm.tmAveCharWidth)+2 : 0; INT nCharsFit = tm.tmAveCharWidth > 0 ? rcWidth/tm.tmAveCharWidth+2 : 0;
/* place the ellipse accordingly, without overrunning the buffer */ INT eos = min(strlenW(lvItem.pszText), nCharsFit);
len = strlenW(szDispText); if (eos > 0) lvItem.pszText[eos-1] = '.';
eos = min((nCharsFit > 1 && nCharsFit < len) ? nCharsFit+3 : len+2, if (eos > 1) lvItem.pszText[eos-2] = '.';
sizeof(szDispText)/sizeof(WCHAR)-1); if (eos < 3) lvItem.pszText[eos] = '\0';
for ( ; eos > 2; eos--)
nLabelWidth = ListView_GetStringWidthW(hwnd, szDispText);
while ((nLabelWidth > rcWidth) && (eos > 3))
{ {
for (i = 1; i < 4; i++) lvItem.pszText[eos - 3] = '.';
szDispText[eos-i] = '.'; lvItem.pszText[eos] = '\0';
/* shift the ellipse one char to the left for each iteration */ if (ListView_GetStringWidthW(hwnd, lvItem.pszText) <= rcWidth) break;
szDispText[eos--] = '\0';
nLabelWidth = ListView_GetStringWidthW(hwnd, szDispText);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment