Release 1.6-rc2.
[wine/testsucceed.git] / dlls / comctl32 / tests / monthcal.c
blob5440f49760a974427420fdf41c1c6e15d11817e7
1 /*
2 * comctl32 month calendar unit tests
4 * Copyright (C) 2006 Vitaliy Margolen
5 * Copyright (C) 2007 Farshad Agah
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <stdarg.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winuser.h"
28 #include "commctrl.h"
30 #include "wine/test.h"
31 #include "v6util.h"
32 #include <assert.h>
33 #include <windows.h>
34 #include "msg.h"
36 #define expect(expected, got) ok(expected == got, "Expected %d, got %d\n", expected, got);
37 #define expect_hex(expected, got) ok(expected == got, "Expected %x, got %x\n", expected, got);
38 #define expect_d(expected, got) ok(abs((expected) - (got)) <= 2, "Expected %d, got %d\n", expected, got);
40 #define NUM_MSG_SEQUENCES 2
41 #define PARENT_SEQ_INDEX 0
42 #define MONTHCAL_SEQ_INDEX 1
44 #define SEL_NOTIFY_TEST_ID 100
46 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
48 static HWND parent_wnd;
50 static const struct message create_parent_window_seq[] = {
51 { WM_GETMINMAXINFO, sent },
52 { WM_NCCREATE, sent },
53 { WM_NCCALCSIZE, sent|wparam, 0 },
54 { WM_CREATE, sent },
55 { WM_SHOWWINDOW, sent|wparam, 1 },
56 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
57 { WM_QUERYNEWPALETTE, sent|optional },
58 { WM_WINDOWPOSCHANGING, sent|wparam|optional, 0 },
59 { WM_WINDOWPOSCHANGED, sent|optional },
60 { WM_ACTIVATEAPP, sent|wparam, 1 },
61 { WM_NCACTIVATE, sent },
62 { WM_ACTIVATE, sent|wparam, 1 },
63 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
64 { WM_IME_NOTIFY, sent|defwinproc|optional },
65 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
66 /* Win9x adds SWP_NOZORDER below */
67 { WM_WINDOWPOSCHANGED, sent, /*|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ },
68 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
69 { WM_SIZE, sent },
70 { WM_MOVE, sent },
71 { 0 }
74 static const struct message create_monthcal_control_seq[] = {
75 { WM_NOTIFYFORMAT, sent|lparam, 0, NF_QUERY },
76 { WM_QUERYUISTATE, sent|optional },
77 { WM_GETFONT, sent },
78 { WM_PARENTNOTIFY, sent|wparam, WM_CREATE},
79 { 0 }
82 static const struct message create_monthcal_multi_sel_style_seq[] = {
83 { WM_NOTIFYFORMAT, sent|lparam, 0, NF_QUERY },
84 { WM_QUERYUISTATE, sent|optional },
85 { WM_GETFONT, sent },
86 { WM_PARENTNOTIFY, sent },
87 { 0 }
90 static const struct message monthcal_curr_date_seq[] = {
91 { MCM_SETCURSEL, sent|wparam, 0},
92 { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
93 { MCM_SETCURSEL, sent|wparam, 0},
94 { MCM_SETCURSEL, sent|wparam, 0},
95 { MCM_GETCURSEL, sent|wparam, 0},
96 { MCM_GETCURSEL, sent|wparam|lparam, 0, 0},
97 { 0 }
100 static const struct message monthcal_first_day_seq[] = {
101 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
103 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -5},
104 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
106 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -4},
107 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
109 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -3},
110 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
112 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -2},
113 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
115 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -1},
116 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
118 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
119 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
121 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 1},
122 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
124 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 2},
125 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
127 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 3},
128 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
130 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 4},
131 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
133 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 5},
134 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
136 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 6},
137 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
139 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 7},
140 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
142 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 8},
143 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
145 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 9},
146 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
148 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 10},
149 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
151 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 11},
152 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
153 { 0 }
156 static const struct message monthcal_unicode_seq[] = {
157 { MCM_GETUNICODEFORMAT, sent|wparam|lparam, 0, 0},
158 { MCM_SETUNICODEFORMAT, sent|wparam|lparam, 1, 0},
159 { MCM_GETUNICODEFORMAT, sent|wparam|lparam, 0, 0},
160 { MCM_SETUNICODEFORMAT, sent|wparam|lparam, 0, 0},
161 { MCM_GETUNICODEFORMAT, sent|wparam|lparam, 0, 0},
162 { MCM_SETUNICODEFORMAT, sent|wparam|lparam, 1, 0},
163 { 0 }
166 static const struct message monthcal_hit_test_seq[] = {
167 { MCM_SETCURSEL, sent|wparam, 0},
168 { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
169 { MCM_HITTEST, sent|wparam, 0},
170 { MCM_HITTEST, sent|wparam, 0},
171 { MCM_HITTEST, sent|wparam, 0},
172 { MCM_HITTEST, sent|wparam, 0},
173 { MCM_HITTEST, sent|wparam, 0},
174 { MCM_HITTEST, sent|wparam, 0},
175 { MCM_HITTEST, sent|wparam, 0},
176 { MCM_HITTEST, sent|wparam, 0},
177 { MCM_HITTEST, sent|wparam, 0},
178 { MCM_HITTEST, sent|wparam, 0},
179 { 0 }
182 static const struct message monthcal_todaylink_seq[] = {
183 { MCM_HITTEST, sent|wparam, 0},
184 { MCM_SETTODAY, sent|wparam, 0},
185 { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
186 { MCM_GETTODAY, sent|wparam, 0},
187 { WM_LBUTTONDOWN, sent|wparam, MK_LBUTTON},
188 { WM_CAPTURECHANGED, sent|wparam|lparam|defwinproc, 0, 0},
189 { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
190 { MCM_GETCURSEL, sent|wparam, 0},
191 { 0 }
194 static const struct message monthcal_today_seq[] = {
195 { MCM_SETTODAY, sent|wparam, 0},
196 { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
197 { MCM_GETTODAY, sent|wparam, 0},
198 { MCM_SETTODAY, sent|wparam, 0},
199 { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
200 { MCM_GETTODAY, sent|wparam, 0},
201 { 0 }
204 static const struct message monthcal_scroll_seq[] = {
205 { MCM_SETMONTHDELTA, sent|wparam|lparam, 2, 0},
206 { MCM_SETMONTHDELTA, sent|wparam|lparam, 3, 0},
207 { MCM_GETMONTHDELTA, sent|wparam|lparam, 0, 0},
208 { MCM_SETMONTHDELTA, sent|wparam|lparam, 12, 0},
209 { MCM_GETMONTHDELTA, sent|wparam|lparam, 0, 0},
210 { MCM_SETMONTHDELTA, sent|wparam|lparam, 15, 0},
211 { MCM_GETMONTHDELTA, sent|wparam|lparam, 0, 0},
212 { MCM_SETMONTHDELTA, sent|wparam|lparam, -5, 0},
213 { MCM_GETMONTHDELTA, sent|wparam|lparam, 0, 0},
214 { 0 }
217 static const struct message monthcal_monthrange_seq[] = {
218 { MCM_GETMONTHRANGE, sent|wparam, GMR_VISIBLE},
219 { MCM_GETMONTHRANGE, sent|wparam, GMR_DAYSTATE},
220 { 0 }
223 static const struct message monthcal_max_sel_day_seq[] = {
224 { MCM_SETMAXSELCOUNT, sent|wparam|lparam, 5, 0},
225 { MCM_GETMAXSELCOUNT, sent|wparam|lparam, 0, 0},
226 { MCM_SETMAXSELCOUNT, sent|wparam|lparam, 15, 0},
227 { MCM_GETMAXSELCOUNT, sent|wparam|lparam, 0, 0},
228 { MCM_SETMAXSELCOUNT, sent|wparam|lparam, -1, 0},
229 { MCM_GETMAXSELCOUNT, sent|wparam|lparam, 0, 0},
230 { 0 }
233 /* expected message sequence for parent*/
234 static const struct message destroy_monthcal_parent_msgs_seq[] = {
235 { WM_PARENTNOTIFY, sent|wparam, WM_DESTROY},
236 { 0 }
239 /* expected message sequence for child*/
240 static const struct message destroy_monthcal_child_msgs_seq[] = {
241 { 0x0090, sent|optional }, /* Vista */
242 { WM_SHOWWINDOW, sent|wparam|lparam, 0, 0},
243 { WM_WINDOWPOSCHANGING, sent|wparam, 0},
244 { WM_WINDOWPOSCHANGED, sent|wparam, 0},
245 { WM_DESTROY, sent|wparam|lparam, 0, 0},
246 { WM_NCDESTROY, sent|wparam|lparam, 0, 0},
247 { 0 }
250 static const struct message destroy_monthcal_multi_sel_style_seq[] = {
251 { 0x0090, sent|optional }, /* Vista */
252 { WM_SHOWWINDOW, sent|wparam|lparam, 0, 0},
253 { WM_WINDOWPOSCHANGING, sent|wparam, 0},
254 { WM_WINDOWPOSCHANGED, sent|wparam, 0},
255 { WM_DESTROY, sent|wparam|lparam, 0, 0},
256 { WM_NCDESTROY, sent|wparam|lparam, 0, 0},
257 { 0 }
260 static void test_monthcal(void)
262 HWND hwnd;
263 SYSTEMTIME st[2], st1[2], today;
264 int res, month_range;
265 DWORD limits;
267 hwnd = CreateWindowA(MONTHCAL_CLASSA, "MonthCal", WS_POPUP | WS_VISIBLE, CW_USEDEFAULT,
268 0, 300, 300, 0, 0, NULL, NULL);
269 ok(hwnd != NULL, "Failed to create MonthCal\n");
271 /* test range just after creation */
272 memset(&st, 0xcc, sizeof(st));
273 limits = SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st);
274 ok(limits == 0 ||
275 broken(limits == GDTR_MIN), /* comctl32 <= 4.70 */
276 "No limits should be set (%d)\n", limits);
277 if (limits == GDTR_MIN)
279 win_skip("comctl32 <= 4.70 is broken\n");
280 DestroyWindow(hwnd);
281 return;
284 ok(0 == st[0].wYear ||
285 broken(1752 == st[0].wYear), /* comctl32 <= 4.72 */
286 "Expected 0, got %d\n", st[0].wYear);
287 ok(0 == st[0].wMonth ||
288 broken(9 == st[0].wMonth), /* comctl32 <= 4.72 */
289 "Expected 0, got %d\n", st[0].wMonth);
290 ok(0 == st[0].wDay ||
291 broken(14 == st[0].wDay), /* comctl32 <= 4.72 */
292 "Expected 0, got %d\n", st[0].wDay);
293 expect(0, st[0].wDayOfWeek);
294 expect(0, st[0].wHour);
295 expect(0, st[0].wMinute);
296 expect(0, st[0].wSecond);
297 expect(0, st[0].wMilliseconds);
299 expect(0, st[1].wYear);
300 expect(0, st[1].wMonth);
301 expect(0, st[1].wDay);
302 expect(0, st[1].wDayOfWeek);
303 expect(0, st[1].wHour);
304 expect(0, st[1].wMinute);
305 expect(0, st[1].wSecond);
306 expect(0, st[1].wMilliseconds);
308 GetSystemTime(&st[0]);
309 st[1] = st[0];
311 SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&today);
313 /* Invalid date/time */
314 st[0].wYear = 2000;
315 /* Time should not matter */
316 st[1].wHour = st[1].wMinute = st[1].wSecond = 70;
317 st[1].wMilliseconds = 1200;
318 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set MAX limit\n");
319 /* invalid timestamp is written back with today data and msecs untouched */
320 expect(today.wHour, st[1].wHour);
321 expect(today.wMinute, st[1].wMinute);
322 expect(today.wSecond, st[1].wSecond);
323 expect(1200, st[1].wMilliseconds);
325 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "No limits should be set\n");
326 ok(st1[0].wYear != 2000, "Lower limit changed\n");
327 /* invalid timestamp should be replaced with today data, except msecs */
328 expect(today.wHour, st1[1].wHour);
329 expect(today.wMinute, st1[1].wMinute);
330 expect(today.wSecond, st1[1].wSecond);
331 expect(1200, st1[1].wMilliseconds);
333 /* Invalid date/time with invalid milliseconds only */
334 GetSystemTime(&st[0]);
335 st[1] = st[0];
336 /* Time should not matter */
337 st[1].wMilliseconds = 1200;
338 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set MAX limit\n");
339 /* invalid milliseconds field doesn't lead to invalid timestamp */
340 expect(st[0].wHour, st[1].wHour);
341 expect(st[0].wMinute, st[1].wMinute);
342 expect(st[0].wSecond, st[1].wSecond);
343 expect(1200, st[1].wMilliseconds);
345 GetSystemTime(&st[0]);
347 st[1].wMonth = 0;
348 ok(!SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Should have failed to set limits\n");
349 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "No limits should be set\n");
350 ok(st1[0].wYear != 2000, "Lower limit changed\n");
351 ok(!SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Should have failed to set MAX limit\n");
352 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "No limits should be set\n");
353 ok(st1[0].wYear != 2000, "Lower limit changed\n");
355 GetSystemTime(&st[0]);
356 st[0].wDay = 20;
357 st[0].wMonth = 5;
358 st[1] = st[0];
360 month_range = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st1);
361 st[1].wMonth--;
362 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Failed to set both min and max limits\n");
363 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st1);
364 ok(res == month_range, "Invalid month range (%d)\n", res);
365 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == (GDTR_MIN|GDTR_MAX), "Limits should be set\n");
367 st[1].wMonth += 2;
368 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Failed to set both min and max limits\n");
369 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st1);
370 ok(res == month_range, "Invalid month range (%d)\n", res);
372 st[1].wYear --;
373 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Failed to set both min and max limits\n");
374 st[1].wYear += 1;
375 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Failed to set both min and max limits\n");
377 st[1].wMonth -= 3;
378 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
379 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "Only MAX limit should be set\n");
380 st[1].wMonth += 4;
381 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
382 st[1].wYear -= 3;
383 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
384 st[1].wYear += 4;
385 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
386 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "Only MAX limit should be set\n");
388 /* set both limits, then set max < min */
389 GetSystemTime(&st[0]);
390 st[0].wDay = 25;
391 st[1] = st[0];
392 st[1].wYear++;
393 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN|GDTR_MAX, (LPARAM)st), "Failed to set limits\n");
394 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == (GDTR_MIN|GDTR_MAX), "Min limit expected\n");
395 st[1].wYear -= 2;
396 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set limits\n");
397 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "Max limit expected\n");
399 expect(0, st1[0].wYear);
400 expect(0, st1[0].wMonth);
401 expect(0, st1[0].wDay);
402 expect(0, st1[0].wDayOfWeek);
403 expect(0, st1[0].wHour);
404 expect(0, st1[0].wMinute);
405 expect(0, st1[0].wSecond);
406 expect(0, st1[0].wMilliseconds);
408 expect(st[1].wYear, st1[1].wYear);
409 expect(st[1].wMonth, st1[1].wMonth);
410 expect(st[1].wDay, st1[1].wDay);
411 expect(st[1].wDayOfWeek, st1[1].wDayOfWeek);
412 expect(st[1].wHour, st1[1].wHour);
413 expect(st[1].wMinute, st1[1].wMinute);
414 expect(st[1].wSecond, st1[1].wSecond);
415 expect(st[1].wMilliseconds, st1[1].wMilliseconds);
417 st[1] = st[0];
418 st[1].wYear++;
419 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN|GDTR_MAX, (LPARAM)st), "Failed to set limits\n");
420 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == (GDTR_MIN|GDTR_MAX), "Min limit expected\n");
421 st[0].wYear++; /* start == end now */
422 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN, (LPARAM)st), "Failed to set limits\n");
423 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MIN, "Min limit expected\n");
425 expect(st[0].wYear, st1[0].wYear);
426 expect(st[0].wMonth, st1[0].wMonth);
427 expect(st[0].wDay, st1[0].wDay);
428 expect(st[0].wDayOfWeek, st1[0].wDayOfWeek);
429 expect(st[0].wHour, st1[0].wHour);
430 expect(st[0].wMinute, st1[0].wMinute);
431 expect(st[0].wSecond, st1[0].wSecond);
432 expect(st[0].wMilliseconds, st1[0].wMilliseconds);
434 expect(0, st1[1].wYear);
435 expect(0, st1[1].wMonth);
436 expect(0, st1[1].wDay);
437 expect(0, st1[1].wDayOfWeek);
438 expect(0, st1[1].wHour);
439 expect(0, st1[1].wMinute);
440 expect(0, st1[1].wSecond);
441 expect(0, st1[1].wMilliseconds);
443 DestroyWindow(hwnd);
446 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
448 static LONG defwndproc_counter = 0;
449 LRESULT ret;
450 struct message msg;
452 /* log system messages, except for painting */
453 if (message < WM_USER &&
454 message != WM_PAINT &&
455 message != WM_ERASEBKGND &&
456 message != WM_NCPAINT &&
457 message != WM_NCHITTEST &&
458 message != WM_GETTEXT &&
459 message != WM_GETICON &&
460 message != WM_DEVICECHANGE)
462 msg.message = message;
463 msg.flags = sent|wparam|lparam;
464 if (defwndproc_counter) msg.flags |= defwinproc;
465 msg.wParam = wParam;
466 msg.lParam = lParam;
467 add_message(sequences, PARENT_SEQ_INDEX, &msg);
470 if (message == WM_NOTIFY)
472 NMHDR *hdr = (NMHDR*)lParam;
473 switch (hdr->code)
475 case MCN_GETDAYSTATE:
477 NMDAYSTATE *nmstate = (NMDAYSTATE*)lParam;
478 static MONTHDAYSTATE months[14] = { 0 };
480 ok(nmstate->cDayState > 0, "got %d\n", nmstate->cDayState);
481 ok(nmstate->cDayState <= 14, "got %d\n", nmstate->cDayState);
482 ok(nmstate->prgDayState != NULL, "got %p\n", nmstate->prgDayState);
484 nmstate->prgDayState = months;
486 return TRUE;
488 case MCN_SELECT:
489 case MCN_SELCHANGE:
491 NMSELCHANGE *nmchg = (NMSELCHANGE*)lParam;
492 SYSTEMTIME st[2];
493 BOOL is_multisel = GetWindowLongPtr(nmchg->nmhdr.hwndFrom, GWL_STYLE) &
494 MCS_MULTISELECT;
496 if(GetWindowLongPtr(nmchg->nmhdr.hwndFrom, GWLP_ID) != SEL_NOTIFY_TEST_ID)
497 break;
498 SendMessage(nmchg->nmhdr.hwndFrom, is_multisel ? MCM_GETSELRANGE :
499 MCM_GETCURSEL, 0, (LPARAM)st);
501 expect(st[0].wYear, nmchg->stSelStart.wYear);
502 expect(st[0].wMonth, nmchg->stSelStart.wMonth);
503 expect(0, nmchg->stSelStart.wDayOfWeek);
504 expect(st[0].wDay, nmchg->stSelStart.wDay);
506 if(is_multisel)
508 expect(st[1].wYear, nmchg->stSelEnd.wYear);
509 expect(st[1].wMonth, nmchg->stSelEnd.wMonth);
510 expect(0, nmchg->stSelEnd.wDayOfWeek);
511 expect(st[1].wDay, nmchg->stSelEnd.wDay);
513 else
514 ok(!(nmchg->stSelEnd.wYear | nmchg->stSelEnd.wMonth |
515 nmchg->stSelEnd.wDayOfWeek | nmchg->stSelEnd.wDay |
516 nmchg->stSelEnd.wHour | nmchg->stSelEnd.wMinute |
517 nmchg->stSelEnd.wSecond | nmchg->stSelEnd.wMilliseconds),
518 "Non-zero member in stSelEnd\n");
519 return TRUE;
521 default:
522 break;
526 defwndproc_counter++;
527 ret = DefWindowProcA(hwnd, message, wParam, lParam);
528 defwndproc_counter--;
530 return ret;
533 static BOOL register_parent_wnd_class(void)
535 WNDCLASSA cls;
537 cls.style = 0;
538 cls.lpfnWndProc = parent_wnd_proc;
539 cls.cbClsExtra = 0;
540 cls.cbWndExtra = 0;
541 cls.hInstance = GetModuleHandleA(NULL);
542 cls.hIcon = 0;
543 cls.hCursor = LoadCursorA(0, IDC_ARROW);
544 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
545 cls.lpszMenuName = NULL;
546 cls.lpszClassName = "Month-Cal test parent class";
547 return RegisterClassA(&cls);
550 static HWND create_parent_window(void)
552 HWND hwnd;
554 InitCommonControls();
556 /* flush message sequences, so we can check the new sequence by the end of function */
557 flush_sequences(sequences, NUM_MSG_SEQUENCES);
559 if (!register_parent_wnd_class())
560 return NULL;
562 hwnd = CreateWindowEx(0, "Month-Cal test parent class",
563 "Month-Cal test parent window",
564 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
565 WS_MAXIMIZEBOX | WS_VISIBLE,
566 0, 0, 500, 500,
567 GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL);
569 assert(hwnd);
571 /* check for message sequences */
572 ok_sequence(sequences, PARENT_SEQ_INDEX, create_parent_window_seq, "create parent window", FALSE);
574 return hwnd;
577 static LRESULT WINAPI monthcal_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
579 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
580 static LONG defwndproc_counter = 0;
581 LRESULT ret;
582 struct message msg;
584 msg.message = message;
585 msg.flags = sent|wparam|lparam;
586 if (defwndproc_counter) msg.flags |= defwinproc;
587 msg.wParam = wParam;
588 msg.lParam = lParam;
589 msg.id = 0;
590 add_message(sequences, MONTHCAL_SEQ_INDEX, &msg);
592 /* some debug output for style changing */
593 if ((message == WM_STYLECHANGING ||
594 message == WM_STYLECHANGED) && lParam)
596 STYLESTRUCT *style = (STYLESTRUCT*)lParam;
597 trace("\told style: 0x%08x, new style: 0x%08x\n", style->styleOld, style->styleNew);
600 defwndproc_counter++;
601 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
602 defwndproc_counter--;
604 return ret;
607 static HWND create_monthcal_control(DWORD style)
609 WNDPROC oldproc;
610 HWND hwnd;
612 hwnd = CreateWindowEx(0,
613 MONTHCAL_CLASS,
615 WS_CHILD | WS_BORDER | WS_VISIBLE | style,
616 0, 0, 300, 400,
617 parent_wnd, NULL, GetModuleHandleA(NULL), NULL);
619 if (!hwnd) return NULL;
621 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
622 (LONG_PTR)monthcal_subclass_proc);
623 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
625 SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(SYSTEM_FONT), 0);
627 return hwnd;
631 /* Setter and Getters Tests */
633 static void test_color(void)
635 COLORREF color, prev;
636 HWND hwnd;
638 hwnd = create_monthcal_control(0);
640 /* invalid color index */
641 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT + 1, 0);
642 expect(~0u, color);
643 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TRAILINGTEXT + 1, RGB(255,255,255));
644 expect(~0u, prev);
646 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_BACKGROUND, 0);
647 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_BACKGROUND, RGB(0,0,0));
648 expect(color, prev);
649 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_BACKGROUND, 0);
650 expect(RGB(0,0,0), color);
651 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_BACKGROUND, RGB(255,255,255));
652 expect(color, prev);
653 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_BACKGROUND, 0);
654 expect(RGB(255,255,255), color);
656 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_MONTHBK, 0);
657 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_MONTHBK, RGB(0,0,0));
658 expect(color, prev);
659 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_MONTHBK, 0);
660 expect(RGB(0,0,0), color);
661 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_MONTHBK, RGB(255,255,255));
662 expect(color, prev);
663 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_MONTHBK, 0);
664 expect(RGB(255,255,255), color);
666 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TEXT, 0);
667 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TEXT, RGB(0,0,0));
668 expect(color, prev);
669 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TEXT, 0);
670 expect(RGB(0,0,0), color);
671 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TEXT, RGB(255,255,255));
672 expect(color, prev);
673 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TEXT, 0);
674 expect(RGB(255,255,255), color);
676 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLEBK, 0);
677 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLEBK, RGB(0,0,0));
678 expect(color, prev);
679 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLEBK, 0);
680 expect(RGB(0,0,0), color);
681 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLEBK, RGB(255,255,255));
682 expect(color, prev);
683 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLEBK, 0);
684 expect(RGB(255,255,255), color);
686 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLETEXT, 0);
687 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLETEXT, RGB(0,0,0));
688 expect(color, prev);
689 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLETEXT, 0);
690 expect(RGB(0,0,0), color);
691 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLETEXT, RGB(255,255,255));
692 expect(color, prev);
693 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLETEXT, 0);
694 expect(RGB(255,255,255), color);
696 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT, 0);
697 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TRAILINGTEXT, RGB(0,0,0));
698 expect(color, prev);
699 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT, 0);
700 expect(RGB(0,0,0), color);
701 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TRAILINGTEXT, RGB(255,255,255));
702 expect(color, prev);
703 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT, 0);
704 expect(RGB(255,255,255), color);
706 DestroyWindow(hwnd);
709 static void test_currdate(void)
711 SYSTEMTIME st_original, st_new, st_test;
712 int res;
713 HWND hwnd;
715 hwnd = create_monthcal_control(0);
717 flush_sequences(sequences, NUM_MSG_SEQUENCES);
719 /* Setter and Getters for current date selected */
720 st_original.wYear = 2000;
721 st_original.wMonth = 11;
722 st_original.wDay = 28;
723 st_original.wHour = 11;
724 st_original.wMinute = 59;
725 st_original.wSecond = 30;
726 st_original.wMilliseconds = 0;
727 st_original.wDayOfWeek = 0;
729 st_new = st_test = st_original;
731 /* Should not validate the time */
732 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
733 expect(1,res);
735 /* Overflow matters, check for wDay */
736 st_test.wDay += 4;
737 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
738 expect(0,res);
740 /* correct wDay before checking for wMonth */
741 st_test.wDay -= 4;
742 expect(st_original.wDay, st_test.wDay);
744 /* Overflow matters, check for wMonth */
745 st_test.wMonth += 4;
746 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
747 expect(0,res);
749 /* checking if gets the information right, modify st_new */
750 st_new.wYear += 4;
751 st_new.wMonth += 4;
752 st_new.wDay += 4;
753 st_new.wHour += 4;
754 st_new.wMinute += 4;
755 st_new.wSecond += 4;
757 res = SendMessage(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_new);
758 expect(1, res);
760 /* st_new change to st_origin, above settings with overflow */
761 /* should not change the current settings */
762 expect(st_original.wYear, st_new.wYear);
763 expect(st_original.wMonth, st_new.wMonth);
764 expect(st_original.wDay, st_new.wDay);
765 ok(st_original.wHour == st_new.wHour ||
766 broken(0 == st_new.wHour), /* comctl32 <= 4.70 */
767 "Expected %d, got %d\n", st_original.wHour, st_new.wHour);
768 ok(st_original.wMinute == st_new.wMinute ||
769 broken(0 == st_new.wMinute), /* comctl32 <= 4.70 */
770 "Expected %d, got %d\n", st_original.wMinute, st_new.wMinute);
771 ok(st_original.wSecond == st_new.wSecond ||
772 broken(0 == st_new.wSecond), /* comctl32 <= 4.70 */
773 "Expected %d, got %d\n", st_original.wSecond, st_new.wSecond);
775 /* lparam cannot be NULL */
776 res = SendMessage(hwnd, MCM_GETCURSEL, 0, 0);
777 expect(0, res);
779 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_curr_date_seq, "monthcal currDate", TRUE);
781 /* December, 31, 9999 is the maximum allowed date */
782 memset(&st_new, 0, sizeof(st_new));
783 st_new.wYear = 9999;
784 st_new.wMonth = 12;
785 st_new.wDay = 31;
786 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_new);
787 expect(1, res);
788 memset(&st_test, 0, sizeof(st_test));
789 res = SendMessage(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_test);
790 expect(1, res);
791 expect(st_new.wYear, st_test.wYear);
792 expect(st_new.wMonth, st_test.wMonth);
793 expect(st_new.wDay, st_test.wDay);
794 expect(st_new.wHour, st_test.wHour);
795 expect(st_new.wMinute, st_test.wMinute);
796 expect(st_new.wSecond, st_test.wSecond);
797 /* try one day later */
798 st_original = st_new;
799 st_new.wYear = 10000;
800 st_new.wMonth = 1;
801 st_new.wDay = 1;
802 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_new);
803 ok(0 == res ||
804 broken(1 == res), /* comctl32 <= 4.72 */
805 "Expected 0, got %d\n", res);
806 if (0 == res)
808 memset(&st_test, 0, sizeof(st_test));
809 res = SendMessage(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_test);
810 expect(1, res);
811 expect(st_original.wYear, st_test.wYear);
812 expect(st_original.wMonth, st_test.wMonth);
813 expect(st_original.wDay, st_test.wDay);
814 expect(st_original.wHour, st_test.wHour);
815 expect(st_original.wMinute, st_test.wMinute);
816 expect(st_original.wSecond, st_test.wSecond);
819 /* setting selection equal to current reports success even if out range */
820 memset(&st_new, 0, sizeof(st_new));
821 st_new.wYear = 2009;
822 st_new.wDay = 5;
823 st_new.wMonth = 10;
824 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_new);
825 expect(1, res);
826 memset(&st_test, 0, sizeof(st_test));
827 st_test.wYear = 2009;
828 st_test.wDay = 6;
829 st_test.wMonth = 10;
830 res = SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN, (LPARAM)&st_test);
831 expect(1, res);
832 /* set to current again */
833 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_new);
834 expect(1, res);
836 /* set with invalid day of week */
837 memset(&st_test, 0, sizeof(st_test));
838 st_test.wYear = 2009;
839 st_test.wDay = 7;
840 st_test.wMonth = 10;
841 st_test.wDayOfWeek = 100;
842 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
843 expect(1, res);
845 memset(&st_test, 0, sizeof(st_test));
846 res = SendMessage(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_test);
847 expect(1, res);
848 expect(2009, st_test.wYear);
849 expect(7, st_test.wDay);
850 expect(10, st_test.wMonth);
851 expect(3, st_test.wDayOfWeek);
853 DestroyWindow(hwnd);
856 static void test_firstDay(void)
858 int res, fday, i, prev;
859 CHAR b[128], caltype[3];
860 LCID lcid = LOCALE_USER_DEFAULT;
861 HWND hwnd;
862 LRESULT ret;
864 SetLastError(0xdeadbeef);
865 ret = GetLocaleInfoA(lcid, LOCALE_ICALENDARTYPE, caltype, 3);
866 if (ret == 0) {
867 skip("Must know local calendar type (%x)\n", GetLastError());
868 return;
869 } else if (atoi(caltype) != CAL_GREGORIAN) {
870 skip("MonthCalendar Control only supports Gregorian calendar (type: %s)\n", caltype);
871 return;
874 hwnd = create_monthcal_control(0);
876 flush_sequences(sequences, NUM_MSG_SEQUENCES);
878 /* Setter and Getters for first day of week */
879 /* check for locale first day */
880 if(GetLocaleInfoA(lcid, LOCALE_IFIRSTDAYOFWEEK, b, 128)){
881 fday = atoi(b);
882 res = SendMessage(hwnd, MCM_GETFIRSTDAYOFWEEK, 0, 0);
883 expect(fday, res);
884 prev = fday;
886 /* checking for the values that actually will be stored as */
887 /* current first day when we set a new value */
888 for (i = -5; i < 12; i++){
889 res = SendMessage(hwnd, MCM_SETFIRSTDAYOFWEEK, 0, i);
890 expect(prev, res);
891 res = SendMessage(hwnd, MCM_GETFIRSTDAYOFWEEK, 0, 0);
892 prev = res;
894 if (i == -1){
895 expect(MAKELONG(fday, FALSE), res);
896 }else if (i >= 7){
897 /* out of range sets max first day of week, locale is ignored */
898 expect(MAKELONG(6, TRUE), res);
899 }else{
900 expect(MAKELONG(i, TRUE), res);
904 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_first_day_seq, "monthcal firstDay", FALSE);
906 }else{
907 skip("Cannot retrieve first day of the week\n");
910 DestroyWindow(hwnd);
913 static void test_unicode(void)
915 int res, temp;
916 HWND hwnd;
918 hwnd = create_monthcal_control(0);
920 flush_sequences(sequences, NUM_MSG_SEQUENCES);
922 /* Setter and Getters for Unicode format */
924 /* getting the current settings */
925 temp = SendMessage(hwnd, MCM_GETUNICODEFORMAT, 0, 0);
927 /* setting to 1, should return previous settings */
928 res = SendMessage(hwnd, MCM_SETUNICODEFORMAT, 1, 0);
929 expect(temp, res);
931 /* current setting is 1, so, should return 1 */
932 res = SendMessage(hwnd, MCM_GETUNICODEFORMAT, 0, 0);
933 ok(1 == res ||
934 broken(0 == res), /* comctl32 <= 4.70 */
935 "Expected 1, got %d\n", res);
937 /* setting to 0, should return previous settings */
938 res = SendMessage(hwnd, MCM_SETUNICODEFORMAT, 0, 0);
939 ok(1 == res ||
940 broken(0 == res), /* comctl32 <= 4.70 */
941 "Expected 1, got %d\n", res);
943 /* current setting is 0, so, it should return 0 */
944 res = SendMessage(hwnd, MCM_GETUNICODEFORMAT, 0, 0);
945 expect(0, res);
947 /* should return previous settings */
948 res = SendMessage(hwnd, MCM_SETUNICODEFORMAT, 1, 0);
949 expect(0, res);
951 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_unicode_seq, "monthcal unicode", FALSE);
953 DestroyWindow(hwnd);
956 static void test_hittest(void)
958 typedef struct hittest_test
960 UINT ht;
961 int todo;
962 } hittest_test_t;
964 static const hittest_test_t title_hits[] = {
965 /* Start is the same everywhere */
966 { MCHT_TITLE, 0 },
967 { MCHT_TITLEBTNPREV, 0 },
968 /* The middle piece is only tested for presence of items */
969 /* End is the same everywhere */
970 { MCHT_TITLEBTNNEXT, 0 },
971 { MCHT_TITLE, 0 },
972 { MCHT_NOWHERE, 1 }
975 MCHITTESTINFO mchit;
976 UINT res, old_res;
977 SYSTEMTIME st;
978 LONG x;
979 UINT title_index;
980 HWND hwnd;
981 RECT r;
982 char yearmonth[80], *locale_month, *locale_year;
983 int month_count, year_count;
984 BOOL in_the_middle;
986 memset(&mchit, 0, sizeof(MCHITTESTINFO));
988 hwnd = create_monthcal_control(0);
990 /* test with invalid structure size */
991 mchit.cbSize = MCHITTESTINFO_V1_SIZE - 1;
992 mchit.pt.x = 0;
993 mchit.pt.y = 0;
994 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
995 expect(0, mchit.pt.x);
996 expect(0, mchit.pt.y);
997 expect(~0u, res);
998 expect(0, mchit.uHit);
999 /* test with invalid pointer */
1000 res = SendMessage(hwnd, MCM_HITTEST, 0, 0);
1001 expect(~0u, res);
1003 /* resize control to display single Calendar */
1004 res = SendMessage(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r);
1005 if (res == 0)
1007 win_skip("Message MCM_GETMINREQRECT unsupported. Skipping.\n");
1008 DestroyWindow(hwnd);
1009 return;
1011 MoveWindow(hwnd, 0, 0, r.right, r.bottom, FALSE);
1013 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1015 st.wYear = 2007;
1016 st.wMonth = 4;
1017 st.wDay = 11;
1018 st.wHour = 1;
1019 st.wMinute = 0;
1020 st.wSecond = 0;
1021 st.wMilliseconds = 0;
1022 st.wDayOfWeek = 0;
1024 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st);
1025 expect(1,res);
1027 /* (0, 0) is the top left of the control - title */
1028 mchit.cbSize = MCHITTESTINFO_V1_SIZE;
1029 mchit.pt.x = 0;
1030 mchit.pt.y = 0;
1031 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1032 expect(0, mchit.pt.x);
1033 expect(0, mchit.pt.y);
1034 expect(mchit.uHit, res);
1035 expect_hex(MCHT_TITLE, res);
1037 /* bottom right of the control and should not be active */
1038 mchit.pt.x = r.right;
1039 mchit.pt.y = r.bottom;
1040 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1041 expect(r.right, mchit.pt.x);
1042 expect(r.bottom, mchit.pt.y);
1043 expect(mchit.uHit, res);
1044 todo_wine expect_hex(MCHT_NOWHERE, res);
1046 /* completely out of the control, should not be active */
1047 mchit.pt.x = 2 * r.right;
1048 mchit.pt.y = 2 * r.bottom;
1049 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1050 expect(2 * r.right, mchit.pt.x);
1051 expect(2 * r.bottom, mchit.pt.y);
1052 expect(mchit.uHit, res);
1053 todo_wine expect_hex(MCHT_NOWHERE, res);
1055 /* in active area - day of the week */
1056 mchit.pt.x = r.right / 2;
1057 mchit.pt.y = r.bottom / 2;
1058 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1059 expect(r.right / 2, mchit.pt.x);
1060 expect(r.bottom / 2, mchit.pt.y);
1061 expect(mchit.uHit, res);
1062 expect_hex(MCHT_CALENDARDATE, res);
1064 /* in active area - day of the week #2 */
1065 mchit.pt.x = r.right / 14; /* half of first day rect */
1066 mchit.pt.y = r.bottom / 2;
1067 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1068 expect(r.right / 14, mchit.pt.x);
1069 expect(r.bottom / 2, mchit.pt.y);
1070 expect(mchit.uHit, res);
1071 expect_hex(MCHT_CALENDARDATE, res);
1073 /* in active area - date from prev month */
1074 mchit.pt.x = r.right / 14; /* half of first day rect */
1075 mchit.pt.y = 6 * r.bottom / 19;
1076 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1077 expect(r.right / 14, mchit.pt.x);
1078 expect(6 * r.bottom / 19, mchit.pt.y);
1079 expect(mchit.uHit, res);
1080 expect_hex(MCHT_CALENDARDATEPREV, res);
1082 #if 0
1083 /* (125, 115) is in active area - date from this month */
1084 mchit.pt.x = 125;
1085 mchit.pt.y = 115;
1086 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1087 expect(125, mchit.pt.x);
1088 expect(115, mchit.pt.y);
1089 expect(mchit.uHit, res);
1090 expect(MCHT_CALENDARDATE, res);
1091 #endif
1093 /* in active area - date from next month */
1094 mchit.pt.x = 11 * r.right / 14;
1095 mchit.pt.y = 16 * r.bottom / 19;
1096 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1097 expect(11 * r.right / 14, mchit.pt.x);
1098 expect(16 * r.bottom / 19, mchit.pt.y);
1099 expect(mchit.uHit, res);
1100 expect_hex(MCHT_CALENDARDATENEXT, res);
1102 /* in active area - today link */
1103 mchit.pt.x = r.right / 14;
1104 mchit.pt.y = 18 * r.bottom / 19;
1105 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1106 expect(r.right / 14, mchit.pt.x);
1107 expect(18 * r.bottom / 19, mchit.pt.y);
1108 expect(mchit.uHit, res);
1109 expect_hex(MCHT_TODAYLINK, res);
1111 /* in active area - today link */
1112 mchit.pt.x = r.right / 2;
1113 mchit.pt.y = 18 * r.bottom / 19;
1114 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1115 expect(r.right / 2, mchit.pt.x);
1116 expect(18 * r.bottom / 19, mchit.pt.y);
1117 expect(mchit.uHit, res);
1118 expect_hex(MCHT_TODAYLINK, res);
1120 /* in active area - today link */
1121 mchit.pt.x = r.right / 10;
1122 mchit.pt.y = 18 * r.bottom / 19;
1123 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1124 expect(r.right / 10, mchit.pt.x);
1125 expect(18 * r.bottom / 19, mchit.pt.y);
1126 expect(mchit.uHit, res);
1127 expect_hex(MCHT_TODAYLINK, res);
1129 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_hit_test_seq, "monthcal hit test", TRUE);
1131 /* The horizontal position of title bar elements depends on locale (y pos
1132 is constant), so we sample across a horizontal line and make sure we
1133 find all elements. */
1135 /* Get the format of the title */
1136 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SYEARMONTH, yearmonth, 80);
1137 /* Find out if we have a month and/or year */
1138 locale_year = strstr(yearmonth, "y");
1139 locale_month = strstr(yearmonth, "M");
1141 mchit.pt.x = 0;
1142 mchit.pt.y = (5/2) * r.bottom / 19;
1143 title_index = 0;
1144 old_res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1145 expect_hex(title_hits[title_index].ht, old_res);
1147 in_the_middle = FALSE;
1148 month_count = year_count = 0;
1149 for (x = 0; x < r.right; x++){
1150 mchit.pt.x = x;
1151 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1152 expect(x, mchit.pt.x);
1153 expect((5/2) * r.bottom / 19, mchit.pt.y);
1154 expect(mchit.uHit, res);
1155 if (res != old_res) {
1157 if (old_res == MCHT_TITLEBTNPREV)
1158 in_the_middle = TRUE;
1160 if (res == MCHT_TITLEBTNNEXT)
1161 in_the_middle = FALSE;
1163 if (in_the_middle) {
1164 if (res == MCHT_TITLEMONTH)
1165 month_count++;
1166 else if (res == MCHT_TITLEYEAR)
1167 year_count++;
1168 } else {
1169 title_index++;
1171 if (sizeof(title_hits) / sizeof(title_hits[0]) <= title_index)
1172 break;
1174 if (title_hits[title_index].todo) {
1175 todo_wine
1176 ok(title_hits[title_index].ht == res, "Expected %x, got %x, pos %d\n",
1177 title_hits[title_index].ht, res, x);
1178 } else {
1179 ok(title_hits[title_index].ht == res, "Expected %x, got %x, pos %d\n",
1180 title_hits[title_index].ht, res, x);
1183 old_res = res;
1187 /* There are some limits, even if LOCALE_SYEARMONTH contains rubbish
1188 * or no month/year indicators at all */
1189 if (locale_month)
1190 todo_wine ok(month_count == 1, "Expected 1 month item, got %d\n", month_count);
1191 else
1192 ok(month_count <= 1, "Too many month items: %d\n", month_count);
1194 if (locale_year)
1195 todo_wine ok(year_count == 1, "Expected 1 year item, got %d\n", year_count);
1196 else
1197 ok(year_count <= 1, "Too many year items: %d\n", year_count);
1199 todo_wine ok(month_count + year_count >= 1, "Not enough month and year items\n");
1201 ok(r.right <= x && title_index + 1 == sizeof(title_hits) / sizeof(title_hits[0]),
1202 "Wrong title layout\n");
1204 DestroyWindow(hwnd);
1207 static void test_todaylink(void)
1209 MCHITTESTINFO mchit;
1210 SYSTEMTIME st_test, st_new;
1211 UINT res;
1212 HWND hwnd;
1213 RECT r;
1215 memset(&mchit, 0, sizeof(MCHITTESTINFO));
1217 hwnd = create_monthcal_control(0);
1219 res = SendMessage(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r);
1220 expect(1, res);
1221 MoveWindow(hwnd, 0, 0, r.right, r.bottom, FALSE);
1223 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1225 /* hit active area - today link */
1226 mchit.cbSize = MCHITTESTINFO_V1_SIZE;
1227 mchit.pt.x = r.right / 14;
1228 mchit.pt.y = 18 * r.bottom / 19;
1229 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1230 expect(r.right / 14, mchit.pt.x);
1231 expect(18 * r.bottom / 19, mchit.pt.y);
1232 expect(mchit.uHit, res);
1233 expect(MCHT_TODAYLINK, res);
1235 st_test.wDay = 1;
1236 st_test.wMonth = 1;
1237 st_test.wYear = 2005;
1239 res = SendMessage(hwnd, MCM_SETTODAY, 0, (LPARAM)&st_test);
1240 expect(0, res);
1242 memset(&st_new, 0, sizeof(st_new));
1243 res = SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&st_new);
1244 expect(1, res);
1245 expect(1, st_new.wDay);
1246 expect(1, st_new.wMonth);
1247 expect(2005, st_new.wYear);
1249 res = SendMessage(hwnd, WM_LBUTTONDOWN, MK_LBUTTON, MAKELONG(mchit.pt.x, mchit.pt.y));
1250 expect(0, res);
1252 memset(&st_new, 0, sizeof(st_new));
1253 res = SendMessage(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_new);
1254 expect(1, res);
1255 expect(1, st_new.wDay);
1256 expect(1, st_new.wMonth);
1257 expect(2005, st_new.wYear);
1259 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_todaylink_seq, "monthcal hit test", TRUE);
1261 DestroyWindow(hwnd);
1264 static void test_today(void)
1266 SYSTEMTIME st_test, st_new;
1267 int res;
1268 HWND hwnd;
1270 hwnd = create_monthcal_control(0);
1272 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1274 /* Setter and Getters for "today" information */
1276 /* check for overflow, should be ok */
1277 memset(&st_test, 0, sizeof(st_test));
1278 st_test.wDay = 38;
1279 st_test.wMonth = 38;
1281 st_new.wDay = 27;
1282 st_new.wMonth = 27;
1284 res = SendMessage(hwnd, MCM_SETTODAY, 0, (LPARAM)&st_test);
1285 expect(0, res);
1287 res = SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&st_new);
1288 expect(1, res);
1290 /* st_test should not change */
1291 expect(38, st_test.wDay);
1292 expect(38, st_test.wMonth);
1294 /* st_new should change, overflow does not matter */
1295 expect(38, st_new.wDay);
1296 expect(38, st_new.wMonth);
1298 /* check for zero, should be ok*/
1299 st_test.wDay = 0;
1300 st_test.wMonth = 0;
1302 res = SendMessage(hwnd, MCM_SETTODAY, 0, (LPARAM)&st_test);
1303 expect(0, res);
1305 res = SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&st_new);
1306 expect(1, res);
1308 /* st_test should not change */
1309 expect(0, st_test.wDay);
1310 expect(0, st_test.wMonth);
1312 /* st_new should change to zero*/
1313 expect(0, st_new.wDay);
1314 expect(0, st_new.wMonth);
1316 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_today_seq, "monthcal today", TRUE);
1318 DestroyWindow(hwnd);
1321 static void test_scroll(void)
1323 int res;
1324 HWND hwnd;
1326 hwnd = create_monthcal_control(0);
1328 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1330 /* Setter and Getters for scroll rate */
1331 res = SendMessage(hwnd, MCM_SETMONTHDELTA, 2, 0);
1332 expect(0, res);
1334 res = SendMessage(hwnd, MCM_SETMONTHDELTA, 3, 0);
1335 expect(2, res);
1336 res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
1337 expect(3, res);
1339 res = SendMessage(hwnd, MCM_SETMONTHDELTA, 12, 0);
1340 expect(3, res);
1341 res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
1342 expect(12, res);
1344 res = SendMessage(hwnd, MCM_SETMONTHDELTA, 15, 0);
1345 expect(12, res);
1346 res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
1347 expect(15, res);
1349 res = SendMessage(hwnd, MCM_SETMONTHDELTA, -5, 0);
1350 expect(15, res);
1351 res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
1352 expect(-5, res);
1354 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_scroll_seq, "monthcal scroll", FALSE);
1356 DestroyWindow(hwnd);
1359 static void test_monthrange(void)
1361 int res;
1362 SYSTEMTIME st_visible[2], st_daystate[2], st;
1363 HWND hwnd;
1364 RECT r;
1366 hwnd = create_monthcal_control(0);
1368 memset(&st_visible, 0, sizeof(st_visible));
1369 memset(&st_daystate, 0, sizeof(st_daystate));
1371 st.wYear = 2000;
1372 st.wMonth = 11;
1373 st.wDay = 28;
1374 st.wHour = 11;
1375 st.wMinute = 59;
1376 st.wSecond = 30;
1377 st.wMilliseconds = 0;
1378 st.wDayOfWeek = 0;
1380 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st);
1381 expect(1,res);
1383 /* to be locale independent */
1384 SendMessage(hwnd, MCM_SETFIRSTDAYOFWEEK, 0, (LPARAM)6);
1386 res = SendMessage(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r);
1387 expect(TRUE, res);
1388 /* resize control to display two Calendars */
1389 MoveWindow(hwnd, 0, 0, r.right, (5/2)*r.bottom, FALSE);
1391 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1393 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st_visible);
1394 expect(2, res);
1395 expect(2000, st_visible[0].wYear);
1396 expect(11, st_visible[0].wMonth);
1397 expect(1, st_visible[0].wDay);
1398 expect(2000, st_visible[1].wYear);
1399 expect(12, st_visible[1].wMonth);
1400 expect(31, st_visible[1].wDay);
1402 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_DAYSTATE, (LPARAM)st_daystate);
1403 expect(4, res);
1404 expect(2000, st_daystate[0].wYear);
1405 expect(10, st_daystate[0].wMonth);
1406 expect(29, st_daystate[0].wDay);
1407 expect(2001, st_daystate[1].wYear);
1408 expect(1, st_daystate[1].wMonth);
1409 expect(6, st_daystate[1].wDay);
1411 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_monthrange_seq, "monthcal monthrange", FALSE);
1413 /* with null date array parameter */
1414 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, 0);
1415 expect(2, res);
1417 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_DAYSTATE, 0);
1418 expect(4, res);
1420 /* resize control to display single Calendar */
1421 MoveWindow(hwnd, 0, 0, r.right, r.bottom, FALSE);
1423 memset(&st, 0, sizeof(st));
1424 st.wMonth = 9;
1425 st.wYear = 1752;
1426 st.wDay = 14;
1428 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st);
1429 expect(1, res);
1431 /* September 1752 has 19 days */
1432 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st_visible);
1433 expect(1, res);
1435 expect(1752, st_visible[0].wYear);
1436 expect(9, st_visible[0].wMonth);
1437 ok(14 == st_visible[0].wDay ||
1438 broken(1 == st_visible[0].wDay), /* comctl32 <= 4.72 */
1439 "Expected 14, got %d\n", st_visible[0].wDay);
1441 expect(1752, st_visible[1].wYear);
1442 expect(9, st_visible[1].wMonth);
1443 expect(19, st_visible[1].wDay);
1445 DestroyWindow(hwnd);
1448 static void test_maxselday(void)
1450 int res;
1451 HWND hwnd;
1452 DWORD style;
1454 hwnd = create_monthcal_control(0);
1455 /* if no style specified default to 1 */
1456 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1457 expect(1, res);
1458 res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, 5, 0);
1459 expect(0, res);
1460 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1461 expect(1, res);
1463 /* try to set style */
1464 style = GetWindowLong(hwnd, GWL_STYLE);
1465 SetWindowLong(hwnd, GWL_STYLE, style | MCS_MULTISELECT);
1466 style = GetWindowLong(hwnd, GWL_STYLE);
1467 ok(!(style & MCS_MULTISELECT), "Expected MCS_MULTISELECT not to be set\n");
1468 DestroyWindow(hwnd);
1470 hwnd = create_monthcal_control(MCS_MULTISELECT);
1471 /* try to remove style */
1472 style = GetWindowLong(hwnd, GWL_STYLE);
1473 SetWindowLong(hwnd, GWL_STYLE, style & ~MCS_MULTISELECT);
1474 style = GetWindowLong(hwnd, GWL_STYLE);
1475 ok(style & MCS_MULTISELECT, "Expected MCS_MULTISELECT to be set\n");
1476 DestroyWindow(hwnd);
1478 hwnd = create_monthcal_control(MCS_MULTISELECT);
1480 /* default width is a week */
1481 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1482 expect(7, res);
1484 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1486 /* Setter and Getters for max selected days */
1487 res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, 5, 0);
1488 expect(1, res);
1489 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1490 expect(5, res);
1492 res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, 15, 0);
1493 expect(1, res);
1494 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1495 expect(15, res);
1497 /* test invalid value */
1498 res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, -1, 0);
1499 expect(0, res);
1500 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1501 expect(15, res);
1503 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_max_sel_day_seq, "monthcal MaxSelDay", FALSE);
1505 /* zero value is invalid too */
1506 res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, 0, 0);
1507 expect(0, res);
1508 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1509 expect(15, res);
1511 DestroyWindow(hwnd);
1514 static void test_size(void)
1516 int res;
1517 RECT r1, r2;
1518 HFONT hFont1, hFont2;
1519 LOGFONTA logfont;
1520 HWND hwnd;
1522 hwnd = create_monthcal_control(0);
1524 lstrcpyA(logfont.lfFaceName, "Arial");
1525 memset(&logfont, 0, sizeof(logfont));
1526 logfont.lfHeight = 12;
1527 hFont1 = CreateFontIndirectA(&logfont);
1529 logfont.lfHeight = 24;
1530 hFont2 = CreateFontIndirectA(&logfont);
1532 /* initialize to a font we can compare against */
1533 SendMessage(hwnd, WM_SETFONT, (WPARAM)hFont1, 0);
1534 res = SendMessage(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r1);
1535 ok(res, "SendMessage(MCM_GETMINREQRECT) failed\n");
1537 /* check that setting a larger font results in an larger rect */
1538 SendMessage(hwnd, WM_SETFONT, (WPARAM)hFont2, 0);
1539 res = SendMessage(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r2);
1540 ok(res, "SendMessage(MCM_GETMINREQRECT) failed\n");
1542 OffsetRect(&r1, -r1.left, -r1.top);
1543 OffsetRect(&r2, -r2.left, -r2.top);
1545 ok(r1.bottom < r2.bottom, "Failed to get larger rect with larger font\n");
1547 DestroyWindow(hwnd);
1550 static void test_create(void)
1552 HWND hwnd;
1554 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1556 hwnd = create_monthcal_control(0);
1557 ok_sequence(sequences, PARENT_SEQ_INDEX, create_monthcal_control_seq, "create monthcal control", TRUE);
1559 DestroyWindow(hwnd);
1561 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1562 hwnd = create_monthcal_control(MCS_MULTISELECT);
1563 ok_sequence(sequences, PARENT_SEQ_INDEX, create_monthcal_multi_sel_style_seq, "create monthcal (multi sel style)", TRUE);
1564 DestroyWindow(hwnd);
1567 static void test_destroy(void)
1569 HWND hwnd;
1571 hwnd = create_monthcal_control(0);
1572 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1573 DestroyWindow(hwnd);
1574 ok_sequence(sequences, PARENT_SEQ_INDEX, destroy_monthcal_parent_msgs_seq, "Destroy monthcal (parent msg)", FALSE);
1575 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, destroy_monthcal_child_msgs_seq, "Destroy monthcal (child msg)", FALSE);
1577 /* MCS_MULTISELECT */
1578 hwnd = create_monthcal_control(MCS_MULTISELECT);
1579 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1580 DestroyWindow(hwnd);
1581 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, destroy_monthcal_multi_sel_style_seq, "Destroy monthcal (multi sel style)", FALSE);
1584 static void test_selrange(void)
1586 HWND hwnd;
1587 SYSTEMTIME st, range[2], range2[2];
1588 BOOL ret, old_comctl32 = FALSE;
1590 hwnd = create_monthcal_control(MCS_MULTISELECT);
1592 /* just after creation selection should start and end today */
1593 ret = SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&st);
1594 expect(TRUE, ret);
1596 memset(range, 0xcc, sizeof(range));
1597 ret = SendMessage(hwnd, MCM_GETSELRANGE, 0, (LPARAM)range);
1598 expect(TRUE, ret);
1599 expect(st.wYear, range[0].wYear);
1600 expect(st.wMonth, range[0].wMonth);
1601 expect(st.wDay, range[0].wDay);
1602 if (range[0].wDayOfWeek != st.wDayOfWeek)
1604 win_skip("comctl32 <= 4.70 doesn't set some values\n");
1605 old_comctl32 = TRUE;
1607 else
1609 expect(st.wDayOfWeek, range[0].wDayOfWeek);
1610 expect(st.wHour, range[0].wHour);
1611 expect(st.wMinute, range[0].wMinute);
1612 expect(st.wSecond, range[0].wSecond);
1613 expect(st.wMilliseconds, range[0].wMilliseconds);
1616 expect(st.wYear, range[1].wYear);
1617 expect(st.wMonth, range[1].wMonth);
1618 expect(st.wDay, range[1].wDay);
1619 if (!old_comctl32)
1621 expect(st.wDayOfWeek, range[1].wDayOfWeek);
1622 expect(st.wHour, range[1].wHour);
1623 expect(st.wMinute, range[1].wMinute);
1624 expect(st.wSecond, range[1].wSecond);
1625 expect(st.wMilliseconds, range[1].wMilliseconds);
1628 /* bounds are swapped if min > max */
1629 memset(&range[0], 0, sizeof(range[0]));
1630 range[0].wYear = 2009;
1631 range[0].wMonth = 10;
1632 range[0].wDay = 5;
1633 range[1] = range[0];
1634 range[1].wDay = 3;
1636 ret = SendMessage(hwnd, MCM_SETSELRANGE, 0, (LPARAM)range);
1637 expect(TRUE, ret);
1639 ret = SendMessage(hwnd, MCM_GETSELRANGE, 0, (LPARAM)range2);
1640 expect(TRUE, ret);
1642 expect(range[1].wYear, range2[0].wYear);
1643 expect(range[1].wMonth, range2[0].wMonth);
1644 expect(range[1].wDay, range2[0].wDay);
1645 expect(6, range2[0].wDayOfWeek);
1646 expect(range[1].wHour, range2[0].wHour);
1647 expect(range[1].wMinute, range2[0].wMinute);
1648 expect(range[1].wSecond, range2[0].wSecond);
1649 expect(range[1].wMilliseconds, range2[0].wMilliseconds);
1651 expect(range[0].wYear, range2[1].wYear);
1652 expect(range[0].wMonth, range2[1].wMonth);
1653 expect(range[0].wDay, range2[1].wDay);
1654 expect(1, range2[1].wDayOfWeek);
1655 expect(range[0].wHour, range2[1].wHour);
1656 expect(range[0].wMinute, range2[1].wMinute);
1657 expect(range[0].wSecond, range2[1].wSecond);
1658 expect(range[0].wMilliseconds, range2[1].wMilliseconds);
1660 /* try with range larger than maximum configured */
1661 memset(&range[0], 0, sizeof(range[0]));
1662 range[0].wYear = 2009;
1663 range[0].wMonth = 10;
1664 range[0].wDay = 1;
1665 range[1] = range[0];
1667 ret = SendMessage(hwnd, MCM_SETSELRANGE, 0, (LPARAM)range);
1668 expect(TRUE, ret);
1670 range[1] = range[0];
1671 /* default max. range is 7 days */
1672 range[1].wDay = 8;
1674 ret = SendMessage(hwnd, MCM_SETSELRANGE, 0, (LPARAM)range);
1675 expect(FALSE, ret);
1677 ret = SendMessage(hwnd, MCM_GETSELRANGE, 0, (LPARAM)range2);
1678 expect(TRUE, ret);
1680 expect(range[0].wYear, range2[0].wYear);
1681 expect(range[0].wMonth, range2[0].wMonth);
1682 expect(range[0].wDay, range2[0].wDay);
1683 expect(range[0].wYear, range2[1].wYear);
1684 expect(range[0].wMonth, range2[1].wMonth);
1685 expect(range[0].wDay, range2[1].wDay);
1687 DestroyWindow(hwnd);
1690 static void test_killfocus(void)
1692 HWND hwnd;
1693 DWORD style;
1695 hwnd = create_monthcal_control(0);
1697 /* make parent invisible */
1698 style = GetWindowLong(parent_wnd, GWL_STYLE);
1699 SetWindowLong(parent_wnd, GWL_STYLE, style &~ WS_VISIBLE);
1701 SendMessage(hwnd, WM_KILLFOCUS, (WPARAM)GetDesktopWindow(), 0);
1703 style = GetWindowLong(hwnd, GWL_STYLE);
1704 ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
1706 style = GetWindowLong(parent_wnd, GWL_STYLE);
1707 SetWindowLong(parent_wnd, GWL_STYLE, style | WS_VISIBLE);
1709 DestroyWindow(hwnd);
1712 static void test_hittest_v6(void)
1714 MCHITTESTINFO mchit;
1715 DWORD ret;
1716 HWND hwnd;
1717 RECT r;
1719 hwnd = create_monthcal_control(0);
1720 SendMessage(hwnd, MCM_SETCALENDARBORDER, TRUE, 0);
1722 SendMessage(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r);
1723 /* reserving some area around calendar */
1724 MoveWindow(hwnd, 0, 0, r.right * 3 / 2, r.bottom * 3 / 2, FALSE);
1725 mchit.cbSize = sizeof(MCHITTESTINFO);
1726 mchit.pt.x = mchit.pt.y = 0;
1727 mchit.iOffset = -1;
1728 mchit.iRow = -1;
1729 mchit.iCol = -1;
1730 ret = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1731 if (ret == ~0u)
1733 win_skip("Only MCHITTESTINFO_V1 supported\n");
1734 DestroyWindow(hwnd);
1735 return;
1737 todo_wine expect_hex(MCHT_NOWHERE, ret);
1738 expect(-1, mchit.iOffset);
1739 expect(-1, mchit.iRow);
1740 expect(-1, mchit.iCol);
1742 MoveWindow(hwnd, 0, 0, r.right, r.bottom, FALSE);
1743 mchit.pt.x = r.right / 2;
1744 mchit.pt.y = r.bottom / 2;
1745 mchit.iOffset = -1;
1746 ret = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1747 expect_hex(MCHT_CALENDARDATE, ret);
1748 expect(0, mchit.iOffset);
1750 /* over day area */
1751 mchit.pt.x = r.right / (7*2);
1752 mchit.pt.y = r.bottom / 2;
1753 mchit.iOffset = -1;
1754 mchit.iCol = mchit.iRow = -1;
1755 mchit.uHit = 0;
1756 mchit.rc.left = mchit.rc.right = mchit.rc.top = mchit.rc.bottom = -1;
1757 ret = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1758 expect_hex(MCHT_CALENDARDATE, ret);
1759 expect_hex(MCHT_CALENDARDATE, mchit.uHit);
1760 expect(0, mchit.iOffset);
1761 expect(2, mchit.iRow);
1762 expect(0, mchit.iCol);
1763 /* returned a one day rectangle */
1764 expect_d(r.right / 7, mchit.rc.right - mchit.rc.left);
1765 expect_d(r.bottom / 10, mchit.rc.bottom - mchit.rc.top);
1767 /* title */
1768 mchit.pt.x = 1;
1769 mchit.pt.y = 1;
1770 mchit.iOffset = -1;
1771 mchit.iCol = mchit.iRow = -1;
1772 mchit.uHit = 0;
1773 mchit.rc.left = mchit.rc.right = mchit.rc.top = mchit.rc.bottom = -1;
1774 ret = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1775 expect_hex(MCHT_TITLE, ret);
1776 expect_hex(MCHT_TITLE, mchit.uHit);
1777 expect(0, mchit.iOffset);
1778 expect(-1, mchit.iRow);
1779 expect(-1, mchit.iCol);
1780 expect(0, mchit.rc.left);
1781 expect(0, mchit.rc.top);
1782 expect_d(r.right, mchit.rc.right);
1783 ok(mchit.rc.bottom > 0, "got %d\n", mchit.rc.bottom);
1785 /* between two calendars */
1786 MoveWindow(hwnd, 0, 0, r.right * 5/2, r.bottom, FALSE);
1787 mchit.pt.x = r.right / (5*4);
1788 mchit.pt.y = r.bottom / 2;
1789 mchit.iOffset = -2;
1790 mchit.iCol = mchit.iRow = -2;
1791 mchit.uHit = ~0;
1792 mchit.rc.left = mchit.rc.right = mchit.rc.top = mchit.rc.bottom = -1;
1793 ret = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1794 todo_wine expect_hex(MCHT_NOWHERE, ret);
1795 todo_wine expect_hex(MCHT_NOWHERE, mchit.uHit);
1796 expect(-2, mchit.iOffset);
1797 expect(-2, mchit.iRow);
1798 expect(-2, mchit.iCol);
1799 todo_wine expect(0, mchit.rc.left);
1800 todo_wine expect(0, mchit.rc.top);
1801 todo_wine expect_d(r.right * 5/2, mchit.rc.right);
1802 todo_wine expect_d(r.bottom, mchit.rc.bottom);
1804 DestroyWindow(hwnd);
1807 static void test_get_set_border(void)
1809 HWND hwnd;
1810 DWORD ret;
1812 hwnd = create_monthcal_control(0);
1814 /* a non-default value */
1815 ret = SendMessage(hwnd, MCM_SETCALENDARBORDER, TRUE, 10);
1816 expect(0, ret);
1818 ret = SendMessage(hwnd, MCM_GETCALENDARBORDER, 0, 0);
1820 if (ret != 10)
1822 skip("MCM_GET/SETCALENDARBORDER not supported\n");
1823 DestroyWindow(hwnd);
1824 return;
1827 expect(10, ret);
1829 DestroyWindow(hwnd);
1832 static void test_MCM_SIZERECTTOMIN(void)
1834 HWND hwnd;
1835 DWORD ret;
1836 RECT r, r2;
1838 hwnd = create_monthcal_control(0);
1840 ret = SendMessageA(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r2);
1841 if (ret == 0)
1843 win_skip("Message MCM_GETMINREQRECT unsupported. Skipping.\n");
1844 DestroyWindow(hwnd);
1845 return;
1848 ret = SendMessageA(hwnd, MCM_SIZERECTTOMIN, 0, 0);
1849 ok(ret == 0, "got %d\n", ret);
1851 r.left = r.right = r.top = r.bottom = 0;
1852 ret = SendMessageA(hwnd, MCM_SIZERECTTOMIN, 0, (LPARAM)&r);
1853 if (ret == 0)
1855 skip("Message MCM_SIZERECTTOMIN unsupported. Skipping.\n");
1856 DestroyWindow(hwnd);
1857 return;
1859 ok(ret == 1, "got %d\n", ret);
1860 ok(r.left == 0 && r.right > 0, "got %d, %d\n", r.left, r.right);
1862 r = r2;
1863 ret = SendMessageA(hwnd, MCM_SIZERECTTOMIN, 0, (LPARAM)&r);
1864 ok(ret == 1, "got %d\n", ret);
1866 r2.right = (r2.right - r2.left) * 3;
1867 r2.bottom = (r2.bottom - r2.top) * 3;
1868 r2.left = r2.top = 0;
1869 ret = SendMessageA(hwnd, MCM_SIZERECTTOMIN, 0, (LPARAM)&r2);
1870 ok(ret == 1, "got %d\n", ret);
1872 DestroyWindow(hwnd);
1875 static void test_MCM_GETCALENDARCOUNT(void)
1877 HWND hwnd;
1878 DWORD ret;
1880 hwnd = create_monthcal_control(0);
1882 ret = SendMessageA(hwnd, MCM_GETCALENDARCOUNT, 0, 0);
1883 if (ret == 0)
1885 win_skip("Message MCM_GETCALENDARCOUNT unsupported. Skipping.\n");
1886 DestroyWindow(hwnd);
1887 return;
1890 expect(2, ret);
1892 DestroyWindow(hwnd);
1895 static void test_daystate(void)
1897 MONTHDAYSTATE state[4];
1898 DWORD ret, style;
1899 HWND hwnd;
1900 RECT r;
1902 /* without MCS_DAYSTATE */
1903 hwnd = create_monthcal_control(0);
1905 ret = SendMessage(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r);
1906 expect(TRUE, ret);
1908 /* resize control to display two Calendars */
1909 MoveWindow(hwnd, 0, 0, r.right, (5/2)*r.bottom, FALSE);
1911 ret = SendMessageA(hwnd, MCM_GETMONTHRANGE, GMR_DAYSTATE, 0);
1912 expect(4, ret);
1914 ret = SendMessageA(hwnd, MCM_SETDAYSTATE, 4, (LPARAM)&state);
1915 expect(0, ret);
1917 ret = SendMessageA(hwnd, MCM_SETDAYSTATE, 2, (LPARAM)&state);
1918 expect(0, ret);
1920 ret = SendMessageA(hwnd, MCM_SETDAYSTATE, 0, 0);
1921 expect(0, ret);
1923 /* try to switch on */
1924 SetWindowLongA(hwnd, GWL_STYLE, GetWindowLongA(hwnd, GWL_STYLE) | MCS_DAYSTATE);
1925 style = GetWindowLongA(hwnd, GWL_STYLE);
1926 ok((style & MCS_DAYSTATE) == 0, "got 0x%08x\n", style);
1928 DestroyWindow(hwnd);
1930 /* with MCS_DAYSTATE */
1931 hwnd = create_monthcal_control(MCS_DAYSTATE);
1933 ret = SendMessageA(hwnd, MCM_GETMONTHRANGE, GMR_DAYSTATE, 0);
1934 expect(4, ret);
1936 ret = SendMessageA(hwnd, MCM_SETDAYSTATE, 4, (LPARAM)&state);
1937 expect(1, ret);
1939 ret = SendMessageA(hwnd, MCM_SETDAYSTATE, 2, (LPARAM)&state);
1940 expect(0, ret);
1942 ret = SendMessageA(hwnd, MCM_SETDAYSTATE, 0, 0);
1943 expect(0, ret);
1945 /* try to switch off */
1946 SetWindowLongA(hwnd, GWL_STYLE, GetWindowLongA(hwnd, GWL_STYLE) & ~MCS_DAYSTATE);
1947 style = GetWindowLongA(hwnd, GWL_STYLE);
1948 ok((style & MCS_DAYSTATE) == MCS_DAYSTATE, "got 0x%08x\n", style);
1950 DestroyWindow(hwnd);
1953 static void test_sel_notify(void)
1955 typedef struct
1957 DWORD val;
1958 const char* name;
1959 } Monthcal_style;
1961 HWND hwnd;
1962 RECT rc;
1963 MCHITTESTINFO mchit = {sizeof(MCHITTESTINFO)};
1964 SYSTEMTIME st;
1965 Monthcal_style styles[] = {
1966 {MCS_NOTODAY, "MCS_NOTODAY"},
1967 {MCS_NOTODAY | MCS_MULTISELECT, "MCS_NOTODAY | MCS_MULTISELECT"},
1968 {MCS_DAYSTATE, "MCS_DAYSTATE"},
1969 {MCS_DAYSTATE | MCS_MULTISELECT, "MCS_DAYSTATE | MCS_MULTISELECT"}
1971 int i;
1973 for(i = 0; i < sizeof styles / sizeof styles[0]; i++)
1975 hwnd = create_monthcal_control(styles[i].val);
1976 SetWindowLongPtr(hwnd, GWLP_ID, SEL_NOTIFY_TEST_ID);
1977 assert(hwnd);
1978 SendMessage(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&rc);
1979 MoveWindow(hwnd, 0, 0, rc.right, rc.bottom, FALSE);
1980 /* Simulate mouse click on some unselected day to generate
1981 MCN_SELECT and MCN_SELCHANGE notifications */
1982 mchit.pt.x = rc.right / 2;
1983 mchit.pt.y = rc.bottom / 2;
1984 SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1985 SendMessage(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st);
1986 while(st.wDay == mchit.st.wDay) /* Ensure that mchit.pt points to unselected day */
1988 mchit.pt.y++;
1989 SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1991 SendMessage(hwnd, WM_LBUTTONDOWN, 0, MAKELPARAM(mchit.pt.x, mchit.pt.y));
1992 SendMessage(hwnd, WM_LBUTTONUP, 0, MAKELPARAM(mchit.pt.x, mchit.pt.y));
1993 DestroyWindow(hwnd);
1997 START_TEST(monthcal)
1999 BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
2000 INITCOMMONCONTROLSEX iccex;
2001 HMODULE hComctl32;
2002 HWND hwnd;
2004 ULONG_PTR ctx_cookie;
2005 HANDLE hCtx;
2007 hComctl32 = GetModuleHandleA("comctl32.dll");
2008 pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
2009 if (!pInitCommonControlsEx)
2011 skip("InitCommonControlsEx() is missing. Skipping the tests\n");
2012 return;
2014 iccex.dwSize = sizeof(iccex);
2015 iccex.dwICC = ICC_DATE_CLASSES;
2016 pInitCommonControlsEx(&iccex);
2018 test_monthcal();
2020 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
2022 parent_wnd = create_parent_window();
2024 test_create();
2025 test_destroy();
2026 test_color();
2027 test_currdate();
2028 test_firstDay();
2029 test_unicode();
2030 test_today();
2031 test_scroll();
2032 test_monthrange();
2033 test_hittest();
2034 test_todaylink();
2035 test_size();
2036 test_maxselday();
2037 test_selrange();
2038 test_killfocus();
2039 test_daystate();
2040 test_sel_notify();
2042 if (!load_v6_module(&ctx_cookie, &hCtx))
2044 DestroyWindow(parent_wnd);
2045 return;
2048 /* this is a XP SP3 failure workaround */
2049 hwnd = CreateWindowExA(0, MONTHCAL_CLASSA, "foo",
2050 WS_CHILD | WS_BORDER | WS_VISIBLE,
2051 0, 0, 100, 100,
2052 parent_wnd, NULL, GetModuleHandleA(NULL), NULL);
2053 if (!IsWindow(hwnd))
2055 win_skip("FIXME: failed to create Monthcal window.\n");
2056 unload_v6_module(ctx_cookie, hCtx);
2057 DestroyWindow(parent_wnd);
2058 return;
2060 else
2061 DestroyWindow(hwnd);
2063 test_hittest_v6();
2064 test_get_set_border();
2065 test_MCM_SIZERECTTOMIN();
2066 test_MCM_GETCALENDARCOUNT();
2068 unload_v6_module(ctx_cookie, hCtx);
2070 DestroyWindow(parent_wnd);