fixed some scrollbar issues
authorThomas Bluemel <thomas@reactsoft.com>
Sat, 17 Apr 2004 11:00:14 +0000 (11:00 +0000)
committerThomas Bluemel <thomas@reactsoft.com>
Sat, 17 Apr 2004 11:00:14 +0000 (11:00 +0000)
svn path=/trunk/; revision=9173

reactos/lib/user32/windows/nonclient.c
reactos/subsys/win32k/include/scroll.h
reactos/subsys/win32k/include/window.h
reactos/subsys/win32k/ntuser/scrollbar.c
reactos/subsys/win32k/ntuser/window.c

index 652511c..62b7b3e 100644 (file)
@@ -67,6 +67,10 @@ Already defined in makefile now.
              (WindowRect.right - WindowRect.left == ParentClientRect.right) && \
              (WindowRect.bottom - WindowRect.top == ParentClientRect.bottom)))
 
+#ifndef STATE_SYSTEM_OFFSCREEN
+#define STATE_SYSTEM_OFFSCREEN 0x00010000
+#endif
+
 /*
  * FIXME: This should be moved to a header
  */
@@ -83,6 +87,17 @@ extern ATOM AtomInternalPos;
 
 /* PRIVATE FUNCTIONS **********************************************************/
 
+BOOL
+IntIsScrollBarVisible(HWND hWnd, INT hBar)
+{
+  SCROLLBARINFO sbi;
+  sbi.cbSize = sizeof(SCROLLBARINFO);
+  if(!NtUserGetScrollBarInfo(hWnd, hBar, &sbi))
+    return FALSE;
+  
+  return !(sbi.rgstate[0] & STATE_SYSTEM_OFFSCREEN);
+}
+
 BOOL
 UserHasWindowEdge(DWORD Style, DWORD ExStyle)
 {
@@ -459,7 +474,7 @@ DefWndNCPaint(HWND hWnd, HRGN hRgn)
      
      /* Draw the scrollbars */
      if ((Style & WS_VSCROLL) && (Style & WS_HSCROLL) &&
-         (CurrentRect.bottom - CurrentRect.top) > GetSystemMetrics(SM_CYHSCROLL))
+         IntIsScrollBarVisible(hWnd, OBJID_VSCROLL) && IntIsScrollBarVisible(hWnd, OBJID_HSCROLL))
      {
         RECT ParentClientRect;
         
@@ -469,7 +484,7 @@ DefWndNCPaint(HWND hWnd, HRGN hRgn)
         else
            TempRect.left = TempRect.right - GetSystemMetrics(SM_CXVSCROLL);
         TempRect.top = TempRect.bottom - GetSystemMetrics(SM_CYHSCROLL);
-        FillRect(hDC, &TempRect, GetSysColorBrush(COLOR_SCROLLBAR));
+        FillRect(hDC, &TempRect, GetSysColorBrush(COLOR_BTNFACE));
         /* FIXME: Correct drawing of size-box with WS_EX_LEFTSCROLLBAR */
         if(Parent)
           GetClientRect(Parent, &ParentClientRect);
@@ -482,9 +497,9 @@ DefWndNCPaint(HWND hWnd, HRGN hRgn)
      }
      else
      {
-        if (Style & WS_VSCROLL)
+        if (Style & WS_VSCROLL && IntIsScrollBarVisible(hWnd, OBJID_VSCROLL))
            IntDrawScrollBar(hWnd, hDC, SB_VERT);
-        else if (Style & WS_HSCROLL)
+        else if (Style & WS_HSCROLL && IntIsScrollBarVisible(hWnd, OBJID_HSCROLL))
            IntDrawScrollBar(hWnd, hDC, SB_HORZ);
      }
    }
@@ -561,9 +576,53 @@ DefWndNCCalcSize(HWND hWnd, BOOL CalcSizeStruct, RECT *Rect)
          InflateRect(Rect, -2 * GetSystemMetrics(SM_CXBORDER),
             -2 * GetSystemMetrics(SM_CYBORDER));
       }
