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 or V 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 or V 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 %08x/%08x\n", winstyle
, style
);
307 ok( (winstyle
& (WS_HSCROLL
|WS_VSCROLL
)) == style
,
308 "unexpected style change %08x/%08x\n", winstyle
, style
);
310 /* do the test again with H and V reversed.
311 * Start with a clean window */
312 DestroyWindow( hwnd
);
313 hwnd
= CreateWindowExA( 0, "static", "", WS_POPUP
| style
,
314 0, 0, 10, 10, 0, 0, 0, NULL
);
316 /* Set Horizontal Scroll range to something that could be the default value it
318 ret
= SetScrollRange( hwnd
, SB_HORZ
, 0, 100, FALSE
);
319 ok( ret
, "SetScrollRange failed.\n");
320 /* and request the Vertical range */
321 ret
= GetScrollRange( hwnd
, SB_VERT
, &min
, &max
);
322 ok( ret
, "GetScrollRange failed.\n");
323 /* now the range should be 0,100 in ALL cases */
324 ok( min
== 0 && max
== 100,
325 "Scroll bar range is %d,%d. Expected 0,100. Style %08x\n", min
, max
, style
);
326 /* See what is different now for GetScrollRange */
327 ret
= GetScrollInfo( hwnd
, SB_HORZ
, &si
);
328 /* should succeed in ALL cases */
329 ok( ret
, "GetScrollInfo failed unexpectedly. Style is %08x\n", style
);
330 ret
= GetScrollInfo( hwnd
, SB_VERT
, &si
);
331 /* should succeed in ALL cases */
332 ok( ret
, "GetScrollInfo failed unexpectedly. Style is %08x\n", style
);
333 /* report the windows style */
334 winstyle
= GetWindowLongA( hwnd
, GWL_STYLE
);
335 /* WS_HSCROLL added to the window style */
336 if( !(style
& WS_HSCROLL
))
338 if (bThemeActive
|| style
!= WS_VSCROLL
)
340 ok( (winstyle
& (WS_HSCROLL
|WS_VSCROLL
)) == ( style
| WS_HSCROLL
),
341 "unexpected style change %08x/%08x\n", winstyle
, style
);
343 ok( (winstyle
& (WS_HSCROLL
|WS_VSCROLL
)) == style
,
344 "unexpected style change %08x/%08x\n", winstyle
, style
);
346 /* Slightly change the test to use SetScrollInfo
347 * Start with a clean window */
348 DestroyWindow( hwnd
);
349 hwnd
= CreateWindowExA( 0, "static", "", WS_POPUP
| style
,
350 0, 0, 10, 10, 0, 0, 0, NULL
);
352 /* set Horizontal position with SetScrollInfo */
356 si
.fMask
|= SIF_RANGE
;
357 ret
= SetScrollInfo( hwnd
, SB_HORZ
, &si
, FALSE
);
358 ok( ret
, "SetScrollInfo failed. Style is %08x\n", style
);
359 /* and request the Vertical range */
360 ret
= GetScrollRange( hwnd
, SB_VERT
, &min
, &max
);
361 ok( ret
, "GetScrollRange failed.\n");
362 /* now the range should be 0,100 in ALL cases */
363 ok( min
== 0 && max
== 100,
364 "Scroll bar range is %d,%d. Expected 0,100. Style %08x\n", min
, max
, style
);
365 /* See what is different now for GetScrollRange */
366 ret
= GetScrollInfo( hwnd
, SB_HORZ
, &si
);
367 /* should succeed in ALL cases */
368 ok( ret
, "GetScrollInfo failed unexpectedly. Style is %08x\n", style
);
369 ret
= GetScrollInfo( hwnd
, SB_VERT
, &si
);
370 /* should succeed in ALL cases */
371 ok( ret
, "GetScrollInfo failed unexpectedly. Style is %08x\n", style
);
372 /* also test if the window scroll bars are enabled */
373 ret
= EnableScrollBar( hwnd
, SB_VERT
, ESB_ENABLE_BOTH
);
374 ok( !ret
, "Vertical window scroll bar was not enabled\n");
375 ret
= EnableScrollBar( hwnd
, SB_HORZ
, ESB_ENABLE_BOTH
);
376 ok( !ret
, "Horizontal window scroll bar was not enabled\n");
377 DestroyWindow( hwnd
);
378 /* finally, check if adding a WS_[HV]SCROLL style of a window makes the scroll info
380 if( style
& (WS_HSCROLL
| WS_VSCROLL
)) return;/* only test if not yet set */
381 /* Start with a clean window */
382 DestroyWindow( hwnd
);
383 hwnd
= CreateWindowExA( 0, "static", "", WS_POPUP
,
384 0, 0, 10, 10, 0, 0, 0, NULL
);
386 ret
= GetScrollInfo( hwnd
, SB_VERT
, &si
);
388 ok( !ret
, "GetScrollInfo succeeded unexpectedly. Style is %08x\n", style
);
389 /* add scroll styles */
390 winstyle
= GetWindowLongA( hwnd
, GWL_STYLE
);
391 SetWindowLongW( hwnd
, GWL_STYLE
, winstyle
| WS_VSCROLL
| WS_HSCROLL
);
392 ret
= GetScrollInfo( hwnd
, SB_VERT
, &si
);
393 /* should still fail */
394 ok( !ret
, "GetScrollInfo succeeded unexpectedly. Style is %08x\n", style
);
396 DestroyWindow( hwnd
);
399 START_TEST ( scroll
)
403 BOOL (WINAPI
* pIsThemeActive
)(VOID
);
405 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
408 wc
.hInstance
= GetModuleHandleA(NULL
);
410 wc
.hCursor
= LoadCursorA(NULL
, IDC_IBEAM
);
411 wc
.hbrBackground
= GetSysColorBrush(COLOR_WINDOW
);
412 wc
.lpszMenuName
= NULL
;
413 wc
.lpszClassName
= "MyTestWnd";
414 wc
.lpfnWndProc
= MyWndProc
;
417 hMainWnd
= CreateWindowExA( 0, "MyTestWnd", "Scroll",
418 WS_OVERLAPPEDWINDOW
|WS_VSCROLL
|WS_HSCROLL
,
419 CW_USEDEFAULT
, CW_USEDEFAULT
, 100, 100, NULL
, NULL
, GetModuleHandleA(NULL
), 0 );
421 ok(hMainWnd
!= NULL
, "Failed to create parent window. Tests aborted.\n");
422 if (!hMainWnd
) return;
430 scrollbar_test_track();
432 /* Some test results vary depending of theming being active or not */
433 hUxtheme
= LoadLibraryA("uxtheme.dll");
436 pIsThemeActive
= (void*)GetProcAddress(hUxtheme
, "IsThemeActive");
438 bThemeActive
= pIsThemeActive();
439 FreeLibrary(hUxtheme
);
442 scrollbar_test_default( 0);
443 scrollbar_test_default( WS_HSCROLL
);
444 scrollbar_test_default( WS_VSCROLL
);
445 scrollbar_test_default( WS_HSCROLL
| WS_VSCROLL
);
447 DestroyWindow(hScroll
);
448 DestroyWindow(hMainWnd
);