comctl32/listview: Correct icon spacing calculation when set to 0 or -1.

This commit is contained in:
Daniel Jelinski 2013-02-04 20:42:44 +01:00 committed by Alexandre Julliard
parent 72989b5b03
commit cb77ab1a00
2 changed files with 56 additions and 49 deletions

View File

@ -8,6 +8,7 @@
* Copyright 2002 Dimitrie O. Paun
* Copyright 2009-2013 Nikolay Sivov
* Copyright 2009 Owen Rudge for CodeWeavers
* Copyright 2012-2013 Daniel Jelinski
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -8593,28 +8594,21 @@ static DWORD LISTVIEW_SetIconSpacing(LISTVIEW_INFO *infoPtr, INT cx, INT cy)
if (infoPtr->uView != LV_VIEW_ICON) return oldspacing;
/* set to defaults, if instructed to */
if (cx == -1) cx = GetSystemMetrics(SM_CXICONSPACING);
if (cy == -1) cy = GetSystemMetrics(SM_CYICONSPACING);
/* if 0 then compute width
* FIXME: computed cx and cy is not matching native behaviour */
if (cx == 0) {
cx = GetSystemMetrics(SM_CXICONSPACING);
if (infoPtr->iconSize.cx + ICON_LR_PADDING > cx)
cx = infoPtr->iconSize.cx + ICON_LR_PADDING;
if (cx == -1 && cy == -1)
{
cx = GetSystemMetrics(SM_CXICONSPACING) - GetSystemMetrics(SM_CXICON) + infoPtr->iconSize.cx;
cy = GetSystemMetrics(SM_CYICONSPACING) - GetSystemMetrics(SM_CYICON) + infoPtr->iconSize.cy;
}
/* if 0 then keep width */
if (cx != 0)
infoPtr->iconSpacing.cx = cx;
/* if 0 then compute height */
if (cy == 0)
cy = infoPtr->iconSize.cy + 2 * infoPtr->ntmHeight +
ICON_BOTTOM_PADDING + ICON_TOP_PADDING + LABEL_VERT_PADDING;
infoPtr->iconSpacing.cx = cx;
infoPtr->iconSpacing.cy = cy;
/* if 0 then keep height */
if (cy != 0)
infoPtr->iconSpacing.cy = cy;
TRACE("old=(%d,%d), new=(%d,%d), iconSize=(%d,%d), ntmH=%d\n",
LOWORD(oldspacing), HIWORD(oldspacing), cx, cy,
LOWORD(oldspacing), HIWORD(oldspacing), infoPtr->iconSpacing.cx, infoPtr->iconSpacing.cy,
infoPtr->iconSize.cx, infoPtr->iconSize.cy,
infoPtr->ntmHeight);
@ -8666,7 +8660,7 @@ static HIMAGELIST LISTVIEW_SetImageList(LISTVIEW_INFO *infoPtr, INT nType, HIMAG
himlOld = infoPtr->himlNormal;
infoPtr->himlNormal = himl;
if (infoPtr->uView == LV_VIEW_ICON) set_icon_size(&infoPtr->iconSize, himl, FALSE);
LISTVIEW_SetIconSpacing(infoPtr, 0, 0);
LISTVIEW_SetIconSpacing(infoPtr, -1, -1);
break;
case LVSIL_SMALL:
@ -9090,7 +9084,7 @@ static INT LISTVIEW_SetView(LISTVIEW_INFO *infoPtr, DWORD nView)
{
TRACE("icon old size=(%d,%d), new size=(%d,%d)\n",
oldIconSize.cx, oldIconSize.cy, infoPtr->iconSize.cx, infoPtr->iconSize.cy);
LISTVIEW_SetIconSpacing(infoPtr, 0, 0);
LISTVIEW_SetIconSpacing(infoPtr, -1, -1);
}
LISTVIEW_Arrange(infoPtr, LVA_DEFAULT);
break;
@ -9389,8 +9383,8 @@ static LRESULT LISTVIEW_NCCreate(HWND hwnd, const CREATESTRUCTW *lpcs)
infoPtr->bRedraw = TRUE;
infoPtr->bNoItemMetrics = TRUE;
infoPtr->bDoChangeNotify = TRUE;
infoPtr->iconSpacing.cx = GetSystemMetrics(SM_CXICONSPACING);
infoPtr->iconSpacing.cy = GetSystemMetrics(SM_CYICONSPACING);
infoPtr->iconSpacing.cx = GetSystemMetrics(SM_CXICONSPACING) - GetSystemMetrics(SM_CXICON);
infoPtr->iconSpacing.cy = GetSystemMetrics(SM_CYICONSPACING) - GetSystemMetrics(SM_CYICON);
infoPtr->nEditLabelItem = -1;
infoPtr->nLButtonDownItem = -1;
infoPtr->dwHoverTime = HOVER_DEFAULT; /* default system hover time */
@ -11040,7 +11034,7 @@ static INT LISTVIEW_StyleChanged(LISTVIEW_INFO *infoPtr, WPARAM wStyleType,
{
TRACE("icon old size=(%d,%d), new size=(%d,%d)\n",
oldIconSize.cx, oldIconSize.cy, infoPtr->iconSize.cx, infoPtr->iconSize.cy);
LISTVIEW_SetIconSpacing(infoPtr, 0, 0);
LISTVIEW_SetIconSpacing(infoPtr, -1, -1);
}
}
else if (uNewView == LVS_REPORT)

View File

@ -4598,9 +4598,7 @@ static void test_getitemspacing(void)
HWND hwnd;
DWORD ret;
INT cx, cy;
HIMAGELIST himl;
HBITMAP hbmp;
LVITEMA itema;
HIMAGELIST himl40, himl80;
cx = GetSystemMetrics(SM_CXICONSPACING) - GetSystemMetrics(SM_CXICON);
cy = GetSystemMetrics(SM_CYICONSPACING) - GetSystemMetrics(SM_CYICON);
@ -4608,56 +4606,71 @@ static void test_getitemspacing(void)
/* LVS_ICON */
hwnd = create_listview_control(LVS_ICON);
ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
todo_wine {
expect(cx, LOWORD(ret));
expect(cy, HIWORD(ret));
}
/* now try with icons */
himl = ImageList_Create(40, 40, 0, 4, 4);
ok(himl != NULL, "failed to create imagelist\n");
hbmp = CreateBitmap(40, 40, 1, 1, NULL);
ok(hbmp != NULL, "failed to create bitmap\n");
ret = ImageList_Add(himl, hbmp, 0);
expect(0, ret);
ret = SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
himl40 = ImageList_Create(40, 40, 0, 4, 4);
ok(himl40 != NULL, "failed to create imagelist\n");
himl80 = ImageList_Create(80, 80, 0, 4, 4);
ok(himl80 != NULL, "failed to create imagelist\n");
ret = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl40);
expect(0, ret);
itema.mask = LVIF_IMAGE;
itema.iImage = 0;
itema.iItem = 0;
itema.iSubItem = 0;
ret = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM)&itema);
expect(0, ret);
ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
todo_wine {
/* spacing + icon size returned */
expect(cx + 40, LOWORD(ret));
expect(cy + 40, HIWORD(ret));
}
/* try changing icon size */
SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl80);
ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
/* spacing + icon size returned */
expect(cx + 80, LOWORD(ret));
expect(cy + 80, HIWORD(ret));
/* set own icon spacing */
ret = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(100, 100));
expect(cx + 80, LOWORD(ret));
expect(cy + 80, HIWORD(ret));
ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
/* set size returned */
expect(100, LOWORD(ret));
expect(100, HIWORD(ret));
/* now change image list - icon spacing should be unaffected */
SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl40);
ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
/* spacing + icon size returned */
expect(cx + 40, LOWORD(ret));
expect(cy + 40, HIWORD(ret));
SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, 0);
ImageList_Destroy(himl80);
DestroyWindow(hwnd);
/* LVS_SMALLICON */
hwnd = create_listview_control(LVS_SMALLICON);
ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
todo_wine {
expect(cx, LOWORD(ret));
expect(cy, HIWORD(ret));
}
ImageList_Destroy(himl40);
DestroyWindow(hwnd);
/* LVS_REPORT */
hwnd = create_listview_control(LVS_REPORT);
ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
todo_wine {
expect(cx, LOWORD(ret));
expect(cy, HIWORD(ret));
}
DestroyWindow(hwnd);
/* LVS_LIST */
hwnd = create_listview_control(LVS_LIST);
ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
todo_wine {
expect(cx, LOWORD(ret));
expect(cy, HIWORD(ret));
}
DestroyWindow(hwnd);
}