[PATCH 8/8] Prevent item height to be calculated to zero value

Nikolay Sivov nsivov at codeweavers.com
Sun Oct 3 18:59:51 CDT 2010


---
 dlls/comctl32/tests/treeview.c |   26 ++++++++++++++++++++++++++
 dlls/comctl32/treeview.c       |   15 ++++++++++-----
 2 files changed, 36 insertions(+), 5 deletions(-)

diff --git a/dlls/comctl32/tests/treeview.c b/dlls/comctl32/tests/treeview.c
index 906a12d..1de63c6 100644
--- a/dlls/comctl32/tests/treeview.c
+++ b/dlls/comctl32/tests/treeview.c
@@ -713,6 +713,32 @@ static void test_get_set_itemheight(void)
     ok_sequence(sequences, TREEVIEW_SEQ_INDEX, test_get_set_itemheight_seq,
         "test get set item height", FALSE);
 
+    /* without TVS_NONEVENHEIGHT */
+    SetWindowLong(hTree, GWL_STYLE, GetWindowLong(hTree, GWL_STYLE) & ~TVS_NONEVENHEIGHT);
+    /* odd value */
+    ulOldHeight = SendMessage( hTree, TVM_SETITEMHEIGHT, 3, 0);
+    ok(ulOldHeight == 8, "got %d, expected %d\n", ulOldHeight, 8);
+    ulNewHeight = (int) SendMessage( hTree, TVM_GETITEMHEIGHT, 0, 0 );
+    ok(ulNewHeight == 2, "got %d, expected %d\n", ulNewHeight, 2);
+
+    ulOldHeight = SendMessage( hTree, TVM_SETITEMHEIGHT, 4, 0);
+    ok(ulOldHeight == 2, "got %d, expected %d\n", ulOldHeight, 2);
+    ulNewHeight = (int) SendMessage( hTree, TVM_GETITEMHEIGHT, 0, 0 );
+    ok(ulNewHeight == 4, "got %d, expected %d\n", ulNewHeight, 4);
+
+    /* with TVS_NONEVENHEIGHT */
+    SetWindowLong(hTree, GWL_STYLE, GetWindowLong(hTree, GWL_STYLE) | TVS_NONEVENHEIGHT);
+    /* odd value */
+    ulOldHeight = SendMessage( hTree, TVM_SETITEMHEIGHT, 3, 0);
+    ok(ulOldHeight == 4, "got %d, expected %d\n", ulOldHeight, 4);
+    ulNewHeight = (int) SendMessage( hTree, TVM_GETITEMHEIGHT, 0, 0 );
+    ok(ulNewHeight == 3, "got %d, expected %d\n", ulNewHeight, 3);
+    /* even value */
+    ulOldHeight = SendMessage( hTree, TVM_SETITEMHEIGHT, 10, 0);
+    ok(ulOldHeight == 3, "got %d, expected %d\n", ulOldHeight, 3);
+    ulNewHeight = (int) SendMessage( hTree, TVM_GETITEMHEIGHT, 0, 0 );
+    ok(ulNewHeight == 10, "got %d, expected %d\n", ulNewHeight, 10);
+
     DestroyWindow(hTree);
 }
 
diff --git a/dlls/comctl32/treeview.c b/dlls/comctl32/treeview.c
index 9609336..1ffcf64 100644
--- a/dlls/comctl32/treeview.c
+++ b/dlls/comctl32/treeview.c
@@ -1828,7 +1828,7 @@ TREEVIEW_SetItemHeight(TREEVIEW_INFO *infoPtr, INT newHeight)
 {
     INT prevHeight = infoPtr->uItemHeight;
 
-    TRACE("%d\n", newHeight);
+    TRACE("new=%d, old=%d\n", newHeight, prevHeight);
     if (newHeight == -1)
     {
 	infoPtr->uItemHeight = TREEVIEW_NaturalHeight(infoPtr);
@@ -1836,13 +1836,17 @@ TREEVIEW_SetItemHeight(TREEVIEW_INFO *infoPtr, INT newHeight)
     }
     else
     {
-	infoPtr->uItemHeight = newHeight;
-	infoPtr->bHeightSet = TRUE;
+        if (newHeight == 0) newHeight = 1;
+        infoPtr->uItemHeight = newHeight;
+        infoPtr->bHeightSet = TRUE;
     }
 
     /* Round down, unless we support odd ("non even") heights. */
-    if (!(infoPtr->dwStyle & TVS_NONEVENHEIGHT))
-	infoPtr->uItemHeight &= ~1;
+    if (!(infoPtr->dwStyle & TVS_NONEVENHEIGHT) && infoPtr->uItemHeight != 1)
+    {
+        infoPtr->uItemHeight &= ~1;
+        TRACE("after rounding=%d\n", infoPtr->uItemHeight);
+    }
 
     if (infoPtr->uItemHeight != prevHeight)
     {
@@ -2062,6 +2066,7 @@ static inline LRESULT
 TREEVIEW_GetVisibleCount(const TREEVIEW_INFO *infoPtr)
 {
     /* Surprise! This does not take integral height into account. */
+    TRACE("client=%d, item=%d\n", infoPtr->clientHeight, infoPtr->uItemHeight);
     return infoPtr->clientHeight / infoPtr->uItemHeight;
 }
 
-- 
1.5.6.5


--------------050101010606040105020905--



More information about the wine-patches mailing list