>From 4f21a42848d00209e17bc581b154038fd122a95d Mon Sep 17 00:00:00 2001
From: Nikolay Sivov <nsivov@codeweavers.com>
Date: Sun, 12 Feb 2012 16:29:54 +0300
Subject: [PATCH 6/6] Update ticks on TBM_SETRANGE

---
 dlls/comctl32/tests/trackbar.c |    9 +++++++++
 dlls/comctl32/trackbar.c       |   14 ++++++++++----
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/dlls/comctl32/tests/trackbar.c b/dlls/comctl32/tests/trackbar.c
index a444503..687ed07 100644
--- a/dlls/comctl32/tests/trackbar.c
+++ b/dlls/comctl32/tests/trackbar.c
@@ -1034,6 +1034,15 @@ static void test_TBS_AUTOTICKS(void)
     ret = SendMessage(hWnd, TBM_GETNUMTICS, 0, 0);
     expect(91, ret);
 
+    ret = SendMessage(hWnd, TBM_SETRANGEMIN, TRUE, 0);
+    expect(0, ret);
+
+    /* TBM_SETRANGE rebuilds tics */
+    ret = SendMessage(hWnd, TBM_SETRANGE, TRUE, MAKELONG(10, 200));
+    expect(0, ret);
+    ret = SendMessage(hWnd, TBM_GETNUMTICS, 0, 0);
+    expect(191, ret);
+
     DestroyWindow(hWnd);
 }
 
diff --git a/dlls/comctl32/trackbar.c b/dlls/comctl32/trackbar.c
index 679d979..299c44c 100644
--- a/dlls/comctl32/trackbar.c
+++ b/dlls/comctl32/trackbar.c
@@ -1151,10 +1151,13 @@ TRACKBAR_SetPos (TRACKBAR_INFO *infoPtr, BOOL fPosition, LONG lPosition)
 
 
 static inline LRESULT
-TRACKBAR_SetRange (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lRange)
+TRACKBAR_SetRange (TRACKBAR_INFO *infoPtr, BOOL redraw, LONG range)
 {
-    infoPtr->lRangeMin = (SHORT)LOWORD(lRange);
-    infoPtr->lRangeMax = (SHORT)HIWORD(lRange);
+    BOOL changed = infoPtr->lRangeMin != (SHORT)LOWORD(range) ||
+                   infoPtr->lRangeMax != (SHORT)HIWORD(range);
+
+    infoPtr->lRangeMin = (SHORT)LOWORD(range);
+    infoPtr->lRangeMax = (SHORT)HIWORD(range);
 
     if (infoPtr->lPos < infoPtr->lRangeMin) {
         infoPtr->lPos = infoPtr->lRangeMin;
@@ -1169,7 +1172,10 @@ TRACKBAR_SetRange (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lRange)
     infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
     if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
 
-    if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
+    if (changed && (infoPtr->dwStyle & TBS_AUTOTICKS))
+        TRACKBAR_RecalculateTics (infoPtr);
+
+    if (redraw) TRACKBAR_InvalidateAll(infoPtr);
 
     return 0;
 }
-- 
1.5.6.5


