[User32]
[reactos.git] / reactos / dll / win32 / user32 / controls / scrollbar.c
index 460fd6a..b238b64 100644 (file)
@@ -68,7 +68,7 @@ static BOOL ScrollTrackVertical;
 
 HBRUSH DefWndControlColor(HDC hDC, UINT ctlType);
 
-UINT WINAPI SetSystemTimer(HWND,UINT_PTR,UINT,TIMERPROC);
+UINT_PTR WINAPI SetSystemTimer(HWND,UINT_PTR,UINT,TIMERPROC);
 BOOL WINAPI KillSystemTimer(HWND,UINT_PTR);
 
 /*********************************************************************
@@ -1196,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);
 }
 
 
@@ -1268,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:
         {