user32: combine horizontal and vertical window scroll bar info in a single structure.

Rein Klazes wijn at online.nl
Fri May 1 00:03:18 CDT 2009


Fixes bug #18102
---
 dlls/user32/defwnd.c       |    5 ++---
 dlls/user32/scroll.c       |   42 +++++++++++++++++++++++++++++++-----------
 dlls/user32/tests/scroll.c |   14 ++++++--------
 dlls/user32/win.c          |    3 +--
 dlls/user32/win.h          |    3 +--
 5 files changed, 41 insertions(+), 26 deletions(-)

diff --git a/dlls/user32/defwnd.c b/dlls/user32/defwnd.c
index e3ec37c..bf30c97 100644
--- a/dlls/user32/defwnd.c
+++ b/dlls/user32/defwnd.c
@@ -406,9 +406,8 @@ static LRESULT DEFWND_DefWinProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPa
             if (!wndPtr) return 0;
             HeapFree( GetProcessHeap(), 0, wndPtr->text );
             wndPtr->text = NULL;
-            HeapFree( GetProcessHeap(), 0, wndPtr->pVScroll );
-            HeapFree( GetProcessHeap(), 0, wndPtr->pHScroll );
-            wndPtr->pVScroll = wndPtr->pHScroll = NULL;
+            HeapFree( GetProcessHeap(), 0, wndPtr->pScroll );
+            wndPtr->pScroll = NULL;
             WIN_ReleasePtr( wndPtr );
             return 0;
         }
diff --git a/dlls/user32/scroll.c b/dlls/user32/scroll.c
index 91adb74..d7c891f 100644
--- a/dlls/user32/scroll.c
+++ b/dlls/user32/scroll.c
@@ -41,6 +41,7 @@
 
 WINE_DEFAULT_DEBUG_CHANNEL(scroll);
 
+/* data for a single scroll bar */
 typedef struct
 {
     INT   curVal;   /* Current scroll-bar value */
@@ -50,6 +51,12 @@ typedef struct
     UINT  flags;    /* EnableScrollBar flags */
 } SCROLLBAR_INFO, *LPSCROLLBAR_INFO;
 
+/* data for window that has (one or two) scroll bars */
+typedef struct
+{
+    SCROLLBAR_INFO HorzSBInfo;
+    SCROLLBAR_INFO VertSBInfo;
+} WINSCROLLBAR_INFO, *LPWINSCROLLBAR_INFO;
 
   /* Minimum size of the rectangle between the arrows */
 #define SCROLL_MIN_RECT  4
