2 * Month calendar control
4 * Copyright 1998, 1999 Eric Kohl (ekohl@abo.rhein-zeitung.de)
5 * Copyright 1999 Alex Priem (alexp@sci.kun.nl)
6 * Copyright 1999 Chris Morgan <cmorgan@wpi.edu> and
7 * James Abbatiello <abbeyj@wpi.edu>
8 * Copyright 2000 Uwe Bonnes <bon@elektron.ikp.physik.tu-darmstadt.de>
9 * Copyright 2009-2011 Nikolay Sivov
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 * This code was audited for completeness against the documented features
28 * of Comctl32.dll version 6.0 on Oct. 20, 2004, by Dimitrie O. Paun.
30 * Unless otherwise noted, we believe this code to be complete, as per
31 * the specification mentioned above.
32 * If you discover missing features, or bugs, please note them below.
35 * -- MCM_[GS]ETUNICODEFORMAT
36 * -- handle resources better (doesn't work now);
37 * -- take care of internationalization.
38 * -- keyboard handling.
57 #include "wine/unicode.h"
58 #include "wine/debug.h"
60 WINE_DEFAULT_DEBUG_CHANNEL(monthcal);
62 #define MC_SEL_LBUTUP 1 /* Left button released */
63 #define MC_SEL_LBUTDOWN 2 /* Left button pressed in calendar */
64 #define MC_PREVPRESSED 4 /* Prev month button pressed */
65 #define MC_NEXTPRESSED 8 /* Next month button pressed */
66 #define MC_PREVNEXTMONTHDELAY 350 /* when continuously pressing `next/prev
67 month', wait 350 ms before going
68 to the next/prev month */
69 #define MC_TODAYUPDATEDELAY 120000 /* time between today check for update (2 min) */
71 #define MC_PREVNEXTMONTHTIMER 1 /* Timer ID's */
72 #define MC_TODAYUPDATETIMER 2
74 #define countof(arr) (sizeof(arr)/sizeof(arr[0]))
76 /* convert from days to 100 nanoseconds unit - used as FILETIME unit */
77 #define DAYSTO100NSECS(days) (((ULONGLONG)(days))*24*60*60*10000000)
94 /* single calendar data */
95 typedef struct _CALENDAR_INFO
97 RECT title; /* rect for the header above the calendar */
98 RECT titlemonth; /* the 'month name' text in the header */
99 RECT titleyear; /* the 'year number' text in the header */
100 RECT wdays; /* week days at top */
101 RECT days; /* calendar area */
102 RECT weeknums; /* week numbers at left side */
104 SYSTEMTIME month;/* contains calendar main month/year */
110 DWORD dwStyle; /* cached GWL_STYLE */
112 COLORREF colors[MCSC_TRAILINGTEXT+1];
113 HBRUSH brushes[BrushLast];
120 int height_increment;
122 INT delta; /* scroll rate; # of months that the */
123 /* control moves when user clicks a scroll button */
124 int visible; /* # of months visible */
125 int firstDay; /* Start month calendar with firstDay's day,
126 stored in SYSTEMTIME format */
127 BOOL firstDaySet; /* first week day differs from locale defined */
129 BOOL isUnicode; /* value set with MCM_SETUNICODE format */
132 MONTHDAYSTATE *monthdayState;
133 SYSTEMTIME todaysDate;
134 BOOL todaySet; /* Today was forced with MCM_SETTODAY */
135 int status; /* See MC_SEL flags */
136 SYSTEMTIME firstSel; /* first selected day */
138 SYSTEMTIME minSel; /* contains single selection when used without MCS_MULTISELECT */
140 SYSTEMTIME focusedSel; /* date currently focused with mouse movement */
145 RECT titlebtnnext; /* the `next month' button in the header */
146 RECT titlebtnprev; /* the `prev month' button in the header */
147 RECT todayrect; /* `today: xx/xx/xx' text rect */
148 HWND hwndNotify; /* Window to receive the notifications */
149 HWND hWndYearEdit; /* Window Handle of edit box to handle years */
150 HWND hWndYearUpDown;/* Window Handle of updown box to handle years */
151 WNDPROC EditWndProc; /* original Edit window procedure */
153 CALENDAR_INFO *calendars;
155 } MONTHCAL_INFO, *LPMONTHCAL_INFO;
157 static const WCHAR themeClass[] = { 'S','c','r','o','l','l','b','a','r',0 };
159 /* empty SYSTEMTIME const */
160 static const SYSTEMTIME st_null;
161 /* valid date limits */
162 static const SYSTEMTIME max_allowed_date = { .wYear = 9999, .wMonth = 12, .wDay = 31 };
163 static const SYSTEMTIME min_allowed_date = { .wYear = 1752, .wMonth = 9, .wDay = 14 };
165 /* Prev/Next buttons */
172 /* helper functions */
174 /* send a single MCN_SELCHANGE notification */
175 static inline void MONTHCAL_NotifySelectionChange(const MONTHCAL_INFO *infoPtr)
179 nmsc.nmhdr.hwndFrom = infoPtr->hwndSelf;
180 nmsc.nmhdr.idFrom = GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_ID);
181 nmsc.nmhdr.code = MCN_SELCHANGE;
182 nmsc.stSelStart = infoPtr->minSel;
183 nmsc.stSelEnd = infoPtr->maxSel;
184 SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, nmsc.nmhdr.idFrom, (LPARAM)&nmsc);
187 /* send a single MCN_SELECT notification */
188 static inline void MONTHCAL_NotifySelect(const MONTHCAL_INFO *infoPtr)
192 nmsc.nmhdr.hwndFrom = infoPtr->hwndSelf;
193 nmsc.nmhdr.idFrom = GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_ID);
194 nmsc.nmhdr.code = MCN_SELECT;
195 nmsc.stSelStart = infoPtr->minSel;
196 nmsc.stSelEnd = infoPtr->maxSel;
198 SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, nmsc.nmhdr.idFrom, (LPARAM)&nmsc);
201 /* returns the number of days in any given month, checking for leap days */
202 /* january is 1, december is 12 */
203 int MONTHCAL_MonthLength(int month, int year)
205 const int mdays[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
206 /* Wrap around, this eases handling. Getting length only we shouldn't care
207 about year change here cause January and December have
208 the same day quantity */
214 /* special case for calendar transition year */
215 if(month == min_allowed_date.wMonth && year == min_allowed_date.wYear) return 19;
217 /* if we have a leap year add 1 day to February */
218 /* a leap year is a year either divisible by 400 */
219 /* or divisible by 4 and not by 100 */
220 if(month == 2) { /* February */
221 return mdays[month - 1] + ((year%400 == 0) ? 1 : ((year%100 != 0) &&
222 (year%4 == 0)) ? 1 : 0);
225 return mdays[month - 1];
229 /* compares timestamps using date part only */
230 static inline BOOL MONTHCAL_IsDateEqual(const SYSTEMTIME *first, const SYSTEMTIME *second)
232 return (first->wYear == second->wYear) && (first->wMonth == second->wMonth) &&
233 (first->wDay == second->wDay);
236 /* make sure that date fields are valid */
237 static BOOL MONTHCAL_ValidateDate(const SYSTEMTIME *time)
239 if(time->wMonth < 1 || time->wMonth > 12 ) return FALSE;
240 if(time->wDayOfWeek > 6) return FALSE;
241 if(time->wDay > MONTHCAL_MonthLength(time->wMonth, time->wYear))
247 /* Copies timestamp part only.
251 * [I] from : source date
254 static void MONTHCAL_CopyTime(const SYSTEMTIME *from, SYSTEMTIME *to)
256 to->wHour = from->wHour;
257 to->wMinute = from->wMinute;
258 to->wSecond = from->wSecond;
261 /* Copies date part only.
265 * [I] from : source date
268 static void MONTHCAL_CopyDate(const SYSTEMTIME *from, SYSTEMTIME *to)
270 to->wYear = from->wYear;
271 to->wMonth = from->wMonth;
272 to->wDay = from->wDay;
273 to->wDayOfWeek = from->wDayOfWeek;
276 /* Compares two dates in SYSTEMTIME format
280 * [I] first : pointer to valid first date data to compare
281 * [I] second : pointer to valid second date data to compare
285 * -1 : first < second
286 * 0 : first == second
289 * Note that no date validation performed, alreadt validated values expected.
291 static LONG MONTHCAL_CompareSystemTime(const SYSTEMTIME *first, const SYSTEMTIME *second)
293 FILETIME ft_first, ft_second;
295 SystemTimeToFileTime(first, &ft_first);
296 SystemTimeToFileTime(second, &ft_second);
298 return CompareFileTime(&ft_first, &ft_second);
301 static LONG MONTHCAL_CompareMonths(const SYSTEMTIME *first, const SYSTEMTIME *second)
303 SYSTEMTIME st_first, st_second;
305 st_first = st_second = st_null;
306 MONTHCAL_CopyDate(first, &st_first);
307 MONTHCAL_CopyDate(second, &st_second);
308 st_first.wDay = st_second.wDay = 1;
310 return MONTHCAL_CompareSystemTime(&st_first, &st_second);
313 static LONG MONTHCAL_CompareDate(const SYSTEMTIME *first, const SYSTEMTIME *second)
315 SYSTEMTIME st_first, st_second;
317 st_first = st_second = st_null;
318 MONTHCAL_CopyDate(first, &st_first);
319 MONTHCAL_CopyDate(second, &st_second);
321 return MONTHCAL_CompareSystemTime(&st_first, &st_second);
324 /* Checks largest possible date range and configured one
328 * [I] infoPtr : valid pointer to control data
329 * [I] date : pointer to valid date data to check
330 * [I] fix : make date fit valid range
334 * TRUE - date whithin largest and configured range
335 * FALSE - date is outside largest or configured range
337 static BOOL MONTHCAL_IsDateInValidRange(const MONTHCAL_INFO *infoPtr,
338 SYSTEMTIME *date, BOOL fix)
340 const SYSTEMTIME *fix_st = NULL;
342 if(MONTHCAL_CompareSystemTime(date, &max_allowed_date) == 1) {
343 fix_st = &max_allowed_date;
345 else if(MONTHCAL_CompareSystemTime(date, &min_allowed_date) == -1) {
346 fix_st = &min_allowed_date;
348 else if(infoPtr->rangeValid & GDTR_MAX) {
349 if((MONTHCAL_CompareSystemTime(date, &infoPtr->maxDate) == 1)) {
350 fix_st = &infoPtr->maxDate;
353 else if(infoPtr->rangeValid & GDTR_MIN) {
354 if((MONTHCAL_CompareSystemTime(date, &infoPtr->minDate) == -1)) {
355 fix_st = &infoPtr->minDate;
360 date->wYear = fix_st->wYear;
361 date->wMonth = fix_st->wMonth;
364 return fix_st ? FALSE : TRUE;
367 /* Checks passed range width with configured maximum selection count
371 * [I] infoPtr : valid pointer to control data
372 * [I] range0 : pointer to valid date data (requested bound)
373 * [I] range1 : pointer to valid date data (primary bound)
374 * [O] adjust : returns adjusted range bound to fit maximum range (optional)
376 * Adjust value computed basing on primary bound and current maximum selection
377 * count. For simple range check (without adjusted value required) (range0, range1)
378 * relation means nothing.
382 * TRUE - range is shorter or equal to maximum
383 * FALSE - range is larger than maximum
385 static BOOL MONTHCAL_IsSelRangeValid(const MONTHCAL_INFO *infoPtr,
386 const SYSTEMTIME *range0,
387 const SYSTEMTIME *range1,
390 ULARGE_INTEGER ul_range0, ul_range1, ul_diff;
391 FILETIME ft_range0, ft_range1;
394 SystemTimeToFileTime(range0, &ft_range0);
395 SystemTimeToFileTime(range1, &ft_range1);
397 ul_range0.u.LowPart = ft_range0.dwLowDateTime;
398 ul_range0.u.HighPart = ft_range0.dwHighDateTime;
399 ul_range1.u.LowPart = ft_range1.dwLowDateTime;
400 ul_range1.u.HighPart = ft_range1.dwHighDateTime;
402 cmp = CompareFileTime(&ft_range0, &ft_range1);
405 ul_diff.QuadPart = ul_range0.QuadPart - ul_range1.QuadPart;
407 ul_diff.QuadPart = -ul_range0.QuadPart + ul_range1.QuadPart;
409 if(ul_diff.QuadPart >= DAYSTO100NSECS(infoPtr->maxSelCount)) {
413 ul_range0.QuadPart = ul_range1.QuadPart + DAYSTO100NSECS(infoPtr->maxSelCount - 1);
415 ul_range0.QuadPart = ul_range1.QuadPart - DAYSTO100NSECS(infoPtr->maxSelCount - 1);
417 ft_range0.dwLowDateTime = ul_range0.u.LowPart;
418 ft_range0.dwHighDateTime = ul_range0.u.HighPart;
419 FileTimeToSystemTime(&ft_range0, adjust);
427 /* Used in MCM_SETRANGE/MCM_SETSELRANGE to determine resulting time part.
428 Milliseconds are intentionally not validated. */
429 static BOOL MONTHCAL_ValidateTime(const SYSTEMTIME *time)
431 if((time->wHour > 24) || (time->wMinute > 59) || (time->wSecond > 59))
437 /* Note:Depending on DST, this may be offset by a day.
438 Need to find out if we're on a DST place & adjust the clock accordingly.
439 Above function assumes we have a valid data.
440 Valid for year>1752; 1 <= d <= 31, 1 <= m <= 12.
444 /* Returns the day in the week
447 * [i] date : input date
448 * [I] inplace : set calculated value back to date structure
451 * day of week in SYSTEMTIME format: (0 == sunday,..., 6 == saturday)
453 int MONTHCAL_CalculateDayOfWeek(SYSTEMTIME *date, BOOL inplace)
455 SYSTEMTIME st = st_null;
458 MONTHCAL_CopyDate(date, &st);
460 SystemTimeToFileTime(&st, &ft);
461 FileTimeToSystemTime(&ft, &st);
463 if (inplace) date->wDayOfWeek = st.wDayOfWeek;
465 return st.wDayOfWeek;
468 /* add/subtract 'months' from date */
469 static inline void MONTHCAL_GetMonth(SYSTEMTIME *date, INT months)
471 INT length, m = date->wMonth + months;
473 date->wYear += m > 0 ? (m - 1) / 12 : m / 12 - 1;
474 date->wMonth = m > 0 ? (m - 1) % 12 + 1 : 12 + m % 12;
475 /* fix moving from last day in a month */
476 length = MONTHCAL_MonthLength(date->wMonth, date->wYear);
477 if(date->wDay > length) date->wDay = length;
478 MONTHCAL_CalculateDayOfWeek(date, TRUE);
481 /* properly updates date to point on next month */
482 static inline void MONTHCAL_GetNextMonth(SYSTEMTIME *date)
484 return MONTHCAL_GetMonth(date, 1);
487 /* properly updates date to point on prev month */
488 static inline void MONTHCAL_GetPrevMonth(SYSTEMTIME *date)
490 return MONTHCAL_GetMonth(date, -1);
493 /* Returns full date for a first currently visible day */
494 static void MONTHCAL_GetMinDate(const MONTHCAL_INFO *infoPtr, SYSTEMTIME *date)
496 /* zero indexed calendar has the earliest date */
497 SYSTEMTIME st_first = infoPtr->calendars[0].month;
501 firstDay = MONTHCAL_CalculateDayOfWeek(&st_first, FALSE);
503 *date = infoPtr->calendars[0].month;
504 MONTHCAL_GetPrevMonth(date);
506 date->wDay = MONTHCAL_MonthLength(date->wMonth, date->wYear) +
507 (infoPtr->firstDay - firstDay) % 7 + 1;
509 if(date->wDay > MONTHCAL_MonthLength(date->wMonth, date->wYear))
512 /* fix day of week */
513 MONTHCAL_CalculateDayOfWeek(date, TRUE);
516 /* Returns full date for a last currently visible day */
517 static void MONTHCAL_GetMaxDate(const MONTHCAL_INFO *infoPtr, SYSTEMTIME *date)
519 /* the latest date is in latest calendar */
520 SYSTEMTIME st, lt_month = infoPtr->calendars[infoPtr->cal_num-1].month;
523 MONTHCAL_GetNextMonth(date);
525 MONTHCAL_GetMinDate(infoPtr, &st);
526 /* Use month length to get max day. 42 means max day count in calendar area */
527 date->wDay = 42 - (MONTHCAL_MonthLength(st.wMonth, st.wYear) - st.wDay + 1) -
528 MONTHCAL_MonthLength(lt_month.wMonth, lt_month.wYear);
530 /* fix day of week */
531 MONTHCAL_CalculateDayOfWeek(date, TRUE);
534 /* From a given point, calculate the row (weekpos), column(daypos)
535 and day in the calendar. day== 0 mean the last day of tha last month
537 static int MONTHCAL_CalcDayFromPos(const MONTHCAL_INFO *infoPtr, int x, int y,
538 int *daypos, int *weekpos)
540 int retval, firstDay;
542 SYSTEMTIME st = infoPtr->minSel;
544 GetClientRect(infoPtr->hwndSelf, &rcClient);
546 /* if the point is outside the x bounds of the window put
547 it at the boundary */
548 if (x > rcClient.right)
551 *daypos = (x - infoPtr->calendars[0].days.left ) / infoPtr->width_increment;
552 *weekpos = (y - infoPtr->calendars[0].days.top ) / infoPtr->height_increment;
555 firstDay = (MONTHCAL_CalculateDayOfWeek(&st, FALSE) + 6 - infoPtr->firstDay) % 7;
556 retval = *daypos + (7 * *weekpos) - firstDay;
560 /* Sets the RECT struct r to the rectangle around the date
564 * [I] infoPtr : pointer to control data
565 * [I] date : date value
566 * [O] x : day column (zero based)
567 * [O] y : week column (zero based)
569 static void MONTHCAL_CalcDayXY(const MONTHCAL_INFO *infoPtr,
570 const SYSTEMTIME *date, INT *x, INT *y)
572 SYSTEMTIME st = infoPtr->minSel;
577 first = (MONTHCAL_CalculateDayOfWeek(&st, FALSE) + 6 - infoPtr->firstDay) % 7;
579 cmp = MONTHCAL_CompareMonths(date, &infoPtr->minSel);
583 *x = (first - MONTHCAL_MonthLength(date->wMonth, infoPtr->minSel.wYear) + date->wDay) % 7;
588 /* next month calculation is same as for current,
589 just add current month length */
591 first += MONTHCAL_MonthLength(infoPtr->minSel.wMonth, infoPtr->minSel.wYear);
594 *x = (date->wDay + first) % 7;
595 *y = (date->wDay + first - *x) / 7;
599 /* x: column(day), y: row(week) */
600 static inline void MONTHCAL_CalcDayRect(const MONTHCAL_INFO *infoPtr, RECT *r, int x, int y)
602 r->left = infoPtr->calendars[0].days.left + x * infoPtr->width_increment;
603 r->right = r->left + infoPtr->width_increment;
604 r->top = infoPtr->calendars[0].days.top + y * infoPtr->height_increment;
605 r->bottom = r->top + infoPtr->textHeight;
609 /* Sets the RECT struct r to the rectangle around the date */
610 static inline void MONTHCAL_CalcPosFromDay(const MONTHCAL_INFO *infoPtr,
611 const SYSTEMTIME *date, RECT *r)
615 MONTHCAL_CalcDayXY(infoPtr, date, &x, &y);
616 MONTHCAL_CalcDayRect(infoPtr, r, x, y);
619 /* Focused day helper:
621 - set focused date to given value;
622 - reset to zero value if NULL passed;
623 - invalidate previous and new day rectangle only if needed.
625 Returns TRUE if focused day changed, FALSE otherwise.
627 static BOOL MONTHCAL_SetDayFocus(MONTHCAL_INFO *infoPtr, const SYSTEMTIME *st)
633 /* there's nothing to do if it's the same date,
634 mouse move within same date rectangle case */
635 if(MONTHCAL_IsDateEqual(&infoPtr->focusedSel, st)) return FALSE;
637 /* invalidate old focused day */
638 MONTHCAL_CalcPosFromDay(infoPtr, &infoPtr->focusedSel, &r);
639 InvalidateRect(infoPtr->hwndSelf, &r, FALSE);
641 infoPtr->focusedSel = *st;
644 MONTHCAL_CalcPosFromDay(infoPtr, &infoPtr->focusedSel, &r);
646 if(!st && MONTHCAL_ValidateDate(&infoPtr->focusedSel))
647 infoPtr->focusedSel = st_null;
649 /* on set invalidates new day, on reset clears previous focused day */
650 InvalidateRect(infoPtr->hwndSelf, &r, FALSE);
655 /* draw today boundary box for specified rectangle */
656 static void MONTHCAL_Circle(const MONTHCAL_INFO *infoPtr, HDC hdc, const RECT *r)
658 HPEN old_pen = SelectObject(hdc, infoPtr->pens[PenRed]);
661 old_brush = SelectObject(hdc, GetStockObject(NULL_BRUSH));
662 Rectangle(hdc, r->left, r->top, r->right, r->bottom);
664 SelectObject(hdc, old_brush);
665 SelectObject(hdc, old_pen);
668 /* Draw today day mark rectangle
670 * [I] hdc : context to draw in
671 * [I] date : day to mark with rectangle
674 static void MONTHCAL_CircleDay(const MONTHCAL_INFO *infoPtr, HDC hdc,
675 const SYSTEMTIME *date)
678 MONTHCAL_CalcPosFromDay(infoPtr, date, &day_rect);
679 MONTHCAL_Circle(infoPtr, hdc, &day_rect);
682 static void MONTHCAL_DrawDay(const MONTHCAL_INFO *infoPtr, HDC hdc, const SYSTEMTIME *st,
683 int bold, const PAINTSTRUCT *ps)
685 static const WCHAR fmtW[] = { '%','d',0 };
690 INT old_bkmode, selection;
692 /* no need to check styles: when selection is not valid, it is set to zero.
693 1 < day < 31, so everything is OK */
694 MONTHCAL_CalcPosFromDay(infoPtr, st, &r);
695 if(!IntersectRect(&r_temp, &(ps->rcPaint), &r)) return;
697 if ((MONTHCAL_CompareDate(st, &infoPtr->minSel) >= 0) &&
698 (MONTHCAL_CompareDate(st, &infoPtr->maxSel) <= 0))
701 TRACE("%d %d %d\n", st->wDay, infoPtr->minSel.wDay, infoPtr->maxSel.wDay);
702 TRACE("%s\n", wine_dbgstr_rect(&r));
703 oldCol = SetTextColor(hdc, infoPtr->colors[MCSC_MONTHBK]);
704 oldBk = SetBkColor(hdc, infoPtr->colors[MCSC_TRAILINGTEXT]);
705 FillRect(hdc, &r, infoPtr->brushes[BrushTitle]);
712 SelectObject(hdc, bold ? infoPtr->hBoldFont : infoPtr->hFont);
714 old_bkmode = SetBkMode(hdc, TRANSPARENT);
715 wsprintfW(buf, fmtW, st->wDay);
716 DrawTextW(hdc, buf, -1, &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE );
717 SetBkMode(hdc, old_bkmode);
721 SetTextColor(hdc, oldCol);
722 SetBkColor(hdc, oldBk);
727 static void MONTHCAL_PaintButton(MONTHCAL_INFO *infoPtr, HDC hdc, enum nav_direction button)
729 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
730 RECT *r = button == DIRECTION_FORWARD ? &infoPtr->titlebtnnext : &infoPtr->titlebtnprev;
731 BOOL pressed = button == DIRECTION_FORWARD ? infoPtr->status & MC_NEXTPRESSED :
732 infoPtr->status & MC_PREVPRESSED;
735 static const int states[] = {
737 ABS_LEFTNORMAL, ABS_LEFTPRESSED, ABS_LEFTDISABLED,
739 ABS_RIGHTNORMAL, ABS_RIGHTPRESSED, ABS_RIGHTDISABLED
741 int stateNum = button == DIRECTION_FORWARD ? 3 : 0;
746 if (infoPtr->dwStyle & WS_DISABLED) stateNum += 2;
748 DrawThemeBackground (theme, hdc, SBP_ARROWBTN, states[stateNum], r, NULL);
752 int style = button == DIRECTION_FORWARD ? DFCS_SCROLLRIGHT : DFCS_SCROLLLEFT;
754 style |= DFCS_PUSHED;
757 if (infoPtr->dwStyle & WS_DISABLED) style |= DFCS_INACTIVE;
760 DrawFrameControl(hdc, r, DFC_SCROLL, style);
763 /* paint a title with buttons and month/year string */
764 static void MONTHCAL_PaintTitle(MONTHCAL_INFO *infoPtr, HDC hdc, const PAINTSTRUCT *ps, INT calIdx)
766 static const WCHAR fmt_monthW[] = { '%','s',' ','%','l','d',0 };
767 RECT *title = &infoPtr->calendars[calIdx].title;
768 const SYSTEMTIME *st = &infoPtr->calendars[calIdx].month;
769 WCHAR buf_month[80], buf_fmt[80];
772 /* fill header box */
773 FillRect(hdc, title, infoPtr->brushes[BrushTitle]);
775 /* month/year string */
776 SetBkColor(hdc, infoPtr->colors[MCSC_TITLEBK]);
777 SetTextColor(hdc, infoPtr->colors[MCSC_TITLETEXT]);
778 SelectObject(hdc, infoPtr->hBoldFont);
780 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SMONTHNAME1 + st->wMonth - 1,
781 buf_month, countof(buf_month));
783 wsprintfW(buf_fmt, fmt_monthW, buf_month, st->wYear);
784 DrawTextW(hdc, buf_fmt, strlenW(buf_fmt), title,
785 DT_CENTER | DT_VCENTER | DT_SINGLELINE);
787 /* update title rectangles with current month - used while testing hits */
788 GetTextExtentPoint32W(hdc, buf_fmt, strlenW(buf_fmt), &sz);
789 infoPtr->calendars[calIdx].titlemonth.left = title->right / 2 + title->left / 2 - sz.cx / 2;
790 infoPtr->calendars[calIdx].titleyear.right = title->right / 2 + title->left / 2 + sz.cx / 2;
792 GetTextExtentPoint32W(hdc, buf_month, strlenW(buf_month), &sz);
793 infoPtr->calendars[calIdx].titlemonth.right = infoPtr->calendars[calIdx].titlemonth.left + sz.cx;
794 infoPtr->calendars[calIdx].titleyear.left = infoPtr->calendars[calIdx].titlemonth.right;
797 static void MONTHCAL_PaintWeeknumbers(const MONTHCAL_INFO *infoPtr, HDC hdc, const PAINTSTRUCT *ps, INT calIdx)
799 const SYSTEMTIME *date = &infoPtr->calendars[calIdx].month;
800 static const WCHAR fmt_weekW[] = { '%','d',0 };
801 INT mindays, weeknum, weeknum1, startofprescal;
808 if (!(infoPtr->dwStyle & MCS_WEEKNUMBERS)) return;
810 MONTHCAL_GetMinDate(infoPtr, &st);
811 startofprescal = st.wDay;
814 prev_month = date->wMonth - 1;
815 if(prev_month == 0) prev_month = 12;
818 Rules what week to call the first week of a new year:
819 LOCALE_IFIRSTWEEKOFYEAR == 0 (e.g US?):
820 The week containing Jan 1 is the first week of year
821 LOCALE_IFIRSTWEEKOFYEAR == 2 (e.g. Germany):
822 First week of year must contain 4 days of the new year
823 LOCALE_IFIRSTWEEKOFYEAR == 1 (what contries?)
824 The first week of the year must contain only days of the new year
826 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_IFIRSTWEEKOFYEAR, buf, countof(buf));
827 weeknum = atoiW(buf);
837 WARN("Unknown LOCALE_IFIRSTWEEKOFYEAR value %d, defaulting to 0\n", weeknum);
841 if (date->wMonth == 1)
843 /* calculate all those exceptions for january */
844 st.wDay = st.wMonth = 1;
845 weeknum1 = MONTHCAL_CalculateDayOfWeek(&st, FALSE);
846 if ((infoPtr->firstDay - weeknum1) % 7 > mindays)
851 for(i = 0; i < 11; i++)
852 weeknum += MONTHCAL_MonthLength(i+1, date->wYear - 1);
854 weeknum += startofprescal + 7;
857 weeknum1 = MONTHCAL_CalculateDayOfWeek(&st, FALSE);
858 if ((infoPtr->firstDay - weeknum1) % 7 > mindays) weeknum++;
864 for(i = 0; i < prev_month - 1; i++)
865 weeknum += MONTHCAL_MonthLength(i+1, date->wYear);
867 weeknum += startofprescal + 7;
869 st.wDay = st.wMonth = 1;
870 weeknum1 = MONTHCAL_CalculateDayOfWeek(&st, FALSE);
871 if ((infoPtr->firstDay - weeknum1) % 7 > mindays) weeknum++;
874 r = infoPtr->calendars[calIdx].weeknums;
876 /* erase whole week numbers area */
877 FillRect(hdc, &r, infoPtr->brushes[BrushTitle]);
878 SetTextColor(hdc, infoPtr->colors[MCSC_TITLEBK]);
880 /* reduce rectangle to one week number */
881 r.bottom = r.top + infoPtr->height_increment;
883 for(i = 0; i < 6; i++) {
884 if((i == 0) && (weeknum > 50))
886 wsprintfW(buf, fmt_weekW, weeknum);
889 else if((i == 5) && (weeknum > 47))
891 wsprintfW(buf, fmt_weekW, 1);
894 wsprintfW(buf, fmt_weekW, weeknum + i);
896 DrawTextW(hdc, buf, -1, &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
897 OffsetRect(&r, 0, infoPtr->height_increment);
900 /* line separator for week numbers column */
901 old_pen = SelectObject(hdc, infoPtr->pens[PenText]);
902 MoveToEx(hdc, infoPtr->calendars[calIdx].weeknums.right, infoPtr->calendars[calIdx].weeknums.top + 3 , NULL);
903 LineTo(hdc, infoPtr->calendars[calIdx].weeknums.right, infoPtr->calendars[calIdx].weeknums.bottom);
904 SelectObject(hdc, old_pen);
907 /* bottom today date */
908 static void MONTHCAL_PaintTodayTitle(const MONTHCAL_INFO *infoPtr, HDC hdc, const PAINTSTRUCT *ps)
910 static const WCHAR fmt_todayW[] = { '%','s',' ','%','s',0 };
911 WCHAR buf_todayW[30], buf_dateW[20], buf[80];
912 RECT text_rect, box_rect;
916 if(infoPtr->dwStyle & MCS_NOTODAY) return;
918 if (!LoadStringW(COMCTL32_hModule, IDM_TODAY, buf_todayW, countof(buf_todayW)))
920 static const WCHAR todayW[] = { 'T','o','d','a','y',':',0 };
921 WARN("Can't load resource\n");
922 strcpyW(buf_todayW, todayW);
925 col = infoPtr->dwStyle & MCS_NOTODAYCIRCLE ? 0 : 1;
926 if (infoPtr->dwStyle & MCS_WEEKNUMBERS) col--;
927 MONTHCAL_CalcDayRect(infoPtr, &text_rect, col, 6);
928 box_rect = text_rect;
930 GetDateFormatW(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &infoPtr->todaysDate, NULL,
931 buf_dateW, countof(buf_dateW));
932 old_font = SelectObject(hdc, infoPtr->hBoldFont);
933 SetTextColor(hdc, infoPtr->colors[MCSC_TEXT]);
935 wsprintfW(buf, fmt_todayW, buf_todayW, buf_dateW);
936 DrawTextW(hdc, buf, -1, &text_rect, DT_CALCRECT | DT_LEFT | DT_VCENTER | DT_SINGLELINE);
937 DrawTextW(hdc, buf, -1, &text_rect, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
939 if(!(infoPtr->dwStyle & MCS_NOTODAYCIRCLE)) {
940 OffsetRect(&box_rect, -infoPtr->width_increment, 0);
941 MONTHCAL_Circle(infoPtr, hdc, &box_rect);
944 SelectObject(hdc, old_font);
947 /* today mark + focus */
948 static void MONTHCAL_PaintFocusAndCircle(const MONTHCAL_INFO *infoPtr, HDC hdc, const PAINTSTRUCT *ps)
950 if((infoPtr->minSel.wMonth == infoPtr->todaysDate.wMonth) &&
951 (infoPtr->minSel.wYear == infoPtr->todaysDate.wYear) &&
952 !(infoPtr->dwStyle & MCS_NOTODAYCIRCLE))
954 MONTHCAL_CircleDay(infoPtr, hdc, &infoPtr->todaysDate);
957 if(!MONTHCAL_IsDateEqual(&infoPtr->focusedSel, &st_null))
960 MONTHCAL_CalcPosFromDay(infoPtr, &infoPtr->focusedSel, &r);
961 DrawFocusRect(hdc, &r);
965 /* months before first calendar month and after last calendar month */
966 static void MONTHCAL_PaintLeadTrailMonths(const MONTHCAL_INFO *infoPtr, HDC hdc, const PAINTSTRUCT *ps)
969 SYSTEMTIME st_max, st;
971 if (infoPtr->dwStyle & MCS_NOTRAILINGDATES) return;
973 SetTextColor(hdc, infoPtr->colors[MCSC_TRAILINGTEXT]);
975 /* draw prev month */
976 MONTHCAL_GetMinDate(infoPtr, &st);
977 mask = 1 << (st.wDay-1);
978 /* December and January both 31 days long, so no worries if wrapped */
979 length = MONTHCAL_MonthLength(infoPtr->calendars[0].month.wMonth - 1,
980 infoPtr->calendars[0].month.wYear);
981 while(st.wDay <= length)
983 MONTHCAL_DrawDay(infoPtr, hdc, &st, infoPtr->monthdayState[0] & mask, ps);
988 /* draw next month */
989 st = infoPtr->calendars[infoPtr->cal_num-1].month;
991 MONTHCAL_GetNextMonth(&st);
992 MONTHCAL_GetMaxDate(infoPtr, &st_max);
995 while(st.wDay <= st_max.wDay)
997 MONTHCAL_DrawDay(infoPtr, hdc, &st, infoPtr->monthdayState[2] & mask, ps);
1003 /* paint a calendar area */
1004 static void MONTHCAL_PaintCalendar(const MONTHCAL_INFO *infoPtr, HDC hdc, const PAINTSTRUCT *ps, INT calIdx)
1006 const SYSTEMTIME *date = &infoPtr->calendars[calIdx].month;
1007 INT prev_month, i, j, length;
1008 RECT r, fill_bk_rect;
1014 /* fill whole days area - from week days area to today note rectangle */
1015 fill_bk_rect = infoPtr->calendars[calIdx].wdays;
1016 fill_bk_rect.bottom = infoPtr->calendars[calIdx].days.bottom +
1017 (infoPtr->todayrect.bottom - infoPtr->todayrect.top);
1019 FillRect(hdc, &fill_bk_rect, infoPtr->brushes[BrushMonth]);
1021 /* draw line under day abbreviations */
1022 old_pen = SelectObject(hdc, infoPtr->pens[PenText]);
1023 MoveToEx(hdc, infoPtr->calendars[calIdx].days.left + 3,
1024 infoPtr->calendars[calIdx].title.bottom + infoPtr->textHeight + 1, NULL);
1025 LineTo(hdc, infoPtr->calendars[calIdx].days.right - 3,
1026 infoPtr->calendars[calIdx].title.bottom + infoPtr->textHeight + 1);
1027 SelectObject(hdc, old_pen);
1029 prev_month = date->wMonth - 1;
1030 if (prev_month == 0) prev_month = 12;
1032 infoPtr->calendars[calIdx].wdays.left = infoPtr->calendars[calIdx].days.left =
1033 infoPtr->calendars[calIdx].weeknums.right;
1035 /* draw day abbreviations */
1036 SelectObject(hdc, infoPtr->hFont);
1037 SetBkColor(hdc, infoPtr->colors[MCSC_MONTHBK]);
1038 SetTextColor(hdc, infoPtr->colors[MCSC_TITLEBK]);
1039 /* rectangle to draw a single day abbreviation within */
1040 r = infoPtr->calendars[calIdx].wdays;
1041 r.right = r.left + infoPtr->width_increment;
1043 i = infoPtr->firstDay;
1044 for(j = 0; j < 7; j++) {
1045 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SABBREVDAYNAME1 + (i+j+6)%7, buf, countof(buf));
1046 DrawTextW(hdc, buf, strlenW(buf), &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
1047 OffsetRect(&r, infoPtr->width_increment, 0);
1050 /* draw current month */
1051 SetTextColor(hdc, infoPtr->colors[MCSC_TEXT]);
1055 length = MONTHCAL_MonthLength(date->wMonth, date->wYear);
1056 while(st.wDay <= length)
1058 MONTHCAL_DrawDay(infoPtr, hdc, &st, infoPtr->monthdayState[1] & mask, ps);
1064 static void MONTHCAL_Refresh(MONTHCAL_INFO *infoPtr, HDC hdc, const PAINTSTRUCT *ps)
1066 COLORREF old_text_clr, old_bk_clr;
1070 old_text_clr = SetTextColor(hdc, comctl32_color.clrWindowText);
1071 old_bk_clr = GetBkColor(hdc);
1072 old_font = GetCurrentObject(hdc, OBJ_FONT);
1074 for (i = 0; i < infoPtr->cal_num; i++)
1076 RECT *title = &infoPtr->calendars[i].title;
1079 /* draw title, redraw all its elements */
1080 if (IntersectRect(&r, &(ps->rcPaint), title))
1081 MONTHCAL_PaintTitle(infoPtr, hdc, ps, i);
1083 /* draw calendar area */
1084 UnionRect(&r, &infoPtr->calendars[i].wdays, &infoPtr->todayrect);
1085 if (IntersectRect(&r, &(ps->rcPaint), &r))
1086 MONTHCAL_PaintCalendar(infoPtr, hdc, ps, i);
1089 MONTHCAL_PaintWeeknumbers(infoPtr, hdc, ps, i);
1092 /* partially visible months */
1093 MONTHCAL_PaintLeadTrailMonths(infoPtr, hdc, ps);
1095 /* focus and today rectangle */
1096 MONTHCAL_PaintFocusAndCircle(infoPtr, hdc, ps);
1098 /* today at the bottom left */
1099 MONTHCAL_PaintTodayTitle(infoPtr, hdc, ps);
1101 /* navigation buttons */
1102 MONTHCAL_PaintButton(infoPtr, hdc, DIRECTION_BACKWARD);
1103 MONTHCAL_PaintButton(infoPtr, hdc, DIRECTION_FORWARD);
1105 /* restore context */
1106 SetBkColor(hdc, old_bk_clr);
1107 SelectObject(hdc, old_font);
1108 SetTextColor(hdc, old_text_clr);
1112 MONTHCAL_GetMinReqRect(const MONTHCAL_INFO *infoPtr, RECT *rect)
1114 TRACE("rect %p\n", rect);
1116 if(!rect) return FALSE;
1118 *rect = infoPtr->calendars[0].title;
1119 rect->bottom = infoPtr->calendars[0].days.bottom + infoPtr->todayrect.bottom -
1120 infoPtr->todayrect.top;
1122 AdjustWindowRect(rect, infoPtr->dwStyle, FALSE);
1124 /* minimal rectangle is zero based */
1125 OffsetRect(rect, -rect->left, -rect->top);
1127 TRACE("%s\n", wine_dbgstr_rect(rect));
1133 MONTHCAL_GetColor(const MONTHCAL_INFO *infoPtr, UINT index)
1135 TRACE("%p, %d\n", infoPtr, index);
1137 if (index > MCSC_TRAILINGTEXT) return -1;
1138 return infoPtr->colors[index];
1142 MONTHCAL_SetColor(MONTHCAL_INFO *infoPtr, UINT index, COLORREF color)
1144 enum CachedBrush type;
1147 TRACE("%p, %d: color %08x\n", infoPtr, index, color);
1149 if (index > MCSC_TRAILINGTEXT) return -1;
1151 prev = infoPtr->colors[index];
1152 infoPtr->colors[index] = color;
1154 /* update cached brush */
1157 case MCSC_BACKGROUND:
1158 type = BrushBackground;
1170 if (type != BrushLast)
1172 DeleteObject(infoPtr->brushes[type]);
1173 infoPtr->brushes[type] = CreateSolidBrush(color);
1176 /* update cached pen */
1177 if (index == MCSC_TEXT)
1179 DeleteObject(infoPtr->pens[PenText]);
1180 infoPtr->pens[PenText] = CreatePen(PS_SOLID, 1, infoPtr->colors[index]);
1183 InvalidateRect(infoPtr->hwndSelf, NULL, index == MCSC_BACKGROUND ? TRUE : FALSE);
1188 MONTHCAL_GetMonthDelta(const MONTHCAL_INFO *infoPtr)
1193 return infoPtr->delta;
1195 return infoPtr->visible;
1200 MONTHCAL_SetMonthDelta(MONTHCAL_INFO *infoPtr, INT delta)
1202 INT prev = infoPtr->delta;
1204 TRACE("delta %d\n", delta);
1206 infoPtr->delta = delta;
1211 static inline LRESULT
1212 MONTHCAL_GetFirstDayOfWeek(const MONTHCAL_INFO *infoPtr)
1216 /* convert from SYSTEMTIME to locale format */
1217 day = (infoPtr->firstDay >= 0) ? (infoPtr->firstDay+6)%7 : infoPtr->firstDay;
1219 return MAKELONG(day, infoPtr->firstDaySet);
1223 /* Sets the first day of the week that will appear in the control
1227 * [I] infoPtr : valid pointer to control data
1228 * [I] day : day number to set as new first day (0 == Monday,...,6 == Sunday)
1232 * Low word contains previous first day,
1233 * high word indicates was first day forced with this message before or is
1234 * locale difined (TRUE - was forced, FALSE - wasn't).
1236 * FIXME: this needs to be implemented properly in MONTHCAL_Refresh()
1237 * FIXME: we need more error checking here
1240 MONTHCAL_SetFirstDayOfWeek(MONTHCAL_INFO *infoPtr, INT day)
1242 LRESULT prev = MONTHCAL_GetFirstDayOfWeek(infoPtr);
1251 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_IFIRSTDAYOFWEEK, buf, countof(buf));
1252 TRACE("%s %d\n", debugstr_w(buf), strlenW(buf));
1254 new_day = atoiW(buf);
1256 infoPtr->firstDaySet = FALSE;
1260 new_day = 6; /* max first day allowed */
1261 infoPtr->firstDaySet = TRUE;
1265 /* Native behaviour for that case is broken: invalid date number >31
1266 got displayed at (0,0) position, current month starts always from
1267 (1,0) position. Should be implemented here as well only if there's
1268 nothing else to do. */
1270 FIXME("No bug compatibility for day=%d\n", day);
1273 infoPtr->firstDaySet = TRUE;
1276 /* convert from locale to SYSTEMTIME format */
1277 infoPtr->firstDay = (new_day >= 0) ? (++new_day) % 7 : new_day;
1279 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1286 MONTHCAL_GetMonthRange(const MONTHCAL_INFO *infoPtr, DWORD flag, SYSTEMTIME *st)
1288 TRACE("flag=%d, st=%p\n", flag, st);
1295 st[0] = infoPtr->calendars[0].month;
1296 st[1] = infoPtr->calendars[infoPtr->cal_num-1].month;
1298 if (st[0].wMonth == min_allowed_date.wMonth &&
1299 st[0].wYear == min_allowed_date.wYear)
1301 st[0].wDay = min_allowed_date.wDay;
1305 MONTHCAL_CalculateDayOfWeek(&st[0], TRUE);
1307 st[1].wDay = MONTHCAL_MonthLength(st[1].wMonth, st[1].wYear);
1308 MONTHCAL_CalculateDayOfWeek(&st[1], TRUE);
1310 return infoPtr->cal_num;
1314 MONTHCAL_GetMinDate(infoPtr, &st[0]);
1315 MONTHCAL_GetMaxDate(infoPtr, &st[1]);
1319 WARN("Unknown flag value, got %d\n", flag);
1323 return infoPtr->monthRange;
1328 MONTHCAL_GetMaxTodayWidth(const MONTHCAL_INFO *infoPtr)
1330 return(infoPtr->todayrect.right - infoPtr->todayrect.left);
1335 MONTHCAL_SetRange(MONTHCAL_INFO *infoPtr, SHORT limits, SYSTEMTIME *range)
1337 FILETIME ft_min, ft_max;
1339 TRACE("%x %p\n", limits, range);
1341 if ((limits & GDTR_MIN && !MONTHCAL_ValidateDate(&range[0])) ||
1342 (limits & GDTR_MAX && !MONTHCAL_ValidateDate(&range[1])))
1345 if (limits & GDTR_MIN)
1347 if (!MONTHCAL_ValidateTime(&range[0]))
1348 MONTHCAL_CopyTime(&infoPtr->todaysDate, &range[0]);
1350 infoPtr->minDate = range[0];
1351 infoPtr->rangeValid |= GDTR_MIN;
1353 if (limits & GDTR_MAX)
1355 if (!MONTHCAL_ValidateTime(&range[1]))
1356 MONTHCAL_CopyTime(&infoPtr->todaysDate, &range[1]);
1358 infoPtr->maxDate = range[1];
1359 infoPtr->rangeValid |= GDTR_MAX;
1362 /* Only one limit set - we are done */
1363 if ((infoPtr->rangeValid & (GDTR_MIN | GDTR_MAX)) != (GDTR_MIN | GDTR_MAX))
1366 SystemTimeToFileTime(&infoPtr->maxDate, &ft_max);
1367 SystemTimeToFileTime(&infoPtr->minDate, &ft_min);
1369 if (CompareFileTime(&ft_min, &ft_max) >= 0)
1371 if ((limits & (GDTR_MIN | GDTR_MAX)) == (GDTR_MIN | GDTR_MAX))
1373 /* Native swaps limits only when both limits are being set. */
1374 SYSTEMTIME st_tmp = infoPtr->minDate;
1375 infoPtr->minDate = infoPtr->maxDate;
1376 infoPtr->maxDate = st_tmp;
1380 /* reset the other limit */
1381 if (limits & GDTR_MIN) infoPtr->maxDate = st_null;
1382 if (limits & GDTR_MAX) infoPtr->minDate = st_null;
1383 infoPtr->rangeValid &= limits & GDTR_MIN ? ~GDTR_MAX : ~GDTR_MIN;
1392 MONTHCAL_GetRange(const MONTHCAL_INFO *infoPtr, SYSTEMTIME *range)
1394 TRACE("%p\n", range);
1396 if(!range) return FALSE;
1398 range[1] = infoPtr->maxDate;
1399 range[0] = infoPtr->minDate;
1401 return infoPtr->rangeValid;
1406 MONTHCAL_SetDayState(const MONTHCAL_INFO *infoPtr, INT months, MONTHDAYSTATE *states)
1408 TRACE("%p %d %p\n", infoPtr, months, states);
1409 if(months != infoPtr->monthRange) return 0;
1411 memcpy(infoPtr->monthdayState, states, months*sizeof(MONTHDAYSTATE));
1417 MONTHCAL_GetCurSel(const MONTHCAL_INFO *infoPtr, SYSTEMTIME *curSel)
1419 TRACE("%p\n", curSel);
1420 if(!curSel) return FALSE;
1421 if(infoPtr->dwStyle & MCS_MULTISELECT) return FALSE;
1423 *curSel = infoPtr->minSel;
1424 TRACE("%d/%d/%d\n", curSel->wYear, curSel->wMonth, curSel->wDay);
1429 MONTHCAL_SetCurSel(MONTHCAL_INFO *infoPtr, SYSTEMTIME *curSel)
1431 SYSTEMTIME prev = infoPtr->minSel;
1434 TRACE("%p\n", curSel);
1435 if(!curSel) return FALSE;
1436 if(infoPtr->dwStyle & MCS_MULTISELECT) return FALSE;
1438 if(!MONTHCAL_ValidateDate(curSel)) return FALSE;
1439 /* exit earlier if selection equals current */
1440 if (MONTHCAL_IsDateEqual(&infoPtr->minSel, curSel)) return TRUE;
1442 if(!MONTHCAL_IsDateInValidRange(infoPtr, curSel, FALSE)) return FALSE;
1444 infoPtr->calendars[0].month = *curSel;
1445 infoPtr->minSel = *curSel;
1446 infoPtr->maxSel = *curSel;
1448 /* if selection is still in current month, reduce rectangle */
1450 prev.wDay = curSel->wDay;
1451 if (MONTHCAL_IsDateEqual(&prev, curSel))
1456 MONTHCAL_CalcPosFromDay(infoPtr, &prev, &r_prev);
1457 MONTHCAL_CalcPosFromDay(infoPtr, curSel, &r_new);
1459 InvalidateRect(infoPtr->hwndSelf, &r_prev, FALSE);
1460 InvalidateRect(infoPtr->hwndSelf, &r_new, FALSE);
1463 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1470 MONTHCAL_GetMaxSelCount(const MONTHCAL_INFO *infoPtr)
1472 return infoPtr->maxSelCount;
1477 MONTHCAL_SetMaxSelCount(MONTHCAL_INFO *infoPtr, INT max)
1481 if(!(infoPtr->dwStyle & MCS_MULTISELECT)) return FALSE;
1482 if(max <= 0) return FALSE;
1484 infoPtr->maxSelCount = max;
1491 MONTHCAL_GetSelRange(const MONTHCAL_INFO *infoPtr, SYSTEMTIME *range)
1493 TRACE("%p\n", range);
1495 if(!range) return FALSE;
1497 if(infoPtr->dwStyle & MCS_MULTISELECT)
1499 range[1] = infoPtr->maxSel;
1500 range[0] = infoPtr->minSel;
1501 TRACE("[min,max]=[%d %d]\n", infoPtr->minSel.wDay, infoPtr->maxSel.wDay);
1510 MONTHCAL_SetSelRange(MONTHCAL_INFO *infoPtr, SYSTEMTIME *range)
1512 TRACE("%p\n", range);
1514 if(!range) return FALSE;
1516 if(infoPtr->dwStyle & MCS_MULTISELECT)
1518 SYSTEMTIME old_range[2];
1520 /* adjust timestamps */
1521 if(!MONTHCAL_ValidateTime(&range[0]))
1522 MONTHCAL_CopyTime(&infoPtr->todaysDate, &range[0]);
1523 if(!MONTHCAL_ValidateTime(&range[1]))
1524 MONTHCAL_CopyTime(&infoPtr->todaysDate, &range[1]);
1526 /* maximum range exceeded */
1527 if(!MONTHCAL_IsSelRangeValid(infoPtr, &range[0], &range[1], NULL)) return FALSE;
1529 old_range[0] = infoPtr->minSel;
1530 old_range[1] = infoPtr->maxSel;
1532 /* swap if min > max */
1533 if(MONTHCAL_CompareSystemTime(&range[0], &range[1]) <= 0)
1535 infoPtr->minSel = range[0];
1536 infoPtr->maxSel = range[1];
1540 infoPtr->minSel = range[1];
1541 infoPtr->maxSel = range[0];
1543 infoPtr->calendars[0].month = infoPtr->minSel;
1545 /* update day of week */
1546 MONTHCAL_CalculateDayOfWeek(&infoPtr->minSel, TRUE);
1547 MONTHCAL_CalculateDayOfWeek(&infoPtr->maxSel, TRUE);
1549 /* redraw if bounds changed */
1550 /* FIXME: no actual need to redraw everything */
1551 if(!MONTHCAL_IsDateEqual(&old_range[0], &range[0]) ||
1552 !MONTHCAL_IsDateEqual(&old_range[1], &range[1]))
1554 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1557 TRACE("[min,max]=[%d %d]\n", infoPtr->minSel.wDay, infoPtr->maxSel.wDay);
1566 MONTHCAL_GetToday(const MONTHCAL_INFO *infoPtr, SYSTEMTIME *today)
1568 TRACE("%p\n", today);
1570 if(!today) return FALSE;
1571 *today = infoPtr->todaysDate;
1575 /* Internal helper for MCM_SETTODAY handler and auto update timer handler
1579 * TRUE - today date changed
1580 * FALSE - today date isn't changed
1583 MONTHCAL_UpdateToday(MONTHCAL_INFO *infoPtr, const SYSTEMTIME *today)
1587 if(MONTHCAL_IsDateEqual(today, &infoPtr->todaysDate)) return FALSE;
1589 MONTHCAL_CalcPosFromDay(infoPtr, &infoPtr->todaysDate, &old_r);
1590 MONTHCAL_CalcPosFromDay(infoPtr, today, &new_r);
1592 infoPtr->todaysDate = *today;
1594 /* only two days need redrawing */
1595 InvalidateRect(infoPtr->hwndSelf, &old_r, FALSE);
1596 InvalidateRect(infoPtr->hwndSelf, &new_r, FALSE);
1600 /* MCM_SETTODAT handler */
1602 MONTHCAL_SetToday(MONTHCAL_INFO *infoPtr, const SYSTEMTIME *today)
1604 TRACE("%p\n", today);
1606 if(!today) return FALSE;
1608 /* remember if date was set successfully */
1609 if(MONTHCAL_UpdateToday(infoPtr, today)) infoPtr->todaySet = TRUE;
1614 /* returns calendar index containing specified point, or -1 if it's background */
1615 static INT MONTHCAL_GetCalendarFromPoint(const MONTHCAL_INFO *infoPtr, const POINT *pt)
1620 for (i = 0; i < infoPtr->cal_num; i++)
1622 /* whole bounding rectangle allows some optimization to compute */
1623 r.left = infoPtr->calendars[i].title.left;
1624 r.top = infoPtr->calendars[i].title.top;
1625 r.bottom = infoPtr->calendars[i].days.bottom;
1626 r.right = infoPtr->calendars[i].days.right;
1628 if (PtInRect(&r, *pt)) return i;
1634 static inline UINT fill_hittest_info(const MCHITTESTINFO *src, MCHITTESTINFO *dest)
1636 dest->uHit = src->uHit;
1639 if (dest->cbSize == sizeof(MCHITTESTINFO))
1640 memcpy(&dest->rc, &src->rc, sizeof(MCHITTESTINFO) - MCHITTESTINFO_V1_SIZE);
1646 MONTHCAL_HitTest(const MONTHCAL_INFO *infoPtr, MCHITTESTINFO *lpht)
1648 INT day, wday, wnum, calIdx;
1649 MCHITTESTINFO htinfo;
1650 SYSTEMTIME ht_month;
1653 if(!lpht || lpht->cbSize < MCHITTESTINFO_V1_SIZE) return -1;
1658 htinfo.st = st_null;
1660 /* we should preserve passed fields if hit area doesn't need them */
1661 if (lpht->cbSize == sizeof(MCHITTESTINFO))
1662 memcpy(&htinfo.rc, &lpht->rc, sizeof(MCHITTESTINFO) - MCHITTESTINFO_V1_SIZE);
1664 /* Comment in for debugging...
1665 TRACE("%d %d wd[%d %d %d %d] d[%d %d %d %d] t[%d %d %d %d] wn[%d %d %d %d]\n", x, y,
1666 infoPtr->wdays.left, infoPtr->wdays.right,
1667 infoPtr->wdays.top, infoPtr->wdays.bottom,
1668 infoPtr->days.left, infoPtr->days.right,
1669 infoPtr->days.top, infoPtr->days.bottom,
1670 infoPtr->todayrect.left, infoPtr->todayrect.right,
1671 infoPtr->todayrect.top, infoPtr->todayrect.bottom,
1672 infoPtr->weeknums.left, infoPtr->weeknums.right,
1673 infoPtr->weeknums.top, infoPtr->weeknums.bottom);
1676 /* guess in what calendar we are */
1677 calIdx = MONTHCAL_GetCalendarFromPoint(infoPtr, &lpht->pt);
1680 if (PtInRect(&infoPtr->todayrect, lpht->pt))
1682 htinfo.uHit = MCHT_TODAYLINK;
1683 htinfo.rc = infoPtr->todayrect;
1686 /* outside of calendar area? What's left must be background :-) */
1687 htinfo.uHit = MCHT_CALENDARBK;
1689 return fill_hittest_info(&htinfo, lpht);
1692 ht_month = infoPtr->calendars[calIdx].month;
1694 /* are we in the header? */
1695 if (PtInRect(&infoPtr->calendars[calIdx].title, lpht->pt)) {
1696 /* FIXME: buttons hittesting could be optimized cause maximum
1697 two calendars have buttons */
1698 if (calIdx == 0 && PtInRect(&infoPtr->titlebtnprev, lpht->pt))
1700 htinfo.uHit = MCHT_TITLEBTNPREV;
1701 htinfo.rc = infoPtr->titlebtnprev;
1703 else if (PtInRect(&infoPtr->titlebtnnext, lpht->pt))
1705 htinfo.uHit = MCHT_TITLEBTNNEXT;
1706 htinfo.rc = infoPtr->titlebtnnext;
1708 else if (PtInRect(&infoPtr->calendars[calIdx].titlemonth, lpht->pt))
1710 htinfo.uHit = MCHT_TITLEMONTH;
1711 htinfo.rc = infoPtr->calendars[calIdx].titlemonth;
1712 htinfo.iOffset = calIdx;
1714 else if (PtInRect(&infoPtr->calendars[calIdx].titleyear, lpht->pt))
1716 htinfo.uHit = MCHT_TITLEYEAR;
1717 htinfo.rc = infoPtr->calendars[calIdx].titleyear;
1718 htinfo.iOffset = calIdx;
1722 htinfo.uHit = MCHT_TITLE;
1723 htinfo.rc = infoPtr->calendars[calIdx].title;
1724 htinfo.iOffset = calIdx;
1727 return fill_hittest_info(&htinfo, lpht);
1730 /* days area (including week days and week numbers */
1731 day = MONTHCAL_CalcDayFromPos(infoPtr, x, y, &wday, &wnum);
1732 if (PtInRect(&infoPtr->calendars[calIdx].wdays, lpht->pt))
1734 htinfo.uHit = MCHT_CALENDARDAY;
1735 htinfo.iOffset = calIdx;
1736 htinfo.st.wYear = ht_month.wYear;
1737 htinfo.st.wMonth = (day < 1) ? ht_month.wMonth -1 : ht_month.wMonth;
1738 htinfo.st.wDay = (day < 1) ?
1739 MONTHCAL_MonthLength(ht_month.wMonth-1, ht_month.wYear) - day : day;
1741 MONTHCAL_CalcDayXY(infoPtr, &htinfo.st, &htinfo.iCol, &htinfo.iRow);
1743 else if(PtInRect(&infoPtr->calendars[calIdx].weeknums, lpht->pt))
1745 htinfo.uHit = MCHT_CALENDARWEEKNUM;
1746 htinfo.st.wYear = ht_month.wYear;
1747 htinfo.iOffset = calIdx;
1751 htinfo.st.wMonth = ht_month.wMonth - 1;
1752 htinfo.st.wDay = MONTHCAL_MonthLength(ht_month.wMonth-1, ht_month.wYear) - day;
1754 else if (day > MONTHCAL_MonthLength(ht_month.wMonth, ht_month.wYear))
1756 htinfo.st.wMonth = ht_month.wMonth + 1;
1757 htinfo.st.wDay = day - MONTHCAL_MonthLength(ht_month.wMonth, ht_month.wYear);
1761 htinfo.st.wMonth = ht_month.wMonth;
1762 htinfo.st.wDay = day;
1765 else if(PtInRect(&infoPtr->calendars[calIdx].days, lpht->pt))
1767 htinfo.iOffset = calIdx;
1768 htinfo.st.wYear = ht_month.wYear;
1769 htinfo.st.wMonth = ht_month.wMonth;
1772 htinfo.uHit = MCHT_CALENDARDATEPREV;
1773 MONTHCAL_GetPrevMonth(&htinfo.st);
1774 htinfo.st.wDay = MONTHCAL_MonthLength(htinfo.st.wMonth, htinfo.st.wYear) + day;
1776 else if (day > MONTHCAL_MonthLength(ht_month.wMonth, ht_month.wYear))
1778 htinfo.uHit = MCHT_CALENDARDATENEXT;
1779 MONTHCAL_GetNextMonth(&htinfo.st);
1780 htinfo.st.wDay = day - MONTHCAL_MonthLength(ht_month.wMonth, ht_month.wYear);
1784 htinfo.uHit = MCHT_CALENDARDATE;
1785 htinfo.st.wDay = day;
1788 MONTHCAL_CalcDayXY(infoPtr, &htinfo.st, &htinfo.iCol, &htinfo.iRow);
1789 MONTHCAL_CalcDayRect(infoPtr, &htinfo.rc, htinfo.iCol, htinfo.iRow);
1790 /* always update day of week */
1791 MONTHCAL_CalculateDayOfWeek(&htinfo.st, TRUE);
1794 return fill_hittest_info(&htinfo, lpht);
1797 /* MCN_GETDAYSTATE notification helper */
1798 static void MONTHCAL_NotifyDayState(MONTHCAL_INFO *infoPtr)
1800 if(infoPtr->dwStyle & MCS_DAYSTATE) {
1803 nmds.nmhdr.hwndFrom = infoPtr->hwndSelf;
1804 nmds.nmhdr.idFrom = GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_ID);
1805 nmds.nmhdr.code = MCN_GETDAYSTATE;
1806 nmds.cDayState = infoPtr->monthRange;
1807 nmds.prgDayState = Alloc(infoPtr->monthRange * sizeof(MONTHDAYSTATE));
1809 nmds.stStart = infoPtr->todaysDate;
1810 nmds.stStart.wYear = infoPtr->minSel.wYear;
1811 nmds.stStart.wMonth = infoPtr->minSel.wMonth;
1812 nmds.stStart.wDay = 1;
1814 SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, nmds.nmhdr.idFrom, (LPARAM)&nmds);
1815 memcpy(infoPtr->monthdayState, nmds.prgDayState, infoPtr->monthRange*sizeof(MONTHDAYSTATE));
1817 Free(nmds.prgDayState);
1821 /* no valid range check performed */
1822 static void MONTHCAL_Scroll(MONTHCAL_INFO *infoPtr, INT delta)
1826 for(i = 0; i < infoPtr->cal_num; i++)
1828 /* save selection position to shift it later */
1829 if (selIdx == -1 && MONTHCAL_CompareMonths(&infoPtr->minSel, &infoPtr->calendars[i].month) == 0)
1832 MONTHCAL_GetMonth(&infoPtr->calendars[i].month, delta);
1835 /* selection is always shifted to first calendar */
1836 if(infoPtr->dwStyle & MCS_MULTISELECT)
1838 SYSTEMTIME range[2];
1840 MONTHCAL_GetSelRange(infoPtr, range);
1841 MONTHCAL_GetMonth(&range[0], delta - selIdx);
1842 MONTHCAL_GetMonth(&range[1], delta - selIdx);
1843 MONTHCAL_SetSelRange(infoPtr, range);
1847 SYSTEMTIME st = infoPtr->minSel;
1849 MONTHCAL_GetMonth(&st, delta - selIdx);
1850 MONTHCAL_SetCurSel(infoPtr, &st);
1854 static void MONTHCAL_GoToMonth(MONTHCAL_INFO *infoPtr, enum nav_direction direction)
1856 INT delta = infoPtr->delta ? infoPtr->delta : infoPtr->cal_num;
1859 TRACE("%s\n", direction == DIRECTION_BACKWARD ? "back" : "fwd");
1861 /* check if change allowed by range set */
1862 if(direction == DIRECTION_BACKWARD)
1864 st = infoPtr->calendars[0].month;
1865 MONTHCAL_GetMonth(&st, -delta);
1869 st = infoPtr->calendars[infoPtr->cal_num-1].month;
1870 MONTHCAL_GetMonth(&st, delta);
1873 if(!MONTHCAL_IsDateInValidRange(infoPtr, &st, FALSE)) return;
1875 MONTHCAL_Scroll(infoPtr, direction == DIRECTION_BACKWARD ? -delta : delta);
1876 MONTHCAL_NotifyDayState(infoPtr);
1877 MONTHCAL_NotifySelectionChange(infoPtr);
1881 MONTHCAL_RButtonUp(MONTHCAL_INFO *infoPtr, LPARAM lParam)
1883 static const WCHAR todayW[] = { 'G','o',' ','t','o',' ','T','o','d','a','y',':',0 };
1888 hMenu = CreatePopupMenu();
1889 if (!LoadStringW(COMCTL32_hModule, IDM_GOTODAY, buf, countof(buf)))
1891 WARN("Can't load resource\n");
1892 strcpyW(buf, todayW);
1894 AppendMenuW(hMenu, MF_STRING|MF_ENABLED, 1, buf);
1895 menupoint.x = (short)LOWORD(lParam);
1896 menupoint.y = (short)HIWORD(lParam);
1897 ClientToScreen(infoPtr->hwndSelf, &menupoint);
1898 if( TrackPopupMenu(hMenu, TPM_RIGHTBUTTON | TPM_NONOTIFY | TPM_RETURNCMD,
1899 menupoint.x, menupoint.y, 0, infoPtr->hwndSelf, NULL))
1901 infoPtr->calendars[0].month = infoPtr->todaysDate;
1902 infoPtr->minSel = infoPtr->todaysDate;
1903 infoPtr->maxSel = infoPtr->todaysDate;
1904 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1912 * Subclassed edit control windproc function
1915 * [I] hwnd : the edit window handle
1916 * [I] uMsg : the message that is to be processed
1917 * [I] wParam : first message parameter
1918 * [I] lParam : second message parameter
1921 static LRESULT CALLBACK EditWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1923 MONTHCAL_INFO *infoPtr = (MONTHCAL_INFO *)GetWindowLongPtrW(GetParent(hwnd), 0);
1925 TRACE("(hwnd=%p, uMsg=%x, wParam=%lx, lParam=%lx)\n",
1926 hwnd, uMsg, wParam, lParam);
1931 return DLGC_WANTARROWS | DLGC_WANTALLKEYS;
1935 WNDPROC editProc = infoPtr->EditWndProc;
1936 infoPtr->EditWndProc = NULL;
1937 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (DWORD_PTR)editProc);
1938 return CallWindowProcW(editProc, hwnd, uMsg, wParam, lParam);
1945 if ((VK_ESCAPE == (INT)wParam) || (VK_RETURN == (INT)wParam))
1949 return CallWindowProcW(infoPtr->EditWndProc, hwnd, uMsg, wParam, lParam);
1952 SendMessageW(infoPtr->hWndYearUpDown, WM_CLOSE, 0, 0);
1953 SendMessageW(hwnd, WM_CLOSE, 0, 0);
1957 /* creates updown control and edit box */
1958 static void MONTHCAL_EditYear(MONTHCAL_INFO *infoPtr, INT calIdx)
1960 RECT *rc = &infoPtr->calendars[calIdx].titleyear;
1961 RECT *title = &infoPtr->calendars[calIdx].title;
1963 infoPtr->hWndYearEdit =
1964 CreateWindowExW(0, WC_EDITW, 0, WS_VISIBLE | WS_CHILD | ES_READONLY,
1965 rc->left + 3, (title->bottom + title->top - infoPtr->textHeight) / 2,
1966 rc->right - rc->left + 4,
1967 infoPtr->textHeight, infoPtr->hwndSelf,
1970 SendMessageW(infoPtr->hWndYearEdit, WM_SETFONT, (WPARAM)infoPtr->hBoldFont, TRUE);
1972 infoPtr->hWndYearUpDown =
1973 CreateWindowExW(0, UPDOWN_CLASSW, 0,
1974 WS_VISIBLE | WS_CHILD | UDS_SETBUDDYINT | UDS_NOTHOUSANDS | UDS_ARROWKEYS,
1975 rc->right + 7, (title->bottom + title->top - infoPtr->textHeight) / 2,
1976 18, infoPtr->textHeight, infoPtr->hwndSelf,
1979 /* attach edit box */
1980 SendMessageW(infoPtr->hWndYearUpDown, UDM_SETRANGE, 0,
1981 MAKELONG(max_allowed_date.wYear, min_allowed_date.wYear));
1982 SendMessageW(infoPtr->hWndYearUpDown, UDM_SETBUDDY, (WPARAM)infoPtr->hWndYearEdit, 0);
1983 SendMessageW(infoPtr->hWndYearUpDown, UDM_SETPOS, 0, infoPtr->calendars[calIdx].month.wYear);
1985 /* subclass edit box */
1986 infoPtr->EditWndProc = (WNDPROC)SetWindowLongPtrW(infoPtr->hWndYearEdit,
1987 GWLP_WNDPROC, (DWORD_PTR)EditWndProc);
1989 SetFocus(infoPtr->hWndYearEdit);
1993 MONTHCAL_LButtonDown(MONTHCAL_INFO *infoPtr, LPARAM lParam)
1998 /* Actually we don't need input focus for calendar, this is used to kill
1999 year updown and its buddy edit box */
2000 if (IsWindow(infoPtr->hWndYearUpDown))
2002 SetFocus(infoPtr->hwndSelf);
2006 SetCapture(infoPtr->hwndSelf);
2008 ht.cbSize = sizeof(MCHITTESTINFO);
2009 ht.pt.x = (short)LOWORD(lParam);
2010 ht.pt.y = (short)HIWORD(lParam);
2012 hit = MONTHCAL_HitTest(infoPtr, &ht);
2014 TRACE("%x at (%d, %d)\n", hit, ht.pt.x, ht.pt.y);
2018 case MCHT_TITLEBTNNEXT:
2019 MONTHCAL_GoToMonth(infoPtr, DIRECTION_FORWARD);
2020 infoPtr->status = MC_NEXTPRESSED;
2021 SetTimer(infoPtr->hwndSelf, MC_PREVNEXTMONTHTIMER, MC_PREVNEXTMONTHDELAY, 0);
2022 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
2025 case MCHT_TITLEBTNPREV:
2026 MONTHCAL_GoToMonth(infoPtr, DIRECTION_BACKWARD);
2027 infoPtr->status = MC_PREVPRESSED;
2028 SetTimer(infoPtr->hwndSelf, MC_PREVNEXTMONTHTIMER, MC_PREVNEXTMONTHDELAY, 0);
2029 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
2032 case MCHT_TITLEMONTH:
2034 HMENU hMenu = CreatePopupMenu();
2039 for (i = 0; i < 12; i++)
2041 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SMONTHNAME1+i, buf, countof(buf));
2042 AppendMenuW(hMenu, MF_STRING|MF_ENABLED, i + 1, buf);
2044 menupoint.x = ht.pt.x;
2045 menupoint.y = ht.pt.y;
2046 ClientToScreen(infoPtr->hwndSelf, &menupoint);
2047 i = TrackPopupMenu(hMenu,TPM_LEFTALIGN | TPM_NONOTIFY | TPM_RIGHTBUTTON | TPM_RETURNCMD,
2048 menupoint.x, menupoint.y, 0, infoPtr->hwndSelf, NULL);
2050 if ((i > 0) && (i < 13) && infoPtr->calendars[ht.iOffset].month.wMonth != i)
2052 INT delta = i - infoPtr->calendars[ht.iOffset].month.wMonth;
2055 /* check if change allowed by range set */
2056 st = delta < 0 ? infoPtr->calendars[0].month :
2057 infoPtr->calendars[infoPtr->cal_num-1].month;
2058 MONTHCAL_GetMonth(&st, delta);
2060 if (MONTHCAL_IsDateInValidRange(infoPtr, &st, FALSE))
2062 MONTHCAL_Scroll(infoPtr, delta);
2063 MONTHCAL_NotifyDayState(infoPtr);
2064 MONTHCAL_NotifySelectionChange(infoPtr);
2065 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
2070 case MCHT_TITLEYEAR:
2072 MONTHCAL_EditYear(infoPtr, ht.iOffset);
2075 case MCHT_TODAYLINK:
2077 infoPtr->calendars[0].month = infoPtr->todaysDate;
2078 infoPtr->minSel = infoPtr->todaysDate;
2079 infoPtr->maxSel = infoPtr->todaysDate;
2080 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
2082 MONTHCAL_NotifySelectionChange(infoPtr);
2083 MONTHCAL_NotifySelect(infoPtr);
2086 case MCHT_CALENDARDATENEXT:
2087 case MCHT_CALENDARDATEPREV:
2088 case MCHT_CALENDARDATE:
2092 MONTHCAL_CopyDate(&ht.st, &infoPtr->firstSel);
2094 st[0] = st[1] = ht.st;
2095 /* clear selection range */
2096 MONTHCAL_SetSelRange(infoPtr, st);
2098 infoPtr->status = MC_SEL_LBUTDOWN;
2099 MONTHCAL_SetDayFocus(infoPtr, &ht.st);
2109 MONTHCAL_LButtonUp(MONTHCAL_INFO *infoPtr, LPARAM lParam)
2117 if(infoPtr->status & (MC_PREVPRESSED | MC_NEXTPRESSED)) {
2120 KillTimer(infoPtr->hwndSelf, MC_PREVNEXTMONTHTIMER);
2121 r = infoPtr->status & MC_PREVPRESSED ? &infoPtr->titlebtnprev : &infoPtr->titlebtnnext;
2122 infoPtr->status &= ~(MC_PREVPRESSED | MC_NEXTPRESSED);
2124 InvalidateRect(infoPtr->hwndSelf, r, FALSE);
2129 /* always send NM_RELEASEDCAPTURE notification */
2130 nmhdr.hwndFrom = infoPtr->hwndSelf;
2131 nmhdr.idFrom = GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_ID);
2132 nmhdr.code = NM_RELEASEDCAPTURE;
2133 TRACE("Sent notification from %p to %p\n", infoPtr->hwndSelf, infoPtr->hwndNotify);
2135 SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, nmhdr.idFrom, (LPARAM)&nmhdr);
2137 if(!(infoPtr->status & MC_SEL_LBUTDOWN)) return 0;
2139 ht.cbSize = sizeof(MCHITTESTINFO);
2140 ht.pt.x = (short)LOWORD(lParam);
2141 ht.pt.y = (short)HIWORD(lParam);
2142 hit = MONTHCAL_HitTest(infoPtr, &ht);
2144 infoPtr->status = MC_SEL_LBUTUP;
2145 MONTHCAL_SetDayFocus(infoPtr, NULL);
2147 if((hit & MCHT_CALENDARDATE) == MCHT_CALENDARDATE)
2149 SYSTEMTIME sel = infoPtr->minSel;
2151 /* will be invalidated here */
2152 MONTHCAL_SetCurSel(infoPtr, &ht.st);
2154 /* send MCN_SELCHANGE only if new date selected */
2155 if (!MONTHCAL_IsDateEqual(&sel, &ht.st))
2156 MONTHCAL_NotifySelectionChange(infoPtr);
2158 MONTHCAL_NotifySelect(infoPtr);
2166 MONTHCAL_Timer(MONTHCAL_INFO *infoPtr, WPARAM id)
2171 case MC_PREVNEXTMONTHTIMER:
2172 if(infoPtr->status & MC_NEXTPRESSED) MONTHCAL_GoToMonth(infoPtr, DIRECTION_FORWARD);
2173 if(infoPtr->status & MC_PREVPRESSED) MONTHCAL_GoToMonth(infoPtr, DIRECTION_BACKWARD);
2174 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
2176 case MC_TODAYUPDATETIMER:
2180 if(infoPtr->todaySet) return 0;
2183 MONTHCAL_UpdateToday(infoPtr, &st);
2185 /* notification sent anyway */
2186 MONTHCAL_NotifySelectionChange(infoPtr);
2191 ERR("got unknown timer %ld\n", id);
2200 MONTHCAL_MouseMove(MONTHCAL_INFO *infoPtr, LPARAM lParam)
2207 if(!(infoPtr->status & MC_SEL_LBUTDOWN)) return 0;
2209 ht.cbSize = sizeof(MCHITTESTINFO);
2210 ht.pt.x = (short)LOWORD(lParam);
2211 ht.pt.y = (short)HIWORD(lParam);
2213 hit = MONTHCAL_HitTest(infoPtr, &ht);
2215 /* not on the calendar date numbers? bail out */
2216 TRACE("hit:%x\n",hit);
2217 if((hit & MCHT_CALENDARDATE) != MCHT_CALENDARDATE)
2219 MONTHCAL_SetDayFocus(infoPtr, NULL);
2225 /* if pointer is over focused day still there's nothing to do */
2226 if(!MONTHCAL_SetDayFocus(infoPtr, &ht.st)) return 0;
2228 MONTHCAL_CalcPosFromDay(infoPtr, &ht.st, &r);
2230 if(infoPtr->dwStyle & MCS_MULTISELECT) {
2233 MONTHCAL_GetSelRange(infoPtr, st);
2235 /* If we're still at the first selected date and range is empty, return.
2236 If range isn't empty we should change range to a single firstSel */
2237 if(MONTHCAL_IsDateEqual(&infoPtr->firstSel, &st_ht) &&
2238 MONTHCAL_IsDateEqual(&st[0], &st[1])) goto done;
2240 MONTHCAL_IsSelRangeValid(infoPtr, &st_ht, &infoPtr->firstSel, &st_ht);
2242 st[0] = infoPtr->firstSel;
2243 /* we should overwrite timestamp here */
2244 MONTHCAL_CopyDate(&st_ht, &st[1]);
2246 /* bounds will be swapped here if needed */
2247 MONTHCAL_SetSelRange(infoPtr, st);
2254 /* FIXME: this should specify a rectangle containing only the days that changed
2255 using InvalidateRect */
2256 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
2263 MONTHCAL_Paint(MONTHCAL_INFO *infoPtr, HDC hdc_paint)
2270 GetClientRect(infoPtr->hwndSelf, &ps.rcPaint);
2274 hdc = BeginPaint(infoPtr->hwndSelf, &ps);
2276 MONTHCAL_Refresh(infoPtr, hdc, &ps);
2277 if (!hdc_paint) EndPaint(infoPtr->hwndSelf, &ps);
2282 MONTHCAL_EraseBkgnd(const MONTHCAL_INFO *infoPtr, HDC hdc)
2286 if (!GetClipBox(hdc, &rc)) return FALSE;
2288 FillRect(hdc, &rc, infoPtr->brushes[BrushBackground]);
2294 MONTHCAL_PrintClient(MONTHCAL_INFO *infoPtr, HDC hdc, DWORD options)
2296 FIXME("Partial Stub: (hdc=%p options=0x%08x)\n", hdc, options);
2298 if ((options & PRF_CHECKVISIBLE) && !IsWindowVisible(infoPtr->hwndSelf))
2301 if (options & PRF_ERASEBKGND)
2302 MONTHCAL_EraseBkgnd(infoPtr, hdc);
2304 if (options & PRF_CLIENT)
2305 MONTHCAL_Paint(infoPtr, hdc);
2311 MONTHCAL_SetFocus(const MONTHCAL_INFO *infoPtr)
2315 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
2320 /* sets the size information */
2321 static void MONTHCAL_UpdateSize(MONTHCAL_INFO *infoPtr)
2323 static const WCHAR O0W[] = { '0','0',0 };
2324 HDC hdc = GetDC(infoPtr->hwndSelf);
2325 RECT *title=&infoPtr->calendars[0].title;
2326 RECT *prev=&infoPtr->titlebtnprev;
2327 RECT *next=&infoPtr->titlebtnnext;
2328 RECT *titlemonth=&infoPtr->calendars[0].titlemonth;
2329 RECT *titleyear=&infoPtr->calendars[0].titleyear;
2330 RECT *wdays=&infoPtr->calendars[0].wdays;
2331 RECT *weeknumrect=&infoPtr->calendars[0].weeknums;
2332 RECT *days=&infoPtr->calendars[0].days;
2333 RECT *todayrect=&infoPtr->todayrect;
2337 INT xdiv, dx, dy, i;
2341 GetClientRect(infoPtr->hwndSelf, &rcClient);
2343 currentFont = SelectObject(hdc, infoPtr->hFont);
2345 /* get the height and width of each day's text */
2346 GetTextMetricsW(hdc, &tm);
2347 infoPtr->textHeight = tm.tmHeight + tm.tmExternalLeading + tm.tmInternalLeading;
2349 /* find largest abbreviated day name for current locale */
2350 size.cx = sz.cx = 0;
2351 for (i = 0; i < 7; i++)
2353 if(GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SABBREVDAYNAME1 + i,
2354 buff, countof(buff)))
2356 GetTextExtentPoint32W(hdc, buff, lstrlenW(buff), &sz);
2357 if (sz.cx > size.cx) size.cx = sz.cx;
2359 else /* locale independent fallback on failure */
2361 static const WCHAR SunW[] = { 'S','u','n',0 };
2363 GetTextExtentPoint32W(hdc, SunW, lstrlenW(SunW), &size);
2368 infoPtr->textWidth = size.cx + 2;
2370 /* recalculate the height and width increments and offsets */
2371 GetTextExtentPoint32W(hdc, O0W, 2, &size);
2373 xdiv = (infoPtr->dwStyle & MCS_WEEKNUMBERS) ? 8 : 7;
2375 infoPtr->width_increment = size.cx * 2 + 4;
2376 infoPtr->height_increment = infoPtr->textHeight;
2378 /* calculate title area */
2380 title->bottom = 3 * infoPtr->height_increment / 2;
2382 title->right = infoPtr->width_increment * xdiv;
2384 /* set the dimensions of the next and previous buttons and center */
2385 /* the month text vertically */
2386 prev->top = next->top = title->top + 4;
2387 prev->bottom = next->bottom = title->bottom - 4;
2388 prev->left = title->left + 4;
2389 prev->right = prev->left + (title->bottom - title->top);
2390 next->right = title->right - 4;
2391 next->left = next->right - (title->bottom - title->top);
2393 /* titlemonth->left and right change based upon the current month */
2394 /* and are recalculated in refresh as the current month may change */
2395 /* without the control being resized */
2396 titlemonth->top = titleyear->top = title->top + (infoPtr->height_increment)/2;
2397 titlemonth->bottom = titleyear->bottom = title->bottom - (infoPtr->height_increment)/2;
2399 /* setup the dimensions of the rectangle we draw the names of the */
2400 /* days of the week in */
2401 weeknumrect->left = 0;
2403 if(infoPtr->dwStyle & MCS_WEEKNUMBERS)
2404 weeknumrect->right = prev->right;
2406 weeknumrect->right = weeknumrect->left;
2408 wdays->left = days->left = weeknumrect->right;
2409 wdays->right = days->right = wdays->left + 7 * infoPtr->width_increment;
2410 wdays->top = title->bottom;
2411 wdays->bottom = wdays->top + infoPtr->height_increment;
2413 days->top = weeknumrect->top = wdays->bottom;
2414 days->bottom = weeknumrect->bottom = days->top + 6 * infoPtr->height_increment;
2416 todayrect->left = 0;
2417 todayrect->right = title->right;
2418 todayrect->top = days->bottom;
2419 todayrect->bottom = days->bottom + infoPtr->height_increment;
2421 /* offset all rectangles to center in client area */
2422 dx = (rcClient.right - title->right) / 2;
2423 dy = (rcClient.bottom - todayrect->bottom) / 2;
2425 /* if calendar doesn't fit client area show it at left/top bounds */
2426 if (title->left + dx < 0) dx = 0;
2427 if (title->top + dy < 0) dy = 0;
2429 if (dx != 0 || dy != 0)
2431 OffsetRect(title, dx, dy);
2432 OffsetRect(prev, dx, dy);
2433 OffsetRect(next, dx, dy);
2434 OffsetRect(titlemonth, dx, dy);
2435 OffsetRect(titleyear, dx, dy);
2436 OffsetRect(wdays, dx, dy);
2437 OffsetRect(weeknumrect, dx, dy);
2438 OffsetRect(days, dx, dy);
2439 OffsetRect(todayrect, dx, dy);
2442 TRACE("dx=%d dy=%d client[%s] title[%s] wdays[%s] days[%s] today[%s]\n",
2443 infoPtr->width_increment,infoPtr->height_increment,
2444 wine_dbgstr_rect(&rcClient),
2445 wine_dbgstr_rect(title),
2446 wine_dbgstr_rect(wdays),
2447 wine_dbgstr_rect(days),
2448 wine_dbgstr_rect(todayrect));
2450 /* restore the originally selected font */
2451 SelectObject(hdc, currentFont);
2453 ReleaseDC(infoPtr->hwndSelf, hdc);
2456 static LRESULT MONTHCAL_Size(MONTHCAL_INFO *infoPtr, int Width, int Height)
2458 TRACE("(width=%d, height=%d)\n", Width, Height);
2460 MONTHCAL_UpdateSize(infoPtr);
2461 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
2466 static LRESULT MONTHCAL_GetFont(const MONTHCAL_INFO *infoPtr)
2468 return (LRESULT)infoPtr->hFont;
2471 static LRESULT MONTHCAL_SetFont(MONTHCAL_INFO *infoPtr, HFONT hFont, BOOL redraw)
2476 if (!hFont) return 0;
2478 hOldFont = infoPtr->hFont;
2479 infoPtr->hFont = hFont;
2481 GetObjectW(infoPtr->hFont, sizeof(lf), &lf);
2482 lf.lfWeight = FW_BOLD;
2483 infoPtr->hBoldFont = CreateFontIndirectW(&lf);
2485 MONTHCAL_UpdateSize(infoPtr);
2488 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
2490 return (LRESULT)hOldFont;
2493 /* update theme after a WM_THEMECHANGED message */
2494 static LRESULT theme_changed (const MONTHCAL_INFO* infoPtr)
2496 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
2497 CloseThemeData (theme);
2498 OpenThemeData (infoPtr->hwndSelf, themeClass);
2502 static INT MONTHCAL_StyleChanged(MONTHCAL_INFO *infoPtr, WPARAM wStyleType,
2503 const STYLESTRUCT *lpss)
2505 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
2506 wStyleType, lpss->styleOld, lpss->styleNew);
2508 if (wStyleType != GWL_STYLE) return 0;
2510 infoPtr->dwStyle = lpss->styleNew;
2512 /* make room for week numbers */
2513 if ((lpss->styleNew ^ lpss->styleOld) & MCS_WEEKNUMBERS)
2514 MONTHCAL_UpdateSize(infoPtr);
2519 static INT MONTHCAL_StyleChanging(MONTHCAL_INFO *infoPtr, WPARAM wStyleType,
2522 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
2523 wStyleType, lpss->styleOld, lpss->styleNew);
2525 /* block MCS_MULTISELECT change */
2526 if ((lpss->styleNew ^ lpss->styleOld) & MCS_MULTISELECT)
2528 if (lpss->styleOld & MCS_MULTISELECT)
2529 lpss->styleNew |= MCS_MULTISELECT;
2531 lpss->styleNew &= ~MCS_MULTISELECT;
2537 /* FIXME: check whether dateMin/dateMax need to be adjusted. */
2539 MONTHCAL_Create(HWND hwnd, LPCREATESTRUCTW lpcs)
2541 MONTHCAL_INFO *infoPtr;
2543 /* allocate memory for info structure */
2544 infoPtr = Alloc(sizeof(MONTHCAL_INFO));
2545 SetWindowLongPtrW(hwnd, 0, (DWORD_PTR)infoPtr);
2547 if (infoPtr == NULL) {
2548 ERR("could not allocate info memory!\n");
2552 infoPtr->hwndSelf = hwnd;
2553 infoPtr->hwndNotify = lpcs->hwndParent;
2554 infoPtr->dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
2555 infoPtr->calendars = Alloc(sizeof(CALENDAR_INFO));
2556 if (!infoPtr->calendars) goto fail;
2558 infoPtr->cal_num = 1;
2560 MONTHCAL_SetFont(infoPtr, GetStockObject(DEFAULT_GUI_FONT), FALSE);
2562 /* initialize info structure */
2563 /* FIXME: calculate systemtime ->> localtime(subtract timezoneinfo) */
2565 GetLocalTime(&infoPtr->todaysDate);
2566 MONTHCAL_SetFirstDayOfWeek(infoPtr, -1);
2568 infoPtr->maxSelCount = (infoPtr->dwStyle & MCS_MULTISELECT) ? 7 : 1;
2569 infoPtr->monthRange = 3;
2571 infoPtr->monthdayState = Alloc(infoPtr->monthRange * sizeof(MONTHDAYSTATE));
2572 if (!infoPtr->monthdayState) goto fail;
2574 infoPtr->colors[MCSC_BACKGROUND] = comctl32_color.clrWindow;
2575 infoPtr->colors[MCSC_TEXT] = comctl32_color.clrWindowText;
2576 infoPtr->colors[MCSC_TITLEBK] = comctl32_color.clrActiveCaption;
2577 infoPtr->colors[MCSC_TITLETEXT] = comctl32_color.clrWindow;
2578 infoPtr->colors[MCSC_MONTHBK] = comctl32_color.clrWindow;
2579 infoPtr->colors[MCSC_TRAILINGTEXT] = comctl32_color.clrGrayText;
2581 infoPtr->brushes[BrushBackground] = CreateSolidBrush(infoPtr->colors[MCSC_BACKGROUND]);
2582 infoPtr->brushes[BrushTitle] = CreateSolidBrush(infoPtr->colors[MCSC_TITLEBK]);
2583 infoPtr->brushes[BrushMonth] = CreateSolidBrush(infoPtr->colors[MCSC_MONTHBK]);
2585 infoPtr->pens[PenRed] = CreatePen(PS_SOLID, 1, RGB(255, 0, 0));
2586 infoPtr->pens[PenText] = CreatePen(PS_SOLID, 1, infoPtr->colors[MCSC_TEXT]);
2588 infoPtr->minSel = infoPtr->todaysDate;
2589 infoPtr->maxSel = infoPtr->todaysDate;
2590 infoPtr->calendars[0].month = infoPtr->todaysDate;
2591 infoPtr->isUnicode = TRUE;
2593 /* call MONTHCAL_UpdateSize to set all of the dimensions */
2594 /* of the control */
2595 MONTHCAL_UpdateSize(infoPtr);
2597 /* today auto update timer, to be freed only on control destruction */
2598 SetTimer(infoPtr->hwndSelf, MC_TODAYUPDATETIMER, MC_TODAYUPDATEDELAY, 0);
2600 OpenThemeData (infoPtr->hwndSelf, themeClass);
2605 Free(infoPtr->monthdayState);
2606 Free(infoPtr->calendars);
2612 MONTHCAL_Destroy(MONTHCAL_INFO *infoPtr)
2616 /* free month calendar info data */
2617 Free(infoPtr->monthdayState);
2618 Free(infoPtr->calendars);
2619 SetWindowLongPtrW(infoPtr->hwndSelf, 0, 0);
2621 CloseThemeData (GetWindowTheme (infoPtr->hwndSelf));
2623 for (i = 0; i < BrushLast; i++) DeleteObject(infoPtr->brushes[i]);
2624 for (i = 0; i < PenLast; i++) DeleteObject(infoPtr->pens[i]);
2631 * Handler for WM_NOTIFY messages
2634 MONTHCAL_Notify(MONTHCAL_INFO *infoPtr, NMHDR *hdr)
2636 /* notification from year edit updown */
2637 if (hdr->code == UDN_DELTAPOS)
2639 NMUPDOWN *nmud = (NMUPDOWN*)hdr;
2641 if (hdr->hwndFrom == infoPtr->hWndYearUpDown && nmud->iDelta)
2643 /* year value limits are set up explicitly after updown creation */
2644 MONTHCAL_Scroll(infoPtr, 12 * nmud->iDelta);
2645 MONTHCAL_NotifyDayState(infoPtr);
2646 MONTHCAL_NotifySelectionChange(infoPtr);
2653 MONTHCAL_SetUnicodeFormat(MONTHCAL_INFO *infoPtr, BOOL isUnicode)
2655 BOOL prev = infoPtr->isUnicode;
2656 infoPtr->isUnicode = isUnicode;
2661 MONTHCAL_GetUnicodeFormat(const MONTHCAL_INFO *infoPtr)
2663 return infoPtr->isUnicode;
2666 static LRESULT WINAPI
2667 MONTHCAL_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2669 MONTHCAL_INFO *infoPtr = (MONTHCAL_INFO *)GetWindowLongPtrW(hwnd, 0);
2671 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n", hwnd, uMsg, wParam, lParam);
2673 if (!infoPtr && (uMsg != WM_CREATE))
2674 return DefWindowProcW(hwnd, uMsg, wParam, lParam);
2678 return MONTHCAL_GetCurSel(infoPtr, (LPSYSTEMTIME)lParam);
2681 return MONTHCAL_SetCurSel(infoPtr, (LPSYSTEMTIME)lParam);
2683 case MCM_GETMAXSELCOUNT:
2684 return MONTHCAL_GetMaxSelCount(infoPtr);
2686 case MCM_SETMAXSELCOUNT:
2687 return MONTHCAL_SetMaxSelCount(infoPtr, wParam);
2689 case MCM_GETSELRANGE:
2690 return MONTHCAL_GetSelRange(infoPtr, (LPSYSTEMTIME)lParam);
2692 case MCM_SETSELRANGE:
2693 return MONTHCAL_SetSelRange(infoPtr, (LPSYSTEMTIME)lParam);
2695 case MCM_GETMONTHRANGE:
2696 return MONTHCAL_GetMonthRange(infoPtr, wParam, (SYSTEMTIME*)lParam);
2698 case MCM_SETDAYSTATE:
2699 return MONTHCAL_SetDayState(infoPtr, (INT)wParam, (LPMONTHDAYSTATE)lParam);
2701 case MCM_GETMINREQRECT:
2702 return MONTHCAL_GetMinReqRect(infoPtr, (LPRECT)lParam);
2705 return MONTHCAL_GetColor(infoPtr, wParam);
2708 return MONTHCAL_SetColor(infoPtr, wParam, (COLORREF)lParam);
2711 return MONTHCAL_GetToday(infoPtr, (LPSYSTEMTIME)lParam);
2714 return MONTHCAL_SetToday(infoPtr, (LPSYSTEMTIME)lParam);
2717 return MONTHCAL_HitTest(infoPtr, (PMCHITTESTINFO)lParam);
2719 case MCM_GETFIRSTDAYOFWEEK:
2720 return MONTHCAL_GetFirstDayOfWeek(infoPtr);
2722 case MCM_SETFIRSTDAYOFWEEK:
2723 return MONTHCAL_SetFirstDayOfWeek(infoPtr, (INT)lParam);
2726 return MONTHCAL_GetRange(infoPtr, (LPSYSTEMTIME)lParam);
2729 return MONTHCAL_SetRange(infoPtr, (SHORT)wParam, (LPSYSTEMTIME)lParam);
2731 case MCM_GETMONTHDELTA:
2732 return MONTHCAL_GetMonthDelta(infoPtr);
2734 case MCM_SETMONTHDELTA:
2735 return MONTHCAL_SetMonthDelta(infoPtr, wParam);
2737 case MCM_GETMAXTODAYWIDTH:
2738 return MONTHCAL_GetMaxTodayWidth(infoPtr);
2740 case MCM_SETUNICODEFORMAT:
2741 return MONTHCAL_SetUnicodeFormat(infoPtr, (BOOL)wParam);
2743 case MCM_GETUNICODEFORMAT:
2744 return MONTHCAL_GetUnicodeFormat(infoPtr);
2747 return DLGC_WANTARROWS | DLGC_WANTCHARS;
2750 return MONTHCAL_RButtonUp(infoPtr, lParam);
2752 case WM_LBUTTONDOWN:
2753 return MONTHCAL_LButtonDown(infoPtr, lParam);
2756 return MONTHCAL_MouseMove(infoPtr, lParam);
2759 return MONTHCAL_LButtonUp(infoPtr, lParam);
2762 return MONTHCAL_Paint(infoPtr, (HDC)wParam);
2764 case WM_PRINTCLIENT:
2765 return MONTHCAL_PrintClient(infoPtr, (HDC)wParam, (DWORD)lParam);
2768 return MONTHCAL_EraseBkgnd(infoPtr, (HDC)wParam);
2771 return MONTHCAL_SetFocus(infoPtr);
2774 return MONTHCAL_Size(infoPtr, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
2777 return MONTHCAL_Notify(infoPtr, (NMHDR*)lParam);
2780 return MONTHCAL_Create(hwnd, (LPCREATESTRUCTW)lParam);
2783 return MONTHCAL_SetFont(infoPtr, (HFONT)wParam, (BOOL)lParam);
2786 return MONTHCAL_GetFont(infoPtr);
2789 return MONTHCAL_Timer(infoPtr, wParam);
2791 case WM_THEMECHANGED:
2792 return theme_changed (infoPtr);
2795 return MONTHCAL_Destroy(infoPtr);
2797 case WM_SYSCOLORCHANGE:
2798 COMCTL32_RefreshSysColors();
2801 case WM_STYLECHANGED:
2802 return MONTHCAL_StyleChanged(infoPtr, wParam, (LPSTYLESTRUCT)lParam);
2804 case WM_STYLECHANGING:
2805 return MONTHCAL_StyleChanging(infoPtr, wParam, (LPSTYLESTRUCT)lParam);
2808 if ((uMsg >= WM_USER) && (uMsg < WM_APP) && !COMCTL32_IsReflectedMessage(uMsg))
2809 ERR( "unknown msg %04x wp=%08lx lp=%08lx\n", uMsg, wParam, lParam);
2810 return DefWindowProcW(hwnd, uMsg, wParam, lParam);
2816 MONTHCAL_Register(void)
2820 ZeroMemory(&wndClass, sizeof(WNDCLASSW));
2821 wndClass.style = CS_GLOBALCLASS;
2822 wndClass.lpfnWndProc = MONTHCAL_WindowProc;
2823 wndClass.cbClsExtra = 0;
2824 wndClass.cbWndExtra = sizeof(MONTHCAL_INFO *);
2825 wndClass.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
2826 wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
2827 wndClass.lpszClassName = MONTHCAL_CLASSW;
2829 RegisterClassW(&wndClass);
2834 MONTHCAL_Unregister(void)
2836 UnregisterClassW(MONTHCAL_CLASSW, NULL);