[2/5] comctl32/listview: correct icon spacing calculation when set to 0 or -1
Daniel Jelinski
djelinski1 at gmail.com
Sat Jan 19 17:16:41 CST 2013
-------------- next part --------------
From 4e247cab75542e5891d1923d31b502177e82608e Mon Sep 17 00:00:00 2001
From: Daniel Jelinski <djelinski1 at gmail.com>
Date: Sat, 19 Jan 2013 23:36:27 +0100
Subject: comctl32/listview: correct icon spacing calculation when set to 0 or
-1
---
dlls/comctl32/listview.c | 40 +++++++++++++++++-----------------------
dlls/comctl32/tests/listview.c | 28 +++++++++++-----------------
2 files changed, 28 insertions(+), 40 deletions(-)
diff --git a/dlls/comctl32/listview.c b/dlls/comctl32/listview.c
index 49da83c..31b94a4 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
@@ -8584,28 +8585,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);
@@ -8657,7 +8651,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:
@@ -9081,7 +9075,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;
@@ -9380,8 +9374,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 */
@@ -11003,7 +10997,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 45e403a..ccb55d7 100644
--- a/dlls/comctl32/tests/listview.c
+++ b/dlls/comctl32/tests/listview.c
@@ -4609,10 +4609,9 @@ 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 */
himl40 = ImageList_Create(40, 40, 0, 4, 4);
ok(himl40 != NULL, "failed to create imagelist\n");
@@ -4622,7 +4621,6 @@ todo_wine {
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));
@@ -4638,7 +4636,7 @@ todo_wine {
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));
@@ -4660,15 +4658,16 @@ todo_wine {
ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
expect(100, LOWORD(ret));
- expect(0xFFFF, HIWORD(ret));
}
+ expect(0xFFFF, HIWORD(ret));
+
#ifdef _WIN64
/* NOTE: -1 is not treated the same as (DWORD)-1 by 64bit listview */
ret = SendMessage(hwnd, LVM_SETICONSPACING, 0, (DWORD)-1);
-todo_wine {
+todo_wine
expect(100, LOWORD(ret));
expect(0xFFFF, HIWORD(ret));
-}
+
ret = SendMessage(hwnd, LVM_SETICONSPACING, 0, 0xBAADF00DDEADBEEFLL);
todo_wine {
expect(0xFFFF, LOWORD(ret));
@@ -4680,27 +4679,24 @@ todo_wine {
ok(0xDEADBEEF == ret2, "Expected 00000000DEADBEEF, got %p\n", (void*)ret2);
#else
ret = SendMessage(hwnd, LVM_SETICONSPACING, 0, -1);
-todo_wine {
+todo_wine
expect(100, LOWORD(ret));
expect(0xFFFF, HIWORD(ret));
-}
#endif
ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
/* spacing + icon size returned */
-todo_wine {
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));
-}
+
/* spacing does not depend on selected view type */
ret = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl40);
expect(0, ret);
@@ -4717,18 +4713,16 @@ todo_wine {
/* 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);
}
--
1.7.5.4
More information about the wine-patches
mailing list