Commit 66331a73 authored by Chris Morgan's avatar Chris Morgan Committed by Alexandre Julliard

Finished the implementation of LISTVIEW_SetColumnWidth. Tested

against windows thoroughly. Fixed bug resulting in unsigned values being passed into LISTVIEW_SetColumnWidth from the listview window procedure. Fixed LISTVIEW_GetItemHeight to disregard the height of icons if no icons exist.
parent 47a6f31f
...@@ -984,7 +984,12 @@ static INT LISTVIEW_GetItemHeight(HWND hwnd) ...@@ -984,7 +984,12 @@ static INT LISTVIEW_GetItemHeight(HWND hwnd)
HDC hdc = GetDC(hwnd); HDC hdc = GetDC(hwnd);
HFONT hOldFont = SelectObject(hdc, infoPtr->hFont); HFONT hOldFont = SelectObject(hdc, infoPtr->hFont);
GetTextMetricsA(hdc, &tm); GetTextMetricsA(hdc, &tm);
if(infoPtr->himlState || infoPtr->himlSmall)
nItemHeight = max(tm.tmHeight, infoPtr->iconSize.cy) + HEIGHT_PADDING; nItemHeight = max(tm.tmHeight, infoPtr->iconSize.cy) + HEIGHT_PADDING;
else
nItemHeight = tm.tmHeight;
SelectObject(hdc, hOldFont); SelectObject(hdc, hOldFont);
ReleaseDC(hwnd, hdc); ReleaseDC(hwnd, hdc);
} }
...@@ -5598,32 +5603,103 @@ static LRESULT LISTVIEW_SetColumnWidth(HWND hwnd, INT iCol, INT cx) ...@@ -5598,32 +5603,103 @@ static LRESULT LISTVIEW_SetColumnWidth(HWND hwnd, INT iCol, INT cx)
LISTVIEW_INFO *infoPtr; LISTVIEW_INFO *infoPtr;
HDITEMA hdi; HDITEMA hdi;
LRESULT lret; LRESULT lret;
LONG lStyle; LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
UINT uView = lStyle & LVS_TYPEMASK;
HDC hdc;
HFONT header_font;
HFONT old_font;
SIZE size;
CHAR text_buffer[DISP_TEXT_SIZE];
INT header_item_count;
INT item_index;
RECT rcHeader;
/* set column width only if in report mode */
lStyle = GetWindowLongA(hwnd, GWL_STYLE);
if ((lStyle & LVS_TYPEMASK) != LVS_REPORT)
return (FALSE);
/* make sure we can get the listview info */ /* make sure we can get the listview info */
if (!(infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0))) if (!(infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0)))
return (FALSE); return (FALSE);
if (!infoPtr->hwndHeader) /* make sure we have a header */ if (!infoPtr->hwndHeader) /* make sure we have a header */
return (FALSE); return (FALSE);
/* FIXME: currently ignoring LVSCW_AUTOSIZE (-1) and /* set column width only if in report or list mode */
* LVSCV_AUTOSIZE_USEHEADER (-2) if ((uView != LVS_REPORT) && (uView != LVS_LIST))
*/
if (cx < 0)
return (FALSE); return (FALSE);
/* take care of invalid cx values */
if((uView == LVS_REPORT) && (cx < -2))
cx = LVSCW_AUTOSIZE;
else if (uView == LVS_LIST && (cx < 1))
return FALSE;
/* resize all columns if in LVS_LIST mode */
if(uView == LVS_LIST) {
infoPtr->nItemWidth = cx;
InvalidateRect(hwnd, NULL, TRUE); /* force redraw of the listview */
return TRUE;
}
/* autosize based on listview items width */
if(cx == LVSCW_AUTOSIZE)
{
/* set the width of the header to the width of the widest item */
for(item_index = 0; item_index < GETITEMCOUNT(infoPtr); item_index++)
{
if(cx < LISTVIEW_GetLabelWidth(hwnd, item_index))
cx = LISTVIEW_GetLabelWidth(hwnd, item_index);
}
} /* autosize based on listview header width */
else if(cx == LVSCW_AUTOSIZE_USEHEADER)
{
header_item_count = Header_GetItemCount(infoPtr->hwndHeader);
/* if iCol is the last column make it fill the remainder of the controls width */
if(iCol == (header_item_count - 1)) {
/* get the width of every item except the current one */
hdi.mask = HDI_WIDTH; hdi.mask = HDI_WIDTH;
hdi.cxy = cx; cx = 0;
for(item_index = 0; item_index < (header_item_count - 1); item_index++) {
Header_GetItemA(infoPtr->hwndHeader, item_index, (LPARAM)(&hdi));
cx+=hdi.cxy;
}
/* retrieve the layout of the header */
GetWindowRect(infoPtr->hwndHeader, &rcHeader);
cx = (rcHeader.right - rcHeader.left) - cx;
}
else
{
/* retrieve header font */
header_font = SendMessageA(infoPtr->hwndHeader, WM_GETFONT, 0L, 0L);
/* retrieve header text */
hdi.mask = HDI_TEXT;
hdi.cchTextMax = sizeof(text_buffer);
hdi.pszText = text_buffer;
Header_GetItemA(infoPtr->hwndHeader, iCol, (LPARAM)(&hdi));
/* determine the width of the text in the header */
hdc = GetDC(hwnd);
old_font = SelectObject(hdc, header_font); /* select the font into hdc */
GetTextExtentPoint32A(hdc, text_buffer, strlen(text_buffer), &size);
SelectObject(hdc, old_font); /* restore the old font */
ReleaseDC(hwnd, hdc);
/* set the width of this column to the width of the text */
cx = size.cx;
}
}
/* call header to update the column change */ /* call header to update the column change */
lret = Header_SetItemA(infoPtr->hwndHeader, (WPARAM)iCol, (LPARAM)&hdi); hdi.mask = HDI_WIDTH;
infoPtr->nItemWidth = LISTVIEW_GetItemWidth(hwnd); hdi.cxy = cx;
lret = Header_SetItemA(infoPtr->hwndHeader, (WPARAM)iCol, (LPARAM)&hdi);
InvalidateRect(hwnd, NULL, TRUE); /* force redraw of the listview */ InvalidateRect(hwnd, NULL, TRUE); /* force redraw of the listview */
...@@ -7763,7 +7839,7 @@ static LRESULT WINAPI LISTVIEW_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, ...@@ -7763,7 +7839,7 @@ static LRESULT WINAPI LISTVIEW_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
return LISTVIEW_SetColumnOrderArray(hwnd, (INT)wParam, (LPINT)lParam); return LISTVIEW_SetColumnOrderArray(hwnd, (INT)wParam, (LPINT)lParam);
case LVM_SETCOLUMNWIDTH: case LVM_SETCOLUMNWIDTH:
return LISTVIEW_SetColumnWidth(hwnd, (INT)wParam, (INT)lParam); return LISTVIEW_SetColumnWidth(hwnd, (INT)wParam, SLOWORD(lParam));
case LVM_SETEXTENDEDLISTVIEWSTYLE: case LVM_SETEXTENDEDLISTVIEWSTYLE:
return LISTVIEW_SetExtendedListViewStyle(hwnd, (DWORD)wParam, (DWORD)lParam); return LISTVIEW_SetExtendedListViewStyle(hwnd, (DWORD)wParam, (DWORD)lParam);
......
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