+      
+      if(Style & (WS_VSCROLL | WS_HSCROLL))
+      {
+        SCROLLBARINFO sbi;
+        SETSCROLLBARINFO ssbi;
+        
+        sbi.cbSize = sizeof(SCROLLBARINFO);
+        if((Style & WS_VSCROLL) && NtUserGetScrollBarInfo(hWnd, OBJID_VSCROLL, &sbi))
+        {
+          int i;
+          LONG sx = Rect->right;
+          
+          sx -= GetSystemMetrics(SM_CXVSCROLL);
+          for(i = 0; i <= CCHILDREN_SCROLLBAR; i++)
+            ssbi.rgstate[i] = sbi.rgstate[i];
+          if(sx <= Rect->left)
+            ssbi.rgstate[0] |= STATE_SYSTEM_OFFSCREEN;
+          else
+            ssbi.rgstate[0] &= ~STATE_SYSTEM_OFFSCREEN;
+          NtUserSetScrollBarInfo(hWnd, OBJID_VSCROLL, &ssbi);
+          if(ssbi.rgstate[0] & STATE_SYSTEM_OFFSCREEN)
+            Style &= ~WS_VSCROLL;
+        }
+        else
+          Style &= ~WS_VSCROLL;
+        
+        if((Style & WS_HSCROLL) && NtUserGetScrollBarInfo(hWnd, OBJID_HSCROLL, &sbi))
+        {
+          int i;
+          LONG sy = Rect->bottom;
+          
+          sy -= GetSystemMetrics(SM_CYHSCROLL);
+          for(i = 0; i <= CCHILDREN_SCROLLBAR; i++)
+            ssbi.rgstate[i] = sbi.rgstate[i];
+          if(sy <= Rect->top)
+            ssbi.rgstate[0] |= STATE_SYSTEM_OFFSCREEN;
+          else
+            ssbi.rgstate[0] &= ~STATE_SYSTEM_OFFSCREEN;
+          NtUserSetScrollBarInfo(hWnd, OBJID_HSCROLL, &ssbi);
+          if(ssbi.rgstate[0] & STATE_SYSTEM_OFFSCREEN)
+            Style &= ~WS_HSCROLL;
+        }
+        else
+          Style &= ~WS_HSCROLL;
+      }
 
