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 IDs */
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;
154 SIZE dim; /* [cx,cy] - dimensions of calendars matrix, row/column count */
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 */
173 static inline INT MONTHCAL_GetCalCount(const MONTHCAL_INFO *infoPtr)
175 return infoPtr->dim.cx * infoPtr->dim.cy;
178 /* send a single MCN_SELCHANGE notification */
179 static inline void MONTHCAL_NotifySelectionChange(const MONTHCAL_INFO *infoPtr)
183 nmsc.nmhdr.hwndFrom = infoPtr->hwndSelf;
184 nmsc.nmhdr.idFrom = GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_ID);
185 nmsc.nmhdr.code = MCN_SELCHANGE;
186 nmsc.stSelStart = infoPtr->minSel;
187 nmsc.stSelEnd = infoPtr->maxSel;
188 SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, nmsc.nmhdr.idFrom, (LPARAM)&nmsc);
191 /* send a single MCN_SELECT notification */
192 static inline void MONTHCAL_NotifySelect(const MONTHCAL_INFO *infoPtr)
196 nmsc.nmhdr.hwndFrom = infoPtr->hwndSelf;
197 nmsc.nmhdr.idFrom = GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_ID);
198 nmsc.nmhdr.code = MCN_SELECT;
199 nmsc.stSelStart = infoPtr->minSel;
200 nmsc.stSelEnd = infoPtr->maxSel;
202 SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, nmsc.nmhdr.idFrom, (LPARAM)&nmsc);
205 /* returns the number of days in any given month, checking for leap days */
206 /* January is 1, December is 12 */
207 int MONTHCAL_MonthLength(int month, int year)
209 const int mdays[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
210 /* Wrap around, this eases handling. Getting length only we shouldn't care
211 about year change here cause January and December have
212 the same day quantity */
218 /* special case for calendar transition year */
219 if(month == min_allowed_date.wMonth && year == min_allowed_date.wYear) return 19;
221 /* if we have a leap year add 1 day to February */
222 /* a leap year is a year either divisible by 400 */
223 /* or divisible by 4 and not by 100 */
224 if(month == 2) { /* February */
225 return mdays[month - 1] + ((year%400 == 0) ? 1 : ((year%100 != 0) &&
226 (year%4 == 0)) ? 1 : 0);
229 return mdays[month - 1];
233 /* compares timestamps using date part only */
234 static inline BOOL MONTHCAL_IsDateEqual(const SYSTEMTIME *first, const SYSTEMTIME *second)
236 return (first->wYear == second->wYear) && (first->wMonth == second->wMonth) &&
237 (first->wDay == second->wDay);
240 /* make sure that date fields are valid */
241 static BOOL MONTHCAL_ValidateDate(const SYSTEMTIME *time)
243 if(time->wMonth < 1 || time->wMonth > 12 ) return FALSE;
244 if(time->wDayOfWeek > 6) return FALSE;
245 if(time->wDay > MONTHCAL_MonthLength(time->wMonth, time->wYear))
251 /* Copies timestamp part only.
255 * [I] from : source date
258 static void MONTHCAL_CopyTime(const SYSTEMTIME *from, SYSTEMTIME *to)
260 to->wHour = from->wHour;
261 to->wMinute = from->wMinute;
262 to->wSecond = from->wSecond;
265 /* Copies date part only.
269 * [I] from : source date
272 static void MONTHCAL_CopyDate(const SYSTEMTIME *from, SYSTEMTIME *to)
274 to->wYear = from->wYear;
275 to->wMonth = from->wMonth;
276 to->wDay = from->wDay;
277 to->wDayOfWeek = from->wDayOfWeek;
280 /* Compares two dates in SYSTEMTIME format
284 * [I] first : pointer to valid first date data to compare
285 * [I] second : pointer to valid second date data to compare
289 * -1 : first < second
290 * 0 : first == second
293 * Note that no date validation performed, already validated values expected.
295 static LONG MONTHCAL_CompareSystemTime(const SYSTEMTIME *first, const SYSTEMTIME *second)
297 FILETIME ft_first, ft_second;
299 SystemTimeToFileTime(first, &ft_first);
300 SystemTimeToFileTime(second, &ft_second);
302 return CompareFileTime(&ft_first, &ft_second);
305 static LONG MONTHCAL_CompareMonths(const SYSTEMTIME *first, const SYSTEMTIME *second)
307 SYSTEMTIME st_first, st_second;
309 st_first = st_second = st_null;
310 MONTHCAL_CopyDate(first, &st_first);
311 MONTHCAL_CopyDate(second, &st_second);
312 st_first.wDay = st_second.wDay = 1;
314 return MONTHCAL_CompareSystemTime(&st_first, &st_second);
317 static LONG MONTHCAL_CompareDate(const SYSTEMTIME *first, const SYSTEMTIME *second)
319 SYSTEMTIME st_first, st_second;
321 st_first = st_second = st_null;
322 MONTHCAL_CopyDate(first, &st_first);
323 MONTHCAL_CopyDate(second, &st_second);
325 return MONTHCAL_CompareSystemTime(&st_first, &st_second);
328 /* Checks largest possible date range and configured one
332 * [I] infoPtr : valid pointer to control data
333 * [I] date : pointer to valid date data to check
334 * [I] fix : make date fit valid range
338 * TRUE - date within largest and configured range
339 * FALSE - date is outside largest or configured range
341 static BOOL MONTHCAL_IsDateInValidRange(const MONTHCAL_INFO *infoPtr,
342 SYSTEMTIME *date, BOOL fix)
344 const SYSTEMTIME *fix_st = NULL;
346 if(MONTHCAL_CompareSystemTime(date, &max_allowed_date) == 1) {
347 fix_st = &max_allowed_date;
349 else if(MONTHCAL_CompareSystemTime(date, &min_allowed_date) == -1) {
350 fix_st = &min_allowed_date;
352 else if(infoPtr->rangeValid & GDTR_MAX) {
353 if((MONTHCAL_CompareSystemTime(date, &infoPtr->maxDate) == 1)) {
354 fix_st = &infoPtr->maxDate;
357 else if(infoPtr->rangeValid & GDTR_MIN) {
358 if((MONTHCAL_CompareSystemTime(date, &infoPtr->minDate) == -1)) {
359 fix_st = &infoPtr->minDate;
364 date->wYear = fix_st->wYear;
365 date->wMonth = fix_st->wMonth;
368 return fix_st ? FALSE : TRUE;
371 /* Checks passed range width with configured maximum selection count
375 * [I] infoPtr : valid pointer to control data
376 * [I] range0 : pointer to valid date data (requested bound)
377 * [I] range1 : pointer to valid date data (primary bound)
378 * [O] adjust : returns adjusted range bound to fit maximum range (optional)
380 * Adjust value computed basing on primary bound and current maximum selection
381 * count. For simple range check (without adjusted value required) (range0, range1)
382 * relation means nothing.
386 * TRUE - range is shorter or equal to maximum
387 * FALSE - range is larger than maximum
389 static BOOL MONTHCAL_IsSelRangeValid(const MONTHCAL_INFO *infoPtr,
390 const SYSTEMTIME *range0,
391 const SYSTEMTIME *range1,
394 ULARGE_INTEGER ul_range0, ul_range1, ul_diff;
395 FILETIME ft_range0, ft_range1;
398 SystemTimeToFileTime(range0, &ft_range0);
399 SystemTimeToFileTime(range1, &ft_range1);
401 ul_range0.u.LowPart = ft_range0.dwLowDateTime;
402 ul_range0.u.HighPart = ft_range0.dwHighDateTime;
403 ul_range1.u.LowPart = ft_range1.dwLowDateTime;
404 ul_range1.u.HighPart = ft_range1.dwHighDateTime;
406 cmp = CompareFileTime(&ft_range0, &ft_range1);
409 ul_diff.QuadPart = ul_range0.QuadPart - ul_range1.QuadPart;
411 ul_diff.QuadPart = -ul_range0.QuadPart + ul_range1.QuadPart;
413 if(ul_diff.QuadPart >= DAYSTO100NSECS(infoPtr->maxSelCount)) {
417 ul_range0.QuadPart = ul_range1.QuadPart + DAYSTO100NSECS(infoPtr->maxSelCount - 1);
419 ul_range0.QuadPart = ul_range1.QuadPart - DAYSTO100NSECS(infoPtr->maxSelCount - 1);
421 ft_range0.dwLowDateTime = ul_range0.u.LowPart;
422 ft_range0.dwHighDateTime = ul_range0.u.HighPart;
423 FileTimeToSystemTime(&ft_range0, adjust);
431 /* Used in MCM_SETRANGE/MCM_SETSELRANGE to determine resulting time part.
432 Milliseconds are intentionally not validated. */
433 static BOOL MONTHCAL_ValidateTime(const SYSTEMTIME *time)
435 if((time->wHour > 24) || (time->wMinute > 59) || (time->wSecond > 59))
441 /* Note:Depending on DST, this may be offset by a day.
442 Need to find out if we're on a DST place & adjust the clock accordingly.
443 Above function assumes we have a valid data.
444 Valid for year>1752; 1 <= d <= 31, 1 <= m <= 12.
448 /* Returns the day in the week
451 * [i] date : input date
452 * [I] inplace : set calculated value back to date structure
455 * day of week in SYSTEMTIME format: (0 == sunday,..., 6 == saturday)
457 int MONTHCAL_CalculateDayOfWeek(SYSTEMTIME *date, BOOL inplace)
459 SYSTEMTIME st = st_null;
462 MONTHCAL_CopyDate(date, &st);
464 SystemTimeToFileTime(&st, &ft);
465 FileTimeToSystemTime(&ft, &st);
467 if (inplace) date->wDayOfWeek = st.wDayOfWeek;
469 return st.wDayOfWeek;
472 /* add/subtract 'months' from date */
473 static inline void MONTHCAL_GetMonth(SYSTEMTIME *date, INT months)
475 INT length, m = date->wMonth + months;
477 date->wYear += m > 0 ? (m - 1) / 12 : m / 12 - 1;
478 date->wMonth = m > 0 ? (m - 1) % 12 + 1 : 12 + m % 12;
479 /* fix moving from last day in a month */
480 length = MONTHCAL_MonthLength(date->wMonth, date->wYear);
481 if(date->wDay > length) date->wDay = length;
482 MONTHCAL_CalculateDayOfWeek(date, TRUE);
485 /* properly updates date to point on next month */
486 static inline void MONTHCAL_GetNextMonth(SYSTEMTIME *date)
488 MONTHCAL_GetMonth(date, 1);
491 /* properly updates date to point on prev month */
492 static inline void MONTHCAL_GetPrevMonth(SYSTEMTIME *date)
494 MONTHCAL_GetMonth(date, -1);
497 /* Returns full date for a first currently visible day */
498 static void MONTHCAL_GetMinDate(const MONTHCAL_INFO *infoPtr, SYSTEMTIME *date)
500 /* zero indexed calendar has the earliest date */
501 SYSTEMTIME st_first = infoPtr->calendars[0].month;
505 firstDay = MONTHCAL_CalculateDayOfWeek(&st_first, FALSE);
507 *date = infoPtr->calendars[0].month;
508 MONTHCAL_GetPrevMonth(date);
510 date->wDay = MONTHCAL_MonthLength(date->wMonth, date->wYear) +
511 (infoPtr->firstDay - firstDay) % 7 + 1;
513 if(date->wDay > MONTHCAL_MonthLength(date->wMonth, date->wYear))
516 /* fix day of week */
517 MONTHCAL_CalculateDayOfWeek(date, TRUE);
520 /* Returns full date for a last currently visible day */
521 static void MONTHCAL_GetMaxDate(const MONTHCAL_INFO *infoPtr, SYSTEMTIME *date)
523 /* the latest date is in latest calendar */
524 SYSTEMTIME st, *lt_month = &infoPtr->calendars[MONTHCAL_GetCalCount(infoPtr)-1].month;
530 /* day of week of first day of current month */
532 first_day = MONTHCAL_CalculateDayOfWeek(&st, FALSE);
534 MONTHCAL_GetNextMonth(date);
535 MONTHCAL_GetPrevMonth(&st);
537 /* last calendar starts with some date from previous month that not displayed */
538 st.wDay = MONTHCAL_MonthLength(st.wMonth, st.wYear) +
539 (infoPtr->firstDay - first_day) % 7 + 1;
540 if (st.wDay > MONTHCAL_MonthLength(st.wMonth, st.wYear)) st.wDay -= 7;
542 /* Use month length to get max day. 42 means max day count in calendar area */
543 date->wDay = 42 - (MONTHCAL_MonthLength(st.wMonth, st.wYear) - st.wDay + 1) -
544 MONTHCAL_MonthLength(lt_month->wMonth, lt_month->wYear);
546 /* fix day of week */
547 MONTHCAL_CalculateDayOfWeek(date, TRUE);
550 /* From a given point calculate the row, column and day in the calendar,
551 'day == 0' means the last day of the last month. */
552 static int MONTHCAL_GetDayFromPos(const MONTHCAL_INFO *infoPtr, POINT pt, INT calIdx)
554 SYSTEMTIME st = infoPtr->calendars[calIdx].month;
555 int firstDay, col, row;
558 GetClientRect(infoPtr->hwndSelf, &client);
560 /* if the point is outside the x bounds of the window put it at the boundary */
561 if (pt.x > client.right) pt.x = client.right;
563 col = (pt.x - infoPtr->calendars[calIdx].days.left ) / infoPtr->width_increment;
564 row = (pt.y - infoPtr->calendars[calIdx].days.top ) / infoPtr->height_increment;
567 firstDay = (MONTHCAL_CalculateDayOfWeek(&st, FALSE) + 6 - infoPtr->firstDay) % 7;
568 return col + 7 * row - firstDay;
571 /* Get day position for given date and calendar
575 * [I] infoPtr : pointer to control data
576 * [I] date : date value
577 * [O] col : day column (zero based)
578 * [O] row : week column (zero based)
579 * [I] calIdx : calendar index
581 static void MONTHCAL_GetDayPos(const MONTHCAL_INFO *infoPtr, const SYSTEMTIME *date,
582 INT *col, INT *row, INT calIdx)
584 SYSTEMTIME st = infoPtr->calendars[calIdx].month;
588 first = (MONTHCAL_CalculateDayOfWeek(&st, FALSE) + 6 - infoPtr->firstDay) % 7;
590 if (calIdx == 0 || calIdx == MONTHCAL_GetCalCount(infoPtr)-1) {
591 const SYSTEMTIME *cal = &infoPtr->calendars[calIdx].month;
592 LONG cmp = MONTHCAL_CompareMonths(date, &st);
596 *col = (first - MONTHCAL_MonthLength(date->wMonth, cal->wYear) + date->wDay) % 7;
601 /* next month calculation is same as for current, just add current month length */
603 first += MONTHCAL_MonthLength(cal->wMonth, cal->wYear);
606 *col = (date->wDay + first) % 7;
607 *row = (date->wDay + first - *col) / 7;
610 /* returns bounding box for day in given position in given calendar */
611 static inline void MONTHCAL_GetDayRectI(const MONTHCAL_INFO *infoPtr, RECT *r,
612 INT col, INT row, INT calIdx)
614 r->left = infoPtr->calendars[calIdx].days.left + col * infoPtr->width_increment;
615 r->right = r->left + infoPtr->width_increment;
616 r->top = infoPtr->calendars[calIdx].days.top + row * infoPtr->height_increment;
617 r->bottom = r->top + infoPtr->textHeight;
620 /* Returns bounding box for given date
622 * NOTE: when calendar index is unknown pass -1
624 static inline void MONTHCAL_GetDayRect(const MONTHCAL_INFO *infoPtr, const SYSTEMTIME *date,
631 INT cmp = MONTHCAL_CompareMonths(date, &infoPtr->calendars[0].month);
637 cmp = MONTHCAL_CompareMonths(date, &infoPtr->calendars[MONTHCAL_GetCalCount(infoPtr)-1].month);
639 calIdx = MONTHCAL_GetCalCount(infoPtr)-1;
642 for (calIdx = 1; calIdx < MONTHCAL_GetCalCount(infoPtr)-1; calIdx++)
643 if (MONTHCAL_CompareMonths(date, &infoPtr->calendars[calIdx].month) == 0)
649 MONTHCAL_GetDayPos(infoPtr, date, &col, &row, calIdx);
650 MONTHCAL_GetDayRectI(infoPtr, r, col, row, calIdx);
653 /* Focused day helper:
655 - set focused date to given value;
656 - reset to zero value if NULL passed;
657 - invalidate previous and new day rectangle only if needed.
659 Returns TRUE if focused day changed, FALSE otherwise.
661 static BOOL MONTHCAL_SetDayFocus(MONTHCAL_INFO *infoPtr, const SYSTEMTIME *st)
667 /* there's nothing to do if it's the same date,
668 mouse move within same date rectangle case */
669 if(MONTHCAL_IsDateEqual(&infoPtr->focusedSel, st)) return FALSE;
671 /* invalidate old focused day */
672 MONTHCAL_GetDayRect(infoPtr, &infoPtr->focusedSel, &r, -1);
673 InvalidateRect(infoPtr->hwndSelf, &r, FALSE);
675 infoPtr->focusedSel = *st;
678 MONTHCAL_GetDayRect(infoPtr, &infoPtr->focusedSel, &r, -1);
680 if(!st && MONTHCAL_ValidateDate(&infoPtr->focusedSel))
681 infoPtr->focusedSel = st_null;
683 /* on set invalidates new day, on reset clears previous focused day */
684 InvalidateRect(infoPtr->hwndSelf, &r, FALSE);
689 /* draw today boundary box for specified rectangle */
690 static void MONTHCAL_Circle(const MONTHCAL_INFO *infoPtr, HDC hdc, const RECT *r)
692 HPEN old_pen = SelectObject(hdc, infoPtr->pens[PenRed]);
695 old_brush = SelectObject(hdc, GetStockObject(NULL_BRUSH));
696 Rectangle(hdc, r->left, r->top, r->right, r->bottom);
698 SelectObject(hdc, old_brush);
699 SelectObject(hdc, old_pen);
702 /* Draw today day mark rectangle
704 * [I] hdc : context to draw in
705 * [I] date : day to mark with rectangle
708 static void MONTHCAL_CircleDay(const MONTHCAL_INFO *infoPtr, HDC hdc,
709 const SYSTEMTIME *date)
713 MONTHCAL_GetDayRect(infoPtr, date, &r, -1);
714 MONTHCAL_Circle(infoPtr, hdc, &r);
717 static void MONTHCAL_DrawDay(const MONTHCAL_INFO *infoPtr, HDC hdc, const SYSTEMTIME *st,
718 int bold, const PAINTSTRUCT *ps)
720 static const WCHAR fmtW[] = { '%','d',0 };
725 INT old_bkmode, selection;
727 /* no need to check styles: when selection is not valid, it is set to zero.
728 1 < day < 31, so everything is OK */
729 MONTHCAL_GetDayRect(infoPtr, st, &r, -1);
730 if(!IntersectRect(&r_temp, &(ps->rcPaint), &r)) return;
732 if ((MONTHCAL_CompareDate(st, &infoPtr->minSel) >= 0) &&
733 (MONTHCAL_CompareDate(st, &infoPtr->maxSel) <= 0))
735 TRACE("%d %d %d\n", st->wDay, infoPtr->minSel.wDay, infoPtr->maxSel.wDay);
736 TRACE("%s\n", wine_dbgstr_rect(&r));
737 oldCol = SetTextColor(hdc, infoPtr->colors[MCSC_MONTHBK]);
738 oldBk = SetBkColor(hdc, infoPtr->colors[MCSC_TRAILINGTEXT]);
739 FillRect(hdc, &r, infoPtr->brushes[BrushTitle]);
746 SelectObject(hdc, bold ? infoPtr->hBoldFont : infoPtr->hFont);
748 old_bkmode = SetBkMode(hdc, TRANSPARENT);
749 wsprintfW(buf, fmtW, st->wDay);
750 DrawTextW(hdc, buf, -1, &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE );
751 SetBkMode(hdc, old_bkmode);
755 SetTextColor(hdc, oldCol);
756 SetBkColor(hdc, oldBk);
760 static void MONTHCAL_PaintButton(MONTHCAL_INFO *infoPtr, HDC hdc, enum nav_direction button)
762 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
763 RECT *r = button == DIRECTION_FORWARD ? &infoPtr->titlebtnnext : &infoPtr->titlebtnprev;
764 BOOL pressed = button == DIRECTION_FORWARD ? infoPtr->status & MC_NEXTPRESSED :
765 infoPtr->status & MC_PREVPRESSED;
768 static const int states[] = {
770 ABS_LEFTNORMAL, ABS_LEFTPRESSED, ABS_LEFTDISABLED,
772 ABS_RIGHTNORMAL, ABS_RIGHTPRESSED, ABS_RIGHTDISABLED
774 int stateNum = button == DIRECTION_FORWARD ? 3 : 0;
779 if (infoPtr->dwStyle & WS_DISABLED) stateNum += 2;
781 DrawThemeBackground (theme, hdc, SBP_ARROWBTN, states[stateNum], r, NULL);
785 int style = button == DIRECTION_FORWARD ? DFCS_SCROLLRIGHT : DFCS_SCROLLLEFT;
787 style |= DFCS_PUSHED;
790 if (infoPtr->dwStyle & WS_DISABLED) style |= DFCS_INACTIVE;
793 DrawFrameControl(hdc, r, DFC_SCROLL, style);
797 /* paint a title with buttons and month/year string */
798 static void MONTHCAL_PaintTitle(MONTHCAL_INFO *infoPtr, HDC hdc, const PAINTSTRUCT *ps, INT calIdx)
800 static const WCHAR fmt_monthW[] = { '%','s',' ','%','l','d',0 };
801 RECT *title = &infoPtr->calendars[calIdx].title;
802 const SYSTEMTIME *st = &infoPtr->calendars[calIdx].month;
803 WCHAR buf_month[80], buf_fmt[80];
806 /* fill header box */
807 FillRect(hdc, title, infoPtr->brushes[BrushTitle]);
809 /* month/year string */
810 SetBkColor(hdc, infoPtr->colors[MCSC_TITLEBK]);
811 SetTextColor(hdc, infoPtr->colors[MCSC_TITLETEXT]);
812 SelectObject(hdc, infoPtr->hBoldFont);
814 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SMONTHNAME1 + st->wMonth - 1,
815 buf_month, countof(buf_month));
817 wsprintfW(buf_fmt, fmt_monthW, buf_month, st->wYear);
818 DrawTextW(hdc, buf_fmt, strlenW(buf_fmt), title,
819 DT_CENTER | DT_VCENTER | DT_SINGLELINE);
821 /* update title rectangles with current month - used while testing hits */
822 GetTextExtentPoint32W(hdc, buf_fmt, strlenW(buf_fmt), &sz);
823 infoPtr->calendars[calIdx].titlemonth.left = title->right / 2 + title->left / 2 - sz.cx / 2;
824 infoPtr->calendars[calIdx].titleyear.right = title->right / 2 + title->left / 2 + sz.cx / 2;
826 GetTextExtentPoint32W(hdc, buf_month, strlenW(buf_month), &sz);
827 infoPtr->calendars[calIdx].titlemonth.right = infoPtr->calendars[calIdx].titlemonth.left + sz.cx;
828 infoPtr->calendars[calIdx].titleyear.left = infoPtr->calendars[calIdx].titlemonth.right;
831 static void MONTHCAL_PaintWeeknumbers(const MONTHCAL_INFO *infoPtr, HDC hdc, const PAINTSTRUCT *ps, INT calIdx)
833 const SYSTEMTIME *date = &infoPtr->calendars[calIdx].month;
834 static const WCHAR fmt_weekW[] = { '%','d',0 };
835 INT mindays, weeknum, weeknum1, startofprescal;
842 if (!(infoPtr->dwStyle & MCS_WEEKNUMBERS)) return;
844 MONTHCAL_GetMinDate(infoPtr, &st);
845 startofprescal = st.wDay;
848 prev_month = date->wMonth - 1;
849 if(prev_month == 0) prev_month = 12;
852 Rules what week to call the first week of a new year:
853 LOCALE_IFIRSTWEEKOFYEAR == 0 (e.g US?):
854 The week containing Jan 1 is the first week of year
855 LOCALE_IFIRSTWEEKOFYEAR == 2 (e.g. Germany):
856 First week of year must contain 4 days of the new year
857 LOCALE_IFIRSTWEEKOFYEAR == 1 (what countries?)
858 The first week of the year must contain only days of the new year
860 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_IFIRSTWEEKOFYEAR, buf, countof(buf));
861 weeknum = atoiW(buf);
871 WARN("Unknown LOCALE_IFIRSTWEEKOFYEAR value %d, defaulting to 0\n", weeknum);
875 if (date->wMonth == 1)
877 /* calculate all those exceptions for January */
878 st.wDay = st.wMonth = 1;
879 weeknum1 = MONTHCAL_CalculateDayOfWeek(&st, FALSE);
880 if ((infoPtr->firstDay - weeknum1) % 7 > mindays)
885 for(i = 0; i < 11; i++)
886 weeknum += MONTHCAL_MonthLength(i+1, date->wYear - 1);
888 weeknum += startofprescal + 7;
891 weeknum1 = MONTHCAL_CalculateDayOfWeek(&st, FALSE);
892 if ((infoPtr->firstDay - weeknum1) % 7 > mindays) weeknum++;
898 for(i = 0; i < prev_month - 1; i++)
899 weeknum += MONTHCAL_MonthLength(i+1, date->wYear);
901 weeknum += startofprescal + 7;
903 st.wDay = st.wMonth = 1;
904 weeknum1 = MONTHCAL_CalculateDayOfWeek(&st, FALSE);
905 if ((infoPtr->firstDay - weeknum1) % 7 > mindays) weeknum++;
908 r = infoPtr->calendars[calIdx].weeknums;
910 /* erase whole week numbers area */
911 FillRect(hdc, &r, infoPtr->brushes[BrushTitle]);
912 SetTextColor(hdc, infoPtr->colors[MCSC_TITLEBK]);
914 /* reduce rectangle to one week number */
915 r.bottom = r.top + infoPtr->height_increment;
917 for(i = 0; i < 6; i++) {
918 if((i == 0) && (weeknum > 50))
920 wsprintfW(buf, fmt_weekW, weeknum);
923 else if((i == 5) && (weeknum > 47))
925 wsprintfW(buf, fmt_weekW, 1);
928 wsprintfW(buf, fmt_weekW, weeknum + i);
930 DrawTextW(hdc, buf, -1, &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
931 OffsetRect(&r, 0, infoPtr->height_increment);
934 /* line separator for week numbers column */
935 old_pen = SelectObject(hdc, infoPtr->pens[PenText]);
936 MoveToEx(hdc, infoPtr->calendars[calIdx].weeknums.right, infoPtr->calendars[calIdx].weeknums.top + 3 , NULL);
937 LineTo(hdc, infoPtr->calendars[calIdx].weeknums.right, infoPtr->calendars[calIdx].weeknums.bottom);
938 SelectObject(hdc, old_pen);
941 /* bottom today date */
942 static void MONTHCAL_PaintTodayTitle(const MONTHCAL_INFO *infoPtr, HDC hdc, const PAINTSTRUCT *ps)
944 static const WCHAR fmt_todayW[] = { '%','s',' ','%','s',0 };
945 WCHAR buf_todayW[30], buf_dateW[20], buf[80];
946 RECT text_rect, box_rect;
950 if(infoPtr->dwStyle & MCS_NOTODAY) return;
952 if (!LoadStringW(COMCTL32_hModule, IDM_TODAY, buf_todayW, countof(buf_todayW)))
954 static const WCHAR todayW[] = { 'T','o','d','a','y',':',0 };
955 WARN("Can't load resource\n");
956 strcpyW(buf_todayW, todayW);
959 col = infoPtr->dwStyle & MCS_NOTODAYCIRCLE ? 0 : 1;
960 if (infoPtr->dwStyle & MCS_WEEKNUMBERS) col--;
961 /* TODO: when multiple calendars layout is calculated use first column/last row calendar for that
962 imaginary day position */
963 MONTHCAL_GetDayRectI(infoPtr, &text_rect, col, 6, 0);
964 box_rect = text_rect;
966 GetDateFormatW(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &infoPtr->todaysDate, NULL,
967 buf_dateW, countof(buf_dateW));
968 old_font = SelectObject(hdc, infoPtr->hBoldFont);
969 SetTextColor(hdc, infoPtr->colors[MCSC_TEXT]);
971 wsprintfW(buf, fmt_todayW, buf_todayW, buf_dateW);
972 DrawTextW(hdc, buf, -1, &text_rect, DT_CALCRECT | DT_LEFT | DT_VCENTER | DT_SINGLELINE);
973 DrawTextW(hdc, buf, -1, &text_rect, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
975 if(!(infoPtr->dwStyle & MCS_NOTODAYCIRCLE)) {
976 OffsetRect(&box_rect, -infoPtr->width_increment, 0);
977 MONTHCAL_Circle(infoPtr, hdc, &box_rect);
980 SelectObject(hdc, old_font);
983 /* today mark + focus */
984 static void MONTHCAL_PaintFocusAndCircle(const MONTHCAL_INFO *infoPtr, HDC hdc, const PAINTSTRUCT *ps)
986 if((infoPtr->minSel.wMonth == infoPtr->todaysDate.wMonth) &&
987 (infoPtr->minSel.wYear == infoPtr->todaysDate.wYear) &&
988 !(infoPtr->dwStyle & MCS_NOTODAYCIRCLE))
990 MONTHCAL_CircleDay(infoPtr, hdc, &infoPtr->todaysDate);
993 if(!MONTHCAL_IsDateEqual(&infoPtr->focusedSel, &st_null))
996 MONTHCAL_GetDayRect(infoPtr, &infoPtr->focusedSel, &r, -1);
997 DrawFocusRect(hdc, &r);
1001 /* months before first calendar month and after last calendar month */
1002 static void MONTHCAL_PaintLeadTrailMonths(const MONTHCAL_INFO *infoPtr, HDC hdc, const PAINTSTRUCT *ps)
1005 SYSTEMTIME st_max, st;
1007 if (infoPtr->dwStyle & MCS_NOTRAILINGDATES) return;
1009 SetTextColor(hdc, infoPtr->colors[MCSC_TRAILINGTEXT]);
1011 /* draw prev month */
1012 MONTHCAL_GetMinDate(infoPtr, &st);
1013 mask = 1 << (st.wDay-1);
1014 /* December and January both 31 days long, so no worries if wrapped */
1015 length = MONTHCAL_MonthLength(infoPtr->calendars[0].month.wMonth - 1,
1016 infoPtr->calendars[0].month.wYear);
1017 while(st.wDay <= length)
1019 MONTHCAL_DrawDay(infoPtr, hdc, &st, infoPtr->monthdayState[0] & mask, ps);
1024 /* draw next month */
1025 st = infoPtr->calendars[MONTHCAL_GetCalCount(infoPtr)-1].month;
1027 MONTHCAL_GetNextMonth(&st);
1028 MONTHCAL_GetMaxDate(infoPtr, &st_max);
1031 while(st.wDay <= st_max.wDay)
1033 MONTHCAL_DrawDay(infoPtr, hdc, &st, infoPtr->monthdayState[2] & mask, ps);
1039 /* paint a calendar area */
1040 static void MONTHCAL_PaintCalendar(const MONTHCAL_INFO *infoPtr, HDC hdc, const PAINTSTRUCT *ps, INT calIdx)
1042 const SYSTEMTIME *date = &infoPtr->calendars[calIdx].month;
1044 RECT r, fill_bk_rect;
1050 /* fill whole days area - from week days area to today note rectangle */
1051 fill_bk_rect = infoPtr->calendars[calIdx].wdays;
1052 fill_bk_rect.bottom = infoPtr->calendars[calIdx].days.bottom +
1053 (infoPtr->todayrect.bottom - infoPtr->todayrect.top);
1055 FillRect(hdc, &fill_bk_rect, infoPtr->brushes[BrushMonth]);
1057 /* draw line under day abbreviations */
1058 old_pen = SelectObject(hdc, infoPtr->pens[PenText]);
1059 MoveToEx(hdc, infoPtr->calendars[calIdx].days.left + 3,
1060 infoPtr->calendars[calIdx].title.bottom + infoPtr->textHeight + 1, NULL);
1061 LineTo(hdc, infoPtr->calendars[calIdx].days.right - 3,
1062 infoPtr->calendars[calIdx].title.bottom + infoPtr->textHeight + 1);
1063 SelectObject(hdc, old_pen);
1065 infoPtr->calendars[calIdx].wdays.left = infoPtr->calendars[calIdx].days.left =
1066 infoPtr->calendars[calIdx].weeknums.right;
1068 /* draw day abbreviations */
1069 SelectObject(hdc, infoPtr->hFont);
1070 SetBkColor(hdc, infoPtr->colors[MCSC_MONTHBK]);
1071 SetTextColor(hdc, infoPtr->colors[MCSC_TITLEBK]);
1072 /* rectangle to draw a single day abbreviation within */
1073 r = infoPtr->calendars[calIdx].wdays;
1074 r.right = r.left + infoPtr->width_increment;
1076 i = infoPtr->firstDay;
1077 for(j = 0; j < 7; j++) {
1078 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SABBREVDAYNAME1 + (i+j+6)%7, buf, countof(buf));
1079 DrawTextW(hdc, buf, strlenW(buf), &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
1080 OffsetRect(&r, infoPtr->width_increment, 0);
1083 /* draw current month */
1084 SetTextColor(hdc, infoPtr->colors[MCSC_TEXT]);
1088 length = MONTHCAL_MonthLength(date->wMonth, date->wYear);
1089 while(st.wDay <= length)
1091 MONTHCAL_DrawDay(infoPtr, hdc, &st, infoPtr->monthdayState[1] & mask, ps);
1097 static void MONTHCAL_Refresh(MONTHCAL_INFO *infoPtr, HDC hdc, const PAINTSTRUCT *ps)
1099 COLORREF old_text_clr, old_bk_clr;
1103 old_text_clr = SetTextColor(hdc, comctl32_color.clrWindowText);
1104 old_bk_clr = GetBkColor(hdc);
1105 old_font = GetCurrentObject(hdc, OBJ_FONT);
1107 for (i = 0; i < MONTHCAL_GetCalCount(infoPtr); i++)
1109 RECT *title = &infoPtr->calendars[i].title;
1112 /* draw title, redraw all its elements */
1113 if (IntersectRect(&r, &(ps->rcPaint), title))
1114 MONTHCAL_PaintTitle(infoPtr, hdc, ps, i);
1116 /* draw calendar area */
1117 UnionRect(&r, &infoPtr->calendars[i].wdays, &infoPtr->todayrect);
1118 if (IntersectRect(&r, &(ps->rcPaint), &r))
1119 MONTHCAL_PaintCalendar(infoPtr, hdc, ps, i);
1122 MONTHCAL_PaintWeeknumbers(infoPtr, hdc, ps, i);
1125 /* partially visible months */
1126 MONTHCAL_PaintLeadTrailMonths(infoPtr, hdc, ps);
1128 /* focus and today rectangle */
1129 MONTHCAL_PaintFocusAndCircle(infoPtr, hdc, ps);
1131 /* today at the bottom left */
1132 MONTHCAL_PaintTodayTitle(infoPtr, hdc, ps);
1134 /* navigation buttons */
1135 MONTHCAL_PaintButton(infoPtr, hdc, DIRECTION_BACKWARD);
1136 MONTHCAL_PaintButton(infoPtr, hdc, DIRECTION_FORWARD);
1138 /* restore context */
1139 SetBkColor(hdc, old_bk_clr);
1140 SelectObject(hdc, old_font);
1141 SetTextColor(hdc, old_text_clr);
1145 MONTHCAL_GetMinReqRect(const MONTHCAL_INFO *infoPtr, RECT *rect)
1147 TRACE("rect %p\n", rect);
1149 if(!rect) return FALSE;
1151 *rect = infoPtr->calendars[0].title;
1152 rect->bottom = infoPtr->calendars[0].days.bottom + infoPtr->todayrect.bottom -
1153 infoPtr->todayrect.top;
1155 AdjustWindowRect(rect, infoPtr->dwStyle, FALSE);
1157 /* minimal rectangle is zero based */
1158 OffsetRect(rect, -rect->left, -rect->top);
1160 TRACE("%s\n", wine_dbgstr_rect(rect));
1166 MONTHCAL_GetColor(const MONTHCAL_INFO *infoPtr, UINT index)
1168 TRACE("%p, %d\n", infoPtr, index);
1170 if (index > MCSC_TRAILINGTEXT) return -1;
1171 return infoPtr->colors[index];
1175 MONTHCAL_SetColor(MONTHCAL_INFO *infoPtr, UINT index, COLORREF color)
1177 enum CachedBrush type;
1180 TRACE("%p, %d: color %08x\n", infoPtr, index, color);
1182 if (index > MCSC_TRAILINGTEXT) return -1;
1184 prev = infoPtr->colors[index];
1185 infoPtr->colors[index] = color;
1187 /* update cached brush */
1190 case MCSC_BACKGROUND:
1191 type = BrushBackground;
1203 if (type != BrushLast)
1205 DeleteObject(infoPtr->brushes[type]);
1206 infoPtr->brushes[type] = CreateSolidBrush(color);
1209 /* update cached pen */
1210 if (index == MCSC_TEXT)
1212 DeleteObject(infoPtr->pens[PenText]);
1213 infoPtr->pens[PenText] = CreatePen(PS_SOLID, 1, infoPtr->colors[index]);
1216 InvalidateRect(infoPtr->hwndSelf, NULL, index == MCSC_BACKGROUND ? TRUE : FALSE);
1221 MONTHCAL_GetMonthDelta(const MONTHCAL_INFO *infoPtr)
1226 return infoPtr->delta;
1228 return infoPtr->visible;
1233 MONTHCAL_SetMonthDelta(MONTHCAL_INFO *infoPtr, INT delta)
1235 INT prev = infoPtr->delta;
1237 TRACE("delta %d\n", delta);
1239 infoPtr->delta = delta;
1244 static inline LRESULT
1245 MONTHCAL_GetFirstDayOfWeek(const MONTHCAL_INFO *infoPtr)
1249 /* convert from SYSTEMTIME to locale format */
1250 day = (infoPtr->firstDay >= 0) ? (infoPtr->firstDay+6)%7 : infoPtr->firstDay;
1252 return MAKELONG(day, infoPtr->firstDaySet);
1256 /* Sets the first day of the week that will appear in the control
1260 * [I] infoPtr : valid pointer to control data
1261 * [I] day : day number to set as new first day (0 == Monday,...,6 == Sunday)
1265 * Low word contains previous first day,
1266 * high word indicates was first day forced with this message before or is
1267 * locale defined (TRUE - was forced, FALSE - wasn't).
1269 * FIXME: this needs to be implemented properly in MONTHCAL_Refresh()
1270 * FIXME: we need more error checking here
1273 MONTHCAL_SetFirstDayOfWeek(MONTHCAL_INFO *infoPtr, INT day)
1275 LRESULT prev = MONTHCAL_GetFirstDayOfWeek(infoPtr);
1284 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_IFIRSTDAYOFWEEK, buf, countof(buf));
1285 TRACE("%s %d\n", debugstr_w(buf), strlenW(buf));
1287 new_day = atoiW(buf);
1289 infoPtr->firstDaySet = FALSE;
1293 new_day = 6; /* max first day allowed */
1294 infoPtr->firstDaySet = TRUE;
1298 /* Native behaviour for that case is broken: invalid date number >31
1299 got displayed at (0,0) position, current month starts always from
1300 (1,0) position. Should be implemented here as well only if there's
1301 nothing else to do. */
1303 FIXME("No bug compatibility for day=%d\n", day);
1306 infoPtr->firstDaySet = TRUE;
1309 /* convert from locale to SYSTEMTIME format */
1310 infoPtr->firstDay = (new_day >= 0) ? (++new_day) % 7 : new_day;
1312 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1319 MONTHCAL_GetMonthRange(const MONTHCAL_INFO *infoPtr, DWORD flag, SYSTEMTIME *st)
1321 TRACE("flag=%d, st=%p\n", flag, st);
1328 st[0] = infoPtr->calendars[0].month;
1329 st[1] = infoPtr->calendars[MONTHCAL_GetCalCount(infoPtr)-1].month;
1331 if (st[0].wMonth == min_allowed_date.wMonth &&
1332 st[0].wYear == min_allowed_date.wYear)
1334 st[0].wDay = min_allowed_date.wDay;
1338 MONTHCAL_CalculateDayOfWeek(&st[0], TRUE);
1340 st[1].wDay = MONTHCAL_MonthLength(st[1].wMonth, st[1].wYear);
1341 MONTHCAL_CalculateDayOfWeek(&st[1], TRUE);
1343 return MONTHCAL_GetCalCount(infoPtr);
1347 MONTHCAL_GetMinDate(infoPtr, &st[0]);
1348 MONTHCAL_GetMaxDate(infoPtr, &st[1]);
1352 WARN("Unknown flag value, got %d\n", flag);
1356 return infoPtr->monthRange;
1361 MONTHCAL_GetMaxTodayWidth(const MONTHCAL_INFO *infoPtr)
1363 return(infoPtr->todayrect.right - infoPtr->todayrect.left);
1368 MONTHCAL_SetRange(MONTHCAL_INFO *infoPtr, SHORT limits, SYSTEMTIME *range)
1370 FILETIME ft_min, ft_max;
1372 TRACE("%x %p\n", limits, range);
1374 if ((limits & GDTR_MIN && !MONTHCAL_ValidateDate(&range[0])) ||
1375 (limits & GDTR_MAX && !MONTHCAL_ValidateDate(&range[1])))
1378 if (limits & GDTR_MIN)
1380 if (!MONTHCAL_ValidateTime(&range[0]))
1381 MONTHCAL_CopyTime(&infoPtr->todaysDate, &range[0]);
1383 infoPtr->minDate = range[0];
1384 infoPtr->rangeValid |= GDTR_MIN;
1386 if (limits & GDTR_MAX)
1388 if (!MONTHCAL_ValidateTime(&range[1]))
1389 MONTHCAL_CopyTime(&infoPtr->todaysDate, &range[1]);
1391 infoPtr->maxDate = range[1];
1392 infoPtr->rangeValid |= GDTR_MAX;
1395 /* Only one limit set - we are done */
1396 if ((infoPtr->rangeValid & (GDTR_MIN | GDTR_MAX)) != (GDTR_MIN | GDTR_MAX))
1399 SystemTimeToFileTime(&infoPtr->maxDate, &ft_max);
1400 SystemTimeToFileTime(&infoPtr->minDate, &ft_min);
1402 if (CompareFileTime(&ft_min, &ft_max) >= 0)
1404 if ((limits & (GDTR_MIN | GDTR_MAX)) == (GDTR_MIN | GDTR_MAX))
1406 /* Native swaps limits only when both limits are being set. */
1407 SYSTEMTIME st_tmp = infoPtr->minDate;
1408 infoPtr->minDate = infoPtr->maxDate;
1409 infoPtr->maxDate = st_tmp;
1413 /* reset the other limit */
1414 if (limits & GDTR_MIN) infoPtr->maxDate = st_null;
1415 if (limits & GDTR_MAX) infoPtr->minDate = st_null;
1416 infoPtr->rangeValid &= limits & GDTR_MIN ? ~GDTR_MAX : ~GDTR_MIN;
1425 MONTHCAL_GetRange(const MONTHCAL_INFO *infoPtr, SYSTEMTIME *range)
1427 TRACE("%p\n", range);
1429 if(!range) return FALSE;
1431 range[1] = infoPtr->maxDate;
1432 range[0] = infoPtr->minDate;
1434 return infoPtr->rangeValid;
1439 MONTHCAL_SetDayState(const MONTHCAL_INFO *infoPtr, INT months, MONTHDAYSTATE *states)
1441 TRACE("%p %d %p\n", infoPtr, months, states);
1442 if(months != infoPtr->monthRange) return 0;
1444 memcpy(infoPtr->monthdayState, states, months*sizeof(MONTHDAYSTATE));
1450 MONTHCAL_GetCurSel(const MONTHCAL_INFO *infoPtr, SYSTEMTIME *curSel)
1452 TRACE("%p\n", curSel);
1453 if(!curSel) return FALSE;
1454 if(infoPtr->dwStyle & MCS_MULTISELECT) return FALSE;
1456 *curSel = infoPtr->minSel;
1457 TRACE("%d/%d/%d\n", curSel->wYear, curSel->wMonth, curSel->wDay);
1462 MONTHCAL_SetCurSel(MONTHCAL_INFO *infoPtr, SYSTEMTIME *curSel)
1464 SYSTEMTIME prev = infoPtr->minSel;
1467 TRACE("%p\n", curSel);
1468 if(!curSel) return FALSE;
1469 if(infoPtr->dwStyle & MCS_MULTISELECT) return FALSE;
1471 if(!MONTHCAL_ValidateDate(curSel)) return FALSE;
1472 /* exit earlier if selection equals current */
1473 if (MONTHCAL_IsDateEqual(&infoPtr->minSel, curSel)) return TRUE;
1475 if(!MONTHCAL_IsDateInValidRange(infoPtr, curSel, FALSE)) return FALSE;
1477 infoPtr->calendars[0].month = *curSel;
1478 infoPtr->minSel = *curSel;
1479 infoPtr->maxSel = *curSel;
1481 /* if selection is still in current month, reduce rectangle */
1483 prev.wDay = curSel->wDay;
1484 if (MONTHCAL_IsDateEqual(&prev, curSel))
1489 MONTHCAL_GetDayRect(infoPtr, &prev, &r_prev, -1);
1490 MONTHCAL_GetDayRect(infoPtr, curSel, &r_new, -1);
1492 InvalidateRect(infoPtr->hwndSelf, &r_prev, FALSE);
1493 InvalidateRect(infoPtr->hwndSelf, &r_new, FALSE);
1496 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1503 MONTHCAL_GetMaxSelCount(const MONTHCAL_INFO *infoPtr)
1505 return infoPtr->maxSelCount;
1510 MONTHCAL_SetMaxSelCount(MONTHCAL_INFO *infoPtr, INT max)
1514 if(!(infoPtr->dwStyle & MCS_MULTISELECT)) return FALSE;
1515 if(max <= 0) return FALSE;
1517 infoPtr->maxSelCount = max;
1524 MONTHCAL_GetSelRange(const MONTHCAL_INFO *infoPtr, SYSTEMTIME *range)
1526 TRACE("%p\n", range);
1528 if(!range) return FALSE;
1530 if(infoPtr->dwStyle & MCS_MULTISELECT)
1532 range[1] = infoPtr->maxSel;
1533 range[0] = infoPtr->minSel;
1534 TRACE("[min,max]=[%d %d]\n", infoPtr->minSel.wDay, infoPtr->maxSel.wDay);
1543 MONTHCAL_SetSelRange(MONTHCAL_INFO *infoPtr, SYSTEMTIME *range)
1545 TRACE("%p\n", range);
1547 if(!range) return FALSE;
1549 if(infoPtr->dwStyle & MCS_MULTISELECT)
1551 SYSTEMTIME old_range[2];
1553 /* adjust timestamps */
1554 if(!MONTHCAL_ValidateTime(&range[0]))
1555 MONTHCAL_CopyTime(&infoPtr->todaysDate, &range[0]);
1556 if(!MONTHCAL_ValidateTime(&range[1]))
1557 MONTHCAL_CopyTime(&infoPtr->todaysDate, &range[1]);
1559 /* maximum range exceeded */
1560 if(!MONTHCAL_IsSelRangeValid(infoPtr, &range[0], &range[1], NULL)) return FALSE;
1562 old_range[0] = infoPtr->minSel;
1563 old_range[1] = infoPtr->maxSel;
1565 /* swap if min > max */
1566 if(MONTHCAL_CompareSystemTime(&range[0], &range[1]) <= 0)
1568 infoPtr->minSel = range[0];
1569 infoPtr->maxSel = range[1];
1573 infoPtr->minSel = range[1];
1574 infoPtr->maxSel = range[0];
1576 infoPtr->calendars[0].month = infoPtr->minSel;
1578 /* update day of week */
1579 MONTHCAL_CalculateDayOfWeek(&infoPtr->minSel, TRUE);
1580 MONTHCAL_CalculateDayOfWeek(&infoPtr->maxSel, TRUE);
1582 /* redraw if bounds changed */
1583 /* FIXME: no actual need to redraw everything */
1584 if(!MONTHCAL_IsDateEqual(&old_range[0], &range[0]) ||
1585 !MONTHCAL_IsDateEqual(&old_range[1], &range[1]))
1587 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1590 TRACE("[min,max]=[%d %d]\n", infoPtr->minSel.wDay, infoPtr->maxSel.wDay);
1599 MONTHCAL_GetToday(const MONTHCAL_INFO *infoPtr, SYSTEMTIME *today)
1601 TRACE("%p\n", today);
1603 if(!today) return FALSE;
1604 *today = infoPtr->todaysDate;
1608 /* Internal helper for MCM_SETTODAY handler and auto update timer handler
1612 * TRUE - today date changed
1613 * FALSE - today date isn't changed
1616 MONTHCAL_UpdateToday(MONTHCAL_INFO *infoPtr, const SYSTEMTIME *today)
1620 if(MONTHCAL_IsDateEqual(today, &infoPtr->todaysDate)) return FALSE;
1622 MONTHCAL_GetDayRect(infoPtr, &infoPtr->todaysDate, &old_r, -1);
1623 MONTHCAL_GetDayRect(infoPtr, today, &new_r, -1);
1625 infoPtr->todaysDate = *today;
1627 /* only two days need redrawing */
1628 InvalidateRect(infoPtr->hwndSelf, &old_r, FALSE);
1629 InvalidateRect(infoPtr->hwndSelf, &new_r, FALSE);
1633 /* MCM_SETTODAT handler */
1635 MONTHCAL_SetToday(MONTHCAL_INFO *infoPtr, const SYSTEMTIME *today)
1637 TRACE("%p\n", today);
1639 if(!today) return FALSE;
1641 /* remember if date was set successfully */
1642 if(MONTHCAL_UpdateToday(infoPtr, today)) infoPtr->todaySet = TRUE;
1647 /* returns calendar index containing specified point, or -1 if it's background */
1648 static INT MONTHCAL_GetCalendarFromPoint(const MONTHCAL_INFO *infoPtr, const POINT *pt)
1653 for (i = 0; i < MONTHCAL_GetCalCount(infoPtr); i++)
1655 /* whole bounding rectangle allows some optimization to compute */
1656 r.left = infoPtr->calendars[i].title.left;
1657 r.top = infoPtr->calendars[i].title.top;
1658 r.bottom = infoPtr->calendars[i].days.bottom;
1659 r.right = infoPtr->calendars[i].days.right;
1661 if (PtInRect(&r, *pt)) return i;
1667 static inline UINT fill_hittest_info(const MCHITTESTINFO *src, MCHITTESTINFO *dest)
1669 dest->uHit = src->uHit;
1672 if (dest->cbSize == sizeof(MCHITTESTINFO))
1673 memcpy(&dest->rc, &src->rc, sizeof(MCHITTESTINFO) - MCHITTESTINFO_V1_SIZE);
1679 MONTHCAL_HitTest(const MONTHCAL_INFO *infoPtr, MCHITTESTINFO *lpht)
1681 MCHITTESTINFO htinfo;
1682 SYSTEMTIME ht_month;
1685 if(!lpht || lpht->cbSize < MCHITTESTINFO_V1_SIZE) return -1;
1687 htinfo.st = st_null;
1689 /* we should preserve passed fields if hit area doesn't need them */
1690 if (lpht->cbSize == sizeof(MCHITTESTINFO))
1691 memcpy(&htinfo.rc, &lpht->rc, sizeof(MCHITTESTINFO) - MCHITTESTINFO_V1_SIZE);
1693 /* Comment in for debugging...
1694 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,
1695 infoPtr->wdays.left, infoPtr->wdays.right,
1696 infoPtr->wdays.top, infoPtr->wdays.bottom,
1697 infoPtr->days.left, infoPtr->days.right,
1698 infoPtr->days.top, infoPtr->days.bottom,
1699 infoPtr->todayrect.left, infoPtr->todayrect.right,
1700 infoPtr->todayrect.top, infoPtr->todayrect.bottom,
1701 infoPtr->weeknums.left, infoPtr->weeknums.right,
1702 infoPtr->weeknums.top, infoPtr->weeknums.bottom);
1705 /* guess in what calendar we are */
1706 calIdx = MONTHCAL_GetCalendarFromPoint(infoPtr, &lpht->pt);
1709 if (PtInRect(&infoPtr->todayrect, lpht->pt))
1711 htinfo.uHit = MCHT_TODAYLINK;
1712 htinfo.rc = infoPtr->todayrect;
1715 /* outside of calendar area? What's left must be background :-) */
1716 htinfo.uHit = MCHT_CALENDARBK;
1718 return fill_hittest_info(&htinfo, lpht);
1721 ht_month = infoPtr->calendars[calIdx].month;
1723 /* are we in the header? */
1724 if (PtInRect(&infoPtr->calendars[calIdx].title, lpht->pt)) {
1725 /* FIXME: buttons hittesting could be optimized cause maximum
1726 two calendars have buttons */
1727 if (calIdx == 0 && PtInRect(&infoPtr->titlebtnprev, lpht->pt))
1729 htinfo.uHit = MCHT_TITLEBTNPREV;
1730 htinfo.rc = infoPtr->titlebtnprev;
1732 else if (PtInRect(&infoPtr->titlebtnnext, lpht->pt))
1734 htinfo.uHit = MCHT_TITLEBTNNEXT;
1735 htinfo.rc = infoPtr->titlebtnnext;
1737 else if (PtInRect(&infoPtr->calendars[calIdx].titlemonth, lpht->pt))
1739 htinfo.uHit = MCHT_TITLEMONTH;
1740 htinfo.rc = infoPtr->calendars[calIdx].titlemonth;
1741 htinfo.iOffset = calIdx;
1743 else if (PtInRect(&infoPtr->calendars[calIdx].titleyear, lpht->pt))
1745 htinfo.uHit = MCHT_TITLEYEAR;
1746 htinfo.rc = infoPtr->calendars[calIdx].titleyear;
1747 htinfo.iOffset = calIdx;
1751 htinfo.uHit = MCHT_TITLE;
1752 htinfo.rc = infoPtr->calendars[calIdx].title;
1753 htinfo.iOffset = calIdx;
1756 return fill_hittest_info(&htinfo, lpht);
1759 /* days area (including week days and week numbers */
1760 day = MONTHCAL_GetDayFromPos(infoPtr, lpht->pt, calIdx);
1761 if (PtInRect(&infoPtr->calendars[calIdx].wdays, lpht->pt))
1763 htinfo.uHit = MCHT_CALENDARDAY;
1764 htinfo.iOffset = calIdx;
1765 htinfo.st.wYear = ht_month.wYear;
1766 htinfo.st.wMonth = (day < 1) ? ht_month.wMonth -1 : ht_month.wMonth;
1767 htinfo.st.wDay = (day < 1) ?
1768 MONTHCAL_MonthLength(ht_month.wMonth-1, ht_month.wYear) - day : day;
1770 MONTHCAL_GetDayPos(infoPtr, &htinfo.st, &htinfo.iCol, &htinfo.iRow, calIdx);
1772 else if(PtInRect(&infoPtr->calendars[calIdx].weeknums, lpht->pt))
1774 htinfo.uHit = MCHT_CALENDARWEEKNUM;
1775 htinfo.st.wYear = ht_month.wYear;
1776 htinfo.iOffset = calIdx;
1780 htinfo.st.wMonth = ht_month.wMonth - 1;
1781 htinfo.st.wDay = MONTHCAL_MonthLength(ht_month.wMonth-1, ht_month.wYear) - day;
1783 else if (day > MONTHCAL_MonthLength(ht_month.wMonth, ht_month.wYear))
1785 htinfo.st.wMonth = ht_month.wMonth + 1;
1786 htinfo.st.wDay = day - MONTHCAL_MonthLength(ht_month.wMonth, ht_month.wYear);
1790 htinfo.st.wMonth = ht_month.wMonth;
1791 htinfo.st.wDay = day;
1794 else if(PtInRect(&infoPtr->calendars[calIdx].days, lpht->pt))
1796 htinfo.iOffset = calIdx;
1797 htinfo.st.wYear = ht_month.wYear;
1798 htinfo.st.wMonth = ht_month.wMonth;
1801 htinfo.uHit = MCHT_CALENDARDATEPREV;
1802 MONTHCAL_GetPrevMonth(&htinfo.st);
1803 htinfo.st.wDay = MONTHCAL_MonthLength(htinfo.st.wMonth, htinfo.st.wYear) + day;
1805 else if (day > MONTHCAL_MonthLength(ht_month.wMonth, ht_month.wYear))
1807 htinfo.uHit = MCHT_CALENDARDATENEXT;
1808 MONTHCAL_GetNextMonth(&htinfo.st);
1809 htinfo.st.wDay = day - MONTHCAL_MonthLength(ht_month.wMonth, ht_month.wYear);
1813 htinfo.uHit = MCHT_CALENDARDATE;
1814 htinfo.st.wDay = day;
1817 MONTHCAL_GetDayPos(infoPtr, &htinfo.st, &htinfo.iCol, &htinfo.iRow, calIdx);
1818 MONTHCAL_GetDayRectI(infoPtr, &htinfo.rc, htinfo.iCol, htinfo.iRow, calIdx);
1819 /* always update day of week */
1820 MONTHCAL_CalculateDayOfWeek(&htinfo.st, TRUE);
1823 return fill_hittest_info(&htinfo, lpht);
1826 /* MCN_GETDAYSTATE notification helper */
1827 static void MONTHCAL_NotifyDayState(MONTHCAL_INFO *infoPtr)
1829 if(infoPtr->dwStyle & MCS_DAYSTATE) {
1832 nmds.nmhdr.hwndFrom = infoPtr->hwndSelf;
1833 nmds.nmhdr.idFrom = GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_ID);
1834 nmds.nmhdr.code = MCN_GETDAYSTATE;
1835 nmds.cDayState = infoPtr->monthRange;
1836 nmds.prgDayState = Alloc(infoPtr->monthRange * sizeof(MONTHDAYSTATE));
1838 nmds.stStart = infoPtr->todaysDate;
1839 nmds.stStart.wYear = infoPtr->minSel.wYear;
1840 nmds.stStart.wMonth = infoPtr->minSel.wMonth;
1841 nmds.stStart.wDay = 1;
1843 SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, nmds.nmhdr.idFrom, (LPARAM)&nmds);
1844 memcpy(infoPtr->monthdayState, nmds.prgDayState, infoPtr->monthRange*sizeof(MONTHDAYSTATE));
1846 Free(nmds.prgDayState);
1850 /* no valid range check performed */
1851 static void MONTHCAL_Scroll(MONTHCAL_INFO *infoPtr, INT delta)
1855 for(i = 0; i < MONTHCAL_GetCalCount(infoPtr); i++)
1857 /* save selection position to shift it later */
1858 if (selIdx == -1 && MONTHCAL_CompareMonths(&infoPtr->minSel, &infoPtr->calendars[i].month) == 0)
1861 MONTHCAL_GetMonth(&infoPtr->calendars[i].month, delta);
1864 /* selection is always shifted to first calendar */
1865 if(infoPtr->dwStyle & MCS_MULTISELECT)
1867 SYSTEMTIME range[2];
1869 MONTHCAL_GetSelRange(infoPtr, range);
1870 MONTHCAL_GetMonth(&range[0], delta - selIdx);
1871 MONTHCAL_GetMonth(&range[1], delta - selIdx);
1872 MONTHCAL_SetSelRange(infoPtr, range);
1876 SYSTEMTIME st = infoPtr->minSel;
1878 MONTHCAL_GetMonth(&st, delta - selIdx);
1879 MONTHCAL_SetCurSel(infoPtr, &st);
1883 static void MONTHCAL_GoToMonth(MONTHCAL_INFO *infoPtr, enum nav_direction direction)
1885 INT delta = infoPtr->delta ? infoPtr->delta : MONTHCAL_GetCalCount(infoPtr);
1888 TRACE("%s\n", direction == DIRECTION_BACKWARD ? "back" : "fwd");
1890 /* check if change allowed by range set */
1891 if(direction == DIRECTION_BACKWARD)
1893 st = infoPtr->calendars[0].month;
1894 MONTHCAL_GetMonth(&st, -delta);
1898 st = infoPtr->calendars[MONTHCAL_GetCalCount(infoPtr)-1].month;
1899 MONTHCAL_GetMonth(&st, delta);
1902 if(!MONTHCAL_IsDateInValidRange(infoPtr, &st, FALSE)) return;
1904 MONTHCAL_Scroll(infoPtr, direction == DIRECTION_BACKWARD ? -delta : delta);
1905 MONTHCAL_NotifyDayState(infoPtr);
1906 MONTHCAL_NotifySelectionChange(infoPtr);
1910 MONTHCAL_RButtonUp(MONTHCAL_INFO *infoPtr, LPARAM lParam)
1912 static const WCHAR todayW[] = { 'G','o',' ','t','o',' ','T','o','d','a','y',':',0 };
1917 hMenu = CreatePopupMenu();
1918 if (!LoadStringW(COMCTL32_hModule, IDM_GOTODAY, buf, countof(buf)))
1920 WARN("Can't load resource\n");
1921 strcpyW(buf, todayW);
1923 AppendMenuW(hMenu, MF_STRING|MF_ENABLED, 1, buf);
1924 menupoint.x = (short)LOWORD(lParam);
1925 menupoint.y = (short)HIWORD(lParam);
1926 ClientToScreen(infoPtr->hwndSelf, &menupoint);
1927 if( TrackPopupMenu(hMenu, TPM_RIGHTBUTTON | TPM_NONOTIFY | TPM_RETURNCMD,
1928 menupoint.x, menupoint.y, 0, infoPtr->hwndSelf, NULL))
1930 infoPtr->calendars[0].month = infoPtr->todaysDate;
1931 infoPtr->minSel = infoPtr->todaysDate;
1932 infoPtr->maxSel = infoPtr->todaysDate;
1933 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1941 * Subclassed edit control windproc function
1944 * [I] hwnd : the edit window handle
1945 * [I] uMsg : the message that is to be processed
1946 * [I] wParam : first message parameter
1947 * [I] lParam : second message parameter
1950 static LRESULT CALLBACK EditWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1952 MONTHCAL_INFO *infoPtr = (MONTHCAL_INFO *)GetWindowLongPtrW(GetParent(hwnd), 0);
1954 TRACE("(hwnd=%p, uMsg=%x, wParam=%lx, lParam=%lx)\n",
1955 hwnd, uMsg, wParam, lParam);
1960 return DLGC_WANTARROWS | DLGC_WANTALLKEYS;
1964 WNDPROC editProc = infoPtr->EditWndProc;
1965 infoPtr->EditWndProc = NULL;
1966 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (DWORD_PTR)editProc);
1967 return CallWindowProcW(editProc, hwnd, uMsg, wParam, lParam);
1974 if ((VK_ESCAPE == (INT)wParam) || (VK_RETURN == (INT)wParam))
1978 return CallWindowProcW(infoPtr->EditWndProc, hwnd, uMsg, wParam, lParam);
1981 SendMessageW(infoPtr->hWndYearUpDown, WM_CLOSE, 0, 0);
1982 SendMessageW(hwnd, WM_CLOSE, 0, 0);
1986 /* creates updown control and edit box */
1987 static void MONTHCAL_EditYear(MONTHCAL_INFO *infoPtr, INT calIdx)
1989 RECT *rc = &infoPtr->calendars[calIdx].titleyear;
1990 RECT *title = &infoPtr->calendars[calIdx].title;
1992 infoPtr->hWndYearEdit =
1993 CreateWindowExW(0, WC_EDITW, 0, WS_VISIBLE | WS_CHILD | ES_READONLY,
1994 rc->left + 3, (title->bottom + title->top - infoPtr->textHeight) / 2,
1995 rc->right - rc->left + 4,
1996 infoPtr->textHeight, infoPtr->hwndSelf,
1999 SendMessageW(infoPtr->hWndYearEdit, WM_SETFONT, (WPARAM)infoPtr->hBoldFont, TRUE);
2001 infoPtr->hWndYearUpDown =
2002 CreateWindowExW(0, UPDOWN_CLASSW, 0,
2003 WS_VISIBLE | WS_CHILD | UDS_SETBUDDYINT | UDS_NOTHOUSANDS | UDS_ARROWKEYS,
2004 rc->right + 7, (title->bottom + title->top - infoPtr->textHeight) / 2,
2005 18, infoPtr->textHeight, infoPtr->hwndSelf,
2008 /* attach edit box */
2009 SendMessageW(infoPtr->hWndYearUpDown, UDM_SETRANGE, 0,
2010 MAKELONG(max_allowed_date.wYear, min_allowed_date.wYear));
2011 SendMessageW(infoPtr->hWndYearUpDown, UDM_SETBUDDY, (WPARAM)infoPtr->hWndYearEdit, 0);
2012 SendMessageW(infoPtr->hWndYearUpDown, UDM_SETPOS, 0, infoPtr->calendars[calIdx].month.wYear);
2014 /* subclass edit box */
2015 infoPtr->EditWndProc = (WNDPROC)SetWindowLongPtrW(infoPtr->hWndYearEdit,
2016 GWLP_WNDPROC, (DWORD_PTR)EditWndProc);
2018 SetFocus(infoPtr->hWndYearEdit);
2022 MONTHCAL_LButtonDown(MONTHCAL_INFO *infoPtr, LPARAM lParam)
2027 /* Actually we don't need input focus for calendar, this is used to kill
2028 year updown and its buddy edit box */
2029 if (IsWindow(infoPtr->hWndYearUpDown))
2031 SetFocus(infoPtr->hwndSelf);
2035 SetCapture(infoPtr->hwndSelf);
2037 ht.cbSize = sizeof(MCHITTESTINFO);
2038 ht.pt.x = (short)LOWORD(lParam);
2039 ht.pt.y = (short)HIWORD(lParam);
2041 hit = MONTHCAL_HitTest(infoPtr, &ht);
2043 TRACE("%x at (%d, %d)\n", hit, ht.pt.x, ht.pt.y);
2047 case MCHT_TITLEBTNNEXT:
2048 MONTHCAL_GoToMonth(infoPtr, DIRECTION_FORWARD);
2049 infoPtr->status = MC_NEXTPRESSED;
2050 SetTimer(infoPtr->hwndSelf, MC_PREVNEXTMONTHTIMER, MC_PREVNEXTMONTHDELAY, 0);
2051 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
2054 case MCHT_TITLEBTNPREV:
2055 MONTHCAL_GoToMonth(infoPtr, DIRECTION_BACKWARD);
2056 infoPtr->status = MC_PREVPRESSED;
2057 SetTimer(infoPtr->hwndSelf, MC_PREVNEXTMONTHTIMER, MC_PREVNEXTMONTHDELAY, 0);
2058 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
2061 case MCHT_TITLEMONTH:
2063 HMENU hMenu = CreatePopupMenu();
2068 for (i = 0; i < 12; i++)
2070 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SMONTHNAME1+i, buf, countof(buf));
2071 AppendMenuW(hMenu, MF_STRING|MF_ENABLED, i + 1, buf);
2073 menupoint.x = ht.pt.x;
2074 menupoint.y = ht.pt.y;
2075 ClientToScreen(infoPtr->hwndSelf, &menupoint);
2076 i = TrackPopupMenu(hMenu,TPM_LEFTALIGN | TPM_NONOTIFY | TPM_RIGHTBUTTON | TPM_RETURNCMD,
2077 menupoint.x, menupoint.y, 0, infoPtr->hwndSelf, NULL);
2079 if ((i > 0) && (i < 13) && infoPtr->calendars[ht.iOffset].month.wMonth != i)
2081 INT delta = i - infoPtr->calendars[ht.iOffset].month.wMonth;
2084 /* check if change allowed by range set */
2085 st = delta < 0 ? infoPtr->calendars[0].month :
2086 infoPtr->calendars[MONTHCAL_GetCalCount(infoPtr)-1].month;
2087 MONTHCAL_GetMonth(&st, delta);
2089 if (MONTHCAL_IsDateInValidRange(infoPtr, &st, FALSE))
2091 MONTHCAL_Scroll(infoPtr, delta);
2092 MONTHCAL_NotifyDayState(infoPtr);
2093 MONTHCAL_NotifySelectionChange(infoPtr);
2094 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
2099 case MCHT_TITLEYEAR:
2101 MONTHCAL_EditYear(infoPtr, ht.iOffset);
2104 case MCHT_TODAYLINK:
2106 infoPtr->calendars[0].month = infoPtr->todaysDate;
2107 infoPtr->minSel = infoPtr->todaysDate;
2108 infoPtr->maxSel = infoPtr->todaysDate;
2109 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
2111 MONTHCAL_NotifySelectionChange(infoPtr);
2112 MONTHCAL_NotifySelect(infoPtr);
2115 case MCHT_CALENDARDATENEXT:
2116 case MCHT_CALENDARDATEPREV:
2117 case MCHT_CALENDARDATE:
2121 MONTHCAL_CopyDate(&ht.st, &infoPtr->firstSel);
2123 st[0] = st[1] = ht.st;
2124 /* clear selection range */
2125 MONTHCAL_SetSelRange(infoPtr, st);
2127 infoPtr->status = MC_SEL_LBUTDOWN;
2128 MONTHCAL_SetDayFocus(infoPtr, &ht.st);
2138 MONTHCAL_LButtonUp(MONTHCAL_INFO *infoPtr, LPARAM lParam)
2146 if(infoPtr->status & (MC_PREVPRESSED | MC_NEXTPRESSED)) {
2149 KillTimer(infoPtr->hwndSelf, MC_PREVNEXTMONTHTIMER);
2150 r = infoPtr->status & MC_PREVPRESSED ? &infoPtr->titlebtnprev : &infoPtr->titlebtnnext;
2151 infoPtr->status &= ~(MC_PREVPRESSED | MC_NEXTPRESSED);
2153 InvalidateRect(infoPtr->hwndSelf, r, FALSE);
2158 /* always send NM_RELEASEDCAPTURE notification */
2159 nmhdr.hwndFrom = infoPtr->hwndSelf;
2160 nmhdr.idFrom = GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_ID);
2161 nmhdr.code = NM_RELEASEDCAPTURE;
2162 TRACE("Sent notification from %p to %p\n", infoPtr->hwndSelf, infoPtr->hwndNotify);
2164 SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, nmhdr.idFrom, (LPARAM)&nmhdr);
2166 if(!(infoPtr->status & MC_SEL_LBUTDOWN)) return 0;
2168 ht.cbSize = sizeof(MCHITTESTINFO);
2169 ht.pt.x = (short)LOWORD(lParam);
2170 ht.pt.y = (short)HIWORD(lParam);
2171 hit = MONTHCAL_HitTest(infoPtr, &ht);
2173 infoPtr->status = MC_SEL_LBUTUP;
2174 MONTHCAL_SetDayFocus(infoPtr, NULL);
2176 if((hit & MCHT_CALENDARDATE) == MCHT_CALENDARDATE)
2178 SYSTEMTIME sel = infoPtr->minSel;
2180 /* will be invalidated here */
2181 MONTHCAL_SetCurSel(infoPtr, &ht.st);
2183 /* send MCN_SELCHANGE only if new date selected */
2184 if (!MONTHCAL_IsDateEqual(&sel, &ht.st))
2185 MONTHCAL_NotifySelectionChange(infoPtr);
2187 MONTHCAL_NotifySelect(infoPtr);
2195 MONTHCAL_Timer(MONTHCAL_INFO *infoPtr, WPARAM id)
2200 case MC_PREVNEXTMONTHTIMER:
2201 if(infoPtr->status & MC_NEXTPRESSED) MONTHCAL_GoToMonth(infoPtr, DIRECTION_FORWARD);
2202 if(infoPtr->status & MC_PREVPRESSED) MONTHCAL_GoToMonth(infoPtr, DIRECTION_BACKWARD);
2203 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
2205 case MC_TODAYUPDATETIMER:
2209 if(infoPtr->todaySet) return 0;
2212 MONTHCAL_UpdateToday(infoPtr, &st);
2214 /* notification sent anyway */
2215 MONTHCAL_NotifySelectionChange(infoPtr);
2220 ERR("got unknown timer %ld\n", id);
2229 MONTHCAL_MouseMove(MONTHCAL_INFO *infoPtr, LPARAM lParam)
2236 if(!(infoPtr->status & MC_SEL_LBUTDOWN)) return 0;
2238 ht.cbSize = sizeof(MCHITTESTINFO);
2239 ht.pt.x = (short)LOWORD(lParam);
2240 ht.pt.y = (short)HIWORD(lParam);
2243 hit = MONTHCAL_HitTest(infoPtr, &ht);
2245 /* not on the calendar date numbers? bail out */
2246 TRACE("hit:%x\n",hit);
2247 if((hit & MCHT_CALENDARDATE) != MCHT_CALENDARDATE)
2249 MONTHCAL_SetDayFocus(infoPtr, NULL);
2255 /* if pointer is over focused day still there's nothing to do */
2256 if(!MONTHCAL_SetDayFocus(infoPtr, &ht.st)) return 0;
2258 MONTHCAL_GetDayRect(infoPtr, &ht.st, &r, ht.iOffset);
2260 if(infoPtr->dwStyle & MCS_MULTISELECT) {
2263 MONTHCAL_GetSelRange(infoPtr, st);
2265 /* If we're still at the first selected date and range is empty, return.
2266 If range isn't empty we should change range to a single firstSel */
2267 if(MONTHCAL_IsDateEqual(&infoPtr->firstSel, &st_ht) &&
2268 MONTHCAL_IsDateEqual(&st[0], &st[1])) goto done;
2270 MONTHCAL_IsSelRangeValid(infoPtr, &st_ht, &infoPtr->firstSel, &st_ht);
2272 st[0] = infoPtr->firstSel;
2273 /* we should overwrite timestamp here */
2274 MONTHCAL_CopyDate(&st_ht, &st[1]);
2276 /* bounds will be swapped here if needed */
2277 MONTHCAL_SetSelRange(infoPtr, st);
2284 /* FIXME: this should specify a rectangle containing only the days that changed
2285 using InvalidateRect */
2286 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
2293 MONTHCAL_Paint(MONTHCAL_INFO *infoPtr, HDC hdc_paint)
2300 GetClientRect(infoPtr->hwndSelf, &ps.rcPaint);
2304 hdc = BeginPaint(infoPtr->hwndSelf, &ps);
2306 MONTHCAL_Refresh(infoPtr, hdc, &ps);
2307 if (!hdc_paint) EndPaint(infoPtr->hwndSelf, &ps);
2312 MONTHCAL_EraseBkgnd(const MONTHCAL_INFO *infoPtr, HDC hdc)
2316 if (!GetClipBox(hdc, &rc)) return FALSE;
2318 FillRect(hdc, &rc, infoPtr->brushes[BrushBackground]);
2324 MONTHCAL_PrintClient(MONTHCAL_INFO *infoPtr, HDC hdc, DWORD options)
2326 FIXME("Partial Stub: (hdc=%p options=0x%08x)\n", hdc, options);
2328 if ((options & PRF_CHECKVISIBLE) && !IsWindowVisible(infoPtr->hwndSelf))
2331 if (options & PRF_ERASEBKGND)
2332 MONTHCAL_EraseBkgnd(infoPtr, hdc);
2334 if (options & PRF_CLIENT)
2335 MONTHCAL_Paint(infoPtr, hdc);
2341 MONTHCAL_SetFocus(const MONTHCAL_INFO *infoPtr)
2345 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
2350 /* sets the size information */
2351 static void MONTHCAL_UpdateSize(MONTHCAL_INFO *infoPtr)
2353 static const WCHAR O0W[] = { '0','0',0 };
2354 HDC hdc = GetDC(infoPtr->hwndSelf);
2355 RECT *title=&infoPtr->calendars[0].title;
2356 RECT *prev=&infoPtr->titlebtnprev;
2357 RECT *next=&infoPtr->titlebtnnext;
2358 RECT *titlemonth=&infoPtr->calendars[0].titlemonth;
2359 RECT *titleyear=&infoPtr->calendars[0].titleyear;
2360 RECT *wdays=&infoPtr->calendars[0].wdays;
2361 RECT *weeknumrect=&infoPtr->calendars[0].weeknums;
2362 RECT *days=&infoPtr->calendars[0].days;
2363 RECT *todayrect=&infoPtr->todayrect;
2367 INT xdiv, dx, dy, i;
2371 GetClientRect(infoPtr->hwndSelf, &client);
2373 currentFont = SelectObject(hdc, infoPtr->hFont);
2375 /* get the height and width of each day's text */
2376 GetTextMetricsW(hdc, &tm);
2377 infoPtr->textHeight = tm.tmHeight + tm.tmExternalLeading + tm.tmInternalLeading;
2379 /* find largest abbreviated day name for current locale */
2380 size.cx = sz.cx = 0;
2381 for (i = 0; i < 7; i++)
2383 if(GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SABBREVDAYNAME1 + i,
2384 buff, countof(buff)))
2386 GetTextExtentPoint32W(hdc, buff, lstrlenW(buff), &sz);
2387 if (sz.cx > size.cx) size.cx = sz.cx;
2389 else /* locale independent fallback on failure */
2391 static const WCHAR SunW[] = { 'S','u','n',0 };
2393 GetTextExtentPoint32W(hdc, SunW, lstrlenW(SunW), &size);
2398 infoPtr->textWidth = size.cx + 2;
2400 /* recalculate the height and width increments and offsets */
2401 GetTextExtentPoint32W(hdc, O0W, 2, &size);
2403 xdiv = (infoPtr->dwStyle & MCS_WEEKNUMBERS) ? 8 : 7;
2405 infoPtr->width_increment = size.cx * 2 + 4;
2406 infoPtr->height_increment = infoPtr->textHeight;
2408 /* calculate title area */
2410 title->bottom = 3 * infoPtr->height_increment / 2;
2412 title->right = infoPtr->width_increment * xdiv;
2414 /* set the dimensions of the next and previous buttons and center */
2415 /* the month text vertically */
2416 prev->top = next->top = title->top + 4;
2417 prev->bottom = next->bottom = title->bottom - 4;
2418 prev->left = title->left + 4;
2419 prev->right = prev->left + (title->bottom - title->top);
2420 next->right = title->right - 4;
2421 next->left = next->right - (title->bottom - title->top);
2423 /* titlemonth->left and right change based upon the current month */
2424 /* and are recalculated in refresh as the current month may change */
2425 /* without the control being resized */
2426 titlemonth->top = titleyear->top = title->top + (infoPtr->height_increment)/2;
2427 titlemonth->bottom = titleyear->bottom = title->bottom - (infoPtr->height_increment)/2;
2429 /* setup the dimensions of the rectangle we draw the names of the */
2430 /* days of the week in */
2431 weeknumrect->left = 0;
2433 if(infoPtr->dwStyle & MCS_WEEKNUMBERS)
2434 weeknumrect->right = prev->right;
2436 weeknumrect->right = weeknumrect->left;
2438 wdays->left = days->left = weeknumrect->right;
2439 wdays->right = days->right = wdays->left + 7 * infoPtr->width_increment;
2440 wdays->top = title->bottom;
2441 wdays->bottom = wdays->top + infoPtr->height_increment;
2443 days->top = weeknumrect->top = wdays->bottom;
2444 days->bottom = weeknumrect->bottom = days->top + 6 * infoPtr->height_increment;
2446 todayrect->left = 0;
2447 todayrect->right = title->right;
2448 todayrect->top = days->bottom;
2449 todayrect->bottom = days->bottom + infoPtr->height_increment;
2451 /* offset all rectangles to center in client area */
2452 dx = (client.right - title->right) / 2;
2453 dy = (client.bottom - todayrect->bottom) / 2;
2455 /* if calendar doesn't fit client area show it at left/top bounds */
2456 if (title->left + dx < 0) dx = 0;
2457 if (title->top + dy < 0) dy = 0;
2459 if (dx != 0 || dy != 0)
2461 OffsetRect(title, dx, dy);
2462 OffsetRect(prev, dx, dy);
2463 OffsetRect(next, dx, dy);
2464 OffsetRect(titlemonth, dx, dy);
2465 OffsetRect(titleyear, dx, dy);
2466 OffsetRect(wdays, dx, dy);
2467 OffsetRect(weeknumrect, dx, dy);
2468 OffsetRect(days, dx, dy);
2469 OffsetRect(todayrect, dx, dy);
2472 /* TODO: update calendars count */
2473 infoPtr->dim.cx = infoPtr->dim.cy = 1;
2475 TRACE("dx=%d dy=%d client[%s] title[%s] wdays[%s] days[%s] today[%s]\n",
2476 infoPtr->width_increment,infoPtr->height_increment,
2477 wine_dbgstr_rect(&client),
2478 wine_dbgstr_rect(title),
2479 wine_dbgstr_rect(wdays),
2480 wine_dbgstr_rect(days),
2481 wine_dbgstr_rect(todayrect));
2483 /* restore the originally selected font */
2484 SelectObject(hdc, currentFont);
2486 ReleaseDC(infoPtr->hwndSelf, hdc);
2489 static LRESULT MONTHCAL_Size(MONTHCAL_INFO *infoPtr, int Width, int Height)
2491 TRACE("(width=%d, height=%d)\n", Width, Height);
2493 MONTHCAL_UpdateSize(infoPtr);
2494 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
2499 static LRESULT MONTHCAL_GetFont(const MONTHCAL_INFO *infoPtr)
2501 return (LRESULT)infoPtr->hFont;
2504 static LRESULT MONTHCAL_SetFont(MONTHCAL_INFO *infoPtr, HFONT hFont, BOOL redraw)
2509 if (!hFont) return 0;
2511 hOldFont = infoPtr->hFont;
2512 infoPtr->hFont = hFont;
2514 GetObjectW(infoPtr->hFont, sizeof(lf), &lf);
2515 lf.lfWeight = FW_BOLD;
2516 infoPtr->hBoldFont = CreateFontIndirectW(&lf);
2518 MONTHCAL_UpdateSize(infoPtr);
2521 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
2523 return (LRESULT)hOldFont;
2526 /* update theme after a WM_THEMECHANGED message */
2527 static LRESULT theme_changed (const MONTHCAL_INFO* infoPtr)
2529 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
2530 CloseThemeData (theme);
2531 OpenThemeData (infoPtr->hwndSelf, themeClass);
2535 static INT MONTHCAL_StyleChanged(MONTHCAL_INFO *infoPtr, WPARAM wStyleType,
2536 const STYLESTRUCT *lpss)
2538 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
2539 wStyleType, lpss->styleOld, lpss->styleNew);
2541 if (wStyleType != GWL_STYLE) return 0;
2543 infoPtr->dwStyle = lpss->styleNew;
2545 /* make room for week numbers */
2546 if ((lpss->styleNew ^ lpss->styleOld) & MCS_WEEKNUMBERS)
2547 MONTHCAL_UpdateSize(infoPtr);
2552 static INT MONTHCAL_StyleChanging(MONTHCAL_INFO *infoPtr, WPARAM wStyleType,
2555 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
2556 wStyleType, lpss->styleOld, lpss->styleNew);
2558 /* block MCS_MULTISELECT change */
2559 if ((lpss->styleNew ^ lpss->styleOld) & MCS_MULTISELECT)
2561 if (lpss->styleOld & MCS_MULTISELECT)
2562 lpss->styleNew |= MCS_MULTISELECT;
2564 lpss->styleNew &= ~MCS_MULTISELECT;
2570 /* FIXME: check whether dateMin/dateMax need to be adjusted. */
2572 MONTHCAL_Create(HWND hwnd, LPCREATESTRUCTW lpcs)
2574 MONTHCAL_INFO *infoPtr;
2576 /* allocate memory for info structure */
2577 infoPtr = Alloc(sizeof(MONTHCAL_INFO));
2578 SetWindowLongPtrW(hwnd, 0, (DWORD_PTR)infoPtr);
2580 if (infoPtr == NULL) {
2581 ERR("could not allocate info memory!\n");
2585 infoPtr->hwndSelf = hwnd;
2586 infoPtr->hwndNotify = lpcs->hwndParent;
2587 infoPtr->dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
2588 infoPtr->calendars = Alloc(sizeof(CALENDAR_INFO));
2589 if (!infoPtr->calendars) goto fail;
2591 MONTHCAL_SetFont(infoPtr, GetStockObject(DEFAULT_GUI_FONT), FALSE);
2593 /* initialize info structure */
2594 /* FIXME: calculate systemtime ->> localtime(subtract timezoneinfo) */
2596 GetLocalTime(&infoPtr->todaysDate);
2597 MONTHCAL_SetFirstDayOfWeek(infoPtr, -1);
2599 infoPtr->maxSelCount = (infoPtr->dwStyle & MCS_MULTISELECT) ? 7 : 1;
2600 infoPtr->monthRange = 3;
2602 infoPtr->monthdayState = Alloc(infoPtr->monthRange * sizeof(MONTHDAYSTATE));
2603 if (!infoPtr->monthdayState) goto fail;
2605 infoPtr->colors[MCSC_BACKGROUND] = comctl32_color.clrWindow;
2606 infoPtr->colors[MCSC_TEXT] = comctl32_color.clrWindowText;
2607 infoPtr->colors[MCSC_TITLEBK] = comctl32_color.clrActiveCaption;
2608 infoPtr->colors[MCSC_TITLETEXT] = comctl32_color.clrWindow;
2609 infoPtr->colors[MCSC_MONTHBK] = comctl32_color.clrWindow;
2610 infoPtr->colors[MCSC_TRAILINGTEXT] = comctl32_color.clrGrayText;
2612 infoPtr->brushes[BrushBackground] = CreateSolidBrush(infoPtr->colors[MCSC_BACKGROUND]);
2613 infoPtr->brushes[BrushTitle] = CreateSolidBrush(infoPtr->colors[MCSC_TITLEBK]);
2614 infoPtr->brushes[BrushMonth] = CreateSolidBrush(infoPtr->colors[MCSC_MONTHBK]);
2616 infoPtr->pens[PenRed] = CreatePen(PS_SOLID, 1, RGB(255, 0, 0));
2617 infoPtr->pens[PenText] = CreatePen(PS_SOLID, 1, infoPtr->colors[MCSC_TEXT]);
2619 infoPtr->minSel = infoPtr->todaysDate;
2620 infoPtr->maxSel = infoPtr->todaysDate;
2621 infoPtr->calendars[0].month = infoPtr->todaysDate;
2622 infoPtr->isUnicode = TRUE;
2624 /* set all control dimensions */
2625 MONTHCAL_UpdateSize(infoPtr);
2627 /* today auto update timer, to be freed only on control destruction */
2628 SetTimer(infoPtr->hwndSelf, MC_TODAYUPDATETIMER, MC_TODAYUPDATEDELAY, 0);
2630 OpenThemeData (infoPtr->hwndSelf, themeClass);
2635 Free(infoPtr->monthdayState);
2636 Free(infoPtr->calendars);
2642 MONTHCAL_Destroy(MONTHCAL_INFO *infoPtr)
2646 /* free month calendar info data */
2647 Free(infoPtr->monthdayState);
2648 Free(infoPtr->calendars);
2649 SetWindowLongPtrW(infoPtr->hwndSelf, 0, 0);
2651 CloseThemeData (GetWindowTheme (infoPtr->hwndSelf));
2653 for (i = 0; i < BrushLast; i++) DeleteObject(infoPtr->brushes[i]);
2654 for (i = 0; i < PenLast; i++) DeleteObject(infoPtr->pens[i]);
2661 * Handler for WM_NOTIFY messages
2664 MONTHCAL_Notify(MONTHCAL_INFO *infoPtr, NMHDR *hdr)
2666 /* notification from year edit updown */
2667 if (hdr->code == UDN_DELTAPOS)
2669 NMUPDOWN *nmud = (NMUPDOWN*)hdr;
2671 if (hdr->hwndFrom == infoPtr->hWndYearUpDown && nmud->iDelta)
2673 /* year value limits are set up explicitly after updown creation */
2674 MONTHCAL_Scroll(infoPtr, 12 * nmud->iDelta);
2675 MONTHCAL_NotifyDayState(infoPtr);
2676 MONTHCAL_NotifySelectionChange(infoPtr);
2683 MONTHCAL_SetUnicodeFormat(MONTHCAL_INFO *infoPtr, BOOL isUnicode)
2685 BOOL prev = infoPtr->isUnicode;
2686 infoPtr->isUnicode = isUnicode;
2691 MONTHCAL_GetUnicodeFormat(const MONTHCAL_INFO *infoPtr)
2693 return infoPtr->isUnicode;
2696 static LRESULT WINAPI
2697 MONTHCAL_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2699 MONTHCAL_INFO *infoPtr = (MONTHCAL_INFO *)GetWindowLongPtrW(hwnd, 0);
2701 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n", hwnd, uMsg, wParam, lParam);
2703 if (!infoPtr && (uMsg != WM_CREATE))
2704 return DefWindowProcW(hwnd, uMsg, wParam, lParam);
2708 return MONTHCAL_GetCurSel(infoPtr, (LPSYSTEMTIME)lParam);
2711 return MONTHCAL_SetCurSel(infoPtr, (LPSYSTEMTIME)lParam);
2713 case MCM_GETMAXSELCOUNT:
2714 return MONTHCAL_GetMaxSelCount(infoPtr);
2716 case MCM_SETMAXSELCOUNT:
2717 return MONTHCAL_SetMaxSelCount(infoPtr, wParam);
2719 case MCM_GETSELRANGE:
2720 return MONTHCAL_GetSelRange(infoPtr, (LPSYSTEMTIME)lParam);
2722 case MCM_SETSELRANGE:
2723 return MONTHCAL_SetSelRange(infoPtr, (LPSYSTEMTIME)lParam);
2725 case MCM_GETMONTHRANGE:
2726 return MONTHCAL_GetMonthRange(infoPtr, wParam, (SYSTEMTIME*)lParam);
2728 case MCM_SETDAYSTATE:
2729 return MONTHCAL_SetDayState(infoPtr, (INT)wParam, (LPMONTHDAYSTATE)lParam);
2731 case MCM_GETMINREQRECT:
2732 return MONTHCAL_GetMinReqRect(infoPtr, (LPRECT)lParam);
2735 return MONTHCAL_GetColor(infoPtr, wParam);
2738 return MONTHCAL_SetColor(infoPtr, wParam, (COLORREF)lParam);
2741 return MONTHCAL_GetToday(infoPtr, (LPSYSTEMTIME)lParam);
2744 return MONTHCAL_SetToday(infoPtr, (LPSYSTEMTIME)lParam);
2747 return MONTHCAL_HitTest(infoPtr, (PMCHITTESTINFO)lParam);
2749 case MCM_GETFIRSTDAYOFWEEK:
2750 return MONTHCAL_GetFirstDayOfWeek(infoPtr);
2752 case MCM_SETFIRSTDAYOFWEEK:
2753 return MONTHCAL_SetFirstDayOfWeek(infoPtr, (INT)lParam);
2756 return MONTHCAL_GetRange(infoPtr, (LPSYSTEMTIME)lParam);
2759 return MONTHCAL_SetRange(infoPtr, (SHORT)wParam, (LPSYSTEMTIME)lParam);
2761 case MCM_GETMONTHDELTA:
2762 return MONTHCAL_GetMonthDelta(infoPtr);
2764 case MCM_SETMONTHDELTA:
2765 return MONTHCAL_SetMonthDelta(infoPtr, wParam);
2767 case MCM_GETMAXTODAYWIDTH:
2768 return MONTHCAL_GetMaxTodayWidth(infoPtr);
2770 case MCM_SETUNICODEFORMAT:
2771 return MONTHCAL_SetUnicodeFormat(infoPtr, (BOOL)wParam);
2773 case MCM_GETUNICODEFORMAT:
2774 return MONTHCAL_GetUnicodeFormat(infoPtr);
2777 return DLGC_WANTARROWS | DLGC_WANTCHARS;
2780 return MONTHCAL_RButtonUp(infoPtr, lParam);
2782 case WM_LBUTTONDOWN:
2783 return MONTHCAL_LButtonDown(infoPtr, lParam);
2786 return MONTHCAL_MouseMove(infoPtr, lParam);
2789 return MONTHCAL_LButtonUp(infoPtr, lParam);
2792 return MONTHCAL_Paint(infoPtr, (HDC)wParam);
2794 case WM_PRINTCLIENT:
2795 return MONTHCAL_PrintClient(infoPtr, (HDC)wParam, (DWORD)lParam);
2798 return MONTHCAL_EraseBkgnd(infoPtr, (HDC)wParam);
2801 return MONTHCAL_SetFocus(infoPtr);
2804 return MONTHCAL_Size(infoPtr, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
2807 return MONTHCAL_Notify(infoPtr, (NMHDR*)lParam);
2810 return MONTHCAL_Create(hwnd, (LPCREATESTRUCTW)lParam);
2813 return MONTHCAL_SetFont(infoPtr, (HFONT)wParam, (BOOL)lParam);
2816 return MONTHCAL_GetFont(infoPtr);
2819 return MONTHCAL_Timer(infoPtr, wParam);
2821 case WM_THEMECHANGED:
2822 return theme_changed (infoPtr);
2825 return MONTHCAL_Destroy(infoPtr);
2827 case WM_SYSCOLORCHANGE:
2828 COMCTL32_RefreshSysColors();
2831 case WM_STYLECHANGED:
2832 return MONTHCAL_StyleChanged(infoPtr, wParam, (LPSTYLESTRUCT)lParam);
2834 case WM_STYLECHANGING:
2835 return MONTHCAL_StyleChanging(infoPtr, wParam, (LPSTYLESTRUCT)lParam);
2838 if ((uMsg >= WM_USER) && (uMsg < WM_APP) && !COMCTL32_IsReflectedMessage(uMsg))
2839 ERR( "unknown msg %04x wp=%08lx lp=%08lx\n", uMsg, wParam, lParam);
2840 return DefWindowProcW(hwnd, uMsg, wParam, lParam);
2846 MONTHCAL_Register(void)
2850 ZeroMemory(&wndClass, sizeof(WNDCLASSW));
2851 wndClass.style = CS_GLOBALCLASS;
2852 wndClass.lpfnWndProc = MONTHCAL_WindowProc;
2853 wndClass.cbClsExtra = 0;
2854 wndClass.cbWndExtra = sizeof(MONTHCAL_INFO *);
2855 wndClass.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
2856 wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
2857 wndClass.lpszClassName = MONTHCAL_CLASSW;
2859 RegisterClassW(&wndClass);
2864 MONTHCAL_Unregister(void)
2866 UnregisterClassW(MONTHCAL_CLASSW, NULL);