2 * comctl32 month calendar unit tests
4 * Copyright (C) 2006 Vitaliy Margolen
5 * Copyright (C) 2007 Farshad Agah
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <wine/test.h>
27 //#include "winbase.h"
35 //#include <windows.h>
38 #define expect(expected, got) ok(expected == got, "Expected %d, got %d\n", expected, got);
39 #define expect_hex(expected, got) ok(expected == got, "Expected %x, got %x\n", expected, got);
40 #define expect_d(expected, got) ok(abs((expected) - (got)) <= 2, "Expected %d, got %d\n", expected, got);
42 #define NUM_MSG_SEQUENCES 2
43 #define PARENT_SEQ_INDEX 0
44 #define MONTHCAL_SEQ_INDEX 1
46 #define SEL_NOTIFY_TEST_ID 100
48 static struct msg_sequence
*sequences
[NUM_MSG_SEQUENCES
];
50 static HWND parent_wnd
;
52 static const struct message create_parent_window_seq
[] = {
53 { WM_GETMINMAXINFO
, sent
},
54 { WM_NCCREATE
, sent
},
55 { WM_NCCALCSIZE
, sent
|wparam
, 0 },
57 { WM_SHOWWINDOW
, sent
|wparam
, 1 },
58 { WM_WINDOWPOSCHANGING
, sent
|wparam
, 0 },
59 { WM_QUERYNEWPALETTE
, sent
|optional
},
60 { WM_WINDOWPOSCHANGING
, sent
|wparam
|optional
, 0 },
61 { WM_WINDOWPOSCHANGED
, sent
|optional
},
62 { WM_ACTIVATEAPP
, sent
|wparam
, 1 },
63 { WM_NCACTIVATE
, sent
},
64 { WM_ACTIVATE
, sent
|wparam
, 1 },
65 { WM_IME_SETCONTEXT
, sent
|wparam
|defwinproc
|optional
, 1 },
66 { WM_IME_NOTIFY
, sent
|defwinproc
|optional
},
67 { WM_SETFOCUS
, sent
|wparam
|defwinproc
, 0 },
68 /* Win9x adds SWP_NOZORDER below */
69 { WM_WINDOWPOSCHANGED
, sent
, /*|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ },
70 { WM_NCCALCSIZE
, sent
|wparam
|optional
, 1 },
76 static const struct message create_monthcal_control_seq
[] = {
77 { WM_NOTIFYFORMAT
, sent
|lparam
, 0, NF_QUERY
},
78 { WM_QUERYUISTATE
, sent
|optional
},
80 { WM_PARENTNOTIFY
, sent
|wparam
, WM_CREATE
},
84 static const struct message create_monthcal_multi_sel_style_seq
[] = {
85 { WM_NOTIFYFORMAT
, sent
|lparam
, 0, NF_QUERY
},
86 { WM_QUERYUISTATE
, sent
|optional
},
88 { WM_PARENTNOTIFY
, sent
},
92 static const struct message monthcal_curr_date_seq
[] = {
93 { MCM_SETCURSEL
, sent
|wparam
, 0},
94 { WM_PAINT
, sent
|wparam
|lparam
|defwinproc
, 0, 0},
95 { MCM_SETCURSEL
, sent
|wparam
, 0},
96 { MCM_SETCURSEL
, sent
|wparam
, 0},
97 { MCM_GETCURSEL
, sent
|wparam
, 0},
98 { MCM_GETCURSEL
, sent
|wparam
|lparam
, 0, 0},
102 static const struct message monthcal_first_day_seq
[] = {
103 { MCM_GETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 0},
105 { MCM_SETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, -5},
106 { MCM_GETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 0},
108 { MCM_SETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, -4},
109 { MCM_GETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 0},
111 { MCM_SETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, -3},
112 { MCM_GETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 0},
114 { MCM_SETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, -2},
115 { MCM_GETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 0},
117 { MCM_SETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, -1},
118 { MCM_GETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 0},
120 { MCM_SETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 0},
121 { MCM_GETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 0},
123 { MCM_SETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 1},
124 { MCM_GETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 0},
126 { MCM_SETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 2},
127 { MCM_GETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 0},
129 { MCM_SETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 3},
130 { MCM_GETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 0},
132 { MCM_SETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 4},
133 { MCM_GETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 0},
135 { MCM_SETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 5},
136 { MCM_GETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 0},
138 { MCM_SETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 6},
139 { MCM_GETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 0},
141 { MCM_SETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 7},
142 { MCM_GETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 0},
144 { MCM_SETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 8},
145 { MCM_GETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 0},
147 { MCM_SETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 9},
148 { MCM_GETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 0},
150 { MCM_SETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 10},
151 { MCM_GETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 0},
153 { MCM_SETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 11},
154 { MCM_GETFIRSTDAYOFWEEK
, sent
|wparam
|lparam
, 0, 0},
158 static const struct message monthcal_unicode_seq
[] = {
159 { MCM_GETUNICODEFORMAT
, sent
|wparam
|lparam
, 0, 0},
160 { MCM_SETUNICODEFORMAT
, sent
|wparam
|lparam
, 1, 0},
161 { MCM_GETUNICODEFORMAT
, sent
|wparam
|lparam
, 0, 0},
162 { MCM_SETUNICODEFORMAT
, sent
|wparam
|lparam
, 0, 0},
163 { MCM_GETUNICODEFORMAT
, sent
|wparam
|lparam
, 0, 0},
164 { MCM_SETUNICODEFORMAT
, sent
|wparam
|lparam
, 1, 0},
168 static const struct message monthcal_hit_test_seq
[] = {
169 { MCM_SETCURSEL
, sent
|wparam
, 0},
170 { WM_PAINT
, sent
|wparam
|lparam
|defwinproc
, 0, 0},
171 { MCM_HITTEST
, sent
|wparam
, 0},
172 { MCM_HITTEST
, sent
|wparam
, 0},
173 { MCM_HITTEST
, sent
|wparam
, 0},
174 { MCM_HITTEST
, sent
|wparam
, 0},
175 { MCM_HITTEST
, sent
|wparam
, 0},
176 { MCM_HITTEST
, sent
|wparam
, 0},
177 { MCM_HITTEST
, sent
|wparam
, 0},
178 { MCM_HITTEST
, sent
|wparam
, 0},
179 { MCM_HITTEST
, sent
|wparam
, 0},
180 { MCM_HITTEST
, sent
|wparam
, 0},
184 static const struct message monthcal_todaylink_seq
[] = {
185 { MCM_HITTEST
, sent
|wparam
, 0},
186 { MCM_SETTODAY
, sent
|wparam
, 0},
187 { WM_PAINT
, sent
|wparam
|lparam
|defwinproc
, 0, 0},
188 { MCM_GETTODAY
, sent
|wparam
, 0},
189 { WM_LBUTTONDOWN
, sent
|wparam
, MK_LBUTTON
},
190 { WM_CAPTURECHANGED
, sent
|wparam
|lparam
|defwinproc
, 0, 0},
191 { WM_PAINT
, sent
|wparam
|lparam
|defwinproc
, 0, 0},
192 { MCM_GETCURSEL
, sent
|wparam
, 0},
196 static const struct message monthcal_today_seq
[] = {
197 { MCM_SETTODAY
, sent
|wparam
, 0},
198 { WM_PAINT
, sent
|wparam
|lparam
|defwinproc
, 0, 0},
199 { MCM_GETTODAY
, sent
|wparam
, 0},
200 { MCM_SETTODAY
, sent
|wparam
, 0},
201 { WM_PAINT
, sent
|wparam
|lparam
|defwinproc
, 0, 0},
202 { MCM_GETTODAY
, sent
|wparam
, 0},
206 static const struct message monthcal_scroll_seq
[] = {
207 { MCM_SETMONTHDELTA
, sent
|wparam
|lparam
, 2, 0},
208 { MCM_SETMONTHDELTA
, sent
|wparam
|lparam
, 3, 0},
209 { MCM_GETMONTHDELTA
, sent
|wparam
|lparam
, 0, 0},
210 { MCM_SETMONTHDELTA
, sent
|wparam
|lparam
, 12, 0},
211 { MCM_GETMONTHDELTA
, sent
|wparam
|lparam
, 0, 0},
212 { MCM_SETMONTHDELTA
, sent
|wparam
|lparam
, 15, 0},
213 { MCM_GETMONTHDELTA
, sent
|wparam
|lparam
, 0, 0},
214 { MCM_SETMONTHDELTA
, sent
|wparam
|lparam
, -5, 0},
215 { MCM_GETMONTHDELTA
, sent
|wparam
|lparam
, 0, 0},
219 static const struct message monthcal_monthrange_seq
[] = {
220 { MCM_GETMONTHRANGE
, sent
|wparam
, GMR_VISIBLE
},
221 { MCM_GETMONTHRANGE
, sent
|wparam
, GMR_DAYSTATE
},
225 static const struct message monthcal_max_sel_day_seq
[] = {
226 { MCM_SETMAXSELCOUNT
, sent
|wparam
|lparam
, 5, 0},
227 { MCM_GETMAXSELCOUNT
, sent
|wparam
|lparam
, 0, 0},
228 { MCM_SETMAXSELCOUNT
, sent
|wparam
|lparam
, 15, 0},
229 { MCM_GETMAXSELCOUNT
, sent
|wparam
|lparam
, 0, 0},
230 { MCM_SETMAXSELCOUNT
, sent
|wparam
|lparam
, -1, 0},
231 { MCM_GETMAXSELCOUNT
, sent
|wparam
|lparam
, 0, 0},
235 /* expected message sequence for parent*/
236 static const struct message destroy_monthcal_parent_msgs_seq
[] = {
237 { WM_PARENTNOTIFY
, sent
|wparam
, WM_DESTROY
},
241 /* expected message sequence for child*/
242 static const struct message destroy_monthcal_child_msgs_seq
[] = {
243 { 0x0090, sent
|optional
}, /* Vista */
244 { WM_SHOWWINDOW
, sent
|wparam
|lparam
, 0, 0},
245 { WM_WINDOWPOSCHANGING
, sent
|wparam
, 0},
246 { WM_WINDOWPOSCHANGED
, sent
|wparam
, 0},
247 { WM_DESTROY
, sent
|wparam
|lparam
, 0, 0},
248 { WM_NCDESTROY
, sent
|wparam
|lparam
, 0, 0},
252 static const struct message destroy_monthcal_multi_sel_style_seq
[] = {
253 { 0x0090, sent
|optional
}, /* Vista */
254 { WM_SHOWWINDOW
, sent
|wparam
|lparam
, 0, 0},
255 { WM_WINDOWPOSCHANGING
, sent
|wparam
, 0},
256 { WM_WINDOWPOSCHANGED
, sent
|wparam
, 0},
257 { WM_DESTROY
, sent
|wparam
|lparam
, 0, 0},
258 { WM_NCDESTROY
, sent
|wparam
|lparam
, 0, 0},
262 static void test_monthcal(void)
265 SYSTEMTIME st
[2], st1
[2], today
;
266 int res
, month_range
;
269 hwnd
= CreateWindowA(MONTHCAL_CLASSA
, "MonthCal", WS_POPUP
| WS_VISIBLE
, CW_USEDEFAULT
,
270 0, 300, 300, 0, 0, NULL
, NULL
);
271 ok(hwnd
!= NULL
, "Failed to create MonthCal\n");
273 /* test range just after creation */
274 memset(&st
, 0xcc, sizeof(st
));
275 limits
= SendMessageA(hwnd
, MCM_GETRANGE
, 0, (LPARAM
)st
);
277 broken(limits
== GDTR_MIN
), /* comctl32 <= 4.70 */
278 "No limits should be set (%d)\n", limits
);
279 if (limits
== GDTR_MIN
)
281 win_skip("comctl32 <= 4.70 is broken\n");
286 ok(0 == st
[0].wYear
||
287 broken(1752 == st
[0].wYear
), /* comctl32 <= 4.72 */
288 "Expected 0, got %d\n", st
[0].wYear
);
289 ok(0 == st
[0].wMonth
||
290 broken(9 == st
[0].wMonth
), /* comctl32 <= 4.72 */
291 "Expected 0, got %d\n", st
[0].wMonth
);
292 ok(0 == st
[0].wDay
||
293 broken(14 == st
[0].wDay
), /* comctl32 <= 4.72 */
294 "Expected 0, got %d\n", st
[0].wDay
);
295 expect(0, st
[0].wDayOfWeek
);
296 expect(0, st
[0].wHour
);
297 expect(0, st
[0].wMinute
);
298 expect(0, st
[0].wSecond
);
299 expect(0, st
[0].wMilliseconds
);
301 expect(0, st
[1].wYear
);
302 expect(0, st
[1].wMonth
);
303 expect(0, st
[1].wDay
);
304 expect(0, st
[1].wDayOfWeek
);
305 expect(0, st
[1].wHour
);
306 expect(0, st
[1].wMinute
);
307 expect(0, st
[1].wSecond
);
308 expect(0, st
[1].wMilliseconds
);
310 GetSystemTime(&st
[0]);
313 SendMessageA(hwnd
, MCM_GETTODAY
, 0, (LPARAM
)&today
);
315 /* Invalid date/time */
317 /* Time should not matter */
318 st
[1].wHour
= st
[1].wMinute
= st
[1].wSecond
= 70;
319 st
[1].wMilliseconds
= 1200;
320 ok(SendMessageA(hwnd
, MCM_SETRANGE
, GDTR_MAX
, (LPARAM
)st
), "Failed to set MAX limit\n");
321 /* invalid timestamp is written back with today data and msecs untouched */
322 expect(today
.wHour
, st
[1].wHour
);
323 expect(today
.wMinute
, st
[1].wMinute
);
324 expect(today
.wSecond
, st
[1].wSecond
);
325 expect(1200, st
[1].wMilliseconds
);
327 ok(SendMessageA(hwnd
, MCM_GETRANGE
, 0, (LPARAM
)st1
) == GDTR_MAX
, "No limits should be set\n");
328 ok(st1
[0].wYear
!= 2000, "Lower limit changed\n");
329 /* invalid timestamp should be replaced with today data, except msecs */
330 expect(today
.wHour
, st1
[1].wHour
);
331 expect(today
.wMinute
, st1
[1].wMinute
);
332 expect(today
.wSecond
, st1
[1].wSecond
);
333 expect(1200, st1
[1].wMilliseconds
);
335 /* Invalid date/time with invalid milliseconds only */
336 GetSystemTime(&st
[0]);
338 /* Time should not matter */
339 st
[1].wMilliseconds
= 1200;
340 ok(SendMessageA(hwnd
, MCM_SETRANGE
, GDTR_MAX
, (LPARAM
)st
), "Failed to set MAX limit\n");
341 /* invalid milliseconds field doesn't lead to invalid timestamp */
342 expect(st
[0].wHour
, st
[1].wHour
);
343 expect(st
[0].wMinute
, st
[1].wMinute
);
344 expect(st
[0].wSecond
, st
[1].wSecond
);
345 expect(1200, st
[1].wMilliseconds
);
347 GetSystemTime(&st
[0]);
350 ok(!SendMessageA(hwnd
, MCM_SETRANGE
, GDTR_MIN
| GDTR_MAX
, (LPARAM
)st
),
351 "Should have failed to set limits\n");
352 ok(SendMessageA(hwnd
, MCM_GETRANGE
, 0, (LPARAM
)st1
) == GDTR_MAX
, "No limits should be set\n");
353 ok(st1
[0].wYear
!= 2000, "Lower limit changed\n");
354 ok(!SendMessageA(hwnd
, MCM_SETRANGE
, GDTR_MAX
, (LPARAM
)st
),
355 "Should have failed to set MAX limit\n");
356 ok(SendMessageA(hwnd
, MCM_GETRANGE
, 0, (LPARAM
)st1
) == GDTR_MAX
, "No limits should be set\n");
357 ok(st1
[0].wYear
!= 2000, "Lower limit changed\n");
359 GetSystemTime(&st
[0]);
364 month_range
= SendMessageA(hwnd
, MCM_GETMONTHRANGE
, GMR_VISIBLE
, (LPARAM
)st1
);
366 ok(SendMessageA(hwnd
, MCM_SETRANGE
, GDTR_MIN
| GDTR_MAX
, (LPARAM
)st
),
367 "Failed to set both min and max limits\n");
368 res
= SendMessageA(hwnd
, MCM_GETMONTHRANGE
, GMR_VISIBLE
, (LPARAM
)st1
);
369 ok(res
== month_range
, "Invalid month range (%d)\n", res
);
370 ok(SendMessageA(hwnd
, MCM_GETRANGE
, 0, (LPARAM
)st1
) == (GDTR_MIN
|GDTR_MAX
),
371 "Limits should be set\n");
374 ok(SendMessageA(hwnd
, MCM_SETRANGE
, GDTR_MIN
| GDTR_MAX
, (LPARAM
)st
),
375 "Failed to set both min and max limits\n");
376 res
= SendMessageA(hwnd
, MCM_GETMONTHRANGE
, GMR_VISIBLE
, (LPARAM
)st1
);
377 ok(res
== month_range
, "Invalid month range (%d)\n", res
);
380 ok(SendMessageA(hwnd
, MCM_SETRANGE
, GDTR_MIN
| GDTR_MAX
, (LPARAM
)st
),
381 "Failed to set both min and max limits\n");
383 ok(SendMessageA(hwnd
, MCM_SETRANGE
, GDTR_MIN
| GDTR_MAX
, (LPARAM
)st
),
384 "Failed to set both min and max limits\n");
387 ok(SendMessageA(hwnd
, MCM_SETRANGE
, GDTR_MAX
, (LPARAM
)st
), "Failed to set max limit\n");
388 ok(SendMessageA(hwnd
, MCM_GETRANGE
, 0, (LPARAM
)st1
) == GDTR_MAX
,
389 "Only MAX limit should be set\n");
391 ok(SendMessageA(hwnd
, MCM_SETRANGE
, GDTR_MAX
, (LPARAM
)st
), "Failed to set max limit\n");
393 ok(SendMessageA(hwnd
, MCM_SETRANGE
, GDTR_MAX
, (LPARAM
)st
), "Failed to set max limit\n");
395 ok(SendMessageA(hwnd
, MCM_SETRANGE
, GDTR_MAX
, (LPARAM
)st
), "Failed to set max limit\n");
396 ok(SendMessageA(hwnd
, MCM_GETRANGE
, 0, (LPARAM
)st1
) == GDTR_MAX
,
397 "Only MAX limit should be set\n");
399 /* set both limits, then set max < min */
400 GetSystemTime(&st
[0]);
404 ok(SendMessageA(hwnd
, MCM_SETRANGE
, GDTR_MIN
|GDTR_MAX
, (LPARAM
)st
), "Failed to set limits\n");
405 ok(SendMessageA(hwnd
, MCM_GETRANGE
, 0, (LPARAM
)st1
) == (GDTR_MIN
|GDTR_MAX
),
406 "Min limit expected\n");
408 ok(SendMessageA(hwnd
, MCM_SETRANGE
, GDTR_MAX
, (LPARAM
)st
), "Failed to set limits\n");
409 ok(SendMessageA(hwnd
, MCM_GETRANGE
, 0, (LPARAM
)st1
) == GDTR_MAX
, "Max limit expected\n");
411 expect(0, st1
[0].wYear
);
412 expect(0, st1
[0].wMonth
);
413 expect(0, st1
[0].wDay
);
414 expect(0, st1
[0].wDayOfWeek
);
415 expect(0, st1
[0].wHour
);
416 expect(0, st1
[0].wMinute
);
417 expect(0, st1
[0].wSecond
);
418 expect(0, st1
[0].wMilliseconds
);
420 expect(st
[1].wYear
, st1
[1].wYear
);
421 expect(st
[1].wMonth
, st1
[1].wMonth
);
422 expect(st
[1].wDay
, st1
[1].wDay
);
423 expect(st
[1].wDayOfWeek
, st1
[1].wDayOfWeek
);
424 expect(st
[1].wHour
, st1
[1].wHour
);
425 expect(st
[1].wMinute
, st1
[1].wMinute
);
426 expect(st
[1].wSecond
, st1
[1].wSecond
);
427 expect(st
[1].wMilliseconds
, st1
[1].wMilliseconds
);
431 ok(SendMessageA(hwnd
, MCM_SETRANGE
, GDTR_MIN
|GDTR_MAX
, (LPARAM
)st
), "Failed to set limits\n");
432 ok(SendMessageA(hwnd
, MCM_GETRANGE
, 0, (LPARAM
)st1
) == (GDTR_MIN
|GDTR_MAX
),
433 "Min limit expected\n");
434 st
[0].wYear
++; /* start == end now */
435 ok(SendMessageA(hwnd
, MCM_SETRANGE
, GDTR_MIN
, (LPARAM
)st
), "Failed to set limits\n");
436 ok(SendMessageA(hwnd
, MCM_GETRANGE
, 0, (LPARAM
)st1
) == GDTR_MIN
, "Min limit expected\n");
438 expect(st
[0].wYear
, st1
[0].wYear
);
439 expect(st
[0].wMonth
, st1
[0].wMonth
);
440 expect(st
[0].wDay
, st1
[0].wDay
);
441 expect(st
[0].wDayOfWeek
, st1
[0].wDayOfWeek
);
442 expect(st
[0].wHour
, st1
[0].wHour
);
443 expect(st
[0].wMinute
, st1
[0].wMinute
);
444 expect(st
[0].wSecond
, st1
[0].wSecond
);
445 expect(st
[0].wMilliseconds
, st1
[0].wMilliseconds
);
447 expect(0, st1
[1].wYear
);
448 expect(0, st1
[1].wMonth
);
449 expect(0, st1
[1].wDay
);
450 expect(0, st1
[1].wDayOfWeek
);
451 expect(0, st1
[1].wHour
);
452 expect(0, st1
[1].wMinute
);
453 expect(0, st1
[1].wSecond
);
454 expect(0, st1
[1].wMilliseconds
);
459 static LRESULT WINAPI
parent_wnd_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
461 static LONG defwndproc_counter
= 0;
465 /* log system messages, except for painting */
466 if (message
< WM_USER
&&
467 message
!= WM_PAINT
&&
468 message
!= WM_ERASEBKGND
&&
469 message
!= WM_NCPAINT
&&
470 message
!= WM_NCHITTEST
&&
471 message
!= WM_GETTEXT
&&
472 message
!= WM_GETICON
&&
473 message
!= WM_DEVICECHANGE
)
475 msg
.message
= message
;
476 msg
.flags
= sent
|wparam
|lparam
;
477 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
480 add_message(sequences
, PARENT_SEQ_INDEX
, &msg
);
483 if (message
== WM_NOTIFY
)
485 NMHDR
*hdr
= (NMHDR
*)lParam
;
488 case MCN_GETDAYSTATE
:
490 NMDAYSTATE
*nmstate
= (NMDAYSTATE
*)lParam
;
491 static MONTHDAYSTATE months
[14] = { 0 };
493 ok(nmstate
->cDayState
> 0, "got %d\n", nmstate
->cDayState
);
494 ok(nmstate
->cDayState
<= 14, "got %d\n", nmstate
->cDayState
);
495 ok(nmstate
->prgDayState
!= NULL
, "got %p\n", nmstate
->prgDayState
);
497 nmstate
->prgDayState
= months
;
504 NMSELCHANGE
*nmchg
= (NMSELCHANGE
*)lParam
;
506 BOOL is_multisel
= GetWindowLongPtrA(nmchg
->nmhdr
.hwndFrom
, GWL_STYLE
) & MCS_MULTISELECT
;
508 if(GetWindowLongPtrA(nmchg
->nmhdr
.hwndFrom
, GWLP_ID
) != SEL_NOTIFY_TEST_ID
)
510 SendMessageA(nmchg
->nmhdr
.hwndFrom
, is_multisel
? MCM_GETSELRANGE
: MCM_GETCURSEL
,
513 expect(st
[0].wYear
, nmchg
->stSelStart
.wYear
);
514 expect(st
[0].wMonth
, nmchg
->stSelStart
.wMonth
);
515 expect(0, nmchg
->stSelStart
.wDayOfWeek
);
516 expect(st
[0].wDay
, nmchg
->stSelStart
.wDay
);
520 expect(st
[1].wYear
, nmchg
->stSelEnd
.wYear
);
521 expect(st
[1].wMonth
, nmchg
->stSelEnd
.wMonth
);
522 expect(0, nmchg
->stSelEnd
.wDayOfWeek
);
523 expect(st
[1].wDay
, nmchg
->stSelEnd
.wDay
);
526 ok(!(nmchg
->stSelEnd
.wYear
| nmchg
->stSelEnd
.wMonth
|
527 nmchg
->stSelEnd
.wDayOfWeek
| nmchg
->stSelEnd
.wDay
|
528 nmchg
->stSelEnd
.wHour
| nmchg
->stSelEnd
.wMinute
|
529 nmchg
->stSelEnd
.wSecond
| nmchg
->stSelEnd
.wMilliseconds
),
530 "Non-zero member in stSelEnd\n");
538 defwndproc_counter
++;
539 ret
= DefWindowProcA(hwnd
, message
, wParam
, lParam
);
540 defwndproc_counter
--;
545 static BOOL
register_parent_wnd_class(void)
550 cls
.lpfnWndProc
= parent_wnd_proc
;
553 cls
.hInstance
= GetModuleHandleA(NULL
);
555 cls
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
556 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
557 cls
.lpszMenuName
= NULL
;
558 cls
.lpszClassName
= "Month-Cal test parent class";
559 return RegisterClassA(&cls
);
562 static HWND
create_parent_window(void)
566 InitCommonControls();
568 /* flush message sequences, so we can check the new sequence by the end of function */
569 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
571 if (!register_parent_wnd_class())
574 hwnd
= CreateWindowExA(0, "Month-Cal test parent class", "Month-Cal test parent window",
575 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
| WS_VISIBLE
,
576 0, 0, 500, 500, GetDesktopWindow(), NULL
, GetModuleHandleA(NULL
), NULL
);
577 ok(hwnd
!= NULL
, "failed to create parent wnd\n");
579 /* check for message sequences */
580 ok_sequence(sequences
, PARENT_SEQ_INDEX
, create_parent_window_seq
, "create parent window", FALSE
);
585 static LRESULT WINAPI
monthcal_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
587 WNDPROC oldproc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
588 static LONG defwndproc_counter
= 0;
592 msg
.message
= message
;
593 msg
.flags
= sent
|wparam
|lparam
;
594 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
598 add_message(sequences
, MONTHCAL_SEQ_INDEX
, &msg
);
600 /* some debug output for style changing */
601 if ((message
== WM_STYLECHANGING
||
602 message
== WM_STYLECHANGED
) && lParam
)
604 STYLESTRUCT
*style
= (STYLESTRUCT
*)lParam
;
605 trace("\told style: 0x%08x, new style: 0x%08x\n", style
->styleOld
, style
->styleNew
);
608 defwndproc_counter
++;
609 ret
= CallWindowProcA(oldproc
, hwnd
, message
, wParam
, lParam
);
610 defwndproc_counter
--;
615 static HWND
create_monthcal_control(DWORD style
)
622 hwnd
= CreateWindowExA(0, MONTHCAL_CLASSA
, "", WS_CHILD
| WS_BORDER
| WS_VISIBLE
| style
,
623 0, 0, 300, 400, parent_wnd
, NULL
, GetModuleHandleA(NULL
), NULL
);
624 ok(hwnd
!= NULL
, "failed to create monthcal wnd\n");
625 if (!hwnd
) return NULL
;
627 oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
628 (LONG_PTR
)monthcal_subclass_proc
);
629 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
631 SendMessageA(hwnd
, WM_SETFONT
, (WPARAM
)GetStockObject(SYSTEM_FONT
), 0);
633 /* make sure calendar grid is 2x1 */
634 ret
= SendMessageA(hwnd
, MCM_GETMINREQRECT
, 0, (LPARAM
)&rect
);
635 ok(ret
, "got %d\n", ret
);
637 ret
= SetWindowPos(hwnd
, NULL
, 0, 0, rect
.right
* 5 / 2, rect
.bottom
* 3 / 2, SWP_NOMOVE
);
638 ok(ret
, "got %d\n", ret
);
644 /* Setter and Getters Tests */
646 static void test_color(void)
648 COLORREF color
, prev
;
651 hwnd
= create_monthcal_control(0);
653 /* invalid color index */
654 color
= SendMessageA(hwnd
, MCM_GETCOLOR
, MCSC_TRAILINGTEXT
+ 1, 0);
656 prev
= SendMessageA(hwnd
, MCM_SETCOLOR
, MCSC_TRAILINGTEXT
+ 1, RGB(255,255,255));
659 color
= SendMessageA(hwnd
, MCM_GETCOLOR
, MCSC_BACKGROUND
, 0);
660 prev
= SendMessageA(hwnd
, MCM_SETCOLOR
, MCSC_BACKGROUND
, RGB(0,0,0));
662 color
= SendMessageA(hwnd
, MCM_GETCOLOR
, MCSC_BACKGROUND
, 0);
663 expect(RGB(0,0,0), color
);
664 prev
= SendMessageA(hwnd
, MCM_SETCOLOR
, MCSC_BACKGROUND
, RGB(255,255,255));
666 color
= SendMessageA(hwnd
, MCM_GETCOLOR
, MCSC_BACKGROUND
, 0);
667 expect(RGB(255,255,255), color
);
669 color
= SendMessageA(hwnd
, MCM_GETCOLOR
, MCSC_MONTHBK
, 0);
670 prev
= SendMessageA(hwnd
, MCM_SETCOLOR
, MCSC_MONTHBK
, RGB(0,0,0));
672 color
= SendMessageA(hwnd
, MCM_GETCOLOR
, MCSC_MONTHBK
, 0);
673 expect(RGB(0,0,0), color
);
674 prev
= SendMessageA(hwnd
, MCM_SETCOLOR
, MCSC_MONTHBK
, RGB(255,255,255));
676 color
= SendMessageA(hwnd
, MCM_GETCOLOR
, MCSC_MONTHBK
, 0);
677 expect(RGB(255,255,255), color
);
679 color
= SendMessageA(hwnd
, MCM_GETCOLOR
, MCSC_TEXT
, 0);
680 prev
= SendMessageA(hwnd
, MCM_SETCOLOR
, MCSC_TEXT
, RGB(0,0,0));
682 color
= SendMessageA(hwnd
, MCM_GETCOLOR
, MCSC_TEXT
, 0);
683 expect(RGB(0,0,0), color
);
684 prev
= SendMessageA(hwnd
, MCM_SETCOLOR
, MCSC_TEXT
, RGB(255,255,255));
686 color
= SendMessageA(hwnd
, MCM_GETCOLOR
, MCSC_TEXT
, 0);
687 expect(RGB(255,255,255), color
);
689 color
= SendMessageA(hwnd
, MCM_GETCOLOR
, MCSC_TITLEBK
, 0);
690 prev
= SendMessageA(hwnd
, MCM_SETCOLOR
, MCSC_TITLEBK
, RGB(0,0,0));
692 color
= SendMessageA(hwnd
, MCM_GETCOLOR
, MCSC_TITLEBK
, 0);
693 expect(RGB(0,0,0), color
);
694 prev
= SendMessageA(hwnd
, MCM_SETCOLOR
, MCSC_TITLEBK
, RGB(255,255,255));
696 color
= SendMessageA(hwnd
, MCM_GETCOLOR
, MCSC_TITLEBK
, 0);
697 expect(RGB(255,255,255), color
);
699 color
= SendMessageA(hwnd
, MCM_GETCOLOR
, MCSC_TITLETEXT
, 0);
700 prev
= SendMessageA(hwnd
, MCM_SETCOLOR
, MCSC_TITLETEXT
, RGB(0,0,0));
702 color
= SendMessageA(hwnd
, MCM_GETCOLOR
, MCSC_TITLETEXT
, 0);
703 expect(RGB(0,0,0), color
);
704 prev
= SendMessageA(hwnd
, MCM_SETCOLOR
, MCSC_TITLETEXT
, RGB(255,255,255));
706 color
= SendMessageA(hwnd
, MCM_GETCOLOR
, MCSC_TITLETEXT
, 0);
707 expect(RGB(255,255,255), color
);
709 color
= SendMessageA(hwnd
, MCM_GETCOLOR
, MCSC_TRAILINGTEXT
, 0);
710 prev
= SendMessageA(hwnd
, MCM_SETCOLOR
, MCSC_TRAILINGTEXT
, RGB(0,0,0));
712 color
= SendMessageA(hwnd
, MCM_GETCOLOR
, MCSC_TRAILINGTEXT
, 0);
713 expect(RGB(0,0,0), color
);
714 prev
= SendMessageA(hwnd
, MCM_SETCOLOR
, MCSC_TRAILINGTEXT
, RGB(255,255,255));
716 color
= SendMessageA(hwnd
, MCM_GETCOLOR
, MCSC_TRAILINGTEXT
, 0);
717 expect(RGB(255,255,255), color
);
722 static void test_currdate(void)
724 SYSTEMTIME st_original
, st_new
, st_test
;
728 hwnd
= create_monthcal_control(0);
730 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
732 /* Setter and Getters for current date selected */
733 st_original
.wYear
= 2000;
734 st_original
.wMonth
= 11;
735 st_original
.wDay
= 28;
736 st_original
.wHour
= 11;
737 st_original
.wMinute
= 59;
738 st_original
.wSecond
= 30;
739 st_original
.wMilliseconds
= 0;
740 st_original
.wDayOfWeek
= 0;
742 st_new
= st_test
= st_original
;
744 /* Should not validate the time */
745 res
= SendMessageA(hwnd
, MCM_SETCURSEL
, 0, (LPARAM
)&st_test
);
748 /* Overflow matters, check for wDay */
750 res
= SendMessageA(hwnd
, MCM_SETCURSEL
, 0, (LPARAM
)&st_test
);
753 /* correct wDay before checking for wMonth */
755 expect(st_original
.wDay
, st_test
.wDay
);
757 /* Overflow matters, check for wMonth */
759 res
= SendMessageA(hwnd
, MCM_SETCURSEL
, 0, (LPARAM
)&st_test
);
762 /* checking if gets the information right, modify st_new */
770 res
= SendMessageA(hwnd
, MCM_GETCURSEL
, 0, (LPARAM
)&st_new
);
773 /* st_new change to st_origin, above settings with overflow */
774 /* should not change the current settings */
775 expect(st_original
.wYear
, st_new
.wYear
);
776 expect(st_original
.wMonth
, st_new
.wMonth
);
777 expect(st_original
.wDay
, st_new
.wDay
);
778 ok(st_original
.wHour
== st_new
.wHour
||
779 broken(0 == st_new
.wHour
), /* comctl32 <= 4.70 */
780 "Expected %d, got %d\n", st_original
.wHour
, st_new
.wHour
);
781 ok(st_original
.wMinute
== st_new
.wMinute
||
782 broken(0 == st_new
.wMinute
), /* comctl32 <= 4.70 */
783 "Expected %d, got %d\n", st_original
.wMinute
, st_new
.wMinute
);
784 ok(st_original
.wSecond
== st_new
.wSecond
||
785 broken(0 == st_new
.wSecond
), /* comctl32 <= 4.70 */
786 "Expected %d, got %d\n", st_original
.wSecond
, st_new
.wSecond
);
788 /* lparam cannot be NULL */
789 res
= SendMessageA(hwnd
, MCM_GETCURSEL
, 0, 0);
792 ok_sequence(sequences
, MONTHCAL_SEQ_INDEX
, monthcal_curr_date_seq
, "monthcal currDate", TRUE
);
794 /* December, 31, 9999 is the maximum allowed date */
795 memset(&st_new
, 0, sizeof(st_new
));
799 res
= SendMessageA(hwnd
, MCM_SETCURSEL
, 0, (LPARAM
)&st_new
);
801 memset(&st_test
, 0, sizeof(st_test
));
802 res
= SendMessageA(hwnd
, MCM_GETCURSEL
, 0, (LPARAM
)&st_test
);
804 expect(st_new
.wYear
, st_test
.wYear
);
805 expect(st_new
.wMonth
, st_test
.wMonth
);
806 expect(st_new
.wDay
, st_test
.wDay
);
807 expect(st_new
.wHour
, st_test
.wHour
);
808 expect(st_new
.wMinute
, st_test
.wMinute
);
809 expect(st_new
.wSecond
, st_test
.wSecond
);
810 /* try one day later */
811 st_original
= st_new
;
812 st_new
.wYear
= 10000;
815 res
= SendMessageA(hwnd
, MCM_SETCURSEL
, 0, (LPARAM
)&st_new
);
817 broken(1 == res
), /* comctl32 <= 4.72 */
818 "Expected 0, got %d\n", res
);
821 memset(&st_test
, 0, sizeof(st_test
));
822 res
= SendMessageA(hwnd
, MCM_GETCURSEL
, 0, (LPARAM
)&st_test
);
824 expect(st_original
.wYear
, st_test
.wYear
);
825 expect(st_original
.wMonth
, st_test
.wMonth
);
826 expect(st_original
.wDay
, st_test
.wDay
);
827 expect(st_original
.wHour
, st_test
.wHour
);
828 expect(st_original
.wMinute
, st_test
.wMinute
);
829 expect(st_original
.wSecond
, st_test
.wSecond
);
832 /* setting selection equal to current reports success even if out range */
833 memset(&st_new
, 0, sizeof(st_new
));
837 res
= SendMessageA(hwnd
, MCM_SETCURSEL
, 0, (LPARAM
)&st_new
);
839 memset(&st_test
, 0, sizeof(st_test
));
840 st_test
.wYear
= 2009;
843 res
= SendMessageA(hwnd
, MCM_SETRANGE
, GDTR_MIN
, (LPARAM
)&st_test
);
845 /* set to current again */
846 res
= SendMessageA(hwnd
, MCM_SETCURSEL
, 0, (LPARAM
)&st_new
);
849 /* set with invalid day of week */
850 memset(&st_test
, 0, sizeof(st_test
));
851 st_test
.wYear
= 2009;
854 st_test
.wDayOfWeek
= 100;
855 res
= SendMessageA(hwnd
, MCM_SETCURSEL
, 0, (LPARAM
)&st_test
);
858 memset(&st_test
, 0, sizeof(st_test
));
859 res
= SendMessageA(hwnd
, MCM_GETCURSEL
, 0, (LPARAM
)&st_test
);
861 expect(2009, st_test
.wYear
);
862 expect(7, st_test
.wDay
);
863 expect(10, st_test
.wMonth
);
864 expect(3, st_test
.wDayOfWeek
);
869 static void test_firstDay(void)
871 int res
, fday
, i
, prev
;
872 CHAR b
[128], caltype
[3];
873 LCID lcid
= LOCALE_USER_DEFAULT
;
877 SetLastError(0xdeadbeef);
878 ret
= GetLocaleInfoA(lcid
, LOCALE_ICALENDARTYPE
, caltype
, 3);
880 skip("Must know local calendar type (%x)\n", GetLastError());
882 } else if (atoi(caltype
) != CAL_GREGORIAN
) {
883 skip("MonthCalendar Control only supports Gregorian calendar (type: %s)\n", caltype
);
887 hwnd
= create_monthcal_control(0);
889 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
891 /* Setter and Getters for first day of week */
892 /* check for locale first day */
893 if(GetLocaleInfoA(lcid
, LOCALE_IFIRSTDAYOFWEEK
, b
, 128)){
895 res
= SendMessageA(hwnd
, MCM_GETFIRSTDAYOFWEEK
, 0, 0);
899 /* checking for the values that actually will be stored as */
900 /* current first day when we set a new value */
901 for (i
= -5; i
< 12; i
++){
902 res
= SendMessageA(hwnd
, MCM_SETFIRSTDAYOFWEEK
, 0, i
);
904 res
= SendMessageA(hwnd
, MCM_GETFIRSTDAYOFWEEK
, 0, 0);
908 expect(MAKELONG(fday
, FALSE
), res
);
910 /* out of range sets max first day of week, locale is ignored */
911 expect(MAKELONG(6, TRUE
), res
);
913 expect(MAKELONG(i
, TRUE
), res
);
917 ok_sequence(sequences
, MONTHCAL_SEQ_INDEX
, monthcal_first_day_seq
, "monthcal firstDay", FALSE
);
920 skip("Cannot retrieve first day of the week\n");
926 static void test_unicode(void)
931 hwnd
= create_monthcal_control(0);
933 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
935 /* Setter and Getters for Unicode format */
937 /* getting the current settings */
938 temp
= SendMessageA(hwnd
, MCM_GETUNICODEFORMAT
, 0, 0);
940 /* setting to 1, should return previous settings */
941 res
= SendMessageA(hwnd
, MCM_SETUNICODEFORMAT
, 1, 0);
944 /* current setting is 1, so, should return 1 */
945 res
= SendMessageA(hwnd
, MCM_GETUNICODEFORMAT
, 0, 0);
947 broken(0 == res
), /* comctl32 <= 4.70 */
948 "Expected 1, got %d\n", res
);
950 /* setting to 0, should return previous settings */
951 res
= SendMessageA(hwnd
, MCM_SETUNICODEFORMAT
, 0, 0);
953 broken(0 == res
), /* comctl32 <= 4.70 */
954 "Expected 1, got %d\n", res
);
956 /* current setting is 0, so, it should return 0 */
957 res
= SendMessageA(hwnd
, MCM_GETUNICODEFORMAT
, 0, 0);
960 /* should return previous settings */
961 res
= SendMessageA(hwnd
, MCM_SETUNICODEFORMAT
, 1, 0);
964 ok_sequence(sequences
, MONTHCAL_SEQ_INDEX
, monthcal_unicode_seq
, "monthcal unicode", FALSE
);
969 static void test_hittest(void)
971 typedef struct hittest_test
977 static const hittest_test_t title_hits
[] = {
978 /* Start is the same everywhere */
979 { MCHT_TITLE
, FALSE
},
980 { MCHT_TITLEBTNPREV
, FALSE
},
981 /* The middle piece is only tested for presence of items */
982 /* End is the same everywhere */
983 { MCHT_TITLEBTNNEXT
, FALSE
},
984 { MCHT_TITLE
, FALSE
},
985 { MCHT_NOWHERE
, TRUE
}
995 char yearmonth
[80], *locale_month
, *locale_year
;
996 int month_count
, year_count
;
999 memset(&mchit
, 0, sizeof(MCHITTESTINFO
));
1001 hwnd
= create_monthcal_control(0);
1003 /* test with invalid structure size */
1004 mchit
.cbSize
= MCHITTESTINFO_V1_SIZE
- 1;
1007 res
= SendMessageA(hwnd
, MCM_HITTEST
, 0, (LPARAM
)&mchit
);
1008 expect(0, mchit
.pt
.x
);
1009 expect(0, mchit
.pt
.y
);
1011 expect(0, mchit
.uHit
);
1012 /* test with invalid pointer */
1013 res
= SendMessageA(hwnd
, MCM_HITTEST
, 0, 0);
1016 /* resize control to display single Calendar */
1017 res
= SendMessageA(hwnd
, MCM_GETMINREQRECT
, 0, (LPARAM
)&r
);
1020 win_skip("Message MCM_GETMINREQRECT unsupported. Skipping.\n");
1021 DestroyWindow(hwnd
);
1024 MoveWindow(hwnd
, 0, 0, r
.right
, r
.bottom
, FALSE
);
1026 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1034 st
.wMilliseconds
= 0;
1037 res
= SendMessageA(hwnd
, MCM_SETCURSEL
, 0, (LPARAM
)&st
);
1040 /* (0, 0) is the top left of the control - title */
1041 mchit
.cbSize
= MCHITTESTINFO_V1_SIZE
;
1044 res
= SendMessageA(hwnd
, MCM_HITTEST
, 0, (LPARAM
)&mchit
);
1045 expect(0, mchit
.pt
.x
);
1046 expect(0, mchit
.pt
.y
);
1047 expect(mchit
.uHit
, res
);
1048 expect_hex(MCHT_TITLE
, res
);
1050 /* bottom right of the control and should not be active */
1051 mchit
.pt
.x
= r
.right
;
1052 mchit
.pt
.y
= r
.bottom
;
1053 res
= SendMessageA(hwnd
, MCM_HITTEST
, 0, (LPARAM
)&mchit
);
1054 expect(r
.right
, mchit
.pt
.x
);
1055 expect(r
.bottom
, mchit
.pt
.y
);
1056 expect(mchit
.uHit
, res
);
1057 todo_wine
expect_hex(MCHT_NOWHERE
, res
);
1059 /* completely out of the control, should not be active */
1060 mchit
.pt
.x
= 2 * r
.right
;
1061 mchit
.pt
.y
= 2 * r
.bottom
;
1062 res
= SendMessageA(hwnd
, MCM_HITTEST
, 0, (LPARAM
)&mchit
);
1063 expect(2 * r
.right
, mchit
.pt
.x
);
1064 expect(2 * r
.bottom
, mchit
.pt
.y
);
1065 expect(mchit
.uHit
, res
);
1066 todo_wine
expect_hex(MCHT_NOWHERE
, res
);
1068 /* in active area - day of the week */
1069 mchit
.pt
.x
= r
.right
/ 2;
1070 mchit
.pt
.y
= r
.bottom
/ 2;
1071 res
= SendMessageA(hwnd
, MCM_HITTEST
, 0, (LPARAM
)&mchit
);
1072 expect(r
.right
/ 2, mchit
.pt
.x
);
1073 expect(r
.bottom
/ 2, mchit
.pt
.y
);
1074 expect(mchit
.uHit
, res
);
1075 expect_hex(MCHT_CALENDARDATE
, res
);
1077 /* in active area - day of the week #2 */
1078 mchit
.pt
.x
= r
.right
/ 14; /* half of first day rect */
1079 mchit
.pt
.y
= r
.bottom
/ 2;
1080 res
= SendMessageA(hwnd
, MCM_HITTEST
, 0, (LPARAM
)&mchit
);
1081 expect(r
.right
/ 14, mchit
.pt
.x
);
1082 expect(r
.bottom
/ 2, mchit
.pt
.y
);
1083 expect(mchit
.uHit
, res
);
1084 expect_hex(MCHT_CALENDARDATE
, res
);
1086 /* in active area - date from prev month */
1087 mchit
.pt
.x
= r
.right
/ 14; /* half of first day rect */
1088 mchit
.pt
.y
= 6 * r
.bottom
/ 19;
1089 res
= SendMessageA(hwnd
, MCM_HITTEST
, 0, (LPARAM
)&mchit
);
1090 expect(r
.right
/ 14, mchit
.pt
.x
);
1091 expect(6 * r
.bottom
/ 19, mchit
.pt
.y
);
1092 expect(mchit
.uHit
, res
);
1093 expect_hex(MCHT_CALENDARDATEPREV
, res
);
1097 /* (125, 115) is in active area - date from this month */
1100 res
= SendMessageA(hwnd
, MCM_HITTEST
, 0, (LPARAM
)&mchit
);
1101 expect(125, mchit
.pt
.x
);
1102 expect(115, mchit
.pt
.y
);
1103 expect(mchit
.uHit
, res
);
1104 expect(MCHT_CALENDARDATE
, res
);
1107 /* in active area - date from next month */
1108 mchit
.pt
.x
= 11 * r
.right
/ 14;
1109 mchit
.pt
.y
= 16 * r
.bottom
/ 19;
1110 res
= SendMessageA(hwnd
, MCM_HITTEST
, 0, (LPARAM
)&mchit
);
1111 expect(11 * r
.right
/ 14, mchit
.pt
.x
);
1112 expect(16 * r
.bottom
/ 19, mchit
.pt
.y
);
1113 expect(mchit
.uHit
, res
);
1114 expect_hex(MCHT_CALENDARDATENEXT
, res
);
1116 /* in active area - today link */
1117 mchit
.pt
.x
= r
.right
/ 14;
1118 mchit
.pt
.y
= 18 * r
.bottom
/ 19;
1119 res
= SendMessageA(hwnd
, MCM_HITTEST
, 0, (LPARAM
)&mchit
);
1120 expect(r
.right
/ 14, mchit
.pt
.x
);
1121 expect(18 * r
.bottom
/ 19, mchit
.pt
.y
);
1122 expect(mchit
.uHit
, res
);
1123 expect_hex(MCHT_TODAYLINK
, res
);
1125 /* in active area - today link */
1126 mchit
.pt
.x
= r
.right
/ 2;
1127 mchit
.pt
.y
= 18 * r
.bottom
/ 19;
1128 res
= SendMessageA(hwnd
, MCM_HITTEST
, 0, (LPARAM
)&mchit
);
1129 expect(r
.right
/ 2, mchit
.pt
.x
);
1130 expect(18 * r
.bottom
/ 19, mchit
.pt
.y
);
1131 expect(mchit
.uHit
, res
);
1132 expect_hex(MCHT_TODAYLINK
, res
);
1134 /* in active area - today link */
1135 mchit
.pt
.x
= r
.right
/ 10;
1136 mchit
.pt
.y
= 18 * r
.bottom
/ 19;
1137 res
= SendMessageA(hwnd
, MCM_HITTEST
, 0, (LPARAM
)&mchit
);
1138 expect(r
.right
/ 10, mchit
.pt
.x
);
1139 expect(18 * r
.bottom
/ 19, mchit
.pt
.y
);
1140 expect(mchit
.uHit
, res
);
1141 expect_hex(MCHT_TODAYLINK
, res
);
1143 ok_sequence(sequences
, MONTHCAL_SEQ_INDEX
, monthcal_hit_test_seq
, "monthcal hit test", TRUE
);
1145 /* The horizontal position of title bar elements depends on locale (y pos
1146 is constant), so we sample across a horizontal line and make sure we
1147 find all elements. */
1149 /* Get the format of the title */
1150 GetLocaleInfoA(LOCALE_USER_DEFAULT
, LOCALE_SYEARMONTH
, yearmonth
, 80);
1151 /* Find out if we have a month and/or year */
1152 locale_year
= strstr(yearmonth
, "y");
1153 locale_month
= strstr(yearmonth
, "M");
1156 mchit
.pt
.y
= (5/2) * r
.bottom
/ 19;
1158 old_res
= SendMessageA(hwnd
, MCM_HITTEST
, 0, (LPARAM
)&mchit
);
1159 expect_hex(title_hits
[title_index
].ht
, old_res
);
1161 in_the_middle
= FALSE
;
1162 month_count
= year_count
= 0;
1163 for (x
= 0; x
< r
.right
; x
++){
1165 res
= SendMessageA(hwnd
, MCM_HITTEST
, 0, (LPARAM
)&mchit
);
1166 expect(x
, mchit
.pt
.x
);
1167 expect((5/2) * r
.bottom
/ 19, mchit
.pt
.y
);
1168 expect(mchit
.uHit
, res
);
1169 if (res
!= old_res
) {
1171 if (old_res
== MCHT_TITLEBTNPREV
)
1172 in_the_middle
= TRUE
;
1174 if (res
== MCHT_TITLEBTNNEXT
)
1175 in_the_middle
= FALSE
;
1177 if (in_the_middle
) {
1178 if (res
== MCHT_TITLEMONTH
)
1180 else if (res
== MCHT_TITLEYEAR
)
1185 if (sizeof(title_hits
) / sizeof(title_hits
[0]) <= title_index
)
1188 if (title_hits
[title_index
].todo
) {
1190 ok(title_hits
[title_index
].ht
== res
, "Expected %x, got %x, pos %d\n",
1191 title_hits
[title_index
].ht
, res
, x
);
1193 ok(title_hits
[title_index
].ht
== res
, "Expected %x, got %x, pos %d\n",
1194 title_hits
[title_index
].ht
, res
, x
);
1201 /* There are some limits, even if LOCALE_SYEARMONTH contains rubbish
1202 * or no month/year indicators at all */
1204 todo_wine
ok(month_count
== 1, "Expected 1 month item, got %d\n", month_count
);
1206 ok(month_count
<= 1, "Too many month items: %d\n", month_count
);
1209 todo_wine
ok(year_count
== 1, "Expected 1 year item, got %d\n", year_count
);
1211 ok(year_count
<= 1, "Too many year items: %d\n", year_count
);
1213 todo_wine
ok(month_count
+ year_count
>= 1, "Not enough month and year items\n");
1215 ok(r
.right
<= x
&& title_index
+ 1 == sizeof(title_hits
) / sizeof(title_hits
[0]),
1216 "Wrong title layout\n");
1218 DestroyWindow(hwnd
);
1221 static void test_todaylink(void)
1223 MCHITTESTINFO mchit
;
1224 SYSTEMTIME st_test
, st_new
;
1229 memset(&mchit
, 0, sizeof(MCHITTESTINFO
));
1231 hwnd
= create_monthcal_control(0);
1233 res
= SendMessageA(hwnd
, MCM_GETMINREQRECT
, 0, (LPARAM
)&r
);
1235 MoveWindow(hwnd
, 0, 0, r
.right
, r
.bottom
, FALSE
);
1237 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1239 /* hit active area - today link */
1240 mchit
.cbSize
= MCHITTESTINFO_V1_SIZE
;
1241 mchit
.pt
.x
= r
.right
/ 14;
1242 mchit
.pt
.y
= 18 * r
.bottom
/ 19;
1243 res
= SendMessageA(hwnd
, MCM_HITTEST
, 0, (LPARAM
)&mchit
);
1244 expect(r
.right
/ 14, mchit
.pt
.x
);
1245 expect(18 * r
.bottom
/ 19, mchit
.pt
.y
);
1246 expect(mchit
.uHit
, res
);
1247 expect(MCHT_TODAYLINK
, res
);
1251 st_test
.wYear
= 2005;
1253 res
= SendMessageA(hwnd
, MCM_SETTODAY
, 0, (LPARAM
)&st_test
);
1256 memset(&st_new
, 0, sizeof(st_new
));
1257 res
= SendMessageA(hwnd
, MCM_GETTODAY
, 0, (LPARAM
)&st_new
);
1259 expect(1, st_new
.wDay
);
1260 expect(1, st_new
.wMonth
);
1261 expect(2005, st_new
.wYear
);
1263 res
= SendMessageA(hwnd
, WM_LBUTTONDOWN
, MK_LBUTTON
, MAKELONG(mchit
.pt
.x
, mchit
.pt
.y
));
1266 memset(&st_new
, 0, sizeof(st_new
));
1267 res
= SendMessageA(hwnd
, MCM_GETCURSEL
, 0, (LPARAM
)&st_new
);
1269 expect(1, st_new
.wDay
);
1270 expect(1, st_new
.wMonth
);
1271 expect(2005, st_new
.wYear
);
1273 ok_sequence(sequences
, MONTHCAL_SEQ_INDEX
, monthcal_todaylink_seq
, "monthcal hit test", TRUE
);
1275 DestroyWindow(hwnd
);
1278 static void test_today(void)
1280 SYSTEMTIME st_test
, st_new
;
1284 hwnd
= create_monthcal_control(0);
1286 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1288 /* Setter and Getters for "today" information */
1290 /* check for overflow, should be ok */
1291 memset(&st_test
, 0, sizeof(st_test
));
1293 st_test
.wMonth
= 38;
1298 res
= SendMessageA(hwnd
, MCM_SETTODAY
, 0, (LPARAM
)&st_test
);
1301 res
= SendMessageA(hwnd
, MCM_GETTODAY
, 0, (LPARAM
)&st_new
);
1304 /* st_test should not change */
1305 expect(38, st_test
.wDay
);
1306 expect(38, st_test
.wMonth
);
1308 /* st_new should change, overflow does not matter */
1309 expect(38, st_new
.wDay
);
1310 expect(38, st_new
.wMonth
);
1312 /* check for zero, should be ok*/
1316 res
= SendMessageA(hwnd
, MCM_SETTODAY
, 0, (LPARAM
)&st_test
);
1319 res
= SendMessageA(hwnd
, MCM_GETTODAY
, 0, (LPARAM
)&st_new
);
1322 /* st_test should not change */
1323 expect(0, st_test
.wDay
);
1324 expect(0, st_test
.wMonth
);
1326 /* st_new should change to zero*/
1327 expect(0, st_new
.wDay
);
1328 expect(0, st_new
.wMonth
);
1330 ok_sequence(sequences
, MONTHCAL_SEQ_INDEX
, monthcal_today_seq
, "monthcal today", TRUE
);
1332 DestroyWindow(hwnd
);
1335 static void test_scroll(void)
1340 hwnd
= create_monthcal_control(0);
1342 res
= SendMessageA(hwnd
, MCM_GETMONTHDELTA
, 0, 0);
1345 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1347 /* Setter and Getters for scroll rate */
1348 res
= SendMessageA(hwnd
, MCM_SETMONTHDELTA
, 2, 0);
1351 res
= SendMessageA(hwnd
, MCM_SETMONTHDELTA
, 3, 0);
1353 res
= SendMessageA(hwnd
, MCM_GETMONTHDELTA
, 0, 0);
1356 res
= SendMessageA(hwnd
, MCM_SETMONTHDELTA
, 12, 0);
1358 res
= SendMessageA(hwnd
, MCM_GETMONTHDELTA
, 0, 0);
1361 res
= SendMessageA(hwnd
, MCM_SETMONTHDELTA
, 15, 0);
1363 res
= SendMessageA(hwnd
, MCM_GETMONTHDELTA
, 0, 0);
1366 res
= SendMessageA(hwnd
, MCM_SETMONTHDELTA
, -5, 0);
1368 res
= SendMessageA(hwnd
, MCM_GETMONTHDELTA
, 0, 0);
1371 ok_sequence(sequences
, MONTHCAL_SEQ_INDEX
, monthcal_scroll_seq
, "monthcal scroll", FALSE
);
1373 DestroyWindow(hwnd
);
1376 static void test_monthrange(void)
1379 SYSTEMTIME st_visible
[2], st_daystate
[2], st
;
1383 hwnd
= create_monthcal_control(0);
1385 memset(&st_visible
, 0, sizeof(st_visible
));
1386 memset(&st_daystate
, 0, sizeof(st_daystate
));
1394 st
.wMilliseconds
= 0;
1397 res
= SendMessageA(hwnd
, MCM_SETCURSEL
, 0, (LPARAM
)&st
);
1400 /* to be locale independent */
1401 SendMessageA(hwnd
, MCM_SETFIRSTDAYOFWEEK
, 0, (LPARAM
)6);
1403 res
= SendMessageA(hwnd
, MCM_GETMINREQRECT
, 0, (LPARAM
)&r
);
1405 /* resize control to display two Calendars */
1406 MoveWindow(hwnd
, 0, 0, r
.right
, (5/2)*r
.bottom
, FALSE
);
1408 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1410 res
= SendMessageA(hwnd
, MCM_GETMONTHRANGE
, GMR_VISIBLE
, (LPARAM
)st_visible
);
1412 expect(2000, st_visible
[0].wYear
);
1413 expect(11, st_visible
[0].wMonth
);
1414 expect(1, st_visible
[0].wDay
);
1415 expect(2000, st_visible
[1].wYear
);
1416 expect(12, st_visible
[1].wMonth
);
1417 expect(31, st_visible
[1].wDay
);
1419 res
= SendMessageA(hwnd
, MCM_GETMONTHRANGE
, GMR_DAYSTATE
, (LPARAM
)st_daystate
);
1421 expect(2000, st_daystate
[0].wYear
);
1422 expect(10, st_daystate
[0].wMonth
);
1423 expect(29, st_daystate
[0].wDay
);
1424 expect(2001, st_daystate
[1].wYear
);
1425 expect(1, st_daystate
[1].wMonth
);
1426 expect(6, st_daystate
[1].wDay
);
1428 ok_sequence(sequences
, MONTHCAL_SEQ_INDEX
, monthcal_monthrange_seq
, "monthcal monthrange", FALSE
);
1430 /* with null date array parameter */
1431 res
= SendMessageA(hwnd
, MCM_GETMONTHRANGE
, GMR_VISIBLE
, 0);
1434 res
= SendMessageA(hwnd
, MCM_GETMONTHRANGE
, GMR_DAYSTATE
, 0);
1437 /* resize control to display single Calendar */
1438 MoveWindow(hwnd
, 0, 0, r
.right
, r
.bottom
, FALSE
);
1440 memset(&st
, 0, sizeof(st
));
1445 res
= SendMessageA(hwnd
, MCM_SETCURSEL
, 0, (LPARAM
)&st
);
1448 /* September 1752 has 19 days */
1449 res
= SendMessageA(hwnd
, MCM_GETMONTHRANGE
, GMR_VISIBLE
, (LPARAM
)st_visible
);
1452 expect(1752, st_visible
[0].wYear
);
1453 expect(9, st_visible
[0].wMonth
);
1454 ok(14 == st_visible
[0].wDay
||
1455 broken(1 == st_visible
[0].wDay
), /* comctl32 <= 4.72 */
1456 "Expected 14, got %d\n", st_visible
[0].wDay
);
1458 expect(1752, st_visible
[1].wYear
);
1459 expect(9, st_visible
[1].wMonth
);
1460 expect(19, st_visible
[1].wDay
);
1462 DestroyWindow(hwnd
);
1465 static void test_maxselday(void)
1471 hwnd
= create_monthcal_control(0);
1472 /* if no style specified default to 1 */
1473 res
= SendMessageA(hwnd
, MCM_GETMAXSELCOUNT
, 0, 0);
1475 res
= SendMessageA(hwnd
, MCM_SETMAXSELCOUNT
, 5, 0);
1477 res
= SendMessageA(hwnd
, MCM_GETMAXSELCOUNT
, 0, 0);
1480 /* try to set style */
1481 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1482 SetWindowLongA(hwnd
, GWL_STYLE
, style
| MCS_MULTISELECT
);
1483 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1484 ok(!(style
& MCS_MULTISELECT
), "Expected MCS_MULTISELECT not to be set\n");
1485 DestroyWindow(hwnd
);
1487 hwnd
= create_monthcal_control(MCS_MULTISELECT
);
1488 /* try to remove style */
1489 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1490 SetWindowLongA(hwnd
, GWL_STYLE
, style
& ~MCS_MULTISELECT
);
1491 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1492 ok(style
& MCS_MULTISELECT
, "Expected MCS_MULTISELECT to be set\n");
1493 DestroyWindow(hwnd
);
1495 hwnd
= create_monthcal_control(MCS_MULTISELECT
);
1497 /* default width is a week */
1498 res
= SendMessageA(hwnd
, MCM_GETMAXSELCOUNT
, 0, 0);
1501 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1503 /* Setter and Getters for max selected days */
1504 res
= SendMessageA(hwnd
, MCM_SETMAXSELCOUNT
, 5, 0);
1506 res
= SendMessageA(hwnd
, MCM_GETMAXSELCOUNT
, 0, 0);
1509 res
= SendMessageA(hwnd
, MCM_SETMAXSELCOUNT
, 15, 0);
1511 res
= SendMessageA(hwnd
, MCM_GETMAXSELCOUNT
, 0, 0);
1514 /* test invalid value */
1515 res
= SendMessageA(hwnd
, MCM_SETMAXSELCOUNT
, -1, 0);
1517 res
= SendMessageA(hwnd
, MCM_GETMAXSELCOUNT
, 0, 0);
1520 ok_sequence(sequences
, MONTHCAL_SEQ_INDEX
, monthcal_max_sel_day_seq
, "monthcal MaxSelDay", FALSE
);
1522 /* zero value is invalid too */
1523 res
= SendMessageA(hwnd
, MCM_SETMAXSELCOUNT
, 0, 0);
1525 res
= SendMessageA(hwnd
, MCM_GETMAXSELCOUNT
, 0, 0);
1528 DestroyWindow(hwnd
);
1531 static void test_size(void)
1535 HFONT hFont1
, hFont2
;
1539 hwnd
= create_monthcal_control(0);
1541 lstrcpyA(logfont
.lfFaceName
, "Arial");
1542 memset(&logfont
, 0, sizeof(logfont
));
1543 logfont
.lfHeight
= 12;
1544 hFont1
= CreateFontIndirectA(&logfont
);
1546 logfont
.lfHeight
= 24;
1547 hFont2
= CreateFontIndirectA(&logfont
);
1549 /* initialize to a font we can compare against */
1550 SendMessageA(hwnd
, WM_SETFONT
, (WPARAM
)hFont1
, 0);
1551 res
= SendMessageA(hwnd
, MCM_GETMINREQRECT
, 0, (LPARAM
)&r1
);
1552 ok(res
, "SendMessageA(MCM_GETMINREQRECT) failed\n");
1554 /* check that setting a larger font results in an larger rect */
1555 SendMessageA(hwnd
, WM_SETFONT
, (WPARAM
)hFont2
, 0);
1556 res
= SendMessageA(hwnd
, MCM_GETMINREQRECT
, 0, (LPARAM
)&r2
);
1557 ok(res
, "SendMessageA(MCM_GETMINREQRECT) failed\n");
1559 OffsetRect(&r1
, -r1
.left
, -r1
.top
);
1560 OffsetRect(&r2
, -r2
.left
, -r2
.top
);
1562 ok(r1
.bottom
< r2
.bottom
, "Failed to get larger rect with larger font\n");
1564 DestroyWindow(hwnd
);
1567 static void test_create(void)
1571 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1573 hwnd
= create_monthcal_control(0);
1574 ok_sequence(sequences
, PARENT_SEQ_INDEX
, create_monthcal_control_seq
, "create monthcal control", TRUE
);
1576 DestroyWindow(hwnd
);
1578 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1579 hwnd
= create_monthcal_control(MCS_MULTISELECT
);
1580 ok_sequence(sequences
, PARENT_SEQ_INDEX
, create_monthcal_multi_sel_style_seq
, "create monthcal (multi sel style)", TRUE
);
1581 DestroyWindow(hwnd
);
1584 static void test_destroy(void)
1588 hwnd
= create_monthcal_control(0);
1589 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1590 DestroyWindow(hwnd
);
1591 ok_sequence(sequences
, PARENT_SEQ_INDEX
, destroy_monthcal_parent_msgs_seq
, "Destroy monthcal (parent msg)", FALSE
);
1592 ok_sequence(sequences
, MONTHCAL_SEQ_INDEX
, destroy_monthcal_child_msgs_seq
, "Destroy monthcal (child msg)", FALSE
);
1594 /* MCS_MULTISELECT */
1595 hwnd
= create_monthcal_control(MCS_MULTISELECT
);
1596 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1597 DestroyWindow(hwnd
);
1598 ok_sequence(sequences
, MONTHCAL_SEQ_INDEX
, destroy_monthcal_multi_sel_style_seq
, "Destroy monthcal (multi sel style)", FALSE
);
1601 static void test_selrange(void)
1604 SYSTEMTIME st
, range
[2], range2
[2];
1605 BOOL ret
, old_comctl32
= FALSE
;
1607 hwnd
= create_monthcal_control(MCS_MULTISELECT
);
1609 /* just after creation selection should start and end today */
1610 ret
= SendMessageA(hwnd
, MCM_GETTODAY
, 0, (LPARAM
)&st
);
1613 memset(range
, 0xcc, sizeof(range
));
1614 ret
= SendMessageA(hwnd
, MCM_GETSELRANGE
, 0, (LPARAM
)range
);
1616 expect(st
.wYear
, range
[0].wYear
);
1617 expect(st
.wMonth
, range
[0].wMonth
);
1618 expect(st
.wDay
, range
[0].wDay
);
1619 if (range
[0].wDayOfWeek
!= st
.wDayOfWeek
)
1621 win_skip("comctl32 <= 4.70 doesn't set some values\n");
1622 old_comctl32
= TRUE
;
1626 expect(st
.wDayOfWeek
, range
[0].wDayOfWeek
);
1627 expect(st
.wHour
, range
[0].wHour
);
1628 expect(st
.wMinute
, range
[0].wMinute
);
1629 expect(st
.wSecond
, range
[0].wSecond
);
1630 expect(st
.wMilliseconds
, range
[0].wMilliseconds
);
1633 expect(st
.wYear
, range
[1].wYear
);
1634 expect(st
.wMonth
, range
[1].wMonth
);
1635 expect(st
.wDay
, range
[1].wDay
);
1638 expect(st
.wDayOfWeek
, range
[1].wDayOfWeek
);
1639 expect(st
.wHour
, range
[1].wHour
);
1640 expect(st
.wMinute
, range
[1].wMinute
);
1641 expect(st
.wSecond
, range
[1].wSecond
);
1642 expect(st
.wMilliseconds
, range
[1].wMilliseconds
);
1645 /* bounds are swapped if min > max */
1646 memset(&range
[0], 0, sizeof(range
[0]));
1647 range
[0].wYear
= 2009;
1648 range
[0].wMonth
= 10;
1650 range
[1] = range
[0];
1653 ret
= SendMessageA(hwnd
, MCM_SETSELRANGE
, 0, (LPARAM
)range
);
1656 ret
= SendMessageA(hwnd
, MCM_GETSELRANGE
, 0, (LPARAM
)range2
);
1659 expect(range
[1].wYear
, range2
[0].wYear
);
1660 expect(range
[1].wMonth
, range2
[0].wMonth
);
1661 expect(range
[1].wDay
, range2
[0].wDay
);
1662 expect(6, range2
[0].wDayOfWeek
);
1663 expect(range
[1].wHour
, range2
[0].wHour
);
1664 expect(range
[1].wMinute
, range2
[0].wMinute
);
1665 expect(range
[1].wSecond
, range2
[0].wSecond
);
1666 expect(range
[1].wMilliseconds
, range2
[0].wMilliseconds
);
1668 expect(range
[0].wYear
, range2
[1].wYear
);
1669 expect(range
[0].wMonth
, range2
[1].wMonth
);
1670 expect(range
[0].wDay
, range2
[1].wDay
);
1671 expect(1, range2
[1].wDayOfWeek
);
1672 expect(range
[0].wHour
, range2
[1].wHour
);
1673 expect(range
[0].wMinute
, range2
[1].wMinute
);
1674 expect(range
[0].wSecond
, range2
[1].wSecond
);
1675 expect(range
[0].wMilliseconds
, range2
[1].wMilliseconds
);
1677 /* try with range larger than maximum configured */
1678 memset(&range
[0], 0, sizeof(range
[0]));
1679 range
[0].wYear
= 2009;
1680 range
[0].wMonth
= 10;
1682 range
[1] = range
[0];
1684 ret
= SendMessageA(hwnd
, MCM_SETSELRANGE
, 0, (LPARAM
)range
);
1687 range
[1] = range
[0];
1688 /* default max. range is 7 days */
1691 ret
= SendMessageA(hwnd
, MCM_SETSELRANGE
, 0, (LPARAM
)range
);
1694 ret
= SendMessageA(hwnd
, MCM_GETSELRANGE
, 0, (LPARAM
)range2
);
1697 expect(range
[0].wYear
, range2
[0].wYear
);
1698 expect(range
[0].wMonth
, range2
[0].wMonth
);
1699 expect(range
[0].wDay
, range2
[0].wDay
);
1700 expect(range
[0].wYear
, range2
[1].wYear
);
1701 expect(range
[0].wMonth
, range2
[1].wMonth
);
1702 expect(range
[0].wDay
, range2
[1].wDay
);
1704 DestroyWindow(hwnd
);
1707 static void test_killfocus(void)
1712 hwnd
= create_monthcal_control(0);
1714 /* make parent invisible */
1715 style
= GetWindowLongA(parent_wnd
, GWL_STYLE
);
1716 SetWindowLongA(parent_wnd
, GWL_STYLE
, style
& ~WS_VISIBLE
);
1718 SendMessageA(hwnd
, WM_KILLFOCUS
, (WPARAM
)GetDesktopWindow(), 0);
1720 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1721 ok(style
& WS_VISIBLE
, "Expected WS_VISIBLE to be set\n");
1723 style
= GetWindowLongA(parent_wnd
, GWL_STYLE
);
1724 SetWindowLongA(parent_wnd
, GWL_STYLE
, style
| WS_VISIBLE
);
1726 DestroyWindow(hwnd
);
1729 static void test_hittest_v6(void)
1731 MCHITTESTINFO mchit
;
1736 hwnd
= create_monthcal_control(0);
1737 SendMessageA(hwnd
, MCM_SETCALENDARBORDER
, TRUE
, 0);
1739 SendMessageA(hwnd
, MCM_GETMINREQRECT
, 0, (LPARAM
)&r
);
1740 /* reserving some area around calendar */
1741 MoveWindow(hwnd
, 0, 0, r
.right
* 3 / 2, r
.bottom
* 3 / 2, FALSE
);
1742 mchit
.cbSize
= sizeof(MCHITTESTINFO
);
1743 mchit
.pt
.x
= mchit
.pt
.y
= 0;
1747 ret
= SendMessageA(hwnd
, MCM_HITTEST
, 0, (LPARAM
)&mchit
);
1750 win_skip("Only MCHITTESTINFO_V1 supported\n");
1751 DestroyWindow(hwnd
);
1754 todo_wine
expect_hex(MCHT_NOWHERE
, ret
);
1755 expect(-1, mchit
.iOffset
);
1756 expect(-1, mchit
.iRow
);
1757 expect(-1, mchit
.iCol
);
1759 MoveWindow(hwnd
, 0, 0, r
.right
, r
.bottom
, FALSE
);
1760 mchit
.pt
.x
= r
.right
/ 2;
1761 mchit
.pt
.y
= r
.bottom
/ 2;
1763 ret
= SendMessageA(hwnd
, MCM_HITTEST
, 0, (LPARAM
)&mchit
);
1764 expect_hex(MCHT_CALENDARDATE
, ret
);
1765 expect(0, mchit
.iOffset
);
1768 mchit
.pt
.x
= r
.right
/ (7*2);
1769 mchit
.pt
.y
= r
.bottom
/ 2;
1771 mchit
.iCol
= mchit
.iRow
= -1;
1773 mchit
.rc
.left
= mchit
.rc
.right
= mchit
.rc
.top
= mchit
.rc
.bottom
= -1;
1774 ret
= SendMessageA(hwnd
, MCM_HITTEST
, 0, (LPARAM
)&mchit
);
1775 expect_hex(MCHT_CALENDARDATE
, ret
);
1776 expect_hex(MCHT_CALENDARDATE
, mchit
.uHit
);
1777 expect(0, mchit
.iOffset
);
1778 expect(2, mchit
.iRow
);
1779 expect(0, mchit
.iCol
);
1780 /* returned a one day rectangle */
1781 expect_d(r
.right
/ 7, mchit
.rc
.right
- mchit
.rc
.left
);
1782 expect_d(r
.bottom
/ 10, mchit
.rc
.bottom
- mchit
.rc
.top
);
1788 mchit
.iCol
= mchit
.iRow
= -1;
1790 mchit
.rc
.left
= mchit
.rc
.right
= mchit
.rc
.top
= mchit
.rc
.bottom
= -1;
1791 ret
= SendMessageA(hwnd
, MCM_HITTEST
, 0, (LPARAM
)&mchit
);
1792 expect_hex(MCHT_TITLE
, ret
);
1793 expect_hex(MCHT_TITLE
, mchit
.uHit
);
1794 expect(0, mchit
.iOffset
);
1795 expect(-1, mchit
.iRow
);
1796 expect(-1, mchit
.iCol
);
1797 expect(0, mchit
.rc
.left
);
1798 expect(0, mchit
.rc
.top
);
1799 expect_d(r
.right
, mchit
.rc
.right
);
1800 ok(mchit
.rc
.bottom
> 0, "got %d\n", mchit
.rc
.bottom
);
1802 /* between two calendars */
1803 MoveWindow(hwnd
, 0, 0, r
.right
* 5/2, r
.bottom
, FALSE
);
1804 mchit
.pt
.x
= r
.right
/ (5*4);
1805 mchit
.pt
.y
= r
.bottom
/ 2;
1807 mchit
.iCol
= mchit
.iRow
= -2;
1809 mchit
.rc
.left
= mchit
.rc
.right
= mchit
.rc
.top
= mchit
.rc
.bottom
= -1;
1810 ret
= SendMessageA(hwnd
, MCM_HITTEST
, 0, (LPARAM
)&mchit
);
1811 todo_wine
expect_hex(MCHT_NOWHERE
, ret
);
1812 todo_wine
expect_hex(MCHT_NOWHERE
, mchit
.uHit
);
1813 expect(-2, mchit
.iOffset
);
1814 expect(-2, mchit
.iRow
);
1815 expect(-2, mchit
.iCol
);
1816 todo_wine
expect(0, mchit
.rc
.left
);
1817 todo_wine
expect(0, mchit
.rc
.top
);
1818 todo_wine
expect_d(r
.right
* 5/2, mchit
.rc
.right
);
1819 todo_wine
expect_d(r
.bottom
, mchit
.rc
.bottom
);
1821 DestroyWindow(hwnd
);
1824 static void test_get_set_border(void)
1829 hwnd
= create_monthcal_control(0);
1831 /* a non-default value */
1832 ret
= SendMessageA(hwnd
, MCM_SETCALENDARBORDER
, TRUE
, 10);
1835 ret
= SendMessageA(hwnd
, MCM_GETCALENDARBORDER
, 0, 0);
1839 skip("MCM_GET/SETCALENDARBORDER not supported\n");
1840 DestroyWindow(hwnd
);
1846 DestroyWindow(hwnd
);
1849 static void test_MCM_SIZERECTTOMIN(void)
1855 hwnd
= create_monthcal_control(0);
1857 ret
= SendMessageA(hwnd
, MCM_GETMINREQRECT
, 0, (LPARAM
)&r2
);
1860 win_skip("Message MCM_GETMINREQRECT unsupported. Skipping.\n");
1861 DestroyWindow(hwnd
);
1865 ret
= SendMessageA(hwnd
, MCM_SIZERECTTOMIN
, 0, 0);
1866 ok(ret
== 0, "got %d\n", ret
);
1868 r
.left
= r
.right
= r
.top
= r
.bottom
= 0;
1869 ret
= SendMessageA(hwnd
, MCM_SIZERECTTOMIN
, 0, (LPARAM
)&r
);
1872 skip("Message MCM_SIZERECTTOMIN unsupported. Skipping.\n");
1873 DestroyWindow(hwnd
);
1876 ok(ret
== 1, "got %d\n", ret
);
1877 ok(r
.left
== 0 && r
.right
> 0, "got %d, %d\n", r
.left
, r
.right
);
1880 ret
= SendMessageA(hwnd
, MCM_SIZERECTTOMIN
, 0, (LPARAM
)&r
);
1881 ok(ret
== 1, "got %d\n", ret
);
1883 r2
.right
= (r2
.right
- r2
.left
) * 3;
1884 r2
.bottom
= (r2
.bottom
- r2
.top
) * 3;
1885 r2
.left
= r2
.top
= 0;
1886 ret
= SendMessageA(hwnd
, MCM_SIZERECTTOMIN
, 0, (LPARAM
)&r2
);
1887 ok(ret
== 1, "got %d\n", ret
);
1889 DestroyWindow(hwnd
);
1892 static void test_MCM_GETCALENDARCOUNT(void)
1897 hwnd
= create_monthcal_control(0);
1899 ret
= SendMessageA(hwnd
, MCM_GETCALENDARCOUNT
, 0, 0);
1902 win_skip("Message MCM_GETCALENDARCOUNT unsupported. Skipping.\n");
1903 DestroyWindow(hwnd
);
1909 DestroyWindow(hwnd
);
1912 static void test_daystate(void)
1914 MONTHDAYSTATE state
[4];
1919 /* without MCS_DAYSTATE */
1920 hwnd
= create_monthcal_control(0);
1922 ret
= SendMessageA(hwnd
, MCM_GETMINREQRECT
, 0, (LPARAM
)&r
);
1925 /* resize control to display two Calendars */
1926 MoveWindow(hwnd
, 0, 0, r
.right
, (5/2)*r
.bottom
, FALSE
);
1928 ret
= SendMessageA(hwnd
, MCM_GETMONTHRANGE
, GMR_DAYSTATE
, 0);
1931 ret
= SendMessageA(hwnd
, MCM_SETDAYSTATE
, 4, (LPARAM
)&state
);
1934 ret
= SendMessageA(hwnd
, MCM_SETDAYSTATE
, 2, (LPARAM
)&state
);
1937 ret
= SendMessageA(hwnd
, MCM_SETDAYSTATE
, 0, 0);
1940 /* try to switch on */
1941 SetWindowLongA(hwnd
, GWL_STYLE
, GetWindowLongA(hwnd
, GWL_STYLE
) | MCS_DAYSTATE
);
1942 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1943 ok((style
& MCS_DAYSTATE
) == 0, "got 0x%08x\n", style
);
1945 DestroyWindow(hwnd
);
1947 /* with MCS_DAYSTATE */
1948 hwnd
= create_monthcal_control(MCS_DAYSTATE
);
1950 ret
= SendMessageA(hwnd
, MCM_GETMONTHRANGE
, GMR_DAYSTATE
, 0);
1953 ret
= SendMessageA(hwnd
, MCM_SETDAYSTATE
, 4, (LPARAM
)&state
);
1956 ret
= SendMessageA(hwnd
, MCM_SETDAYSTATE
, 2, (LPARAM
)&state
);
1959 ret
= SendMessageA(hwnd
, MCM_SETDAYSTATE
, 0, 0);
1962 /* try to switch off */
1963 SetWindowLongA(hwnd
, GWL_STYLE
, GetWindowLongA(hwnd
, GWL_STYLE
) & ~MCS_DAYSTATE
);
1964 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1965 ok((style
& MCS_DAYSTATE
) == MCS_DAYSTATE
, "got 0x%08x\n", style
);
1967 DestroyWindow(hwnd
);
1970 static void test_sel_notify(void)
1980 MCHITTESTINFO mchit
= {sizeof(MCHITTESTINFO
)};
1982 Monthcal_style styles
[] = {
1983 {MCS_NOTODAY
, "MCS_NOTODAY"},
1984 {MCS_NOTODAY
| MCS_MULTISELECT
, "MCS_NOTODAY | MCS_MULTISELECT"},
1985 {MCS_DAYSTATE
, "MCS_DAYSTATE"},
1986 {MCS_DAYSTATE
| MCS_MULTISELECT
, "MCS_DAYSTATE | MCS_MULTISELECT"}
1990 for(i
= 0; i
< sizeof styles
/ sizeof styles
[0]; i
++)
1992 hwnd
= create_monthcal_control(styles
[i
].val
);
1993 SetWindowLongPtrA(hwnd
, GWLP_ID
, SEL_NOTIFY_TEST_ID
);
1994 SendMessageA(hwnd
, MCM_GETMINREQRECT
, 0, (LPARAM
)&rc
);
1995 MoveWindow(hwnd
, 0, 0, rc
.right
, rc
.bottom
, FALSE
);
1996 /* Simulate mouse click on some unselected day to generate
1997 MCN_SELECT and MCN_SELCHANGE notifications */
1998 mchit
.pt
.x
= rc
.right
/ 2;
1999 mchit
.pt
.y
= rc
.bottom
/ 2;
2000 SendMessageA(hwnd
, MCM_HITTEST
, 0, (LPARAM
)&mchit
);
2001 SendMessageA(hwnd
, MCM_GETCURSEL
, 0, (LPARAM
)&st
);
2002 while(st
.wDay
== mchit
.st
.wDay
) /* Ensure that mchit.pt points to unselected day */
2005 SendMessageA(hwnd
, MCM_HITTEST
, 0, (LPARAM
)&mchit
);
2007 SendMessageA(hwnd
, WM_LBUTTONDOWN
, 0, MAKELPARAM(mchit
.pt
.x
, mchit
.pt
.y
));
2008 SendMessageA(hwnd
, WM_LBUTTONUP
, 0, MAKELPARAM(mchit
.pt
.x
, mchit
.pt
.y
));
2009 DestroyWindow(hwnd
);
2013 START_TEST(monthcal
)
2015 BOOL (WINAPI
*pInitCommonControlsEx
)(const INITCOMMONCONTROLSEX
*);
2016 INITCOMMONCONTROLSEX iccex
;
2019 ULONG_PTR ctx_cookie
;
2022 hComctl32
= GetModuleHandleA("comctl32.dll");
2023 pInitCommonControlsEx
= (void*)GetProcAddress(hComctl32
, "InitCommonControlsEx");
2024 if (!pInitCommonControlsEx
)
2026 skip("InitCommonControlsEx() is missing. Skipping the tests\n");
2029 iccex
.dwSize
= sizeof(iccex
);
2030 iccex
.dwICC
= ICC_DATE_CLASSES
;
2031 pInitCommonControlsEx(&iccex
);
2035 init_msg_sequences(sequences
, NUM_MSG_SEQUENCES
);
2037 parent_wnd
= create_parent_window();
2057 if (!load_v6_module(&ctx_cookie
, &hCtx
))
2059 DestroyWindow(parent_wnd
);
2064 test_get_set_border();
2065 test_MCM_SIZERECTTOMIN();
2066 test_MCM_GETCALENDARCOUNT();
2068 unload_v6_module(ctx_cookie
, hCtx
);
2070 DestroyWindow(parent_wnd
);