54a982e05170cebab0399e072cb2eba77702cac6
[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 = SendMessage(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 SendMessage(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(SendMessage(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(SendMessage(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(SendMessage(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(!SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Should have failed to set limits\n");
351 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "No limits should be set\n");
352 ok(st1[0].wYear != 2000, "Lower limit changed\n");
353 ok(!SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Should have failed to set MAX limit\n");
354 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "No limits should be set\n");
355 ok(st1[0].wYear != 2000, "Lower limit changed\n");
356
357 GetSystemTime(&st[0]);
358 st[0].wDay = 20;
359 st[0].wMonth = 5;
360 st[1] = st[0];
361
362 month_range = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st1);
363 st[1].wMonth--;
364 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Failed to set both min and max limits\n");
365 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st1);
366 ok(res == month_range, "Invalid month range (%d)\n", res);
367 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == (GDTR_MIN|GDTR_MAX), "Limits should be set\n");
368
369 st[1].wMonth += 2;
370 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Failed to set both min and max limits\n");
371 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st1);
372 ok(res == month_range, "Invalid month range (%d)\n", res);
373
374 st[1].wYear --;
375 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Failed to set both min and max limits\n");
376 st[1].wYear += 1;
377 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Failed to set both min and max limits\n");
378
379 st[1].wMonth -= 3;
380 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
381 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "Only MAX limit should be set\n");
382 st[1].wMonth += 4;
383 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
384 st[1].wYear -= 3;
385 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
386 st[1].wYear += 4;
387 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
388 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "Only MAX limit should be set\n");
389
390 /* set both limits, then set max < min */
391 GetSystemTime(&st[0]);
392 st[0].wDay = 25;
393 st[1] = st[0];
394 st[1].wYear++;
395 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN|GDTR_MAX, (LPARAM)st), "Failed to set limits\n");
396 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == (GDTR_MIN|GDTR_MAX), "Min limit expected\n");
397 st[1].wYear -= 2;
398 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set limits\n");
399 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "Max limit expected\n");
400
401 expect(0, st1[0].wYear);
402 expect(0, st1[0].wMonth);
403 expect(0, st1[0].wDay);
404 expect(0, st1[0].wDayOfWeek);
405 expect(0, st1[0].wHour);
406 expect(0, st1[0].wMinute);
407 expect(0, st1[0].wSecond);
408 expect(0, st1[0].wMilliseconds);
409
410 expect(st[1].wYear, st1[1].wYear);
411 expect(st[1].wMonth, st1[1].wMonth);
412 expect(st[1].wDay, st1[1].wDay);
413 expect(st[1].wDayOfWeek, st1[1].wDayOfWeek);
414 expect(st[1].wHour, st1[1].wHour);
415 expect(st[1].wMinute, st1[1].wMinute);
416 expect(st[1].wSecond, st1[1].wSecond);
417 expect(st[1].wMilliseconds, st1[1].wMilliseconds);
418
419 st[1] = st[0];
420 st[1].wYear++;
421 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN|GDTR_MAX, (LPARAM)st), "Failed to set limits\n");
422 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == (GDTR_MIN|GDTR_MAX), "Min limit expected\n");
423 st[0].wYear++; /* start == end now */
424 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN, (LPARAM)st), "Failed to set limits\n");
425 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MIN, "Min limit expected\n");
426
427 expect(st[0].wYear, st1[0].wYear);
428 expect(st[0].wMonth, st1[0].wMonth);
429 expect(st[0].wDay, st1[0].wDay);
430 expect(st[0].wDayOfWeek, st1[0].wDayOfWeek);
431 expect(st[0].wHour, st1[0].wHour);
432 expect(st[0].wMinute, st1[0].wMinute);
433 expect(st[0].wSecond, st1[0].wSecond);
434 expect(st[0].wMilliseconds, st1[0].wMilliseconds);
435
436 expect(0, st1[1].wYear);
437 expect(0, st1[1].wMonth);
438 expect(0, st1[1].wDay);
439 expect(0, st1[1].wDayOfWeek);
440 expect(0, st1[1].wHour);
441 expect(0, st1[1].wMinute);
442 expect(0, st1[1].wSecond);
443 expect(0, st1[1].wMilliseconds);
444
445 DestroyWindow(hwnd);
446 }
447
448 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
449 {
450 static LONG defwndproc_counter = 0;
451 LRESULT ret;
452 struct message msg;
453
454 /* log system messages, except for painting */
455 if (message < WM_USER &&
456 message != WM_PAINT &&
457 message != WM_ERASEBKGND &&
458 message != WM_NCPAINT &&
459 message != WM_NCHITTEST &&
460 message != WM_GETTEXT &&
461 message != WM_GETICON &&
462 message != WM_DEVICECHANGE)
463 {
464 msg.message = message;
465 msg.flags = sent|wparam|lparam;
466 if (defwndproc_counter) msg.flags |= defwinproc;
467 msg.wParam = wParam;
468 msg.lParam = lParam;
469 add_message(sequences, PARENT_SEQ_INDEX, &msg);
470 }
471
472 if (message == WM_NOTIFY)
473 {
474 NMHDR *hdr = (NMHDR*)lParam;
475 switch (hdr->code)
476 {
477 case MCN_GETDAYSTATE:
478 {
479 NMDAYSTATE *nmstate = (NMDAYSTATE*)lParam;
480 static MONTHDAYSTATE months[14] = { 0 };
481
482 ok(nmstate->cDayState > 0, "got %d\n", nmstate->cDayState);
483 ok(nmstate->cDayState <= 14, "got %d\n", nmstate->cDayState);
484 ok(nmstate->prgDayState != NULL, "got %p\n", nmstate->prgDayState);
485
486 nmstate->prgDayState = months;
487
488 return TRUE;
489 }
490 case MCN_SELECT:
491 case MCN_SELCHANGE:
492 {
493 NMSELCHANGE *nmchg = (NMSELCHANGE*)lParam;
494 SYSTEMTIME st[2];
495 BOOL is_multisel = GetWindowLongPtr(nmchg->nmhdr.hwndFrom, GWL_STYLE) &
496 MCS_MULTISELECT;
497
498 if(GetWindowLongPtr(nmchg->nmhdr.hwndFrom, GWLP_ID) != SEL_NOTIFY_TEST_ID)
499 break;
500 SendMessage(nmchg->nmhdr.hwndFrom, is_multisel ? MCM_GETSELRANGE :
501 MCM_GETCURSEL, 0, (LPARAM)st);
502
503 expect(st[0].wYear, nmchg->stSelStart.wYear);
504 expect(st[0].wMonth, nmchg->stSelStart.wMonth);
505 expect(0, nmchg->stSelStart.wDayOfWeek);
506 expect(st[0].wDay, nmchg->stSelStart.wDay);
507
508 if(is_multisel)
509 {
510 expect(st[1].wYear, nmchg->stSelEnd.wYear);
511 expect(st[1].wMonth, nmchg->stSelEnd.wMonth);
512 expect(0, nmchg->stSelEnd.wDayOfWeek);
513 expect(st[1].wDay, nmchg->stSelEnd.wDay);
514 }
515 else
516 ok(!(nmchg->stSelEnd.wYear | nmchg->stSelEnd.wMonth |
517 nmchg->stSelEnd.wDayOfWeek | nmchg->stSelEnd.wDay |
518 nmchg->stSelEnd.wHour | nmchg->stSelEnd.wMinute |
519 nmchg->stSelEnd.wSecond | nmchg->stSelEnd.wMilliseconds),
520 "Non-zero member in stSelEnd\n");
521 return TRUE;
522 }
523 default:
524 break;
525 }
526 }
527
528 defwndproc_counter++;
529 ret = DefWindowProcA(hwnd, message, wParam, lParam);
530 defwndproc_counter--;
531
532 return ret;
533 }
534
535 static BOOL register_parent_wnd_class(void)
536 {
537 WNDCLASSA cls;
538
539 cls.style = 0;
540 cls.lpfnWndProc = parent_wnd_proc;
541 cls.cbClsExtra = 0;
542 cls.cbWndExtra = 0;
543 cls.hInstance = GetModuleHandleA(NULL);
544 cls.hIcon = 0;
545 cls.hCursor = LoadCursorA(0, IDC_ARROW);
546 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
547 cls.lpszMenuName = NULL;
548 cls.lpszClassName = "Month-Cal test parent class";
549 return RegisterClassA(&cls);
550 }
551
552 static HWND create_parent_window(void)
553 {
554 HWND hwnd;
555
556 InitCommonControls();
557
558 /* flush message sequences, so we can check the new sequence by the end of function */
559 flush_sequences(sequences, NUM_MSG_SEQUENCES);
560
561 if (!register_parent_wnd_class())
562 return NULL;
563
564 hwnd = CreateWindowEx(0, "Month-Cal test parent class",
565 "Month-Cal test parent window",
566 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
567 WS_MAXIMIZEBOX | WS_VISIBLE,
568 0, 0, 500, 500,
569 GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL);
570
571 assert(hwnd);
572
573 /* check for message sequences */
574 ok_sequence(sequences, PARENT_SEQ_INDEX, create_parent_window_seq, "create parent window", FALSE);
575
576 return hwnd;
577 }
578
579 static LRESULT WINAPI monthcal_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
580 {
581 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
582 static LONG defwndproc_counter = 0;
583 LRESULT ret;
584 struct message msg;
585
586 msg.message = message;
587 msg.flags = sent|wparam|lparam;
588 if (defwndproc_counter) msg.flags |= defwinproc;
589 msg.wParam = wParam;
590 msg.lParam = lParam;
591 msg.id = 0;
592 add_message(sequences, MONTHCAL_SEQ_INDEX, &msg);
593
594 /* some debug output for style changing */
595 if ((message == WM_STYLECHANGING ||
596 message == WM_STYLECHANGED) && lParam)
597 {
598 STYLESTRUCT *style = (STYLESTRUCT*)lParam;
599 trace("\told style: 0x%08x, new style: 0x%08x\n", style->styleOld, style->styleNew);
600 }
601
602 defwndproc_counter++;
603 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
604 defwndproc_counter--;
605
606 return ret;
607 }
608
609 static HWND create_monthcal_control(DWORD style)
610 {
611 WNDPROC oldproc;
612 HWND hwnd;
613
614 hwnd = CreateWindowEx(0,
615 MONTHCAL_CLASS,
616 "",
617 WS_CHILD | WS_BORDER | WS_VISIBLE | style,
618 0, 0, 300, 400,
619 parent_wnd, NULL, GetModuleHandleA(NULL), NULL);
620
621 if (!hwnd) return NULL;
622
623 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
624 (LONG_PTR)monthcal_subclass_proc);
625 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
626
627 SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(SYSTEM_FONT), 0);
628
629 return hwnd;
630 }
631
632
633 /* Setter and Getters Tests */
634
635 static void test_color(void)
636 {
637 COLORREF color, prev;
638 HWND hwnd;
639
640 hwnd = create_monthcal_control(0);
641
642 /* invalid color index */
643 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT + 1, 0);
644 expect(~0u, color);
645 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TRAILINGTEXT + 1, RGB(255,255,255));
646 expect(~0u, prev);
647
648 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_BACKGROUND, 0);
649 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_BACKGROUND, RGB(0,0,0));
650 expect(color, prev);
651 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_BACKGROUND, 0);
652 expect(RGB(0,0,0), color);
653 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_BACKGROUND, RGB(255,255,255));
654 expect(color, prev);
655 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_BACKGROUND, 0);
656 expect(RGB(255,255,255), color);
657
658 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_MONTHBK, 0);
659 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_MONTHBK, RGB(0,0,0));
660 expect(color, prev);
661 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_MONTHBK, 0);
662 expect(RGB(0,0,0), color);
663 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_MONTHBK, RGB(255,255,255));
664 expect(color, prev);
665 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_MONTHBK, 0);
666 expect(RGB(255,255,255), color);
667
668 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TEXT, 0);
669 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TEXT, RGB(0,0,0));
670 expect(color, prev);
671 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TEXT, 0);
672 expect(RGB(0,0,0), color);
673 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TEXT, RGB(255,255,255));
674 expect(color, prev);
675 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TEXT, 0);
676 expect(RGB(255,255,255), color);
677
678 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLEBK, 0);
679 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLEBK, RGB(0,0,0));
680 expect(color, prev);
681 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLEBK, 0);
682 expect(RGB(0,0,0), color);
683 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLEBK, RGB(255,255,255));
684 expect(color, prev);
685 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLEBK, 0);
686 expect(RGB(255,255,255), color);
687
688 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLETEXT, 0);
689 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLETEXT, RGB(0,0,0));
690 expect(color, prev);
691 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLETEXT, 0);
692 expect(RGB(0,0,0), color);
693 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLETEXT, RGB(255,255,255));
694 expect(color, prev);
695 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLETEXT, 0);
696 expect(RGB(255,255,255), color);
697
698 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT, 0);
699 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TRAILINGTEXT, RGB(0,0,0));
700 expect(color, prev);
701 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT, 0);
702 expect(RGB(0,0,0), color);
703 prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TRAILINGTEXT, RGB(255,255,255));
704 expect(color, prev);
705 color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT, 0);
706 expect(RGB(255,255,255), color);
707
708 DestroyWindow(hwnd);
709 }
710
711 static void test_currdate(void)
712 {
713 SYSTEMTIME st_original, st_new, st_test;
714 int res;
715 HWND hwnd;
716
717 hwnd = create_monthcal_control(0);
718
719 flush_sequences(sequences, NUM_MSG_SEQUENCES);
720
721 /* Setter and Getters for current date selected */
722 st_original.wYear = 2000;
723 st_original.wMonth = 11;
724 st_original.wDay = 28;
725 st_original.wHour = 11;
726 st_original.wMinute = 59;
727 st_original.wSecond = 30;
728 st_original.wMilliseconds = 0;
729 st_original.wDayOfWeek = 0;
730
731 st_new = st_test = st_original;
732
733 /* Should not validate the time */
734 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
735 expect(1,res);
736
737 /* Overflow matters, check for wDay */
738 st_test.wDay += 4;
739 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
740 expect(0,res);
741
742 /* correct wDay before checking for wMonth */
743 st_test.wDay -= 4;
744 expect(st_original.wDay, st_test.wDay);
745
746 /* Overflow matters, check for wMonth */
747 st_test.wMonth += 4;
748 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
749 expect(0,res);
750
751 /* checking if gets the information right, modify st_new */
752 st_new.wYear += 4;
753 st_new.wMonth += 4;
754 st_new.wDay += 4;
755 st_new.wHour += 4;
756 st_new.wMinute += 4;
757 st_new.wSecond += 4;
758
759 res = SendMessage(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_new);
760 expect(1, res);
761
762 /* st_new change to st_origin, above settings with overflow */
763 /* should not change the current settings */
764 expect(st_original.wYear, st_new.wYear);
765 expect(st_original.wMonth, st_new.wMonth);
766 expect(st_original.wDay, st_new.wDay);
767 ok(st_original.wHour == st_new.wHour ||
768 broken(0 == st_new.wHour), /* comctl32 <= 4.70 */
769 "Expected %d, got %d\n", st_original.wHour, st_new.wHour);
770 ok(st_original.wMinute == st_new.wMinute ||
771 broken(0 == st_new.wMinute), /* comctl32 <= 4.70 */
772 "Expected %d, got %d\n", st_original.wMinute, st_new.wMinute);
773 ok(st_original.wSecond == st_new.wSecond ||
774 broken(0 == st_new.wSecond), /* comctl32 <= 4.70 */
775 "Expected %d, got %d\n", st_original.wSecond, st_new.wSecond);
776
777 /* lparam cannot be NULL */
778 res = SendMessage(hwnd, MCM_GETCURSEL, 0, 0);
779 expect(0, res);
780
781 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_curr_date_seq, "monthcal currDate", TRUE);
782
783 /* December, 31, 9999 is the maximum allowed date */
784 memset(&st_new, 0, sizeof(st_new));
785 st_new.wYear = 9999;
786 st_new.wMonth = 12;
787 st_new.wDay = 31;
788 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_new);
789 expect(1, res);
790 memset(&st_test, 0, sizeof(st_test));
791 res = SendMessage(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_test);
792 expect(1, res);
793 expect(st_new.wYear, st_test.wYear);
794 expect(st_new.wMonth, st_test.wMonth);
795 expect(st_new.wDay, st_test.wDay);
796 expect(st_new.wHour, st_test.wHour);
797 expect(st_new.wMinute, st_test.wMinute);
798 expect(st_new.wSecond, st_test.wSecond);
799 /* try one day later */
800 st_original = st_new;
801 st_new.wYear = 10000;
802 st_new.wMonth = 1;
803 st_new.wDay = 1;
804 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_new);
805 ok(0 == res ||
806 broken(1 == res), /* comctl32 <= 4.72 */
807 "Expected 0, got %d\n", res);
808 if (0 == res)
809 {
810 memset(&st_test, 0, sizeof(st_test));
811 res = SendMessage(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_test);
812 expect(1, res);
813 expect(st_original.wYear, st_test.wYear);
814 expect(st_original.wMonth, st_test.wMonth);
815 expect(st_original.wDay, st_test.wDay);
816 expect(st_original.wHour, st_test.wHour);
817 expect(st_original.wMinute, st_test.wMinute);
818 expect(st_original.wSecond, st_test.wSecond);
819 }
820
821 /* setting selection equal to current reports success even if out range */
822 memset(&st_new, 0, sizeof(st_new));
823 st_new.wYear = 2009;
824 st_new.wDay = 5;
825 st_new.wMonth = 10;
826 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_new);
827 expect(1, res);
828 memset(&st_test, 0, sizeof(st_test));
829 st_test.wYear = 2009;
830 st_test.wDay = 6;
831 st_test.wMonth = 10;
832 res = SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN, (LPARAM)&st_test);
833 expect(1, res);
834 /* set to current again */
835 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_new);
836 expect(1, res);
837
838 /* set with invalid day of week */
839 memset(&st_test, 0, sizeof(st_test));
840 st_test.wYear = 2009;
841 st_test.wDay = 7;
842 st_test.wMonth = 10;
843 st_test.wDayOfWeek = 100;
844 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
845 expect(1, res);
846
847 memset(&st_test, 0, sizeof(st_test));
848 res = SendMessage(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_test);
849 expect(1, res);
850 expect(2009, st_test.wYear);
851 expect(7, st_test.wDay);
852 expect(10, st_test.wMonth);
853 expect(3, st_test.wDayOfWeek);
854
855 DestroyWindow(hwnd);
856 }
857
858 static void test_firstDay(void)
859 {
860 int res, fday, i, prev;
861 CHAR b[128], caltype[3];
862 LCID lcid = LOCALE_USER_DEFAULT;
863 HWND hwnd;
864 LRESULT ret;
865
866 SetLastError(0xdeadbeef);
867 ret = GetLocaleInfoA(lcid, LOCALE_ICALENDARTYPE, caltype, 3);
868 if (ret == 0) {
869 skip("Must know local calendar type (%x)\n", GetLastError());
870 return;
871 } else if (atoi(caltype) != CAL_GREGORIAN) {
872 skip("MonthCalendar Control only supports Gregorian calendar (type: %s)\n", caltype);
873 return;
874 }
875
876 hwnd = create_monthcal_control(0);
877
878 flush_sequences(sequences, NUM_MSG_SEQUENCES);
879
880 /* Setter and Getters for first day of week */
881 /* check for locale first day */
882 if(GetLocaleInfoA(lcid, LOCALE_IFIRSTDAYOFWEEK, b, 128)){
883 fday = atoi(b);
884 res = SendMessage(hwnd, MCM_GETFIRSTDAYOFWEEK, 0, 0);
885 expect(fday, res);
886 prev = fday;
887
888 /* checking for the values that actually will be stored as */
889 /* current first day when we set a new value */
890 for (i = -5; i < 12; i++){
891 res = SendMessage(hwnd, MCM_SETFIRSTDAYOFWEEK, 0, i);
892 expect(prev, res);
893 res = SendMessage(hwnd, MCM_GETFIRSTDAYOFWEEK, 0, 0);
894 prev = res;
895
896 if (i == -1){
897 expect(MAKELONG(fday, FALSE), res);
898 }else if (i >= 7){
899 /* out of range sets max first day of week, locale is ignored */
900 expect(MAKELONG(6, TRUE), res);
901 }else{
902 expect(MAKELONG(i, TRUE), res);
903 }
904 }
905
906 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_first_day_seq, "monthcal firstDay", FALSE);
907
908 }else{
909 skip("Cannot retrieve first day of the week\n");
910 }
911
912 DestroyWindow(hwnd);
913 }
914
915 static void test_unicode(void)
916 {
917 int res, temp;
918 HWND hwnd;
919
920 hwnd = create_monthcal_control(0);
921
922 flush_sequences(sequences, NUM_MSG_SEQUENCES);
923
924 /* Setter and Getters for Unicode format */
925
926 /* getting the current settings */
927 temp = SendMessage(hwnd, MCM_GETUNICODEFORMAT, 0, 0);
928
929 /* setting to 1, should return previous settings */
930 res = SendMessage(hwnd, MCM_SETUNICODEFORMAT, 1, 0);
931 expect(temp, res);
932
933 /* current setting is 1, so, should return 1 */
934 res = SendMessage(hwnd, MCM_GETUNICODEFORMAT, 0, 0);
935 ok(1 == res ||
936 broken(0 == res), /* comctl32 <= 4.70 */
937 "Expected 1, got %d\n", res);
938
939 /* setting to 0, should return previous settings */
940 res = SendMessage(hwnd, MCM_SETUNICODEFORMAT, 0, 0);
941 ok(1 == res ||
942 broken(0 == res), /* comctl32 <= 4.70 */
943 "Expected 1, got %d\n", res);
944
945 /* current setting is 0, so, it should return 0 */
946 res = SendMessage(hwnd, MCM_GETUNICODEFORMAT, 0, 0);
947 expect(0, res);
948
949 /* should return previous settings */
950 res = SendMessage(hwnd, MCM_SETUNICODEFORMAT, 1, 0);
951 expect(0, res);
952
953 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_unicode_seq, "monthcal unicode", FALSE);
954
955 DestroyWindow(hwnd);
956 }
957
958 static void test_hittest(void)
959 {
960 typedef struct hittest_test
961 {
962 UINT ht;
963 int todo;
964 } hittest_test_t;
965
966 static const hittest_test_t title_hits[] = {
967 /* Start is the same everywhere */
968 { MCHT_TITLE, 0 },
969 { MCHT_TITLEBTNPREV, 0 },
970 /* The middle piece is only tested for presence of items */
971 /* End is the same everywhere */
972 { MCHT_TITLEBTNNEXT, 0 },
973 { MCHT_TITLE, 0 },
974 { MCHT_NOWHERE, 1 }
975 };
976
977 MCHITTESTINFO mchit;
978 UINT res, old_res;
979 SYSTEMTIME st;
980 LONG x;
981 UINT title_index;
982 HWND hwnd;
983 RECT r;
984 char yearmonth[80], *locale_month, *locale_year;
985 int month_count, year_count;
986 BOOL in_the_middle;
987
988 memset(&mchit, 0, sizeof(MCHITTESTINFO));
989
990 hwnd = create_monthcal_control(0);
991
992 /* test with invalid structure size */
993 mchit.cbSize = MCHITTESTINFO_V1_SIZE - 1;
994 mchit.pt.x = 0;
995 mchit.pt.y = 0;
996 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
997 expect(0, mchit.pt.x);
998 expect(0, mchit.pt.y);
999 expect(~0u, res);
1000 expect(0, mchit.uHit);
1001 /* test with invalid pointer */
1002 res = SendMessage(hwnd, MCM_HITTEST, 0, 0);
1003 expect(~0u, res);
1004
1005 /* resize control to display single Calendar */
1006 res = SendMessage(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r);
1007 if (res == 0)
1008 {
1009 win_skip("Message MCM_GETMINREQRECT unsupported. Skipping.\n");
1010 DestroyWindow(hwnd);
1011 return;
1012 }
1013 MoveWindow(hwnd, 0, 0, r.right, r.bottom, FALSE);
1014
1015 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1016
1017 st.wYear = 2007;
1018 st.wMonth = 4;
1019 st.wDay = 11;
1020 st.wHour = 1;
1021 st.wMinute = 0;
1022 st.wSecond = 0;
1023 st.wMilliseconds = 0;
1024 st.wDayOfWeek = 0;
1025
1026 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st);
1027 expect(1,res);
1028
1029 /* (0, 0) is the top left of the control - title */
1030 mchit.cbSize = MCHITTESTINFO_V1_SIZE;
1031 mchit.pt.x = 0;
1032 mchit.pt.y = 0;
1033 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1034 expect(0, mchit.pt.x);
1035 expect(0, mchit.pt.y);
1036 expect(mchit.uHit, res);
1037 expect_hex(MCHT_TITLE, res);
1038
1039 /* bottom right of the control and should not be active */
1040 mchit.pt.x = r.right;
1041 mchit.pt.y = r.bottom;
1042 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1043 expect(r.right, mchit.pt.x);
1044 expect(r.bottom, mchit.pt.y);
1045 expect(mchit.uHit, res);
1046 todo_wine expect_hex(MCHT_NOWHERE, res);
1047
1048 /* completely out of the control, should not be active */
1049 mchit.pt.x = 2 * r.right;
1050 mchit.pt.y = 2 * r.bottom;
1051 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1052 expect(2 * r.right, mchit.pt.x);
1053 expect(2 * r.bottom, mchit.pt.y);
1054 expect(mchit.uHit, res);
1055 todo_wine expect_hex(MCHT_NOWHERE, res);
1056
1057 /* in active area - day of the week */
1058 mchit.pt.x = r.right / 2;
1059 mchit.pt.y = r.bottom / 2;
1060 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1061 expect(r.right / 2, mchit.pt.x);
1062 expect(r.bottom / 2, mchit.pt.y);
1063 expect(mchit.uHit, res);
1064 expect_hex(MCHT_CALENDARDATE, res);
1065
1066 /* in active area - day of the week #2 */
1067 mchit.pt.x = r.right / 14; /* half of first day rect */
1068 mchit.pt.y = r.bottom / 2;
1069 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1070 expect(r.right / 14, mchit.pt.x);
1071 expect(r.bottom / 2, mchit.pt.y);
1072 expect(mchit.uHit, res);
1073 expect_hex(MCHT_CALENDARDATE, res);
1074
1075 /* in active area - date from prev month */
1076 mchit.pt.x = r.right / 14; /* half of first day rect */
1077 mchit.pt.y = 6 * r.bottom / 19;
1078 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1079 expect(r.right / 14, mchit.pt.x);
1080 expect(6 * r.bottom / 19, mchit.pt.y);
1081 expect(mchit.uHit, res);
1082 expect_hex(MCHT_CALENDARDATEPREV, res);
1083
1084 #if 0
1085 /* (125, 115) is in active area - date from this month */
1086 mchit.pt.x = 125;
1087 mchit.pt.y = 115;
1088 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1089 expect(125, mchit.pt.x);
1090 expect(115, mchit.pt.y);
1091 expect(mchit.uHit, res);
1092 expect(MCHT_CALENDARDATE, res);
1093 #endif
1094
1095 /* in active area - date from next month */
1096 mchit.pt.x = 11 * r.right / 14;
1097 mchit.pt.y = 16 * r.bottom / 19;
1098 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1099 expect(11 * r.right / 14, mchit.pt.x);
1100 expect(16 * r.bottom / 19, mchit.pt.y);
1101 expect(mchit.uHit, res);
1102 expect_hex(MCHT_CALENDARDATENEXT, res);
1103
1104 /* in active area - today link */
1105 mchit.pt.x = r.right / 14;
1106 mchit.pt.y = 18 * r.bottom / 19;
1107 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1108 expect(r.right / 14, mchit.pt.x);
1109 expect(18 * r.bottom / 19, mchit.pt.y);
1110 expect(mchit.uHit, res);
1111 expect_hex(MCHT_TODAYLINK, res);
1112
1113 /* in active area - today link */
1114 mchit.pt.x = r.right / 2;
1115 mchit.pt.y = 18 * r.bottom / 19;
1116 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1117 expect(r.right / 2, mchit.pt.x);
1118 expect(18 * r.bottom / 19, mchit.pt.y);
1119 expect(mchit.uHit, res);
1120 expect_hex(MCHT_TODAYLINK, res);
1121
1122 /* in active area - today link */
1123 mchit.pt.x = r.right / 10;
1124 mchit.pt.y = 18 * r.bottom / 19;
1125 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1126 expect(r.right / 10, mchit.pt.x);
1127 expect(18 * r.bottom / 19, mchit.pt.y);
1128 expect(mchit.uHit, res);
1129 expect_hex(MCHT_TODAYLINK, res);
1130
1131 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_hit_test_seq, "monthcal hit test", TRUE);
1132
1133 /* The horizontal position of title bar elements depends on locale (y pos
1134 is constant), so we sample across a horizontal line and make sure we
1135 find all elements. */
1136
1137 /* Get the format of the title */
1138 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SYEARMONTH, yearmonth, 80);
1139 /* Find out if we have a month and/or year */
1140 locale_year = strstr(yearmonth, "y");
1141 locale_month = strstr(yearmonth, "M");
1142
1143 mchit.pt.x = 0;
1144 mchit.pt.y = (5/2) * r.bottom / 19;
1145 title_index = 0;
1146 old_res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1147 expect_hex(title_hits[title_index].ht, old_res);
1148
1149 in_the_middle = FALSE;
1150 month_count = year_count = 0;
1151 for (x = 0; x < r.right; x++){
1152 mchit.pt.x = x;
1153 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1154 expect(x, mchit.pt.x);
1155 expect((5/2) * r.bottom / 19, mchit.pt.y);
1156 expect(mchit.uHit, res);
1157 if (res != old_res) {
1158
1159 if (old_res == MCHT_TITLEBTNPREV)
1160 in_the_middle = TRUE;
1161
1162 if (res == MCHT_TITLEBTNNEXT)
1163 in_the_middle = FALSE;
1164
1165 if (in_the_middle) {
1166 if (res == MCHT_TITLEMONTH)
1167 month_count++;
1168 else if (res == MCHT_TITLEYEAR)
1169 year_count++;
1170 } else {
1171 title_index++;
1172
1173 if (sizeof(title_hits) / sizeof(title_hits[0]) <= title_index)
1174 break;
1175
1176 if (title_hits[title_index].todo) {
1177 todo_wine
1178 ok(title_hits[title_index].ht == res, "Expected %x, got %x, pos %d\n",
1179 title_hits[title_index].ht, res, x);
1180 } else {
1181 ok(title_hits[title_index].ht == res, "Expected %x, got %x, pos %d\n",
1182 title_hits[title_index].ht, res, x);
1183 }
1184 }
1185 old_res = res;
1186 }
1187 }
1188
1189 /* There are some limits, even if LOCALE_SYEARMONTH contains rubbish
1190 * or no month/year indicators at all */
1191 if (locale_month)
1192 todo_wine ok(month_count == 1, "Expected 1 month item, got %d\n", month_count);
1193 else
1194 ok(month_count <= 1, "Too many month items: %d\n", month_count);
1195
1196 if (locale_year)
1197 todo_wine ok(year_count == 1, "Expected 1 year item, got %d\n", year_count);
1198 else
1199 ok(year_count <= 1, "Too many year items: %d\n", year_count);
1200
1201 todo_wine ok(month_count + year_count >= 1, "Not enough month and year items\n");
1202
1203 ok(r.right <= x && title_index + 1 == sizeof(title_hits) / sizeof(title_hits[0]),
1204 "Wrong title layout\n");
1205
1206 DestroyWindow(hwnd);
1207 }
1208
1209 static void test_todaylink(void)
1210 {
1211 MCHITTESTINFO mchit;
1212 SYSTEMTIME st_test, st_new;
1213 UINT res;
1214 HWND hwnd;
1215 RECT r;
1216
1217 memset(&mchit, 0, sizeof(MCHITTESTINFO));
1218
1219 hwnd = create_monthcal_control(0);
1220
1221 res = SendMessage(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r);
1222 expect(1, res);
1223 MoveWindow(hwnd, 0, 0, r.right, r.bottom, FALSE);
1224
1225 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1226
1227 /* hit active area - today link */
1228 mchit.cbSize = MCHITTESTINFO_V1_SIZE;
1229 mchit.pt.x = r.right / 14;
1230 mchit.pt.y = 18 * r.bottom / 19;
1231 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1232 expect(r.right / 14, mchit.pt.x);
1233 expect(18 * r.bottom / 19, mchit.pt.y);
1234 expect(mchit.uHit, res);
1235 expect(MCHT_TODAYLINK, res);
1236
1237 st_test.wDay = 1;
1238 st_test.wMonth = 1;
1239 st_test.wYear = 2005;
1240
1241 res = SendMessage(hwnd, MCM_SETTODAY, 0, (LPARAM)&st_test);
1242 expect(0, res);
1243
1244 memset(&st_new, 0, sizeof(st_new));
1245 res = SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&st_new);
1246 expect(1, res);
1247 expect(1, st_new.wDay);
1248 expect(1, st_new.wMonth);
1249 expect(2005, st_new.wYear);
1250
1251 res = SendMessage(hwnd, WM_LBUTTONDOWN, MK_LBUTTON, MAKELONG(mchit.pt.x, mchit.pt.y));
1252 expect(0, res);
1253
1254 memset(&st_new, 0, sizeof(st_new));
1255 res = SendMessage(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_new);
1256 expect(1, res);
1257 expect(1, st_new.wDay);
1258 expect(1, st_new.wMonth);
1259 expect(2005, st_new.wYear);
1260
1261 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_todaylink_seq, "monthcal hit test", TRUE);
1262
1263 DestroyWindow(hwnd);
1264 }
1265
1266 static void test_today(void)
1267 {
1268 SYSTEMTIME st_test, st_new;
1269 int res;
1270 HWND hwnd;
1271
1272 hwnd = create_monthcal_control(0);
1273
1274 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1275
1276 /* Setter and Getters for "today" information */
1277
1278 /* check for overflow, should be ok */
1279 memset(&st_test, 0, sizeof(st_test));
1280 st_test.wDay = 38;
1281 st_test.wMonth = 38;
1282
1283 st_new.wDay = 27;
1284 st_new.wMonth = 27;
1285
1286 res = SendMessage(hwnd, MCM_SETTODAY, 0, (LPARAM)&st_test);
1287 expect(0, res);
1288
1289 res = SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&st_new);
1290 expect(1, res);
1291
1292 /* st_test should not change */
1293 expect(38, st_test.wDay);
1294 expect(38, st_test.wMonth);
1295
1296 /* st_new should change, overflow does not matter */
1297 expect(38, st_new.wDay);
1298 expect(38, st_new.wMonth);
1299
1300 /* check for zero, should be ok*/
1301 st_test.wDay = 0;
1302 st_test.wMonth = 0;
1303
1304 res = SendMessage(hwnd, MCM_SETTODAY, 0, (LPARAM)&st_test);
1305 expect(0, res);
1306
1307 res = SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&st_new);
1308 expect(1, res);
1309
1310 /* st_test should not change */
1311 expect(0, st_test.wDay);
1312 expect(0, st_test.wMonth);
1313
1314 /* st_new should change to zero*/
1315 expect(0, st_new.wDay);
1316 expect(0, st_new.wMonth);
1317
1318 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_today_seq, "monthcal today", TRUE);
1319
1320 DestroyWindow(hwnd);
1321 }
1322
1323 static void test_scroll(void)
1324 {
1325 int res;
1326 HWND hwnd;
1327
1328 hwnd = create_monthcal_control(0);
1329
1330 res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
1331 expect(2, res);
1332
1333 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1334
1335 /* Setter and Getters for scroll rate */
1336 res = SendMessage(hwnd, MCM_SETMONTHDELTA, 2, 0);
1337 expect(0, res);
1338
1339 res = SendMessage(hwnd, MCM_SETMONTHDELTA, 3, 0);
1340 expect(2, res);
1341 res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
1342 expect(3, res);
1343
1344 res = SendMessage(hwnd, MCM_SETMONTHDELTA, 12, 0);
1345 expect(3, res);
1346 res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
1347 expect(12, res);
1348
1349 res = SendMessage(hwnd, MCM_SETMONTHDELTA, 15, 0);
1350 expect(12, res);
1351 res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
1352 expect(15, res);
1353
1354 res = SendMessage(hwnd, MCM_SETMONTHDELTA, -5, 0);
1355 expect(15, res);
1356 res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
1357 expect(-5, res);
1358
1359 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_scroll_seq, "monthcal scroll", FALSE);
1360
1361 DestroyWindow(hwnd);
1362 }
1363
1364 static void test_monthrange(void)
1365 {
1366 int res;
1367 SYSTEMTIME st_visible[2], st_daystate[2], st;
1368 HWND hwnd;
1369 RECT r;
1370
1371 hwnd = create_monthcal_control(0);
1372
1373 memset(&st_visible, 0, sizeof(st_visible));
1374 memset(&st_daystate, 0, sizeof(st_daystate));
1375
1376 st.wYear = 2000;
1377 st.wMonth = 11;
1378 st.wDay = 28;
1379 st.wHour = 11;
1380 st.wMinute = 59;
1381 st.wSecond = 30;
1382 st.wMilliseconds = 0;
1383 st.wDayOfWeek = 0;
1384
1385 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st);
1386 expect(1,res);
1387
1388 /* to be locale independent */
1389 SendMessage(hwnd, MCM_SETFIRSTDAYOFWEEK, 0, (LPARAM)6);
1390
1391 res = SendMessage(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r);
1392 expect(TRUE, res);
1393 /* resize control to display two Calendars */
1394 MoveWindow(hwnd, 0, 0, r.right, (5/2)*r.bottom, FALSE);
1395
1396 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1397
1398 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st_visible);
1399 expect(2, res);
1400 expect(2000, st_visible[0].wYear);
1401 expect(11, st_visible[0].wMonth);
1402 expect(1, st_visible[0].wDay);
1403 expect(2000, st_visible[1].wYear);
1404 expect(12, st_visible[1].wMonth);
1405 expect(31, st_visible[1].wDay);
1406
1407 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_DAYSTATE, (LPARAM)st_daystate);
1408 expect(4, res);
1409 expect(2000, st_daystate[0].wYear);
1410 expect(10, st_daystate[0].wMonth);
1411 expect(29, st_daystate[0].wDay);
1412 expect(2001, st_daystate[1].wYear);
1413 expect(1, st_daystate[1].wMonth);
1414 expect(6, st_daystate[1].wDay);
1415
1416 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_monthrange_seq, "monthcal monthrange", FALSE);
1417
1418 /* with null date array parameter */
1419 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, 0);
1420 expect(2, res);
1421
1422 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_DAYSTATE, 0);
1423 expect(4, res);
1424
1425 /* resize control to display single Calendar */
1426 MoveWindow(hwnd, 0, 0, r.right, r.bottom, FALSE);
1427
1428 memset(&st, 0, sizeof(st));
1429 st.wMonth = 9;
1430 st.wYear = 1752;
1431 st.wDay = 14;
1432
1433 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st);
1434 expect(1, res);
1435
1436 /* September 1752 has 19 days */
1437 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st_visible);
1438 expect(1, res);
1439
1440 expect(1752, st_visible[0].wYear);
1441 expect(9, st_visible[0].wMonth);
1442 ok(14 == st_visible[0].wDay ||
1443 broken(1 == st_visible[0].wDay), /* comctl32 <= 4.72 */
1444 "Expected 14, got %d\n", st_visible[0].wDay);
1445
1446 expect(1752, st_visible[1].wYear);
1447 expect(9, st_visible[1].wMonth);
1448 expect(19, st_visible[1].wDay);
1449
1450 DestroyWindow(hwnd);
1451 }
1452
1453 static void test_maxselday(void)
1454 {
1455 int res;
1456 HWND hwnd;
1457 DWORD style;
1458
1459 hwnd = create_monthcal_control(0);
1460 /* if no style specified default to 1 */
1461 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1462 expect(1, res);
1463 res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, 5, 0);
1464 expect(0, res);
1465 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1466 expect(1, res);
1467
1468 /* try to set style */
1469 style = GetWindowLong(hwnd, GWL_STYLE);
1470 SetWindowLong(hwnd, GWL_STYLE, style | MCS_MULTISELECT);
1471 style = GetWindowLong(hwnd, GWL_STYLE);
1472 ok(!(style & MCS_MULTISELECT), "Expected MCS_MULTISELECT not to be set\n");
1473 DestroyWindow(hwnd);
1474
1475 hwnd = create_monthcal_control(MCS_MULTISELECT);
1476 /* try to remove style */
1477 style = GetWindowLong(hwnd, GWL_STYLE);
1478 SetWindowLong(hwnd, GWL_STYLE, style & ~MCS_MULTISELECT);
1479 style = GetWindowLong(hwnd, GWL_STYLE);
1480 ok(style & MCS_MULTISELECT, "Expected MCS_MULTISELECT to be set\n");
1481 DestroyWindow(hwnd);
1482
1483 hwnd = create_monthcal_control(MCS_MULTISELECT);
1484
1485 /* default width is a week */
1486 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1487 expect(7, res);
1488
1489 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1490
1491 /* Setter and Getters for max selected days */
1492 res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, 5, 0);
1493 expect(1, res);
1494 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1495 expect(5, res);
1496
1497 res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, 15, 0);
1498 expect(1, res);
1499 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1500 expect(15, res);
1501
1502 /* test invalid value */
1503 res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, -1, 0);
1504 expect(0, res);
1505 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1506 expect(15, res);
1507
1508 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_max_sel_day_seq, "monthcal MaxSelDay", FALSE);
1509
1510 /* zero value is invalid too */
1511 res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, 0, 0);
1512 expect(0, res);
1513 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1514 expect(15, res);
1515
1516 DestroyWindow(hwnd);
1517 }
1518
1519 static void test_size(void)
1520 {
1521 int res;
1522 RECT r1, r2;
1523 HFONT hFont1, hFont2;
1524 LOGFONTA logfont;
1525 HWND hwnd;
1526
1527 hwnd = create_monthcal_control(0);
1528
1529 lstrcpyA(logfont.lfFaceName, "Arial");
1530 memset(&logfont, 0, sizeof(logfont));
1531 logfont.lfHeight = 12;
1532 hFont1 = CreateFontIndirectA(&logfont);
1533
1534 logfont.lfHeight = 24;
1535 hFont2 = CreateFontIndirectA(&logfont);
1536
1537 /* initialize to a font we can compare against */
1538 SendMessage(hwnd, WM_SETFONT, (WPARAM)hFont1, 0);
1539 res = SendMessage(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r1);
1540 ok(res, "SendMessage(MCM_GETMINREQRECT) failed\n");
1541
1542 /* check that setting a larger font results in an larger rect */
1543 SendMessage(hwnd, WM_SETFONT, (WPARAM)hFont2, 0);
1544 res = SendMessage(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r2);
1545 ok(res, "SendMessage(MCM_GETMINREQRECT) failed\n");
1546
1547 OffsetRect(&r1, -r1.left, -r1.top);
1548 OffsetRect(&r2, -r2.left, -r2.top);
1549
1550 ok(r1.bottom < r2.bottom, "Failed to get larger rect with larger font\n");
1551
1552 DestroyWindow(hwnd);
1553 }
1554
1555 static void test_create(void)
1556 {
1557 HWND hwnd;
1558
1559 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1560
1561 hwnd = create_monthcal_control(0);
1562 ok_sequence(sequences, PARENT_SEQ_INDEX, create_monthcal_control_seq, "create monthcal control", TRUE);
1563
1564 DestroyWindow(hwnd);
1565
1566 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1567 hwnd = create_monthcal_control(MCS_MULTISELECT);
1568 ok_sequence(sequences, PARENT_SEQ_INDEX, create_monthcal_multi_sel_style_seq, "create monthcal (multi sel style)", TRUE);
1569 DestroyWindow(hwnd);
1570 }
1571
1572 static void test_destroy(void)
1573 {
1574 HWND hwnd;
1575
1576 hwnd = create_monthcal_control(0);
1577 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1578 DestroyWindow(hwnd);
1579 ok_sequence(sequences, PARENT_SEQ_INDEX, destroy_monthcal_parent_msgs_seq, "Destroy monthcal (parent msg)", FALSE);
1580 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, destroy_monthcal_child_msgs_seq, "Destroy monthcal (child msg)", FALSE);
1581
1582 /* MCS_MULTISELECT */
1583 hwnd = create_monthcal_control(MCS_MULTISELECT);
1584 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1585 DestroyWindow(hwnd);
1586 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, destroy_monthcal_multi_sel_style_seq, "Destroy monthcal (multi sel style)", FALSE);
1587 }
1588
1589 static void test_selrange(void)
1590 {
1591 HWND hwnd;
1592 SYSTEMTIME st, range[2], range2[2];
1593 BOOL ret, old_comctl32 = FALSE;
1594
1595 hwnd = create_monthcal_control(MCS_MULTISELECT);
1596
1597 /* just after creation selection should start and end today */
1598 ret = SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&st);
1599 expect(TRUE, ret);
1600
1601 memset(range, 0xcc, sizeof(range));
1602 ret = SendMessage(hwnd, MCM_GETSELRANGE, 0, (LPARAM)range);
1603 expect(TRUE, ret);
1604 expect(st.wYear, range[0].wYear);
1605 expect(st.wMonth, range[0].wMonth);
1606 expect(st.wDay, range[0].wDay);
1607 if (range[0].wDayOfWeek != st.wDayOfWeek)
1608 {
1609 win_skip("comctl32 <= 4.70 doesn't set some values\n");
1610 old_comctl32 = TRUE;
1611 }
1612 else
1613 {
1614 expect(st.wDayOfWeek, range[0].wDayOfWeek);
1615 expect(st.wHour, range[0].wHour);
1616 expect(st.wMinute, range[0].wMinute);
1617 expect(st.wSecond, range[0].wSecond);
1618 expect(st.wMilliseconds, range[0].wMilliseconds);
1619 }
1620
1621 expect(st.wYear, range[1].wYear);
1622 expect(st.wMonth, range[1].wMonth);
1623 expect(st.wDay, range[1].wDay);
1624 if (!old_comctl32)
1625 {
1626 expect(st.wDayOfWeek, range[1].wDayOfWeek);
1627 expect(st.wHour, range[1].wHour);
1628 expect(st.wMinute, range[1].wMinute);
1629 expect(st.wSecond, range[1].wSecond);
1630 expect(st.wMilliseconds, range[1].wMilliseconds);
1631 }
1632
1633 /* bounds are swapped if min > max */
1634 memset(&range[0], 0, sizeof(range[0]));
1635 range[0].wYear = 2009;
1636 range[0].wMonth = 10;
1637 range[0].wDay = 5;
1638 range[1] = range[0];
1639 range[1].wDay = 3;
1640
1641 ret = SendMessage(hwnd, MCM_SETSELRANGE, 0, (LPARAM)range);
1642 expect(TRUE, ret);
1643
1644 ret = SendMessage(hwnd, MCM_GETSELRANGE, 0, (LPARAM)range2);
1645 expect(TRUE, ret);
1646
1647 expect(range[1].wYear, range2[0].wYear);
1648 expect(range[1].wMonth, range2[0].wMonth);
1649 expect(range[1].wDay, range2[0].wDay);
1650 expect(6, range2[0].wDayOfWeek);
1651 expect(range[1].wHour, range2[0].wHour);
1652 expect(range[1].wMinute, range2[0].wMinute);
1653 expect(range[1].wSecond, range2[0].wSecond);
1654 expect(range[1].wMilliseconds, range2[0].wMilliseconds);
1655
1656 expect(range[0].wYear, range2[1].wYear);
1657 expect(range[0].wMonth, range2[1].wMonth);
1658 expect(range[0].wDay, range2[1].wDay);
1659 expect(1, range2[1].wDayOfWeek);
1660 expect(range[0].wHour, range2[1].wHour);
1661 expect(range[0].wMinute, range2[1].wMinute);
1662 expect(range[0].wSecond, range2[1].wSecond);
1663 expect(range[0].wMilliseconds, range2[1].wMilliseconds);
1664
1665 /* try with range larger than maximum configured */
1666 memset(&range[0], 0, sizeof(range[0]));
1667 range[0].wYear = 2009;
1668 range[0].wMonth = 10;
1669 range[0].wDay = 1;
1670 range[1] = range[0];
1671
1672 ret = SendMessage(hwnd, MCM_SETSELRANGE, 0, (LPARAM)range);
1673 expect(TRUE, ret);
1674
1675 range[1] = range[0];
1676 /* default max. range is 7 days */
1677 range[1].wDay = 8;
1678
1679 ret = SendMessage(hwnd, MCM_SETSELRANGE, 0, (LPARAM)range);
1680 expect(FALSE, ret);
1681
1682 ret = SendMessage(hwnd, MCM_GETSELRANGE, 0, (LPARAM)range2);
1683 expect(TRUE, ret);
1684
1685 expect(range[0].wYear, range2[0].wYear);
1686 expect(range[0].wMonth, range2[0].wMonth);
1687 expect(range[0].wDay, range2[0].wDay);
1688 expect(range[0].wYear, range2[1].wYear);
1689 expect(range[0].wMonth, range2[1].wMonth);
1690 expect(range[0].wDay, range2[1].wDay);
1691
1692 DestroyWindow(hwnd);
1693 }
1694
1695 static void test_killfocus(void)
1696 {
1697 HWND hwnd;
1698 DWORD style;
1699
1700 hwnd = create_monthcal_control(0);
1701
1702 /* make parent invisible */
1703 style = GetWindowLong(parent_wnd, GWL_STYLE);
1704 SetWindowLong(parent_wnd, GWL_STYLE, style &~ WS_VISIBLE);
1705
1706 SendMessage(hwnd, WM_KILLFOCUS, (WPARAM)GetDesktopWindow(), 0);
1707
1708 style = GetWindowLong(hwnd, GWL_STYLE);
1709 ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
1710
1711 style = GetWindowLong(parent_wnd, GWL_STYLE);
1712 SetWindowLong(parent_wnd, GWL_STYLE, style | WS_VISIBLE);
1713
1714 DestroyWindow(hwnd);
1715 }
1716
1717 static void test_hittest_v6(void)
1718 {
1719 MCHITTESTINFO mchit;
1720 DWORD ret;
1721 HWND hwnd;
1722 RECT r;
1723
1724 hwnd = create_monthcal_control(0);
1725 SendMessage(hwnd, MCM_SETCALENDARBORDER, TRUE, 0);
1726
1727 SendMessage(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r);
1728 /* reserving some area around calendar */
1729 MoveWindow(hwnd, 0, 0, r.right * 3 / 2, r.bottom * 3 / 2, FALSE);
1730 mchit.cbSize = sizeof(MCHITTESTINFO);
1731 mchit.pt.x = mchit.pt.y = 0;
1732 mchit.iOffset = -1;
1733 mchit.iRow = -1;
1734 mchit.iCol = -1;
1735 ret = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1736 if (ret == ~0u)
1737 {
1738 win_skip("Only MCHITTESTINFO_V1 supported\n");
1739 DestroyWindow(hwnd);
1740 return;
1741 }
1742 todo_wine expect_hex(MCHT_NOWHERE, ret);
1743 expect(-1, mchit.iOffset);
1744 expect(-1, mchit.iRow);
1745 expect(-1, mchit.iCol);
1746
1747 MoveWindow(hwnd, 0, 0, r.right, r.bottom, FALSE);
1748 mchit.pt.x = r.right / 2;
1749 mchit.pt.y = r.bottom / 2;
1750 mchit.iOffset = -1;
1751 ret = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1752 expect_hex(MCHT_CALENDARDATE, ret);
1753 expect(0, mchit.iOffset);
1754
1755 /* over day area */
1756 mchit.pt.x = r.right / (7*2);
1757 mchit.pt.y = r.bottom / 2;
1758 mchit.iOffset = -1;
1759 mchit.iCol = mchit.iRow = -1;
1760 mchit.uHit = 0;
1761 mchit.rc.left = mchit.rc.right = mchit.rc.top = mchit.rc.bottom = -1;
1762 ret = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1763 expect_hex(MCHT_CALENDARDATE, ret);
1764 expect_hex(MCHT_CALENDARDATE, mchit.uHit);
1765 expect(0, mchit.iOffset);
1766 expect(2, mchit.iRow);
1767 expect(0, mchit.iCol);
1768 /* returned a one day rectangle */
1769 expect_d(r.right / 7, mchit.rc.right - mchit.rc.left);
1770 expect_d(r.bottom / 10, mchit.rc.bottom - mchit.rc.top);
1771
1772 /* title */
1773 mchit.pt.x = 1;
1774 mchit.pt.y = 1;
1775 mchit.iOffset = -1;
1776 mchit.iCol = mchit.iRow = -1;
1777 mchit.uHit = 0;
1778 mchit.rc.left = mchit.rc.right = mchit.rc.top = mchit.rc.bottom = -1;
1779 ret = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1780 expect_hex(MCHT_TITLE, ret);
1781 expect_hex(MCHT_TITLE, mchit.uHit);
1782 expect(0, mchit.iOffset);
1783 expect(-1, mchit.iRow);
1784 expect(-1, mchit.iCol);
1785 expect(0, mchit.rc.left);
1786 expect(0, mchit.rc.top);
1787 expect_d(r.right, mchit.rc.right);
1788 ok(mchit.rc.bottom > 0, "got %d\n", mchit.rc.bottom);
1789
1790 /* between two calendars */
1791 MoveWindow(hwnd, 0, 0, r.right * 5/2, r.bottom, FALSE);
1792 mchit.pt.x = r.right / (5*4);
1793 mchit.pt.y = r.bottom / 2;
1794 mchit.iOffset = -2;
1795 mchit.iCol = mchit.iRow = -2;
1796 mchit.uHit = ~0;
1797 mchit.rc.left = mchit.rc.right = mchit.rc.top = mchit.rc.bottom = -1;
1798 ret = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1799 todo_wine expect_hex(MCHT_NOWHERE, ret);
1800 todo_wine expect_hex(MCHT_NOWHERE, mchit.uHit);
1801 expect(-2, mchit.iOffset);
1802 expect(-2, mchit.iRow);
1803 expect(-2, mchit.iCol);
1804 todo_wine expect(0, mchit.rc.left);
1805 todo_wine expect(0, mchit.rc.top);
1806 todo_wine expect_d(r.right * 5/2, mchit.rc.right);
1807 todo_wine expect_d(r.bottom, mchit.rc.bottom);
1808
1809 DestroyWindow(hwnd);
1810 }
1811
1812 static void test_get_set_border(void)
1813 {
1814 HWND hwnd;
1815 DWORD ret;
1816
1817 hwnd = create_monthcal_control(0);
1818
1819 /* a non-default value */
1820 ret = SendMessage(hwnd, MCM_SETCALENDARBORDER, TRUE, 10);
1821 expect(0, ret);
1822
1823 ret = SendMessage(hwnd, MCM_GETCALENDARBORDER, 0, 0);
1824
1825 if (ret != 10)
1826 {
1827 skip("MCM_GET/SETCALENDARBORDER not supported\n");
1828 DestroyWindow(hwnd);
1829 return;
1830 }
1831
1832 expect(10, ret);
1833
1834 DestroyWindow(hwnd);
1835 }
1836
1837 static void test_MCM_SIZERECTTOMIN(void)
1838 {
1839 HWND hwnd;
1840 DWORD ret;
1841 RECT r, r2;
1842
1843 hwnd = create_monthcal_control(0);
1844
1845 ret = SendMessageA(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r2);
1846 if (ret == 0)
1847 {
1848 win_skip("Message MCM_GETMINREQRECT unsupported. Skipping.\n");
1849 DestroyWindow(hwnd);
1850 return;
1851 }
1852
1853 ret = SendMessageA(hwnd, MCM_SIZERECTTOMIN, 0, 0);
1854 ok(ret == 0, "got %d\n", ret);
1855
1856 r.left = r.right = r.top = r.bottom = 0;
1857 ret = SendMessageA(hwnd, MCM_SIZERECTTOMIN, 0, (LPARAM)&r);
1858 if (ret == 0)
1859 {
1860 skip("Message MCM_SIZERECTTOMIN unsupported. Skipping.\n");
1861 DestroyWindow(hwnd);
1862 return;
1863 }
1864 ok(ret == 1, "got %d\n", ret);
1865 ok(r.left == 0 && r.right > 0, "got %d, %d\n", r.left, r.right);
1866
1867 r = r2;
1868 ret = SendMessageA(hwnd, MCM_SIZERECTTOMIN, 0, (LPARAM)&r);
1869 ok(ret == 1, "got %d\n", ret);
1870
1871 r2.right = (r2.right - r2.left) * 3;
1872 r2.bottom = (r2.bottom - r2.top) * 3;
1873 r2.left = r2.top = 0;
1874 ret = SendMessageA(hwnd, MCM_SIZERECTTOMIN, 0, (LPARAM)&r2);
1875 ok(ret == 1, "got %d\n", ret);
1876
1877 DestroyWindow(hwnd);
1878 }
1879
1880 static void test_MCM_GETCALENDARCOUNT(void)
1881 {
1882 HWND hwnd;
1883 DWORD ret;
1884
1885 hwnd = create_monthcal_control(0);
1886
1887 ret = SendMessageA(hwnd, MCM_GETCALENDARCOUNT, 0, 0);
1888 if (ret == 0)
1889 {
1890 win_skip("Message MCM_GETCALENDARCOUNT unsupported. Skipping.\n");
1891 DestroyWindow(hwnd);
1892 return;
1893 }
1894
1895 expect(2, ret);
1896
1897 DestroyWindow(hwnd);
1898 }
1899
1900 static void test_daystate(void)
1901 {
1902 MONTHDAYSTATE state[4];
1903 DWORD ret, style;
1904 HWND hwnd;
1905 RECT r;
1906
1907 /* without MCS_DAYSTATE */
1908 hwnd = create_monthcal_control(0);
1909
1910 ret = SendMessage(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r);
1911 expect(TRUE, ret);
1912
1913 /* resize control to display two Calendars */
1914 MoveWindow(hwnd, 0, 0, r.right, (5/2)*r.bottom, FALSE);
1915
1916 ret = SendMessageA(hwnd, MCM_GETMONTHRANGE, GMR_DAYSTATE, 0);
1917 expect(4, ret);
1918
1919 ret = SendMessageA(hwnd, MCM_SETDAYSTATE, 4, (LPARAM)&state);
1920 expect(0, ret);
1921
1922 ret = SendMessageA(hwnd, MCM_SETDAYSTATE, 2, (LPARAM)&state);
1923 expect(0, ret);
1924
1925 ret = SendMessageA(hwnd, MCM_SETDAYSTATE, 0, 0);
1926 expect(0, ret);
1927
1928 /* try to switch on */
1929 SetWindowLongA(hwnd, GWL_STYLE, GetWindowLongA(hwnd, GWL_STYLE) | MCS_DAYSTATE);
1930 style = GetWindowLongA(hwnd, GWL_STYLE);
1931 ok((style & MCS_DAYSTATE) == 0, "got 0x%08x\n", style);
1932
1933 DestroyWindow(hwnd);
1934
1935 /* with MCS_DAYSTATE */
1936 hwnd = create_monthcal_control(MCS_DAYSTATE);
1937
1938 ret = SendMessageA(hwnd, MCM_GETMONTHRANGE, GMR_DAYSTATE, 0);
1939 expect(4, ret);
1940
1941 ret = SendMessageA(hwnd, MCM_SETDAYSTATE, 4, (LPARAM)&state);
1942 expect(1, ret);
1943
1944 ret = SendMessageA(hwnd, MCM_SETDAYSTATE, 2, (LPARAM)&state);
1945 expect(0, ret);
1946
1947 ret = SendMessageA(hwnd, MCM_SETDAYSTATE, 0, 0);
1948 expect(0, ret);
1949
1950 /* try to switch off */
1951 SetWindowLongA(hwnd, GWL_STYLE, GetWindowLongA(hwnd, GWL_STYLE) & ~MCS_DAYSTATE);
1952 style = GetWindowLongA(hwnd, GWL_STYLE);
1953 ok((style & MCS_DAYSTATE) == MCS_DAYSTATE, "got 0x%08x\n", style);
1954
1955 DestroyWindow(hwnd);
1956 }
1957
1958 static void test_sel_notify(void)
1959 {
1960 typedef struct
1961 {
1962 DWORD val;
1963 const char* name;
1964 } Monthcal_style;
1965
1966 HWND hwnd;
1967 RECT rc;
1968 MCHITTESTINFO mchit = {sizeof(MCHITTESTINFO)};
1969 SYSTEMTIME st;
1970 Monthcal_style styles[] = {
1971 {MCS_NOTODAY, "MCS_NOTODAY"},
1972 {MCS_NOTODAY | MCS_MULTISELECT, "MCS_NOTODAY | MCS_MULTISELECT"},
1973 {MCS_DAYSTATE, "MCS_DAYSTATE"},
1974 {MCS_DAYSTATE | MCS_MULTISELECT, "MCS_DAYSTATE | MCS_MULTISELECT"}
1975 };
1976 int i;
1977
1978 for(i = 0; i < sizeof styles / sizeof styles[0]; i++)
1979 {
1980 hwnd = create_monthcal_control(styles[i].val);
1981 SetWindowLongPtr(hwnd, GWLP_ID, SEL_NOTIFY_TEST_ID);
1982 assert(hwnd);
1983 SendMessage(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&rc);
1984 MoveWindow(hwnd, 0, 0, rc.right, rc.bottom, FALSE);
1985 /* Simulate mouse click on some unselected day to generate
1986 MCN_SELECT and MCN_SELCHANGE notifications */
1987 mchit.pt.x = rc.right / 2;
1988 mchit.pt.y = rc.bottom / 2;
1989 SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1990 SendMessage(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st);
1991 while(st.wDay == mchit.st.wDay) /* Ensure that mchit.pt points to unselected day */
1992 {
1993 mchit.pt.y++;
1994 SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1995 }
1996 SendMessage(hwnd, WM_LBUTTONDOWN, 0, MAKELPARAM(mchit.pt.x, mchit.pt.y));
1997 SendMessage(hwnd, WM_LBUTTONUP, 0, MAKELPARAM(mchit.pt.x, mchit.pt.y));
1998 DestroyWindow(hwnd);
1999 }
2000 }
2001
2002 START_TEST(monthcal)
2003 {
2004 BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
2005 INITCOMMONCONTROLSEX iccex;
2006 HMODULE hComctl32;
2007 HWND hwnd;
2008
2009 ULONG_PTR ctx_cookie;
2010 HANDLE hCtx;
2011
2012 hComctl32 = GetModuleHandleA("comctl32.dll");
2013 pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
2014 if (!pInitCommonControlsEx)
2015 {
2016 skip("InitCommonControlsEx() is missing. Skipping the tests\n");
2017 return;
2018 }
2019 iccex.dwSize = sizeof(iccex);
2020 iccex.dwICC = ICC_DATE_CLASSES;
2021 pInitCommonControlsEx(&iccex);
2022
2023 test_monthcal();
2024
2025 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
2026
2027 parent_wnd = create_parent_window();
2028
2029 test_create();
2030 test_destroy();
2031 test_color();
2032 test_currdate();
2033 test_firstDay();
2034 test_unicode();
2035 test_today();
2036 test_scroll();
2037 test_monthrange();
2038 test_hittest();
2039 test_todaylink();
2040 test_size();
2041 test_maxselday();
2042 test_selrange();
2043 test_killfocus();
2044 test_daystate();
2045 test_sel_notify();
2046
2047 if (!load_v6_module(&ctx_cookie, &hCtx))
2048 {
2049 DestroyWindow(parent_wnd);
2050 return;
2051 }
2052
2053 /* this is a XP SP3 failure workaround */
2054 hwnd = CreateWindowExA(0, MONTHCAL_CLASSA, "foo",
2055 WS_CHILD | WS_BORDER | WS_VISIBLE,
2056 0, 0, 100, 100,
2057 parent_wnd, NULL, GetModuleHandleA(NULL), NULL);
2058 if (!IsWindow(hwnd))
2059 {
2060 win_skip("FIXME: failed to create Monthcal window.\n");
2061 unload_v6_module(ctx_cookie, hCtx);
2062 DestroyWindow(parent_wnd);
2063 return;
2064 }
2065 else
2066 DestroyWindow(hwnd);
2067
2068 test_hittest_v6();
2069 test_get_set_border();
2070 test_MCM_SIZERECTTOMIN();
2071 test_MCM_GETCALENDARCOUNT();
2072
2073 unload_v6_module(ctx_cookie, hCtx);
2074
2075 DestroyWindow(parent_wnd);
2076 }