Daniel Jelinski : comctl32/listview: Correct icon spacing calculation when set to 0 or -1.
Alexandre Julliard
julliard at winehq.org
Wed Feb 6 13:38:12 CST 2013
Module: wine
Branch: master
Commit: cb77ab1a004be9092590414212fb7bd109d9236a
URL: http://source.winehq.org/git/wine.git/?a=commit;h=cb77ab1a004be9092590414212fb7bd109d9236a
Author: Daniel Jelinski <djelinski1 at gmail.com>
Date: Mon Feb 4 20:42:44 2013 +0100
comctl32/listview: Correct icon spacing calculation when set to 0 or -1.
---
dlls/comctl32/listview.c | 40 ++++++++++--------------
dlls/comctl32/tests/listview.c | 65 ++++++++++++++++++++++++----------------
2 files changed, 56 insertions(+), 49 deletions(-)
diff --git a/dlls/comctl32/listview.c b/dlls/comctl32/listview.c
index 8031d37..cee1154 100644
--- a/dlls/comctl32/listview.c
+++ b/dlls/comctl32/listview.c
@@ -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)
diff --git a/dlls/comctl32/tests/listview.c b/dlls/comctl32/tests/listview.c
index 2fb7cb5..2347bfa 100644
--- a/dlls/comctl32/tests/listview.c
+++ b/dlls/comctl32/tests/listview.c
@@ -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);
}
More information about the wine-cvs
mailing list