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 );
51 return DefWindowProcA(hWnd, msg, wParam, lParam);
55 static void scrollbar_test_track(void)
57 /* test that scrollbar tracking is terminated when
58 * the control looses mouse capture */
59 SendMessage( hScroll, WM_LBUTTONDOWN, 0, MAKELPARAM( 1, 1));
60 /* a normal return from the sendmessage */
61 /* not normal for instance by closing the windws */
62 ok( IsWindow( hScroll), "Scrollbar has gone!\n");
65 static void scrollbar_test1(void)
69 ret = EnableScrollBar( hScroll, SB_CTL, ESB_DISABLE_BOTH );
70 ok( ret, "The scrollbar should be disabled.\n" );
71 ok( !IsWindowEnabled( hScroll ), "The scrollbar window should be disabled.\n" );
73 ret = EnableScrollBar( hScroll, SB_CTL, ESB_ENABLE_BOTH );
74 ok( ret, "The scrollbar should be enabled.\n" );
75 ok( IsWindowEnabled( hScroll ), "The scrollbar window should be enabled.\n" );
77 /* test buttons separately */
78 ret = EnableScrollBar( hScroll, SB_CTL, ESB_DISABLE_LTUP );
79 ok( ret, "The scrollbar LTUP button should be disabled.\n" );
80 ok( IsWindowEnabled( hScroll ), "The scrollbar window should be enabled.\n" );
81 ret = EnableScrollBar( hScroll, SB_CTL, ESB_ENABLE_BOTH );
82 ok( ret, "The scrollbar should be enabled.\n" );
83 ok( IsWindowEnabled( hScroll ), "The scrollbar window should be enabled.\n" );
85 ret = EnableScrollBar( hScroll, SB_CTL, ESB_DISABLE_RTDN );
86 ok( ret, "The scrollbar RTDN button should be disabled.\n" );
87 ok( IsWindowEnabled( hScroll ), "The scrollbar window should be enabled.\n" );
88 ret = EnableScrollBar( hScroll, SB_CTL, ESB_ENABLE_BOTH );
89 ok( ret, "The scrollbar should be enabled.\n" );
90 ok( IsWindowEnabled( hScroll ), "The scrollbar window should be enabled.\n" );
93 static void scrollbar_test2(void)
97 trace("The scrollbar is disabled.\n");
99 EnableWindow( hScroll, FALSE );
100 ok( !IsWindowEnabled( hScroll ), "The scroll should be disabled.\n" );
102 ret = SetScrollPos( hScroll, SB_CTL, 30, TRUE);
103 ok( !ret, "The position should not be set.\n" );
105 ret = GetScrollPos( hScroll, SB_CTL);
106 ok( !ret, "The position should be equal to zero\n");
108 ret = SetScrollRange( hScroll, SB_CTL, 0, 100, TRUE );
109 ok( ret, "The range should be set.\n" );
111 ret = SetScrollPos( hScroll, SB_CTL, 30, TRUE);
112 ok( !ret , "The position should not be set.\n" );
114 ret = GetScrollPos( hScroll, SB_CTL);
115 ok( ret == 30, "The position should be set!!!\n");
117 trace("The scrollbar is enabled.\n");
119 EnableWindow( hScroll, TRUE );
120 ok( IsWindowEnabled( hScroll ), "The scroll should be enabled.\n" );
122 ret = SetScrollPos( hScroll, SB_CTL, 30, TRUE);
123 ok( ret == 30, "The position should be set.\n" );
125 ret = GetScrollPos( hScroll, SB_CTL);
126 ok( ret == 30, "The position should not be equal to zero\n");
128 ret = SetScrollRange( hScroll, SB_CTL, 0, 100, TRUE );
129 ok( ret, "The range should be set.\n" );
131 ret = SetScrollPos( hScroll, SB_CTL, 30, TRUE);
132 ok( ret == 30, "The position should be set.\n" );
134 ret = GetScrollPos( hScroll, SB_CTL);
135 ok( ret == 30, "The position should not be equal to zero\n");
138 static void scrollbar_test3(void)
142 ret = ShowScrollBar( hScroll, SB_CTL, FALSE );
143 ok( ret, "The ShowScrollBar() should not failed.\n" );
144 ok( !IsWindowVisible( hScroll ), "The scrollbar window should not be visible\n" );
146 ret = ShowScrollBar( hScroll, SB_CTL, TRUE );
147 ok( ret, "The ShowScrollBar() should not failed.\n" );
148 ok( !IsWindowVisible( hScroll ), "The scrollbar window should be visible\n" );
150 ret = ShowScrollBar( NULL, SB_CTL, TRUE );
151 ok( !ret, "The ShowScrollBar() should failed.\n" );
155 static void scrollbar_test4(void)
160 BOOL (WINAPI *pGetScrollBarInfo)(HWND, LONG, LPSCROLLBARINFO);
162 pGetScrollBarInfo = (void*)GetProcAddress(GetModuleHandleA("user32.dll"), "GetScrollBarInfo");
163 if (!pGetScrollBarInfo)
165 win_skip("GetScrollBarInfo is not available\n");
169 /* Test GetScrollBarInfo to make sure it returns rcScrollBar in screen
171 sbi.cbSize = sizeof(sbi);
172 ret = pGetScrollBarInfo( hScroll, OBJID_CLIENT, &sbi);
173 ok( ret, "The GetScrollBarInfo() call should not fail.\n" );
174 GetWindowRect( hScroll, &rect );
175 ok( ret, "The GetWindowRect() call should not fail.\n" );
176 ok( !(sbi.rgstate[0] & (STATE_SYSTEM_INVISIBLE|STATE_SYSTEM_OFFSCREEN)),
177 "unexpected rgstate(0x%x)\n", sbi.rgstate[0]);
178 ok( EqualRect(&rect, &sbi.rcScrollBar),
179 "WindowRect(%d, %d, %d, %d) != rcScrollBar(%d, %d, %d, %d)\n",
180 rect.top, rect.left, rect.bottom, rect.right,
181 sbi.rcScrollBar.top, sbi.rcScrollBar.left,
182 sbi.rcScrollBar.bottom, sbi.rcScrollBar.right );
184 /* Test windows horizontal and vertical scrollbar to make sure rcScrollBar
185 * is still returned in screen coordinates by moving the window, and
186 * making sure that it shifts the rcScrollBar value. */
187 ShowWindow( hMainWnd, SW_SHOW );
188 sbi.cbSize = sizeof(sbi);
189 ret = pGetScrollBarInfo( hMainWnd, OBJID_HSCROLL, &sbi);
190 ok( ret, "The GetScrollBarInfo() call should not fail.\n" );
191 GetWindowRect( hMainWnd, &rect );
192 ok( ret, "The GetWindowRect() call should not fail.\n" );
193 MoveWindow( hMainWnd, rect.left+5, rect.top+5,
194 rect.right-rect.left, rect.bottom-rect.top, TRUE );
195 rect = sbi.rcScrollBar;
196 OffsetRect(&rect, 5, 5);
197 ret = pGetScrollBarInfo( hMainWnd, OBJID_HSCROLL, &sbi);
198 ok( ret, "The GetScrollBarInfo() call should not fail.\n" );
199 ok( EqualRect(&rect, &sbi.rcScrollBar),
200 "PreviousRect(%d, %d, %d, %d) != CurrentRect(%d, %d, %d, %d)\n",
201 rect.top, rect.left, rect.bottom, rect.right,
202 sbi.rcScrollBar.top, sbi.rcScrollBar.left,
203 sbi.rcScrollBar.bottom, sbi.rcScrollBar.right );
205 sbi.cbSize = sizeof(sbi);
206 ret = pGetScrollBarInfo( hMainWnd, OBJID_VSCROLL, &sbi);
207 ok( ret, "The GetScrollBarInfo() call should not fail.\n" );
208 GetWindowRect( hMainWnd, &rect );
209 ok( ret, "The GetWindowRect() call should not fail.\n" );
210 MoveWindow( hMainWnd, rect.left+5, rect.top+5,
211 rect.right-rect.left, rect.bottom-rect.top, TRUE );
212 rect = sbi.rcScrollBar;
213 OffsetRect(&rect, 5, 5);
214 ret = pGetScrollBarInfo( hMainWnd, OBJID_VSCROLL, &sbi);
215 ok( ret, "The GetScrollBarInfo() call should not fail.\n" );
216 ok( EqualRect(&rect, &sbi.rcScrollBar),
217 "PreviousRect(%d, %d, %d, %d) != CurrentRect(%d, %d, %d, %d)\n",
218 rect.top, rect.left, rect.bottom, rect.right,
219 sbi.rcScrollBar.top, sbi.rcScrollBar.left,
220 sbi.rcScrollBar.bottom, sbi.rcScrollBar.right );
223 /* some tests designed to show that Horizontal and Vertical
224 * window scroll bar info are not created independently */
225 static void scrollbar_test_default( DWORD style)
230 SCROLLINFO si = { sizeof( SCROLLINFO), SIF_TRACKPOS };
232 hwnd = CreateWindowExA( 0, "static", "", WS_POPUP | style,
233 0, 0, 10, 10, 0, 0, 0, NULL);
236 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
238 broken( !ret) /* Win 9x/ME */ , "GetScrollRange failed.\n");
239 /* range is 0,0 if there are no H or V scroll bars. 0,100 otherwise */
240 if( !( style & ( WS_VSCROLL | WS_HSCROLL)))
241 ok( min == 0 && max == 0,
242 "Scroll bar range is %d,%d. Expected 0,0. Style %08x\n", min, max, style);
245 ok(( min == 0 && max == 100) ||
246 broken( min == 0 && max == 0), /* Win 9x/ME */
247 "Scroll bar range is %d,%d. Expected 0,100. Style %08x\n", min, max, style);
248 ret = GetScrollRange( hwnd, SB_HORZ, &min, &max);
250 broken( !ret) /* Win 9x/ME */ , "GetScrollRange failed.\n");
251 /* range is 0,0 if there are no H or V scroll bars. 0,100 otherwise */
252 if( !( style & ( WS_VSCROLL | WS_HSCROLL)))
253 ok( min == 0 && max == 0,
254 "Scroll bar range is %d,%d. Expected 0,0. Style %08x\n", min, max, style);
257 ok(( min == 0 && max == 100) ||
258 broken( min == 0 && max == 0), /* Win 9x/ME */
259 "Scroll bar range is %d,%d. Expected 0,100. Style %08x\n", min, max, style);
260 /* test GetScrollInfo, vist for vertical SB */
261 ret = GetScrollInfo( hwnd, SB_VERT, &si);
262 /* should fail if no H orV scroll bar styles are present. Succeed otherwise */
263 if( !( style & ( WS_VSCROLL | WS_HSCROLL)))
264 ok( !ret, "GetScrollInfo succeeded unexpectedly. Style is %08x\n", style);
268 broken( !ret), /* Win 9x/ME */
269 "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
270 /* Same for Horizontal SB */
271 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
272 /* should fail if no H orV scroll bar styles are present. Succeed otherwise */
273 if( !( style & ( WS_VSCROLL | WS_HSCROLL)))
274 ok( !ret, "GetScrollInfo succeeded unexpectedly. Style is %08x\n", style);
278 broken( !ret), /* Win 9x/ME */
279 "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
280 /* now set the Vertical Scroll range to something that could be the default value it
282 ret = SetScrollRange( hwnd, SB_VERT, 0, 100, FALSE);
283 ok( ret, "SetScrollRange failed.\n");
284 /* and request the Horizontal range */
285 ret = GetScrollRange( hwnd, SB_HORZ, &min, &max);
286 ok( ret, "GetScrollRange failed.\n");
287 /* now the range should be 0,100 in ALL cases */
288 ok( min == 0 && max == 100,
289 "Scroll bar range is %d,%d. Expected 0,100. Style %08x\n", min, max, style);
290 /* See what is different now for GetScrollRange */
291 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
292 /* should succeed in ALL cases */
293 ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
294 ret = GetScrollInfo( hwnd, SB_VERT, &si);
295 /* should succeed in ALL cases */
296 ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
297 /* report the windows style */
298 winstyle = GetWindowLongA( hwnd, GWL_STYLE );
299 /* WS_VSCROLL added to the window style */
300 if( !(style & WS_VSCROLL))
302 if (bThemeActive || style != WS_HSCROLL)
304 ok( (winstyle & (WS_HSCROLL|WS_VSCROLL)) == ( style | WS_VSCROLL),
305 "unexpected style change %8lx expected %8lx\n",
306 (winstyle & (WS_HSCROLL|WS_VSCROLL)), style | WS_VSCROLL);
308 ok( (winstyle & (WS_HSCROLL|WS_VSCROLL)) == style ||
309 broken((winstyle & (WS_HSCROLL|WS_VSCROLL)) == (WS_HSCROLL|WS_VSCROLL)), /* Win 9x/ME */
310 "unexpected style change %8lx expected %8x\n",
311 (winstyle & (WS_HSCROLL|WS_VSCROLL)), style);
313 /* do the test again with H and V reversed.
314 * Start with a clean window */
315 DestroyWindow( hwnd);
316 hwnd = CreateWindowExA( 0, "static", "", WS_POPUP | style,
317 0, 0, 10, 10, 0, 0, 0, NULL);
319 /* Set Horizonta Scroll range to something that could be the default value it
321 ret = SetScrollRange( hwnd, SB_HORZ, 0, 100, FALSE);
322 ok( ret, "SetScrollRange failed.\n");
323 /* and request the Vertical range */
324 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
325 ok( ret, "GetScrollRange failed.\n");
326 /* now the range should be 0,100 in ALL cases */
327 ok( min == 0 && max == 100,
328 "Scroll bar range is %d,%d. Expected 0,100. Style %08x\n", min, max, style);
329 /* See what is different now for GetScrollRange */
330 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
331 /* should succeed in ALL cases */
332 ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
333 ret = GetScrollInfo( hwnd, SB_VERT, &si);
334 /* should succeed in ALL cases */
335 ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
336 /* report the windows style */
337 winstyle = GetWindowLongA( hwnd, GWL_STYLE );
338 /* WS_HSCROLL added to the window style */
339 if( !(style & WS_HSCROLL))
341 if (bThemeActive || style != WS_VSCROLL)
343 ok( (winstyle & (WS_HSCROLL|WS_VSCROLL)) == ( style | WS_HSCROLL),
344 "unexpected style change %8lx expected %8lx\n",
345 (winstyle & (WS_HSCROLL|WS_VSCROLL)), style | WS_HSCROLL);
347 ok( (winstyle & (WS_HSCROLL|WS_VSCROLL)) == style ||
348 broken((winstyle & (WS_HSCROLL|WS_VSCROLL)) == (WS_HSCROLL|WS_VSCROLL)), /* Win 9x/ME */
349 "unexpected style change %8lx expected %8x\n",
350 (winstyle & (WS_HSCROLL|WS_VSCROLL)), style);
352 /* Slightly change the test to use SetScrollInfo
353 * Start with a clean window */
354 DestroyWindow( hwnd);
355 hwnd = CreateWindowExA( 0, "static", "", WS_POPUP | style,
356 0, 0, 10, 10, 0, 0, 0, NULL);
358 /* set Horizontal position with SetScrollInfo */
362 si.fMask |= SIF_RANGE;
363 ret = SetScrollInfo( hwnd, SB_HORZ, &si, FALSE);
364 ok( ret, "SetScrollInfo failed. Style is %08x\n", style);
365 /* and request the Vertical range */
366 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
367 ok( ret, "GetScrollRange failed.\n");
368 /* now the range should be 0,100 in ALL cases */
369 ok( min == 0 && max == 100,
370 "Scroll bar range is %d,%d. Expected 0,100. Style %08x\n", min, max, style);
371 /* See what is different now for GetScrollRange */
372 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
373 /* should succeed in ALL cases */
374 ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
375 ret = GetScrollInfo( hwnd, SB_VERT, &si);
376 /* should succeed in ALL cases */
377 ok( ret, "GetScrollInfo failed unexpectedly. Style is %08x\n", style);
378 /* also test if the window scroll bars are enabled */
379 ret = EnableScrollBar( hwnd, SB_VERT, ESB_ENABLE_BOTH);
380 ok( !ret, "Vertical window scroll bar was not enabled\n");
381 ret = EnableScrollBar( hwnd, SB_HORZ, ESB_ENABLE_BOTH);
382 ok( !ret, "Horizontal window scroll bar was not enabled\n");
383 DestroyWindow( hwnd);
384 /* finally, check if adding a WS_[HV]SColl style of a window makes the scroll info
386 if( style & (WS_HSCROLL | WS_VSCROLL)) return;/* only test if not yet set */
387 /* Start with a clean window */
388 DestroyWindow( hwnd);
389 hwnd = CreateWindowExA( 0, "static", "", WS_POPUP ,
390 0, 0, 10, 10, 0, 0, 0, NULL);
392 ret = GetScrollInfo( hwnd, SB_VERT, &si);
394 ok( !ret, "GetScrollInfo succeeded unexpectedly. Style is %08x\n", style);
395 /* add scroll styles */
396 winstyle = GetWindowLongA( hwnd, GWL_STYLE );
397 SetWindowLongW( hwnd, GWL_STYLE, winstyle | WS_VSCROLL | WS_HSCROLL);
398 ret = GetScrollInfo( hwnd, SB_VERT, &si);
399 /* should still fail */
400 ok( !ret, "GetScrollInfo succeeded unexpectedly. Style is %08x\n", style);
402 DestroyWindow( hwnd);
405 START_TEST ( scroll )
409 BOOL (WINAPI * pIsThemeActive)(VOID);
411 wc.style = CS_HREDRAW | CS_VREDRAW;
414 wc.hInstance = GetModuleHandleA(NULL);
416 wc.hCursor = LoadCursorA(NULL, IDC_IBEAM);
417 wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
418 wc.lpszMenuName = NULL;
419 wc.lpszClassName = "MyTestWnd";
420 wc.lpfnWndProc = MyWndProc;
423 hMainWnd = CreateWindowExA( 0, "MyTestWnd", "Scroll",
424 WS_OVERLAPPEDWINDOW|WS_VSCROLL|WS_HSCROLL,
425 CW_USEDEFAULT, CW_USEDEFAULT, 100, 100, NULL, NULL, GetModuleHandleA(NULL), 0 );
427 ok(hMainWnd != NULL, "Failed to create parent window. Tests aborted.\n");
428 if (!hMainWnd) return;
436 scrollbar_test_track();
438 /* Some test results vary depending of theming being active or not */
439 hUxtheme = LoadLibraryA("uxtheme.dll");
442 pIsThemeActive = (void*)GetProcAddress(hUxtheme, "IsThemeActive");
444 bThemeActive = pIsThemeActive();
445 FreeLibrary(hUxtheme);
448 scrollbar_test_default( 0);
449 scrollbar_test_default( WS_HSCROLL);
450 scrollbar_test_default( WS_VSCROLL);
451 scrollbar_test_default( WS_HSCROLL | WS_VSCROLL);
453 DestroyWindow(hScroll);
454 DestroyWindow(hMainWnd);