[COMCTL32_WINETEST] Sync with Wine Staging 2.2. CORE-12823
[reactos.git] / rostests / winetests / comctl32 / trackbar.c
1 /* Unit tests for the track bar control.
2 *
3 * Copyright 2007 Keith Stevens
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18 */
19
20 #include <wine/test.h>
21
22 //#include <windows.h>
23 #include <wingdi.h>
24 #include <winuser.h>
25 #include <commctrl.h>
26 #include <stdio.h>
27
28 #include "msg.h"
29
30 #define expect(expected, got) ok(got == expected, "Expected %d, got %d\n", expected, got)
31 #define NUM_MSG_SEQUENCE 2
32 #define PARENT_SEQ_INDEX 0
33 #define TRACKBAR_SEQ_INDEX 1
34
35 static const DWORD defaultstyle = WS_VISIBLE | TBS_TOOLTIPS | TBS_ENABLESELRANGE | TBS_FIXEDLENGTH | TBS_AUTOTICKS;
36 static HWND hWndParent;
37
38 static LRESULT WINAPI trackbar_no_wmpaint_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
39 {
40 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
41
42 if (message == WM_PAINT)
43 return 0;
44
45 return CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
46 }
47
48 static struct msg_sequence *sequences[NUM_MSG_SEQUENCE];
49
50 static const struct message empty_seq[] = {
51 {0}
52 };
53
54 static const struct message parent_create_trackbar_wnd_seq[] = {
55 { WM_NOTIFYFORMAT, sent},
56 { WM_QUERYUISTATE, sent|optional},
57 { WM_WINDOWPOSCHANGING, sent},
58 { WM_NCACTIVATE, sent},
59 { PBT_APMRESUMECRITICAL, sent},
60 { WM_WINDOWPOSCHANGING, sent},
61 { PBT_APMRESUMESTANDBY, sent},
62 { WM_IME_SETCONTEXT, sent|optional},
63 { WM_IME_NOTIFY, sent|optional},
64 { WM_CTLCOLORSTATIC, sent},
65 { WM_NOTIFY, sent},
66 {0}
67 };
68
69 static const struct message parent_new_window_test_seq[] = {
70 { WM_QUERYNEWPALETTE, sent|optional },
71 { WM_WINDOWPOSCHANGING, sent|optional},
72 { WM_NCACTIVATE, sent|optional},
73 { PBT_APMRESUMECRITICAL, sent|optional},
74 { WM_IME_SETCONTEXT, sent|defwinproc|optional},
75 { WM_IME_NOTIFY, sent|defwinproc|optional},
76 { WM_SETFOCUS, sent|defwinproc|optional},
77 { WM_NOTIFYFORMAT, sent},
78 { WM_QUERYUISTATE, sent|optional},
79 {0}
80 };
81
82 static const struct message buddy_window_test_seq[] = {
83 { TBM_GETBUDDY, sent|wparam, TRUE},
84 { TBM_SETBUDDY, sent|wparam, FALSE},
85 { WM_PAINT, sent|defwinproc},
86 { TBM_SETBUDDY, sent|wparam, FALSE},
87 { WM_PAINT, sent|defwinproc},
88 { TBM_GETBUDDY, sent|wparam, TRUE},
89 { TBM_SETBUDDY, sent|wparam, TRUE},
90 { WM_PAINT, sent|defwinproc},
91 { TBM_SETBUDDY, sent|wparam, TRUE},
92 { WM_PAINT, sent|defwinproc},
93 { TBM_GETBUDDY, sent|wparam, FALSE},
94 { TBM_GETBUDDY, sent|wparam, TRUE},
95 {0}
96 };
97
98 static const struct message parent_buddy_window_test_seq[] = {
99 { WM_CTLCOLORSTATIC, sent},
100 { WM_NOTIFY, sent},
101 { WM_CTLCOLORSTATIC, sent},
102 { WM_NOTIFY, sent},
103 { WM_CTLCOLORSTATIC, sent},
104 { WM_NOTIFY, sent},
105 { WM_CTLCOLORSTATIC, sent},
106 { WM_NOTIFY, sent},
107 {0}
108 };
109
110 static const struct message line_size_test_seq[] = {
111 { TBM_SETLINESIZE, sent|lparam, 0, 10},
112 { TBM_SETLINESIZE, sent|lparam, 0, 4},
113 { TBM_GETLINESIZE, sent},
114 {0}
115 };
116
117 static const struct message page_size_test_seq[] = {
118 { TBM_SETPAGESIZE, sent|lparam, 0, 10},
119 { TBM_SETPAGESIZE, sent|lparam, 0, -1},
120 { TBM_GETPAGESIZE, sent},
121 {0}
122 };
123
124 static const struct message position_test_seq[] = {
125 { TBM_SETPOS, sent|wparam|lparam, TRUE, -1},
126 { WM_PAINT, sent|defwinproc},
127 { TBM_GETPOS, sent},
128 { TBM_SETPOS, sent|wparam|lparam, TRUE, 5},
129 { WM_PAINT, sent|defwinproc},
130 { TBM_GETPOS, sent},
131 { TBM_SETPOS, sent|wparam|lparam, TRUE, 5},
132 { TBM_SETPOS, sent|wparam|lparam, TRUE, 1000},
133 { WM_PAINT, sent|defwinproc},
134 { TBM_GETPOS, sent},
135 { TBM_SETPOS, sent|wparam|lparam, FALSE, 20},
136 { TBM_GETPOS, sent},
137 { TBM_SETPOS, sent|wparam|lparam, TRUE, 20},
138 { TBM_GETPOS, sent},
139 {0}
140 };
141
142 static const struct message parent_position_test_seq[] = {
143 { WM_CTLCOLORSTATIC, sent},
144 { WM_NOTIFY, sent},
145 { WM_CTLCOLORSTATIC, sent},
146 { WM_NOTIFY, sent},
147 { WM_CTLCOLORSTATIC, sent},
148 { WM_NOTIFY, sent},
149 {0}
150 };
151
152 static const struct message range_test_seq[] = {
153 { TBM_SETRANGE, sent|wparam|lparam, TRUE, MAKELONG(0, 10)},
154 { WM_PAINT, sent|defwinproc},
155 { TBM_GETRANGEMAX, sent},
156 { TBM_GETRANGEMIN, sent},
157 { TBM_SETRANGE, sent|wparam|lparam, TRUE, MAKELONG(-1, 1000)},
158 { WM_PAINT, sent|defwinproc},
159 { TBM_GETRANGEMAX, sent},
160 { TBM_GETRANGEMIN, sent},
161 { TBM_SETRANGE, sent|wparam|lparam, TRUE, MAKELONG(10, 0)},
162 { WM_PAINT, sent|defwinproc},
163 { TBM_GETRANGEMAX, sent},
164 { TBM_GETRANGEMIN, sent},
165 { TBM_SETRANGE, sent|wparam|lparam, FALSE, MAKELONG(0, 10)},
166 { TBM_GETRANGEMAX, sent},
167 { TBM_GETRANGEMIN, sent},
168 { TBM_SETRANGEMAX, sent|wparam|lparam, TRUE, 10},
169 { WM_PAINT, sent|defwinproc},
170 { TBM_GETRANGEMAX, sent},
171 { TBM_SETRANGEMAX, sent|wparam|lparam, TRUE, -1},
172 { WM_PAINT, sent|defwinproc},
173 { TBM_GETRANGEMAX, sent},
174 { TBM_SETRANGEMAX, sent|wparam|lparam, FALSE, 10},
175 { TBM_GETRANGEMAX, sent},
176 { TBM_SETRANGEMIN, sent|wparam|lparam, TRUE, 0},
177 { WM_PAINT, sent|defwinproc},
178 { TBM_GETRANGEMIN, sent},
179 { TBM_SETRANGEMIN, sent|wparam|lparam, TRUE, 10},
180 { WM_PAINT, sent|defwinproc},
181 { TBM_GETRANGEMIN, sent},
182 { TBM_SETRANGEMIN, sent|wparam|lparam, TRUE, -10},
183 { WM_PAINT, sent|defwinproc},
184 { TBM_GETRANGEMIN, sent},
185 { TBM_SETRANGEMIN, sent|wparam|lparam, FALSE, 5},
186 { TBM_GETRANGEMIN, sent},
187 { TBM_GETRANGEMAX, sent},
188 { TBM_GETRANGEMIN, sent},
189 {0}
190 };
191
192 static const struct message parent_range_test_seq[] = {
193 { WM_CTLCOLORSTATIC, sent},
194 { WM_NOTIFY, sent},
195 { WM_CTLCOLORSTATIC, sent},
196 { WM_NOTIFY, sent},
197 { WM_CTLCOLORSTATIC, sent},
198 { WM_NOTIFY, sent},
199 { WM_CTLCOLORSTATIC, sent},
200 { WM_NOTIFY, sent},
201 { WM_CTLCOLORSTATIC, sent},
202 { WM_NOTIFY, sent},
203 { WM_CTLCOLORSTATIC, sent},
204 { WM_NOTIFY, sent},
205 { WM_CTLCOLORSTATIC, sent},
206 { WM_NOTIFY, sent},
207 { WM_CTLCOLORSTATIC, sent},
208 { WM_NOTIFY, sent},
209 {0}
210 };
211
212 static const struct message selection_test_seq[] = {
213 { TBM_SETSEL, sent|wparam|lparam, TRUE, MAKELONG(0, 10)},
214 { WM_PAINT, sent|defwinproc},
215 { TBM_GETSELEND, sent},
216 { TBM_GETSELSTART, sent},
217 { TBM_SETSEL, sent|wparam|lparam, TRUE, MAKELONG(5, 20)},
218 { WM_PAINT, sent|defwinproc},
219 { TBM_GETSELEND, sent},
220 { TBM_GETSELSTART, sent},
221 { TBM_SETSEL, sent|wparam|lparam, FALSE, MAKELONG(5, 10)},
222 { TBM_GETSELEND, sent},
223 { TBM_GETSELSTART, sent},
224 { TBM_SETSELEND, sent|wparam|lparam, TRUE, 10},
225 { WM_PAINT, sent|defwinproc},
226 { TBM_GETSELEND, sent},
227 { TBM_SETSELEND, sent|wparam|lparam, TRUE, 20},
228 { WM_PAINT, sent|defwinproc},
229 { TBM_GETSELEND, sent},
230 { TBM_SETSELEND, sent|wparam|lparam, TRUE, 4},
231 { WM_PAINT, sent|defwinproc},
232 { TBM_GETSELEND, sent},
233 { TBM_SETSELEND, sent|wparam|lparam, FALSE, 2},
234 { TBM_GETSELEND, sent},
235 { TBM_GETSELEND, sent},
236 { TBM_SETSELSTART, sent|wparam|lparam, TRUE, 5},
237 { WM_PAINT, sent|defwinproc},
238 { TBM_GETSELSTART, sent},
239 { TBM_SETSELSTART, sent|wparam|lparam, TRUE, 0},
240 { WM_PAINT, sent|defwinproc},
241 { TBM_GETSELSTART, sent},
242 { TBM_SETSELSTART, sent|wparam|lparam, TRUE, 20},
243 { WM_PAINT, sent|defwinproc},
244 { TBM_GETSELSTART, sent},
245 { TBM_SETSELSTART, sent|wparam|lparam, FALSE, 8},
246 { TBM_GETSELSTART, sent},
247 { TBM_GETSELSTART, sent},
248 {0}
249 };
250
251 static const struct message parent_selection_test_seq[] = {
252 { WM_CTLCOLORSTATIC, sent},
253 { WM_NOTIFY, sent},
254 { WM_CTLCOLORSTATIC, sent},
255 { WM_NOTIFY, sent},
256 { WM_CTLCOLORSTATIC, sent},
257 { WM_NOTIFY, sent},
258 { WM_CTLCOLORSTATIC, sent},
259 { WM_NOTIFY, sent},
260 { WM_CTLCOLORSTATIC, sent},
261 { WM_NOTIFY, sent},
262 { WM_CTLCOLORSTATIC, sent},
263 { WM_NOTIFY, sent},
264 { WM_CTLCOLORSTATIC, sent},
265 { WM_NOTIFY, sent},
266 { WM_CTLCOLORSTATIC, sent},
267 { WM_NOTIFY, sent},
268 {0}
269 };
270
271 static const struct message tic_settings_test_seq[] = {
272 { TBM_SETTIC, sent|lparam, 0, 0},
273 { TBM_SETTIC, sent|lparam, 0, 5},
274 { TBM_SETTIC, sent|lparam, 0, 10},
275 { TBM_SETTIC, sent|lparam, 0, 20},
276 { TBM_SETRANGE, sent|wparam|lparam, TRUE, MAKELONG(0,10)},
277 { WM_PAINT, sent|defwinproc},
278 { TBM_SETTICFREQ, sent|wparam, 2},
279 { WM_PAINT, sent|defwinproc},
280 { TBM_GETNUMTICS, sent},
281 { TBM_SETTICFREQ, sent|wparam, 5},
282 { WM_PAINT, sent|defwinproc},
283 { TBM_GETNUMTICS, sent},
284 { TBM_SETTICFREQ, sent|wparam, 15},
285 { WM_PAINT, sent|defwinproc},
286 { TBM_GETNUMTICS, sent},
287 { TBM_GETNUMTICS, sent},
288 {0}
289 };
290
291 static const struct message parent_tic_settings_test_seq[] = {
292 { WM_CTLCOLORSTATIC, sent},
293 { WM_NOTIFY, sent},
294 { WM_CTLCOLORSTATIC, sent},
295 { WM_NOTIFY, sent},
296 { WM_CTLCOLORSTATIC, sent},
297 { WM_NOTIFY, sent},
298 { WM_CTLCOLORSTATIC, sent},
299 { WM_NOTIFY, sent},
300 {0}
301 };
302
303 static const struct message thumb_length_test_seq[] = {
304 { TBM_SETTHUMBLENGTH, sent|wparam|lparam, 15, 0},
305 { WM_PAINT, sent|defwinproc},
306 { TBM_GETTHUMBLENGTH, sent},
307 { TBM_SETTHUMBLENGTH, sent|wparam|lparam, 20, 0},
308 { WM_PAINT, sent|defwinproc},
309 { TBM_GETTHUMBLENGTH, sent},
310 { TBM_GETTHUMBLENGTH, sent},
311 { WM_SIZE, sent},
312 { WM_PAINT, sent|defwinproc},
313 { TBM_GETTHUMBLENGTH, sent},
314 { WM_SIZE, sent},
315 { WM_PAINT, sent|defwinproc},
316 { TBM_GETTHUMBLENGTH, sent},
317 {0}
318 };
319
320 static const struct message parent_thumb_length_test_seq[] = {
321 { WM_CTLCOLORSTATIC, sent},
322 { WM_NOTIFY, sent},
323 { WM_CTLCOLORSTATIC, sent},
324 { WM_NOTIFY, sent},
325 { WM_CTLCOLORSTATIC, sent},
326 { WM_NOTIFY, sent},
327 { WM_CTLCOLORSTATIC, sent},
328 { WM_NOTIFY, sent},
329 {0}
330 };
331
332 static const struct message tic_placement_test_seq[] = {
333 { TBM_GETPTICS, sent},
334 { TBM_GETTIC, sent|wparam, 0},
335 { TBM_GETTIC, sent|wparam, 2},
336 { TBM_GETTIC, sent|wparam, 4},
337 { TBM_GETTICPOS, sent|wparam, 0},
338 { TBM_GETTICPOS, sent|wparam, 2},
339 {0}
340 };
341
342 static const struct message tool_tips_test_seq[] = {
343 { TBM_SETTIPSIDE, sent|wparam, TBTS_TOP},
344 { TBM_SETTIPSIDE, sent|wparam, TBTS_LEFT},
345 { TBM_SETTIPSIDE, sent|wparam, TBTS_BOTTOM},
346 { TBM_SETTIPSIDE, sent|wparam, TBTS_RIGHT},
347 { TBM_SETTOOLTIPS, sent},
348 { TBM_GETTOOLTIPS, sent},
349 { TBM_SETTOOLTIPS, sent},
350 { TBM_GETTOOLTIPS, sent},
351 { TBM_SETTOOLTIPS, sent},
352 { TBM_GETTOOLTIPS, sent},
353 { TBM_GETTOOLTIPS, sent},
354 {0}
355 };
356
357 static const struct message unicode_test_seq[] = {
358 { TBM_SETUNICODEFORMAT, sent|wparam, TRUE},
359 { TBM_SETUNICODEFORMAT, sent|wparam, FALSE},
360 { TBM_GETUNICODEFORMAT, sent},
361 {0}
362 };
363
364 static const struct message ignore_selection_test_seq[] = {
365 { TBM_SETSEL, sent|wparam|lparam, TRUE, MAKELONG(0,10)},
366 { TBM_GETSELEND, sent},
367 { TBM_GETSELSTART, sent},
368 { TBM_SETSEL, sent|wparam|lparam, FALSE, MAKELONG(0,10)},
369 { TBM_GETSELEND, sent},
370 { TBM_GETSELSTART, sent},
371 { TBM_SETSELEND, sent|wparam|lparam, TRUE,0},
372 { TBM_GETSELEND, sent},
373 { TBM_SETSELEND, sent|wparam|lparam, TRUE, 10},
374 { TBM_GETSELEND, sent},
375 { TBM_SETSELEND, sent|wparam|lparam, FALSE,0},
376 { TBM_GETSELEND, sent},
377 { TBM_SETSELSTART, sent|wparam|lparam, TRUE,0},
378 { TBM_GETSELSTART, sent},
379 { TBM_SETSELSTART, sent|wparam|lparam, TRUE, 10},
380 { TBM_GETSELSTART, sent},
381 { TBM_SETSELSTART, sent|wparam|lparam, FALSE,0},
382 { TBM_GETSELSTART, sent},
383 {0}
384 };
385
386 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){
387 static LONG defwndproc_counter = 0;
388 LRESULT ret;
389 struct message msg;
390
391 /* log system messages, except for painting */
392 if (message < WM_USER &&
393 message != WM_PAINT &&
394 message != WM_ERASEBKGND &&
395 message != WM_NCPAINT &&
396 message != WM_NCHITTEST &&
397 message != WM_GETTEXT &&
398 message != WM_GETICON &&
399 message != WM_DEVICECHANGE)
400 {
401 msg.message = message;
402 msg.flags = sent|wparam|lparam;
403 if (defwndproc_counter) msg.flags |= defwinproc;
404 msg.wParam = wParam;
405 msg.lParam = lParam;
406 msg.id = 0;
407 add_message(sequences, PARENT_SEQ_INDEX, &msg);
408 }
409
410 defwndproc_counter++;
411 ret = DefWindowProcA(hwnd, message, wParam, lParam);
412 defwndproc_counter--;
413
414 return ret;
415 }
416
417 static BOOL register_parent_wnd_class(void){
418 WNDCLASSA cls;
419
420 cls.style = 0;
421 cls.lpfnWndProc = parent_wnd_proc;
422 cls.cbClsExtra = 0;
423 cls.cbWndExtra = 0;
424 cls.hInstance = GetModuleHandleA(NULL);
425 cls.hIcon = 0;
426 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
427 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
428 cls.lpszMenuName = NULL;
429 cls.lpszClassName = "Trackbar test parent class";
430 return RegisterClassA(&cls);
431 }
432
433 static HWND create_parent_window(void){
434 if (!register_parent_wnd_class())
435 return NULL;
436
437 return CreateWindowA("Trackbar test parent class", "Trackbar test parent window",
438 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_VISIBLE,
439 0, 0, 100, 100, GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL);
440 }
441
442 static LRESULT WINAPI trackbar_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){
443 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
444 static LONG defwndproc_counter = 0;
445 LRESULT ret;
446 struct message msg;
447
448 msg.message = message;
449 msg.flags = sent|wparam|lparam;
450 if (defwndproc_counter) msg.flags |= defwinproc;
451 msg.wParam = wParam;
452 msg.lParam = lParam;
453 msg.id = 0;
454 add_message(sequences, TRACKBAR_SEQ_INDEX, &msg);
455
456 defwndproc_counter++;
457 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
458 defwndproc_counter--;
459
460 return ret;
461 }
462
463 static HWND create_trackbar(DWORD style, HWND parent){
464 HWND hWndTrack;
465 WNDPROC oldproc;
466 RECT rect;
467
468 GetClientRect(parent, &rect);
469 hWndTrack = CreateWindowA(TRACKBAR_CLASSA, "Trackbar Control", style,
470 rect.right, rect.bottom, 100, 50,
471 parent, NULL, GetModuleHandleA(NULL), NULL);
472
473 if (!hWndTrack) return NULL;
474
475 oldproc = (WNDPROC)SetWindowLongPtrA(hWndTrack, GWLP_WNDPROC, (LONG_PTR)trackbar_subclass_proc);
476 SetWindowLongPtrA(hWndTrack, GWLP_USERDATA, (LONG_PTR)oldproc);
477
478 return hWndTrack;
479 }
480
481 static HWND create_trackbar2(DWORD style, HWND parent)
482 {
483 RECT rect;
484 GetClientRect(parent, &rect);
485 return CreateWindowA(TRACKBAR_CLASSA, "Trackbar Control", style,
486 rect.right, rect.bottom, 100, 50,
487 parent, NULL, GetModuleHandleA(NULL), NULL);
488 }
489
490 /* test functions for setters, getters, and sequences */
491
492 static void test_trackbar_buddy(void)
493 {
494 HWND hWndLeftBuddy, hWndTrackbar;
495 HWND hWndRightBuddy;
496 HWND hWndCurrentBuddy;
497 HWND rTest;
498
499 hWndTrackbar = create_trackbar(defaultstyle, hWndParent);
500 ok(hWndTrackbar != NULL, "Expected non NULL value\n");
501
502 flush_sequences(sequences, NUM_MSG_SEQUENCE);
503
504 hWndLeftBuddy = CreateWindowA(STATUSCLASSNAMEA, NULL, 0, 0, 0, 300, 20, NULL, NULL, NULL, NULL);
505 ok(hWndLeftBuddy != NULL, "Expected non NULL value\n");
506
507 if (hWndLeftBuddy != NULL){
508 hWndCurrentBuddy = (HWND) SendMessageA(hWndTrackbar, TBM_GETBUDDY, TRUE, 0);
509 rTest = (HWND) SendMessageA(hWndTrackbar, TBM_SETBUDDY, FALSE, (LPARAM) hWndLeftBuddy);
510 ok(rTest == hWndCurrentBuddy, "Expected hWndCurrentBuddy\n");
511 rTest = (HWND) SendMessageA(hWndTrackbar, TBM_SETBUDDY, FALSE, (LPARAM) hWndLeftBuddy);
512 ok(rTest == hWndLeftBuddy, "Expected hWndLeftBuddy\n");
513 } else
514 skip ("left buddy control not present?\n");
515
516 hWndRightBuddy = CreateWindowA(STATUSCLASSNAMEA, NULL, 0, 0, 0, 300, 20, NULL, NULL, NULL, NULL);
517
518 ok(hWndRightBuddy != NULL, "expected non NULL value\n");
519
520 /* test TBM_SETBUDDY */
521 if (hWndRightBuddy != NULL){
522 hWndCurrentBuddy = (HWND) SendMessageA(hWndTrackbar, TBM_GETBUDDY, TRUE, 0);
523 rTest = (HWND) SendMessageA(hWndTrackbar, TBM_SETBUDDY, TRUE, (LPARAM) hWndRightBuddy);
524 ok(rTest == hWndCurrentBuddy, "Expected hWndCurrentBuddy\n");
525 rTest = (HWND) SendMessageA(hWndTrackbar, TBM_SETBUDDY, TRUE, (LPARAM) hWndRightBuddy);
526 ok(rTest == hWndRightBuddy, "Expected hWndRightbuddy\n");
527 } else
528 skip("Right buddy control not present?\n");
529
530 /* test TBM_GETBUDDY */
531 if (hWndLeftBuddy != NULL){
532 rTest = (HWND) SendMessageA(hWndTrackbar, TBM_GETBUDDY, FALSE, 0);
533 ok(rTest == hWndLeftBuddy, "Expected hWndLeftBuddy\n");
534 DestroyWindow(hWndLeftBuddy);
535 }
536 if (hWndRightBuddy != NULL){
537 rTest = (HWND) SendMessageA(hWndTrackbar, TBM_GETBUDDY, TRUE,0);
538 ok(rTest == hWndRightBuddy, "Expected hWndRightBuddy\n");
539 DestroyWindow(hWndRightBuddy);
540 }
541
542 ok_sequence(sequences, TRACKBAR_SEQ_INDEX, buddy_window_test_seq, "buddy test sequence", TRUE);
543 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_buddy_window_test_seq, "parent buddy test seq", TRUE);
544
545 DestroyWindow(hWndTrackbar);
546 }
547
548 static void test_line_size(void)
549 {
550 HWND hWndTrackbar;
551 int r;
552
553 hWndTrackbar = create_trackbar(defaultstyle, hWndParent);
554 ok(hWndTrackbar != NULL, "Expected non NULL value\n");
555
556 flush_sequences(sequences, NUM_MSG_SEQUENCE);
557
558 /* test TBM_SETLINESIZE */
559 r = SendMessageA(hWndTrackbar, TBM_SETLINESIZE, 0, 10);
560 expect(1,r);
561 r = SendMessageA(hWndTrackbar, TBM_SETLINESIZE, 0, 4);
562 expect(10, r);
563
564 /* test TBM_GETLINESIZE */
565 r = SendMessageA(hWndTrackbar, TBM_GETLINESIZE, 0,0);
566 expect(4, r);
567
568 ok_sequence(sequences, TRACKBAR_SEQ_INDEX, line_size_test_seq, "linesize test sequence", FALSE);
569 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "parent line test sequence", FALSE);
570
571 DestroyWindow(hWndTrackbar);
572 }
573
574
575 static void test_page_size(void)
576 {
577 HWND hWndTrackbar;
578 int r;
579
580 hWndTrackbar = create_trackbar(defaultstyle, hWndParent);
581 ok(hWndTrackbar != NULL, "Expected non NULL value\n");
582
583 flush_sequences(sequences, NUM_MSG_SEQUENCE);
584
585 /* test TBM_SETPAGESIZE */
586 r = SendMessageA(hWndTrackbar, TBM_SETPAGESIZE, 0, 10);
587 expect(20, r);
588 r = SendMessageA(hWndTrackbar, TBM_SETPAGESIZE, 0, -1);
589 expect(10, r);
590
591 /* test TBM_GETPAGESIZE */
592 r = SendMessageA(hWndTrackbar, TBM_GETPAGESIZE, 0,0);
593 expect(20, r);
594
595 ok_sequence(sequences, TRACKBAR_SEQ_INDEX, page_size_test_seq, "page size test sequence", FALSE);
596 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "parent page size test sequence", FALSE);
597
598 /* check for zero page size */
599 r = SendMessageA(hWndTrackbar, TBM_SETPAGESIZE, 0, 0);
600 expect(20, r);
601 r = SendMessageA(hWndTrackbar, TBM_GETPAGESIZE, 0, 0);
602 expect(0, r);
603 /* revert to default */
604 r = SendMessageA(hWndTrackbar, TBM_SETPAGESIZE, 0, -1);
605 expect(0, r);
606 r = SendMessageA(hWndTrackbar, TBM_GETPAGESIZE, 0, 0);
607 expect(20, r);
608 /* < -1 */
609 r = SendMessageA(hWndTrackbar, TBM_SETPAGESIZE, 0, -2);
610 expect(20, r);
611 r = SendMessageA(hWndTrackbar, TBM_GETPAGESIZE, 0, 0);
612 expect(-2, r);
613
614 DestroyWindow(hWndTrackbar);
615 }
616
617 static void test_position(void)
618 {
619 HWND hWndTrackbar;
620 RECT rect, rect2;
621 WNDPROC oldproc;
622 int r;
623
624 hWndTrackbar = create_trackbar(defaultstyle, hWndParent);
625 ok(hWndTrackbar != NULL, "Expected non NULL value\n");
626
627 flush_sequences(sequences, NUM_MSG_SEQUENCE);
628
629 /* test TBM_SETPOS */
630 SendMessageA(hWndTrackbar, TBM_SETPOS, TRUE, -1);
631 r = SendMessageA(hWndTrackbar, TBM_GETPOS, 0, 0);
632 expect(0, r);
633 SendMessageA(hWndTrackbar, TBM_SETPOS, TRUE, 5);
634 r = SendMessageA(hWndTrackbar, TBM_GETPOS, 0,0);
635 expect(5, r);
636 SendMessageA(hWndTrackbar, TBM_SETPOS, TRUE, 5);
637 SendMessageA(hWndTrackbar, TBM_SETPOS, TRUE, 1000);
638 r = SendMessageA(hWndTrackbar, TBM_GETPOS, 0,0);
639 expect(100, r);
640 SendMessageA(hWndTrackbar, TBM_SETPOS, FALSE, 20);
641 r = SendMessageA(hWndTrackbar, TBM_GETPOS, 0,0);
642 expect(20, r);
643 SendMessageA(hWndTrackbar, TBM_SETPOS, TRUE, 20);
644
645 /* test TBM_GETPOS */
646 r = SendMessageA(hWndTrackbar, TBM_GETPOS, 0,0);
647 expect(20, r);
648
649 ok_sequence(sequences, TRACKBAR_SEQ_INDEX, position_test_seq, "position test sequence", TRUE);
650 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_position_test_seq, "parent position test sequence", TRUE);
651
652 DestroyWindow(hWndTrackbar);
653
654 hWndTrackbar = create_trackbar2(defaultstyle, hWndParent);
655 ok(hWndTrackbar != NULL, "Expected non NULL value\n");
656
657 /* subclassing procedure blocks WM_PAINT */
658 oldproc = (WNDPROC)SetWindowLongPtrA(hWndTrackbar, GWLP_WNDPROC, (LONG_PTR)trackbar_no_wmpaint_proc);
659 SetWindowLongPtrA(hWndTrackbar, GWLP_USERDATA, (LONG_PTR)oldproc);
660
661 SetRectEmpty(&rect);
662 SetRectEmpty(&rect2);
663
664 SendMessageA(hWndTrackbar, TBM_GETTHUMBRECT, 0, (LPARAM)&rect);
665
666 /* without repaint */
667 SendMessageA(hWndTrackbar, TBM_SETPOS, FALSE, 25);
668 r = SendMessageA(hWndTrackbar, TBM_GETPOS, 0, 0);
669 ok(r == 25, "got %d\n", r);
670 SendMessageA(hWndTrackbar, TBM_GETTHUMBRECT, 0, (LPARAM)&rect2);
671 ok(rect.left == rect2.left, "got %d\n", rect.left);
672
673 /* with repaint */
674 SendMessageA(hWndTrackbar, TBM_SETPOS, TRUE, 30);
675 r = SendMessageA(hWndTrackbar, TBM_GETPOS, 0, 0);
676 ok(r == 30, "got %d\n", r);
677 SendMessageA(hWndTrackbar, TBM_GETTHUMBRECT, 0, (LPARAM)&rect2);
678 ok(rect.left != rect2.left, "got %d, expected %d\n", rect2.left, rect.left);
679
680 /* now move it with keys */
681 SendMessageA(hWndTrackbar, WM_KEYDOWN, VK_END, 0);
682 r = SendMessageA(hWndTrackbar, TBM_GETPOS, 0, 0);
683 ok(r == 100, "got %d\n", r);
684 SendMessageA(hWndTrackbar, TBM_GETTHUMBRECT, 0, (LPARAM)&rect);
685 ok(rect.left != rect2.left, "got %d, expected %d\n", rect.left, rect2.left);
686
687 DestroyWindow(hWndTrackbar);
688 }
689
690 static void test_range(void)
691 {
692 HWND hWndTrackbar;
693 RECT rect1, rect2;
694 int r;
695
696 hWndTrackbar = create_trackbar(defaultstyle, hWndParent);
697 ok(hWndTrackbar != NULL, "Expected non NULL value\n");
698
699 flush_sequences(sequences, NUM_MSG_SEQUENCE);
700
701 /* test TBM_SETRANGE */
702 SendMessageA(hWndTrackbar, TBM_SETRANGE, TRUE, MAKELONG(0, 10));
703 r = SendMessageA(hWndTrackbar, TBM_GETRANGEMAX, 0,0);
704 expect(10, r);
705 r = SendMessageA(hWndTrackbar, TBM_GETRANGEMIN, 0,0);
706 expect(0, r);
707 SendMessageA(hWndTrackbar, TBM_SETRANGE, TRUE, MAKELONG(-1, 1000));
708 r = SendMessageA(hWndTrackbar, TBM_GETRANGEMAX, 0,0);
709 expect(1000, r);
710 r = SendMessageA(hWndTrackbar, TBM_GETRANGEMIN, 0,0);
711 expect(-1, r);
712 SendMessageA(hWndTrackbar, TBM_SETRANGE, TRUE, MAKELONG(10, 0));
713 r = SendMessageA(hWndTrackbar, TBM_GETRANGEMAX, 0,0);
714 expect(0, r);
715 r = SendMessageA(hWndTrackbar, TBM_GETRANGEMIN, 0,0);
716 expect(10, r);
717 SendMessageA(hWndTrackbar, TBM_SETRANGE, FALSE, MAKELONG(0,10));
718 r = SendMessageA(hWndTrackbar, TBM_GETRANGEMAX, 0,0);
719 expect(10, r);
720 r = SendMessageA(hWndTrackbar, TBM_GETRANGEMIN, 0,0);
721 expect(0, r);
722
723 /*test TBM_SETRANGEMAX */
724 SendMessageA(hWndTrackbar, TBM_SETRANGEMAX, TRUE, 10);
725 r = SendMessageA(hWndTrackbar, TBM_GETRANGEMAX, 0,0);
726 expect(10, r);
727 SendMessageA(hWndTrackbar, TBM_SETRANGEMAX, TRUE, -1);
728 r = SendMessageA(hWndTrackbar, TBM_GETRANGEMAX, 0,0);
729 expect(-1, r);
730 SendMessageA(hWndTrackbar, TBM_SETRANGEMAX, FALSE, 10);
731 r = SendMessageA(hWndTrackbar, TBM_GETRANGEMAX, 0,0);
732 expect(10, r);
733
734 /* testing TBM_SETRANGEMIN */
735 SendMessageA(hWndTrackbar, TBM_SETRANGEMIN, TRUE, 0);
736 r = SendMessageA(hWndTrackbar, TBM_GETRANGEMIN, 0,0);
737 expect(0, r);
738 SendMessageA(hWndTrackbar, TBM_SETRANGEMIN, TRUE, 10);
739 r = SendMessageA(hWndTrackbar, TBM_GETRANGEMIN, 0,0);
740 expect(10, r);
741 SendMessageA(hWndTrackbar, TBM_SETRANGEMIN, TRUE, -10);
742 r = SendMessageA(hWndTrackbar, TBM_GETRANGEMIN, 0,0);
743 expect(-10, r);
744 SendMessageA(hWndTrackbar, TBM_SETRANGEMIN, FALSE, 5);
745 r = SendMessageA(hWndTrackbar, TBM_GETRANGEMIN, 0,0);
746 expect(5, r);
747
748 /* test TBM_GETRANGEMAX */
749 r = SendMessageA(hWndTrackbar, TBM_GETRANGEMAX, 0,0);
750 expect(10, r);
751
752 /* test TBM_GETRANGEMIN */
753 r = SendMessageA(hWndTrackbar, TBM_GETRANGEMIN, 0,0);
754 expect(5, r);
755
756 ok_sequence(sequences, TRACKBAR_SEQ_INDEX, range_test_seq, "range test sequence", TRUE);
757 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_range_test_seq, "parent range test sequence", TRUE);
758
759 /* TBM_SETRANGE updates thumb visual position (rectangle) if needed */
760 r = SendMessageA(hWndTrackbar, TBM_SETRANGE, TRUE, MAKELONG(-10, 0));
761 ok(r == 0, "got %d\n", r);
762 SendMessageA(hWndTrackbar, TBM_SETPOS, TRUE, 0);
763
764 RedrawWindow(hWndTrackbar, NULL, 0, RDW_UPDATENOW);
765 SendMessageA(hWndTrackbar, TBM_GETTHUMBRECT, 0, (LPARAM)&rect1);
766
767 r = SendMessageA(hWndTrackbar, TBM_SETRANGE, TRUE, MAKELONG(-10, 10));
768 ok(r == 0, "got %d\n", r);
769 RedrawWindow(hWndTrackbar, NULL, 0, RDW_UPDATENOW);
770
771 SendMessageA(hWndTrackbar, TBM_GETTHUMBRECT, 0, (LPARAM)&rect2);
772 ok(!EqualRect(&rect1, &rect2), "thumb rectangle not updated\n");
773
774 /* change range back, don't force repaint */
775 r = SendMessageA(hWndTrackbar, TBM_SETRANGE, FALSE, MAKELONG(-10, 0));
776 ok(r == 0, "got %d\n", r);
777
778 SendMessageA(hWndTrackbar, TBM_GETTHUMBRECT, 0, (LPARAM)&rect1);
779 ok(EqualRect(&rect1, &rect2), "thumb rectangle not updated\n");
780
781 /* test position update on range change */
782
783 /* set to [20, 50], position at 30, reduce range to [20,25] */
784 SendMessageA(hWndTrackbar, TBM_SETRANGEMIN, FALSE, 20);
785 SendMessageA(hWndTrackbar, TBM_SETRANGEMAX, FALSE, 50);
786 SendMessageA(hWndTrackbar, TBM_SETPOS, FALSE, 30);
787 SendMessageA(hWndTrackbar, TBM_SETRANGEMAX, FALSE, 25);
788 r = SendMessageA(hWndTrackbar, TBM_GETPOS, 0, 0);
789 ok(r == 25, "Unexpected position %d\n", r);
790
791 /* set to [20, 50], position at 30, flip max to 10 */
792 SendMessageA(hWndTrackbar, TBM_SETRANGEMIN, FALSE, 20);
793 SendMessageA(hWndTrackbar, TBM_SETRANGEMAX, FALSE, 50);
794 SendMessageA(hWndTrackbar, TBM_SETPOS, FALSE, 30);
795 SendMessageA(hWndTrackbar, TBM_SETRANGEMAX, FALSE, 10);
796 r = SendMessageA(hWndTrackbar, TBM_GETPOS, 0, 0);
797 ok(r == 20, "Unexpected position %d\n", r);
798
799 /* set to [20, 50], position at 30, flip min to 70 */
800 SendMessageA(hWndTrackbar, TBM_SETRANGEMIN, FALSE, 20);
801 SendMessageA(hWndTrackbar, TBM_SETRANGEMAX, FALSE, 50);
802 SendMessageA(hWndTrackbar, TBM_SETPOS, FALSE, 30);
803 SendMessageA(hWndTrackbar, TBM_SETRANGEMIN, FALSE, 70);
804 r = SendMessageA(hWndTrackbar, TBM_GETPOS, 0, 0);
805 ok(r == 70, "Unexpected position %d\n", r);
806
807 DestroyWindow(hWndTrackbar);
808 }
809
810 static void test_selection(void)
811 {
812 HWND hWndTrackbar;
813 int r;
814
815 hWndTrackbar = create_trackbar(defaultstyle, hWndParent);
816 ok(hWndTrackbar != NULL, "Expected non NULL value\n");
817
818 SendMessageA(hWndTrackbar, TBM_SETRANGEMIN, FALSE, 5);
819 SendMessageA(hWndTrackbar, TBM_SETRANGEMAX, FALSE, 10);
820
821 flush_sequences(sequences, NUM_MSG_SEQUENCE);
822
823 /* test TBM_SETSEL */
824 SendMessageA(hWndTrackbar, TBM_SETSEL, TRUE, MAKELONG(0,10));
825 r = SendMessageA(hWndTrackbar, TBM_GETSELEND, 0,0);
826 expect(10, r);
827 r = SendMessageA(hWndTrackbar, TBM_GETSELSTART, 0,0);
828 expect(5, r);
829 SendMessageA(hWndTrackbar, TBM_SETSEL, TRUE, MAKELONG(5, 20));
830 r = SendMessageA(hWndTrackbar, TBM_GETSELEND, 0,0);
831 expect(10, r);
832 r = SendMessageA(hWndTrackbar, TBM_GETSELSTART, 0,0);
833 expect(5, r);
834 SendMessageA(hWndTrackbar, TBM_SETSEL, FALSE, MAKELONG(5, 10));
835 r = SendMessageA(hWndTrackbar, TBM_GETSELEND, 0,0);
836 expect(10, r);
837 r = SendMessageA(hWndTrackbar, TBM_GETSELSTART, 0,0);
838 expect(5, r);
839
840 /* test TBM_SETSELEND */
841 SendMessageA(hWndTrackbar, TBM_SETSELEND, TRUE, 10);
842 r = SendMessageA(hWndTrackbar, TBM_GETSELEND, 0,0);
843 expect(10, r);
844 SendMessageA(hWndTrackbar, TBM_SETSELEND, TRUE, 20);
845 r = SendMessageA(hWndTrackbar, TBM_GETSELEND, 0,0);
846 expect(10, r);
847 SendMessageA(hWndTrackbar, TBM_SETSELEND, TRUE, 4);
848 r = SendMessageA(hWndTrackbar, TBM_GETSELEND, 0,0);
849 expect(4, r);
850 SendMessageA(hWndTrackbar, TBM_SETSELEND, FALSE, 2);
851 r = SendMessageA(hWndTrackbar, TBM_GETSELEND, 0,0);
852 expect(2, r);
853
854 /* test TBM_GETSELEND */
855 r = SendMessageA(hWndTrackbar, TBM_GETSELEND, 0,0);
856 expect(2, r);
857
858 /* testing TBM_SETSELSTART */
859 SendMessageA(hWndTrackbar, TBM_SETSELSTART, TRUE, 5);
860 r = SendMessageA(hWndTrackbar, TBM_GETSELSTART, 0,0);
861 expect(5, r);
862 SendMessageA(hWndTrackbar, TBM_SETSELSTART, TRUE, 0);
863 r = SendMessageA(hWndTrackbar, TBM_GETSELSTART, 0,0);
864 expect(5, r);
865 SendMessageA(hWndTrackbar, TBM_SETSELSTART, TRUE, 20);
866 r = SendMessageA(hWndTrackbar, TBM_GETSELSTART, 0,0);
867 expect(20, r);
868 SendMessageA(hWndTrackbar, TBM_SETSELSTART, FALSE, 8);
869 r = SendMessageA(hWndTrackbar, TBM_GETSELSTART, 0,0);
870 expect(8, r);
871
872 /* test TBM_GETSELSTART */
873 r = SendMessageA(hWndTrackbar, TBM_GETSELSTART, 0,0);
874 expect(8, r);
875
876 ok_sequence(sequences, TRACKBAR_SEQ_INDEX, selection_test_seq, "selection test sequence", TRUE);
877 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_selection_test_seq, "parent selection test sequence", TRUE);
878
879 DestroyWindow(hWndTrackbar);
880 }
881
882 static void test_thumb_length(void)
883 {
884 HWND hWndTrackbar;
885 int r;
886
887 hWndTrackbar = create_trackbar(defaultstyle, hWndParent);
888 ok(hWndTrackbar != NULL, "Expected non NULL value\n");
889
890 flush_sequences(sequences, NUM_MSG_SEQUENCE);
891
892 /* testing TBM_SETTHUMBLENGTH */
893 SendMessageA(hWndTrackbar, TBM_SETTHUMBLENGTH, 15, 0);
894 r = SendMessageA(hWndTrackbar, TBM_GETTHUMBLENGTH, 0,0);
895 expect(15, r);
896 SendMessageA(hWndTrackbar, TBM_SETTHUMBLENGTH, 20, 0);
897 r = SendMessageA(hWndTrackbar, TBM_GETTHUMBLENGTH, 0,0);
898 expect(20, r);
899
900 /* test TBM_GETTHUMBLENGTH */
901 r = SendMessageA(hWndTrackbar, TBM_GETTHUMBLENGTH, 0,0);
902 expect(20, r);
903
904 r = SendMessageA(hWndTrackbar, WM_SIZE, 0,0);
905 expect(0, r);
906 r = SendMessageA(hWndTrackbar, TBM_GETTHUMBLENGTH, 0,0);
907 expect(20, r);
908 r = SendMessageA(hWndTrackbar, WM_SIZE, 0, MAKELPARAM(50, 50) );
909 expect(0, r);
910 r = SendMessageA(hWndTrackbar, TBM_GETTHUMBLENGTH, 0,0);
911 expect(20, r);
912
913 ok_sequence(sequences, TRACKBAR_SEQ_INDEX, thumb_length_test_seq, "thumb length test sequence", TRUE);
914 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_thumb_length_test_seq, "parent thumb length test sequence", TRUE);
915
916 DestroyWindow(hWndTrackbar);
917 }
918
919 static void test_tic_settings(void)
920 {
921 HWND hWndTrackbar;
922 int r, i;
923
924 hWndTrackbar = create_trackbar(defaultstyle, hWndParent);
925 ok(hWndTrackbar != NULL, "Expected non NULL value\n");
926
927 SendMessageA(hWndTrackbar, TBM_SETRANGEMIN, FALSE, 5);
928 SendMessageA(hWndTrackbar, TBM_SETRANGEMAX, FALSE, 10);
929
930 /* testing TBM_SETTIC */
931 /* Set tics at 5 and 10 */
932 /* 0 and 20 are out of range and should not be set */
933 r = SendMessageA(hWndTrackbar, TBM_GETRANGEMAX, 0, 0);
934 expect(10, r);
935 r = SendMessageA(hWndTrackbar, TBM_GETRANGEMIN, 0, 0);
936 expect(5, r);
937
938 flush_sequences(sequences, NUM_MSG_SEQUENCE);
939 r = SendMessageA(hWndTrackbar, TBM_SETTIC, 0, 0);
940 ok(r == FALSE, "Expected FALSE, got %d\n", r);
941 r = SendMessageA(hWndTrackbar, TBM_SETTIC, 0, 5);
942 ok(r == TRUE, "Expected TRUE, got %d\n", r);
943 r = SendMessageA(hWndTrackbar, TBM_SETTIC, 0, 10);
944 ok(r == TRUE, "Expected TRUE, got %d\n", r);
945
946 r = SendMessageA(hWndTrackbar, TBM_SETTIC, 0, 20);
947 ok(r == FALSE, "Expected FALSE, got %d\n", r);
948
949 /* test TBM_SETTICFREQ */
950 SendMessageA(hWndTrackbar, TBM_SETRANGE, TRUE, MAKELONG(0, 10));
951 SendMessageA(hWndTrackbar, TBM_SETTICFREQ, 2, 0);
952 r = SendMessageA(hWndTrackbar, TBM_GETNUMTICS, 0, 0);
953 expect(6, r);
954 SendMessageA(hWndTrackbar, TBM_SETTICFREQ, 5, 0);
955 r = SendMessageA(hWndTrackbar, TBM_GETNUMTICS, 0, 0);
956 expect(3, r);
957 SendMessageA(hWndTrackbar, TBM_SETTICFREQ, 15, 0);
958 r = SendMessageA(hWndTrackbar, TBM_GETNUMTICS, 0, 0);
959 expect(2, r);
960
961 /* test TBM_GETNUMTICS */
962 /* since TIC FREQ is 15, there should be only 2 tics now */
963 r = SendMessageA(hWndTrackbar, TBM_GETNUMTICS, 0, 0);
964 expect(2, r);
965
966 ok_sequence(sequences, TRACKBAR_SEQ_INDEX, tic_settings_test_seq, "tic settings test sequence", TRUE);
967 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_tic_settings_test_seq, "parent tic settings test sequence", TRUE);
968
969 /* range [0,0], freq = 1 */
970 SendMessageA(hWndTrackbar, TBM_SETRANGEMAX, TRUE, 0);
971 SendMessageA(hWndTrackbar, TBM_SETRANGEMIN, TRUE, 0);
972 SendMessageA(hWndTrackbar, TBM_SETTICFREQ, 1, 0);
973 r = SendMessageA(hWndTrackbar, TBM_GETNUMTICS, 0, 0);
974 expect(2, r);
975 /* range [0,1], freq = 1 */
976 SendMessageA(hWndTrackbar, TBM_SETRANGEMAX, TRUE, 1);
977 SendMessageA(hWndTrackbar, TBM_SETRANGEMIN, TRUE, 0);
978 SendMessageA(hWndTrackbar, TBM_SETTICFREQ, 1, 0);
979 r = SendMessageA(hWndTrackbar, TBM_GETNUMTICS, 0, 0);
980 expect(2, r);
981 /* range [0,2], freq = 1 */
982 SendMessageA(hWndTrackbar, TBM_SETRANGEMAX, TRUE, 2);
983 SendMessageA(hWndTrackbar, TBM_SETRANGEMIN, TRUE, 0);
984 SendMessageA(hWndTrackbar, TBM_SETTICFREQ, 1, 0);
985 r = SendMessageA(hWndTrackbar, TBM_GETNUMTICS, 0, 0);
986 expect(3, r);
987
988 DestroyWindow(hWndTrackbar);
989
990 /* Test to show that TBM_SETTICFREQ updates thumb */
991 for (i = 0; i < 2; i++)
992 {
993 DWORD style = i ? defaultstyle : defaultstyle & ~TBS_AUTOTICKS;
994 RECT rect, rect1;
995 WNDPROC oldproc;
996
997 hWndTrackbar = create_trackbar2(style, hWndParent);
998 ok(hWndTrackbar != NULL, "Expected non NULL value\n");
999
1000 oldproc = (WNDPROC)SetWindowLongPtrA(hWndTrackbar, GWLP_WNDPROC, (LONG_PTR)trackbar_no_wmpaint_proc);
1001 SetWindowLongPtrA(hWndTrackbar, GWLP_USERDATA, (LONG_PTR)oldproc);
1002
1003 SendMessageA(hWndTrackbar, TBM_GETTHUMBRECT, 0, (LPARAM)&rect);
1004 SendMessageA(hWndTrackbar, TBM_SETPOS, FALSE, 0);
1005 SendMessageA(hWndTrackbar, TBM_GETTHUMBRECT, 0, (LPARAM)&rect1);
1006 ok(EqualRect(&rect, &rect1), "Unexpected thumb rectangle %s, previous %s\n",
1007 wine_dbgstr_rect(&rect1), wine_dbgstr_rect(&rect));
1008
1009 SendMessageA(hWndTrackbar, TBM_GETTHUMBRECT, 0, (LPARAM)&rect);
1010 SendMessageA(hWndTrackbar, TBM_SETRANGE, FALSE, MAKELONG(-100, 100));
1011 SendMessageA(hWndTrackbar, TBM_GETTHUMBRECT, 0, (LPARAM)&rect1);
1012 ok(EqualRect(&rect, &rect1), "Unexpected thumb rectangle %s, previous %s\n",
1013 wine_dbgstr_rect(&rect1), wine_dbgstr_rect(&rect));
1014 /* Old position is also 0, but thumb position will be different after range change */
1015 SendMessageA(hWndTrackbar, TBM_GETTHUMBRECT, 0, (LPARAM)&rect);
1016 SendMessageA(hWndTrackbar, TBM_SETPOS, TRUE, 0);
1017 SendMessageA(hWndTrackbar, TBM_GETTHUMBRECT, 0, (LPARAM)&rect1);
1018 ok(EqualRect(&rect, &rect1), "Unexpected thumb rectangle %s, previous %s\n",
1019 wine_dbgstr_rect(&rect1), wine_dbgstr_rect(&rect));
1020 /* Previous frequency is also 1, yet thumb is updated */
1021 SendMessageA(hWndTrackbar, TBM_GETTHUMBRECT, 0, (LPARAM)&rect);
1022 SendMessageA(hWndTrackbar, TBM_SETTICFREQ, 1, 0);
1023 SendMessageA(hWndTrackbar, TBM_GETTHUMBRECT, 0, (LPARAM)&rect1);
1024 ok(!EqualRect(&rect, &rect1), "Unexpected thumb rectangle %s, previous %s\n",
1025 wine_dbgstr_rect(&rect1), wine_dbgstr_rect(&rect));
1026
1027 SetWindowLongPtrA(hWndTrackbar, GWLP_WNDPROC, (LONG_PTR)oldproc);
1028
1029 DestroyWindow(hWndTrackbar);
1030 }
1031 }
1032
1033 static void test_tic_placement(void)
1034 {
1035 HWND hWndTrackbar;
1036 int r;
1037 DWORD *rPTics;
1038 DWORD numtics;
1039
1040 hWndTrackbar = create_trackbar(defaultstyle, hWndParent);
1041 ok(hWndTrackbar != NULL, "Expected non NULL value\n");
1042
1043 SendMessageA(hWndTrackbar, TBM_SETRANGE, TRUE, MAKELONG(1, 6));
1044 SendMessageA(hWndTrackbar, TBM_SETTICFREQ, 1, 0);
1045
1046 numtics = SendMessageA(hWndTrackbar, TBM_GETNUMTICS, 0, 0);
1047 ok(numtics == 6, "Expected 6, got %d\n", numtics);
1048
1049 flush_sequences(sequences, NUM_MSG_SEQUENCE);
1050 /* test TBM_GETPTICS */
1051 rPTics = (DWORD *) SendMessageA(hWndTrackbar, TBM_GETPTICS, 0,0);
1052 expect(2, rPTics[0]);
1053 expect(3, rPTics[1]);
1054 expect(4, rPTics[2]);
1055 expect(5, rPTics[3]);
1056
1057 /* test TBM_GETTIC */
1058 r = SendMessageA(hWndTrackbar, TBM_GETTIC, 0,0);
1059 expect(2, r);
1060 r = SendMessageA(hWndTrackbar, TBM_GETTIC, 2,0);
1061 expect(4, r);
1062 r = SendMessageA(hWndTrackbar, TBM_GETTIC, 4,0);
1063 expect(-1, r);
1064
1065 /* test TBM_GETTICPIC */
1066 r = SendMessageA(hWndTrackbar, TBM_GETTICPOS, 0, 0);
1067 ok(r > 0, "Expected r > 0, got %d\n", r);
1068 r = SendMessageA(hWndTrackbar, TBM_GETTICPOS, 2, 0);
1069 ok(r > 0, "Expected r > 0, got %d\n", r);
1070
1071 ok_sequence(sequences, TRACKBAR_SEQ_INDEX, tic_placement_test_seq, "get tic placement test sequence", FALSE);
1072 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "parent get tic placement test sequence", FALSE);
1073
1074 DestroyWindow(hWndTrackbar);
1075 }
1076
1077 static void test_tool_tips(void)
1078 {
1079 HWND hWndTooltip, hWndTrackbar;
1080 HWND rTest;
1081 int r;
1082
1083 hWndTrackbar = create_trackbar(defaultstyle, hWndParent);
1084 ok(hWndTrackbar != NULL, "Expected non NULL value\n");
1085
1086 flush_sequences(sequences, NUM_MSG_SEQUENCE);
1087
1088 /* testing TBM_SETTIPSIDE */
1089 r = SendMessageA(hWndTrackbar, TBM_SETTIPSIDE, TBTS_TOP, 0);
1090 expect(TBTS_TOP, r);
1091 r = SendMessageA(hWndTrackbar, TBM_SETTIPSIDE, TBTS_LEFT, 0);
1092 expect(TBTS_TOP, r);
1093 r = SendMessageA(hWndTrackbar, TBM_SETTIPSIDE, TBTS_BOTTOM, 0);
1094 expect(TBTS_LEFT, r);
1095 r = SendMessageA(hWndTrackbar, TBM_SETTIPSIDE, TBTS_RIGHT, 0);
1096 expect(TBTS_BOTTOM, r);
1097
1098 /* testing TBM_SETTOOLTIPS */
1099 hWndTooltip = CreateWindowExA(WS_EX_TOPMOST, TOOLTIPS_CLASSA, NULL, 0,
1100 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
1101 NULL, NULL, NULL, NULL);
1102
1103 ok(hWndTooltip != NULL, "Expected non NULL value\n");
1104 if (hWndTooltip != NULL){
1105 SendMessageA(hWndTrackbar, TBM_SETTOOLTIPS, (LPARAM) hWndTooltip, 0);
1106 rTest = (HWND) SendMessageA(hWndTrackbar, TBM_GETTOOLTIPS, 0,0);
1107 ok(rTest == hWndTooltip, "Expected hWndToolTip, got\n");
1108 SendMessageA(hWndTrackbar, TBM_SETTOOLTIPS, 0, 0);
1109 rTest = (HWND) SendMessageA(hWndTrackbar, TBM_GETTOOLTIPS, 0,0);
1110 ok(rTest == NULL, "Expected NULL\n");
1111 SendMessageA(hWndTrackbar, TBM_SETTOOLTIPS, (LPARAM) hWndTooltip, 5);
1112 rTest = (HWND) SendMessageA(hWndTrackbar, TBM_GETTOOLTIPS, 0,0);
1113 ok(rTest == hWndTooltip, "Expected hWndTooltip, got\n");
1114 } else
1115 skip("tool tip control not present?\n");
1116
1117 /* test TBM_GETTOOLTIPS */
1118 rTest = (HWND) SendMessageA(hWndTrackbar, TBM_GETTOOLTIPS, 0,0);
1119 ok(rTest == hWndTooltip, "Expected hWndTooltip\n");
1120
1121 ok_sequence(sequences, TRACKBAR_SEQ_INDEX, tool_tips_test_seq, "tool tips test sequence", FALSE);
1122 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "parent tool tips test sequence", FALSE);
1123
1124 DestroyWindow(hWndTrackbar);
1125 }
1126
1127
1128 static void test_unicode(void)
1129 {
1130 HWND hWndTrackbar;
1131 int r;
1132
1133 hWndTrackbar = create_trackbar(defaultstyle, hWndParent);
1134 ok(hWndTrackbar != NULL, "Expected non NULL value\n");
1135
1136 flush_sequences(sequences, NUM_MSG_SEQUENCE);
1137
1138 /* testing TBM_SETUNICODEFORMAT */
1139 r = SendMessageA(hWndTrackbar, TBM_SETUNICODEFORMAT, TRUE, 0);
1140 ok(r == FALSE, "Expected FALSE, got %d\n",r);
1141 r = SendMessageA(hWndTrackbar, TBM_SETUNICODEFORMAT, FALSE, 0);
1142 ok(r == TRUE, "Expected TRUE, got %d\n",r);
1143
1144 /* test TBM_GETUNICODEFORMAT */
1145 r = SendMessageA(hWndTrackbar, TBM_GETUNICODEFORMAT, 0,0);
1146 ok(r == FALSE, "Expected FALSE, got %d\n",r);
1147
1148 ok_sequence(sequences, TRACKBAR_SEQ_INDEX, unicode_test_seq, "unicode test sequence", FALSE);
1149 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "parent unicode test sequence", FALSE);
1150
1151 DestroyWindow(hWndTrackbar);
1152 }
1153
1154 static void test_ignore_selection(void)
1155 {
1156 HWND hWndTrackbar;
1157 int r;
1158
1159 hWndTrackbar = create_trackbar(0, hWndParent);
1160 ok(hWndTrackbar != NULL, "Expected non NULL value\n");
1161
1162 flush_sequences(sequences, NUM_MSG_SEQUENCE);
1163 /* test TBM_SETSEL ensure that it is ignored */
1164 SendMessageA(hWndTrackbar, TBM_SETSEL, TRUE, MAKELONG(0,10));
1165 r = SendMessageA(hWndTrackbar, TBM_GETSELEND, 0,0);
1166 expect(0, r);
1167 r = SendMessageA(hWndTrackbar, TBM_GETSELSTART, 0,0);
1168 expect(0, r);
1169 SendMessageA(hWndTrackbar, TBM_SETSEL, FALSE, MAKELONG(0,10));
1170 r = SendMessageA(hWndTrackbar, TBM_GETSELEND, 0,0);
1171 expect(0, r);
1172 r = SendMessageA(hWndTrackbar, TBM_GETSELSTART, 0,0);
1173 expect(0, r);
1174
1175 /* test TBM_SETSELEND, ensure that it is ignored */
1176 SendMessageA(hWndTrackbar, TBM_SETSELEND, TRUE, 0);
1177 r = SendMessageA(hWndTrackbar, TBM_GETSELEND, 0,0);
1178 expect(0, r);
1179 SendMessageA(hWndTrackbar, TBM_SETSELEND, TRUE, 10);
1180 r = SendMessageA(hWndTrackbar, TBM_GETSELEND, 0,0);
1181 expect(0,r);
1182 SendMessageA(hWndTrackbar, TBM_SETSELEND, FALSE, 0);
1183 r = SendMessageA(hWndTrackbar, TBM_GETSELEND, 0,0);
1184 expect(0, r);
1185
1186 /* test TBM_SETSELSTART, ensure that it is ignored */
1187 SendMessageA(hWndTrackbar, TBM_SETSELSTART, TRUE, 0);
1188 r = SendMessageA(hWndTrackbar, TBM_GETSELSTART, 0,0);
1189 expect(0, r);
1190 SendMessageA(hWndTrackbar, TBM_SETSELSTART, TRUE, 10);
1191 r = SendMessageA(hWndTrackbar, TBM_GETSELSTART, 0,0);
1192 expect(0,r);
1193 SendMessageA(hWndTrackbar, TBM_SETSELSTART, FALSE, 0);
1194 r = SendMessageA(hWndTrackbar, TBM_GETSELSTART, 0,0);
1195 expect(0, r);
1196
1197 ok_sequence(sequences, TRACKBAR_SEQ_INDEX, ignore_selection_test_seq, "ignore selection setting test sequence", FALSE);
1198 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "parent ignore selection setting test sequence", FALSE);
1199
1200 DestroyWindow(hWndTrackbar);
1201 }
1202
1203 static void test_initial_state(void)
1204 {
1205 HWND hWnd;
1206 int ret;
1207
1208 hWnd = create_trackbar(0, hWndParent);
1209
1210 ret = SendMessageA(hWnd, TBM_GETNUMTICS, 0, 0);
1211 expect(2, ret);
1212 ret = SendMessageA(hWnd, TBM_GETTIC, 0, 0);
1213 expect(-1, ret);
1214 ret = SendMessageA(hWnd, TBM_GETTICPOS, 0, 0);
1215 expect(-1, ret);
1216 ret = SendMessageA(hWnd, TBM_GETRANGEMIN, 0, 0);
1217 expect(0, ret);
1218 ret = SendMessageA(hWnd, TBM_GETRANGEMAX, 0, 0);
1219 expect(100, ret);
1220
1221 ret = SendMessageA(hWnd, TBM_SETRANGEMAX, TRUE, 200);
1222 expect(0, ret);
1223
1224 ret = SendMessageA(hWnd, TBM_GETNUMTICS, 0, 0);
1225 expect(2, ret);
1226
1227 ret = SendMessageA(hWnd, TBM_SETRANGEMIN, TRUE, 10);
1228 expect(0, ret);
1229
1230 ret = SendMessageA(hWnd, TBM_GETNUMTICS, 0, 0);
1231 expect(2, ret);
1232
1233 DestroyWindow(hWnd);
1234 }
1235
1236 static void test_TBS_AUTOTICKS(void)
1237 {
1238 HWND hWnd;
1239 int ret;
1240
1241 hWnd = create_trackbar(TBS_AUTOTICKS, hWndParent);
1242
1243 ret = SendMessageA(hWnd, TBM_GETNUMTICS, 0, 0);
1244 expect(2, ret);
1245 ret = SendMessageA(hWnd, TBM_GETTIC, 0, 0);
1246 expect(-1, ret);
1247 ret = SendMessageA(hWnd, TBM_GETTICPOS, 0, 0);
1248 expect(-1, ret);
1249 ret = SendMessageA(hWnd, TBM_GETRANGEMIN, 0, 0);
1250 expect(0, ret);
1251 ret = SendMessageA(hWnd, TBM_GETRANGEMAX, 0, 0);
1252 expect(100, ret);
1253
1254 /* TBM_SETRANGEMAX rebuilds tics */
1255 ret = SendMessageA(hWnd, TBM_SETRANGEMAX, TRUE, 200);
1256 expect(0, ret);
1257 ret = SendMessageA(hWnd, TBM_GETNUMTICS, 0, 0);
1258 expect(201, ret);
1259
1260 /* TBM_SETRANGEMIN rebuilds tics */
1261 ret = SendMessageA(hWnd, TBM_SETRANGEMAX, TRUE, 100);
1262 expect(0, ret);
1263 ret = SendMessageA(hWnd, TBM_SETRANGEMIN, TRUE, 10);
1264 expect(0, ret);
1265 ret = SendMessageA(hWnd, TBM_GETNUMTICS, 0, 0);
1266 expect(91, ret);
1267
1268 ret = SendMessageA(hWnd, TBM_SETRANGEMIN, TRUE, 0);
1269 expect(0, ret);
1270
1271 /* TBM_SETRANGE rebuilds tics */
1272 ret = SendMessageA(hWnd, TBM_SETRANGE, TRUE, MAKELONG(10, 200));
1273 expect(0, ret);
1274 ret = SendMessageA(hWnd, TBM_GETNUMTICS, 0, 0);
1275 expect(191, ret);
1276
1277 DestroyWindow(hWnd);
1278 }
1279
1280 static void test_create(void)
1281 {
1282 HWND hWndTrackbar;
1283
1284 flush_sequences(sequences, NUM_MSG_SEQUENCE);
1285
1286 hWndTrackbar = create_trackbar(defaultstyle, hWndParent);
1287 ok(hWndTrackbar != NULL, "Expected non NULL value\n");
1288 ok_sequence(sequences, TRACKBAR_SEQ_INDEX, empty_seq, "create Trackbar Window", FALSE);
1289 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_create_trackbar_wnd_seq, "parent trackbar window", TRUE);
1290
1291 DestroyWindow(hWndTrackbar);
1292
1293 /* no style bits */
1294 flush_sequences(sequences, NUM_MSG_SEQUENCE);
1295 hWndTrackbar = create_trackbar(0, hWndParent);
1296 ok(hWndTrackbar != NULL, "Expected non NULL value\n");
1297 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_new_window_test_seq, "new trackbar window test sequence", TRUE);
1298 DestroyWindow(hWndTrackbar);
1299 }
1300
1301 START_TEST(trackbar)
1302 {
1303 init_msg_sequences(sequences, NUM_MSG_SEQUENCE);
1304 InitCommonControls();
1305
1306 /* create parent window */
1307 hWndParent = create_parent_window();
1308 ok(hWndParent != NULL, "Failed to create parent Window!\n");
1309
1310 if(!hWndParent){
1311 skip("parent window not present\n");
1312 return;
1313 }
1314
1315 test_create();
1316 test_trackbar_buddy();
1317 test_line_size();
1318 test_page_size();
1319 test_position();
1320 test_range();
1321 test_selection();
1322 test_thumb_length();
1323 test_tic_settings();
1324 test_tic_placement();
1325 test_tool_tips();
1326 test_unicode();
1327 test_TBS_AUTOTICKS();
1328 test_ignore_selection();
1329 test_initial_state();
1330
1331 DestroyWindow(hWndParent);
1332 }