-      if ((Style & WS_VSCROLL) && (Style & WS_HSCROLL) &&
-          (Rect->bottom - Rect->top) > GetSystemMetrics(SM_CYHSCROLL))
+      if ((Style & WS_VSCROLL) && (Style & WS_HSCROLL))
       {
          if ((ExStyle & WS_EX_LEFTSCROLLBAR) != 0)
             Rect->left += GetSystemMetrics(SM_CXVSCROLL);
index 6e6d6f8..19cd1cf 100644 (file)
@@ -1,7 +1,22 @@
 #ifndef _WIN32K_SCROLL_H
 #define _WIN32K_SCROLL_H
 
-DWORD FASTCALL IntCreateScrollBar(PWINDOW_OBJECT Window, LONG idObject);
-BOOL FASTCALL IntDestroyScrollBar(PWINDOW_OBJECT Window, LONG idObject);
+typedef struct _WINDOW_SCROLLINFO
+{
+  SCROLLBARINFO ScrollBarInfo;
+  SCROLLINFO ScrollInfo;
+} WINDOW_SCROLLINFO, *PWINDOW_SCROLLINFO;
+
+#define IntGetScrollbarInfoFromWindow(Window, i) \
+  ((PSCROLLBARINFO)(&((Window)->Scroll + i)->ScrollBarInfo))
+
+#define IntGetScrollInfoFromWindow(Window, i) \
+  ((LPSCROLLINFO)(&((Window)->Scroll + i)->ScrollInfo))
+
+#define SBOBJ_TO_SBID(Obj)     ((Obj) - OBJID_HSCROLL)
+#define SBID_IS_VAILD(id)      (id == SB_HORZ || id == SB_VERT)
+
+BOOL FASTCALL IntCreateScrollBars(PWINDOW_OBJECT Window);
+BOOL FASTCALL IntDestroyScrollBars(PWINDOW_OBJECT Window);
 
 #endif /* _WIN32K_SCROLL_H */
index 5e0ca1b..94d2982 100644 (file)
@@ -13,6 +13,7 @@ typedef struct _WINDOW_OBJECT *PWINDOW_OBJECT;
 #include <include/winsta.h>
 #include <include/dce.h>
 #include <include/prop.h>
+#include <include/scroll.h>
 
 
 VOID FASTCALL
@@ -85,9 +86,7 @@ typedef struct _WINDOW_OBJECT
   FAST_MUTEX PropListLock;
   ULONG PropListItems;
   /* Scrollbar info */
-  PSCROLLBARINFO pHScroll;
-  PSCROLLBARINFO pVScroll;
-  PSCROLLBARINFO wExtra;
+  PWINDOW_SCROLLINFO Scroll;
   LONG UserData;
   BOOL Unicode;
   WNDPROC WndProcA;
index f976cfa..bc66df8 100644 (file)
@@ -16,7 +16,7 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
-/* $Id: scrollbar.c,v 1.29 2004/04/09 20:03:19 navaraf Exp $
+/* $Id: scrollbar.c,v 1.30 2004/04/17 11:00:14 weiden Exp $
  *
  * COPYRIGHT:        See COPYING in the top level directory
  * PROJECT:          ReactOS kernel
 #define SBRG_PAGEDOWNLEFT  4 /* the page down or page left region */
 #define SBRG_BOTTOMLEFTBTN 5 /* the bottom or left button */
 
+#define CHANGERGSTATE(item, status) \
+  if(Info->rgstate[(item)] != (status)) \
+    Chg = TRUE; \
+  Info->rgstate[(item)] = (status); 
+
 /* FUNCTIONS *****************************************************************/
 
 /* Ported from WINE20020904 */
@@ -66,7 +71,7 @@
  * 'thumbSize' returns the size of the thumb, and 'thumbPos' returns the position of the thumb relative to the left or to
  * the top. Return TRUE if the scrollbar is vertical, FALSE if horizontal.
  */
-BOOL STDCALL
+BOOL FASTCALL
 IntGetScrollBarRect (PWINDOW_OBJECT Window, INT nBar, PRECT lprect)
 {
   BOOL vertical;
@@ -180,43 +185,40 @@ IntCalculateThumb(PWINDOW_OBJECT Window, LONG idObject, PSCROLLBARINFO psbi, LPS
   return TRUE;
 }
 
+static VOID FASTCALL
+IntUpdateSBInfo(PWINDOW_OBJECT Window, int wBar)
+{
+  PSCROLLBARINFO sbi;
+  LPSCROLLINFO psi;
+  
+  ASSERT(Window);
+  ASSERT(Window->Scroll);
+  
+  sbi = IntGetScrollbarInfoFromWindow(Window, wBar);
+  psi = IntGetScrollInfoFromWindow(Window, wBar);
+  IntGetScrollBarRect(Window, wBar, &(sbi->rcScrollBar));
+  IntCalculateThumb(Window, wBar, sbi, psi);
+}
+
 static BOOL FASTCALL
 IntGetScrollInfo(PWINDOW_OBJECT Window, INT nBar, LPSCROLLINFO lpsi)
 {
   UINT Mask;
   LPSCROLLINFO psi;
-  PSCROLLBARINFO Info;
   
-  switch (nBar)
-    {
-      case SB_HORZ:
-        Info = Window->pHScroll;
-        break;
-      case SB_VERT:
-        Info = Window->pVScroll;
-        break;
-      case SB_CTL:
-        if (Window->ExtraDataSize < sizeof(SCROLLBARINFO) + sizeof(SCROLLINFO))
-          {
-            Info = NULL;
-          }
-        else
-          {
-            Info = (PSCROLLBARINFO) Window->ExtraData;
-          }
-        break;
-      default:
-        DPRINT1("Trying to get scrollinfo for unknown scrollbar type %d", nBar);
-        return FALSE;
-    }
+  if(!SBID_IS_VAILD(nBar))
+  {
+    SetLastWin32Error(ERROR_INVALID_PARAMETER);
+    DPRINT1("Trying to get scrollinfo for unknown scrollbar type %d", nBar);
+    return FALSE;
+  }
 
-  if (NULL == Info)
+  if(!IntCreateScrollBars(Window))
     {
-      DPRINT1("No scrollinfo available\n");
       return FALSE;
     }
   
-  psi = (LPSCROLLINFO)(Info + 1);
+  psi = IntGetScrollInfoFromWindow(Window, nBar);
   
   if (lpsi->fMask == SIF_ALL)
     {
@@ -264,6 +266,18 @@ IntSetScrollInfo(PWINDOW_OBJECT Window, INT nBar, LPCSCROLLINFO lpsi, BOOL bRedr
 /*   UINT new_flags;*/
   BOOL bChangeParams = FALSE; /* don't show/hide scrollbar if params don't change */
 
+  if(!SBID_IS_VAILD(nBar))
+  {
+    SetLastWin32Error(ERROR_INVALID_PARAMETER);
+    DPRINT1("Trying to set scrollinfo for unknown scrollbar type %d", nBar);
+    return FALSE;
+  }
+
+  if(!IntCreateScrollBars(Window))
+    {
+      return FALSE;
+    }
+  
   if (lpsi->cbSize != sizeof(SCROLLINFO) && 
       lpsi->cbSize != (sizeof(SCROLLINFO) - sizeof(lpsi->nTrackPos)))
     {
@@ -275,38 +289,9 @@ IntSetScrollInfo(PWINDOW_OBJECT Window, INT nBar, LPCSCROLLINFO lpsi, BOOL bRedr
       SetLastWin32Error(ERROR_INVALID_PARAMETER);
       return 0;
     }
-  switch (nBar)
-    {
-      case SB_HORZ:
-        if (NULL == Window->pHScroll)
-          {
-            SetLastWin32Error(ERROR_INVALID_PARAMETER);
-            return 0;
-          }
-        psbi = Window->pHScroll;
-        break;
-      case SB_VERT:
-        if (NULL == Window->pVScroll)
-          {
-            SetLastWin32Error(ERROR_INVALID_PARAMETER);
-            return 0;
-          }
-        psbi = Window->pVScroll;
-        break;
-      case SB_CTL:
-        if (Window->ExtraDataSize < sizeof(SCROLLBARINFO) + sizeof(SCROLLINFO))
-          {
-            SetLastWin32Error(ERROR_INVALID_PARAMETER);
-            return 0;
-          }
-        psbi = (PSCROLLBARINFO) Window->ExtraData;
-        break;
-      default:
-        SetLastWin32Error(ERROR_INVALID_PARAMETER);
-        return 0;
-    }
-
-  Info = (LPSCROLLINFO)(psbi + 1);
+  
+  psbi = IntGetScrollbarInfoFromWindow(Window, nBar);
+  Info = IntGetScrollInfoFromWindow(Window, nBar);
 
   /* Set the page size */
   if (0 != (lpsi->fMask & SIF_PAGE))
@@ -430,39 +415,22 @@ IntGetScrollBarInfo(PWINDOW_OBJECT Window, LONG idObject, PSCROLLBARINFO psbi)
   PSCROLLBARINFO sbi;
   LPSCROLLINFO psi;
   
-  switch(idObject)
-    {
-      case OBJID_HSCROLL:
-        Bar = SB_HORZ;
-        sbi = Window->pHScroll;
-        break;
-      case OBJID_VSCROLL:
-        Bar = SB_VERT;
-        sbi = Window->pVScroll;
-        break;
-      case OBJID_CLIENT:
-        Bar = SB_CTL;
-        if (Window->ExtraDataSize < sizeof(SCROLLBARINFO) + sizeof(SCROLLINFO))
-          {
-            sbi = NULL;
-          }
-        else
-          {
-            sbi = (PSCROLLBARINFO) Window->ExtraData;
-          }
-        break;
-      default:
-        SetLastWin32Error(ERROR_INVALID_PARAMETER);
-        return FALSE;
-    }
-
-  if (NULL == sbi)
+  Bar = SBOBJ_TO_SBID(idObject);
+  
+  if(!SBID_IS_VAILD(Bar))
+  {
+    SetLastWin32Error(ERROR_INVALID_PARAMETER);
+    DPRINT1("Trying to get scrollinfo for unknown scrollbar type %d", Bar);
+    return FALSE;
+  }
+  
+  if(!IntCreateScrollBars(Window))
     {
-      SetLastWin32Error(ERROR_INVALID_PARAMETER);
       return FALSE;
     }
   
-  psi = (LPSCROLLINFO)(sbi + 1);
+  sbi = IntGetScrollbarInfoFromWindow(Window, Bar);
+  psi = IntGetScrollInfoFromWindow(Window, Bar);
 
   IntGetScrollBarRect(Window, Bar, &(sbi->rcScrollBar));
   IntCalculateThumb(Window, Bar, sbi, psi);
@@ -472,97 +440,65 @@ IntGetScrollBarInfo(PWINDOW_OBJECT Window, LONG idObject, PSCROLLBARINFO psbi)
   return TRUE;
 }
 
-DWORD FASTCALL 
-IntCreateScrollBar(PWINDOW_OBJECT Window, LONG idObject)
+BOOL FASTCALL 
+IntCreateScrollBars(PWINDOW_OBJECT Window)
 {
   PSCROLLBARINFO psbi;
   LPSCROLLINFO psi;
   LRESULT Result;
+  ULONG Size, s;
   INT i;
-
-  psbi = ExAllocatePoolWithTag(PagedPool, sizeof(SCROLLBARINFO) + sizeof(SCROLLINFO), TAG_SBARINFO);
-  if(!psbi)
+  
+  if(Window->Scroll)
+  {
+    /* no need to create it anymore */
+    return TRUE;
+  }
+  
+  /* allocate memory for all scrollbars (HORZ, VERT, CONTROL) */
+  Size = 2 * (sizeof(WINDOW_SCROLLINFO));
+  if(!(Window->Scroll = ExAllocatePoolWithTag(PagedPool, Size, TAG_SBARINFO)))
+  {
+    DPRINT1("Unable to allocate memory for scrollbar information for window 0x%x\n", Window->Self);
     return FALSE;
-    
-  psi = (LPSCROLLINFO)((PSCROLLBARINFO)(psbi + 1));
+  }
   
-  psi->cbSize = sizeof(LPSCROLLINFO);
-  psi->nMin = 0;
-  psi->nMax = 100;
-  psi->nPage = 0;
-  psi->nPos = 0;
-  psi->nTrackPos = 0;
+  RtlZeroMemory(Window->Scroll, Size);
 
   Result = WinPosGetNonClientSize(Window->Self,
                                  &Window->WindowRect,
                                  &Window->ClientRect);
-
-  psbi->cbSize = sizeof(SCROLLBARINFO);
-
-  for (i = 0; i < CCHILDREN_SCROLLBAR + 1; i++)
-    psbi->rgstate[i] = 0;
-
-  switch(idObject)
+  
+  for(s = SB_HORZ; s <= SB_VERT; s++)
   {
-    case SB_HORZ:
-      Window->pHScroll = psbi;
-      break;
-    case SB_VERT:
-      Window->pVScroll = psbi;
-      break;
-    case SB_CTL:
-      Window->wExtra = psbi;
-      break;
-    default:
-      ExFreePool(psbi);
-      return FALSE;
+    psbi = IntGetScrollbarInfoFromWindow(Window, s);
+    psbi->cbSize = sizeof(SCROLLBARINFO);
+    for (i = 0; i < CCHILDREN_SCROLLBAR + 1; i++)
+      psbi->rgstate[i] = 0;
+    
+    psi = IntGetScrollInfoFromWindow(Window, s);
+    psi->cbSize = sizeof(LPSCROLLINFO);
+    psi->nMax = 100;
+    
+    IntGetScrollBarRect(Window, s, &(psbi->rcScrollBar));
+    IntCalculateThumb(Window, s, psbi, psi);
   }
 
-  IntGetScrollBarRect(Window, idObject, &(psbi->rcScrollBar));
-  IntCalculateThumb(Window, idObject, psbi, psi);
-
-  return 0;
+  return TRUE;
 }
 
 BOOL FASTCALL 
-IntDestroyScrollBar(PWINDOW_OBJECT Window, LONG idObject)
+IntDestroyScrollBars(PWINDOW_OBJECT Window)
 {
-  switch(idObject)
+  if(Window->Scroll)
   {
-    case SB_HORZ:
-      if(Window->pHScroll)
-      {
-        ExFreePool(Window->pHScroll);
-        Window->pHScroll = NULL;
-        return TRUE;
-      }
-      return FALSE;
-    case SB_VERT:
-      if(Window->pVScroll)
-      {
-        ExFreePool(Window->pVScroll);
-        Window->pVScroll = NULL;
-        return TRUE;
-      }
-      return FALSE;
-    case SB_CTL:
-      if(Window->wExtra)
-      {
-        ExFreePool(Window->wExtra);
-        Window->wExtra = NULL;
-        return TRUE;
-      }
-      return FALSE;
+    ExFreePool(Window->Scroll);
+    Window->Scroll = NULL;
+    return TRUE;
   }
   return FALSE;
 }
 
-#define CHANGERGSTATE(item, status) \
-  if(Info->rgstate[(item)] != (status)) \
-    Chg = TRUE; \
-  Info->rgstate[(item)] = (status); 
-
-
 BOOL STDCALL
 IntEnableScrollBar(BOOL Horz, PSCROLLBARINFO Info, UINT wArrows)
 {
@@ -672,7 +608,13 @@ NtUserGetScrollInfo(HWND hwnd, int fnBar, LPSCROLLINFO lpsi)
     return FALSE;
   }
   
-  Ret = IntGetScrollInfo(Window, fnBar, &psi);
+  if(fnBar == SB_CTL)
+  {
+    IntSendMessage(Window->Self, SBM_GETSCROLLINFO, 0, (LPARAM)lpsi);
+    Ret = TRUE;
+  }
+  else
+    Ret = IntGetScrollInfo(Window, fnBar, &psi);
   
   IntReleaseWindowObject(Window);
   
@@ -706,19 +648,37 @@ NtUserEnableScrollBar(
     return FALSE;
   }
   
+  if(wSBflags == SB_CTL)
+  {
+    /* FIXME */
+    IntReleaseWindowObject(Window);
+    return FALSE;
+  }
+  
+  if(wSBflags != SB_BOTH && !SBID_IS_VAILD(wSBflags))
+  {
+    IntReleaseWindowObject(Window);
+    SetLastWin32Error(ERROR_INVALID_PARAMETER);
+    DPRINT1("Trying to set scrollinfo for unknown scrollbar type %d", wSBflags);
+    return FALSE;
+  }
+  
+  if(!IntCreateScrollBars(Window))
+    {
+      IntReleaseWindowObject(Window);
+      return FALSE;
+    }
+  
   switch(wSBflags)
   {
     case SB_BOTH:
-      InfoV = Window->pVScroll;
+      InfoV = IntGetScrollbarInfoFromWindow(Window, SB_VERT);
       /* fall through */
     case SB_HORZ:
-      InfoH = Window->pHScroll;
+      InfoH = IntGetScrollbarInfoFromWindow(Window, SB_HORZ);
       break;
     case SB_VERT:
-      InfoV = Window->pVScroll;
-      break;
-    case SB_CTL:
-      InfoV = Window->wExtra;
+      InfoV = IntGetScrollbarInfoFromWindow(Window, SB_VERT);
       break;
     default:
       IntReleaseWindowObject(Window);
@@ -747,9 +707,10 @@ NtUserSetScrollBarInfo(
 {
   PWINDOW_OBJECT Window;
   SETSCROLLBARINFO Safeinfo;
-  PSCROLLBARINFO sbi = NULL;
+  PSCROLLBARINFO sbi;
   LPSCROLLINFO psi;
   NTSTATUS Status;
+  LONG Obj;
   
   Window = IntGetWindowObject(hwnd);
 
@@ -759,41 +720,31 @@ NtUserSetScrollBarInfo(
     return FALSE;
   }
   
-  Status = MmCopyFromCaller(&Safeinfo, info, sizeof(SETSCROLLBARINFO));
-  if(!NT_SUCCESS(Status))
+  Obj = SBOBJ_TO_SBID(idObject);
+  if(!SBID_IS_VAILD(Obj))
   {
     IntReleaseWindowObject(Window);
-    SetLastNtError(Status);
+    SetLastWin32Error(ERROR_INVALID_PARAMETER);
+    DPRINT1("Trying to set scrollinfo for unknown scrollbar type %d", Obj);
     return FALSE;
   }
-  
-  switch(idObject)
-  {
-    case OBJID_HSCROLL:
-      sbi = Window->pHScroll;
-      break;
-    case OBJID_VSCROLL:
-      sbi = Window->pVScroll;
-      break;
-    case OBJID_CLIENT:
-      /* FIXME */
-      IntReleaseWindowObject(Window);
-      return FALSE;
 
-    default:
+  if(!IntCreateScrollBars(Window))
+    {
       IntReleaseWindowObject(Window);
-      SetLastWin32Error(ERROR_INVALID_PARAMETER);
       return FALSE;
-  }
+    }
   
-  if(!sbi)
+  Status = MmCopyFromCaller(&Safeinfo, info, sizeof(SETSCROLLBARINFO));
+  if(!NT_SUCCESS(Status))
   {
-    DPRINT1("SCROLLBARINFO structure not allocated!\n");
     IntReleaseWindowObject(Window);
+    SetLastNtError(Status);
     return FALSE;
   }
   
-  psi = (LPSCROLLINFO)((PSCROLLBARINFO)(sbi + 1));
+  sbi = IntGetScrollbarInfoFromWindow(Window, Obj);
+  psi = IntGetScrollInfoFromWindow(Window, Obj);
   
   psi->nTrackPos = Safeinfo.nTrackPos;
   sbi->reserved = Safeinfo.reserved;
@@ -824,6 +775,13 @@ NtUserSetScrollInfo(
     return 0;
   }
   
+  if(fnBar == SB_CTL)
+  {
+    Ret = IntSendMessage(hwnd, SBM_SETSCROLLINFO, (WPARAM)bRedraw, (LPARAM)lpsi);
+    IntReleaseWindowObject(Window);
+    return Ret;
+  }
+  
   Status = MmCopyFromCaller(&ScrollInfo, lpsi, sizeof(SCROLLINFO) - sizeof(ScrollInfo.nTrackPos));
   if(!NT_SUCCESS(Status))
   {
@@ -842,6 +800,7 @@ NtUserSetScrollInfo(
 DWORD STDCALL
 NtUserShowScrollBar(HWND hWnd, int wBar, DWORD bShow)
 {
+   DWORD Style, OldStyle;
    PWINDOW_OBJECT Window = IntGetWindowObject(hWnd);
 
    if (!Window)
@@ -849,46 +808,62 @@ NtUserShowScrollBar(HWND hWnd, int wBar, DWORD bShow)
       SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE);
       return FALSE;
    }
+   
+   switch(wBar)
+   {
+     case SB_HORZ:
+       Style = WS_HSCROLL;
+       break;
+     case SB_VERT:
+       Style = WS_VSCROLL;
+       break;
+     case SB_BOTH:
+       Style = WS_HSCROLL | WS_VSCROLL;
+       break;
+     case SB_CTL:
+       break;
+     default:
+       IntReleaseWindowObject(Window);
+       SetLastWin32Error(ERROR_INVALID_PARAMETER);
+       return FALSE;
+   }
+   
+  if(!IntCreateScrollBars(Window))
+    {
+      IntReleaseWindowObject(Window);
+      return FALSE;
+    }
 
    if (wBar == SB_CTL)
    {
+      IntUpdateSBInfo(Window, SB_CTL);
+      
       WinPosShowWindow(hWnd, bShow ? SW_SHOW : SW_HIDE);
       IntReleaseWindowObject(Window);
       return TRUE;
    }
-
-   if (wBar == SB_BOTH || wBar == SB_HORZ)
+   
+   OldStyle = Window->Style;
+   if(bShow)
+     Window->Style |= Style;
+   else
+     Window->Style &= ~Style;
+   
+   if(Window->Style != OldStyle)
    {
-      if (bShow)
-      {
-         Window->Style |= WS_HSCROLL;
-         if (!Window->pHScroll)
-            IntCreateScrollBar(Window, SB_HORZ);
-      }
-      else
-      {
-         Window->Style &= ~WS_HSCROLL;
-      }
+     if(Window->Style & WS_HSCROLL)
+       IntUpdateSBInfo(Window, SB_HORZ);
+     if(Window->Style & WS_VSCROLL)
+       IntUpdateSBInfo(Window, SB_VERT);
+     
+     if(Window->Style & WS_VISIBLE)
+     {
+       /* Frame has been changed, let the window redraw itself */
+       WinPosSetWindowPos(hWnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
+          SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOSENDCHANGING);
+     }
    }
-
-   if (wBar == SB_BOTH || wBar == SB_VERT)
-   {
-      if (bShow)
-      {
-         Window->Style |= WS_VSCROLL;
-         if (!Window->pVScroll)
-            IntCreateScrollBar(Window, SB_VERT);
-      }
-      else
-      {
-         Window->Style &= ~WS_VSCROLL;
-      }
-   }
-
-   /* Frame has been changed, let the window redraw itself */
-   WinPosSetWindowPos(hWnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
-      SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOSENDCHANGING);
-
+   
    IntReleaseWindowObject(Window);
    return TRUE;
 }
index 94b68e7..7895d82 100644 (file)
@@ -16,7 +16,7 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
-/* $Id: window.c,v 1.218 2004/04/14 23:17:56 weiden Exp $
+/* $Id: window.c,v 1.219 2004/04/17 11:00:14 weiden Exp $
  *
  * COPYRIGHT:        See COPYING in the top level directory
  * PROJECT:          ReactOS kernel
@@ -410,8 +410,7 @@ static LRESULT IntDestroyWindow(PWINDOW_OBJECT Window,
   IntReferenceWindowObject(Window);
   ObmCloseHandle(ProcessData->WindowStation->HandleTable, Window->Self);
   
-  IntDestroyScrollBar(Window, SB_VERT);
-  IntDestroyScrollBar(Window, SB_HORZ);
+  IntDestroyScrollBars(Window);
   
   IntLockThreadWindows(Window->OwnerThread->Win32Thread);
   Window->Status |= WINDOWSTATUS_DESTROYED;
@@ -1648,18 +1647,6 @@ NtUserCreateWindowEx(DWORD dwExStyle,
   WindowObject->ClientRect = WindowObject->WindowRect;
 
   /* FIXME: Initialize the window menu. */
-  
-  /* Initialize the window's scrollbars */
-  if (dwStyle & WS_VSCROLL)
-  {
-     WindowObject->Style &= ~WS_VSCROLL;
-     NtUserShowScrollBar(WindowObject->Self, SB_VERT, TRUE);
-  }
-  if (dwStyle & WS_HSCROLL)
-  {
-     WindowObject->Style &= ~WS_HSCROLL;
-     NtUserShowScrollBar(WindowObject->Self, SB_HORZ, TRUE);
-  }
 
   /* Send a NCCREATE message. */
   Cs.cx = nWidth;
@@ -1822,7 +1809,17 @@ NtUserCreateWindowEx(DWORD dwExStyle,
     {
       IntReleaseWindowObject(ParentWindow);
     }
-
+  
+  /* Initialize and show the window's scrollbars */
+  if (WindowObject->Style & WS_VSCROLL)
+  {
+     NtUserShowScrollBar(WindowObject->Self, SB_VERT, TRUE);
+  }
+  if (WindowObject->Style & WS_HSCROLL)
+  {
+     NtUserShowScrollBar(WindowObject->Self, SB_HORZ, TRUE);
+  }
+  
   if (dwStyle & WS_VISIBLE)
     {
       DPRINT("NtUserCreateWindow(): About to show window\n");