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"
35 #define expect(expected,got) expect_(__LINE__, expected, got)
36 static inline void expect_(unsigned line
, DWORD expected
, DWORD got
)
38 ok_(__FILE__
, line
)(expected
== got
, "Expected %ld, got %ld\n", expected
, got
);
41 #define expect_hex(expected,got) expect_hex_(__LINE__, expected, got)
42 static inline void expect_hex_(unsigned line
, DWORD expected
, DWORD got
)
44 ok_(__FILE__
, line
)(expected
== got
, "Expected %lx, got %lx\n", expected
, got
);
46 #define expect_d(expected, got) ok(abs((expected) - (got)) <= 2, "Expected %ld, got %ld\n", expected, got);
48 #define NUM_MSG_SEQUENCES 2
49 #define PARENT_SEQ_INDEX 0
50 #define MONTHCAL_SEQ_INDEX 1
52 #define SEL_NOTIFY_TEST_ID 100
54 static BOOL (WINAPI
*pInitCommonControlsEx
)(const INITCOMMONCONTROLSEX
*);
56 static struct msg_sequence
*sequences
[NUM_MSG_SEQUENCES
];
58 static HWND parent_wnd
;
59 static BOOL got_MCN_SELECT
, got_MCN_SELCHANGE
;
61 static const struct message create_parent_window_seq
[] = {
62 { WM_GETMINMAXINFO
, sent
},
63 { WM_NCCREATE
, sent
},
64 { WM_NCCALCSIZE
, sent
|wparam
, 0 },
66 { WM_SHOWWINDOW
, sent
|wparam
, 1 },
67 { WM_WINDOWPOSCHANGING
, sent
|wparam
, 0 },
68 { WM_QUERYNEWPALETTE
, sent
|optional
},
69 { WM_WINDOWPOSCHANGING
, sent
|wparam
|optional
, 0 },
70 { WM_WINDOWPOSCHANGED
, sent
|optional
},
71 { WM_ACTIVATEAPP
, sent
|wparam
, 1 },
72 { WM_NCACTIVATE
, sent
},
73 { WM_ACTIVATE
, sent
|wparam
, 1 },
74 { WM_SETFOCUS
, sent
|wparam
|defwinproc
, 0 },
75 /* Win9x adds SWP_NOZORDER below */
76 { WM_WINDOWPOSCHANGED
, sent
, /*|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ },
77 { WM_NCCALCSIZE
, sent
|wparam
|optional
, 1 },
83 static const struct message create_monthcal_control_seq
[] = {
84 { WM_NOTIFYFORMAT
, sent
|lparam
, 0, NF_QUERY
},
85 { WM_QUERYUISTATE
, sent
|optional
},
87 { WM_PARENTNOTIFY
, sent
|wparam
, WM_CREATE
},
91 static const struct message create_monthcal_multi_sel_style_seq
[] = {
92 { WM_NOTIFYFORMAT
, sent
|lparam
, 0, NF_QUERY
},
93 { WM_QUERYUISTATE
, sent
|optional
},
95 { WM_PARENTNOTIFY
, sent
},
99 static const struct message monthcal_curr_date_seq
[] = {
100 { MCM_SETCURSEL
, sent
|wparam
, 0},
101 { WM_PAINT
, sent
|wparam
|lparam
|defwinproc
, 0, 0},
102 { MCM_SETCURSEL
, sent
|wparam
, 0},
103 { MCM_SETCURSEL
, sent
|wparam
, 0},
104 { MCM_GETCURSEL
, sent
|wparam
, 0},
105 { MCM_GETCURSEL
, sent
|wparam
|lparam
, 0, 0},
109 static const struct message monthcal_first_day_seq
[] = {
110 { MCM_GETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 0},
112 { MCM_SETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, -5},
113 { MCM_GETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 0},
115 { MCM_SETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, -4},
116 { MCM_GETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 0},
118 { MCM_SETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, -3},
119 { MCM_GETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 0},
121 { MCM_SETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, -2},
122 { MCM_GETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 0},
124 { MCM_SETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, -1},
125 { MCM_GETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 0},
127 { MCM_SETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 0},
128 { MCM_GETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 0},
130 { MCM_SETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 1},
131 { MCM_GETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 0},
133 { MCM_SETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 2},
134 { MCM_GETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 0},
136 { MCM_SETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 3},
137 { MCM_GETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 0},
139 { MCM_SETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 4},
140 { MCM_GETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 0},
142 { MCM_SETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 5},
143 { MCM_GETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 0},
145 { MCM_SETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 6},
146 { MCM_GETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 0},
148 { MCM_SETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 7},
149 { MCM_GETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 0},
151 { MCM_SETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 8},
152 { MCM_GETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 0},
154 { MCM_SETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 9},
155 { MCM_GETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 0},
157 { MCM_SETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 10},
158 { MCM_GETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 0},
160 { MCM_SETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 11},
161 { MCM_GETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 0},
165 static const struct message monthcal_unicode_seq
[] = {
166 { MCM_GETUNICODEFORMAT
, sent
|wparam
|lparam
, 0, 0},
167 { MCM_SETUNICODEFORMAT
, sent
|wparam
|lparam
, 1, 0},
168 { MCM_GETUNICODEFORMAT
, sent
|wparam
|lparam
, 0, 0},
169 { MCM_SETUNICODEFORMAT
, sent
|wparam
|lparam
, 0, 0},
170 { MCM_GETUNICODEFORMAT
, sent
|wparam
|lparam
, 0, 0},
171 { MCM_SETUNICODEFORMAT
, sent
|wparam
|lparam
, 1, 0},
175 static const struct message monthcal_hit_test_seq
[] = {
176 { MCM_SETCURSEL
, sent
|wparam
, 0},
177 { WM_PAINT
, sent
|wparam
|lparam
|defwinproc
, 0, 0},
178 { MCM_HITTEST
, sent
|wparam
, 0},
179 { MCM_HITTEST
, sent
|wparam
, 0},
180 { MCM_HITTEST
, sent
|wparam
, 0},
181 { MCM_HITTEST
, sent
|wparam
, 0},
182 { MCM_HITTEST
, sent
|wparam
, 0},
183 { MCM_HITTEST
, sent
|wparam
, 0},
184 { MCM_HITTEST
, sent
|wparam
, 0},
185 { MCM_HITTEST
, sent
|wparam
, 0},
186 { MCM_HITTEST
, sent
|wparam
, 0},
187 { MCM_HITTEST
, sent
|wparam
, 0},
191 static const struct message monthcal_todaylink_seq
[] = {
192 { MCM_HITTEST
, sent
|wparam
, 0},
193 { MCM_SETTODAY
, sent
|wparam
, 0},
194 { WM_PAINT
, sent
|wparam
|lparam
|defwinproc
, 0, 0},
195 { MCM_GETTODAY
, sent
|wparam
, 0},
196 { WM_LBUTTONDOWN
, sent
|wparam
, MK_LBUTTON
},
197 { WM_CAPTURECHANGED
, sent
|wparam
|lparam
|defwinproc
, 0, 0},
198 { WM_PAINT
, sent
|wparam
|lparam
|defwinproc
, 0, 0},
199 { MCM_GETCURSEL
, sent
|wparam
, 0},
203 static const struct message monthcal_today_seq
[] = {
204 { MCM_SETTODAY
, sent
|wparam
, 0},
205 { WM_PAINT
, sent
|wparam
|lparam
|defwinproc
, 0, 0},
206 { MCM_GETTODAY
, sent
|wparam
, 0},
207 { MCM_SETTODAY
, sent
|wparam
, 0},
208 { WM_PAINT
, sent
|wparam
|lparam
|defwinproc
, 0, 0},
209 { MCM_GETTODAY
, sent
|wparam
, 0},
213 static const struct message monthcal_scroll_seq
[] = {
214 { MCM_SETMONTHDELTA
, sent
|wparam
|lparam
, 2, 0},
215 { MCM_SETMONTHDELTA
, sent
|wparam
|lparam
, 3, 0},
216 { MCM_GETMONTHDELTA
, sent
|wparam
|lparam
, 0, 0},
217 { MCM_SETMONTHDELTA
, sent
|wparam
|lparam
, 12, 0},
218 { MCM_GETMONTHDELTA
, sent
|wparam
|lparam
, 0, 0},
219 { MCM_SETMONTHDELTA
, sent
|wparam
|lparam
, 15, 0},
220 { MCM_GETMONTHDELTA
, sent
|wparam
|lparam
, 0, 0},
221 { MCM_SETMONTHDELTA
, sent
|wparam
|lparam
, -5, 0},
222 { MCM_GETMONTHDELTA
, sent
|wparam
|lparam
, 0, 0},
226 static const struct message monthcal_monthrange_seq
[] = {
227 { MCM_GETMONTHRANGE
, sent
|wparam
, GMR_VISIBLE
},
228 { MCM_GETMONTHRANGE
, sent
|wparam
, GMR_DAYSTATE
},
232 static const struct message monthcal_max_sel_day_seq
[] = {
233 { MCM_SETMAXSELCOUNT
, sent
|wparam
|lparam
, 5, 0},
234 { MCM_GETMAXSELCOUNT
, sent
|wparam
|lparam
, 0, 0},
235 { MCM_SETMAXSELCOUNT
, sent
|wparam
|lparam
, 15, 0},
236 { MCM_GETMAXSELCOUNT
, sent
|wparam
|lparam
, 0, 0},
237 { MCM_SETMAXSELCOUNT
, sent
|wparam
|lparam
, -1, 0},
238 { MCM_GETMAXSELCOUNT
, sent
|wparam
|lparam
, 0, 0},
242 /* expected message sequence for parent*/
243 static const struct message destroy_monthcal_parent_msgs_seq
[] = {
244 { WM_PARENTNOTIFY
, sent
|wparam
, WM_DESTROY
},
248 /* expected message sequence for child*/
249 static const struct message destroy_monthcal_child_msgs_seq
[] = {
250 { 0x0090, sent
|optional
}, /* Vista */
251 { WM_SHOWWINDOW
, sent
|wparam
|lparam
, 0, 0},
252 { WM_WINDOWPOSCHANGING
, sent
|wparam
, 0},
253 { WM_WINDOWPOSCHANGED
, sent
|wparam
, 0},
254 { WM_DESTROY
, sent
|wparam
|lparam
, 0, 0},
255 { WM_NCDESTROY
, sent
|wparam
|lparam
, 0, 0},
259 static const struct message destroy_monthcal_multi_sel_style_seq
[] = {
260 { 0x0090, sent
|optional
}, /* Vista */
261 { WM_SHOWWINDOW
, sent
|wparam
|lparam
, 0, 0},
262 { WM_WINDOWPOSCHANGING
, sent
|wparam
, 0},
263 { WM_WINDOWPOSCHANGED
, sent
|wparam
, 0},
264 { WM_DESTROY
, sent
|wparam
|lparam
, 0, 0},
265 { WM_NCDESTROY
, sent
|wparam
|lparam
, 0, 0},
269 static void test_monthcal(void)
272 SYSTEMTIME st
[2], st1
[2], today
;
273 int res
, month_range
;
277 hwnd
= CreateWindowA(MONTHCAL_CLASSA
, "MonthCal", WS_POPUP
| WS_VISIBLE
, CW_USEDEFAULT
,
278 0, 300, 300, 0, 0, NULL
, NULL
);
279 ok(hwnd
!= NULL
, "Failed to create MonthCal\n");
281 /* test range just after creation */
282 memset(&st
, 0xcc, sizeof(st
));
283 limits
= SendMessageA(hwnd
, MCM_GETRANGE
, 0, (LPARAM
)st
);
285 broken(limits
== GDTR_MIN
), /* comctl32 <= 4.70 */
286 "No limits should be set (%ld)\n", limits
);
287 if (limits
== GDTR_MIN
)
289 win_skip("comctl32 <= 4.70 is broken\n");
294 ok(0 == st
[0].wYear
||
295 broken(1752 == st
[0].wYear
), /* comctl32 <= 4.72 */
296 "Expected 0, got %d\n", st
[0].wYear
);
297 ok(0 == st
[0].wMonth
||
298 broken(9 == st
[0].wMonth
), /* comctl32 <= 4.72 */
299 "Expected 0, got %d\n", st
[0].wMonth
);
300 ok(0 == st
[0].wDay
||
301 broken(14 == st
[0].wDay
), /* comctl32 <= 4.72 */
302 "Expected 0, got %d\n", st
[0].wDay
);
303 expect(0, st
[0].wDayOfWeek
);
304 expect(0, st
[0].wHour
);
305 expect(0, st
[0].wMinute
);
306 expect(0, st
[0].wSecond
);
307 expect(0, st
[0].wMilliseconds
);
309 expect(0, st
[1].wYear
);
310 expect(0, st
[1].wMonth
);
311 expect(0, st
[1].wDay
);
312 expect(0, st
[1].wDayOfWeek
);
313 expect(0, st
[1].wHour
);
314 expect(0, st
[1].wMinute
);
315 expect(0, st
[1].wSecond
);
316 expect(0, st
[1].wMilliseconds
);
318 limits
= SendMessageA(hwnd
, MCM_GETRANGE
, 0, 0);
319 ok(limits
== 0, "got %lu\n", limits
);
321 GetSystemTime(&st
[0]);
324 SendMessageA(hwnd
, MCM_GETTODAY
, 0, (LPARAM
)&today
);
326 /* Invalid date/time */
328 /* Time should not matter */
329 st
[1].wHour
= st
[1].wMinute
= st
[1].wSecond
= 70;
330 st
[1].wMilliseconds
= 1200;
331 ok(SendMessageA(hwnd
, MCM_SETRANGE
, GDTR_MAX
, (LPARAM
)st
), "Failed to set MAX limit\n");
332 /* invalid timestamp is written back with today data and msecs untouched */
333 expect(today
.wHour
, st
[1].wHour
);
334 expect(today
.wMinute
, st
[1].wMinute
);
335 expect(today
.wSecond
, st
[1].wSecond
);
336 expect(1200, st
[1].wMilliseconds
);
338 ok(SendMessageA(hwnd
, MCM_GETRANGE
, 0, (LPARAM
)st1
) == GDTR_MAX
, "No limits should be set\n");
339 ok(st1
[0].wYear
!= 2000, "Lower limit changed\n");
340 /* invalid timestamp should be replaced with today data, except msecs */
341 expect(today
.wHour
, st1
[1].wHour
);
342 expect(today
.wMinute
, st1
[1].wMinute
);
343 expect(today
.wSecond
, st1
[1].wSecond
);
344 expect(1200, st1
[1].wMilliseconds
);
346 /* Invalid date/time with invalid milliseconds only */
347 GetSystemTime(&st
[0]);
349 /* Time should not matter */
350 st
[1].wMilliseconds
= 1200;
351 ok(SendMessageA(hwnd
, MCM_SETRANGE
, GDTR_MAX
, (LPARAM
)st
), "Failed to set MAX limit\n");
352 /* invalid milliseconds field doesn't lead to invalid timestamp */
353 expect(st
[0].wHour
, st
[1].wHour
);
354 expect(st
[0].wMinute
, st
[1].wMinute
);
355 expect(st
[0].wSecond
, st
[1].wSecond
);
356 expect(1200, st
[1].wMilliseconds
);
358 GetSystemTime(&st
[0]);
361 ok(!SendMessageA(hwnd
, MCM_SETRANGE
, GDTR_MIN
| GDTR_MAX
, (LPARAM
)st
),
362 "Should have failed to set limits\n");
363 ok(SendMessageA(hwnd
, MCM_GETRANGE
, 0, (LPARAM
)st1
) == GDTR_MAX
, "No limits should be set\n");
364 ok(st1
[0].wYear
!= 2000, "Lower limit changed\n");
365 ok(!SendMessageA(hwnd
, MCM_SETRANGE
, GDTR_MAX
, (LPARAM
)st
),
366 "Should have failed to set MAX limit\n");
367 ok(SendMessageA(hwnd
, MCM_GETRANGE
, 0, (LPARAM
)st1
) == GDTR_MAX
, "No limits should be set\n");
368 ok(st1
[0].wYear
!= 2000, "Lower limit changed\n");
370 GetSystemTime(&st
[0]);
375 month_range
= SendMessageA(hwnd
, MCM_GETMONTHRANGE
, GMR_VISIBLE
, (LPARAM
)st1
);
377 ok(SendMessageA(hwnd
, MCM_SETRANGE
, GDTR_MIN
| GDTR_MAX
, (LPARAM
)st
),
378 "Failed to set both min and max limits\n");
379 res
= SendMessageA(hwnd
, MCM_GETMONTHRANGE
, GMR_VISIBLE
, (LPARAM
)st1
);
380 ok(res
== month_range
, "Invalid month range (%d)\n", res
);
381 ok(SendMessageA(hwnd
, MCM_GETRANGE
, 0, (LPARAM
)st1
) == (GDTR_MIN
|GDTR_MAX
),
382 "Limits should be set\n");
385 ok(SendMessageA(hwnd
, MCM_SETRANGE
, GDTR_MIN
| GDTR_MAX
, (LPARAM
)st
),
386 "Failed to set both min and max limits\n");
387 res
= SendMessageA(hwnd
, MCM_GETMONTHRANGE
, GMR_VISIBLE
, (LPARAM
)st1
);
388 ok(res
== month_range
, "Invalid month range (%d)\n", res
);
391 ok(SendMessageA(hwnd
, MCM_SETRANGE
, GDTR_MIN
| GDTR_MAX
, (LPARAM
)st
),
392 "Failed to set both min and max limits\n");
394 ok(SendMessageA(hwnd
, MCM_SETRANGE
, GDTR_MIN
| GDTR_MAX
, (LPARAM
)st
),
395 "Failed to set both min and max limits\n");
398 ok(SendMessageA(hwnd
, MCM_SETRANGE
, GDTR_MAX
, (LPARAM
)st
), "Failed to set max limit\n");
399 ok(SendMessageA(hwnd
, MCM_GETRANGE
, 0, (LPARAM
)st1
) == GDTR_MAX
,
400 "Only MAX limit should be set\n");
402 ok(SendMessageA(hwnd
, MCM_SETRANGE
, GDTR_MAX
, (LPARAM
)st
), "Failed to set max limit\n");
404 ok(SendMessageA(hwnd
, MCM_SETRANGE
, GDTR_MAX
, (LPARAM
)st
), "Failed to set max limit\n");
406 ok(SendMessageA(hwnd
, MCM_SETRANGE
, GDTR_MAX
, (LPARAM
)st
), "Failed to set max limit\n");
407 ok(SendMessageA(hwnd
, MCM_GETRANGE
, 0, (LPARAM
)st1
) == GDTR_MAX
,
408 "Only MAX limit should be set\n");
410 /* set both limits, then set max < min */
411 GetSystemTime(&st
[0]);
415 ok(SendMessageA(hwnd
, MCM_SETRANGE
, GDTR_MIN
|GDTR_MAX
, (LPARAM
)st
), "Failed to set limits\n");
416 ok(SendMessageA(hwnd
, MCM_GETRANGE
, 0, (LPARAM
)st1
) == (GDTR_MIN
|GDTR_MAX
),
417 "Min limit expected\n");
419 ok(SendMessageA(hwnd
, MCM_SETRANGE
, GDTR_MAX
, (LPARAM
)st
), "Failed to set limits\n");
420 ok(SendMessageA(hwnd
, MCM_GETRANGE
, 0, (LPARAM
)st1
) == GDTR_MAX
, "Max limit expected\n");
422 expect(0, st1
[0].wYear
);
423 expect(0, st1
[0].wMonth
);
424 expect(0, st1
[0].wDay
);
425 expect(0, st1
[0].wDayOfWeek
);
426 expect(0, st1
[0].wHour
);
427 expect(0, st1
[0].wMinute
);
428 expect(0, st1
[0].wSecond
);
429 expect(0, st1
[0].wMilliseconds
);
431 expect(st
[1].wYear
, st1
[1].wYear
);
432 expect(st
[1].wMonth
, st1
[1].wMonth
);
433 expect(st
[1].wDay
, st1
[1].wDay
);
434 expect(st
[1].wDayOfWeek
, st1
[1].wDayOfWeek
);
435 expect(st
[1].wHour
, st1
[1].wHour
);
436 expect(st
[1].wMinute
, st1
[1].wMinute
);
437 expect(st
[1].wSecond
, st1
[1].wSecond
);
438 expect(st
[1].wMilliseconds
, st1
[1].wMilliseconds
);
442 ok(SendMessageA(hwnd
, MCM_SETRANGE
, GDTR_MIN
|GDTR_MAX
, (LPARAM
)st
), "Failed to set limits\n");
443 ok(SendMessageA(hwnd
, MCM_GETRANGE
, 0, (LPARAM
)st1
) == (GDTR_MIN
|GDTR_MAX
),
444 "Min limit expected\n");
445 st
[0].wYear
++; /* start == end now */
446 ok(SendMessageA(hwnd
, MCM_SETRANGE
, GDTR_MIN
, (LPARAM
)st
), "Failed to set limits\n");
447 ok(SendMessageA(hwnd
, MCM_GETRANGE
, 0, (LPARAM
)st1
) == GDTR_MIN
, "Min limit expected\n");
449 expect(st
[0].wYear
, st1
[0].wYear
);
450 expect(st
[0].wMonth
, st1
[0].wMonth
);
451 expect(st
[0].wDay
, st1
[0].wDay
);
452 expect(st
[0].wDayOfWeek
, st1
[0].wDayOfWeek
);
453 expect(st
[0].wHour
, st1
[0].wHour
);
454 expect(st
[0].wMinute
, st1
[0].wMinute
);
455 expect(st
[0].wSecond
, st1
[0].wSecond
);
456 expect(st
[0].wMilliseconds
, st1
[0].wMilliseconds
);
458 expect(0, st1
[1].wYear
);
459 expect(0, st1
[1].wMonth
);
460 expect(0, st1
[1].wDay
);
461 expect(0, st1
[1].wDayOfWeek
);
462 expect(0, st1
[1].wHour
);
463 expect(0, st1
[1].wMinute
);
464 expect(0, st1
[1].wSecond
);
465 expect(0, st1
[1].wMilliseconds
);
468 limits
= SendMessageA(hwnd
, MCM_GETRANGE
, 0, (LPARAM
)st1
);
469 ok(limits
== GDTR_MIN
, "got 0x%08lx\n", limits
);
474 r
= SendMessageA(hwnd
, MCM_SETRANGE
, 0, (LPARAM
)st
);
475 ok(r
, "got %d\n", r
);
477 limits
= SendMessageA(hwnd
, MCM_GETRANGE
, 0, (LPARAM
)st
);
478 ok(limits
== 0, "got 0x%08lx\n", limits
);
479 ok(st
[0].wYear
== 0 && st
[1].wYear
== 0, "got %u, %u\n", st
[0].wYear
, st
[1].wYear
);
481 /* flags are 0, set min limit */
486 r
= SendMessageA(hwnd
, MCM_SETRANGE
, GDTR_MIN
, (LPARAM
)st
);
487 ok(r
, "got %d\n", r
);
489 limits
= SendMessageA(hwnd
, MCM_GETRANGE
, 0, (LPARAM
)st1
);
490 ok(limits
== GDTR_MIN
, "got 0x%08lx\n", limits
);
491 ok(st1
[1].wYear
== 0, "got %u\n", st1
[1].wYear
);
493 /* now set max limit, check flags */
494 r
= SendMessageA(hwnd
, MCM_SETRANGE
, GDTR_MAX
, (LPARAM
)st
);
495 ok(r
, "got %d\n", r
);
497 limits
= SendMessageA(hwnd
, MCM_GETRANGE
, 0, (LPARAM
)st1
);
498 ok(limits
== GDTR_MAX
, "got 0x%08lx\n", limits
);
499 ok(st1
[0].wYear
== 0, "got %u\n", st1
[0].wYear
);
504 static LRESULT WINAPI
parent_wnd_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
506 static LONG defwndproc_counter
= 0;
510 /* log system messages, except for painting */
511 if (message
< WM_USER
&&
512 message
!= WM_PAINT
&&
513 message
!= WM_ERASEBKGND
&&
514 message
!= WM_NCPAINT
&&
515 message
!= WM_NCHITTEST
&&
516 message
!= WM_GETTEXT
&&
517 message
!= WM_GETICON
&&
518 message
!= WM_DEVICECHANGE
&&
519 message
!= WM_IME_SETCONTEXT
&&
520 message
!= WM_IME_NOTIFY
)
522 msg
.message
= message
;
523 msg
.flags
= sent
|wparam
|lparam
;
524 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
527 add_message(sequences
, PARENT_SEQ_INDEX
, &msg
);
530 if (message
== WM_NOTIFY
)
532 NMHDR
*hdr
= (NMHDR
*)lParam
;
535 case MCN_GETDAYSTATE
:
537 NMDAYSTATE
*nmstate
= (NMDAYSTATE
*)lParam
;
538 static MONTHDAYSTATE months
[14] = { 0 };
540 ok(nmstate
->cDayState
> 0, "got %d\n", nmstate
->cDayState
);
541 ok(nmstate
->cDayState
<= 14, "got %d\n", nmstate
->cDayState
);
542 ok(nmstate
->prgDayState
!= NULL
, "got %p\n", nmstate
->prgDayState
);
544 nmstate
->prgDayState
= months
;
551 NMSELCHANGE
*nmchg
= (NMSELCHANGE
*)lParam
;
553 BOOL is_multisel
= GetWindowLongPtrA(nmchg
->nmhdr
.hwndFrom
, GWL_STYLE
) & MCS_MULTISELECT
;
555 if(GetWindowLongPtrA(nmchg
->nmhdr
.hwndFrom
, GWLP_ID
) != SEL_NOTIFY_TEST_ID
)
558 if (hdr
->code
== MCN_SELECT
)
559 got_MCN_SELECT
= TRUE
;
561 got_MCN_SELCHANGE
= TRUE
;
563 SendMessageA(nmchg
->nmhdr
.hwndFrom
, is_multisel
? MCM_GETSELRANGE
: MCM_GETCURSEL
,
566 expect(st
[0].wYear
, nmchg
->stSelStart
.wYear
);
567 expect(st
[0].wMonth
, nmchg
->stSelStart
.wMonth
);
568 expect(0, nmchg
->stSelStart
.wDayOfWeek
);
569 expect(st
[0].wDay
, nmchg
->stSelStart
.wDay
);
573 expect(st
[1].wYear
, nmchg
->stSelEnd
.wYear
);
574 expect(st
[1].wMonth
, nmchg
->stSelEnd
.wMonth
);
575 expect(0, nmchg
->stSelEnd
.wDayOfWeek
);
576 expect(st
[1].wDay
, nmchg
->stSelEnd
.wDay
);
579 ok(!(nmchg
->stSelEnd
.wYear
| nmchg
->stSelEnd
.wMonth
|
580 nmchg
->stSelEnd
.wDayOfWeek
| nmchg
->stSelEnd
.wDay
|
581 nmchg
->stSelEnd
.wHour
| nmchg
->stSelEnd
.wMinute
|
582 nmchg
->stSelEnd
.wSecond
| nmchg
->stSelEnd
.wMilliseconds
),
583 "Non-zero member in stSelEnd\n");
591 defwndproc_counter
++;
592 ret
= DefWindowProcA(hwnd
, message
, wParam
, lParam
);
593 defwndproc_counter
--;
598 static BOOL
register_parent_wnd_class(void)
603 cls
.lpfnWndProc
= parent_wnd_proc
;
606 cls
.hInstance
= GetModuleHandleA(NULL
);
608 cls
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
609 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
610 cls
.lpszMenuName
= NULL
;
611 cls
.lpszClassName
= "Month-Cal test parent class";
612 return RegisterClassA(&cls
);
615 static HWND
create_parent_window(void)
619 /* flush message sequences, so we can check the new sequence by the end of function */
620 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
622 if (!register_parent_wnd_class())
625 hwnd
= CreateWindowExA(0, "Month-Cal test parent class", "Month-Cal test parent window",
626 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
| WS_VISIBLE
,
627 0, 0, 500, 500, GetDesktopWindow(), NULL
, GetModuleHandleA(NULL
), NULL
);
628 ok(hwnd
!= NULL
, "failed to create parent wnd\n");
630 /* check for message sequences */
631 ok_sequence(sequences
, PARENT_SEQ_INDEX
, create_parent_window_seq
, "create parent window", FALSE
);
636 static LRESULT WINAPI
monthcal_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
638 WNDPROC oldproc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
639 static LONG defwndproc_counter
= 0;
640 struct message msg
= { 0 };
643 msg
.message
= message
;
644 msg
.flags
= sent
|wparam
|lparam
;
645 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
648 add_message(sequences
, MONTHCAL_SEQ_INDEX
, &msg
);
650 /* some debug output for style changing */
651 if ((message
== WM_STYLECHANGING
||
652 message
== WM_STYLECHANGED
) && lParam
)
654 STYLESTRUCT
*style
= (STYLESTRUCT
*)lParam
;
655 trace("\told style: 0x%08lx, new style: 0x%08lx\n", style
->styleOld
, style
->styleNew
);
658 defwndproc_counter
++;
659 ret
= CallWindowProcA(oldproc
, hwnd
, message
, wParam
, lParam
);
660 defwndproc_counter
--;
665 static HWND
create_monthcal_control(DWORD style
)
672 hwnd
= CreateWindowExA(0, MONTHCAL_CLASSA
, "", WS_CHILD
| WS_BORDER
| WS_VISIBLE
| style
,
673 0, 0, 300, 400, parent_wnd
, NULL
, GetModuleHandleA(NULL
), NULL
);
674 ok(hwnd
!= NULL
, "failed to create monthcal wnd\n");
675 if (!hwnd
) return NULL
;
677 oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
678 (LONG_PTR
)monthcal_subclass_proc
);
679 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
681 SendMessageA(hwnd
, WM_SETFONT
, (WPARAM
)GetStockObject(SYSTEM_FONT
), 0);
683 /* make sure calendar grid is 2x1 */
684 ret
= SendMessageA(hwnd
, MCM_GETMINREQRECT
, 0, (LPARAM
)&rect
);
685 ok(ret
, "got %d\n", ret
);
687 ret
= SetWindowPos(hwnd
, NULL
, 0, 0, rect
.right
* 5 / 2, rect
.bottom
* 3 / 2, SWP_NOMOVE
);
688 ok(ret
, "got %d\n", ret
);
694 /* Setter and Getters Tests */
696 static void test_color(void)
698 COLORREF color
, prev
;
701 hwnd
= create_monthcal_control(0);
703 /* invalid color index */
704 color
= SendMessageA(hwnd
, MCM_GETCOLOR
, MCSC_TRAILINGTEXT
+ 1, 0);
706 prev
= SendMessageA(hwnd
, MCM_SETCOLOR
, MCSC_TRAILINGTEXT
+ 1, RGB(255,255,255));
709 color
= SendMessageA(hwnd
, MCM_GETCOLOR
, MCSC_BACKGROUND
, 0);
710 prev
= SendMessageA(hwnd
, MCM_SETCOLOR
, MCSC_BACKGROUND
, RGB(0,0,0));
712 color
= SendMessageA(hwnd
, MCM_GETCOLOR
, MCSC_BACKGROUND
, 0);
713 expect(RGB(0,0,0), color
);
714 prev
= SendMessageA(hwnd
, MCM_SETCOLOR
, MCSC_BACKGROUND
, RGB(255,255,255));
716 color
= SendMessageA(hwnd
, MCM_GETCOLOR
, MCSC_BACKGROUND
, 0);
717 expect(RGB(255,255,255), color
);
719 color
= SendMessageA(hwnd
, MCM_GETCOLOR
, MCSC_MONTHBK
, 0);
720 prev
= SendMessageA(hwnd
, MCM_SETCOLOR
, MCSC_MONTHBK
, RGB(0,0,0));
722 color
= SendMessageA(hwnd
, MCM_GETCOLOR
, MCSC_MONTHBK
, 0);
723 expect(RGB(0,0,0), color
);
724 prev
= SendMessageA(hwnd
, MCM_SETCOLOR
, MCSC_MONTHBK
, RGB(255,255,255));
726 color
= SendMessageA(hwnd
, MCM_GETCOLOR
, MCSC_MONTHBK
, 0);
727 expect(RGB(255,255,255), color
);
729 color
= SendMessageA(hwnd
, MCM_GETCOLOR
, MCSC_TEXT
, 0);
730 prev
= SendMessageA(hwnd
, MCM_SETCOLOR
, MCSC_TEXT
, RGB(0,0,0));
732 color
= SendMessageA(hwnd
, MCM_GETCOLOR
, MCSC_TEXT
, 0);
733 expect(RGB(0,0,0), color
);
734 prev
= SendMessageA(hwnd
, MCM_SETCOLOR
, MCSC_TEXT
, RGB(255,255,255));
736 color
= SendMessageA(hwnd
, MCM_GETCOLOR
, MCSC_TEXT
, 0);
737 expect(RGB(255,255,255), color
);
739 color
= SendMessageA(hwnd
, MCM_GETCOLOR
, MCSC_TITLEBK
, 0);
740 prev
= SendMessageA(hwnd
, MCM_SETCOLOR
, MCSC_TITLEBK
, RGB(0,0,0));
742 color
= SendMessageA(hwnd
, MCM_GETCOLOR
, MCSC_TITLEBK
, 0);
743 expect(RGB(0,0,0), color
);
744 prev
= SendMessageA(hwnd
, MCM_SETCOLOR
, MCSC_TITLEBK
, RGB(255,255,255));
746 color
= SendMessageA(hwnd
, MCM_GETCOLOR
, MCSC_TITLEBK
, 0);
747 expect(RGB(255,255,255), color
);
749 color
= SendMessageA(hwnd
, MCM_GETCOLOR
, MCSC_TITLETEXT
, 0);
750 prev
= SendMessageA(hwnd
, MCM_SETCOLOR
, MCSC_TITLETEXT
, RGB(0,0,0));
752 color
= SendMessageA(hwnd
, MCM_GETCOLOR
, MCSC_TITLETEXT
, 0);
753 expect(RGB(0,0,0), color
);
754 prev
= SendMessageA(hwnd
, MCM_SETCOLOR
, MCSC_TITLETEXT
, RGB(255,255,255));
756 color
= SendMessageA(hwnd
, MCM_GETCOLOR
, MCSC_TITLETEXT
, 0);
757 expect(RGB(255,255,255), color
);
759 color
= SendMessageA(hwnd
, MCM_GETCOLOR
, MCSC_TRAILINGTEXT
, 0);
760 prev
= SendMessageA(hwnd
, MCM_SETCOLOR
, MCSC_TRAILINGTEXT
, RGB(0,0,0));
762 color
= SendMessageA(hwnd
, MCM_GETCOLOR
, MCSC_TRAILINGTEXT
, 0);
763 expect(RGB(0,0,0), color
);
764 prev
= SendMessageA(hwnd
, MCM_SETCOLOR
, MCSC_TRAILINGTEXT
, RGB(255,255,255));
766 color
= SendMessageA(hwnd
, MCM_GETCOLOR
, MCSC_TRAILINGTEXT
, 0);
767 expect(RGB(255,255,255), color
);
772 static void test_currdate(void)
774 SYSTEMTIME st_original
, st_new
, st_test
;
778 hwnd
= create_monthcal_control(0);
780 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
782 /* Setter and Getters for current date selected */
783 st_original
.wYear
= 2000;
784 st_original
.wMonth
= 11;
785 st_original
.wDay
= 28;
786 st_original
.wHour
= 11;
787 st_original
.wMinute
= 59;
788 st_original
.wSecond
= 30;
789 st_original
.wMilliseconds
= 0;
790 st_original
.wDayOfWeek
= 0;
792 st_new
= st_test
= st_original
;
794 /* Should not validate the time */
795 res
= SendMessageA(hwnd
, MCM_SETCURSEL
, 0, (LPARAM
)&st_test
);
798 /* Overflow matters, check for wDay */
800 res
= SendMessageA(hwnd
, MCM_SETCURSEL
, 0, (LPARAM
)&st_test
);
803 /* correct wDay before checking for wMonth */
805 expect(st_original
.wDay
, st_test
.wDay
);
807 /* Overflow matters, check for wMonth */
809 res
= SendMessageA(hwnd
, MCM_SETCURSEL
, 0, (LPARAM
)&st_test
);
812 /* checking if gets the information right, modify st_new */
820 res
= SendMessageA(hwnd
, MCM_GETCURSEL
, 0, (LPARAM
)&st_new
);
823 /* st_new change to st_origin, above settings with overflow */
824 /* should not change the current settings */
825 expect(st_original
.wYear
, st_new
.wYear
);
826 expect(st_original
.wMonth
, st_new
.wMonth
);
827 expect(st_original
.wDay
, st_new
.wDay
);
828 ok(st_original
.wHour
== st_new
.wHour
||
829 broken(0 == st_new
.wHour
), /* comctl32 <= 4.70 */
830 "Expected %d, got %d\n", st_original
.wHour
, st_new
.wHour
);
831 ok(st_original
.wMinute
== st_new
.wMinute
||
832 broken(0 == st_new
.wMinute
), /* comctl32 <= 4.70 */
833 "Expected %d, got %d\n", st_original
.wMinute
, st_new
.wMinute
);
834 ok(st_original
.wSecond
== st_new
.wSecond
||
835 broken(0 == st_new
.wSecond
), /* comctl32 <= 4.70 */
836 "Expected %d, got %d\n", st_original
.wSecond
, st_new
.wSecond
);
838 /* lparam cannot be NULL */
839 res
= SendMessageA(hwnd
, MCM_GETCURSEL
, 0, 0);
842 ok_sequence(sequences
, MONTHCAL_SEQ_INDEX
, monthcal_curr_date_seq
, "monthcal currDate", TRUE
);
844 /* December, 31, 9999 is the maximum allowed date */
845 memset(&st_new
, 0, sizeof(st_new
));
849 res
= SendMessageA(hwnd
, MCM_SETCURSEL
, 0, (LPARAM
)&st_new
);
851 memset(&st_test
, 0, sizeof(st_test
));
852 res
= SendMessageA(hwnd
, MCM_GETCURSEL
, 0, (LPARAM
)&st_test
);
854 expect(st_new
.wYear
, st_test
.wYear
);
855 expect(st_new
.wMonth
, st_test
.wMonth
);
856 expect(st_new
.wDay
, st_test
.wDay
);
857 expect(st_new
.wHour
, st_test
.wHour
);
858 expect(st_new
.wMinute
, st_test
.wMinute
);
859 expect(st_new
.wSecond
, st_test
.wSecond
);
860 /* try one day later */
861 st_original
= st_new
;
862 st_new
.wYear
= 10000;
865 res
= SendMessageA(hwnd
, MCM_SETCURSEL
, 0, (LPARAM
)&st_new
);
867 broken(1 == res
), /* comctl32 <= 4.72 */
868 "Expected 0, got %d\n", res
);
871 memset(&st_test
, 0, sizeof(st_test
));
872 res
= SendMessageA(hwnd
, MCM_GETCURSEL
, 0, (LPARAM
)&st_test
);
874 expect(st_original
.wYear
, st_test
.wYear
);
875 expect(st_original
.wMonth
, st_test
.wMonth
);
876 expect(st_original
.wDay
, st_test
.wDay
);
877 expect(st_original
.wHour
, st_test
.wHour
);
878 expect(st_original
.wMinute
, st_test
.wMinute
);
879 expect(st_original
.wSecond
, st_test
.wSecond
);
882 /* setting selection equal to current reports success even if out range */
883 memset(&st_new
, 0, sizeof(st_new
));
887 res
= SendMessageA(hwnd
, MCM_SETCURSEL
, 0, (LPARAM
)&st_new
);
889 memset(&st_test
, 0, sizeof(st_test
));
890 st_test
.wYear
= 2009;
893 res
= SendMessageA(hwnd
, MCM_SETRANGE
, GDTR_MIN
, (LPARAM
)&st_test
);
895 /* set to current again */
896 res
= SendMessageA(hwnd
, MCM_SETCURSEL
, 0, (LPARAM
)&st_new
);
899 /* set with invalid day of week */
900 memset(&st_test
, 0, sizeof(st_test
));
901 st_test
.wYear
= 2009;
904 st_test
.wDayOfWeek
= 100;
905 res
= SendMessageA(hwnd
, MCM_SETCURSEL
, 0, (LPARAM
)&st_test
);
908 memset(&st_test
, 0, sizeof(st_test
));
909 res
= SendMessageA(hwnd
, MCM_GETCURSEL
, 0, (LPARAM
)&st_test
);
911 expect(2009, st_test
.wYear
);
912 expect(7, st_test
.wDay
);
913 expect(10, st_test
.wMonth
);
914 expect(3, st_test
.wDayOfWeek
);
919 static void test_firstDay(void)
921 int res
, fday
, i
, prev
;
922 CHAR b
[128], caltype
[3];
923 LCID lcid
= LOCALE_USER_DEFAULT
;
927 SetLastError(0xdeadbeef);
928 ret
= GetLocaleInfoA(lcid
, LOCALE_ICALENDARTYPE
, caltype
, 3);
930 skip("Must know local calendar type (%lx)\n", GetLastError());
932 } else if (atoi(caltype
) != CAL_GREGORIAN
) {
933 skip("MonthCalendar Control only supports Gregorian calendar (type: %s)\n", caltype
);
937 hwnd
= create_monthcal_control(0);
939 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
941 /* Setter and Getters for first day of week */
942 /* check for locale first day */
943 if(GetLocaleInfoA(lcid
, LOCALE_IFIRSTDAYOFWEEK
, b
, 128)){
945 res
= SendMessageA(hwnd
, MCM_GETFIRSTDAYOFWEEK
, 0, 0);
949 /* checking for the values that actually will be stored as */
950 /* current first day when we set a new value */
951 for (i
= -5; i
< 12; i
++){
952 res
= SendMessageA(hwnd
, MCM_SETFIRSTDAYOFWEEK
, 0, i
);
954 res
= SendMessageA(hwnd
, MCM_GETFIRSTDAYOFWEEK
, 0, 0);
958 expect(MAKELONG(fday
, FALSE
), res
);
960 /* out of range sets max first day of week, locale is ignored */
961 expect(MAKELONG(6, TRUE
), res
);
963 expect(MAKELONG(i
, TRUE
), res
);
967 ok_sequence(sequences
, MONTHCAL_SEQ_INDEX
, monthcal_first_day_seq
, "monthcal firstDay", FALSE
);
970 skip("Cannot retrieve first day of the week\n");
976 static void test_unicode(void)
981 hwnd
= create_monthcal_control(0);
983 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
985 /* Setter and Getters for Unicode format */
987 /* getting the current settings */
988 temp
= SendMessageA(hwnd
, MCM_GETUNICODEFORMAT
, 0, 0);
990 /* setting to 1, should return previous settings */
991 res
= SendMessageA(hwnd
, MCM_SETUNICODEFORMAT
, 1, 0);
994 /* current setting is 1, so, should return 1 */
995 res
= SendMessageA(hwnd
, MCM_GETUNICODEFORMAT
, 0, 0);
997 broken(0 == res
), /* comctl32 <= 4.70 */
998 "Expected 1, got %d\n", res
);
1000 /* setting to 0, should return previous settings */
1001 res
= SendMessageA(hwnd
, MCM_SETUNICODEFORMAT
, 0, 0);
1003 broken(0 == res
), /* comctl32 <= 4.70 */
1004 "Expected 1, got %d\n", res
);
1006 /* current setting is 0, so, it should return 0 */
1007 res
= SendMessageA(hwnd
, MCM_GETUNICODEFORMAT
, 0, 0);
1010 /* should return previous settings */
1011 res
= SendMessageA(hwnd
, MCM_SETUNICODEFORMAT
, 1, 0);
1014 ok_sequence(sequences
, MONTHCAL_SEQ_INDEX
, monthcal_unicode_seq
, "monthcal unicode", FALSE
);
1016 DestroyWindow(hwnd
);
1019 static void test_hittest(void)
1021 typedef struct hittest_test
1027 static const hittest_test_t title_hits
[] = {
1028 /* Start is the same everywhere */
1029 { MCHT_TITLE
, FALSE
},
1030 { MCHT_TITLEBTNPREV
, FALSE
},
1031 /* The middle piece is only tested for presence of items */
1032 /* End is the same everywhere */
1033 { MCHT_TITLEBTNNEXT
, FALSE
},
1034 { MCHT_TITLE
, FALSE
},
1035 { MCHT_NOWHERE
, TRUE
}
1038 MCHITTESTINFO mchit
;
1045 char yearmonth
[80], *locale_month
, *locale_year
;
1046 int month_count
, year_count
;
1049 memset(&mchit
, 0, sizeof(MCHITTESTINFO
));
1051 hwnd
= create_monthcal_control(0);
1053 /* test with invalid structure size */
1054 mchit
.cbSize
= MCHITTESTINFO_V1_SIZE
- 1;
1057 res
= SendMessageA(hwnd
, MCM_HITTEST
, 0, (LPARAM
)&mchit
);
1058 expect(0, mchit
.pt
.x
);
1059 expect(0, mchit
.pt
.y
);
1061 expect(0, mchit
.uHit
);
1062 /* test with invalid pointer */
1063 res
= SendMessageA(hwnd
, MCM_HITTEST
, 0, 0);
1066 /* resize control to display single Calendar */
1067 res
= SendMessageA(hwnd
, MCM_GETMINREQRECT
, 0, (LPARAM
)&r
);
1070 win_skip("Message MCM_GETMINREQRECT unsupported. Skipping.\n");
1071 DestroyWindow(hwnd
);
1074 MoveWindow(hwnd
, 0, 0, r
.right
, r
.bottom
, FALSE
);
1076 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1084 st
.wMilliseconds
= 0;
1087 res
= SendMessageA(hwnd
, MCM_SETCURSEL
, 0, (LPARAM
)&st
);
1090 /* (0, 0) is the top left of the control - title */
1091 mchit
.cbSize
= MCHITTESTINFO_V1_SIZE
;
1094 res
= SendMessageA(hwnd
, MCM_HITTEST
, 0, (LPARAM
)&mchit
);
1095 expect(0, mchit
.pt
.x
);
1096 expect(0, mchit
.pt
.y
);
1097 expect(mchit
.uHit
, res
);
1098 expect_hex(MCHT_TITLE
, res
);
1100 /* bottom right of the control and should not be active */
1101 mchit
.pt
.x
= r
.right
;
1102 mchit
.pt
.y
= r
.bottom
;
1103 res
= SendMessageA(hwnd
, MCM_HITTEST
, 0, (LPARAM
)&mchit
);
1104 expect(r
.right
, mchit
.pt
.x
);
1105 expect(r
.bottom
, mchit
.pt
.y
);
1106 expect(mchit
.uHit
, res
);
1107 todo_wine
expect_hex(MCHT_NOWHERE
, res
);
1109 /* completely out of the control, should not be active */
1110 mchit
.pt
.x
= 2 * r
.right
;
1111 mchit
.pt
.y
= 2 * r
.bottom
;
1112 res
= SendMessageA(hwnd
, MCM_HITTEST
, 0, (LPARAM
)&mchit
);
1113 expect(2 * r
.right
, mchit
.pt
.x
);
1114 expect(2 * r
.bottom
, mchit
.pt
.y
);
1115 expect(mchit
.uHit
, res
);
1116 todo_wine
expect_hex(MCHT_NOWHERE
, res
);
1118 /* in active area - day of the week */
1119 mchit
.pt
.x
= r
.right
/ 2;
1120 mchit
.pt
.y
= r
.bottom
/ 2;
1121 res
= SendMessageA(hwnd
, MCM_HITTEST
, 0, (LPARAM
)&mchit
);
1122 expect(r
.right
/ 2, mchit
.pt
.x
);
1123 expect(r
.bottom
/ 2, mchit
.pt
.y
);
1124 expect(mchit
.uHit
, res
);
1125 expect_hex(MCHT_CALENDARDATE
, res
);
1127 /* in active area - day of the week #2 */
1128 mchit
.pt
.x
= r
.right
/ 14; /* half of first day rect */
1129 mchit
.pt
.y
= r
.bottom
/ 2;
1130 res
= SendMessageA(hwnd
, MCM_HITTEST
, 0, (LPARAM
)&mchit
);
1131 expect(r
.right
/ 14, mchit
.pt
.x
);
1132 expect(r
.bottom
/ 2, mchit
.pt
.y
);
1133 expect(mchit
.uHit
, res
);
1134 expect_hex(MCHT_CALENDARDATE
, res
);
1136 /* in active area - date from prev month */
1137 mchit
.pt
.x
= r
.right
/ 14; /* half of first day rect */
1138 mchit
.pt
.y
= 6 * r
.bottom
/ 19;
1139 res
= SendMessageA(hwnd
, MCM_HITTEST
, 0, (LPARAM
)&mchit
);
1140 expect(r
.right
/ 14, mchit
.pt
.x
);
1141 expect(6 * r
.bottom
/ 19, mchit
.pt
.y
);
1142 expect(mchit
.uHit
, res
);
1143 expect_hex(MCHT_CALENDARDATEPREV
, res
);
1147 /* (125, 115) is in active area - date from this month */
1150 res
= SendMessageA(hwnd
, MCM_HITTEST
, 0, (LPARAM
)&mchit
);
1151 expect(125, mchit
.pt
.x
);
1152 expect(115, mchit
.pt
.y
);
1153 expect(mchit
.uHit
, res
);
1154 expect(MCHT_CALENDARDATE
, res
);
1157 /* in active area - date from next month */
1158 mchit
.pt
.x
= 11 * r
.right
/ 14;
1159 mchit
.pt
.y
= 16 * r
.bottom
/ 19;
1160 res
= SendMessageA(hwnd
, MCM_HITTEST
, 0, (LPARAM
)&mchit
);
1161 expect(11 * r
.right
/ 14, mchit
.pt
.x
);
1162 expect(16 * r
.bottom
/ 19, mchit
.pt
.y
);
1163 expect(mchit
.uHit
, res
);
1164 expect_hex(MCHT_CALENDARDATENEXT
, res
);
1166 /* in active area - today link */
1167 mchit
.pt
.x
= r
.right
/ 14;
1168 mchit
.pt
.y
= 18 * r
.bottom
/ 19;
1169 res
= SendMessageA(hwnd
, MCM_HITTEST
, 0, (LPARAM
)&mchit
);
1170 expect(r
.right
/ 14, mchit
.pt
.x
);
1171 expect(18 * r
.bottom
/ 19, mchit
.pt
.y
);
1172 expect(mchit
.uHit
, res
);
1173 expect_hex(MCHT_TODAYLINK
, res
);
1175 /* in active area - today link */
1176 mchit
.pt
.x
= r
.right
/ 2;
1177 mchit
.pt
.y
= 18 * r
.bottom
/ 19;
1178 res
= SendMessageA(hwnd
, MCM_HITTEST
, 0, (LPARAM
)&mchit
);
1179 expect(r
.right
/ 2, mchit
.pt
.x
);
1180 expect(18 * r
.bottom
/ 19, mchit
.pt
.y
);
1181 expect(mchit
.uHit
, res
);
1182 expect_hex(MCHT_TODAYLINK
, res
);
1184 /* in active area - today link */
1185 mchit
.pt
.x
= r
.right
/ 10;
1186 mchit
.pt
.y
= 18 * r
.bottom
/ 19;
1187 res
= SendMessageA(hwnd
, MCM_HITTEST
, 0, (LPARAM
)&mchit
);
1188 expect(r
.right
/ 10, mchit
.pt
.x
);
1189 expect(18 * r
.bottom
/ 19, mchit
.pt
.y
);
1190 expect(mchit
.uHit
, res
);
1191 expect_hex(MCHT_TODAYLINK
, res
);
1193 ok_sequence(sequences
, MONTHCAL_SEQ_INDEX
, monthcal_hit_test_seq
, "monthcal hit test", TRUE
);
1195 /* The horizontal position of title bar elements depends on locale (y pos
1196 is constant), so we sample across a horizontal line and make sure we
1197 find all elements. */
1199 /* Get the format of the title */
1200 GetLocaleInfoA(LOCALE_USER_DEFAULT
, LOCALE_SYEARMONTH
, yearmonth
, 80);
1201 /* Find out if we have a month and/or year */
1202 locale_year
= strstr(yearmonth
, "y");
1203 locale_month
= strstr(yearmonth
, "M");
1206 mchit
.pt
.y
= (5/2) * r
.bottom
/ 19;
1208 old_res
= SendMessageA(hwnd
, MCM_HITTEST
, 0, (LPARAM
)&mchit
);
1209 expect_hex(title_hits
[title_index
].ht
, old_res
);
1211 in_the_middle
= FALSE
;
1212 month_count
= year_count
= 0;
1213 for (x
= 0; x
< r
.right
; x
++){
1215 res
= SendMessageA(hwnd
, MCM_HITTEST
, 0, (LPARAM
)&mchit
);
1216 expect(x
, mchit
.pt
.x
);
1217 expect((5/2) * r
.bottom
/ 19, mchit
.pt
.y
);
1218 expect(mchit
.uHit
, res
);
1219 if (res
!= old_res
) {
1221 if (old_res
== MCHT_TITLEBTNPREV
)
1222 in_the_middle
= TRUE
;
1224 if (res
== MCHT_TITLEBTNNEXT
)
1225 in_the_middle
= FALSE
;
1227 if (in_the_middle
) {
1228 if (res
== MCHT_TITLEMONTH
)
1230 else if (res
== MCHT_TITLEYEAR
)
1235 if (ARRAY_SIZE(title_hits
) <= title_index
)
1238 todo_wine_if(title_hits
[title_index
].todo
)
1239 ok(title_hits
[title_index
].ht
== res
, "Expected %x, got %x, pos %ld\n",
1240 title_hits
[title_index
].ht
, res
, x
);
1246 /* There are some limits, even if LOCALE_SYEARMONTH contains rubbish
1247 * or no month/year indicators at all */
1249 todo_wine
ok(month_count
== 1, "Expected 1 month item, got %d\n", month_count
);
1251 ok(month_count
<= 1, "Too many month items: %d\n", month_count
);
1254 todo_wine
ok(year_count
== 1, "Expected 1 year item, got %d\n", year_count
);
1256 ok(year_count
<= 1, "Too many year items: %d\n", year_count
);
1258 todo_wine
ok(month_count
+ year_count
>= 1, "Not enough month and year items\n");
1260 ok(r
.right
<= x
&& title_index
+ 1 == ARRAY_SIZE(title_hits
), "Wrong title layout\n");
1262 DestroyWindow(hwnd
);
1265 static void test_todaylink(void)
1267 MCHITTESTINFO mchit
;
1268 SYSTEMTIME st_test
, st_new
;
1273 memset(&mchit
, 0, sizeof(MCHITTESTINFO
));
1275 hwnd
= create_monthcal_control(0);
1277 res
= SendMessageA(hwnd
, MCM_GETMINREQRECT
, 0, (LPARAM
)&r
);
1279 MoveWindow(hwnd
, 0, 0, r
.right
, r
.bottom
, FALSE
);
1281 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1283 /* hit active area - today link */
1284 mchit
.cbSize
= MCHITTESTINFO_V1_SIZE
;
1285 mchit
.pt
.x
= r
.right
/ 14;
1286 mchit
.pt
.y
= 18 * r
.bottom
/ 19;
1287 res
= SendMessageA(hwnd
, MCM_HITTEST
, 0, (LPARAM
)&mchit
);
1288 expect(r
.right
/ 14, mchit
.pt
.x
);
1289 expect(18 * r
.bottom
/ 19, mchit
.pt
.y
);
1290 expect(mchit
.uHit
, res
);
1291 expect(MCHT_TODAYLINK
, res
);
1295 st_test
.wYear
= 2005;
1297 res
= SendMessageA(hwnd
, MCM_SETTODAY
, 0, (LPARAM
)&st_test
);
1300 memset(&st_new
, 0, sizeof(st_new
));
1301 res
= SendMessageA(hwnd
, MCM_GETTODAY
, 0, (LPARAM
)&st_new
);
1303 expect(1, st_new
.wDay
);
1304 expect(1, st_new
.wMonth
);
1305 expect(2005, st_new
.wYear
);
1307 res
= SendMessageA(hwnd
, WM_LBUTTONDOWN
, MK_LBUTTON
, MAKELONG(mchit
.pt
.x
, mchit
.pt
.y
));
1310 memset(&st_new
, 0, sizeof(st_new
));
1311 res
= SendMessageA(hwnd
, MCM_GETCURSEL
, 0, (LPARAM
)&st_new
);
1313 expect(1, st_new
.wDay
);
1314 expect(1, st_new
.wMonth
);
1315 expect(2005, st_new
.wYear
);
1317 ok_sequence(sequences
, MONTHCAL_SEQ_INDEX
, monthcal_todaylink_seq
, "monthcal hit test", TRUE
);
1319 DestroyWindow(hwnd
);
1322 static void test_today(void)
1324 SYSTEMTIME st_test
, st_new
;
1328 hwnd
= create_monthcal_control(0);
1330 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1332 /* Setter and Getters for "today" information */
1334 /* check for overflow, should be ok */
1335 memset(&st_test
, 0, sizeof(st_test
));
1337 st_test
.wMonth
= 38;
1342 res
= SendMessageA(hwnd
, MCM_SETTODAY
, 0, (LPARAM
)&st_test
);
1345 res
= SendMessageA(hwnd
, MCM_GETTODAY
, 0, (LPARAM
)&st_new
);
1348 /* st_test should not change */
1349 expect(38, st_test
.wDay
);
1350 expect(38, st_test
.wMonth
);
1352 /* st_new should change, overflow does not matter */
1353 expect(38, st_new
.wDay
);
1354 expect(38, st_new
.wMonth
);
1356 /* check for zero, should be ok*/
1360 res
= SendMessageA(hwnd
, MCM_SETTODAY
, 0, (LPARAM
)&st_test
);
1363 res
= SendMessageA(hwnd
, MCM_GETTODAY
, 0, (LPARAM
)&st_new
);
1366 /* st_test should not change */
1367 expect(0, st_test
.wDay
);
1368 expect(0, st_test
.wMonth
);
1370 /* st_new should change to zero*/
1371 expect(0, st_new
.wDay
);
1372 expect(0, st_new
.wMonth
);
1374 ok_sequence(sequences
, MONTHCAL_SEQ_INDEX
, monthcal_today_seq
, "monthcal today", TRUE
);
1376 DestroyWindow(hwnd
);
1379 static void test_scroll(void)
1384 hwnd
= create_monthcal_control(0);
1386 res
= SendMessageA(hwnd
, MCM_GETMONTHDELTA
, 0, 0);
1389 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1391 /* Setter and Getters for scroll rate */
1392 res
= SendMessageA(hwnd
, MCM_SETMONTHDELTA
, 2, 0);
1395 res
= SendMessageA(hwnd
, MCM_SETMONTHDELTA
, 3, 0);
1397 res
= SendMessageA(hwnd
, MCM_GETMONTHDELTA
, 0, 0);
1400 res
= SendMessageA(hwnd
, MCM_SETMONTHDELTA
, 12, 0);
1402 res
= SendMessageA(hwnd
, MCM_GETMONTHDELTA
, 0, 0);
1405 res
= SendMessageA(hwnd
, MCM_SETMONTHDELTA
, 15, 0);
1407 res
= SendMessageA(hwnd
, MCM_GETMONTHDELTA
, 0, 0);
1410 res
= SendMessageA(hwnd
, MCM_SETMONTHDELTA
, -5, 0);
1412 res
= SendMessageA(hwnd
, MCM_GETMONTHDELTA
, 0, 0);
1415 ok_sequence(sequences
, MONTHCAL_SEQ_INDEX
, monthcal_scroll_seq
, "monthcal scroll", FALSE
);
1417 DestroyWindow(hwnd
);
1420 static void test_monthrange(void)
1423 SYSTEMTIME st_visible
[2], st_daystate
[2], st
;
1427 hwnd
= create_monthcal_control(0);
1429 memset(&st_visible
, 0, sizeof(st_visible
));
1430 memset(&st_daystate
, 0, sizeof(st_daystate
));
1438 st
.wMilliseconds
= 0;
1441 res
= SendMessageA(hwnd
, MCM_SETCURSEL
, 0, (LPARAM
)&st
);
1444 /* to be locale independent */
1445 SendMessageA(hwnd
, MCM_SETFIRSTDAYOFWEEK
, 0, (LPARAM
)6);
1447 res
= SendMessageA(hwnd
, MCM_GETMINREQRECT
, 0, (LPARAM
)&r
);
1449 /* resize control to display two Calendars */
1450 MoveWindow(hwnd
, 0, 0, r
.right
, (5/2)*r
.bottom
, FALSE
);
1452 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1454 res
= SendMessageA(hwnd
, MCM_GETMONTHRANGE
, GMR_VISIBLE
, (LPARAM
)st_visible
);
1456 expect(2000, st_visible
[0].wYear
);
1457 expect(11, st_visible
[0].wMonth
);
1458 expect(1, st_visible
[0].wDay
);
1459 expect(2000, st_visible
[1].wYear
);
1460 expect(12, st_visible
[1].wMonth
);
1461 expect(31, st_visible
[1].wDay
);
1463 res
= SendMessageA(hwnd
, MCM_GETMONTHRANGE
, GMR_DAYSTATE
, (LPARAM
)st_daystate
);
1465 expect(2000, st_daystate
[0].wYear
);
1466 expect(10, st_daystate
[0].wMonth
);
1467 expect(29, st_daystate
[0].wDay
);
1468 expect(2001, st_daystate
[1].wYear
);
1469 expect(1, st_daystate
[1].wMonth
);
1470 expect(6, st_daystate
[1].wDay
);
1472 ok_sequence(sequences
, MONTHCAL_SEQ_INDEX
, monthcal_monthrange_seq
, "monthcal monthrange", FALSE
);
1474 /* with null date array parameter */
1475 res
= SendMessageA(hwnd
, MCM_GETMONTHRANGE
, GMR_VISIBLE
, 0);
1478 res
= SendMessageA(hwnd
, MCM_GETMONTHRANGE
, GMR_DAYSTATE
, 0);
1481 /* resize control to display single Calendar */
1482 MoveWindow(hwnd
, 0, 0, r
.right
, r
.bottom
, FALSE
);
1484 memset(&st
, 0, sizeof(st
));
1489 res
= SendMessageA(hwnd
, MCM_SETCURSEL
, 0, (LPARAM
)&st
);
1492 /* September 1752 has 19 days */
1493 res
= SendMessageA(hwnd
, MCM_GETMONTHRANGE
, GMR_VISIBLE
, (LPARAM
)st_visible
);
1496 expect(1752, st_visible
[0].wYear
);
1497 expect(9, st_visible
[0].wMonth
);
1498 ok(14 == st_visible
[0].wDay
||
1499 broken(1 == st_visible
[0].wDay
), /* comctl32 <= 4.72 */
1500 "Expected 14, got %d\n", st_visible
[0].wDay
);
1502 expect(1752, st_visible
[1].wYear
);
1503 expect(9, st_visible
[1].wMonth
);
1504 expect(19, st_visible
[1].wDay
);
1506 DestroyWindow(hwnd
);
1509 static void test_maxselday(void)
1515 hwnd
= create_monthcal_control(0);
1516 /* if no style specified default to 1 */
1517 res
= SendMessageA(hwnd
, MCM_GETMAXSELCOUNT
, 0, 0);
1519 res
= SendMessageA(hwnd
, MCM_SETMAXSELCOUNT
, 5, 0);
1521 res
= SendMessageA(hwnd
, MCM_GETMAXSELCOUNT
, 0, 0);
1524 /* try to set style */
1525 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1526 SetWindowLongA(hwnd
, GWL_STYLE
, style
| MCS_MULTISELECT
);
1527 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1528 ok(!(style
& MCS_MULTISELECT
), "Expected MCS_MULTISELECT not to be set\n");
1529 DestroyWindow(hwnd
);
1531 hwnd
= create_monthcal_control(MCS_MULTISELECT
);
1532 /* try to remove style */
1533 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1534 SetWindowLongA(hwnd
, GWL_STYLE
, style
& ~MCS_MULTISELECT
);
1535 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1536 ok(style
& MCS_MULTISELECT
, "Expected MCS_MULTISELECT to be set\n");
1537 DestroyWindow(hwnd
);
1539 hwnd
= create_monthcal_control(MCS_MULTISELECT
);
1541 /* default width is a week */
1542 res
= SendMessageA(hwnd
, MCM_GETMAXSELCOUNT
, 0, 0);
1545 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1547 /* Setter and Getters for max selected days */
1548 res
= SendMessageA(hwnd
, MCM_SETMAXSELCOUNT
, 5, 0);
1550 res
= SendMessageA(hwnd
, MCM_GETMAXSELCOUNT
, 0, 0);
1553 res
= SendMessageA(hwnd
, MCM_SETMAXSELCOUNT
, 15, 0);
1555 res
= SendMessageA(hwnd
, MCM_GETMAXSELCOUNT
, 0, 0);
1558 /* test invalid value */
1559 res
= SendMessageA(hwnd
, MCM_SETMAXSELCOUNT
, -1, 0);
1561 res
= SendMessageA(hwnd
, MCM_GETMAXSELCOUNT
, 0, 0);
1564 ok_sequence(sequences
, MONTHCAL_SEQ_INDEX
, monthcal_max_sel_day_seq
, "monthcal MaxSelDay", FALSE
);
1566 /* zero value is invalid too */
1567 res
= SendMessageA(hwnd
, MCM_SETMAXSELCOUNT
, 0, 0);
1569 res
= SendMessageA(hwnd
, MCM_GETMAXSELCOUNT
, 0, 0);
1572 DestroyWindow(hwnd
);
1575 static void test_size(void)
1579 HFONT hFont1
, hFont2
;
1583 hwnd
= create_monthcal_control(0);
1585 lstrcpyA(logfont
.lfFaceName
, "Arial");
1586 memset(&logfont
, 0, sizeof(logfont
));
1587 logfont
.lfHeight
= 12;
1588 hFont1
= CreateFontIndirectA(&logfont
);
1590 logfont
.lfHeight
= 24;
1591 hFont2
= CreateFontIndirectA(&logfont
);
1593 /* initialize to a font we can compare against */
1594 SendMessageA(hwnd
, WM_SETFONT
, (WPARAM
)hFont1
, 0);
1595 res
= SendMessageA(hwnd
, MCM_GETMINREQRECT
, 0, (LPARAM
)&r1
);
1596 ok(res
, "SendMessageA(MCM_GETMINREQRECT) failed\n");
1598 /* check that setting a larger font results in an larger rect */
1599 SendMessageA(hwnd
, WM_SETFONT
, (WPARAM
)hFont2
, 0);
1600 res
= SendMessageA(hwnd
, MCM_GETMINREQRECT
, 0, (LPARAM
)&r2
);
1601 ok(res
, "SendMessageA(MCM_GETMINREQRECT) failed\n");
1603 OffsetRect(&r1
, -r1
.left
, -r1
.top
);
1604 OffsetRect(&r2
, -r2
.left
, -r2
.top
);
1606 ok(r1
.bottom
< r2
.bottom
, "Failed to get larger rect with larger font\n");
1608 DestroyWindow(hwnd
);
1611 static void test_create(void)
1615 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1617 hwnd
= create_monthcal_control(0);
1618 ok_sequence(sequences
, PARENT_SEQ_INDEX
, create_monthcal_control_seq
, "create monthcal control", TRUE
);
1620 DestroyWindow(hwnd
);
1622 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1623 hwnd
= create_monthcal_control(MCS_MULTISELECT
);
1624 ok_sequence(sequences
, PARENT_SEQ_INDEX
, create_monthcal_multi_sel_style_seq
, "create monthcal (multi sel style)", TRUE
);
1625 DestroyWindow(hwnd
);
1628 static void test_destroy(void)
1632 hwnd
= create_monthcal_control(0);
1633 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1634 DestroyWindow(hwnd
);
1635 ok_sequence(sequences
, PARENT_SEQ_INDEX
, destroy_monthcal_parent_msgs_seq
, "Destroy monthcal (parent msg)", FALSE
);
1636 ok_sequence(sequences
, MONTHCAL_SEQ_INDEX
, destroy_monthcal_child_msgs_seq
, "Destroy monthcal (child msg)", FALSE
);
1638 /* MCS_MULTISELECT */
1639 hwnd
= create_monthcal_control(MCS_MULTISELECT
);
1640 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1641 DestroyWindow(hwnd
);
1642 ok_sequence(sequences
, MONTHCAL_SEQ_INDEX
, destroy_monthcal_multi_sel_style_seq
, "Destroy monthcal (multi sel style)", FALSE
);
1645 static void test_selrange(void)
1648 SYSTEMTIME st
, range
[2], range2
[2];
1649 BOOL ret
, old_comctl32
= FALSE
;
1651 hwnd
= create_monthcal_control(MCS_MULTISELECT
);
1653 /* just after creation selection should start and end today */
1654 ret
= SendMessageA(hwnd
, MCM_GETTODAY
, 0, (LPARAM
)&st
);
1657 memset(range
, 0xcc, sizeof(range
));
1658 ret
= SendMessageA(hwnd
, MCM_GETSELRANGE
, 0, (LPARAM
)range
);
1660 expect(st
.wYear
, range
[0].wYear
);
1661 expect(st
.wMonth
, range
[0].wMonth
);
1662 expect(st
.wDay
, range
[0].wDay
);
1663 if (range
[0].wDayOfWeek
!= st
.wDayOfWeek
)
1665 win_skip("comctl32 <= 4.70 doesn't set some values\n");
1666 old_comctl32
= TRUE
;
1670 expect(st
.wDayOfWeek
, range
[0].wDayOfWeek
);
1671 expect(st
.wHour
, range
[0].wHour
);
1672 expect(st
.wMinute
, range
[0].wMinute
);
1673 expect(st
.wSecond
, range
[0].wSecond
);
1674 expect(st
.wMilliseconds
, range
[0].wMilliseconds
);
1677 expect(st
.wYear
, range
[1].wYear
);
1678 expect(st
.wMonth
, range
[1].wMonth
);
1679 expect(st
.wDay
, range
[1].wDay
);
1682 expect(st
.wDayOfWeek
, range
[1].wDayOfWeek
);
1683 expect(st
.wHour
, range
[1].wHour
);
1684 expect(st
.wMinute
, range
[1].wMinute
);
1685 expect(st
.wSecond
, range
[1].wSecond
);
1686 expect(st
.wMilliseconds
, range
[1].wMilliseconds
);
1689 /* bounds are swapped if min > max */
1690 memset(&range
[0], 0, sizeof(range
[0]));
1691 range
[0].wYear
= 2009;
1692 range
[0].wMonth
= 10;
1694 range
[1] = range
[0];
1697 ret
= SendMessageA(hwnd
, MCM_SETSELRANGE
, 0, (LPARAM
)range
);
1700 ret
= SendMessageA(hwnd
, MCM_GETSELRANGE
, 0, (LPARAM
)range2
);
1703 expect(range
[1].wYear
, range2
[0].wYear
);
1704 expect(range
[1].wMonth
, range2
[0].wMonth
);
1705 expect(range
[1].wDay
, range2
[0].wDay
);
1706 expect(6, range2
[0].wDayOfWeek
);
1707 expect(range
[1].wHour
, range2
[0].wHour
);
1708 expect(range
[1].wMinute
, range2
[0].wMinute
);
1709 expect(range
[1].wSecond
, range2
[0].wSecond
);
1710 expect(range
[1].wMilliseconds
, range2
[0].wMilliseconds
);
1712 expect(range
[0].wYear
, range2
[1].wYear
);
1713 expect(range
[0].wMonth
, range2
[1].wMonth
);
1714 expect(range
[0].wDay
, range2
[1].wDay
);
1715 expect(1, range2
[1].wDayOfWeek
);
1716 expect(range
[0].wHour
, range2
[1].wHour
);
1717 expect(range
[0].wMinute
, range2
[1].wMinute
);
1718 expect(range
[0].wSecond
, range2
[1].wSecond
);
1719 expect(range
[0].wMilliseconds
, range2
[1].wMilliseconds
);
1721 /* try with range larger than maximum configured */
1722 memset(&range
[0], 0, sizeof(range
[0]));
1723 range
[0].wYear
= 2009;
1724 range
[0].wMonth
= 10;
1726 range
[1] = range
[0];
1728 ret
= SendMessageA(hwnd
, MCM_SETSELRANGE
, 0, (LPARAM
)range
);
1731 range
[1] = range
[0];
1732 /* default max. range is 7 days */
1735 ret
= SendMessageA(hwnd
, MCM_SETSELRANGE
, 0, (LPARAM
)range
);
1738 ret
= SendMessageA(hwnd
, MCM_GETSELRANGE
, 0, (LPARAM
)range2
);
1741 expect(range
[0].wYear
, range2
[0].wYear
);
1742 expect(range
[0].wMonth
, range2
[0].wMonth
);
1743 expect(range
[0].wDay
, range2
[0].wDay
);
1744 expect(range
[0].wYear
, range2
[1].wYear
);
1745 expect(range
[0].wMonth
, range2
[1].wMonth
);
1746 expect(range
[0].wDay
, range2
[1].wDay
);
1748 DestroyWindow(hwnd
);
1751 static void test_killfocus(void)
1756 hwnd
= create_monthcal_control(0);
1758 /* make parent invisible */
1759 style
= GetWindowLongA(parent_wnd
, GWL_STYLE
);
1760 SetWindowLongA(parent_wnd
, GWL_STYLE
, style
& ~WS_VISIBLE
);
1762 SendMessageA(hwnd
, WM_KILLFOCUS
, (WPARAM
)GetDesktopWindow(), 0);
1764 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1765 ok(style
& WS_VISIBLE
, "Expected WS_VISIBLE to be set\n");
1767 style
= GetWindowLongA(parent_wnd
, GWL_STYLE
);
1768 SetWindowLongA(parent_wnd
, GWL_STYLE
, style
| WS_VISIBLE
);
1770 DestroyWindow(hwnd
);
1773 static void test_hittest_v6(void)
1775 MCHITTESTINFO mchit
;
1780 hwnd
= create_monthcal_control(0);
1781 SendMessageA(hwnd
, MCM_SETCALENDARBORDER
, TRUE
, 0);
1783 SendMessageA(hwnd
, MCM_GETMINREQRECT
, 0, (LPARAM
)&r
);
1784 /* reserving some area around calendar */
1785 MoveWindow(hwnd
, 0, 0, r
.right
* 3 / 2, r
.bottom
* 3 / 2, FALSE
);
1786 mchit
.cbSize
= sizeof(MCHITTESTINFO
);
1787 mchit
.pt
.x
= mchit
.pt
.y
= 0;
1791 ret
= SendMessageA(hwnd
, MCM_HITTEST
, 0, (LPARAM
)&mchit
);
1794 win_skip("Only MCHITTESTINFO_V1 supported\n");
1795 DestroyWindow(hwnd
);
1798 todo_wine
expect_hex(MCHT_NOWHERE
, ret
);
1799 expect(-1, mchit
.iOffset
);
1800 expect(-1, mchit
.iRow
);
1801 expect(-1, mchit
.iCol
);
1803 MoveWindow(hwnd
, 0, 0, r
.right
, r
.bottom
, FALSE
);
1804 mchit
.pt
.x
= r
.right
/ 2;
1805 mchit
.pt
.y
= r
.bottom
/ 2;
1807 ret
= SendMessageA(hwnd
, MCM_HITTEST
, 0, (LPARAM
)&mchit
);
1808 expect_hex(MCHT_CALENDARDATE
, ret
);
1809 expect(0, mchit
.iOffset
);
1812 mchit
.pt
.x
= r
.right
/ (7*2);
1813 mchit
.pt
.y
= r
.bottom
/ 2;
1815 mchit
.iCol
= mchit
.iRow
= -1;
1817 SetRect(&mchit
.rc
, -1, -1, -1, -1);
1818 ret
= SendMessageA(hwnd
, MCM_HITTEST
, 0, (LPARAM
)&mchit
);
1819 expect_hex(MCHT_CALENDARDATE
, ret
);
1820 expect_hex(MCHT_CALENDARDATE
, mchit
.uHit
);
1821 expect(0, mchit
.iOffset
);
1822 expect(2, mchit
.iRow
);
1823 expect(0, mchit
.iCol
);
1824 /* returned a one day rectangle */
1825 expect_d(r
.right
/ 7, mchit
.rc
.right
- mchit
.rc
.left
);
1826 expect_d(r
.bottom
/ 10, mchit
.rc
.bottom
- mchit
.rc
.top
);
1832 mchit
.iCol
= mchit
.iRow
= -1;
1834 SetRect(&mchit
.rc
, -1, -1, -1, -1);
1835 ret
= SendMessageA(hwnd
, MCM_HITTEST
, 0, (LPARAM
)&mchit
);
1836 expect_hex(MCHT_TITLE
, ret
);
1837 expect_hex(MCHT_TITLE
, mchit
.uHit
);
1838 expect(0, mchit
.iOffset
);
1839 expect(-1, mchit
.iRow
);
1840 expect(-1, mchit
.iCol
);
1841 expect(0, mchit
.rc
.left
);
1842 expect(0, mchit
.rc
.top
);
1843 expect_d(r
.right
, mchit
.rc
.right
);
1844 ok(mchit
.rc
.bottom
> 0, "got %ld\n", mchit
.rc
.bottom
);
1846 /* between two calendars */
1847 MoveWindow(hwnd
, 0, 0, r
.right
* 5/2, r
.bottom
, FALSE
);
1848 mchit
.pt
.x
= r
.right
/ (5*4);
1849 mchit
.pt
.y
= r
.bottom
/ 2;
1851 mchit
.iCol
= mchit
.iRow
= -2;
1853 SetRect(&mchit
.rc
, -1, -1, -1, -1);
1854 ret
= SendMessageA(hwnd
, MCM_HITTEST
, 0, (LPARAM
)&mchit
);
1855 todo_wine
expect_hex(MCHT_NOWHERE
, ret
);
1856 todo_wine
expect_hex(MCHT_NOWHERE
, mchit
.uHit
);
1857 expect(-2, mchit
.iOffset
);
1858 expect(-2, mchit
.iRow
);
1859 expect(-2, mchit
.iCol
);
1860 todo_wine
expect(0, mchit
.rc
.left
);
1861 todo_wine
expect(0, mchit
.rc
.top
);
1862 todo_wine
expect_d(r
.right
* 5/2, mchit
.rc
.right
);
1863 todo_wine
expect_d(r
.bottom
, mchit
.rc
.bottom
);
1865 DestroyWindow(hwnd
);
1868 static void test_get_set_border(void)
1873 hwnd
= create_monthcal_control(0);
1875 /* a non-default value */
1876 ret
= SendMessageA(hwnd
, MCM_SETCALENDARBORDER
, TRUE
, 10);
1879 ret
= SendMessageA(hwnd
, MCM_GETCALENDARBORDER
, 0, 0);
1883 skip("MCM_GET/SETCALENDARBORDER not supported\n");
1884 DestroyWindow(hwnd
);
1890 DestroyWindow(hwnd
);
1893 static void test_MCM_SIZERECTTOMIN(void)
1899 hwnd
= create_monthcal_control(0);
1901 ret
= SendMessageA(hwnd
, MCM_GETMINREQRECT
, 0, (LPARAM
)&r2
);
1904 win_skip("Message MCM_GETMINREQRECT unsupported. Skipping.\n");
1905 DestroyWindow(hwnd
);
1909 ret
= SendMessageA(hwnd
, MCM_SIZERECTTOMIN
, 0, 0);
1910 ok(ret
== 0, "got %ld\n", ret
);
1913 ret
= SendMessageA(hwnd
, MCM_SIZERECTTOMIN
, 0, (LPARAM
)&r
);
1916 skip("Message MCM_SIZERECTTOMIN unsupported. Skipping.\n");
1917 DestroyWindow(hwnd
);
1920 ok(ret
== 1, "got %ld\n", ret
);
1921 ok(r
.left
== 0 && r
.right
> 0, "got %ld, %ld\n", r
.left
, r
.right
);
1924 ret
= SendMessageA(hwnd
, MCM_SIZERECTTOMIN
, 0, (LPARAM
)&r
);
1925 ok(ret
== 1, "got %ld\n", ret
);
1927 r2
.right
= (r2
.right
- r2
.left
) * 3;
1928 r2
.bottom
= (r2
.bottom
- r2
.top
) * 3;
1929 r2
.left
= r2
.top
= 0;
1930 ret
= SendMessageA(hwnd
, MCM_SIZERECTTOMIN
, 0, (LPARAM
)&r2
);
1931 ok(ret
== 1, "got %ld\n", ret
);
1933 DestroyWindow(hwnd
);
1936 static void test_MCM_GETCALENDARCOUNT(void)
1941 hwnd
= create_monthcal_control(0);
1943 ret
= SendMessageA(hwnd
, MCM_GETCALENDARCOUNT
, 0, 0);
1946 win_skip("Message MCM_GETCALENDARCOUNT unsupported. Skipping.\n");
1947 DestroyWindow(hwnd
);
1953 DestroyWindow(hwnd
);
1956 static void test_daystate(void)
1958 MONTHDAYSTATE state
[4];
1963 /* without MCS_DAYSTATE */
1964 hwnd
= create_monthcal_control(0);
1966 ret
= SendMessageA(hwnd
, MCM_GETMINREQRECT
, 0, (LPARAM
)&r
);
1969 /* resize control to display two Calendars */
1970 MoveWindow(hwnd
, 0, 0, r
.right
, (5/2)*r
.bottom
, FALSE
);
1972 ret
= SendMessageA(hwnd
, MCM_GETMONTHRANGE
, GMR_DAYSTATE
, 0);
1975 ret
= SendMessageA(hwnd
, MCM_SETDAYSTATE
, 4, (LPARAM
)&state
);
1978 ret
= SendMessageA(hwnd
, MCM_SETDAYSTATE
, 2, (LPARAM
)&state
);
1981 ret
= SendMessageA(hwnd
, MCM_SETDAYSTATE
, 0, 0);
1984 /* try to switch on */
1985 SetWindowLongA(hwnd
, GWL_STYLE
, GetWindowLongA(hwnd
, GWL_STYLE
) | MCS_DAYSTATE
);
1986 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1987 ok((style
& MCS_DAYSTATE
) == 0, "got 0x%08lx\n", style
);
1989 DestroyWindow(hwnd
);
1991 /* with MCS_DAYSTATE */
1992 hwnd
= create_monthcal_control(MCS_DAYSTATE
);
1994 ret
= SendMessageA(hwnd
, MCM_GETMONTHRANGE
, GMR_DAYSTATE
, 0);
1997 ret
= SendMessageA(hwnd
, MCM_SETDAYSTATE
, 4, (LPARAM
)&state
);
2000 ret
= SendMessageA(hwnd
, MCM_SETDAYSTATE
, 2, (LPARAM
)&state
);
2003 ret
= SendMessageA(hwnd
, MCM_SETDAYSTATE
, 0, 0);
2006 /* try to switch off */
2007 SetWindowLongA(hwnd
, GWL_STYLE
, GetWindowLongA(hwnd
, GWL_STYLE
) & ~MCS_DAYSTATE
);
2008 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
2009 ok((style
& MCS_DAYSTATE
) == MCS_DAYSTATE
, "got 0x%08lx\n", style
);
2011 DestroyWindow(hwnd
);
2014 static void test_sel_notify(void)
2024 MCHITTESTINFO mchit
= {MCHITTESTINFO_V1_SIZE
};
2026 Monthcal_style styles
[] = {
2027 {MCS_NOTODAY
, "MCS_NOTODAY"},
2028 {MCS_NOTODAY
| MCS_MULTISELECT
, "MCS_NOTODAY | MCS_MULTISELECT"},
2029 {MCS_DAYSTATE
, "MCS_DAYSTATE"},
2030 {MCS_DAYSTATE
| MCS_MULTISELECT
, "MCS_DAYSTATE | MCS_MULTISELECT"}
2034 for(i
= 0; i
< ARRAY_SIZE(styles
); i
++)
2036 hwnd
= create_monthcal_control(styles
[i
].val
);
2037 SetWindowLongPtrA(hwnd
, GWLP_ID
, SEL_NOTIFY_TEST_ID
);
2038 SendMessageA(hwnd
, MCM_GETMINREQRECT
, 0, (LPARAM
)&rc
);
2039 MoveWindow(hwnd
, 0, 0, rc
.right
, rc
.bottom
, FALSE
);
2040 /* Simulate mouse click on some unselected day to generate
2041 MCN_SELECT and MCN_SELCHANGE notifications */
2042 mchit
.pt
.x
= mchit
.pt
.y
= 0;
2043 SendMessageA(hwnd
, MCM_GETCURSEL
, 0, (LPARAM
)&st
);
2047 /* we assume box for day is larger than 3x3 */
2048 if ((mchit
.pt
.y
+= 3) >= rc
.bottom
)
2051 if ((mchit
.pt
.x
+= 3) >= rc
.right
) break;
2053 SendMessageA(hwnd
, MCM_HITTEST
, 0, (LPARAM
)&mchit
);
2054 } while (mchit
.uHit
!= MCHT_CALENDARDATE
|| st
.wDay
== mchit
.st
.wDay
); /* Ensure that mchit.pt points to unselected day */
2055 got_MCN_SELECT
= got_MCN_SELCHANGE
= FALSE
;
2056 SendMessageA(hwnd
, WM_LBUTTONDOWN
, 0, MAKELPARAM(mchit
.pt
.x
, mchit
.pt
.y
));
2057 if (styles
[i
].val
& MCS_MULTISELECT
)
2058 ok(got_MCN_SELCHANGE
, "%d: MCN_SELCHANGE should be sent\n", i
);
2060 ok(!got_MCN_SELCHANGE
, "%d: MCN_SELCHANGE should not be sent\n", i
);
2061 ok(!got_MCN_SELECT
, "%d: MCN_SELECT should not be sent\n", i
);
2062 got_MCN_SELECT
= got_MCN_SELCHANGE
= FALSE
;
2063 SendMessageA(hwnd
, WM_LBUTTONUP
, 0, MAKELPARAM(mchit
.pt
.x
, mchit
.pt
.y
));
2064 if (styles
[i
].val
& MCS_MULTISELECT
)
2065 ok(!got_MCN_SELCHANGE
, "%d: MCN_SELCHANGE should not be sent\n", i
);
2067 ok(got_MCN_SELCHANGE
, "%d: MCN_SELCHANGE should be sent\n", i
);
2068 ok(got_MCN_SELECT
, "%d: MCN_SELECT should be sent\n", i
);
2069 DestroyWindow(hwnd
);
2073 static void init_functions(void)
2075 HMODULE hComCtl32
= LoadLibraryA("comctl32.dll");
2077 #define X(f) p##f = (void*)GetProcAddress(hComCtl32, #f);
2078 X(InitCommonControlsEx
);
2082 START_TEST(monthcal
)
2084 INITCOMMONCONTROLSEX iccex
;
2085 ULONG_PTR ctx_cookie
;
2090 iccex
.dwSize
= sizeof(iccex
);
2091 iccex
.dwICC
= ICC_DATE_CLASSES
;
2092 pInitCommonControlsEx(&iccex
);
2096 init_msg_sequences(sequences
, NUM_MSG_SEQUENCES
);
2098 parent_wnd
= create_parent_window();
2118 if (!load_v6_module(&ctx_cookie
, &hCtx
))
2120 DestroyWindow(parent_wnd
);
2125 test_get_set_border();
2126 test_MCM_SIZERECTTOMIN();
2127 test_MCM_GETCALENDARCOUNT();
2129 unload_v6_module(ctx_cookie
, hCtx
);
2131 DestroyWindow(parent_wnd
);