4653f52ca10ae05e1bcd0081bba695029eb1e2d2
[reactos.git] / rostests / winetests / comctl32 / monthcal.c
1 /*
2 * comctl32 month calendar unit tests
3 *
4 * Copyright (C) 2006 Vitaliy Margolen
5 * Copyright (C) 2007 Farshad Agah
6 *
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.
11 *
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.
16 *
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
20 */
21
22 #include <wine/test.h>
23
24 //#include <stdarg.h>
25
26 //#include "windef.h"
27 //#include "winbase.h"
28 #include <winuser.h>
29 #include <wingdi.h>
30 #include <winnls.h>
31 #include <commctrl.h>
32
33 #include "v6util.h"
34 //#include <assert.h>
35 //#include <windows.h>
36 #include "msg.h"
37
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);
41
42 #define NUM_MSG_SEQUENCES 2
43 #define PARENT_SEQ_INDEX 0
44 #define MONTHCAL_SEQ_INDEX 1
45
46 #define SEL_NOTIFY_TEST_ID 100
47
48 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
49
50 static HWND parent_wnd;
51
52 static const struct message create_parent_window_seq[] = {
53 { WM_GETMINMAXINFO, sent },
54 { WM_NCCREATE, sent },
55 { WM_NCCALCSIZE, sent|wparam, 0 },
56 { WM_CREATE, sent },
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 },
71 { WM_SIZE, sent },
72 { WM_MOVE, sent },
73 { 0 }
74 };
75
76 static const struct message create_monthcal_control_seq[] = {
77 { WM_NOTIFYFORMAT, sent|lparam, 0, NF_QUERY },
78 { WM_QUERYUISTATE, sent|optional },
79 { WM_GETFONT, sent },
80 { WM_PARENTNOTIFY, sent|wparam, WM_CREATE},
81 { 0 }
82 };
83
84 static const struct message create_monthcal_multi_sel_style_seq[] = {
85 { WM_NOTIFYFORMAT, sent|lparam, 0, NF_QUERY },
86 { WM_QUERYUISTATE, sent|optional },
87 { WM_GETFONT, sent },
88 { WM_PARENTNOTIFY, sent },
89 { 0 }
90 };
91
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},
99 { 0 }
100 };
101
102 static const struct message monthcal_first_day_seq[] = {
103 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
104
105 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -5},
106 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
107
108 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -4},
109 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
110
111 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -3},
112 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
113
114 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -2},
115 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
116
117 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -1},
118 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
119
120 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
121 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
122
123 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 1},
124 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
125
126 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 2},
127 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
128
129 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 3},
130 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
131
132 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 4},
133 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
134
135 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 5},
136 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
137
138 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 6},
139 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
140
141 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 7},
142 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
143
144 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 8},
145 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
146
147 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 9},
148 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
149
150 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 10},
151 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
152
153 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 11},
154 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
155 { 0 }
156 };
157
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},
165 { 0 }
166 };
167
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},
181 { 0 }
182 };
183
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},
193 { 0 }
194 };
195
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},
203 { 0 }
204 };
205
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},
216 { 0 }
217 };
218
219 static const struct message monthcal_monthrange_seq[] = {
220 { MCM_GETMONTHRANGE, sent|wparam, GMR_VISIBLE},
221 { MCM_GETMONTHRANGE, sent|wparam, GMR_DAYSTATE},
222 { 0 }
223 };
224
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},
232 { 0 }
233 };
234
235 /* expected message sequence for parent*/
236 static const struct message destroy_monthcal_parent_msgs_seq[] = {
237 { WM_PARENTNOTIFY, sent|wparam, WM_DESTROY},
238 { 0 }
239 };
240
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},
249 { 0 }
250 };
251
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},
259 { 0 }
260 };
261
262 static void test_monthcal(void)
263 {
264 HWND hwnd;
265 SYSTEMTIME st[2], st1[2], today;
266 int res, month_range;
267 DWORD limits;
268
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");
272
273 /* test range just after creation */
274 memset(&st, 0xcc, sizeof(st));
275 limits = SendMessageA(hwnd, MCM_GETRANGE, 0, (LPARAM)st);
276 ok(limits == 0 ||
277 broken(limits == GDTR_MIN), /* comctl32 <= 4.70 */
278 "No limits should be set (%d)\n", limits);
279 if (limits == GDTR_MIN)
280 {
281 win_skip("comctl32 <= 4.70 is broken\n");
282 DestroyWindow(hwnd);
283 return;
284 }
285
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);
300
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);
309
310 GetSystemTime(&st[0]);
311 st[1] = st[0];
312
313 SendMessageA(hwnd, MCM_GETTODAY, 0, (LPARAM)&today);
314
315 /* Invalid date/time */
316 st[0].wYear = 2000;
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);
326
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);
334
335 /* Invalid date/time with invalid milliseconds only */
336 GetSystemTime(&st[0]);
337 st[1] = 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);
346
347 GetSystemTime(&st[0]);
348
349 st[1].wMonth = 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");
358
359 GetSystemTime(&st[0]);
360 st[0].wDay = 20;
361 st[0].wMonth = 5;
362 st[1] = st[0];
363
364 month_range = SendMessageA(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st1);
365 st[1].wMonth--;
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");
372
373 st[1].wMonth += 2;
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);
378
379 st[1].wYear --;
380 ok(SendMessageA(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st),
381 "Failed to set both min and max limits\n");
382 st[1].wYear += 1;
383 ok(SendMessageA(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st),
384 "Failed to set both min and max limits\n");
385
386 st[1].wMonth -= 3;
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");
390 st[1].wMonth += 4;
391 ok(SendMessageA(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
392 st[1].wYear -= 3;
393 ok(SendMessageA(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
394 st[1].wYear += 4;
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");
398
399 /* set both limits, then set max < min */
400 GetSystemTime(&st[0]);
401 st[0].wDay = 25;
402 st[1] = st[0];
403 st[1].wYear++;
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");
407 st[1].wYear -= 2;
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");
410
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);
419
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);
428
429 st[1] = st[0];
430 st[1].wYear++;
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");
437
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);
446
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);
455
456 DestroyWindow(hwnd);
457 }
458
459 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
460 {
461 static LONG defwndproc_counter = 0;
462 LRESULT ret;
463 struct message msg;
464
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)
474 {
475 msg.message = message;
476 msg.flags = sent|wparam|lparam;
477 if (defwndproc_counter) msg.flags |= defwinproc;
478 msg.wParam = wParam;
479 msg.lParam = lParam;
480 add_message(sequences, PARENT_SEQ_INDEX, &msg);
481 }
482
483 if (message == WM_NOTIFY)
484 {
485 NMHDR *hdr = (NMHDR*)lParam;
486 switch (hdr->code)
487 {
488 case MCN_GETDAYSTATE:
489 {
490 NMDAYSTATE *nmstate = (NMDAYSTATE*)lParam;
491 static MONTHDAYSTATE months[14] = { 0 };
492
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);
496
497 nmstate->prgDayState = months;
498
499 return TRUE;
500 }
501 case MCN_SELECT:
502 case MCN_SELCHANGE:
503 {
504 NMSELCHANGE *nmchg = (NMSELCHANGE*)lParam;
505 SYSTEMTIME st[2];
506 BOOL is_multisel = GetWindowLongPtrA(nmchg->nmhdr.hwndFrom, GWL_STYLE) & MCS_MULTISELECT;
507
508 if(GetWindowLongPtrA(nmchg->nmhdr.hwndFrom, GWLP_ID) != SEL_NOTIFY_TEST_ID)
509 break;
510 SendMessageA(nmchg->nmhdr.hwndFrom, is_multisel ? MCM_GETSELRANGE : MCM_GETCURSEL,
511 0, (LPARAM)st);
512
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);
517
518 if(is_multisel)
519 {
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);
524 }
525 else
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");
531 return TRUE;
532 }
533 default:
534 break;
535 }
536 }
537
538 defwndproc_counter++;
539 ret = DefWindowProcA(hwnd, message, wParam, lParam);
540 defwndproc_counter--;
541
542 return ret;
543 }
544
545 static BOOL register_parent_wnd_class(void)
546 {
547 WNDCLASSA cls;
548
549 cls.style = 0;
550 cls.lpfnWndProc = parent_wnd_proc;
551 cls.cbClsExtra = 0;
552 cls.cbWndExtra = 0;
553 cls.hInstance = GetModuleHandleA(NULL);
554 cls.hIcon = 0;
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);
560 }
561
562 static HWND create_parent_window(void)
563 {
564 HWND hwnd;
565
566 InitCommonControls();
567
568 /* flush message sequences, so we can check the new sequence by the end of function */
569 flush_sequences(sequences, NUM_MSG_SEQUENCES);
570
571 if (!register_parent_wnd_class())
572 return NULL;
573
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");
578
579 /* check for message sequences */
580 ok_sequence(sequences, PARENT_SEQ_INDEX, create_parent_window_seq, "create parent window", FALSE);
581
582 return hwnd;
583 }
584
585 static LRESULT WINAPI monthcal_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
586 {
587 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
588 static LONG defwndproc_counter = 0;
589 LRESULT ret;
590 struct message msg;
591
592 msg.message = message;
593 msg.flags = sent|wparam|lparam;
594 if (defwndproc_counter) msg.flags |= defwinproc;
595 msg.wParam = wParam;
596 msg.lParam = lParam;
597 msg.id = 0;
598 add_message(sequences, MONTHCAL_SEQ_INDEX, &msg);
599
600 /* some debug output for style changing */
601 if ((message == WM_STYLECHANGING ||
602 message == WM_STYLECHANGED) && lParam)
603 {
604 STYLESTRUCT *style = (STYLESTRUCT*)lParam;
605 trace("\told style: 0x%08x, new style: 0x%08x\n", style->styleOld, style->styleNew);
606 }
607
608 defwndproc_counter++;
609 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
610 defwndproc_counter--;
611
612 return ret;
613 }
614
615 static HWND create_monthcal_control(DWORD style)
616 {
617 WNDPROC oldproc;
618 RECT rect;
619 HWND hwnd;
620 BOOL ret;
621
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;
626
627 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
628 (LONG_PTR)monthcal_subclass_proc);
629 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
630
631 SendMessageA(hwnd, WM_SETFONT, (WPARAM)GetStockObject(SYSTEM_FONT), 0);
632
633 /* make sure calendar grid is 2x1 */
634 ret = SendMessageA(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&rect);
635 ok(ret, "got %d\n", ret);
636
637 ret = SetWindowPos(hwnd, NULL, 0, 0, rect.right * 5 / 2, rect.bottom * 3 / 2, SWP_NOMOVE);
638 ok(ret, "got %d\n", ret);
639
640 return hwnd;
641 }
642
643
644 /* Setter and Getters Tests */
645
646 static void test_color(void)
647 {
648 COLORREF color, prev;
649 HWND hwnd;
650
651 hwnd = create_monthcal_control(0);
652
653 /* invalid color index */
654 color = SendMessageA(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT + 1, 0);
655 expect(~0u, color);
656 prev = SendMessageA(hwnd, MCM_SETCOLOR, MCSC_TRAILINGTEXT + 1, RGB(255,255,255));
657 expect(~0u, prev);
658
659 color = SendMessageA(hwnd, MCM_GETCOLOR, MCSC_BACKGROUND, 0);
660 prev = SendMessageA(hwnd, MCM_SETCOLOR, MCSC_BACKGROUND, RGB(0,0,0));
661 expect(color, prev);
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));
665 expect(color, prev);
666 color = SendMessageA(hwnd, MCM_GETCOLOR, MCSC_BACKGROUND, 0);
667 expect(RGB(255,255,255), color);
668
669 color = SendMessageA(hwnd, MCM_GETCOLOR, MCSC_MONTHBK, 0);
670 prev = SendMessageA(hwnd, MCM_SETCOLOR, MCSC_MONTHBK, RGB(0,0,0));
671 expect(color, prev);
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));
675 expect(color, prev);
676 color = SendMessageA(hwnd, MCM_GETCOLOR, MCSC_MONTHBK, 0);
677 expect(RGB(255,255,255), color);
678
679 color = SendMessageA(hwnd, MCM_GETCOLOR, MCSC_TEXT, 0);
680 prev = SendMessageA(hwnd, MCM_SETCOLOR, MCSC_TEXT, RGB(0,0,0));
681 expect(color, prev);
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));
685 expect(color, prev);
686 color = SendMessageA(hwnd, MCM_GETCOLOR, MCSC_TEXT, 0);
687 expect(RGB(255,255,255), color);
688
689 color = SendMessageA(hwnd, MCM_GETCOLOR, MCSC_TITLEBK, 0);
690 prev = SendMessageA(hwnd, MCM_SETCOLOR, MCSC_TITLEBK, RGB(0,0,0));
691 expect(color, prev);
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));
695 expect(color, prev);
696 color = SendMessageA(hwnd, MCM_GETCOLOR, MCSC_TITLEBK, 0);
697 expect(RGB(255,255,255), color);
698
699 color = SendMessageA(hwnd, MCM_GETCOLOR, MCSC_TITLETEXT, 0);
700 prev = SendMessageA(hwnd, MCM_SETCOLOR, MCSC_TITLETEXT, RGB(0,0,0));
701 expect(color, prev);
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));
705 expect(color, prev);
706 color = SendMessageA(hwnd, MCM_GETCOLOR, MCSC_TITLETEXT, 0);
707 expect(RGB(255,255,255), color);
708
709 color = SendMessageA(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT, 0);
710 prev = SendMessageA(hwnd, MCM_SETCOLOR, MCSC_TRAILINGTEXT, RGB(0,0,0));
711 expect(color, prev);
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));
715 expect(color, prev);
716 color = SendMessageA(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT, 0);
717 expect(RGB(255,255,255), color);
718
719 DestroyWindow(hwnd);
720 }
721
722 static void test_currdate(void)
723 {
724 SYSTEMTIME st_original, st_new, st_test;
725 int res;
726 HWND hwnd;
727
728 hwnd = create_monthcal_control(0);
729
730 flush_sequences(sequences, NUM_MSG_SEQUENCES);
731
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;
741
742 st_new = st_test = st_original;
743
744 /* Should not validate the time */
745 res = SendMessageA(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
746 expect(1,res);
747
748 /* Overflow matters, check for wDay */
749 st_test.wDay += 4;
750 res = SendMessageA(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
751 expect(0,res);
752
753 /* correct wDay before checking for wMonth */
754 st_test.wDay -= 4;
755 expect(st_original.wDay, st_test.wDay);
756
757 /* Overflow matters, check for wMonth */
758 st_test.wMonth += 4;
759 res = SendMessageA(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
760 expect(0,res);
761
762 /* checking if gets the information right, modify st_new */
763 st_new.wYear += 4;
764 st_new.wMonth += 4;
765 st_new.wDay += 4;
766 st_new.wHour += 4;
767 st_new.wMinute += 4;
768 st_new.wSecond += 4;
769
770 res = SendMessageA(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_new);
771 expect(1, res);
772
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);
787
788 /* lparam cannot be NULL */
789 res = SendMessageA(hwnd, MCM_GETCURSEL, 0, 0);
790 expect(0, res);
791
792 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_curr_date_seq, "monthcal currDate", TRUE);
793
794 /* December, 31, 9999 is the maximum allowed date */
795 memset(&st_new, 0, sizeof(st_new));
796 st_new.wYear = 9999;
797 st_new.wMonth = 12;
798 st_new.wDay = 31;
799 res = SendMessageA(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_new);
800 expect(1, res);
801 memset(&st_test, 0, sizeof(st_test));
802 res = SendMessageA(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_test);
803 expect(1, res);
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;
813 st_new.wMonth = 1;
814 st_new.wDay = 1;
815 res = SendMessageA(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_new);
816 ok(0 == res ||
817 broken(1 == res), /* comctl32 <= 4.72 */
818 "Expected 0, got %d\n", res);
819 if (0 == res)
820 {
821 memset(&st_test, 0, sizeof(st_test));
822 res = SendMessageA(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_test);
823 expect(1, res);
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);
830 }
831
832 /* setting selection equal to current reports success even if out range */
833 memset(&st_new, 0, sizeof(st_new));
834 st_new.wYear = 2009;
835 st_new.wDay = 5;
836 st_new.wMonth = 10;
837 res = SendMessageA(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_new);
838 expect(1, res);
839 memset(&st_test, 0, sizeof(st_test));
840 st_test.wYear = 2009;
841 st_test.wDay = 6;
842 st_test.wMonth = 10;
843 res = SendMessageA(hwnd, MCM_SETRANGE, GDTR_MIN, (LPARAM)&st_test);
844 expect(1, res);
845 /* set to current again */
846 res = SendMessageA(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_new);
847 expect(1, res);
848
849 /* set with invalid day of week */
850 memset(&st_test, 0, sizeof(st_test));
851 st_test.wYear = 2009;
852 st_test.wDay = 7;
853 st_test.wMonth = 10;
854 st_test.wDayOfWeek = 100;
855 res = SendMessageA(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
856 expect(1, res);
857
858 memset(&st_test, 0, sizeof(st_test));
859 res = SendMessageA(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_test);
860 expect(1, res);
861 expect(2009, st_test.wYear);
862 expect(7, st_test.wDay);
863 expect(10, st_test.wMonth);
864 expect(3, st_test.wDayOfWeek);
865
866 DestroyWindow(hwnd);
867 }
868
869 static void test_firstDay(void)
870 {
871 int res, fday, i, prev;
872 CHAR b[128], caltype[3];
873 LCID lcid = LOCALE_USER_DEFAULT;
874 HWND hwnd;
875 LRESULT ret;
876
877 SetLastError(0xdeadbeef);
878 ret = GetLocaleInfoA(lcid, LOCALE_ICALENDARTYPE, caltype, 3);
879 if (ret == 0) {
880 skip("Must know local calendar type (%x)\n", GetLastError());
881 return;
882 } else if (atoi(caltype) != CAL_GREGORIAN) {
883 skip("MonthCalendar Control only supports Gregorian calendar (type: %s)\n", caltype);
884 return;
885 }
886
887 hwnd = create_monthcal_control(0);
888
889 flush_sequences(sequences, NUM_MSG_SEQUENCES);
890
891 /* Setter and Getters for first day of week */
892 /* check for locale first day */
893 if(GetLocaleInfoA(lcid, LOCALE_IFIRSTDAYOFWEEK, b, 128)){
894 fday = atoi(b);
895 res = SendMessageA(hwnd, MCM_GETFIRSTDAYOFWEEK, 0, 0);
896 expect(fday, res);
897 prev = fday;
898
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);
903 expect(prev, res);
904 res = SendMessageA(hwnd, MCM_GETFIRSTDAYOFWEEK, 0, 0);
905 prev = res;
906
907 if (i == -1){
908 expect(MAKELONG(fday, FALSE), res);
909 }else if (i >= 7){
910 /* out of range sets max first day of week, locale is ignored */
911 expect(MAKELONG(6, TRUE), res);
912 }else{
913 expect(MAKELONG(i, TRUE), res);
914 }
915 }
916
917 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_first_day_seq, "monthcal firstDay", FALSE);
918
919 }else{
920 skip("Cannot retrieve first day of the week\n");
921 }
922
923 DestroyWindow(hwnd);
924 }
925
926 static void test_unicode(void)
927 {
928 int res, temp;
929 HWND hwnd;
930
931 hwnd = create_monthcal_control(0);
932
933 flush_sequences(sequences, NUM_MSG_SEQUENCES);
934
935 /* Setter and Getters for Unicode format */
936
937 /* getting the current settings */
938 temp = SendMessageA(hwnd, MCM_GETUNICODEFORMAT, 0, 0);
939
940 /* setting to 1, should return previous settings */
941 res = SendMessageA(hwnd, MCM_SETUNICODEFORMAT, 1, 0);
942 expect(temp, res);
943
944 /* current setting is 1, so, should return 1 */
945 res = SendMessageA(hwnd, MCM_GETUNICODEFORMAT, 0, 0);
946 ok(1 == res ||
947 broken(0 == res), /* comctl32 <= 4.70 */
948 "Expected 1, got %d\n", res);
949
950 /* setting to 0, should return previous settings */
951 res = SendMessageA(hwnd, MCM_SETUNICODEFORMAT, 0, 0);
952 ok(1 == res ||
953 broken(0 == res), /* comctl32 <= 4.70 */
954 "Expected 1, got %d\n", res);
955
956 /* current setting is 0, so, it should return 0 */
957 res = SendMessageA(hwnd, MCM_GETUNICODEFORMAT, 0, 0);
958 expect(0, res);
959
960 /* should return previous settings */
961 res = SendMessageA(hwnd, MCM_SETUNICODEFORMAT, 1, 0);
962 expect(0, res);
963
964 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_unicode_seq, "monthcal unicode", FALSE);
965
966 DestroyWindow(hwnd);
967 }
968
969 static void test_hittest(void)
970 {
971 typedef struct hittest_test
972 {
973 UINT ht;
974 BOOL todo;
975 } hittest_test_t;
976
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 }
986 };
987
988 MCHITTESTINFO mchit;
989 UINT res, old_res;
990 SYSTEMTIME st;
991 LONG x;
992 UINT title_index;
993 HWND hwnd;
994 RECT r;
995 char yearmonth[80], *locale_month, *locale_year;
996 int month_count, year_count;
997 BOOL in_the_middle;
998
999 memset(&mchit, 0, sizeof(MCHITTESTINFO));
1000
1001 hwnd = create_monthcal_control(0);
1002
1003 /* test with invalid structure size */
1004 mchit.cbSize = MCHITTESTINFO_V1_SIZE - 1;
1005 mchit.pt.x = 0;
1006 mchit.pt.y = 0;
1007 res = SendMessageA(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1008 expect(0, mchit.pt.x);
1009 expect(0, mchit.pt.y);
1010 expect(~0u, res);
1011 expect(0, mchit.uHit);
1012 /* test with invalid pointer */
1013 res = SendMessageA(hwnd, MCM_HITTEST, 0, 0);
1014 expect(~0u, res);
1015
1016 /* resize control to display single Calendar */
1017 res = SendMessageA(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r);
1018 if (res == 0)
1019 {
1020 win_skip("Message MCM_GETMINREQRECT unsupported. Skipping.\n");
1021 DestroyWindow(hwnd);
1022 return;
1023 }
1024 MoveWindow(hwnd, 0, 0, r.right, r.bottom, FALSE);
1025
1026 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1027
1028 st.wYear = 2007;
1029 st.wMonth = 4;
1030 st.wDay = 11;
1031 st.wHour = 1;
1032 st.wMinute = 0;
1033 st.wSecond = 0;
1034 st.wMilliseconds = 0;
1035 st.wDayOfWeek = 0;
1036
1037 res = SendMessageA(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st);
1038 expect(1,res);
1039
1040 /* (0, 0) is the top left of the control - title */
1041 mchit.cbSize = MCHITTESTINFO_V1_SIZE;
1042 mchit.pt.x = 0;
1043 mchit.pt.y = 0;
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);
1049
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);
1058
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);
1067
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);
1076
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);
1085
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);
1094
1095 if (0)
1096 {
1097 /* (125, 115) is in active area - date from this month */
1098 mchit.pt.x = 125;
1099 mchit.pt.y = 115;
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);
1105 }
1106
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);
1115
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);
1124
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);
1133
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);
1142
1143 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_hit_test_seq, "monthcal hit test", TRUE);
1144
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. */
1148
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");
1154
1155 mchit.pt.x = 0;
1156 mchit.pt.y = (5/2) * r.bottom / 19;
1157 title_index = 0;
1158 old_res = SendMessageA(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1159 expect_hex(title_hits[title_index].ht, old_res);
1160
1161 in_the_middle = FALSE;
1162 month_count = year_count = 0;
1163 for (x = 0; x < r.right; x++){
1164 mchit.pt.x = 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) {
1170
1171 if (old_res == MCHT_TITLEBTNPREV)
1172 in_the_middle = TRUE;
1173
1174 if (res == MCHT_TITLEBTNNEXT)
1175 in_the_middle = FALSE;
1176
1177 if (in_the_middle) {
1178 if (res == MCHT_TITLEMONTH)
1179 month_count++;
1180 else if (res == MCHT_TITLEYEAR)
1181 year_count++;
1182 } else {
1183 title_index++;
1184
1185 if (sizeof(title_hits) / sizeof(title_hits[0]) <= title_index)
1186 break;
1187
1188 if (title_hits[title_index].todo) {
1189 todo_wine
1190 ok(title_hits[title_index].ht == res, "Expected %x, got %x, pos %d\n",
1191 title_hits[title_index].ht, res, x);
1192 } else {
1193 ok(title_hits[title_index].ht == res, "Expected %x, got %x, pos %d\n",
1194 title_hits[title_index].ht, res, x);
1195 }
1196 }
1197 old_res = res;
1198 }
1199 }
1200
1201 /* There are some limits, even if LOCALE_SYEARMONTH contains rubbish
1202 * or no month/year indicators at all */
1203 if (locale_month)
1204 todo_wine ok(month_count == 1, "Expected 1 month item, got %d\n", month_count);
1205 else
1206 ok(month_count <= 1, "Too many month items: %d\n", month_count);
1207
1208 if (locale_year)
1209 todo_wine ok(year_count == 1, "Expected 1 year item, got %d\n", year_count);
1210 else
1211 ok(year_count <= 1, "Too many year items: %d\n", year_count);
1212
1213 todo_wine ok(month_count + year_count >= 1, "Not enough month and year items\n");
1214
1215 ok(r.right <= x && title_index + 1 == sizeof(title_hits) / sizeof(title_hits[0]),
1216 "Wrong title layout\n");
1217
1218 DestroyWindow(hwnd);
1219 }
1220
1221 static void test_todaylink(void)
1222 {
1223 MCHITTESTINFO mchit;
1224 SYSTEMTIME st_test, st_new;
1225 UINT res;
1226 HWND hwnd;
1227 RECT r;
1228
1229 memset(&mchit, 0, sizeof(MCHITTESTINFO));
1230
1231 hwnd = create_monthcal_control(0);
1232
1233 res = SendMessageA(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r);
1234 expect(1, res);
1235 MoveWindow(hwnd, 0, 0, r.right, r.bottom, FALSE);
1236
1237 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1238
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);
1248
1249 st_test.wDay = 1;
1250 st_test.wMonth = 1;
1251 st_test.wYear = 2005;
1252
1253 res = SendMessageA(hwnd, MCM_SETTODAY, 0, (LPARAM)&st_test);
1254 expect(0, res);
1255
1256 memset(&st_new, 0, sizeof(st_new));
1257 res = SendMessageA(hwnd, MCM_GETTODAY, 0, (LPARAM)&st_new);
1258 expect(1, res);
1259 expect(1, st_new.wDay);
1260 expect(1, st_new.wMonth);
1261 expect(2005, st_new.wYear);
1262
1263 res = SendMessageA(hwnd, WM_LBUTTONDOWN, MK_LBUTTON, MAKELONG(mchit.pt.x, mchit.pt.y));
1264 expect(0, res);
1265
1266 memset(&st_new, 0, sizeof(st_new));
1267 res = SendMessageA(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_new);
1268 expect(1, res);
1269 expect(1, st_new.wDay);
1270 expect(1, st_new.wMonth);
1271 expect(2005, st_new.wYear);
1272
1273 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_todaylink_seq, "monthcal hit test", TRUE);
1274
1275 DestroyWindow(hwnd);
1276 }
1277
1278 static void test_today(void)
1279 {
1280 SYSTEMTIME st_test, st_new;
1281 int res;
1282 HWND hwnd;
1283
1284 hwnd = create_monthcal_control(0);
1285
1286 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1287
1288 /* Setter and Getters for "today" information */
1289
1290 /* check for overflow, should be ok */
1291 memset(&st_test, 0, sizeof(st_test));
1292 st_test.wDay = 38;
1293 st_test.wMonth = 38;
1294
1295 st_new.wDay = 27;
1296 st_new.wMonth = 27;
1297
1298 res = SendMessageA(hwnd, MCM_SETTODAY, 0, (LPARAM)&st_test);
1299 expect(0, res);
1300
1301 res = SendMessageA(hwnd, MCM_GETTODAY, 0, (LPARAM)&st_new);
1302 expect(1, res);
1303
1304 /* st_test should not change */
1305 expect(38, st_test.wDay);
1306 expect(38, st_test.wMonth);
1307
1308 /* st_new should change, overflow does not matter */
1309 expect(38, st_new.wDay);
1310 expect(38, st_new.wMonth);
1311
1312 /* check for zero, should be ok*/
1313 st_test.wDay = 0;
1314 st_test.wMonth = 0;
1315
1316 res = SendMessageA(hwnd, MCM_SETTODAY, 0, (LPARAM)&st_test);
1317 expect(0, res);
1318
1319 res = SendMessageA(hwnd, MCM_GETTODAY, 0, (LPARAM)&st_new);
1320 expect(1, res);
1321
1322 /* st_test should not change */
1323 expect(0, st_test.wDay);
1324 expect(0, st_test.wMonth);
1325
1326 /* st_new should change to zero*/
1327 expect(0, st_new.wDay);
1328 expect(0, st_new.wMonth);
1329
1330 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_today_seq, "monthcal today", TRUE);
1331
1332 DestroyWindow(hwnd);
1333 }
1334
1335 static void test_scroll(void)
1336 {
1337 int res;
1338 HWND hwnd;
1339
1340 hwnd = create_monthcal_control(0);
1341
1342 res = SendMessageA(hwnd, MCM_GETMONTHDELTA, 0, 0);
1343 expect(2, res);
1344
1345 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1346
1347 /* Setter and Getters for scroll rate */
1348 res = SendMessageA(hwnd, MCM_SETMONTHDELTA, 2, 0);
1349 expect(0, res);
1350
1351 res = SendMessageA(hwnd, MCM_SETMONTHDELTA, 3, 0);
1352 expect(2, res);
1353 res = SendMessageA(hwnd, MCM_GETMONTHDELTA, 0, 0);
1354 expect(3, res);
1355
1356 res = SendMessageA(hwnd, MCM_SETMONTHDELTA, 12, 0);
1357 expect(3, res);
1358 res = SendMessageA(hwnd, MCM_GETMONTHDELTA, 0, 0);
1359 expect(12, res);
1360
1361 res = SendMessageA(hwnd, MCM_SETMONTHDELTA, 15, 0);
1362 expect(12, res);
1363 res = SendMessageA(hwnd, MCM_GETMONTHDELTA, 0, 0);
1364 expect(15, res);
1365
1366 res = SendMessageA(hwnd, MCM_SETMONTHDELTA, -5, 0);
1367 expect(15, res);
1368 res = SendMessageA(hwnd, MCM_GETMONTHDELTA, 0, 0);
1369 expect(-5, res);
1370
1371 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_scroll_seq, "monthcal scroll", FALSE);
1372
1373 DestroyWindow(hwnd);
1374 }
1375
1376 static void test_monthrange(void)
1377 {
1378 int res;
1379 SYSTEMTIME st_visible[2], st_daystate[2], st;
1380 HWND hwnd;
1381 RECT r;
1382
1383 hwnd = create_monthcal_control(0);
1384
1385 memset(&st_visible, 0, sizeof(st_visible));
1386 memset(&st_daystate, 0, sizeof(st_daystate));
1387
1388 st.wYear = 2000;
1389 st.wMonth = 11;
1390 st.wDay = 28;
1391 st.wHour = 11;
1392 st.wMinute = 59;
1393 st.wSecond = 30;
1394 st.wMilliseconds = 0;
1395 st.wDayOfWeek = 0;
1396
1397 res = SendMessageA(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st);
1398 expect(1,res);
1399
1400 /* to be locale independent */
1401 SendMessageA(hwnd, MCM_SETFIRSTDAYOFWEEK, 0, (LPARAM)6);
1402
1403 res = SendMessageA(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r);
1404 expect(TRUE, res);
1405 /* resize control to display two Calendars */
1406 MoveWindow(hwnd, 0, 0, r.right, (5/2)*r.bottom, FALSE);
1407
1408 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1409
1410 res = SendMessageA(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st_visible);
1411 expect(2, res);
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);
1418
1419 res = SendMessageA(hwnd, MCM_GETMONTHRANGE, GMR_DAYSTATE, (LPARAM)st_daystate);
1420 expect(4, res);
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);
1427
1428 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_monthrange_seq, "monthcal monthrange", FALSE);
1429
1430 /* with null date array parameter */
1431 res = SendMessageA(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, 0);
1432 expect(2, res);
1433
1434 res = SendMessageA(hwnd, MCM_GETMONTHRANGE, GMR_DAYSTATE, 0);
1435 expect(4, res);
1436
1437 /* resize control to display single Calendar */
1438 MoveWindow(hwnd, 0, 0, r.right, r.bottom, FALSE);
1439
1440 memset(&st, 0, sizeof(st));
1441 st.wMonth = 9;
1442 st.wYear = 1752;
1443 st.wDay = 14;
1444
1445 res = SendMessageA(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st);
1446 expect(1, res);
1447
1448 /* September 1752 has 19 days */
1449 res = SendMessageA(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st_visible);
1450 expect(1, res);
1451
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);
1457
1458 expect(1752, st_visible[1].wYear);
1459 expect(9, st_visible[1].wMonth);
1460 expect(19, st_visible[1].wDay);
1461
1462 DestroyWindow(hwnd);
1463 }
1464
1465 static void test_maxselday(void)
1466 {
1467 int res;
1468 HWND hwnd;
1469 DWORD style;
1470
1471 hwnd = create_monthcal_control(0);
1472 /* if no style specified default to 1 */
1473 res = SendMessageA(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1474 expect(1, res);
1475 res = SendMessageA(hwnd, MCM_SETMAXSELCOUNT, 5, 0);
1476 expect(0, res);
1477 res = SendMessageA(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1478 expect(1, res);
1479
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);
1486
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);
1494
1495 hwnd = create_monthcal_control(MCS_MULTISELECT);
1496
1497 /* default width is a week */
1498 res = SendMessageA(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1499 expect(7, res);
1500
1501 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1502
1503 /* Setter and Getters for max selected days */
1504 res = SendMessageA(hwnd, MCM_SETMAXSELCOUNT, 5, 0);
1505 expect(1, res);
1506 res = SendMessageA(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1507 expect(5, res);
1508
1509 res = SendMessageA(hwnd, MCM_SETMAXSELCOUNT, 15, 0);
1510 expect(1, res);
1511 res = SendMessageA(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1512 expect(15, res);
1513
1514 /* test invalid value */
1515 res = SendMessageA(hwnd, MCM_SETMAXSELCOUNT, -1, 0);
1516 expect(0, res);
1517 res = SendMessageA(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1518 expect(15, res);
1519
1520 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_max_sel_day_seq, "monthcal MaxSelDay", FALSE);
1521
1522 /* zero value is invalid too */
1523 res = SendMessageA(hwnd, MCM_SETMAXSELCOUNT, 0, 0);
1524 expect(0, res);
1525 res = SendMessageA(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1526 expect(15, res);
1527
1528 DestroyWindow(hwnd);
1529 }
1530
1531 static void test_size(void)
1532 {
1533 int res;
1534 RECT r1, r2;
1535 HFONT hFont1, hFont2;
1536 LOGFONTA logfont;
1537 HWND hwnd;
1538
1539 hwnd = create_monthcal_control(0);
1540
1541 lstrcpyA(logfont.lfFaceName, "Arial");
1542 memset(&logfont, 0, sizeof(logfont));
1543 logfont.lfHeight = 12;
1544 hFont1 = CreateFontIndirectA(&logfont);
1545
1546 logfont.lfHeight = 24;
1547 hFont2 = CreateFontIndirectA(&logfont);
1548
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");
1553
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");
1558
1559 OffsetRect(&r1, -r1.left, -r1.top);
1560 OffsetRect(&r2, -r2.left, -r2.top);
1561
1562 ok(r1.bottom < r2.bottom, "Failed to get larger rect with larger font\n");
1563
1564 DestroyWindow(hwnd);
1565 }
1566
1567 static void test_create(void)
1568 {
1569 HWND hwnd;
1570
1571 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1572
1573 hwnd = create_monthcal_control(0);
1574 ok_sequence(sequences, PARENT_SEQ_INDEX, create_monthcal_control_seq, "create monthcal control", TRUE);
1575
1576 DestroyWindow(hwnd);
1577
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);
1582 }
1583
1584 static void test_destroy(void)
1585 {
1586 HWND hwnd;
1587
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);
1593
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);
1599 }
1600
1601 static void test_selrange(void)
1602 {
1603 HWND hwnd;
1604 SYSTEMTIME st, range[2], range2[2];
1605 BOOL ret, old_comctl32 = FALSE;
1606
1607 hwnd = create_monthcal_control(MCS_MULTISELECT);
1608
1609 /* just after creation selection should start and end today */
1610 ret = SendMessageA(hwnd, MCM_GETTODAY, 0, (LPARAM)&st);
1611 expect(TRUE, ret);
1612
1613 memset(range, 0xcc, sizeof(range));
1614 ret = SendMessageA(hwnd, MCM_GETSELRANGE, 0, (LPARAM)range);
1615 expect(TRUE, ret);
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)
1620 {
1621 win_skip("comctl32 <= 4.70 doesn't set some values\n");
1622 old_comctl32 = TRUE;
1623 }
1624 else
1625 {
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);
1631 }
1632
1633 expect(st.wYear, range[1].wYear);
1634 expect(st.wMonth, range[1].wMonth);
1635 expect(st.wDay, range[1].wDay);
1636 if (!old_comctl32)
1637 {
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);
1643 }
1644
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;
1649 range[0].wDay = 5;
1650 range[1] = range[0];
1651 range[1].wDay = 3;
1652
1653 ret = SendMessageA(hwnd, MCM_SETSELRANGE, 0, (LPARAM)range);
1654 expect(TRUE, ret);
1655
1656 ret = SendMessageA(hwnd, MCM_GETSELRANGE, 0, (LPARAM)range2);
1657 expect(TRUE, ret);
1658
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);
1667
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);
1676
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;
1681 range[0].wDay = 1;
1682 range[1] = range[0];
1683
1684 ret = SendMessageA(hwnd, MCM_SETSELRANGE, 0, (LPARAM)range);
1685 expect(TRUE, ret);
1686
1687 range[1] = range[0];
1688 /* default max. range is 7 days */
1689 range[1].wDay = 8;
1690
1691 ret = SendMessageA(hwnd, MCM_SETSELRANGE, 0, (LPARAM)range);
1692 expect(FALSE, ret);
1693
1694 ret = SendMessageA(hwnd, MCM_GETSELRANGE, 0, (LPARAM)range2);
1695 expect(TRUE, ret);
1696
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);
1703
1704 DestroyWindow(hwnd);
1705 }
1706
1707 static void test_killfocus(void)
1708 {
1709 HWND hwnd;
1710 DWORD style;
1711
1712 hwnd = create_monthcal_control(0);
1713
1714 /* make parent invisible */
1715 style = GetWindowLongA(parent_wnd, GWL_STYLE);
1716 SetWindowLongA(parent_wnd, GWL_STYLE, style & ~WS_VISIBLE);
1717
1718 SendMessageA(hwnd, WM_KILLFOCUS, (WPARAM)GetDesktopWindow(), 0);
1719
1720 style = GetWindowLongA(hwnd, GWL_STYLE);
1721 ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
1722
1723 style = GetWindowLongA(parent_wnd, GWL_STYLE);
1724 SetWindowLongA(parent_wnd, GWL_STYLE, style | WS_VISIBLE);
1725
1726 DestroyWindow(hwnd);
1727 }
1728
1729 static void test_hittest_v6(void)
1730 {
1731 MCHITTESTINFO mchit;
1732 DWORD ret;
1733 HWND hwnd;
1734 RECT r;
1735
1736 hwnd = create_monthcal_control(0);
1737 SendMessageA(hwnd, MCM_SETCALENDARBORDER, TRUE, 0);
1738
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;
1744 mchit.iOffset = -1;
1745 mchit.iRow = -1;
1746 mchit.iCol = -1;
1747 ret = SendMessageA(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1748 if (ret == ~0u)
1749 {
1750 win_skip("Only MCHITTESTINFO_V1 supported\n");
1751 DestroyWindow(hwnd);
1752 return;
1753 }
1754 todo_wine expect_hex(MCHT_NOWHERE, ret);
1755 expect(-1, mchit.iOffset);
1756 expect(-1, mchit.iRow);
1757 expect(-1, mchit.iCol);
1758
1759 MoveWindow(hwnd, 0, 0, r.right, r.bottom, FALSE);
1760 mchit.pt.x = r.right / 2;
1761 mchit.pt.y = r.bottom / 2;
1762 mchit.iOffset = -1;
1763 ret = SendMessageA(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1764 expect_hex(MCHT_CALENDARDATE, ret);
1765 expect(0, mchit.iOffset);
1766
1767 /* over day area */
1768 mchit.pt.x = r.right / (7*2);
1769 mchit.pt.y = r.bottom / 2;
1770 mchit.iOffset = -1;
1771 mchit.iCol = mchit.iRow = -1;
1772 mchit.uHit = 0;
1773 mchit.rc.left = mchit.rc.right = mchit.rc.top = mchit.rc.bottom = -1;
1774 ret = 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);
1783
1784 /* title */
1785 mchit.pt.x = 1;
1786 mchit.pt.y = 1;
1787 mchit.iOffset = -1;
1788 mchit.iCol = mchit.iRow = -1;
1789 mchit.uHit = 0;
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);
1801
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;
1806 mchit.iOffset = -2;
1807 mchit.iCol = mchit.iRow = -2;
1808 mchit.uHit = ~0;
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);
1820
1821 DestroyWindow(hwnd);
1822 }
1823
1824 static void test_get_set_border(void)
1825 {
1826 HWND hwnd;
1827 DWORD ret;
1828
1829 hwnd = create_monthcal_control(0);
1830
1831 /* a non-default value */
1832 ret = SendMessageA(hwnd, MCM_SETCALENDARBORDER, TRUE, 10);
1833 expect(0, ret);
1834
1835 ret = SendMessageA(hwnd, MCM_GETCALENDARBORDER, 0, 0);
1836
1837 if (ret != 10)
1838 {
1839 skip("MCM_GET/SETCALENDARBORDER not supported\n");
1840 DestroyWindow(hwnd);
1841 return;
1842 }
1843
1844 expect(10, ret);
1845
1846 DestroyWindow(hwnd);
1847 }
1848
1849 static void test_MCM_SIZERECTTOMIN(void)
1850 {
1851 HWND hwnd;
1852 DWORD ret;
1853 RECT r, r2;
1854
1855 hwnd = create_monthcal_control(0);
1856
1857 ret = SendMessageA(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r2);
1858 if (ret == 0)
1859 {
1860 win_skip("Message MCM_GETMINREQRECT unsupported. Skipping.\n");
1861 DestroyWindow(hwnd);
1862 return;
1863 }
1864
1865 ret = SendMessageA(hwnd, MCM_SIZERECTTOMIN, 0, 0);
1866 ok(ret == 0, "got %d\n", ret);
1867
1868 r.left = r.right = r.top = r.bottom = 0;
1869 ret = SendMessageA(hwnd, MCM_SIZERECTTOMIN, 0, (LPARAM)&r);
1870 if (ret == 0)
1871 {
1872 skip("Message MCM_SIZERECTTOMIN unsupported. Skipping.\n");
1873 DestroyWindow(hwnd);
1874 return;
1875 }
1876 ok(ret == 1, "got %d\n", ret);
1877 ok(r.left == 0 && r.right > 0, "got %d, %d\n", r.left, r.right);
1878
1879 r = r2;
1880 ret = SendMessageA(hwnd, MCM_SIZERECTTOMIN, 0, (LPARAM)&r);
1881 ok(ret == 1, "got %d\n", ret);
1882
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);
1888
1889 DestroyWindow(hwnd);
1890 }
1891
1892 static void test_MCM_GETCALENDARCOUNT(void)
1893 {
1894 HWND hwnd;
1895 DWORD ret;
1896
1897 hwnd = create_monthcal_control(0);
1898
1899 ret = SendMessageA(hwnd, MCM_GETCALENDARCOUNT, 0, 0);
1900 if (ret == 0)
1901 {
1902 win_skip("Message MCM_GETCALENDARCOUNT unsupported. Skipping.\n");
1903 DestroyWindow(hwnd);
1904 return;
1905 }
1906
1907 expect(2, ret);
1908
1909 DestroyWindow(hwnd);
1910 }
1911
1912 static void test_daystate(void)
1913 {
1914 MONTHDAYSTATE state[4];
1915 DWORD ret, style;
1916 HWND hwnd;
1917 RECT r;
1918
1919 /* without MCS_DAYSTATE */
1920 hwnd = create_monthcal_control(0);
1921
1922 ret = SendMessageA(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r);
1923 expect(TRUE, ret);
1924
1925 /* resize control to display two Calendars */
1926 MoveWindow(hwnd, 0, 0, r.right, (5/2)*r.bottom, FALSE);
1927
1928 ret = SendMessageA(hwnd, MCM_GETMONTHRANGE, GMR_DAYSTATE, 0);
1929 expect(4, ret);
1930
1931 ret = SendMessageA(hwnd, MCM_SETDAYSTATE, 4, (LPARAM)&state);
1932 expect(0, ret);
1933
1934 ret = SendMessageA(hwnd, MCM_SETDAYSTATE, 2, (LPARAM)&state);
1935 expect(0, ret);
1936
1937 ret = SendMessageA(hwnd, MCM_SETDAYSTATE, 0, 0);
1938 expect(0, ret);
1939
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);
1944
1945 DestroyWindow(hwnd);
1946
1947 /* with MCS_DAYSTATE */
1948 hwnd = create_monthcal_control(MCS_DAYSTATE);
1949
1950 ret = SendMessageA(hwnd, MCM_GETMONTHRANGE, GMR_DAYSTATE, 0);
1951 expect(4, ret);
1952
1953 ret = SendMessageA(hwnd, MCM_SETDAYSTATE, 4, (LPARAM)&state);
1954 expect(1, ret);
1955
1956 ret = SendMessageA(hwnd, MCM_SETDAYSTATE, 2, (LPARAM)&state);
1957 expect(0, ret);
1958
1959 ret = SendMessageA(hwnd, MCM_SETDAYSTATE, 0, 0);
1960 expect(0, ret);
1961
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);
1966
1967 DestroyWindow(hwnd);
1968 }
1969
1970 static void test_sel_notify(void)
1971 {
1972 typedef struct
1973 {
1974 DWORD val;
1975 const char* name;
1976 } Monthcal_style;
1977
1978 HWND hwnd;
1979 RECT rc;
1980 MCHITTESTINFO mchit = {sizeof(MCHITTESTINFO)};
1981 SYSTEMTIME st;
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"}
1987 };
1988 int i;
1989
1990 for(i = 0; i < sizeof styles / sizeof styles[0]; i++)
1991 {
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 */
2003 {
2004 mchit.pt.y++;
2005 SendMessageA(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
2006 }
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);
2010 }
2011 }
2012
2013 START_TEST(monthcal)
2014 {
2015 BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
2016 INITCOMMONCONTROLSEX iccex;
2017 HMODULE hComctl32;
2018
2019 ULONG_PTR ctx_cookie;
2020 HANDLE hCtx;
2021
2022 hComctl32 = GetModuleHandleA("comctl32.dll");
2023 pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
2024 if (!pInitCommonControlsEx)
2025 {
2026 skip("InitCommonControlsEx() is missing. Skipping the tests\n");
2027 return;
2028 }
2029 iccex.dwSize = sizeof(iccex);
2030 iccex.dwICC = ICC_DATE_CLASSES;
2031 pInitCommonControlsEx(&iccex);
2032
2033 test_monthcal();
2034
2035 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
2036
2037 parent_wnd = create_parent_window();
2038
2039 test_create();
2040 test_destroy();
2041 test_color();
2042 test_currdate();
2043 test_firstDay();
2044 test_unicode();
2045 test_today();
2046 test_scroll();
2047 test_monthrange();
2048 test_hittest();
2049 test_todaylink();
2050 test_size();
2051 test_maxselday();
2052 test_selrange();
2053 test_killfocus();
2054 test_daystate();
2055 test_sel_notify();
2056
2057 if (!load_v6_module(&ctx_cookie, &hCtx))
2058 {
2059 DestroyWindow(parent_wnd);
2060 return;
2061 }
2062
2063 test_hittest_v6();
2064 test_get_set_border();
2065 test_MCM_SIZERECTTOMIN();
2066 test_MCM_GETCALENDARCOUNT();
2067
2068 unload_v6_module(ctx_cookie, hCtx);
2069
2070 DestroyWindow(parent_wnd);
2071 }