[User32]
[reactos.git] / reactos / dll / win32 / user32 / controls / scrollbar.c
index e55baad..b238b64 100644 (file)
@@ -68,10 +68,7 @@ static BOOL ScrollTrackVertical;
 
 HBRUSH DefWndControlColor(HDC hDC, UINT ctlType);
 
-//static LRESULT WINAPI ScrollBarWndProcW( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
-//static LRESULT WINAPI ScrollBarWndProcA( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
-
-UINT WINAPI SetSystemTimer(HWND,UINT_PTR,UINT,TIMERPROC);
+UINT_PTR WINAPI SetSystemTimer(HWND,UINT_PTR,UINT,TIMERPROC);
 BOOL WINAPI KillSystemTimer(HWND,UINT_PTR);
 
 /*********************************************************************
@@ -712,6 +709,22 @@ IntScrollDrawSizeGrip(HWND Wnd, HDC Dc)
   DrawFrameControl(Dc, &Rect, DFC_SCROLL, DFCS_SCROLLSIZEGRIP);
 }
 
+/***********************************************************************
+ *           SCROLL_RefreshScrollBar
+ *
+ * Repaint the scroll bar interior after a SetScrollRange() or
+ * SetScrollPos() call.
+ */
+static void SCROLL_RefreshScrollBar( HWND hwnd, INT nBar,
+                                    BOOL arrows, BOOL interior )
+{
+    HDC hdc = GetDCEx( hwnd, 0,
+                           DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW) );
+    if (!hdc) return;
+
+    IntDrawScrollBar( hwnd, hdc, nBar);//, arrows, interior );
+    ReleaseDC( hwnd, hdc );
+}
 
 
 /***********************************************************************
@@ -1183,64 +1196,44 @@ VOID FASTCALL
 ScrollTrackScrollBar(HWND Wnd, INT SBType, POINT Pt)
 {
   MSG Msg;
-  RECT WindowRect;
-  UINT XOffset, YOffset;
-  POINT TopLeft;
-
-  if (SB_CTL != SBType)
-    {
-      GetWindowRect(Wnd, &WindowRect);
-
-      Pt.x -= WindowRect.left;
-      Pt.y -= WindowRect.top;
+  UINT XOffset = 0, YOffset = 0;
 
-      TopLeft.x = WindowRect.left;
-      TopLeft.y = WindowRect.top;
-      ScreenToClient(Wnd, &TopLeft);
-      XOffset = - TopLeft.x;
-      YOffset = - TopLeft.y;
-    }
-  else
-    {
-      XOffset = 0;
-      YOffset = 0;
-    }
+  if (SBType != SB_CTL)
+  {
+      PWND pwnd = ValidateHwnd(Wnd);
+      if (!pwnd) return;
+      XOffset = pwnd->rcClient.left - pwnd->rcWindow.left;
+      YOffset = pwnd->rcClient.top - pwnd->rcWindow.top;
+      ScreenToClient(Wnd, &Pt);
+      Pt.x += XOffset;
+      Pt.y += YOffset;
+  }
 
   IntScrollHandleScrollEvent(Wnd, SBType, WM_LBUTTONDOWN, Pt);
 
   do
-    {
-      if (! GetMessageW(&Msg, 0, 0, 0))
-        {
-          break;
-        }
-      if (CallMsgFilterW(&Msg, MSGF_SCROLLBAR))
-        {
-          continue;
-        }
-
-      switch(Msg.message)
-        {
-          case WM_SYSTIMER:
-          case WM_LBUTTONUP:
-          case WM_MOUSEMOVE:
-            Pt.x = LOWORD(Msg.lParam) + XOffset;
-            Pt.y = HIWORD(Msg.lParam) + YOffset;
-            IntScrollHandleScrollEvent(Wnd, SBType, Msg.message, Pt);
-            break;
-          default:
-            TranslateMessage(&Msg);
-            DispatchMessageW(&Msg);
-            break;
-        }
-
-      if (! IsWindow(Wnd))
-        {
+  {
+      if (!GetMessageW(&Msg, 0, 0, 0)) break;
+      if (CallMsgFilterW(&Msg, MSGF_SCROLLBAR)) continue;
+      if ( Msg.message == WM_LBUTTONUP ||
+           Msg.message == WM_MOUSEMOVE ||
+          (Msg.message == WM_SYSTIMER && Msg.wParam == SCROLL_TIMER))
+      {
+          Pt.x = LOWORD(Msg.lParam) + XOffset;
+          Pt.y = HIWORD(Msg.lParam) + YOffset;
+          IntScrollHandleScrollEvent(Wnd, SBType, Msg.message, Pt);
+      }
+      else
+      {
+          TranslateMessage(&Msg);
+          DispatchMessageW(&Msg);
+      }
+      if (!IsWindow(Wnd))
+      {
           ReleaseCapture();
           break;
-        }
-    }
-  while (WM_LBUTTONUP != Msg.message);
+      }
+   } while (Msg.message != WM_LBUTTONUP && GetCapture() == Wnd);
 }
 
 
@@ -1255,12 +1248,31 @@ ScrollBarWndProc(WNDPROC DefWindowProc, HWND Wnd, UINT Msg, WPARAM wParam, LPARA
       return 0;
     }
 
+#ifdef __REACTOS__ // Do this now, remove after Server side is fixed.
+  PWND pWnd;
+
+  pWnd = ValidateHwnd(Wnd);
+  if (pWnd)
+  {
+     if (!pWnd->fnid)
+     {
+        NtUserSetWindowFNID(Wnd, FNID_SCROLLBAR);
+     }
+  }    
+#endif    
+
   switch (Msg)
     {
       case WM_CREATE:
         IntScrollCreateScrollBar(Wnd, (LPCREATESTRUCTW) lParam);
         break;
 
+#ifdef __REACTOS__
+      case WM_DESTROY:
+        NtUserSetWindowFNID(Wnd, FNID_DESTROY);
+        return DefWindowProc(Wnd, Msg, wParam, lParam );
+#endif
+
 //#if 0 /* FIXME */
       case WM_ENABLE:
         {
@@ -1399,14 +1411,14 @@ ScrollBarWndProc(WNDPROC DefWindowProc, HWND Wnd, UINT Msg, WPARAM wParam, LPARA
       case SBM_GETPOS:
         return IntScrollGetScrollPos(Wnd, SB_CTL);
 
+      case SBM_SETRANGEREDRAW:
       case SBM_SETRANGE:
         {
           INT OldPos = IntScrollGetScrollPos(Wnd, SB_CTL);
           SetScrollRange(Wnd, SB_CTL, wParam, lParam, FALSE);
-          if (OldPos != IntScrollGetScrollPos(Wnd, SB_CTL))
-            {
-              return OldPos;
-            }
+          if (Msg == SBM_SETRANGEREDRAW)
+             SCROLL_RefreshScrollBar( Wnd, SB_CTL, TRUE, TRUE );
+          if (OldPos != IntScrollGetScrollPos(Wnd, SB_CTL)) return OldPos;
         }
         return 0;
 
@@ -1416,27 +1428,19 @@ ScrollBarWndProc(WNDPROC DefWindowProc, HWND Wnd, UINT Msg, WPARAM wParam, LPARA
       case SBM_ENABLE_ARROWS:
         return EnableScrollBar(Wnd, SB_CTL, wParam);
 
-      case SBM_SETRANGEREDRAW:
-        {
-          INT OldPos = IntScrollGetScrollPos(Wnd, SB_CTL);
-          SetScrollRange(Wnd, SB_CTL, wParam, lParam, TRUE);
-          if (OldPos != IntScrollGetScrollPos(Wnd, SB_CTL))
-            {
-              return OldPos;
-            }
-        }
-        return 0;
-
       case SBM_SETSCROLLINFO:
         return NtUserSetScrollInfo(Wnd, SB_CTL, (SCROLLINFO *) lParam, wParam);
 
       case SBM_GETSCROLLINFO:
         return NtUserSBGetParms(Wnd, SB_CTL, NULL, (SCROLLINFO *) lParam);
 
+      case SBM_GETSCROLLBARINFO:
+        ((PSCROLLBARINFO)lParam)->cbSize = sizeof(SCROLLBARINFO);
+        return NtUserGetScrollBarInfo(Wnd, OBJID_CLIENT, (PSCROLLBARINFO)lParam);
+
       case 0x00e5:
       case 0x00e7:
       case 0x00e8:
-      case 0x00eb:
       case 0x00ec:
       case 0x00ed:
       case 0x00ee:
@@ -1505,8 +1509,8 @@ RealGetScrollInfo(HWND Wnd, INT SBType, LPSCROLLINFO Info)
   PWND pWnd;
   PSBDATA pSBData = NULL;
 
-   if (SB_CTL == SBType)
-   {
+  if (SB_CTL == SBType)
+  {
      return SendMessageW(Wnd, SBM_GETSCROLLINFO, 0, (LPARAM) Info);
   }