2 * comctl32 month calendar unit tests
4 * Copyright (C) 2006 Vitaliy Margolen
5 * Copyright (C) 2007 Farshad Agah
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 #include "wine/test.h"
35 #define expect(expected, got) ok(expected == got, "Expected %d, got %d\n", expected, got);
36 #define expect_hex(expected, got) ok(expected == got, "Expected %x, got %x\n", expected, got);
38 #define NUM_MSG_SEQUENCES 2
39 #define PARENT_SEQ_INDEX 0
40 #define MONTHCAL_SEQ_INDEX 1
47 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
49 static HWND parent_wnd;
51 static const struct message create_parent_window_seq[] = {
52 { WM_GETMINMAXINFO, sent },
53 { WM_NCCREATE, sent },
54 { WM_NCCALCSIZE, sent|wparam, 0 },
56 { WM_SHOWWINDOW, sent|wparam, 1 },
57 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
58 { WM_QUERYNEWPALETTE, sent|optional },
59 { WM_WINDOWPOSCHANGING, sent|wparam|optional, 0 },
60 { WM_WINDOWPOSCHANGED, sent|optional },
61 { WM_ACTIVATEAPP, sent|wparam, 1 },
62 { WM_NCACTIVATE, sent },
63 { WM_ACTIVATE, sent|wparam, 1 },
64 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
65 { WM_IME_NOTIFY, sent|defwinproc|optional },
66 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
67 /* Win9x adds SWP_NOZORDER below */
68 { WM_WINDOWPOSCHANGED, sent, /*|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ },
69 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
75 static const struct message create_monthcal_control_seq[] = {
76 { WM_NOTIFYFORMAT, sent|lparam, 0, NF_QUERY },
77 { WM_QUERYUISTATE, sent|optional },
79 { WM_PARENTNOTIFY, sent|wparam, WM_CREATE},
83 static const struct message create_monthcal_multi_sel_style_seq[] = {
84 { WM_NOTIFYFORMAT, sent|lparam, 0, NF_QUERY },
85 { WM_QUERYUISTATE, sent|optional },
87 { WM_PARENTNOTIFY, sent },
91 static const struct message monthcal_color_seq[] = {
92 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_BACKGROUND, 0},
93 { MCM_SETCOLOR, sent|wparam|lparam, MCSC_BACKGROUND, RGB(0,0,0)},
94 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_BACKGROUND, 0},
95 { MCM_SETCOLOR, sent|wparam|lparam, MCSC_BACKGROUND, RGB(255,255,255)},
96 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_BACKGROUND, 0},
98 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_MONTHBK, 0},
99 { MCM_SETCOLOR, sent|wparam|lparam, MCSC_MONTHBK, RGB(0,0,0)},
100 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_MONTHBK, 0},
101 { MCM_SETCOLOR, sent|wparam|lparam, MCSC_MONTHBK, RGB(255,255,255)},
102 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_MONTHBK, 0},
104 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TEXT, 0},
105 { MCM_SETCOLOR, sent|wparam|lparam, MCSC_TEXT, RGB(0,0,0)},
106 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TEXT, 0},
107 { MCM_SETCOLOR, sent|wparam|lparam, MCSC_TEXT, RGB(255,255,255)},
108 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TEXT, 0},
110 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TITLEBK, 0},
111 { MCM_SETCOLOR, sent|wparam|lparam, MCSC_TITLEBK, RGB(0,0,0)},
112 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TITLEBK, 0},
113 { MCM_SETCOLOR, sent|wparam|lparam, MCSC_TITLEBK, RGB(255,255,255)},
114 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TITLEBK, 0},
116 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TITLETEXT, 0},
117 { MCM_SETCOLOR, sent|wparam|lparam, MCSC_TITLETEXT, RGB(0,0,0)},
118 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TITLETEXT, 0},
119 { MCM_SETCOLOR, sent|wparam|lparam, MCSC_TITLETEXT, RGB(255,255,255)},
120 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TITLETEXT, 0},
122 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TRAILINGTEXT, 0},
123 { MCM_SETCOLOR, sent|wparam|lparam, MCSC_TRAILINGTEXT, RGB(0,0,0)},
124 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TRAILINGTEXT, 0},
125 { MCM_SETCOLOR, sent|wparam|lparam, MCSC_TRAILINGTEXT, RGB(255,255,255)},
126 { MCM_GETCOLOR, sent|wparam|lparam, MCSC_TRAILINGTEXT, 0},
130 static const struct message monthcal_curr_date_seq[] = {
131 { MCM_SETCURSEL, sent|wparam, 0},
132 { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
133 { MCM_SETCURSEL, sent|wparam, 0},
134 { MCM_SETCURSEL, sent|wparam, 0},
135 { MCM_GETCURSEL, sent|wparam, 0},
136 { MCM_GETCURSEL, sent|wparam|lparam, 0, 0},
140 static const struct message monthcal_first_day_seq[] = {
141 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
143 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -5},
144 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
146 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -4},
147 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
149 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -3},
150 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
152 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -2},
153 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
155 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, -1},
156 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
158 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
159 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
161 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 1},
162 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
164 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 2},
165 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
167 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 3},
168 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
170 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 4},
171 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
173 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 5},
174 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
176 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 6},
177 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
179 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 7},
180 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
182 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 8},
183 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
185 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 9},
186 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
188 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 10},
189 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
191 { MCM_SETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 11},
192 { MCM_GETFIRSTDAYOFWEEK, sent|wparam|lparam, 0, 0},
196 static const struct message monthcal_unicode_seq[] = {
197 { MCM_GETUNICODEFORMAT, sent|wparam|lparam, 0, 0},
198 { MCM_SETUNICODEFORMAT, sent|wparam|lparam, 1, 0},
199 { MCM_GETUNICODEFORMAT, sent|wparam|lparam, 0, 0},
200 { MCM_SETUNICODEFORMAT, sent|wparam|lparam, 0, 0},
201 { MCM_GETUNICODEFORMAT, sent|wparam|lparam, 0, 0},
202 { MCM_SETUNICODEFORMAT, sent|wparam|lparam, 1, 0},
206 static const struct message monthcal_hit_test_seq[] = {
207 { MCM_SETCURSEL, sent|wparam, 0},
208 { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
209 { MCM_HITTEST, sent|wparam, 0},
210 { MCM_HITTEST, sent|wparam, 0},
211 { MCM_HITTEST, sent|wparam, 0},
212 { MCM_HITTEST, sent|wparam, 0},
213 { MCM_HITTEST, sent|wparam, 0},
214 { MCM_HITTEST, sent|wparam, 0},
215 { MCM_HITTEST, sent|wparam, 0},
216 { MCM_HITTEST, sent|wparam, 0},
217 { MCM_HITTEST, sent|wparam, 0},
218 { MCM_HITTEST, sent|wparam, 0},
222 static const struct message monthcal_todaylink_seq[] = {
223 { MCM_HITTEST, sent|wparam, 0},
224 { MCM_SETTODAY, sent|wparam, 0},
225 { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
226 { MCM_GETTODAY, sent|wparam, 0},
227 { WM_LBUTTONDOWN, sent|wparam|lparam, MK_LBUTTON, MAKELONG(70, 370)},
228 { WM_CAPTURECHANGED, sent|wparam|lparam|defwinproc, 0, 0},
229 { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
230 { MCM_GETCURSEL, sent|wparam, 0},
234 static const struct message monthcal_today_seq[] = {
235 { MCM_SETTODAY, sent|wparam, 0},
236 { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
237 { MCM_GETTODAY, sent|wparam, 0},
238 { MCM_SETTODAY, sent|wparam, 0},
239 { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
240 { MCM_GETTODAY, sent|wparam, 0},
244 static const struct message monthcal_scroll_seq[] = {
245 { MCM_SETMONTHDELTA, sent|wparam|lparam, 2, 0},
246 { MCM_SETMONTHDELTA, sent|wparam|lparam, 3, 0},
247 { MCM_GETMONTHDELTA, sent|wparam|lparam, 0, 0},
248 { MCM_SETMONTHDELTA, sent|wparam|lparam, 12, 0},
249 { MCM_GETMONTHDELTA, sent|wparam|lparam, 0, 0},
250 { MCM_SETMONTHDELTA, sent|wparam|lparam, 15, 0},
251 { MCM_GETMONTHDELTA, sent|wparam|lparam, 0, 0},
252 { MCM_SETMONTHDELTA, sent|wparam|lparam, -5, 0},
253 { MCM_GETMONTHDELTA, sent|wparam|lparam, 0, 0},
257 static const struct message monthcal_monthrange_seq[] = {
258 { MCM_GETMONTHRANGE, sent|wparam, GMR_VISIBLE},
259 { MCM_GETMONTHRANGE, sent|wparam, GMR_DAYSTATE},
263 static const struct message monthcal_max_sel_day_seq[] = {
264 { MCM_SETMAXSELCOUNT, sent|wparam|lparam, 5, 0},
265 { MCM_GETMAXSELCOUNT, sent|wparam|lparam, 0, 0},
266 { MCM_SETMAXSELCOUNT, sent|wparam|lparam, 15, 0},
267 { MCM_GETMAXSELCOUNT, sent|wparam|lparam, 0, 0},
268 { MCM_SETMAXSELCOUNT, sent|wparam|lparam, -1, 0},
269 { MCM_GETMAXSELCOUNT, sent|wparam|lparam, 0, 0},
273 /* expected message sequence for parent*/
274 static const struct message destroy_monthcal_parent_msgs_seq[] = {
275 { WM_PARENTNOTIFY, sent|wparam, WM_DESTROY},
279 /* expected message sequence for child*/
280 static const struct message destroy_monthcal_child_msgs_seq[] = {
281 { 0x0090, sent|optional }, /* Vista */
282 { WM_SHOWWINDOW, sent|wparam|lparam, 0, 0},
283 { WM_WINDOWPOSCHANGING, sent|wparam, 0},
284 { WM_WINDOWPOSCHANGED, sent|wparam, 0},
285 { WM_DESTROY, sent|wparam|lparam, 0, 0},
286 { WM_NCDESTROY, sent|wparam|lparam, 0, 0},
290 static const struct message destroy_monthcal_multi_sel_style_seq[] = {
291 { 0x0090, sent|optional }, /* Vista */
292 { WM_SHOWWINDOW, sent|wparam|lparam, 0, 0},
293 { WM_WINDOWPOSCHANGING, sent|wparam, 0},
294 { WM_WINDOWPOSCHANGED, sent|wparam, 0},
295 { WM_DESTROY, sent|wparam|lparam, 0, 0},
296 { WM_NCDESTROY, sent|wparam|lparam, 0, 0},
300 /* expected message sequence for parent window*/
301 static const struct message destroy_parent_seq[] = {
302 { 0x0090, sent|optional }, /* Vista */
303 { WM_WINDOWPOSCHANGING, sent|wparam, 0},
304 { WM_WINDOWPOSCHANGED, sent|wparam, 0},
305 { WM_IME_SETCONTEXT, sent|wparam|optional, 0},
306 { WM_IME_NOTIFY, sent|wparam|lparam|defwinproc|optional, 1, 0},
307 { WM_NCACTIVATE, sent|wparam|optional, 0},
308 { WM_ACTIVATE, sent|wparam|optional, 0},
309 { WM_NCACTIVATE, sent|wparam|lparam|optional, 0, 0},
310 { WM_ACTIVATE, sent|wparam|lparam|optional, 0, 0},
311 { WM_ACTIVATEAPP, sent|wparam|optional, 0},
312 { WM_KILLFOCUS, sent|wparam|lparam|optional, 0, 0},
313 { WM_IME_SETCONTEXT, sent|wparam|optional, 0},
314 { WM_IME_NOTIFY, sent|wparam|lparam|defwinproc|optional, 1, 0},
315 { WM_DESTROY, sent|wparam|lparam, 0, 0},
316 { WM_NCDESTROY, sent|wparam|lparam, 0, 0},
320 static void test_monthcal(void)
323 SYSTEMTIME st[2], st1[2], today;
324 int res, month_range;
327 hwnd = CreateWindowA(MONTHCAL_CLASSA, "MonthCal", WS_POPUP | WS_VISIBLE, CW_USEDEFAULT,
328 0, 300, 300, 0, 0, NULL, NULL);
329 ok(hwnd != NULL, "Failed to create MonthCal\n");
331 /* test range just after creation */
332 memset(&st, 0xcc, sizeof(st));
333 limits = SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st);
335 broken(limits == GDTR_MIN), /* comctl32 <= 4.70 */
336 "No limits should be set (%d)\n", limits);
337 if (limits == GDTR_MIN)
339 win_skip("comctl32 <= 4.70 is broken\n");
344 ok(0 == st[0].wYear ||
345 broken(1752 == st[0].wYear), /* comctl32 <= 4.72 */
346 "Expected 0, got %d\n", st[0].wYear);
347 ok(0 == st[0].wMonth ||
348 broken(9 == st[0].wMonth), /* comctl32 <= 4.72 */
349 "Expected 0, got %d\n", st[0].wMonth);
350 ok(0 == st[0].wDay ||
351 broken(14 == st[0].wDay), /* comctl32 <= 4.72 */
352 "Expected 0, got %d\n", st[0].wDay);
353 expect(0, st[0].wDayOfWeek);
354 expect(0, st[0].wHour);
355 expect(0, st[0].wMinute);
356 expect(0, st[0].wSecond);
357 expect(0, st[0].wMilliseconds);
359 expect(0, st[1].wYear);
360 expect(0, st[1].wMonth);
361 expect(0, st[1].wDay);
362 expect(0, st[1].wDayOfWeek);
363 expect(0, st[1].wHour);
364 expect(0, st[1].wMinute);
365 expect(0, st[1].wSecond);
366 expect(0, st[1].wMilliseconds);
368 GetSystemTime(&st[0]);
371 SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&today);
373 /* Invalid date/time */
375 /* Time should not matter */
376 st[1].wHour = st[1].wMinute = st[1].wSecond = 70;
377 st[1].wMilliseconds = 1200;
378 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set MAX limit\n");
379 /* invalid timestamp is written back with today data and msecs untouched */
380 expect(today.wHour, st[1].wHour);
381 expect(today.wMinute, st[1].wMinute);
382 expect(today.wSecond, st[1].wSecond);
383 expect(1200, st[1].wMilliseconds);
385 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "No limits should be set\n");
386 ok(st1[0].wYear != 2000, "Lower limit changed\n");
387 /* invalid timestamp should be replaced with today data, except msecs */
388 expect(today.wHour, st1[1].wHour);
389 expect(today.wMinute, st1[1].wMinute);
390 expect(today.wSecond, st1[1].wSecond);
391 expect(1200, st1[1].wMilliseconds);
393 /* Invalid date/time with invalid milliseconds only */
394 GetSystemTime(&st[0]);
396 /* Time should not matter */
397 st[1].wMilliseconds = 1200;
398 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set MAX limit\n");
399 /* invalid milliseconds field doesn't lead to invalid timestamp */
400 expect(st[0].wHour, st[1].wHour);
401 expect(st[0].wMinute, st[1].wMinute);
402 expect(st[0].wSecond, st[1].wSecond);
403 expect(1200, st[1].wMilliseconds);
405 GetSystemTime(&st[0]);
408 ok(!SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Should have failed to set limits\n");
409 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "No limits should be set\n");
410 ok(st1[0].wYear != 2000, "Lower limit changed\n");
411 ok(!SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Should have failed to set MAX limit\n");
412 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "No limits should be set\n");
413 ok(st1[0].wYear != 2000, "Lower limit changed\n");
415 GetSystemTime(&st[0]);
420 month_range = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st1);
422 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Failed to set both min and max limits\n");
423 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st1);
424 ok(res == month_range, "Invalid month range (%d)\n", res);
425 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == (GDTR_MIN|GDTR_MAX), "Limits should be set\n");
428 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Failed to set both min and max limits\n");
429 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st1);
430 ok(res == month_range, "Invalid month range (%d)\n", res);
433 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Failed to set both min and max limits\n");
435 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Failed to set both min and max limits\n");
438 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
439 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "Only MAX limit should be set\n");
441 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
443 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
445 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set max limit\n");
446 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "Only MAX limit should be set\n");
448 /* set both limits, then set max < min */
449 GetSystemTime(&st[0]);
452 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN|GDTR_MAX, (LPARAM)st), "Failed to set limits\n");
453 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == (GDTR_MIN|GDTR_MAX), "Min limit expected\n");
455 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set limits\n");
456 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "Max limit expected\n");
458 expect(0, st1[0].wYear);
459 expect(0, st1[0].wMonth);
460 expect(0, st1[0].wDay);
461 expect(0, st1[0].wDayOfWeek);
462 expect(0, st1[0].wHour);
463 expect(0, st1[0].wMinute);
464 expect(0, st1[0].wSecond);
465 expect(0, st1[0].wMilliseconds);
467 expect(st[1].wYear, st1[1].wYear);
468 expect(st[1].wMonth, st1[1].wMonth);
469 expect(st[1].wDay, st1[1].wDay);
470 expect(st[1].wDayOfWeek, st1[1].wDayOfWeek);
471 expect(st[1].wHour, st1[1].wHour);
472 expect(st[1].wMinute, st1[1].wMinute);
473 expect(st[1].wSecond, st1[1].wSecond);
474 expect(st[1].wMilliseconds, st1[1].wMilliseconds);
478 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN|GDTR_MAX, (LPARAM)st), "Failed to set limits\n");
479 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == (GDTR_MIN|GDTR_MAX), "Min limit expected\n");
480 st[0].wYear++; /* start == end now */
481 ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN, (LPARAM)st), "Failed to set limits\n");
482 ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MIN, "Min limit expected\n");
484 expect(st[0].wYear, st1[0].wYear);
485 expect(st[0].wMonth, st1[0].wMonth);
486 expect(st[0].wDay, st1[0].wDay);
487 expect(st[0].wDayOfWeek, st1[0].wDayOfWeek);
488 expect(st[0].wHour, st1[0].wHour);
489 expect(st[0].wMinute, st1[0].wMinute);
490 expect(st[0].wSecond, st1[0].wSecond);
491 expect(st[0].wMilliseconds, st1[0].wMilliseconds);
493 expect(0, st1[1].wYear);
494 expect(0, st1[1].wMonth);
495 expect(0, st1[1].wDay);
496 expect(0, st1[1].wDayOfWeek);
497 expect(0, st1[1].wHour);
498 expect(0, st1[1].wMinute);
499 expect(0, st1[1].wSecond);
500 expect(0, st1[1].wMilliseconds);
505 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
507 static LONG defwndproc_counter = 0;
511 /* log system messages, except for painting */
512 if (message < WM_USER &&
513 message != WM_PAINT &&
514 message != WM_ERASEBKGND &&
515 message != WM_NCPAINT &&
516 message != WM_NCHITTEST &&
517 message != WM_GETTEXT &&
518 message != WM_GETICON &&
519 message != WM_DEVICECHANGE)
521 trace("parent: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
523 msg.message = message;
524 msg.flags = sent|wparam|lparam;
525 if (defwndproc_counter) msg.flags |= defwinproc;
528 add_message(sequences, PARENT_SEQ_INDEX, &msg);
531 defwndproc_counter++;
532 ret = DefWindowProcA(hwnd, message, wParam, lParam);
533 defwndproc_counter--;
538 static BOOL register_parent_wnd_class(void)
543 cls.lpfnWndProc = parent_wnd_proc;
546 cls.hInstance = GetModuleHandleA(NULL);
548 cls.hCursor = LoadCursorA(0, IDC_ARROW);
549 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
550 cls.lpszMenuName = NULL;
551 cls.lpszClassName = "Month-Cal test parent class";
552 return RegisterClassA(&cls);
555 static HWND create_parent_window(void)
559 InitCommonControls();
561 /* flush message sequences, so we can check the new sequence by the end of function */
562 flush_sequences(sequences, NUM_MSG_SEQUENCES);
564 if (!register_parent_wnd_class())
567 hwnd = CreateWindowEx(0, "Month-Cal test parent class",
568 "Month-Cal test parent window",
569 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
570 WS_MAXIMIZEBOX | WS_VISIBLE,
572 GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL);
576 /* check for message sequences */
577 ok_sequence(sequences, PARENT_SEQ_INDEX, create_parent_window_seq, "create parent window", FALSE);
582 static LRESULT WINAPI monthcal_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
584 struct subclass_info *info = (struct subclass_info *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
585 static LONG defwndproc_counter = 0;
589 msg.message = message;
590 msg.flags = sent|wparam|lparam;
591 if (defwndproc_counter) msg.flags |= defwinproc;
594 add_message(sequences, MONTHCAL_SEQ_INDEX, &msg);
596 /* some debug output for style changing */
597 if ((message == WM_STYLECHANGING ||
598 message == WM_STYLECHANGED) && lParam)
600 STYLESTRUCT *style = (STYLESTRUCT*)lParam;
601 trace("\told style: 0x%08x, new style: 0x%08x\n", style->styleOld, style->styleNew);
604 defwndproc_counter++;
605 ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
606 defwndproc_counter--;
611 static HWND create_monthcal_control(DWORD style)
613 struct subclass_info *info;
616 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
620 hwnd = CreateWindowEx(0,
623 WS_CHILD | WS_BORDER | WS_VISIBLE | style,
625 parent_wnd, NULL, GetModuleHandleA(NULL), NULL);
629 HeapFree(GetProcessHeap(), 0, info);
633 info->oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
634 (LONG_PTR)monthcal_subclass_proc);
635 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)info);
637 SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(SYSTEM_FONT), 0);
643 /* Setter and Getters Tests */
645 static void test_monthcal_color(void)
650 hwnd = create_monthcal_control(0);
652 flush_sequences(sequences, NUM_MSG_SEQUENCES);
654 /* Setter and Getters for color*/
655 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_BACKGROUND, 0);
656 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_BACKGROUND, RGB(0,0,0));
658 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_BACKGROUND, 0);
659 expect(RGB(0,0,0), temp);
660 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_BACKGROUND, RGB(255,255,255));
662 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_BACKGROUND, 0);
663 expect(RGB(255,255,255), temp);
665 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_MONTHBK, 0);
666 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_MONTHBK, RGB(0,0,0));
668 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_MONTHBK, 0);
669 expect(RGB(0,0,0), temp);
670 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_MONTHBK, RGB(255,255,255));
672 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_MONTHBK, 0);
673 expect(RGB(255,255,255), temp);
675 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TEXT, 0);
676 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TEXT, RGB(0,0,0));
678 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TEXT, 0);
679 expect(RGB(0,0,0), temp);
680 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TEXT, RGB(255,255,255));
682 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TEXT, 0);
683 expect(RGB(255,255,255), temp);
685 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLEBK, 0);
686 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLEBK, RGB(0,0,0));
688 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLEBK, 0);
689 expect(RGB(0,0,0), temp);
690 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLEBK, RGB(255,255,255));
692 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLEBK, 0);
693 expect(RGB(255,255,255), temp);
695 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLETEXT, 0);
696 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLETEXT, RGB(0,0,0));
698 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLETEXT, 0);
699 expect(RGB(0,0,0), temp);
700 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLETEXT, RGB(255,255,255));
702 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLETEXT, 0);
703 expect(RGB(255,255,255), temp);
705 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT, 0);
706 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TRAILINGTEXT, RGB(0,0,0));
708 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT, 0);
709 expect(RGB(0,0,0), temp);
710 res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TRAILINGTEXT, RGB(255,255,255));
712 temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT, 0);
713 expect(RGB(255,255,255), temp);
715 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_color_seq, "monthcal color", FALSE);
720 static void test_monthcal_currdate(void)
722 SYSTEMTIME st_original, st_new, st_test;
726 hwnd = create_monthcal_control(0);
728 flush_sequences(sequences, NUM_MSG_SEQUENCES);
730 /* Setter and Getters for current date selected */
731 st_original.wYear = 2000;
732 st_original.wMonth = 11;
733 st_original.wDay = 28;
734 st_original.wHour = 11;
735 st_original.wMinute = 59;
736 st_original.wSecond = 30;
737 st_original.wMilliseconds = 0;
738 st_original.wDayOfWeek = 0;
740 st_new = st_test = st_original;
742 /* Should not validate the time */
743 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
746 /* Overflow matters, check for wDay */
748 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
751 /* correct wDay before checking for wMonth */
753 expect(st_original.wDay, st_test.wDay);
755 /* Overflow matters, check for wMonth */
757 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_test);
760 /* checking if gets the information right, modify st_new */
768 res = SendMessage(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_new);
771 /* st_new change to st_origin, above settings with overflow */
772 /* should not change the current settings */
773 expect(st_original.wYear, st_new.wYear);
774 expect(st_original.wMonth, st_new.wMonth);
775 expect(st_original.wDay, st_new.wDay);
776 ok(st_original.wHour == st_new.wHour ||
777 broken(0 == st_new.wHour), /* comctl32 <= 4.70 */
778 "Expected %d, got %d\n", st_original.wHour, st_new.wHour);
779 ok(st_original.wMinute == st_new.wMinute ||
780 broken(0 == st_new.wMinute), /* comctl32 <= 4.70 */
781 "Expected %d, got %d\n", st_original.wMinute, st_new.wMinute);
782 ok(st_original.wSecond == st_new.wSecond ||
783 broken(0 == st_new.wSecond), /* comctl32 <= 4.70 */
784 "Expected %d, got %d\n", st_original.wSecond, st_new.wSecond);
786 /* lparam cannot be NULL */
787 res = SendMessage(hwnd, MCM_GETCURSEL, 0, 0);
790 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_curr_date_seq, "monthcal currDate", TRUE);
792 /* December, 31, 9999 is the maximum allowed date */
793 memset(&st_new, 0, sizeof(st_new));
797 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_new);
799 memset(&st_test, 0, sizeof(st_test));
800 res = SendMessage(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_test);
802 expect(st_new.wYear, st_test.wYear);
803 expect(st_new.wMonth, st_test.wMonth);
804 expect(st_new.wDay, st_test.wDay);
805 expect(st_new.wHour, st_test.wHour);
806 expect(st_new.wMinute, st_test.wMinute);
807 expect(st_new.wSecond, st_test.wSecond);
808 /* try one day later */
809 st_original = st_new;
810 st_new.wYear = 10000;
813 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_new);
815 broken(1 == res), /* comctl32 <= 4.72 */
816 "Expected 0, got %d\n", res);
819 memset(&st_test, 0, sizeof(st_test));
820 res = SendMessage(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_test);
822 expect(st_original.wYear, st_test.wYear);
823 expect(st_original.wMonth, st_test.wMonth);
824 expect(st_original.wDay, st_test.wDay);
825 expect(st_original.wHour, st_test.wHour);
826 expect(st_original.wMinute, st_test.wMinute);
827 expect(st_original.wSecond, st_test.wSecond);
830 /* setting selection equal to current reports success even if out range */
831 memset(&st_new, 0, sizeof(st_new));
835 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_new);
837 memset(&st_test, 0, sizeof(st_test));
838 st_test.wYear = 2009;
841 res = SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN, (LPARAM)&st_test);
843 /* set to current again */
844 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st_new);
850 static void test_monthcal_firstDay(void)
852 int res, fday, i, prev;
854 LCID lcid = LOCALE_USER_DEFAULT;
857 hwnd = create_monthcal_control(0);
859 flush_sequences(sequences, NUM_MSG_SEQUENCES);
861 /* Setter and Getters for first day of week */
862 /* check for locale first day */
863 if(GetLocaleInfoA(lcid, LOCALE_IFIRSTDAYOFWEEK, b, 128)){
865 trace("fday: %d\n", fday);
866 res = SendMessage(hwnd, MCM_GETFIRSTDAYOFWEEK, 0, 0);
870 /* checking for the values that actually will be stored as */
871 /* current first day when we set a new value */
872 for (i = -5; i < 12; i++){
873 res = SendMessage(hwnd, MCM_SETFIRSTDAYOFWEEK, 0, (LPARAM) i);
875 res = SendMessage(hwnd, MCM_GETFIRSTDAYOFWEEK, 0, 0);
879 expect(MAKELONG(fday, FALSE), res);
881 /* out of range sets max first day of week, locale is ignored */
882 expect(MAKELONG(6, TRUE), res);
884 expect(MAKELONG(i, TRUE), res);
888 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_first_day_seq, "monthcal firstDay", FALSE);
891 skip("Cannot retrieve first day of the week\n");
897 static void test_monthcal_unicode(void)
902 hwnd = create_monthcal_control(0);
904 flush_sequences(sequences, NUM_MSG_SEQUENCES);
906 /* Setter and Getters for Unicode format */
908 /* getting the current settings */
909 temp = SendMessage(hwnd, MCM_GETUNICODEFORMAT, 0, 0);
911 /* setting to 1, should return previous settings */
912 res = SendMessage(hwnd, MCM_SETUNICODEFORMAT, 1, 0);
915 /* current setting is 1, so, should return 1 */
916 res = SendMessage(hwnd, MCM_GETUNICODEFORMAT, 0, 0);
919 broken(0 == res), /* comctl32 <= 4.70 */
920 "Expected 1, got %d\n", res);
922 /* setting to 0, should return previous settings */
923 res = SendMessage(hwnd, MCM_SETUNICODEFORMAT, 0, 0);
926 broken(0 == res), /* comctl32 <= 4.70 */
927 "Expected 1, got %d\n", res);
929 /* current setting is 0, so, it should return 0 */
930 res = SendMessage(hwnd, MCM_GETUNICODEFORMAT, 0, 0);
933 /* should return previous settings */
934 res = SendMessage(hwnd, MCM_SETUNICODEFORMAT, 1, 0);
937 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_unicode_seq, "monthcal unicode", FALSE);
942 static void test_monthcal_hittest(void)
944 typedef struct hittest_test
950 static const hittest_test_t title_hits[] = {
951 /* Start is the same everywhere */
953 { MCHT_TITLEBTNPREV, 0 },
954 /* The middle piece is only tested for presence of items */
955 /* End is the same everywhere */
956 { MCHT_TITLEBTNNEXT, 0 },
968 char yearmonth[80], *locale_month, *locale_year;
969 int month_count, year_count;
972 memset(&mchit, 0, sizeof(MCHITTESTINFO));
974 hwnd = create_monthcal_control(0);
976 /* test with invalid structure size */
977 mchit.cbSize = MCHITTESTINFO_V1_SIZE - 1;
980 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
981 expect(0, mchit.pt.x);
982 expect(0, mchit.pt.y);
984 expect(0, mchit.uHit);
985 /* test with invalid pointer */
986 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)NULL);
989 /* resize control to display single Calendar */
990 res = SendMessage(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r);
993 win_skip("Message MCM_GETMINREQRECT unsupported. Skipping.\n");
997 MoveWindow(hwnd, 0, 0, r.right, r.bottom, FALSE);
999 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1007 st.wMilliseconds = 0;
1010 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st);
1013 /* (0, 0) is the top left of the control - title */
1014 mchit.cbSize = MCHITTESTINFO_V1_SIZE;
1017 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1018 expect(0, mchit.pt.x);
1019 expect(0, mchit.pt.y);
1020 expect(mchit.uHit, res);
1021 expect_hex(MCHT_TITLE, res);
1023 /* bottom right of the control and should not be active */
1024 mchit.pt.x = r.right;
1025 mchit.pt.y = r.bottom;
1026 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM)&mchit);
1027 expect(r.right, mchit.pt.x);
1028 expect(r.bottom, mchit.pt.y);
1029 expect(mchit.uHit, res);
1030 todo_wine expect_hex(MCHT_NOWHERE, res);
1032 /* completely out of the control, should not be active */
1033 mchit.pt.x = 2 * r.right;
1034 mchit.pt.y = 2 * r.bottom;
1035 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1036 expect(2 * r.right, mchit.pt.x);
1037 expect(2 * r.bottom, mchit.pt.y);
1038 expect(mchit.uHit, res);
1039 todo_wine expect_hex(MCHT_NOWHERE, res);
1041 /* in active area - day of the week */
1042 mchit.pt.x = r.right / 2;
1043 mchit.pt.y = r.bottom / 2;
1044 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1045 expect(r.right / 2, mchit.pt.x);
1046 expect(r.bottom / 2, mchit.pt.y);
1047 expect(mchit.uHit, res);
1048 expect_hex(MCHT_CALENDARDATE, res);
1050 /* in active area - day of the week #2 */
1051 mchit.pt.x = r.right / 14; /* half of first day rect */
1052 mchit.pt.y = r.bottom / 2;
1053 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1054 expect(r.right / 14, mchit.pt.x);
1055 expect(r.bottom / 2, mchit.pt.y);
1056 expect(mchit.uHit, res);
1057 expect_hex(MCHT_CALENDARDATE, res);
1059 /* in active area - date from prev month */
1060 mchit.pt.x = r.right / 14; /* half of first day rect */
1061 mchit.pt.y = 6 * r.bottom / 19;
1062 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1063 expect(r.right / 14, mchit.pt.x);
1064 expect(6 * r.bottom / 19, mchit.pt.y);
1065 expect(mchit.uHit, res);
1066 expect_hex(MCHT_CALENDARDATEPREV, res);
1069 /* (125, 115) is in active area - date from this month */
1072 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1073 expect(125, mchit.pt.x);
1074 expect(115, mchit.pt.y);
1075 expect(mchit.uHit, res);
1076 expect(MCHT_CALENDARDATE, res);
1079 /* in active area - date from next month */
1080 mchit.pt.x = 11 * r.right / 14;
1081 mchit.pt.y = 16 * r.bottom / 19;
1082 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1083 expect(11 * r.right / 14, mchit.pt.x);
1084 expect(16 * r.bottom / 19, mchit.pt.y);
1085 expect(mchit.uHit, res);
1086 expect_hex(MCHT_CALENDARDATENEXT, res);
1088 /* in active area - today link */
1089 mchit.pt.x = r.right / 14;
1090 mchit.pt.y = 18 * r.bottom / 19;
1091 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1092 expect(r.right / 14, mchit.pt.x);
1093 expect(18 * r.bottom / 19, mchit.pt.y);
1094 expect(mchit.uHit, res);
1095 expect_hex(MCHT_TODAYLINK, res);
1097 /* in active area - today link */
1098 mchit.pt.x = r.right / 2;
1099 mchit.pt.y = 18 * r.bottom / 19;
1100 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1101 expect(r.right / 2, mchit.pt.x);
1102 expect(18 * r.bottom / 19, mchit.pt.y);
1103 expect(mchit.uHit, res);
1104 expect_hex(MCHT_TODAYLINK, res);
1106 /* in active area - today link */
1107 mchit.pt.x = r.right / 10;
1108 mchit.pt.y = 18 * r.bottom / 19;
1109 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1110 expect(r.right / 10, mchit.pt.x);
1111 expect(18 * r.bottom / 19, mchit.pt.y);
1112 expect(mchit.uHit, res);
1113 expect_hex(MCHT_TODAYLINK, res);
1115 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_hit_test_seq, "monthcal hit test", TRUE);
1117 /* The horizontal position of title bar elements depends on locale (y pos
1118 is constant), so we sample across a horizontal line and make sure we
1119 find all elements. */
1121 /* Get the format of the title */
1122 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SYEARMONTH, yearmonth, 80);
1123 /* Find out if we have a month and/or year */
1124 locale_year = strstr(yearmonth, "y");
1125 locale_month = strstr(yearmonth, "M");
1128 mchit.pt.y = (5/2) * r.bottom / 19;
1130 old_res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1131 expect_hex(title_hits[title_index].ht, old_res);
1133 in_the_middle = FALSE;
1134 month_count = year_count = 0;
1135 for (x = 0; x < r.right; x++){
1137 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1138 expect(x, mchit.pt.x);
1139 expect((5/2) * r.bottom / 19, mchit.pt.y);
1140 expect(mchit.uHit, res);
1141 if (res != old_res) {
1143 if (old_res == MCHT_TITLEBTNPREV)
1144 in_the_middle = TRUE;
1146 if (res == MCHT_TITLEBTNNEXT)
1147 in_the_middle = FALSE;
1149 if (in_the_middle) {
1150 if (res == MCHT_TITLEMONTH)
1152 else if (res == MCHT_TITLEYEAR)
1157 if (sizeof(title_hits) / sizeof(title_hits[0]) <= title_index)
1160 if (title_hits[title_index].todo) {
1162 ok(title_hits[title_index].ht == res, "Expected %x, got %x, pos %d\n",
1163 title_hits[title_index].ht, res, x);
1165 ok(title_hits[title_index].ht == res, "Expected %x, got %x, pos %d\n",
1166 title_hits[title_index].ht, res, x);
1173 /* There are some limits, even if LOCALE_SYEARMONTH contains rubbish
1174 * or no month/year indicators at all */
1176 todo_wine ok(month_count == 1, "Expected 1 month item, got %d\n", month_count);
1178 ok(month_count <= 1, "Too many month items: %d\n", month_count);
1181 todo_wine ok(year_count == 1, "Expected 1 year item, got %d\n", year_count);
1183 ok(year_count <= 1, "Too many year items: %d\n", year_count);
1185 todo_wine ok(month_count + year_count >= 1, "Not enough month and year items\n");
1187 ok(r.right <= x && title_index + 1 == sizeof(title_hits) / sizeof(title_hits[0]),
1188 "Wrong title layout\n");
1190 DestroyWindow(hwnd);
1193 static void test_monthcal_todaylink(void)
1195 MCHITTESTINFO mchit;
1196 SYSTEMTIME st_test, st_new;
1201 memset(&mchit, 0, sizeof(MCHITTESTINFO));
1203 hwnd = create_monthcal_control(0);
1205 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1207 /* (70, 370) is in active area - today link */
1208 mchit.cbSize = MCHITTESTINFO_V1_SIZE;
1211 res = SendMessage(hwnd, MCM_HITTEST, 0, (LPARAM) & mchit);
1212 expect(70, mchit.pt.x);
1213 expect(370, mchit.pt.y);
1214 expect(mchit.uHit, res);
1215 todo_wine {expect(MCHT_TODAYLINK, res);}
1216 if (70 != mchit.pt.x || 370 != mchit.pt.y || mchit.uHit != res
1217 || MCHT_TODAYLINK != res)
1222 st_test.wYear = 2005;
1223 memset(&st_new, 0, sizeof(SYSTEMTIME));
1225 SendMessage(hwnd, MCM_SETTODAY, 0, (LPARAM)&st_test);
1227 res = SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&st_new);
1229 expect(1, st_new.wDay);
1230 expect(1, st_new.wMonth);
1231 expect(2005, st_new.wYear);
1232 if (1 != res || 1 != st_new.wDay || 1 != st_new.wMonth
1233 || 2005 != st_new.wYear)
1237 skip("cannot perform today link test\n");
1241 res = SendMessage(hwnd, WM_LBUTTONDOWN, MK_LBUTTON, MAKELONG(70, 370));
1244 memset(&st_new, 0, sizeof(SYSTEMTIME));
1245 res = SendMessage(hwnd, MCM_GETCURSEL, 0, (LPARAM)&st_new);
1247 expect(1, st_new.wDay);
1248 expect(1, st_new.wMonth);
1249 expect(2005, st_new.wYear);
1251 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_todaylink_seq, "monthcal hit test", TRUE);
1253 DestroyWindow(hwnd);
1256 static void test_monthcal_today(void)
1258 SYSTEMTIME st_test, st_new;
1262 hwnd = create_monthcal_control(0);
1264 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1266 /* Setter and Getters for "today" information */
1268 /* check for overflow, should be ok */
1270 st_test.wMonth = 38;
1275 SendMessage(hwnd, MCM_SETTODAY, 0, (LPARAM)&st_test);
1277 res = SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&st_new);
1280 /* st_test should not change */
1281 expect(38, st_test.wDay);
1282 expect(38, st_test.wMonth);
1284 /* st_new should change, overflow does not matter */
1285 expect(38, st_new.wDay);
1286 expect(38, st_new.wMonth);
1288 /* check for zero, should be ok*/
1292 SendMessage(hwnd, MCM_SETTODAY, 0, (LPARAM)&st_test);
1294 res = SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&st_new);
1297 /* st_test should not change */
1298 expect(0, st_test.wDay);
1299 expect(0, st_test.wMonth);
1301 /* st_new should change to zero*/
1302 expect(0, st_new.wDay);
1303 expect(0, st_new.wMonth);
1305 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_today_seq, "monthcal today", TRUE);
1307 DestroyWindow(hwnd);
1310 static void test_monthcal_scroll(void)
1315 hwnd = create_monthcal_control(0);
1317 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1319 /* Setter and Getters for scroll rate */
1320 res = SendMessage(hwnd, MCM_SETMONTHDELTA, 2, 0);
1323 res = SendMessage(hwnd, MCM_SETMONTHDELTA, 3, 0);
1325 res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
1328 res = SendMessage(hwnd, MCM_SETMONTHDELTA, 12, 0);
1330 res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
1333 res = SendMessage(hwnd, MCM_SETMONTHDELTA, 15, 0);
1335 res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
1338 res = SendMessage(hwnd, MCM_SETMONTHDELTA, -5, 0);
1340 res = SendMessage(hwnd, MCM_GETMONTHDELTA, 0, 0);
1343 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_scroll_seq, "monthcal scroll", FALSE);
1345 DestroyWindow(hwnd);
1348 static void test_monthcal_monthrange(void)
1351 SYSTEMTIME st_visible[2], st_daystate[2], st;
1354 hwnd = create_monthcal_control(0);
1356 st_visible[0].wYear = 0;
1357 st_visible[0].wMonth = 0;
1358 st_visible[0].wDay = 0;
1359 st_daystate[1] = st_daystate[0] = st_visible[1] = st_visible[0];
1367 st.wMilliseconds = 0;
1370 res = SendMessage(hwnd, MCM_SETCURSEL, 0, (LPARAM)&st);
1373 /* to be locale independent */
1374 SendMessage(hwnd, MCM_SETFIRSTDAYOFWEEK, 0, (LPARAM)6);
1376 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1378 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_VISIBLE, (LPARAM)st_visible);
1382 expect(2000, st_visible[0].wYear);
1383 expect(11, st_visible[0].wMonth);
1384 expect(1, st_visible[0].wDay);
1385 expect(2000, st_visible[1].wYear);
1388 expect(12, st_visible[1].wMonth);
1389 expect(31, st_visible[1].wDay);
1391 res = SendMessage(hwnd, MCM_GETMONTHRANGE, GMR_DAYSTATE, (LPARAM)st_daystate);
1395 expect(2000, st_daystate[0].wYear);
1396 expect(10, st_daystate[0].wMonth);
1397 expect(29, st_daystate[0].wDay);
1400 expect(2001, st_daystate[1].wYear);
1401 expect(1, st_daystate[1].wMonth);
1402 expect(6, st_daystate[1].wDay);
1405 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_monthrange_seq, "monthcal monthrange", FALSE);
1407 DestroyWindow(hwnd);
1410 static void test_monthcal_maxselday(void)
1416 hwnd = create_monthcal_control(0);
1417 /* if no style specified default to 1 */
1418 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1420 res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, 5, 0);
1422 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1425 /* try to set style */
1426 style = GetWindowLong(hwnd, GWL_STYLE);
1427 SetWindowLong(hwnd, GWL_STYLE, style | MCS_MULTISELECT);
1428 style = GetWindowLong(hwnd, GWL_STYLE);
1429 ok(!(style & MCS_MULTISELECT), "Expected MCS_MULTISELECT not to be set\n");
1430 DestroyWindow(hwnd);
1432 hwnd = create_monthcal_control(MCS_MULTISELECT);
1433 /* try to remove style */
1434 style = GetWindowLong(hwnd, GWL_STYLE);
1435 SetWindowLong(hwnd, GWL_STYLE, style & ~MCS_MULTISELECT);
1436 style = GetWindowLong(hwnd, GWL_STYLE);
1437 ok(style & MCS_MULTISELECT, "Expected MCS_MULTISELECT to be set\n");
1438 DestroyWindow(hwnd);
1440 hwnd = create_monthcal_control(MCS_MULTISELECT);
1442 /* default width is a week */
1443 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1446 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1448 /* Setter and Getters for max selected days */
1449 res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, 5, 0);
1451 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1454 res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, 15, 0);
1456 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1459 /* test invalid value */
1460 res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, -1, 0);
1462 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1465 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_max_sel_day_seq, "monthcal MaxSelDay", FALSE);
1467 /* zero value is invalid too */
1468 res = SendMessage(hwnd, MCM_SETMAXSELCOUNT, 0, 0);
1470 res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0);
1473 DestroyWindow(hwnd);
1476 static void test_monthcal_size(void)
1480 HFONT hFont1, hFont2;
1484 hwnd = create_monthcal_control(0);
1486 lstrcpyA(logfont.lfFaceName, "Arial");
1487 memset(&logfont, 0, sizeof(logfont));
1488 logfont.lfHeight = 12;
1489 hFont1 = CreateFontIndirectA(&logfont);
1491 logfont.lfHeight = 24;
1492 hFont2 = CreateFontIndirectA(&logfont);
1494 /* initialize to a font we can compare against */
1495 SendMessage(hwnd, WM_SETFONT, (WPARAM)hFont1, 0);
1496 res = SendMessage(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r1);
1498 /* check that setting a larger font results in an larger rect */
1499 SendMessage(hwnd, WM_SETFONT, (WPARAM)hFont2, 0);
1500 res = SendMessage(hwnd, MCM_GETMINREQRECT, 0, (LPARAM)&r2);
1502 OffsetRect(&r1, -r1.left, -r1.top);
1503 OffsetRect(&r2, -r2.left, -r2.top);
1505 ok(r1.bottom < r2.bottom, "Failed to get larger rect with larger font\n");
1507 DestroyWindow(hwnd);
1510 static void test_monthcal_create(void)
1514 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1516 hwnd = create_monthcal_control(0);
1517 ok_sequence(sequences, PARENT_SEQ_INDEX, create_monthcal_control_seq, "create monthcal control", TRUE);
1519 DestroyWindow(hwnd);
1521 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1522 hwnd = create_monthcal_control(MCS_MULTISELECT);
1523 ok_sequence(sequences, PARENT_SEQ_INDEX, create_monthcal_multi_sel_style_seq, "create monthcal (multi sel style)", TRUE);
1524 DestroyWindow(hwnd);
1527 static void test_monthcal_destroy(void)
1531 hwnd = create_monthcal_control(0);
1532 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1533 DestroyWindow(hwnd);
1534 ok_sequence(sequences, PARENT_SEQ_INDEX, destroy_monthcal_parent_msgs_seq, "Destroy monthcal (parent msg)", FALSE);
1535 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, destroy_monthcal_child_msgs_seq, "Destroy monthcal (child msg)", FALSE);
1537 /* MCS_MULTISELECT */
1538 hwnd = create_monthcal_control(MCS_MULTISELECT);
1539 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1540 DestroyWindow(hwnd);
1541 ok_sequence(sequences, MONTHCAL_SEQ_INDEX, destroy_monthcal_multi_sel_style_seq, "Destroy monthcal (multi sel style)", FALSE);
1544 static void test_monthcal_selrange(void)
1547 SYSTEMTIME st, range[2], range2[2];
1548 BOOL ret, old_comctl32 = FALSE;
1550 hwnd = create_monthcal_control(MCS_MULTISELECT);
1552 /* just after creation selection should start and end today */
1553 ret = SendMessage(hwnd, MCM_GETTODAY, 0, (LPARAM)&st);
1556 memset(range, 0xcc, sizeof(range));
1557 ret = SendMessage(hwnd, MCM_GETSELRANGE, 0, (LPARAM)range);
1559 expect(st.wYear, range[0].wYear);
1560 expect(st.wMonth, range[0].wMonth);
1561 expect(st.wDay, range[0].wDay);
1562 if (range[0].wDayOfWeek == 0)
1564 win_skip("comctl32 <= 4.70 doesn't set some values\n");
1565 old_comctl32 = TRUE;
1569 expect(st.wDayOfWeek, range[0].wDayOfWeek);
1570 expect(st.wHour, range[0].wHour);
1571 expect(st.wMinute, range[0].wMinute);
1572 expect(st.wSecond, range[0].wSecond);
1573 expect(st.wMilliseconds, range[0].wMilliseconds);
1576 expect(st.wYear, range[1].wYear);
1577 expect(st.wMonth, range[1].wMonth);
1578 expect(st.wDay, range[1].wDay);
1581 expect(st.wDayOfWeek, range[1].wDayOfWeek);
1582 expect(st.wHour, range[1].wHour);
1583 expect(st.wMinute, range[1].wMinute);
1584 expect(st.wSecond, range[1].wSecond);
1585 expect(st.wMilliseconds, range[1].wMilliseconds);
1588 /* bounds are swapped if min > max */
1589 memset(&range[0], 0, sizeof(range[0]));
1590 range[0].wYear = 2009;
1591 range[0].wMonth = 10;
1593 range[1] = range[0];
1596 ret = SendMessage(hwnd, MCM_SETSELRANGE, 0, (LPARAM)range);
1599 ret = SendMessage(hwnd, MCM_GETSELRANGE, 0, (LPARAM)range2);
1602 expect(range[1].wYear, range2[0].wYear);
1603 expect(range[1].wMonth, range2[0].wMonth);
1604 expect(range[1].wDay, range2[0].wDay);
1605 expect(6, range2[0].wDayOfWeek);
1606 expect(range[1].wHour, range2[0].wHour);
1607 expect(range[1].wMinute, range2[0].wMinute);
1608 expect(range[1].wSecond, range2[0].wSecond);
1609 expect(range[1].wMilliseconds, range2[0].wMilliseconds);
1611 expect(range[0].wYear, range2[1].wYear);
1612 expect(range[0].wMonth, range2[1].wMonth);
1613 expect(range[0].wDay, range2[1].wDay);
1614 expect(1, range2[1].wDayOfWeek);
1615 expect(range[0].wHour, range2[1].wHour);
1616 expect(range[0].wMinute, range2[1].wMinute);
1617 expect(range[0].wSecond, range2[1].wSecond);
1618 expect(range[0].wMilliseconds, range2[1].wMilliseconds);
1620 /* try with range larger than maximum configured */
1621 memset(&range[0], 0, sizeof(range[0]));
1622 range[0].wYear = 2009;
1623 range[0].wMonth = 10;
1625 range[1] = range[0];
1627 ret = SendMessage(hwnd, MCM_SETSELRANGE, 0, (LPARAM)range);
1630 range[1] = range[0];
1631 /* default max. range is 7 days */
1634 ret = SendMessage(hwnd, MCM_SETSELRANGE, 0, (LPARAM)range);
1637 ret = SendMessage(hwnd, MCM_GETSELRANGE, 0, (LPARAM)range2);
1640 expect(range[0].wYear, range2[0].wYear);
1641 expect(range[0].wMonth, range2[0].wMonth);
1642 expect(range[0].wDay, range2[0].wDay);
1643 expect(range[0].wYear, range2[1].wYear);
1644 expect(range[0].wMonth, range2[1].wMonth);
1645 expect(range[0].wDay, range2[1].wDay);
1647 DestroyWindow(hwnd);
1650 START_TEST(monthcal)
1653 BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
1654 INITCOMMONCONTROLSEX iccex;
1656 hComctl32 = GetModuleHandleA("comctl32.dll");
1657 pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
1658 if (!pInitCommonControlsEx)
1660 skip("InitCommonControlsEx() is missing. Skipping the tests\n");
1663 iccex.dwSize = sizeof(iccex);
1664 iccex.dwICC = ICC_DATE_CLASSES;
1665 pInitCommonControlsEx(&iccex);
1669 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
1671 parent_wnd = create_parent_window();
1673 test_monthcal_create();
1674 test_monthcal_destroy();
1675 test_monthcal_color();
1676 test_monthcal_currdate();
1677 test_monthcal_firstDay();
1678 test_monthcal_unicode();
1679 test_monthcal_today();
1680 test_monthcal_scroll();
1681 test_monthcal_monthrange();
1682 test_monthcal_hittest();
1683 test_monthcal_todaylink();
1684 test_monthcal_size();
1685 test_monthcal_maxselday();
1686 test_monthcal_selrange();
1688 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1689 DestroyWindow(parent_wnd);
1690 ok_sequence(sequences, PARENT_SEQ_INDEX, destroy_parent_seq, "Destroy parent window", FALSE);