2 * Unit tests for scrollbar
4 * Copyright 2008 Lyutin Anatoly (Etersoft)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wine/test.h"
28 static HWND hScroll, hMainWnd;
29 static BOOL bThemeActive = FALSE;
31 static LRESULT CALLBACK MyWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
38 hScroll = CreateWindowA( "SCROLLBAR", "", WS_CHILD | WS_VISIBLE, 0, 0, 120, 100, hWnd, (HMENU)100, GetModuleHandleA(0), 0 );
47 return DefWindowProcA(hWnd, msg, wParam, lParam);
52 static void scrollbar_test1(void)
56 ret = EnableScrollBar( hScroll, SB_CTL, ESB_DISABLE_BOTH );
57 ok( ret, "The scrollbar should be disabled.\n" );
58 ok( !IsWindowEnabled( hScroll ), "The scrollbar window should be disabled.\n" );
60 ret = EnableScrollBar( hScroll, SB_CTL, ESB_ENABLE_BOTH );
61 ok( ret, "The scrollbar should be enabled.\n" );
62 ok( IsWindowEnabled( hScroll ), "The scrollbar window should be enabled.\n" );
64 /* test buttons separately */
65 ret = EnableScrollBar( hScroll, SB_CTL, ESB_DISABLE_LTUP );
66 ok( ret, "The scrollbar LTUP button should be disabled.\n" );
67 ok( IsWindowEnabled( hScroll ), "The scrollbar window should be enabled.\n" );
68 ret = EnableScrollBar( hScroll, SB_CTL, ESB_ENABLE_BOTH );
69 ok( ret, "The scrollbar should be enabled.\n" );
70 ok( IsWindowEnabled( hScroll ), "The scrollbar window should be enabled.\n" );
72 ret = EnableScrollBar( hScroll, SB_CTL, ESB_DISABLE_RTDN );
73 ok( ret, "The scrollbar RTDN button should be disabled.\n" );
74 ok( IsWindowEnabled( hScroll ), "The scrollbar window should be enabled.\n" );
75 ret = EnableScrollBar( hScroll, SB_CTL, ESB_ENABLE_BOTH );
76 ok( ret, "The scrollbar should be enabled.\n" );
77 ok( IsWindowEnabled( hScroll ), "The scrollbar window should be enabled.\n" );
80 static void scrollbar_test2(void)
84 trace("The scrollbar is disabled.\n");
86 EnableWindow( hScroll, FALSE );
87 ok( !IsWindowEnabled( hScroll ), "The scroll should be disabled.\n" );
89 ret = SetScrollPos( hScroll, SB_CTL, 30, TRUE);
90 ok( !ret, "The position should not be set.\n" );
92 ret = GetScrollPos( hScroll, SB_CTL);
93 ok( !ret, "The position should be equal to zero\n");
95 ret = SetScrollRange( hScroll, SB_CTL, 0, 100, TRUE );
96 ok( ret, "The range should be set.\n" );
98 ret = SetScrollPos( hScroll, SB_CTL, 30, TRUE);
99 ok( !ret , "The position should not be set.\n" );
101 ret = GetScrollPos( hScroll, SB_CTL);
102 ok( ret == 30, "The position should be set!!!\n");
104 trace("The scrollbar is enabled.\n");
106 EnableWindow( hScroll, TRUE );
107 ok( IsWindowEnabled( hScroll ), "The scroll should be enabled.\n" );
109 ret = SetScrollPos( hScroll, SB_CTL, 30, TRUE);
110 ok( ret == 30, "The position should be set.\n" );
112 ret = GetScrollPos( hScroll, SB_CTL);
113 ok( ret == 30, "The position should not be equal to zero\n");
115 ret = SetScrollRange( hScroll, SB_CTL, 0, 100, TRUE );
116 ok( ret, "The range should be set.\n" );
118 ret = SetScrollPos( hScroll, SB_CTL, 30, TRUE);
119 ok( ret == 30, "The position should be set.\n" );
121 ret = GetScrollPos( hScroll, SB_CTL);
122 ok( ret == 30, "The position should not be equal to zero\n");
125 static void scrollbar_test3(void)
129 ret = ShowScrollBar( hScroll, SB_CTL, FALSE );
130 ok( ret, "The ShowScrollBar() should not failed.\n" );
131 ok( !IsWindowVisible( hScroll ), "The scrollbar window should not be visible\n" );
133 ret = ShowScrollBar( hScroll, SB_CTL, TRUE );
134 ok( ret, "The ShowScrollBar() should not failed.\n" );
135 ok( !IsWindowVisible( hScroll ), "The scrollbar window should be visible\n" );
137 ret = ShowScrollBar( NULL, SB_CTL, TRUE );
138 ok( !ret, "The ShowScrollBar() should failed.\n" );
142 static void scrollbar_test4(void)
147 BOOL (WINAPI *pGetScrollBarInfo)(HWND, LONG, LPSCROLLBARINFO);
149 pGetScrollBarInfo = (void*)GetProcAddress(GetModuleHandleA("user32.dll"), "GetScrollBarInfo");
150 if (!pGetScrollBarInfo)
152 win_skip("GetScrollBarInfo is not available\n");
156 /* Test GetScrollBarInfo to make sure it returns rcScrollBar in screen
158 sbi.cbSize = sizeof(sbi);
159 ret = pGetScrollBarInfo( hScroll, OBJID_CLIENT, &sbi);
160 ok( ret, "The GetScrollBarInfo() call should not fail.\n" );
161 GetWindowRect( hScroll, &rect );
162 ok( ret, "The GetWindowRect() call should not fail.\n" );
163 ok( !(sbi.rgstate[0] & (STATE_SYSTEM_INVISIBLE|STATE_SYSTEM_OFFSCREEN)),
164 "unexpected rgstate(0x%x)\n", sbi.rgstate[0]);
165 ok( EqualRect(&rect, &sbi.rcScrollBar),
166 "WindowRect(%d, %d, %d, %d) != rcScrollBar(%d, %d, %d, %d)\n",
167 rect.top, rect.left, rect.bottom, rect.right,
168 sbi.rcScrollBar.top, sbi.rcScrollBar.left,
169 sbi.rcScrollBar.bottom, sbi.rcScrollBar.right );
171 /* Test windows horizontal and vertical scrollbar to make sure rcScrollBar
172 * is still returned in screen coordinates by moving the window, and
173 * making sure that it shifts the rcScrollBar value. */
174 ShowWindow( hMainWnd, SW_SHOW );
175 sbi.cbSize = sizeof(sbi);
176 ret = pGetScrollBarInfo( hMainWnd, OBJID_HSCROLL, &sbi);
177 ok( ret, "The GetScrollBarInfo() call should not fail.\n" );
178 GetWindowRect( hMainWnd, &rect );
179 ok( ret, "The GetWindowRect() call should not fail.\n" );
180 MoveWindow( hMainWnd, rect.left+5, rect.top+5,
181 rect.right-rect.left, rect.bottom-rect.top, TRUE );
182 rect = sbi.rcScrollBar;
183 OffsetRect(&rect, 5, 5);
184 ret = pGetScrollBarInfo( hMainWnd, OBJID_HSCROLL, &sbi);
185 ok( ret, "The GetScrollBarInfo() call should not fail.\n" );
186 ok( EqualRect(&rect, &sbi.rcScrollBar),
187 "PreviousRect(%d, %d, %d, %d) != CurrentRect(%d, %d, %d, %d)\n",
188 rect.top, rect.left, rect.bottom, rect.right,
189 sbi.rcScrollBar.top, sbi.rcScrollBar.left,
190 sbi.rcScrollBar.bottom, sbi.rcScrollBar.right );
192 sbi.cbSize = sizeof(sbi);
193 ret = pGetScrollBarInfo( hMainWnd, OBJID_VSCROLL, &sbi);
194 ok( ret, "The GetScrollBarInfo() call should not fail.\n" );
195 GetWindowRect( hMainWnd, &rect );
196 ok( ret, "The GetWindowRect() call should not fail.\n" );
197 MoveWindow( hMainWnd, rect.left+5, rect.top+5,
198 rect.right-rect.left, rect.bottom-rect.top, TRUE );
199 rect = sbi.rcScrollBar;
200 OffsetRect(&rect, 5, 5);
201 ret = pGetScrollBarInfo( hMainWnd, OBJID_VSCROLL, &sbi);
202 ok( ret, "The GetScrollBarInfo() call should not fail.\n" );
203 ok( EqualRect(&rect, &sbi.rcScrollBar),
204 "PreviousRect(%d, %d, %d, %d) != CurrentRect(%d, %d, %d, %d)\n",
205 rect.top, rect.left, rect.bottom, rect.right,
206 sbi.rcScrollBar.top, sbi.rcScrollBar.left,
207 sbi.rcScrollBar.bottom, sbi.rcScrollBar.right );
210 /* some tests designed to show that Horizontal and Vertical
211 * window scroll bar info are not created independently */
212 static void scrollbar_test_default( DWORD style)
217 SCROLLINFO si = { sizeof( SCROLLINFO), SIF_TRACKPOS };
219 hwnd = CreateWindowExA( 0, "static", "", WS_POPUP | style,
220 0, 0, 10, 10, 0, 0, 0, NULL);
223 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
225 broken( !ret) /* Win 98/ME */ , "GetScrollRange failed.\n");
226 /* range is 0,0 if there are no H or V scroll bars. 0,100 otherwise */
227 if( !( style & ( WS_VSCROLL | WS_HSCROLL)))
228 ok( min == 0 && max == 0,
229 "Scroll bar range is %d,%d. Expected 0,0. Style %08x\n", min, max, style);
232 ok( min == 0 && max == 100,
233 "Scroll bar range is %d,%d. Expected 0,100. Style %08x\n", min, max, style);
234 ret = GetScrollRange( hwnd, SB_HORZ, &min, &max);
236 broken( !ret) /* Win 98/ME */ , "GetScrollRange failed.\n");
237 /* range is 0,0 if there are no H or V scroll bars. 0,100 otherwise */
238 if( !( style & ( WS_VSCROLL | WS_HSCROLL)))
239 ok( min == 0 && max == 0,
240 "Scroll bar range is %d,%d. Expected 0,0. Style %08x\n", min, max, style);
243 ok( min == 0 && max == 100,
244 "Scroll bar range is %d,%d. Expected 0,100. Style %08x\n", min, max, style);
245 /* test GetScrollInfo, vist for vertical SB */
246 ret = GetScrollInfo( hwnd, SB_VERT, &si);
247 /* should fail if no H orV scroll bar styles are present. Succeed otherwise */
248 if( !( style & ( WS_VSCROLL | WS_HSCROLL)))
249 ok( !ret, "GetScrollInfo succeeded unexpectedly. Style is %08x\n", style);
252 ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
253 /* Same for Horizontal SB */
254 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
255 /* should fail if no H orV scroll bar styles are present. Succeed otherwise */
256 if( !( style & ( WS_VSCROLL | WS_HSCROLL)))
257 ok( !ret, "GetScrollInfo succeeded unexpectedly. Style is %08x\n", style);
260 ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
261 /* now set the Vertical Scroll range to something that could be the default value it
263 ret = SetScrollRange( hwnd, SB_VERT, 0, 100, FALSE);
264 ok( ret, "SetScrollRange failed.\n");
265 /* and request the Horizontal range */
266 ret = GetScrollRange( hwnd, SB_HORZ, &min, &max);
267 ok( ret, "GetScrollRange failed.\n");
268 /* now the range should be 0,100 in ALL cases */
269 ok( min == 0 && max == 100,
270 "Scroll bar range is %d,%d. Expected 0,100. Style %08x\n", min, max, style);
271 /* See what is different now for GetScrollRange */
272 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
273 /* should succeed in ALL cases */
274 ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
275 ret = GetScrollInfo( hwnd, SB_VERT, &si);
276 /* should succeed in ALL cases */
277 ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
278 /* report the windows style */
279 winstyle = GetWindowLongW( hwnd, GWL_STYLE );
280 /* WS_VSCROLL added to the window style */
281 if( !(style & WS_VSCROLL))
283 if (bThemeActive || style != WS_HSCROLL)
285 ok( (winstyle & (WS_HSCROLL|WS_VSCROLL)) == ( style | WS_VSCROLL),
286 "unexpected style change %8lx expected %8lx\n",
287 (winstyle & (WS_HSCROLL|WS_VSCROLL)), style | WS_VSCROLL);
289 ok( (winstyle & (WS_HSCROLL|WS_VSCROLL)) == style,
290 "unexpected style change %8lx expected %8x\n",
291 (winstyle & (WS_HSCROLL|WS_VSCROLL)), style);
293 /* do the test again with H and V reversed.
294 * Start with a clean window */
295 DestroyWindow( hwnd);
296 hwnd = CreateWindowExA( 0, "static", "", WS_POPUP | style,
297 0, 0, 10, 10, 0, 0, 0, NULL);
299 /* Set Horizonta Scroll range to something that could be the default value it
301 ret = SetScrollRange( hwnd, SB_HORZ, 0, 100, FALSE);
302 ok( ret, "SetScrollRange failed.\n");
303 /* and request the Vertical range */
304 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
305 ok( ret, "GetScrollRange failed.\n");
306 /* now the range should be 0,100 in ALL cases */
307 ok( min == 0 && max == 100,
308 "Scroll bar range is %d,%d. Expected 0,100. Style %08x\n", min, max, style);
309 /* See what is different now for GetScrollRange */
310 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
311 /* should succeed in ALL cases */
312 ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
313 ret = GetScrollInfo( hwnd, SB_VERT, &si);
314 /* should succeed in ALL cases */
315 ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
316 /* report the windows style */
317 winstyle = GetWindowLongW( hwnd, GWL_STYLE );
318 /* WS_HSCROLL added to the window style */
319 if( !(style & WS_HSCROLL))
321 if (bThemeActive || style != WS_VSCROLL)
323 ok( (winstyle & (WS_HSCROLL|WS_VSCROLL)) == ( style | WS_HSCROLL),
324 "unexpected style change %8lx expected %8lx\n",
325 (winstyle & (WS_HSCROLL|WS_VSCROLL)), style | WS_HSCROLL);
327 ok( (winstyle & (WS_HSCROLL|WS_VSCROLL)) == style,
328 "unexpected style change %8lx expected %8x\n",
329 (winstyle & (WS_HSCROLL|WS_VSCROLL)), style);
331 /* Slightly change the test to use SetScrollInfo
332 * Start with a clean window */
333 DestroyWindow( hwnd);
334 hwnd = CreateWindowExA( 0, "static", "", WS_POPUP | style,
335 0, 0, 10, 10, 0, 0, 0, NULL);
337 /* set Horizontal position with SetScrollInfo */
341 si.fMask |= SIF_RANGE;
342 ret = SetScrollInfo( hwnd, SB_HORZ, &si, FALSE);
343 ok( ret, "SetScrollInfo failed. Style is %08x\n", style);
344 /* and request the Vertical range */
345 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
346 ok( ret, "GetScrollRange failed.\n");
347 /* now the range should be 0,100 in ALL cases */
348 ok( min == 0 && max == 100,
349 "Scroll bar range is %d,%d. Expected 0,100. Style %08x\n", min, max, style);
350 /* See what is different now for GetScrollRange */
351 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
352 /* should succeed in ALL cases */
353 ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
354 ret = GetScrollInfo( hwnd, SB_VERT, &si);
355 /* should succeed in ALL cases */
356 ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
357 /* also test if the window scroll bars are enabled */
358 ret = EnableScrollBar( hwnd, SB_VERT, ESB_ENABLE_BOTH);
359 ok( !ret, "Vertical window scroll bar was not enabled\n");
360 ret = EnableScrollBar( hwnd, SB_HORZ, ESB_ENABLE_BOTH);
361 ok( !ret, "Horizontal window scroll bar was not enabled\n");
362 DestroyWindow( hwnd);
363 /* finally, check if adding a WS_[HV]SColl style of a window makes the scroll info
365 if( style & (WS_HSCROLL | WS_VSCROLL)) return;/* only test if not yet set */
366 /* Start with a clean window */
367 DestroyWindow( hwnd);
368 hwnd = CreateWindowExA( 0, "static", "", WS_POPUP ,
369 0, 0, 10, 10, 0, 0, 0, NULL);
371 ret = GetScrollInfo( hwnd, SB_VERT, &si);
373 ok( !ret, "GetScrollInfo succeeded unexpectedly. Style is %08x\n", style);
374 /* add scroll styles */
375 winstyle = GetWindowLongW( hwnd, GWL_STYLE );
376 SetWindowLongW( hwnd, GWL_STYLE, winstyle | WS_VSCROLL | WS_HSCROLL);
377 ret = GetScrollInfo( hwnd, SB_VERT, &si);
378 /* should still fail */
379 ok( !ret, "GetScrollInfo succeeded unexpectedly. Style is %08x\n", style);
381 DestroyWindow( hwnd);
384 START_TEST ( scroll )
388 BOOL (WINAPI * pIsThemeActive)(VOID);
390 wc.style = CS_HREDRAW | CS_VREDRAW;
393 wc.hInstance = GetModuleHandleA(NULL);
395 wc.hCursor = LoadCursorA(NULL, IDC_IBEAM);
396 wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
397 wc.lpszMenuName = NULL;
398 wc.lpszClassName = "MyTestWnd";
399 wc.lpfnWndProc = MyWndProc;
402 hMainWnd = CreateWindowExA( 0, "MyTestWnd", "Scroll",
403 WS_OVERLAPPEDWINDOW|WS_VSCROLL|WS_HSCROLL,
404 CW_USEDEFAULT, CW_USEDEFAULT, 100, 100, NULL, NULL, GetModuleHandleA(NULL), 0 );
406 if ( !ok( hMainWnd != NULL, "Failed to create parent window. Tests aborted.\n" ) )
416 /* Some test results vary depending of theming being active or not */
417 hUxtheme = LoadLibraryA("uxtheme.dll");
420 pIsThemeActive = (void*)GetProcAddress(hUxtheme, "IsThemeActive");
422 bThemeActive = pIsThemeActive();
423 FreeLibrary(hUxtheme);
426 scrollbar_test_default( 0);
427 scrollbar_test_default( WS_HSCROLL);
428 scrollbar_test_default( WS_VSCROLL);
429 scrollbar_test_default( WS_HSCROLL | WS_VSCROLL);
431 DestroyWindow(hScroll);
432 DestroyWindow(hMainWnd);