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
30 #include "wine/test.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 },
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 },
74 static const struct message create_monthcal_control_seq[] = {
75 { WM_NOTIFYFORMAT, sent|lparam, 0, NF_QUERY },
76 { WM_QUERYUISTATE, sent|optional },
78 { WM_PARENTNOTIFY, sent|wparam, WM_CREATE},
82 static const struct message create_monthcal_multi_sel_style_seq[] = {
83 { WM_NOTIFYFORMAT, sent|lparam, 0, NF_QUERY },
84 { WM_QUERYUISTATE, sent|optional },
86 { WM_PARENTNOTIFY, sent },
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},
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},
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},
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},
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},
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},
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},
217 static const struct message monthcal_monthrange_seq[] = {
218 { MCM_GETMONTHRANGE, sent|wparam, GMR_VISIBLE},
219 { MCM_GETMONTHRANGE, sent|wparam, GMR_DAYSTATE},
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},
233 /* expected message sequence for parent*/
234 static const struct message destroy_monthcal_parent_msgs_seq[] = {
235 { WM_PARENTNOTIFY, sent|wparam, WM_DESTROY},
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},
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},
260 static void test_monthcal(void)
263 SYSTEMTIME st[2], st1[2], today;
264 int res, month_range;
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);
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");
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]);
311 SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&today);
313 /* Invalid date/time */
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]);
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]);
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]);
360 month_range = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st1);
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");
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);
373 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Failed to set both min and max limits\n");
375 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Failed to set both min and max limits\n");
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");
381 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
383 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
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]);
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");
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);
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);
446 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
448 static LONG defwndproc_counter = 0;
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 trace("parent: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
464 msg.message = message;
465 msg.flags = sent|wparam|lparam;
466 if (defwndproc_counter) msg.flags |= defwinproc;
469 add_message(sequences, PARENT_SEQ_INDEX, &msg);
472 if (message == WM_NOTIFY)
474 NMHDR *hdr = (NMHDR*)lParam;
477 case MCN_GETDAYSTATE:
479 NMDAYSTATE *nmstate = (NMDAYSTATE*)lParam;
480 static MONTHDAYSTATE months[14] = { 0 };
482 ok(nmstate->cDayState > 0, "got %d\n", nmstate->cDayState);
483 ok(nmstate->cDayState <= 14, "got %d\n", nmstate->cDayState);
484 ok(nmstate->prgDayState != NULL, "got %p\n", nmstate->prgDayState);
486 nmstate->prgDayState = months;
493 NMSELCHANGE *nmchg = (NMSELCHANGE*)lParam;
495 BOOL is_multisel = GetWindowLongPtr(nmchg->nmhdr.hwndFrom, GWL_STYLE) &
498 if(GetWindowLongPtr(nmchg->nmhdr.hwndFrom, GWLP_ID) != SEL_NOTIFY_TEST_ID)
500 SendMessage(nmchg->nmhdr.hwndFrom, is_multisel ? MCM_GETSELRANGE :
501 MCM_GETCURSEL, 0, (LPARAM)st);
503 expect(st[0].wYear, nmchg->stSelStart.wYear);
504 expect(st[0].wMonth, nmchg->stSelStart.wMonth);
505 expect(0, nmchg->stSelStart.wDayOfWeek);
506 expect(st[0].wDay, nmchg->stSelStart.wDay);
510 expect(st[1].wYear, nmchg->stSelEnd.wYear);
511 expect(st[1].wMonth, nmchg->stSelEnd.wMonth);
512 expect(0, nmchg->stSelEnd.wDayOfWeek);
513 expect(st[1].wDay, nmchg->stSelEnd.wDay);
516 ok(!(nmchg->stSelEnd.wYear | nmchg->stSelEnd.wMonth |
517 nmchg->stSelEnd.wDayOfWeek | nmchg->stSelEnd.wDay |
518 nmchg->stSelEnd.wHour | nmchg->stSelEnd.wMinute |
519 nmchg->stSelEnd.wSecond | nmchg->stSelEnd.wMilliseconds),
520 "Non-zero member in stSelEnd\n");
528 defwndproc_counter++;
529 ret = DefWindowProcA(hwnd, message, wParam, lParam);
530 defwndproc_counter--;
535 static BOOL register_parent_wnd_class(void)
540 cls.lpfnWndProc = parent_wnd_proc;
543 cls.hInstance = GetModuleHandleA(NULL);
545 cls.hCursor = LoadCursorA(0, IDC_ARROW);
546 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
547 cls.lpszMenuName = NULL;
548 cls.lpszClassName = "Month-Cal test parent class";
549 return RegisterClassA(&cls);
552 static HWND create_parent_window(void)
556 InitCommonControls();
558 /* flush message sequences, so we can check the new sequence by the end of function */
559 flush_sequences(sequences, NUM_MSG_SEQUENCES);
561 if (!register_parent_wnd_class())
564 hwnd = CreateWindowEx(0, "Month-Cal test parent class",
565 "Month-Cal test parent window",
566 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
567 WS_MAXIMIZEBOX | WS_VISIBLE,
569 GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL);
573 /* check for message sequences */
574 ok_sequence(sequences, PARENT_SEQ_INDEX, create_parent_window_seq, "create parent window", FALSE);
579 static LRESULT WINAPI monthcal_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
581 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
582 static LONG defwndproc_counter = 0;
586 msg.message = message;
587 msg.flags = sent|wparam|lparam;
588 if (defwndproc_counter) msg.flags |= defwinproc;
592 add_message(sequences, MONTHCAL_SEQ_INDEX, &msg);
594 /* some debug output for style changing */
595 if ((message == WM_STYLECHANGING ||
596 message == WM_STYLECHANGED) && lParam)
598 STYLESTRUCT *style = (STYLESTRUCT*)lParam;
599 trace("\told style: 0x%08x, new style: 0x%08x\n", style->styleOld, style->styleNew);
602 defwndproc_counter++;
603 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
604 defwndproc_counter--;
609 static HWND create_monthcal_control(DWORD style)
614 hwnd = CreateWindowEx(0,
617 WS_CHILD | WS_BORDER | WS_VISIBLE | style,
619 parent_wnd, NULL, GetModuleHandleA(NULL), NULL);
621 if (!hwnd) return NULL;
623 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
624 (LONG_PTR)monthcal_subclass_proc);
625 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
627 SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(SYSTEM_FONT), 0);
633 /* Setter and Getters Tests */
635 static void test_color(void)
637 COLORREF color, prev;
640 hwnd = create_monthcal_control(0);
642 /* invalid color index */
643 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT + 1, 0);
645 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TRAILINGTEXT + 1, RGB(255,255,255));
648 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_BACKGROUND, 0);
649 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_BACKGROUND, RGB(0,0,0));
651 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_BACKGROUND, 0);
652 expect(RGB(0,0,0), color);
653 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_BACKGROUND, RGB(255,255,255));
655 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_BACKGROUND, 0);
656 expect(RGB(255,255,255), color);
658 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_MONTHBK, 0);
659 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_MONTHBK, RGB(0,0,0));
661 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_MONTHBK, 0);
662 expect(RGB(0,0,0), color);
663 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_MONTHBK, RGB(255,255,255));
665 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_MONTHBK, 0);
666 expect(RGB(255,255,255), color);
668 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TEXT, 0);
669 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TEXT, RGB(0,0,0));
671 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TEXT, 0);
672 expect(RGB(0,0,0), color);
673 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TEXT, RGB(255,255,255));
675 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TEXT, 0);
676 expect(RGB(255,255,255), color);
678 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLEBK, 0);
679 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLEBK, RGB(0,0,0));
681 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLEBK, 0);
682 expect(RGB(0,0,0), color);
683 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLEBK, RGB(255,255,255));
685 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLEBK, 0);
686 expect(RGB(255,255,255), color);
688 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLETEXT, 0);
689 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLETEXT, RGB(0,0,0));
691 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLETEXT, 0);
692 expect(RGB(0,0,0), color);
693 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLETEXT, RGB(255,255,255));
695 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLETEXT, 0);
696 expect(RGB(255,255,255), color);
698 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT, 0);
699 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TRAILINGTEXT, RGB(0,0,0));
701 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT, 0);
702 expect(RGB(0,0,0), color);
703 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TRAILINGTEXT, RGB(255,255,255));
705 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT, 0);
706 expect(RGB(255,255,255), color);
711 static void test_currdate(void)
713 SYSTEMTIME st_original, st_new, st_test;
717 hwnd = create_monthcal_control(0);
719 flush_sequences(sequences, NUM_MSG_SEQUENCES);
721 /* Setter and Getters for current date selected */
722 st_original.wYear = 2000;
723 st_original.wMonth = 11;
724 st_original.wDay = 28;
725 st_original.wHour = 11;
726 st_original.wMinute = 59;
727 st_original.wSecond = 30;
728 st_original.wMilliseconds = 0;
729 st_original.wDayOfWeek = 0;
731 st_new = st_test = st_original;
733 /* Should not validate the time */
734 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
737 /* Overflow matters, check for wDay */
739 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
742 /* correct wDay before checking for wMonth */
744 expect(st_original.wDay, st_test.wDay);
746 /* Overflow matters, check for wMonth */
748 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
751 /* checking if gets the information right, modify st_new */
759 res = SendMessage(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_new);
762 /* st_new change to st_origin, above settings with overflow */
763 /* should not change the current settings */
764 expect(st_original.wYear, st_new.wYear);
765 expect(st_original.wMonth, st_new.wMonth);
766 expect(st_original.wDay, st_new.wDay);
767 ok(st_original.wHour == st_new.wHour ||
768 broken(0 == st_new.wHour), /* comctl32 <= 4.70 */
769 "Expected %d, got %d\n", st_original.wHour, st_new.wHour);
770 ok(st_original.wMinute == st_new.wMinute ||
771 broken(0 == st_new.wMinute), /* comctl32 <= 4.70 */
772 "Expected %d, got %d\n", st_original.wMinute, st_new.wMinute);
773 ok(st_original.wSecond == st_new.wSecond ||
774 broken(0 == st_new.wSecond), /* comctl32 <= 4.70 */
775 "Expected %d, got %d\n", st_original.wSecond, st_new.wSecond);
777 /* lparam cannot be NULL */
778 res = SendMessage(hwnd, MCM_GETCURSEL, 0, 0);
781 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_curr_date_seq, "monthcal currDate", TRUE);
783 /* December, 31, 9999 is the maximum allowed date */
784 memset(&st_new, 0, sizeof(st_new));
788 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_new);
790 memset(&st_test, 0, sizeof(st_test));
791 res = SendMessage(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_test);
793 expect(st_new.wYear, st_test.wYear);
794 expect(st_new.wMonth, st_test.wMonth);
795 expect(st_new.wDay, st_test.wDay);
796 expect(st_new.wHour, st_test.wHour);
797 expect(st_new.wMinute, st_test.wMinute);
798 expect(st_new.wSecond, st_test.wSecond);
799 /* try one day later */
800 st_original = st_new;
801 st_new.wYear = 10000;
804 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_new);
806 broken(1 == res), /* comctl32 <= 4.72 */
807 "Expected 0, got %d\n", res);
810 memset(&st_test, 0, sizeof(st_test));
811 res = SendMessage(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_test);
813 expect(st_original.wYear, st_test.wYear);
814 expect(st_original.wMonth, st_test.wMonth);
815 expect(st_original.wDay, st_test.wDay);
816 expect(st_original.wHour, st_test.wHour);
817 expect(st_original.wMinute, st_test.wMinute);
818 expect(st_original.wSecond, st_test.wSecond);
821 /* setting selection equal to current reports success even if out range */
822 memset(&st_new, 0, sizeof(st_new));
826 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_new);
828 memset(&st_test, 0, sizeof(st_test));
829 st_test.wYear = 2009;
832 res = SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN, (LPARAM)&st_test);
834 /* set to current again */
835 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_new);
838 /* set with invalid day of week */
839 memset(&st_test, 0, sizeof(st_test));
840 st_test.wYear = 2009;
843 st_test.wDayOfWeek = 100;
844 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
847 memset(&st_test, 0, sizeof(st_test));
848 res = SendMessage(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_test);
850 expect(2009, st_test.wYear);
851 expect(7, st_test.wDay);
852 expect(10, st_test.wMonth);
853 expect(3, st_test.wDayOfWeek);
858 static void test_firstDay(void)
860 int res, fday, i, prev;
861 CHAR b[128], caltype[3];
862 LCID lcid = LOCALE_USER_DEFAULT;
866 SetLastError(0xdeadbeef);
867 ret = GetLocaleInfoA(lcid, LOCALE_ICALENDARTYPE, caltype, 3);
869 skip("Must know local calendar type (%x)\n", GetLastError());
871 } else if (atoi(caltype) != CAL_GREGORIAN) {
872 skip("MonthCalendar Control only supports Gregorian calendar (type: %s)\n", caltype);
876 hwnd = create_monthcal_control(0);
878 flush_sequences(sequences, NUM_MSG_SEQUENCES);
880 /* Setter and Getters for first day of week */
881 /* check for locale first day */
882 if(GetLocaleInfoA(lcid, LOCALE_IFIRSTDAYOFWEEK, b, 128)){
884 trace("fday: %d\n", fday);
885 res = SendMessage(hwnd, MCM_GETFIRSTDAYOFWEEK, 0, 0);
889 /* checking for the values that actually will be stored as */
890 /* current first day when we set a new value */
891 for (i = -5; i < 12; i++){
892 res = SendMessage(hwnd, MCM_SETFIRSTDAYOFWEEK, 0, i);
894 res = SendMessage(hwnd, MCM_GETFIRSTDAYOFWEEK, 0, 0);
898 expect(MAKELONG(fday, FALSE), res);
900 /* out of range sets max first day of week, locale is ignored */
901 expect(MAKELONG(6, TRUE), res);
903 expect(MAKELONG(i, TRUE), res);
907 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_first_day_seq, "monthcal firstDay", FALSE);
910 skip("Cannot retrieve first day of the week\n");
916 static void test_unicode(void)
921 hwnd = create_monthcal_control(0);
923 flush_sequences(sequences, NUM_MSG_SEQUENCES);
925 /* Setter and Getters for Unicode format */
927 /* getting the current settings */
928 temp = SendMessage(hwnd, MCM_GETUNICODEFORMAT, 0, 0);
930 /* setting to 1, should return previous settings */
931 res = SendMessage(hwnd, MCM_SETUNICODEFORMAT, 1, 0);
934 /* current setting is 1, so, should return 1 */
935 res = SendMessage(hwnd, MCM_GETUNICODEFORMAT, 0, 0);
937 broken(0 == res), /* comctl32 <= 4.70 */
938 "Expected 1, got %d\n", res);
940 /* setting to 0, should return previous settings */
941 res = SendMessage(hwnd, MCM_SETUNICODEFORMAT, 0, 0);
943 broken(0 == res), /* comctl32 <= 4.70 */
944 "Expected 1, got %d\n", res);
946 /* current setting is 0, so, it should return 0 */
947 res = SendMessage(hwnd, MCM_GETUNICODEFORMAT, 0, 0);
950 /* should return previous settings */
951 res = SendMessage(hwnd, MCM_SETUNICODEFORMAT, 1, 0);
954 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_unicode_seq, "monthcal unicode", FALSE);
959 static void test_hittest(void)
961 typedef struct hittest_test
967 static const hittest_test_t title_hits[] = {
968 /* Start is the same everywhere */
970 { MCHT_TITLEBTNPREV, 0 },
971 /* The middle piece is only tested for presence of items */
972 /* End is the same everywhere */
973 { MCHT_TITLEBTNNEXT, 0 },
985 char yearmonth[80], *locale_month, *locale_year;
986 int month_count, year_count;
989 memset(&mchit, 0, sizeof(MCHITTESTINFO));
991 hwnd = create_monthcal_control(0);
993 /* test with invalid structure size */
994 mchit.cbSize = MCHITTESTINFO_V1_SIZE - 1;
997 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
998 expect(0, mchit.pt.x);
999 expect(0, mchit.pt.y);
1001 expect(0, mchit.uHit);
1002 /* test with invalid pointer */
1003 res = SendMessage(hwnd, MCM_HITTEST, 0, 0);
1006 /* resize control to display single Calendar */
1007 res = SendMessage(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r);
1010 win_skip("Message MCM_GETMINREQRECT unsupported. Skipping.\n");
1011 DestroyWindow(hwnd);
1014 MoveWindow(hwnd, 0, 0, r.right, r.bottom, FALSE);
1016 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1024 st.wMilliseconds = 0;
1027 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st);
1030 /* (0, 0) is the top left of the control - title */
1031 mchit.cbSize = MCHITTESTINFO_V1_SIZE;
1034 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1035 expect(0, mchit.pt.x);
1036 expect(0, mchit.pt.y);
1037 expect(mchit.uHit, res);
1038 expect_hex(MCHT_TITLE, res);
1040 /* bottom right of the control and should not be active */
1041 mchit.pt.x = r.right;
1042 mchit.pt.y = r.bottom;
1043 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1044 expect(r.right, mchit.pt.x);
1045 expect(r.bottom, mchit.pt.y);
1046 expect(mchit.uHit, res);
1047 todo_wine expect_hex(MCHT_NOWHERE, res);
1049 /* completely out of the control, should not be active */
1050 mchit.pt.x = 2 * r.right;
1051 mchit.pt.y = 2 * r.bottom;
1052 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1053 expect(2 * r.right, mchit.pt.x);
1054 expect(2 * r.bottom, mchit.pt.y);
1055 expect(mchit.uHit, res);
1056 todo_wine expect_hex(MCHT_NOWHERE, res);
1058 /* in active area - day of the week */
1059 mchit.pt.x = r.right / 2;
1060 mchit.pt.y = r.bottom / 2;
1061 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1062 expect(r.right / 2, mchit.pt.x);
1063 expect(r.bottom / 2, mchit.pt.y);
1064 expect(mchit.uHit, res);
1065 expect_hex(MCHT_CALENDARDATE, res);
1067 /* in active area - day of the week #2 */
1068 mchit.pt.x = r.right / 14; /* half of first day rect */
1069 mchit.pt.y = r.bottom / 2;
1070 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1071 expect(r.right / 14, mchit.pt.x);
1072 expect(r.bottom / 2, mchit.pt.y);
1073 expect(mchit.uHit, res);
1074 expect_hex(MCHT_CALENDARDATE, res);
1076 /* in active area - date from prev month */
1077 mchit.pt.x = r.right / 14; /* half of first day rect */
1078 mchit.pt.y = 6 * r.bottom / 19;
1079 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1080 expect(r.right / 14, mchit.pt.x);
1081 expect(6 * r.bottom / 19, mchit.pt.y);
1082 expect(mchit.uHit, res);
1083 expect_hex(MCHT_CALENDARDATEPREV, res);
1086 /* (125, 115) is in active area - date from this month */
1089 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1090 expect(125, mchit.pt.x);
1091 expect(115, mchit.pt.y);
1092 expect(mchit.uHit, res);
1093 expect(MCHT_CALENDARDATE, res);
1096 /* in active area - date from next month */
1097 mchit.pt.x = 11 * r.right / 14;
1098 mchit.pt.y = 16 * r.bottom / 19;
1099 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1100 expect(11 * r.right / 14, mchit.pt.x);
1101 expect(16 * r.bottom / 19, mchit.pt.y);
1102 expect(mchit.uHit, res);
1103 expect_hex(MCHT_CALENDARDATENEXT, res);
1105 /* in active area - today link */
1106 mchit.pt.x = r.right / 14;
1107 mchit.pt.y = 18 * r.bottom / 19;
1108 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1109 expect(r.right / 14, mchit.pt.x);
1110 expect(18 * r.bottom / 19, mchit.pt.y);
1111 expect(mchit.uHit, res);
1112 expect_hex(MCHT_TODAYLINK, res);
1114 /* in active area - today link */
1115 mchit.pt.x = r.right / 2;
1116 mchit.pt.y = 18 * r.bottom / 19;
1117 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1118 expect(r.right / 2, mchit.pt.x);
1119 expect(18 * r.bottom / 19, mchit.pt.y);
1120 expect(mchit.uHit, res);
1121 expect_hex(MCHT_TODAYLINK, res);
1123 /* in active area - today link */
1124 mchit.pt.x = r.right / 10;
1125 mchit.pt.y = 18 * r.bottom / 19;
1126 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1127 expect(r.right / 10, mchit.pt.x);
1128 expect(18 * r.bottom / 19, mchit.pt.y);
1129 expect(mchit.uHit, res);
1130 expect_hex(MCHT_TODAYLINK, res);
1132 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_hit_test_seq, "monthcal hit test", TRUE);
1134 /* The horizontal position of title bar elements depends on locale (y pos
1135 is constant), so we sample across a horizontal line and make sure we
1136 find all elements. */
1138 /* Get the format of the title */
1139 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SYEARMONTH, yearmonth, 80);
1140 /* Find out if we have a month and/or year */
1141 locale_year = strstr(yearmonth, "y");
1142 locale_month = strstr(yearmonth, "M");
1145 mchit.pt.y = (5/2) * r.bottom / 19;
1147 old_res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1148 expect_hex(title_hits[title_index].ht, old_res);
1150 in_the_middle = FALSE;
1151 month_count = year_count = 0;
1152 for (x = 0; x < r.right; x++){
1154 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1155 expect(x, mchit.pt.x);
1156 expect((5/2) * r.bottom / 19, mchit.pt.y);
1157 expect(mchit.uHit, res);
1158 if (res != old_res) {
1160 if (old_res == MCHT_TITLEBTNPREV)
1161 in_the_middle = TRUE;
1163 if (res == MCHT_TITLEBTNNEXT)
1164 in_the_middle = FALSE;
1166 if (in_the_middle) {
1167 if (res == MCHT_TITLEMONTH)
1169 else if (res == MCHT_TITLEYEAR)
1174 if (sizeof(title_hits) / sizeof(title_hits[0]) <= title_index)
1177 if (title_hits[title_index].todo) {
1179 ok(title_hits[title_index].ht == res, "Expected %x, got %x, pos %d\n",
1180 title_hits[title_index].ht, res, x);
1182 ok(title_hits[title_index].ht == res, "Expected %x, got %x, pos %d\n",
1183 title_hits[title_index].ht, res, x);
1190 /* There are some limits, even if LOCALE_SYEARMONTH contains rubbish
1191 * or no month/year indicators at all */
1193 todo_wine ok(month_count == 1, "Expected 1 month item, got %d\n", month_count);
1195 ok(month_count <= 1, "Too many month items: %d\n", month_count);
1198 todo_wine ok(year_count == 1, "Expected 1 year item, got %d\n", year_count);
1200 ok(year_count <= 1, "Too many year items: %d\n", year_count);
1202 todo_wine ok(month_count + year_count >= 1, "Not enough month and year items\n");
1204 ok(r.right <= x && title_index + 1 == sizeof(title_hits) / sizeof(title_hits[0]),
1205 "Wrong title layout\n");
1207 DestroyWindow(hwnd);
1210 static void test_todaylink(void)
1212 MCHITTESTINFO mchit;
1213 SYSTEMTIME st_test, st_new;
1218 memset(&mchit, 0, sizeof(MCHITTESTINFO));
1220 hwnd = create_monthcal_control(0);
1222 res = SendMessage(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r);
1224 MoveWindow(hwnd, 0, 0, r.right, r.bottom, FALSE);
1226 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1228 /* hit active area - today link */
1229 mchit.cbSize = MCHITTESTINFO_V1_SIZE;
1230 mchit.pt.x = r.right / 14;
1231 mchit.pt.y = 18 * r.bottom / 19;
1232 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1233 expect(r.right / 14, mchit.pt.x);
1234 expect(18 * r.bottom / 19, mchit.pt.y);
1235 expect(mchit.uHit, res);
1236 expect(MCHT_TODAYLINK, res);
1240 st_test.wYear = 2005;
1242 res = SendMessage(hwnd, MCM_SETTODAY, 0, (LPARAM)&st_test);
1245 memset(&st_new, 0, sizeof(st_new));
1246 res = SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&st_new);
1248 expect(1, st_new.wDay);
1249 expect(1, st_new.wMonth);
1250 expect(2005, st_new.wYear);
1252 res = SendMessage(hwnd, WM_LBUTTONDOWN, MK_LBUTTON, MAKELONG(mchit.pt.x, mchit.pt.y));
1255 memset(&st_new, 0, sizeof(st_new));
1256 res = SendMessage(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_new);
1258 expect(1, st_new.wDay);
1259 expect(1, st_new.wMonth);
1260 expect(2005, st_new.wYear);
1262 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_todaylink_seq, "monthcal hit test", TRUE);
1264 DestroyWindow(hwnd);
1267 static void test_today(void)
1269 SYSTEMTIME st_test, st_new;
1273 hwnd = create_monthcal_control(0);
1275 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1277 /* Setter and Getters for "today" information */
1279 /* check for overflow, should be ok */
1280 memset(&st_test, 0, sizeof(st_test));
1282 st_test.wMonth = 38;
1287 res = SendMessage(hwnd, MCM_SETTODAY, 0, (LPARAM)&st_test);
1290 res = SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&st_new);
1293 /* st_test should not change */
1294 expect(38, st_test.wDay);
1295 expect(38, st_test.wMonth);
1297 /* st_new should change, overflow does not matter */
1298 expect(38, st_new.wDay);
1299 expect(38, st_new.wMonth);
1301 /* check for zero, should be ok*/
1305 res = SendMessage(hwnd, MCM_SETTODAY, 0, (LPARAM)&st_test);
1308 res = SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&st_new);
1311 /* st_test should not change */
1312 expect(0, st_test.wDay);
1313 expect(0, st_test.wMonth);
1315 /* st_new should change to zero*/
1316 expect(0, st_new.wDay);
1317 expect(0, st_new.wMonth);
1319 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_today_seq, "monthcal today", TRUE);
1321 DestroyWindow(hwnd);
1324 static void test_scroll(void)
1329 hwnd = create_monthcal_control(0);
1331 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1333 /* Setter and Getters for scroll rate */
1334 res = SendMessage(hwnd, MCM_SETMONTHDELTA, 2, 0);
1337 res = SendMessage(hwnd, MCM_SETMONTHDELTA, 3, 0);
1339 res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
1342 res = SendMessage(hwnd, MCM_SETMONTHDELTA, 12, 0);
1344 res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
1347 res = SendMessage(hwnd, MCM_SETMONTHDELTA, 15, 0);
1349 res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
1352 res = SendMessage(hwnd, MCM_SETMONTHDELTA, -5, 0);
1354 res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
1357 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_scroll_seq, "monthcal scroll", FALSE);
1359 DestroyWindow(hwnd);
1362 static void test_monthrange(void)
1365 SYSTEMTIME st_visible[2], st_daystate[2], st;
1369 hwnd = create_monthcal_control(0);
1371 memset(&st_visible, 0, sizeof(st_visible));
1372 memset(&st_daystate, 0, sizeof(st_daystate));
1380 st.wMilliseconds = 0;
1383 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st);
1386 /* to be locale independent */
1387 SendMessage(hwnd, MCM_SETFIRSTDAYOFWEEK, 0, (LPARAM)6);
1389 res = SendMessage(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r);
1391 /* resize control to display two Calendars */
1392 MoveWindow(hwnd, 0, 0, r.right, (5/2)*r.bottom, FALSE);
1394 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1396 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st_visible);
1398 expect(2000, st_visible[0].wYear);
1399 expect(11, st_visible[0].wMonth);
1400 expect(1, st_visible[0].wDay);
1401 expect(2000, st_visible[1].wYear);
1402 expect(12, st_visible[1].wMonth);
1403 expect(31, st_visible[1].wDay);
1405 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_DAYSTATE, (LPARAM)st_daystate);
1407 expect(2000, st_daystate[0].wYear);
1408 expect(10, st_daystate[0].wMonth);
1409 expect(29, st_daystate[0].wDay);
1410 expect(2001, st_daystate[1].wYear);
1411 expect(1, st_daystate[1].wMonth);
1412 expect(6, st_daystate[1].wDay);
1414 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_monthrange_seq, "monthcal monthrange", FALSE);
1416 /* with null date array parameter */
1417 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, 0);
1420 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_DAYSTATE, 0);
1423 /* resize control to display single Calendar */
1424 MoveWindow(hwnd, 0, 0, r.right, r.bottom, FALSE);
1426 memset(&st, 0, sizeof(st));
1431 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st);
1434 /* September 1752 has 19 days */
1435 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st_visible);
1438 expect(1752, st_visible[0].wYear);
1439 expect(9, st_visible[0].wMonth);
1440 ok(14 == st_visible[0].wDay ||
1441 broken(1 == st_visible[0].wDay), /* comctl32 <= 4.72 */
1442 "Expected 14, got %d\n", st_visible[0].wDay);
1444 expect(1752, st_visible[1].wYear);
1445 expect(9, st_visible[1].wMonth);
1446 expect(19, st_visible[1].wDay);
1448 DestroyWindow(hwnd);
1451 static void test_maxselday(void)
1457 hwnd = create_monthcal_control(0);
1458 /* if no style specified default to 1 */
1459 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1461 res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, 5, 0);
1463 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1466 /* try to set style */
1467 style = GetWindowLong(hwnd, GWL_STYLE);
1468 SetWindowLong(hwnd, GWL_STYLE, style | MCS_MULTISELECT);
1469 style = GetWindowLong(hwnd, GWL_STYLE);
1470 ok(!(style & MCS_MULTISELECT), "Expected MCS_MULTISELECT not to be set\n");
1471 DestroyWindow(hwnd);
1473 hwnd = create_monthcal_control(MCS_MULTISELECT);
1474 /* try to remove style */
1475 style = GetWindowLong(hwnd, GWL_STYLE);
1476 SetWindowLong(hwnd, GWL_STYLE, style & ~MCS_MULTISELECT);
1477 style = GetWindowLong(hwnd, GWL_STYLE);
1478 ok(style & MCS_MULTISELECT, "Expected MCS_MULTISELECT to be set\n");
1479 DestroyWindow(hwnd);
1481 hwnd = create_monthcal_control(MCS_MULTISELECT);
1483 /* default width is a week */
1484 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1487 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1489 /* Setter and Getters for max selected days */
1490 res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, 5, 0);
1492 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1495 res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, 15, 0);
1497 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1500 /* test invalid value */
1501 res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, -1, 0);
1503 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1506 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_max_sel_day_seq, "monthcal MaxSelDay", FALSE);
1508 /* zero value is invalid too */
1509 res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, 0, 0);
1511 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1514 DestroyWindow(hwnd);
1517 static void test_size(void)
1521 HFONT hFont1, hFont2;
1525 hwnd = create_monthcal_control(0);
1527 lstrcpyA(logfont.lfFaceName, "Arial");
1528 memset(&logfont, 0, sizeof(logfont));
1529 logfont.lfHeight = 12;
1530 hFont1 = CreateFontIndirectA(&logfont);
1532 logfont.lfHeight = 24;
1533 hFont2 = CreateFontIndirectA(&logfont);
1535 /* initialize to a font we can compare against */
1536 SendMessage(hwnd, WM_SETFONT, (WPARAM)hFont1, 0);
1537 res = SendMessage(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r1);
1538 ok(res, "SendMessage(MCM_GETMINREQRECT) failed\n");
1540 /* check that setting a larger font results in an larger rect */
1541 SendMessage(hwnd, WM_SETFONT, (WPARAM)hFont2, 0);
1542 res = SendMessage(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r2);
1543 ok(res, "SendMessage(MCM_GETMINREQRECT) failed\n");
1545 OffsetRect(&r1, -r1.left, -r1.top);
1546 OffsetRect(&r2, -r2.left, -r2.top);
1548 ok(r1.bottom < r2.bottom, "Failed to get larger rect with larger font\n");
1550 DestroyWindow(hwnd);
1553 static void test_create(void)
1557 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1559 hwnd = create_monthcal_control(0);
1560 ok_sequence(sequences, PARENT_SEQ_INDEX, create_monthcal_control_seq, "create monthcal control", TRUE);
1562 DestroyWindow(hwnd);
1564 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1565 hwnd = create_monthcal_control(MCS_MULTISELECT);
1566 ok_sequence(sequences, PARENT_SEQ_INDEX, create_monthcal_multi_sel_style_seq, "create monthcal (multi sel style)", TRUE);
1567 DestroyWindow(hwnd);
1570 static void test_destroy(void)
1574 hwnd = create_monthcal_control(0);
1575 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1576 DestroyWindow(hwnd);
1577 ok_sequence(sequences, PARENT_SEQ_INDEX, destroy_monthcal_parent_msgs_seq, "Destroy monthcal (parent msg)", FALSE);
1578 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, destroy_monthcal_child_msgs_seq, "Destroy monthcal (child msg)", FALSE);
1580 /* MCS_MULTISELECT */
1581 hwnd = create_monthcal_control(MCS_MULTISELECT);
1582 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1583 DestroyWindow(hwnd);
1584 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, destroy_monthcal_multi_sel_style_seq, "Destroy monthcal (multi sel style)", FALSE);
1587 static void test_selrange(void)
1590 SYSTEMTIME st, range[2], range2[2];
1591 BOOL ret, old_comctl32 = FALSE;
1593 hwnd = create_monthcal_control(MCS_MULTISELECT);
1595 /* just after creation selection should start and end today */
1596 ret = SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&st);
1599 memset(range, 0xcc, sizeof(range));
1600 ret = SendMessage(hwnd, MCM_GETSELRANGE, 0, (LPARAM)range);
1602 expect(st.wYear, range[0].wYear);
1603 expect(st.wMonth, range[0].wMonth);
1604 expect(st.wDay, range[0].wDay);
1605 if (range[0].wDayOfWeek != st.wDayOfWeek)
1607 win_skip("comctl32 <= 4.70 doesn't set some values\n");
1608 old_comctl32 = TRUE;
1612 expect(st.wDayOfWeek, range[0].wDayOfWeek);
1613 expect(st.wHour, range[0].wHour);
1614 expect(st.wMinute, range[0].wMinute);
1615 expect(st.wSecond, range[0].wSecond);
1616 expect(st.wMilliseconds, range[0].wMilliseconds);
1619 expect(st.wYear, range[1].wYear);
1620 expect(st.wMonth, range[1].wMonth);
1621 expect(st.wDay, range[1].wDay);
1624 expect(st.wDayOfWeek, range[1].wDayOfWeek);
1625 expect(st.wHour, range[1].wHour);
1626 expect(st.wMinute, range[1].wMinute);
1627 expect(st.wSecond, range[1].wSecond);
1628 expect(st.wMilliseconds, range[1].wMilliseconds);
1631 /* bounds are swapped if min > max */
1632 memset(&range[0], 0, sizeof(range[0]));
1633 range[0].wYear = 2009;
1634 range[0].wMonth = 10;
1636 range[1] = range[0];
1639 ret = SendMessage(hwnd, MCM_SETSELRANGE, 0, (LPARAM)range);
1642 ret = SendMessage(hwnd, MCM_GETSELRANGE, 0, (LPARAM)range2);
1645 expect(range[1].wYear, range2[0].wYear);
1646 expect(range[1].wMonth, range2[0].wMonth);
1647 expect(range[1].wDay, range2[0].wDay);
1648 expect(6, range2[0].wDayOfWeek);
1649 expect(range[1].wHour, range2[0].wHour);
1650 expect(range[1].wMinute, range2[0].wMinute);
1651 expect(range[1].wSecond, range2[0].wSecond);
1652 expect(range[1].wMilliseconds, range2[0].wMilliseconds);
1654 expect(range[0].wYear, range2[1].wYear);
1655 expect(range[0].wMonth, range2[1].wMonth);
1656 expect(range[0].wDay, range2[1].wDay);
1657 expect(1, range2[1].wDayOfWeek);
1658 expect(range[0].wHour, range2[1].wHour);
1659 expect(range[0].wMinute, range2[1].wMinute);
1660 expect(range[0].wSecond, range2[1].wSecond);
1661 expect(range[0].wMilliseconds, range2[1].wMilliseconds);
1663 /* try with range larger than maximum configured */
1664 memset(&range[0], 0, sizeof(range[0]));
1665 range[0].wYear = 2009;
1666 range[0].wMonth = 10;
1668 range[1] = range[0];
1670 ret = SendMessage(hwnd, MCM_SETSELRANGE, 0, (LPARAM)range);
1673 range[1] = range[0];
1674 /* default max. range is 7 days */
1677 ret = SendMessage(hwnd, MCM_SETSELRANGE, 0, (LPARAM)range);
1680 ret = SendMessage(hwnd, MCM_GETSELRANGE, 0, (LPARAM)range2);
1683 expect(range[0].wYear, range2[0].wYear);
1684 expect(range[0].wMonth, range2[0].wMonth);
1685 expect(range[0].wDay, range2[0].wDay);
1686 expect(range[0].wYear, range2[1].wYear);
1687 expect(range[0].wMonth, range2[1].wMonth);
1688 expect(range[0].wDay, range2[1].wDay);
1690 DestroyWindow(hwnd);
1693 static void test_killfocus(void)
1698 hwnd = create_monthcal_control(0);
1700 /* make parent invisible */
1701 style = GetWindowLong(parent_wnd, GWL_STYLE);
1702 SetWindowLong(parent_wnd, GWL_STYLE, style &~ WS_VISIBLE);
1704 SendMessage(hwnd, WM_KILLFOCUS, (WPARAM)GetDesktopWindow(), 0);
1706 style = GetWindowLong(hwnd, GWL_STYLE);
1707 ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
1709 style = GetWindowLong(parent_wnd, GWL_STYLE);
1710 SetWindowLong(parent_wnd, GWL_STYLE, style | WS_VISIBLE);
1712 DestroyWindow(hwnd);
1715 static void test_hittest_v6(void)
1717 MCHITTESTINFO mchit;
1722 hwnd = create_monthcal_control(0);
1723 SendMessage(hwnd, MCM_SETCALENDARBORDER, TRUE, 0);
1725 SendMessage(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r);
1726 /* reserving some area around calendar */
1727 MoveWindow(hwnd, 0, 0, r.right * 3 / 2, r.bottom * 3 / 2, FALSE);
1728 mchit.cbSize = sizeof(MCHITTESTINFO);
1729 mchit.pt.x = mchit.pt.y = 0;
1733 ret = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1736 win_skip("Only MCHITTESTINFO_V1 supported\n");
1737 DestroyWindow(hwnd);
1740 todo_wine expect_hex(MCHT_NOWHERE, ret);
1741 expect(-1, mchit.iOffset);
1742 expect(-1, mchit.iRow);
1743 expect(-1, mchit.iCol);
1745 MoveWindow(hwnd, 0, 0, r.right, r.bottom, FALSE);
1746 mchit.pt.x = r.right / 2;
1747 mchit.pt.y = r.bottom / 2;
1749 ret = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1750 expect_hex(MCHT_CALENDARDATE, ret);
1751 expect(0, mchit.iOffset);
1754 mchit.pt.x = r.right / (7*2);
1755 mchit.pt.y = r.bottom / 2;
1757 mchit.iCol = mchit.iRow = -1;
1759 mchit.rc.left = mchit.rc.right = mchit.rc.top = mchit.rc.bottom = -1;
1760 ret = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1761 expect_hex(MCHT_CALENDARDATE, ret);
1762 expect_hex(MCHT_CALENDARDATE, mchit.uHit);
1763 expect(0, mchit.iOffset);
1764 expect(2, mchit.iRow);
1765 expect(0, mchit.iCol);
1766 /* returned a one day rectangle */
1767 expect_d(r.right / 7, mchit.rc.right - mchit.rc.left);
1768 expect_d(r.bottom / 10, mchit.rc.bottom - mchit.rc.top);
1774 mchit.iCol = mchit.iRow = -1;
1776 mchit.rc.left = mchit.rc.right = mchit.rc.top = mchit.rc.bottom = -1;
1777 ret = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1778 expect_hex(MCHT_TITLE, ret);
1779 expect_hex(MCHT_TITLE, mchit.uHit);
1780 expect(0, mchit.iOffset);
1781 expect(-1, mchit.iRow);
1782 expect(-1, mchit.iCol);
1783 expect(0, mchit.rc.left);
1784 expect(0, mchit.rc.top);
1785 expect_d(r.right, mchit.rc.right);
1786 ok(mchit.rc.bottom > 0, "got %d\n", mchit.rc.bottom);
1788 /* between two calendars */
1789 MoveWindow(hwnd, 0, 0, r.right * 5/2, r.bottom, FALSE);
1790 mchit.pt.x = r.right / (5*4);
1791 mchit.pt.y = r.bottom / 2;
1793 mchit.iCol = mchit.iRow = -2;
1795 mchit.rc.left = mchit.rc.right = mchit.rc.top = mchit.rc.bottom = -1;
1796 ret = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1797 todo_wine expect_hex(MCHT_NOWHERE, ret);
1798 todo_wine expect_hex(MCHT_NOWHERE, mchit.uHit);
1799 expect(-2, mchit.iOffset);
1800 expect(-2, mchit.iRow);
1801 expect(-2, mchit.iCol);
1802 todo_wine expect(0, mchit.rc.left);
1803 todo_wine expect(0, mchit.rc.top);
1804 todo_wine expect_d(r.right * 5/2, mchit.rc.right);
1805 todo_wine expect_d(r.bottom, mchit.rc.bottom);
1807 DestroyWindow(hwnd);
1810 static void test_get_set_border(void)
1815 hwnd = create_monthcal_control(0);
1817 /* a non-default value */
1818 ret = SendMessage(hwnd, MCM_SETCALENDARBORDER, TRUE, 10);
1821 ret = SendMessage(hwnd, MCM_GETCALENDARBORDER, 0, 0);
1825 skip("MCM_GET/SETCALENDARBORDER not supported\n");
1826 DestroyWindow(hwnd);
1832 DestroyWindow(hwnd);
1835 static void test_MCM_SIZERECTTOMIN(void)
1841 hwnd = create_monthcal_control(0);
1843 ret = SendMessageA(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r2);
1846 win_skip("Message MCM_GETMINREQRECT unsupported. Skipping.\n");
1847 DestroyWindow(hwnd);
1851 ret = SendMessageA(hwnd, MCM_SIZERECTTOMIN, 0, 0);
1852 ok(ret == 0, "got %d\n", ret);
1854 r.left = r.right = r.top = r.bottom = 0;
1855 ret = SendMessageA(hwnd, MCM_SIZERECTTOMIN, 0, (LPARAM)&r);
1858 skip("Message MCM_SIZERECTTOMIN unsupported. Skipping.\n");
1859 DestroyWindow(hwnd);
1862 ok(ret == 1, "got %d\n", ret);
1863 ok(r.left == 0 && r.right > 0, "got %d, %d\n", r.left, r.right);
1866 ret = SendMessageA(hwnd, MCM_SIZERECTTOMIN, 0, (LPARAM)&r);
1867 ok(ret == 1, "got %d\n", ret);
1869 r2.right = (r2.right - r2.left) * 3;
1870 r2.bottom = (r2.bottom - r2.top) * 3;
1871 r2.left = r2.top = 0;
1872 ret = SendMessageA(hwnd, MCM_SIZERECTTOMIN, 0, (LPARAM)&r2);
1873 ok(ret == 1, "got %d\n", ret);
1875 DestroyWindow(hwnd);
1878 static void test_MCM_GETCALENDARCOUNT(void)
1883 hwnd = create_monthcal_control(0);
1885 ret = SendMessageA(hwnd, MCM_GETCALENDARCOUNT, 0, 0);
1888 win_skip("Message MCM_GETCALENDARCOUNT unsupported. Skipping.\n");
1889 DestroyWindow(hwnd);
1895 DestroyWindow(hwnd);
1898 static void test_daystate(void)
1900 MONTHDAYSTATE state[4];
1905 /* without MCS_DAYSTATE */
1906 hwnd = create_monthcal_control(0);
1908 ret = SendMessage(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r);
1911 /* resize control to display two Calendars */
1912 MoveWindow(hwnd, 0, 0, r.right, (5/2)*r.bottom, FALSE);
1914 ret = SendMessageA(hwnd, MCM_GETMONTHRANGE, GMR_DAYSTATE, 0);
1917 ret = SendMessageA(hwnd, MCM_SETDAYSTATE, 4, (LPARAM)&state);
1920 ret = SendMessageA(hwnd, MCM_SETDAYSTATE, 2, (LPARAM)&state);
1923 ret = SendMessageA(hwnd, MCM_SETDAYSTATE, 0, 0);
1926 /* try to switch on */
1927 SetWindowLongA(hwnd, GWL_STYLE, GetWindowLongA(hwnd, GWL_STYLE) | MCS_DAYSTATE);
1928 style = GetWindowLongA(hwnd, GWL_STYLE);
1929 ok((style & MCS_DAYSTATE) == 0, "got 0x%08x\n", style);
1931 DestroyWindow(hwnd);
1933 /* with MCS_DAYSTATE */
1934 hwnd = create_monthcal_control(MCS_DAYSTATE);
1936 ret = SendMessageA(hwnd, MCM_GETMONTHRANGE, GMR_DAYSTATE, 0);
1939 ret = SendMessageA(hwnd, MCM_SETDAYSTATE, 4, (LPARAM)&state);
1942 ret = SendMessageA(hwnd, MCM_SETDAYSTATE, 2, (LPARAM)&state);
1945 ret = SendMessageA(hwnd, MCM_SETDAYSTATE, 0, 0);
1948 /* try to switch off */
1949 SetWindowLongA(hwnd, GWL_STYLE, GetWindowLongA(hwnd, GWL_STYLE) & ~MCS_DAYSTATE);
1950 style = GetWindowLongA(hwnd, GWL_STYLE);
1951 ok((style & MCS_DAYSTATE) == MCS_DAYSTATE, "got 0x%08x\n", style);
1953 DestroyWindow(hwnd);
1956 static void test_sel_notify(void)
1966 MCHITTESTINFO mchit = {sizeof(MCHITTESTINFO)};
1968 Monthcal_style styles[] = {
1969 {MCS_NOTODAY, "MCS_NOTODAY"},
1970 {MCS_NOTODAY | MCS_MULTISELECT, "MCS_NOTODAY | MCS_MULTISELECT"},
1971 {MCS_DAYSTATE, "MCS_DAYSTATE"},
1972 {MCS_DAYSTATE | MCS_MULTISELECT, "MCS_DAYSTATE | MCS_MULTISELECT"}
1976 for(i = 0; i < sizeof styles / sizeof styles[0]; i++)
1978 trace("%s\n", styles[i].name);
1979 hwnd = create_monthcal_control(styles[i].val);
1980 SetWindowLongPtr(hwnd, GWLP_ID, SEL_NOTIFY_TEST_ID);
1982 SendMessage(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&rc);
1983 MoveWindow(hwnd, 0, 0, rc.right, rc.bottom, FALSE);
1984 /* Simulate mouse click on some unselected day to generate
1985 MCN_SELECT and MCN_SELCHANGE notifications */
1986 mchit.pt.x = rc.right / 2;
1987 mchit.pt.y = rc.bottom / 2;
1988 SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1989 SendMessage(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st);
1990 while(st.wDay == mchit.st.wDay) /* Ensure that mchit.pt points to unselected day */
1993 SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1995 SendMessage(hwnd, WM_LBUTTONDOWN, 0, MAKELPARAM(mchit.pt.x, mchit.pt.y));
1996 SendMessage(hwnd, WM_LBUTTONUP, 0, MAKELPARAM(mchit.pt.x, mchit.pt.y));
1997 DestroyWindow(hwnd);
2001 START_TEST(monthcal)
2003 BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
2004 INITCOMMONCONTROLSEX iccex;
2008 ULONG_PTR ctx_cookie;
2011 hComctl32 = GetModuleHandleA("comctl32.dll");
2012 pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
2013 if (!pInitCommonControlsEx)
2015 skip("InitCommonControlsEx() is missing. Skipping the tests\n");
2018 iccex.dwSize = sizeof(iccex);
2019 iccex.dwICC = ICC_DATE_CLASSES;
2020 pInitCommonControlsEx(&iccex);
2024 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
2026 parent_wnd = create_parent_window();
2046 if (!load_v6_module(&ctx_cookie, &hCtx))
2048 DestroyWindow(parent_wnd);
2052 /* this is a XP SP3 failure workaround */
2053 hwnd = CreateWindowExA(0, MONTHCAL_CLASSA, "foo",
2054 WS_CHILD | WS_BORDER | WS_VISIBLE,
2056 parent_wnd, NULL, GetModuleHandleA(NULL), NULL);
2057 if (!IsWindow(hwnd))
2059 win_skip("FIXME: failed to create Monthcal window.\n");
2060 unload_v6_module(ctx_cookie, hCtx);
2061 DestroyWindow(parent_wnd);
2065 DestroyWindow(hwnd);
2068 test_get_set_border();
2069 test_MCM_SIZERECTTOMIN();
2070 test_MCM_GETCALENDARCOUNT();
2072 unload_v6_module(ctx_cookie, hCtx);
2074 DestroyWindow(parent_wnd);