[0.4.14][NTUSER] Scrollbar.c, improve co_IntSetScrollInfo() CORE-17769, and an intege...
authorJoachim Henze <Joachim.Henze@reactos.org>
Sun, 19 Sep 2021 21:37:34 +0000 (23:37 +0200)
committerJoachim Henze <Joachim.Henze@reactos.org>
Sun, 19 Sep 2021 21:37:34 +0000 (23:37 +0200)
squashed backport of:
0.4.15-dev-2375-g ffea5152e607512f09efdb0bd02499e481877f59 integer underflow and
0.4.15-dev-3174-g dda9c3979e87223b66e61f0f936f46920221e509 CORE-17769

Fixes CORE-17769 'Rapps Listview manual resize may erroneously not draw the triangles sometimes'
This could happen for both: themed and unthemed.

CORE-17769 was a regression introduced by 0.4.14-dev-1134-g 00adb1a3f967ac7f5cd56b4c39df72a7b3814603

We don't really like the added state in form of the static variables,
but the patch works good from a pure testing-perspective.

Many Thanks to the patches author: Doug Lyons

win32ss/user/ntuser/scrollbar.c

index 930a28e..eba1b41 100644 (file)
@@ -495,6 +495,8 @@ co_IntSetScrollInfo(PWND Window, INT nBar, LPCSCROLLINFO lpsi, BOOL bRedraw)
    /* [0] = HORZ, [1] = VERT */
    static PWND PrevHwnd[2] = { 0 };
    static DWORD PrevPos[2] = { 0 };
+   static DWORD PrevMax[2] = { 0 };
+   static INT PrevAction[2] = { 0 };
 
    ASSERT_REFS_CO(Window);
 
@@ -602,7 +604,7 @@ co_IntSetScrollInfo(PWND Window, INT nBar, LPCSCROLLINFO lpsi, BOOL bRedraw)
    if (lpsi->fMask & (SIF_RANGE | SIF_PAGE | SIF_DISABLENOSCROLL))
    {
       new_flags = Window->pSBInfo->WSBflags;
-      if (Info->nMin >= (int)(Info->nMax - max(Info->nPage - 1, 0)))
+      if (Info->nMin + (int)max(Info->nPage, 1) > Info->nMax)
       {
          /* Hide or disable scroll-bar */
          if (lpsi->fMask & SIF_DISABLENOSCROLL)
@@ -637,6 +639,16 @@ co_IntSetScrollInfo(PWND Window, INT nBar, LPCSCROLLINFO lpsi, BOOL bRedraw)
    }
 
 //done:
+   if ((Window != PrevHwnd[nBar]) || (action != PrevAction[nBar]))
+   {
+      if ((action == SA_SSI_SHOW) && (PrevAction[nBar] == SA_SSI_HIDE))
+      {
+         co_UserShowScrollBar(Window, nBar, TRUE, TRUE);
+      }
+   }
+   if ((action != PrevAction[nBar]) && action != 0)
+      PrevAction[nBar] = action;
+
    if ( action & SA_SSI_HIDE )
    {
       co_UserShowScrollBar(Window, nBar, FALSE, FALSE);
@@ -690,12 +702,14 @@ co_IntSetScrollInfo(PWND Window, INT nBar, LPCSCROLLINFO lpsi, BOOL bRedraw)
                }
             }
             CurrentPos = lpsi->fMask & SIF_PREVIOUSPOS ? OldPos : pSBData->pos;
-            /* Check for changes to Window or CurrentPos */
-            if ((Window != PrevHwnd[nBar]) || (CurrentPos != PrevPos[nBar]))
+            /* Check for changes to Window or CurrentPos or lpsi->nMax */
+            if ((Window != PrevHwnd[nBar]) || (CurrentPos != PrevPos[nBar]) ||
+               (lpsi->nMax != PrevMax[nBar]))
             {
                 co_UserRedrawWindow(Window, &UpdateRect, 0, RDW_INVALIDATE | RDW_FRAME);
                 PrevHwnd[nBar] = Window;
                 PrevPos[nBar] = CurrentPos;
+                PrevMax[nBar] = lpsi->nMax;
             }
          }
       } // FIXME: Arrows