@@ -151,31 +158,44 @@ static inline BOOL SCROLL_ScrollInfoValid( LPCSCROLLINFO info )
 static SCROLLBAR_INFO *SCROLL_GetInternalInfo( HWND hwnd, INT nBar, BOOL alloc )
 {
     SCROLLBAR_INFO *infoPtr = NULL;
+    LPWINSCROLLBAR_INFO winInfoPtr;
     WND *wndPtr = WIN_GetPtr( hwnd );
 
     if (!wndPtr || wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return NULL;
     switch(nBar)
     {
-        case SB_HORZ: infoPtr = wndPtr->pHScroll; break;
-        case SB_VERT: infoPtr = wndPtr->pVScroll; break;
+        case SB_HORZ: if( wndPtr->pScroll)
+                          infoPtr = &((LPWINSCROLLBAR_INFO)wndPtr->pScroll)->HorzSBInfo;
+                      break;
+        case SB_VERT: if( wndPtr->pScroll)
+                          infoPtr = &((LPWINSCROLLBAR_INFO)wndPtr->pScroll)->VertSBInfo;
+                      break;
         case SB_CTL:  infoPtr = (SCROLLBAR_INFO *)wndPtr->wExtra; break;
         case SB_BOTH: WARN("with SB_BOTH\n"); break;
     }
 
-    if (!infoPtr && alloc)
+    if (!infoPtr && ( alloc || (wndPtr->dwStyle & (WS_VSCROLL | WS_HSCROLL))))
     {
         if (nBar != SB_HORZ && nBar != SB_VERT)
             WARN("Cannot initialize nBar=%d\n",nBar);
-        else if ((infoPtr = HeapAlloc( GetProcessHeap(), 0, sizeof(SCROLLBAR_INFO) )))
+        else if ((winInfoPtr = HeapAlloc( GetProcessHeap(), 0, sizeof(WINSCROLLBAR_INFO) )))
         {
             /* Set default values */
-            infoPtr->minVal = infoPtr->curVal = infoPtr->page = 0;
-            /* From MSDN: max for a standard scroll bar is 100 by default. */
-            infoPtr->maxVal = 100;
-            /* Scroll bar is enabled by default after create */
-            infoPtr->flags  = ESB_ENABLE_BOTH;
-            if (nBar == SB_HORZ) wndPtr->pHScroll = infoPtr;
-            else wndPtr->pVScroll = infoPtr;
+            winInfoPtr->HorzSBInfo.minVal = 0;
+            winInfoPtr->HorzSBInfo.curVal = 0;
+            winInfoPtr->HorzSBInfo.page = 0;
+            /* From MSDN and our own tests: 
+             * max for a standard scroll bar is 100 by default. */
+            winInfoPtr->HorzSBInfo.maxVal = 100;
+            winInfoPtr->VertSBInfo.minVal = 0;
+            winInfoPtr->VertSBInfo.curVal = 0;
+            winInfoPtr->VertSBInfo.page = 0;
+            winInfoPtr->VertSBInfo.maxVal = 100;
+            /* tests: Scroll bars are enabled by default after create */
+            winInfoPtr->HorzSBInfo.flags  = ESB_ENABLE_BOTH;
+            winInfoPtr->VertSBInfo.flags  = ESB_ENABLE_BOTH;
+            wndPtr->pScroll = winInfoPtr;
+            infoPtr = nBar == SB_HORZ ? &winInfoPtr->HorzSBInfo : &winInfoPtr->VertSBInfo;
         }
     }
     WIN_ReleasePtr( wndPtr );
diff --git a/dlls/user32/tests/scroll.c b/dlls/user32/tests/scroll.c
index dee57a1..e3f679a 100644
--- a/dlls/user32/tests/scroll.c
+++ b/dlls/user32/tests/scroll.c
@@ -274,13 +274,11 @@ static void scrollbar_test_default( DWORD style)
     ret = GetScrollRange( hwnd, SB_HORZ, &min, &max);
     ok( ret, "GetScrollRange failed.\n");
     /* now the range should be 0,100 in ALL cases */
-todo_wine
     ok( min == 0 && max == 100,
             "Scroll bar range is %d,%d. Expected 0,100. Style %08x\n", min, max, style);
     /* See what is different now for GetScrollRange */
     ret = GetScrollInfo( hwnd, SB_HORZ, &si);
     /* should succeed in ALL cases */
-todo_wine
     ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
     ret = GetScrollInfo( hwnd, SB_VERT, &si);
     /* should succeed in ALL cases */
@@ -299,7 +297,6 @@ todo_wine
     ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
     ok( ret, "GetScrollRange failed.\n");
     /* now the range should be 0,100 in ALL cases */
-todo_wine
     ok( min == 0 && max == 100,
             "Scroll bar range is %d,%d. Expected 0,100. Style %08x\n", min, max, style);
     /* See what is different now for GetScrollRange */
@@ -308,7 +305,6 @@ todo_wine
     ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
     ret = GetScrollInfo( hwnd, SB_VERT, &si);
     /* should succeed in ALL cases */
-todo_wine
     ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
     /* Slightly change the test to muse SetScrollInfo
      * Start with a clean window */
@@ -327,7 +323,6 @@ todo_wine
     ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
     ok( ret, "GetScrollRange failed.\n");
     /* now the range should be 0,100 in ALL cases */
-todo_wine
     ok( min == 0 && max == 100,
             "Scroll bar range is %d,%d. Expected 0,100. Style %08x\n", min, max, style);
     /* See what is different now for GetScrollRange */
@@ -336,8 +331,12 @@ todo_wine
     ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
     ret = GetScrollInfo( hwnd, SB_VERT, &si);
     /* should succeed in ALL cases */
-todo_wine
     ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
+    /* finally test if the window scroll bars are enabled */
+    ret = EnableScrollBar( hwnd, SB_VERT, ESB_ENABLE_BOTH);
+    ok( !ret, "Vertical window scroll bar was not enabled\n");
+    ret = EnableScrollBar( hwnd, SB_HORZ, ESB_ENABLE_BOTH);
+    ok( !ret, "Horizontal window scroll bar was not enabled\n");
      /* clean up */
     DestroyWindow( hwnd);
 }
@@ -374,11 +373,10 @@ START_TEST ( scroll )
     scrollbar_test4();
 
     scrollbar_test_default( 0);
-if( 0) { /* enable this when the todo's in scrollbar_test_default are fixed */
     scrollbar_test_default( WS_HSCROLL);
     scrollbar_test_default( WS_VSCROLL);
     scrollbar_test_default( WS_HSCROLL | WS_VSCROLL);
-}
+
     DestroyWindow(hScroll);
     DestroyWindow(hMainWnd);
 }
diff --git a/dlls/user32/win.c b/dlls/user32/win.c
index ab0ab59..7e599ba 100644
--- a/dlls/user32/win.c
+++ b/dlls/user32/win.c
@@ -1073,8 +1073,7 @@ static HWND WIN_CreateWindowEx( CREATESTRUCTA *cs, LPCWSTR className, UINT flags
     wndPtr->dwExStyle      = cs->dwExStyle;
     wndPtr->wIDmenu        = 0;
     wndPtr->helpContext    = 0;
-    wndPtr->pVScroll       = NULL;
-    wndPtr->pHScroll       = NULL;
+    wndPtr->pScroll        = NULL;
     wndPtr->userdata       = 0;
     wndPtr->hIcon          = 0;
     wndPtr->hIconSmall     = 0;
diff --git a/dlls/user32/win.h b/dlls/user32/win.h
index 447f4fd..5cd879a 100644
--- a/dlls/user32/win.h
+++ b/dlls/user32/win.h
@@ -51,8 +51,7 @@ typedef struct tagWND
     POINT          max_pos;       /* Position for maximized window */
     HWND           icon_title;    /* Icon title window */
     LPWSTR         text;          /* Window text */
-    void          *pVScroll;      /* Vertical scroll-bar info */
-    void          *pHScroll;      /* Horizontal scroll-bar info */
+    void          *pScroll;       /* Scroll-bar info */
     DWORD          dwStyle;       /* Window style (from CreateWindow) */
     DWORD          dwExStyle;     /* Extended style (from CreateWindowEx) */
     UINT_PTR       wIDmenu;       /* ID or hmenu (from CreateWindow) */
-- 
1.6.2.1




More information about the wine-patches mailing list