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, 2010 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 * -- MONTHCAL_GetMonthRange
37 * -- handle resources better (doesn't work now);
38 * -- take care of internationalization.
39 * -- keyboard handling.
58 #include "wine/unicode.h"
59 #include "wine/debug.h"
61 WINE_DEFAULT_DEBUG_CHANNEL(monthcal);
63 #define MC_SEL_LBUTUP 1 /* Left button released */
64 #define MC_SEL_LBUTDOWN 2 /* Left button pressed in calendar */
65 #define MC_PREVPRESSED 4 /* Prev month button pressed */
66 #define MC_NEXTPRESSED 8 /* Next month button pressed */
67 #define MC_PREVNEXTMONTHDELAY 350 /* when continuously pressing `next/prev
68 month', wait 350 ms before going
69 to the next/prev month */
70 #define MC_TODAYUPDATEDELAY 120000 /* time between today check for update (2 min) */
72 #define MC_PREVNEXTMONTHTIMER 1 /* Timer ID's */
73 #define MC_TODAYUPDATETIMER 2
75 #define countof(arr) (sizeof(arr)/sizeof(arr[0]))
77 /* convert from days to 100 nanoseconds unit - used as FILETIME unit */
78 #define DAYSTO100NSECS(days) (((ULONGLONG)(days))*24*60*60*10000000)
80 /* single calendar data */
81 typedef struct _CALENDAR_INFO
83 RECT title; /* rect for the header above the calendar */
84 RECT titlemonth; /* the 'month name' text in the header */
85 RECT titleyear; /* the 'year number' text in the header */
86 RECT wdays; /* week days at top */
87 RECT days; /* calendar area */
88 RECT weeknums; /* week numbers at left side */
90 SYSTEMTIME month;/* contains calendar main month/year */
96 DWORD dwStyle; /* cached GWL_STYLE */
98 COLORREF colors[MCSC_TRAILINGTEXT+1];
104 int height_increment;
106 INT delta; /* scroll rate; # of months that the */
107 /* control moves when user clicks a scroll button */
108 int visible; /* # of months visible */
109 int firstDay; /* Start month calendar with firstDay's day,
110 stored in SYSTEMTIME format */
111 BOOL firstDaySet; /* first week day differs from locale defined */
113 BOOL isUnicode; /* value set with MCM_SETUNICODE format */
116 MONTHDAYSTATE *monthdayState;
117 SYSTEMTIME todaysDate;
118 BOOL todaySet; /* Today was forced with MCM_SETTODAY */
119 int status; /* See MC_SEL flags */
120 SYSTEMTIME firstSel; /* first selected day */
122 SYSTEMTIME minSel; /* contains single selection when used without MCS_MULTISELECT */
124 SYSTEMTIME focusedSel; /* date currently focused with mouse movement */
129 RECT titlebtnnext; /* the `next month' button in the header */
130 RECT titlebtnprev; /* the `prev month' button in the header */
131 RECT todayrect; /* `today: xx/xx/xx' text rect */
132 HWND hwndNotify; /* Window to receive the notifications */
133 HWND hWndYearEdit; /* Window Handle of edit box to handle years */
134 HWND hWndYearUpDown;/* Window Handle of updown box to handle years */
135 WNDPROC EditWndProc; /* original Edit window procedure */
137 CALENDAR_INFO *calendars;
139 } MONTHCAL_INFO, *LPMONTHCAL_INFO;
141 static const WCHAR themeClass[] = { 'S','c','r','o','l','l','b','a','r',0 };
143 /* empty SYSTEMTIME const */
144 static const SYSTEMTIME st_null;
145 /* valid date limits */
146 static const SYSTEMTIME max_allowed_date = { .wYear = 9999, .wMonth = 12, .wDay = 31 };
147 static const SYSTEMTIME min_allowed_date = { .wYear = 1752, .wMonth = 9, .wDay = 14 };
149 /* Prev/Next buttons */
156 /* helper functions */
158 /* send a single MCN_SELCHANGE notification */
159 static inline void MONTHCAL_NotifySelectionChange(const MONTHCAL_INFO *infoPtr)
163 nmsc.nmhdr.hwndFrom = infoPtr->hwndSelf;
164 nmsc.nmhdr.idFrom = GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_ID);
165 nmsc.nmhdr.code = MCN_SELCHANGE;
166 nmsc.stSelStart = infoPtr->minSel;
167 nmsc.stSelEnd = infoPtr->maxSel;
168 SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, nmsc.nmhdr.idFrom, (LPARAM)&nmsc);
171 /* send a single MCN_SELECT notification */
172 static inline void MONTHCAL_NotifySelect(const MONTHCAL_INFO *infoPtr)
176 nmsc.nmhdr.hwndFrom = infoPtr->hwndSelf;
177 nmsc.nmhdr.idFrom = GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_ID);
178 nmsc.nmhdr.code = MCN_SELECT;
179 nmsc.stSelStart = infoPtr->minSel;
180 nmsc.stSelEnd = infoPtr->maxSel;
182 SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, nmsc.nmhdr.idFrom, (LPARAM)&nmsc);
185 /* returns the number of days in any given month, checking for leap days */
186 /* january is 1, december is 12 */
187 int MONTHCAL_MonthLength(int month, int year)
189 const int mdays[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
190 /* Wrap around, this eases handling. Getting length only we shouldn't care
191 about year change here cause January and December have
192 the same day quantity */
198 /* special case for calendar transition year */
199 if(month == min_allowed_date.wMonth && year == min_allowed_date.wYear) return 19;
201 /* if we have a leap year add 1 day to February */
202 /* a leap year is a year either divisible by 400 */
203 /* or divisible by 4 and not by 100 */
204 if(month == 2) { /* February */
205 return mdays[month - 1] + ((year%400 == 0) ? 1 : ((year%100 != 0) &&
206 (year%4 == 0)) ? 1 : 0);
209 return mdays[month - 1];
213 /* compares timestamps using date part only */
214 static inline BOOL MONTHCAL_IsDateEqual(const SYSTEMTIME *first, const SYSTEMTIME *second)
216 return (first->wYear == second->wYear) && (first->wMonth == second->wMonth) &&
217 (first->wDay == second->wDay);
220 /* make sure that date fields are valid */
221 static BOOL MONTHCAL_ValidateDate(const SYSTEMTIME *time)
223 if(time->wMonth < 1 || time->wMonth > 12 ) return FALSE;
224 if(time->wDayOfWeek > 6) return FALSE;
225 if(time->wDay > MONTHCAL_MonthLength(time->wMonth, time->wYear))
231 /* Copies timestamp part only.
235 * [I] from : source date
238 static void MONTHCAL_CopyTime(const SYSTEMTIME *from, SYSTEMTIME *to)
240 to->wHour = from->wHour;
241 to->wMinute = from->wMinute;
242 to->wSecond = from->wSecond;
245 /* Copies date part only.
249 * [I] from : source date
252 static void MONTHCAL_CopyDate(const SYSTEMTIME *from, SYSTEMTIME *to)
254 to->wYear = from->wYear;
255 to->wMonth = from->wMonth;
256 to->wDay = from->wDay;
257 to->wDayOfWeek = from->wDayOfWeek;
260 /* Compares two dates in SYSTEMTIME format
264 * [I] first : pointer to valid first date data to compare
265 * [I] second : pointer to valid second date data to compare
269 * -1 : first < second
270 * 0 : first == second
273 * Note that no date validation performed, alreadt validated values expected.
275 static LONG MONTHCAL_CompareSystemTime(const SYSTEMTIME *first, const SYSTEMTIME *second)
277 FILETIME ft_first, ft_second;
279 SystemTimeToFileTime(first, &ft_first);
280 SystemTimeToFileTime(second, &ft_second);
282 return CompareFileTime(&ft_first, &ft_second);
285 static LONG MONTHCAL_CompareMonths(const SYSTEMTIME *first, const SYSTEMTIME *second)
287 SYSTEMTIME st_first, st_second;
289 st_first = st_second = st_null;
290 MONTHCAL_CopyDate(first, &st_first);
291 MONTHCAL_CopyDate(second, &st_second);
292 st_first.wDay = st_second.wDay = 1;
294 return MONTHCAL_CompareSystemTime(&st_first, &st_second);
297 static LONG MONTHCAL_CompareDate(const SYSTEMTIME *first, const SYSTEMTIME *second)
299 SYSTEMTIME st_first, st_second;
301 st_first = st_second = st_null;
302 MONTHCAL_CopyDate(first, &st_first);
303 MONTHCAL_CopyDate(second, &st_second);
305 return MONTHCAL_CompareSystemTime(&st_first, &st_second);
308 /* Checks largest possible date range and configured one
312 * [I] infoPtr : valid pointer to control data
313 * [I] date : pointer to valid date data to check
314 * [I] fix : make date fit valid range
318 * TRUE - date whithin largest and configured range
319 * FALSE - date is outside largest or configured range
321 static BOOL MONTHCAL_IsDateInValidRange(const MONTHCAL_INFO *infoPtr,
322 SYSTEMTIME *date, BOOL fix)
324 const SYSTEMTIME *fix_st = NULL;
326 if(MONTHCAL_CompareSystemTime(date, &max_allowed_date) == 1) {
327 fix_st = &max_allowed_date;
329 else if(MONTHCAL_CompareSystemTime(date, &min_allowed_date) == -1) {
330 fix_st = &min_allowed_date;
332 else if(infoPtr->rangeValid & GDTR_MAX) {
333 if((MONTHCAL_CompareSystemTime(date, &infoPtr->maxDate) == 1)) {
334 fix_st = &infoPtr->maxDate;
337 else if(infoPtr->rangeValid & GDTR_MIN) {
338 if((MONTHCAL_CompareSystemTime(date, &infoPtr->minDate) == -1)) {
339 fix_st = &infoPtr->minDate;
344 date->wYear = fix_st->wYear;
345 date->wMonth = fix_st->wMonth;
348 return fix_st ? FALSE : TRUE;
351 /* Checks passed range width with configured maximum selection count
355 * [I] infoPtr : valid pointer to control data
356 * [I] range0 : pointer to valid date data (requested bound)
357 * [I] range1 : pointer to valid date data (primary bound)
358 * [O] adjust : returns adjusted range bound to fit maximum range (optional)
360 * Adjust value computed basing on primary bound and current maximum selection
361 * count. For simple range check (without adjusted value required) (range0, range1)
362 * relation means nothing.
366 * TRUE - range is shorter or equal to maximum
367 * FALSE - range is larger than maximum
369 static BOOL MONTHCAL_IsSelRangeValid(const MONTHCAL_INFO *infoPtr,
370 const SYSTEMTIME *range0,
371 const SYSTEMTIME *range1,
374 ULARGE_INTEGER ul_range0, ul_range1, ul_diff;
375 FILETIME ft_range0, ft_range1;
378 SystemTimeToFileTime(range0, &ft_range0);
379 SystemTimeToFileTime(range1, &ft_range1);
381 ul_range0.u.LowPart = ft_range0.dwLowDateTime;
382 ul_range0.u.HighPart = ft_range0.dwHighDateTime;
383 ul_range1.u.LowPart = ft_range1.dwLowDateTime;
384 ul_range1.u.HighPart = ft_range1.dwHighDateTime;
386 cmp = CompareFileTime(&ft_range0, &ft_range1);
389 ul_diff.QuadPart = ul_range0.QuadPart - ul_range1.QuadPart;
391 ul_diff.QuadPart = -ul_range0.QuadPart + ul_range1.QuadPart;
393 if(ul_diff.QuadPart >= DAYSTO100NSECS(infoPtr->maxSelCount)) {
397 ul_range0.QuadPart = ul_range1.QuadPart + DAYSTO100NSECS(infoPtr->maxSelCount - 1);
399 ul_range0.QuadPart = ul_range1.QuadPart - DAYSTO100NSECS(infoPtr->maxSelCount - 1);
401 ft_range0.dwLowDateTime = ul_range0.u.LowPart;
402 ft_range0.dwHighDateTime = ul_range0.u.HighPart;
403 FileTimeToSystemTime(&ft_range0, adjust);
411 /* Used in MCM_SETRANGE/MCM_SETSELRANGE to determine resulting time part.
412 Milliseconds are intentionally not validated. */
413 static BOOL MONTHCAL_ValidateTime(const SYSTEMTIME *time)
415 if((time->wHour > 24) || (time->wMinute > 59) || (time->wSecond > 59))
421 /* Note:Depending on DST, this may be offset by a day.
422 Need to find out if we're on a DST place & adjust the clock accordingly.
423 Above function assumes we have a valid data.
424 Valid for year>1752; 1 <= d <= 31, 1 <= m <= 12.
428 /* Returns the day in the week
431 * [i] date : input date
432 * [I] inplace : set calculated value back to date structure
435 * day of week in SYSTEMTIME format: (0 == sunday,..., 6 == saturday)
437 int MONTHCAL_CalculateDayOfWeek(SYSTEMTIME *date, BOOL inplace)
439 SYSTEMTIME st = st_null;
442 MONTHCAL_CopyDate(date, &st);
444 SystemTimeToFileTime(&st, &ft);
445 FileTimeToSystemTime(&ft, &st);
447 if (inplace) date->wDayOfWeek = st.wDayOfWeek;
449 return st.wDayOfWeek;
452 /* add/substract 'months' from date */
453 static inline void MONTHCAL_GetMonth(SYSTEMTIME *date, INT months)
455 INT length, m = date->wMonth + months;
457 date->wYear += m > 0 ? (m - 1) / 12 : m / 12 - 1;
458 date->wMonth = m > 0 ? (m - 1) % 12 + 1 : 12 + m % 12;
459 /* fix moving from last day in a month */
460 length = MONTHCAL_MonthLength(date->wMonth, date->wYear);
461 if(date->wDay > length) date->wDay = length;
462 MONTHCAL_CalculateDayOfWeek(date, TRUE);
465 /* properly updates date to point on next month */
466 static inline void MONTHCAL_GetNextMonth(SYSTEMTIME *date)
468 return MONTHCAL_GetMonth(date, 1);
471 /* properly updates date to point on prev month */
472 static inline void MONTHCAL_GetPrevMonth(SYSTEMTIME *date)
474 return MONTHCAL_GetMonth(date, -1);
477 /* Returns full date for a first currently visible day */
478 static void MONTHCAL_GetMinDate(const MONTHCAL_INFO *infoPtr, SYSTEMTIME *date)
480 /* zero indexed calendar has the earliest date */
481 SYSTEMTIME st_first = infoPtr->calendars[0].month;
485 firstDay = MONTHCAL_CalculateDayOfWeek(&st_first, FALSE);
487 *date = infoPtr->calendars[0].month;
488 MONTHCAL_GetPrevMonth(date);
490 date->wDay = MONTHCAL_MonthLength(date->wMonth, date->wYear) +
491 (infoPtr->firstDay - firstDay) % 7 + 1;
493 if(date->wDay > MONTHCAL_MonthLength(date->wMonth, date->wYear))
496 /* fix day of week */
497 MONTHCAL_CalculateDayOfWeek(date, TRUE);
500 /* Returns full date for a last currently visible day */
501 static void MONTHCAL_GetMaxDate(const MONTHCAL_INFO *infoPtr, SYSTEMTIME *date)
503 /* the latest date is in latest calendar */
504 SYSTEMTIME st, lt_month = infoPtr->calendars[infoPtr->cal_num-1].month;
507 MONTHCAL_GetNextMonth(date);
509 MONTHCAL_GetMinDate(infoPtr, &st);
510 /* Use month length to get max day. 42 means max day count in calendar area */
511 date->wDay = 42 - (MONTHCAL_MonthLength(st.wMonth, st.wYear) - st.wDay + 1) -
512 MONTHCAL_MonthLength(lt_month.wMonth, lt_month.wYear);
514 /* fix day of week */
515 MONTHCAL_CalculateDayOfWeek(date, TRUE);
518 /* From a given point, calculate the row (weekpos), column(daypos)
519 and day in the calendar. day== 0 mean the last day of tha last month
521 static int MONTHCAL_CalcDayFromPos(const MONTHCAL_INFO *infoPtr, int x, int y,
522 int *daypos, int *weekpos)
524 int retval, firstDay;
526 SYSTEMTIME st = infoPtr->minSel;
528 GetClientRect(infoPtr->hwndSelf, &rcClient);
530 /* if the point is outside the x bounds of the window put
531 it at the boundary */
532 if (x > rcClient.right)
535 *daypos = (x - infoPtr->calendars[0].days.left ) / infoPtr->width_increment;
536 *weekpos = (y - infoPtr->calendars[0].days.top ) / infoPtr->height_increment;
539 firstDay = (MONTHCAL_CalculateDayOfWeek(&st, FALSE) + 6 - infoPtr->firstDay) % 7;
540 retval = *daypos + (7 * *weekpos) - firstDay;
544 /* Sets the RECT struct r to the rectangle around the date
548 * [I] infoPtr : pointer to control data
549 * [I] date : date value
550 * [O] x : day column (zero based)
551 * [O] y : week column (zero based)
553 static void MONTHCAL_CalcDayXY(const MONTHCAL_INFO *infoPtr,
554 const SYSTEMTIME *date, INT *x, INT *y)
556 SYSTEMTIME st = infoPtr->minSel;
561 first = (MONTHCAL_CalculateDayOfWeek(&st, FALSE) + 6 - infoPtr->firstDay) % 7;
563 cmp = MONTHCAL_CompareMonths(date, &infoPtr->minSel);
567 *x = (first - MONTHCAL_MonthLength(date->wMonth, infoPtr->minSel.wYear) + date->wDay) % 7;
572 /* next month calculation is same as for current,
573 just add current month length */
575 first += MONTHCAL_MonthLength(infoPtr->minSel.wMonth, infoPtr->minSel.wYear);
578 *x = (date->wDay + first) % 7;
579 *y = (date->wDay + first - *x) / 7;
583 /* x: column(day), y: row(week) */
584 static inline void MONTHCAL_CalcDayRect(const MONTHCAL_INFO *infoPtr, RECT *r, int x, int y)
586 r->left = infoPtr->calendars[0].days.left + x * infoPtr->width_increment;
587 r->right = r->left + infoPtr->width_increment;
588 r->top = infoPtr->calendars[0].days.top + y * infoPtr->height_increment;
589 r->bottom = r->top + infoPtr->textHeight;
593 /* Sets the RECT struct r to the rectangle around the date */
594 static inline void MONTHCAL_CalcPosFromDay(const MONTHCAL_INFO *infoPtr,
595 const SYSTEMTIME *date, RECT *r)
599 MONTHCAL_CalcDayXY(infoPtr, date, &x, &y);
600 MONTHCAL_CalcDayRect(infoPtr, r, x, y);
603 /* Focused day helper:
605 - set focused date to given value;
606 - reset to zero value if NULL passed;
607 - invalidate previous and new day rectangle only if needed.
609 Returns TRUE if focused day changed, FALSE otherwise.
611 static BOOL MONTHCAL_SetDayFocus(MONTHCAL_INFO *infoPtr, const SYSTEMTIME *st)
617 /* there's nothing to do if it's the same date,
618 mouse move within same date rectangle case */
619 if(MONTHCAL_IsDateEqual(&infoPtr->focusedSel, st)) return FALSE;
621 /* invalidate old focused day */
622 MONTHCAL_CalcPosFromDay(infoPtr, &infoPtr->focusedSel, &r);
623 InvalidateRect(infoPtr->hwndSelf, &r, FALSE);
625 infoPtr->focusedSel = *st;
628 MONTHCAL_CalcPosFromDay(infoPtr, &infoPtr->focusedSel, &r);
630 if(!st && MONTHCAL_ValidateDate(&infoPtr->focusedSel))
631 infoPtr->focusedSel = st_null;
633 /* on set invalidates new day, on reset clears previous focused day */
634 InvalidateRect(infoPtr->hwndSelf, &r, FALSE);
639 /* Draw today day mark rectangle
641 * [I] hdc : context to draw in
642 * [I] day : day to mark with rectangle
645 static void MONTHCAL_CircleDay(const MONTHCAL_INFO *infoPtr, HDC hdc,
646 const SYSTEMTIME *date)
648 HPEN hRedPen = CreatePen(PS_SOLID, 1, RGB(255, 0, 0));
649 HPEN hOldPen2 = SelectObject(hdc, hRedPen);
653 MONTHCAL_CalcPosFromDay(infoPtr, date, &day_rect);
655 hOldBrush = SelectObject(hdc, GetStockObject(NULL_BRUSH));
656 Rectangle(hdc, day_rect.left, day_rect.top, day_rect.right, day_rect.bottom);
658 SelectObject(hdc, hOldBrush);
659 DeleteObject(hRedPen);
660 SelectObject(hdc, hOldPen2);
663 static void MONTHCAL_DrawDay(const MONTHCAL_INFO *infoPtr, HDC hdc, const SYSTEMTIME *st,
664 int bold, const PAINTSTRUCT *ps)
666 static const WCHAR fmtW[] = { '%','d',0 };
669 static BOOL bold_selected;
670 BOOL selected_day = FALSE;
675 /* No need to check styles: when selection is not valid, it is set to zero.
676 * 1<day<31, so everything is OK.
679 MONTHCAL_CalcPosFromDay(infoPtr, st, &r);
680 if(!IntersectRect(&r_temp, &(ps->rcPaint), &r)) return;
682 if ((MONTHCAL_CompareDate(st, &infoPtr->minSel) >= 0) &&
683 (MONTHCAL_CompareDate(st, &infoPtr->maxSel) <= 0)) {
685 TRACE("%d %d %d\n", st->wDay, infoPtr->minSel.wDay, infoPtr->maxSel.wDay);
686 TRACE("%s\n", wine_dbgstr_rect(&r));
687 oldCol = SetTextColor(hdc, infoPtr->colors[MCSC_MONTHBK]);
688 oldBk = SetBkColor(hdc, infoPtr->colors[MCSC_TRAILINGTEXT]);
689 hbr = GetSysColorBrush(COLOR_HIGHLIGHT);
690 FillRect(hdc, &r, hbr);
695 if(bold && !bold_selected) {
696 SelectObject(hdc, infoPtr->hBoldFont);
697 bold_selected = TRUE;
699 if(!bold && bold_selected) {
700 SelectObject(hdc, infoPtr->hFont);
701 bold_selected = FALSE;
704 SetBkMode(hdc,TRANSPARENT);
705 wsprintfW(buf, fmtW, st->wDay);
706 DrawTextW(hdc, buf, -1, &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE );
709 SetTextColor(hdc, oldCol);
710 SetBkColor(hdc, oldBk);
715 static void MONTHCAL_PaintButton(MONTHCAL_INFO *infoPtr, HDC hdc, enum nav_direction button)
717 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
718 RECT *r = button == DIRECTION_FORWARD ? &infoPtr->titlebtnnext : &infoPtr->titlebtnprev;
719 BOOL pressed = button == DIRECTION_FORWARD ? infoPtr->status & MC_NEXTPRESSED :
720 infoPtr->status & MC_PREVPRESSED;
723 static const int states[] = {
725 ABS_LEFTNORMAL, ABS_LEFTPRESSED, ABS_LEFTDISABLED,
727 ABS_RIGHTNORMAL, ABS_RIGHTPRESSED, ABS_RIGHTDISABLED
729 int stateNum = button == DIRECTION_FORWARD ? 3 : 0;
734 if (infoPtr->dwStyle & WS_DISABLED) stateNum += 2;
736 DrawThemeBackground (theme, hdc, SBP_ARROWBTN, states[stateNum], r, NULL);
740 int style = button == DIRECTION_FORWARD ? DFCS_SCROLLRIGHT : DFCS_SCROLLLEFT;
742 style |= DFCS_PUSHED;
745 if (infoPtr->dwStyle & WS_DISABLED) style |= DFCS_INACTIVE;
748 DrawFrameControl(hdc, r, DFC_SCROLL, style);
751 /* paint a title with buttons and month/year string */
752 static void MONTHCAL_PaintTitle(MONTHCAL_INFO *infoPtr, HDC hdc, const PAINTSTRUCT *ps, INT calIdx)
754 static const WCHAR fmt_monthW[] = { '%','s',' ','%','l','d',0 };
755 RECT *title = &infoPtr->calendars[calIdx].title;
756 const SYSTEMTIME *st = &infoPtr->calendars[calIdx].month;
757 WCHAR buf_month[80], buf_fmt[80];
761 /* fill header box */
762 hbr = CreateSolidBrush(infoPtr->colors[MCSC_TITLEBK]);
763 FillRect(hdc, title, hbr);
766 /* month/year string */
767 SetBkColor(hdc, infoPtr->colors[MCSC_TITLEBK]);
768 SetTextColor(hdc, infoPtr->colors[MCSC_TITLETEXT]);
769 SelectObject(hdc, infoPtr->hBoldFont);
771 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SMONTHNAME1 + st->wMonth - 1,
772 buf_month, countof(buf_month));
774 wsprintfW(buf_fmt, fmt_monthW, buf_month, st->wYear);
775 DrawTextW(hdc, buf_fmt, strlenW(buf_fmt), title,
776 DT_CENTER | DT_VCENTER | DT_SINGLELINE);
778 /* update title rectangles with current month - used while testing hits */
779 GetTextExtentPoint32W(hdc, buf_fmt, strlenW(buf_fmt), &sz);
780 infoPtr->calendars[calIdx].titlemonth.left = title->right / 2 + title->left / 2 - sz.cx / 2;
781 infoPtr->calendars[calIdx].titleyear.right = title->right / 2 + title->left / 2 + sz.cx / 2;
783 GetTextExtentPoint32W(hdc, buf_month, strlenW(buf_month), &sz);
784 infoPtr->calendars[calIdx].titlemonth.right = infoPtr->calendars[calIdx].titlemonth.left + sz.cx;
785 infoPtr->calendars[calIdx].titleyear.left = infoPtr->calendars[calIdx].titlemonth.right;
788 static void MONTHCAL_PaintWeeknumbers(const MONTHCAL_INFO *infoPtr, HDC hdc, const PAINTSTRUCT *ps, INT calIdx)
790 const SYSTEMTIME *date = &infoPtr->calendars[calIdx].month;
791 static const WCHAR fmt_weekW[] = { '%','d',0 };
792 INT mindays, weeknum, weeknum1, startofprescal;
799 if (!(infoPtr->dwStyle & MCS_WEEKNUMBERS)) return;
801 MONTHCAL_GetMinDate(infoPtr, &st);
802 startofprescal = st.wDay;
805 prev_month = date->wMonth - 1;
806 if(prev_month == 0) prev_month = 12;
809 Rules what week to call the first week of a new year:
810 LOCALE_IFIRSTWEEKOFYEAR == 0 (e.g US?):
811 The week containing Jan 1 is the first week of year
812 LOCALE_IFIRSTWEEKOFYEAR == 2 (e.g. Germany):
813 First week of year must contain 4 days of the new year
814 LOCALE_IFIRSTWEEKOFYEAR == 1 (what contries?)
815 The first week of the year must contain only days of the new year
817 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_IFIRSTWEEKOFYEAR, buf, countof(buf));
818 weeknum = atoiW(buf);
828 WARN("Unknown LOCALE_IFIRSTWEEKOFYEAR value %d, defaulting to 0\n", weeknum);
832 if (date->wMonth == 1)
834 /* calculate all those exceptions for january */
835 st.wDay = st.wMonth = 1;
836 weeknum1 = MONTHCAL_CalculateDayOfWeek(&st, FALSE);
837 if ((infoPtr->firstDay - weeknum1) % 7 > mindays)
842 for(i = 0; i < 11; i++)
843 weeknum += MONTHCAL_MonthLength(i+1, date->wYear - 1);
845 weeknum += startofprescal + 7;
848 weeknum1 = MONTHCAL_CalculateDayOfWeek(&st, FALSE);
849 if ((infoPtr->firstDay - weeknum1) % 7 > mindays) weeknum++;
855 for(i = 0; i < prev_month - 1; i++)
856 weeknum += MONTHCAL_MonthLength(i+1, date->wYear);
858 weeknum += startofprescal + 7;
860 st.wDay = st.wMonth = 1;
861 weeknum1 = MONTHCAL_CalculateDayOfWeek(&st, FALSE);
862 if ((infoPtr->firstDay - weeknum1) % 7 > mindays) weeknum++;
865 r = infoPtr->calendars[calIdx].weeknums;
867 /* erase whole week numbers area */
868 hbr = CreateSolidBrush(infoPtr->colors[MCSC_MONTHBK]);
869 FillRect(hdc, &r, hbr);
872 /* reduce rectangle to one week number */
873 r.bottom = r.top + infoPtr->height_increment;
875 for(i = 0; i < 6; i++) {
876 if((i == 0) && (weeknum > 50))
878 wsprintfW(buf, fmt_weekW, weeknum);
881 else if((i == 5) && (weeknum > 47))
883 wsprintfW(buf, fmt_weekW, 1);
886 wsprintfW(buf, fmt_weekW, weeknum + i);
888 DrawTextW(hdc, buf, -1, &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
889 OffsetRect(&r, 0, infoPtr->height_increment);
892 /* line separator for week numbers column */
893 MoveToEx(hdc, infoPtr->calendars[calIdx].weeknums.right, infoPtr->calendars[calIdx].weeknums.top + 3 , NULL);
894 LineTo(hdc, infoPtr->calendars[calIdx].weeknums.right, infoPtr->calendars[calIdx].weeknums.bottom);
897 /* bottom today date */
898 static void MONTHCAL_PaintTodayTitle(const MONTHCAL_INFO *infoPtr, HDC hdc, const PAINTSTRUCT *ps)
900 if(!(infoPtr->dwStyle & MCS_NOTODAY)) {
901 static const WCHAR todayW[] = { 'T','o','d','a','y',':',0 };
902 static const WCHAR fmt_todayW[] = { '%','s',' ','%','s',0 };
903 WCHAR buf_todayW[30], buf_dateW[20], buf[80];
906 if(!(infoPtr->dwStyle & MCS_NOTODAYCIRCLE)) {
909 MONTHCAL_GetMaxDate(infoPtr, &fake_st);
910 /* this is always safe cause next month will never fully fit calendar */
912 MONTHCAL_CircleDay(infoPtr, hdc, &fake_st);
914 if (!LoadStringW(COMCTL32_hModule, IDM_TODAY, buf_todayW, countof(buf_todayW)))
916 WARN("Can't load resource\n");
917 strcpyW(buf_todayW, todayW);
919 MONTHCAL_CalcDayRect(infoPtr, &rtoday, 1, 6);
920 GetDateFormatW(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &infoPtr->todaysDate, NULL,
921 buf_dateW, countof(buf_dateW));
922 SelectObject(hdc, infoPtr->hBoldFont);
924 wsprintfW(buf, fmt_todayW, buf_todayW, buf_dateW);
925 DrawTextW(hdc, buf, -1, &rtoday, DT_CALCRECT | DT_LEFT | DT_VCENTER | DT_SINGLELINE);
926 DrawTextW(hdc, buf, -1, &rtoday, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
928 SelectObject(hdc, infoPtr->hFont);
932 /* today mark + focus */
933 static void MONTHCAL_PaintFocusAndCircle(const MONTHCAL_INFO *infoPtr, HDC hdc, const PAINTSTRUCT *ps)
935 if((infoPtr->minSel.wMonth == infoPtr->todaysDate.wMonth) &&
936 (infoPtr->minSel.wYear == infoPtr->todaysDate.wYear) &&
937 !(infoPtr->dwStyle & MCS_NOTODAYCIRCLE))
939 MONTHCAL_CircleDay(infoPtr, hdc, &infoPtr->todaysDate);
942 if(!MONTHCAL_IsDateEqual(&infoPtr->focusedSel, &st_null))
945 MONTHCAL_CalcPosFromDay(infoPtr, &infoPtr->focusedSel, &r);
946 DrawFocusRect(hdc, &r);
950 /* paint a calendar area */
951 static void MONTHCAL_PaintCalendar(const MONTHCAL_INFO *infoPtr, HDC hdc, const PAINTSTRUCT *ps, INT calIdx)
953 const SYSTEMTIME *date = &infoPtr->calendars[calIdx].month;
954 INT prev_month, i, j, length;
955 RECT r, fill_bk_rect;
961 /* fill whole days area - from week days area to today note rectangle */
962 fill_bk_rect = infoPtr->calendars[calIdx].wdays;
963 fill_bk_rect.bottom = infoPtr->calendars[calIdx].days.bottom +
964 (infoPtr->todayrect.bottom - infoPtr->todayrect.top);
966 hbr = CreateSolidBrush(infoPtr->colors[MCSC_MONTHBK]);
967 FillRect(hdc, &fill_bk_rect, hbr);
970 /* draw line under day abbreviations */
971 MoveToEx(hdc, infoPtr->calendars[calIdx].days.left + 3,
972 infoPtr->calendars[calIdx].title.bottom + infoPtr->textHeight + 1, NULL);
973 LineTo(hdc, infoPtr->calendars[calIdx].days.right - 3,
974 infoPtr->calendars[calIdx].title.bottom + infoPtr->textHeight + 1);
976 prev_month = date->wMonth - 1;
977 if (prev_month == 0) prev_month = 12;
979 infoPtr->calendars[calIdx].wdays.left = infoPtr->calendars[calIdx].days.left =
980 infoPtr->calendars[calIdx].weeknums.right;
982 /* 1. draw day abbreviations */
983 SelectObject(hdc, infoPtr->hFont);
984 SetBkColor(hdc, infoPtr->colors[MCSC_MONTHBK]);
985 SetTextColor(hdc, infoPtr->colors[MCSC_TRAILINGTEXT]);
986 /* rectangle to draw a single day abbreviation within */
987 r = infoPtr->calendars[calIdx].wdays;
988 r.right = r.left + infoPtr->width_increment;
990 i = infoPtr->firstDay;
991 for(j = 0; j < 7; j++) {
992 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SABBREVDAYNAME1 + (i+j+6)%7, buf, countof(buf));
993 DrawTextW(hdc, buf, strlenW(buf), &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
994 OffsetRect(&r, infoPtr->width_increment, 0);
997 /* 2. previous and next months */
998 if (!(infoPtr->dwStyle & MCS_NOTRAILINGDATES) && (calIdx == 0 || calIdx == infoPtr->cal_num - 1))
1002 SetTextColor(hdc, infoPtr->colors[MCSC_TRAILINGTEXT]);
1004 /* draw prev month */
1007 MONTHCAL_GetMinDate(infoPtr, &st);
1008 mask = 1 << (st.wDay-1);
1009 length = MONTHCAL_MonthLength(prev_month, date->wYear);
1011 while(st.wDay <= length)
1013 MONTHCAL_DrawDay(infoPtr, hdc, &st, infoPtr->monthdayState[0] & mask, ps);
1019 /* draw next month */
1020 if (calIdx == infoPtr->cal_num - 1)
1024 MONTHCAL_GetNextMonth(&st);
1025 MONTHCAL_GetMaxDate(infoPtr, &st_max);
1028 while(st.wDay <= st_max.wDay)
1030 MONTHCAL_DrawDay(infoPtr, hdc, &st, infoPtr->monthdayState[2] & mask, ps);
1037 /* 3. current month */
1038 SetTextColor(hdc, infoPtr->colors[MCSC_TEXT]);
1042 length = MONTHCAL_MonthLength(date->wMonth, date->wYear);
1043 while(st.wDay <= length)
1045 MONTHCAL_DrawDay(infoPtr, hdc, &st, infoPtr->monthdayState[1] & mask, ps);
1051 static void MONTHCAL_Refresh(MONTHCAL_INFO *infoPtr, HDC hdc, const PAINTSTRUCT *ps)
1053 COLORREF old_text_clr, old_bk_clr;
1057 old_text_clr = SetTextColor(hdc, comctl32_color.clrWindowText);
1058 old_bk_clr = GetBkColor(hdc);
1059 old_font = GetCurrentObject(hdc, OBJ_FONT);
1061 for (i = 0; i < infoPtr->cal_num; i++)
1063 RECT *title = &infoPtr->calendars[i].title;
1066 /* draw title, redraw all its elements */
1067 if (IntersectRect(&r, &(ps->rcPaint), title))
1068 MONTHCAL_PaintTitle(infoPtr, hdc, ps, i);
1070 /* draw calendar area */
1071 UnionRect(&r, &infoPtr->calendars[i].wdays, &infoPtr->todayrect);
1072 if (IntersectRect(&r, &(ps->rcPaint), &r))
1073 MONTHCAL_PaintCalendar(infoPtr, hdc, ps, i);
1076 MONTHCAL_PaintWeeknumbers(infoPtr, hdc, ps, i);
1079 /* focus and today rectangle */
1080 MONTHCAL_PaintFocusAndCircle(infoPtr, hdc, ps);
1082 /* today at the bottom left */
1083 MONTHCAL_PaintTodayTitle(infoPtr, hdc, ps);
1085 /* navigation buttons */
1086 MONTHCAL_PaintButton(infoPtr, hdc, DIRECTION_BACKWARD);
1087 MONTHCAL_PaintButton(infoPtr, hdc, DIRECTION_FORWARD);
1089 /* restore context */
1090 SetBkColor(hdc, old_bk_clr);
1091 SelectObject(hdc, old_font);
1092 SetTextColor(hdc, old_text_clr);
1096 MONTHCAL_GetMinReqRect(const MONTHCAL_INFO *infoPtr, RECT *rect)
1098 TRACE("rect %p\n", rect);
1100 if(!rect) return FALSE;
1102 *rect = infoPtr->calendars[0].title;
1103 rect->bottom = infoPtr->calendars[0].days.bottom + infoPtr->todayrect.bottom -
1104 infoPtr->todayrect.top;
1106 AdjustWindowRect(rect, infoPtr->dwStyle, FALSE);
1108 /* minimal rectangle is zero based */
1109 OffsetRect(rect, -rect->left, -rect->top);
1111 TRACE("%s\n", wine_dbgstr_rect(rect));
1117 MONTHCAL_GetColor(const MONTHCAL_INFO *infoPtr, UINT index)
1119 TRACE("%p, %d\n", infoPtr, index);
1121 if (index > MCSC_TRAILINGTEXT) return -1;
1122 return infoPtr->colors[index];
1126 MONTHCAL_SetColor(MONTHCAL_INFO *infoPtr, UINT index, COLORREF color)
1130 TRACE("%p, %d: color %08x\n", infoPtr, index, color);
1132 if (index > MCSC_TRAILINGTEXT) return -1;
1134 prev = infoPtr->colors[index];
1135 infoPtr->colors[index] = color;
1137 InvalidateRect(infoPtr->hwndSelf, NULL, index == MCSC_BACKGROUND ? TRUE : FALSE);
1142 MONTHCAL_GetMonthDelta(const MONTHCAL_INFO *infoPtr)
1147 return infoPtr->delta;
1149 return infoPtr->visible;
1154 MONTHCAL_SetMonthDelta(MONTHCAL_INFO *infoPtr, INT delta)
1156 INT prev = infoPtr->delta;
1158 TRACE("delta %d\n", delta);
1160 infoPtr->delta = delta;
1165 static inline LRESULT
1166 MONTHCAL_GetFirstDayOfWeek(const MONTHCAL_INFO *infoPtr)
1170 /* convert from SYSTEMTIME to locale format */
1171 day = (infoPtr->firstDay >= 0) ? (infoPtr->firstDay+6)%7 : infoPtr->firstDay;
1173 return MAKELONG(day, infoPtr->firstDaySet);
1177 /* Sets the first day of the week that will appear in the control
1181 * [I] infoPtr : valid pointer to control data
1182 * [I] day : day number to set as new first day (0 == Monday,...,6 == Sunday)
1186 * Low word contains previous first day,
1187 * high word indicates was first day forced with this message before or is
1188 * locale difined (TRUE - was forced, FALSE - wasn't).
1190 * FIXME: this needs to be implemented properly in MONTHCAL_Refresh()
1191 * FIXME: we need more error checking here
1194 MONTHCAL_SetFirstDayOfWeek(MONTHCAL_INFO *infoPtr, INT day)
1196 LRESULT prev = MONTHCAL_GetFirstDayOfWeek(infoPtr);
1205 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_IFIRSTDAYOFWEEK, buf, countof(buf));
1206 TRACE("%s %d\n", debugstr_w(buf), strlenW(buf));
1208 new_day = atoiW(buf);
1210 infoPtr->firstDaySet = FALSE;
1214 new_day = 6; /* max first day allowed */
1215 infoPtr->firstDaySet = TRUE;
1219 /* Native behaviour for that case is broken: invalid date number >31
1220 got displayed at (0,0) position, current month starts always from
1221 (1,0) position. Should be implemented here as well only if there's
1222 nothing else to do. */
1224 FIXME("No bug compatibility for day=%d\n", day);
1227 infoPtr->firstDaySet = TRUE;
1230 /* convert from locale to SYSTEMTIME format */
1231 infoPtr->firstDay = (new_day >= 0) ? (++new_day) % 7 : new_day;
1233 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1240 MONTHCAL_GetMonthRange(const MONTHCAL_INFO *infoPtr, DWORD flag, SYSTEMTIME *st)
1242 TRACE("flag=%d, st=%p\n", flag, st);
1249 st[0] = infoPtr->calendars[0].month;
1250 st[1] = infoPtr->calendars[infoPtr->cal_num-1].month;
1252 if (st[0].wMonth == min_allowed_date.wMonth &&
1253 st[0].wYear == min_allowed_date.wYear)
1255 st[0].wDay = min_allowed_date.wDay;
1259 MONTHCAL_CalculateDayOfWeek(&st[0], TRUE);
1261 st[1].wDay = MONTHCAL_MonthLength(st[1].wMonth, st[1].wYear);
1262 MONTHCAL_CalculateDayOfWeek(&st[1], TRUE);
1264 return infoPtr->cal_num;
1268 /*FIXME: currently multicalendar feature isn't implemented,
1269 min date from previous month and max date from next one returned */
1270 MONTHCAL_GetMinDate(infoPtr, &st[0]);
1271 MONTHCAL_GetMaxDate(infoPtr, &st[1]);
1275 WARN("Unknown flag value, got %d\n", flag);
1279 return infoPtr->monthRange;
1284 MONTHCAL_GetMaxTodayWidth(const MONTHCAL_INFO *infoPtr)
1286 return(infoPtr->todayrect.right - infoPtr->todayrect.left);
1291 MONTHCAL_SetRange(MONTHCAL_INFO *infoPtr, SHORT limits, SYSTEMTIME *range)
1293 FILETIME ft_min, ft_max;
1295 TRACE("%x %p\n", limits, range);
1297 if ((limits & GDTR_MIN && !MONTHCAL_ValidateDate(&range[0])) ||
1298 (limits & GDTR_MAX && !MONTHCAL_ValidateDate(&range[1])))
1301 if (limits & GDTR_MIN)
1303 if (!MONTHCAL_ValidateTime(&range[0]))
1304 MONTHCAL_CopyTime(&infoPtr->todaysDate, &range[0]);
1306 infoPtr->minDate = range[0];
1307 infoPtr->rangeValid |= GDTR_MIN;
1309 if (limits & GDTR_MAX)
1311 if (!MONTHCAL_ValidateTime(&range[1]))
1312 MONTHCAL_CopyTime(&infoPtr->todaysDate, &range[1]);
1314 infoPtr->maxDate = range[1];
1315 infoPtr->rangeValid |= GDTR_MAX;
1318 /* Only one limit set - we are done */
1319 if ((infoPtr->rangeValid & (GDTR_MIN | GDTR_MAX)) != (GDTR_MIN | GDTR_MAX))
1322 SystemTimeToFileTime(&infoPtr->maxDate, &ft_max);
1323 SystemTimeToFileTime(&infoPtr->minDate, &ft_min);
1325 if (CompareFileTime(&ft_min, &ft_max) >= 0)
1327 if ((limits & (GDTR_MIN | GDTR_MAX)) == (GDTR_MIN | GDTR_MAX))
1329 /* Native swaps limits only when both limits are being set. */
1330 SYSTEMTIME st_tmp = infoPtr->minDate;
1331 infoPtr->minDate = infoPtr->maxDate;
1332 infoPtr->maxDate = st_tmp;
1336 /* reset the other limit */
1337 if (limits & GDTR_MIN) infoPtr->maxDate = st_null;
1338 if (limits & GDTR_MAX) infoPtr->minDate = st_null;
1339 infoPtr->rangeValid &= limits & GDTR_MIN ? ~GDTR_MAX : ~GDTR_MIN;
1348 MONTHCAL_GetRange(const MONTHCAL_INFO *infoPtr, SYSTEMTIME *range)
1350 TRACE("%p\n", range);
1352 if(!range) return FALSE;
1354 range[1] = infoPtr->maxDate;
1355 range[0] = infoPtr->minDate;
1357 return infoPtr->rangeValid;
1362 MONTHCAL_SetDayState(const MONTHCAL_INFO *infoPtr, INT months, MONTHDAYSTATE *states)
1364 TRACE("%p %d %p\n", infoPtr, months, states);
1365 if(months != infoPtr->monthRange) return 0;
1367 memcpy(infoPtr->monthdayState, states, months*sizeof(MONTHDAYSTATE));
1373 MONTHCAL_GetCurSel(const MONTHCAL_INFO *infoPtr, SYSTEMTIME *curSel)
1375 TRACE("%p\n", curSel);
1376 if(!curSel) return FALSE;
1377 if(infoPtr->dwStyle & MCS_MULTISELECT) return FALSE;
1379 *curSel = infoPtr->minSel;
1380 TRACE("%d/%d/%d\n", curSel->wYear, curSel->wMonth, curSel->wDay);
1385 MONTHCAL_SetCurSel(MONTHCAL_INFO *infoPtr, SYSTEMTIME *curSel)
1387 SYSTEMTIME prev = infoPtr->minSel;
1390 TRACE("%p\n", curSel);
1391 if(!curSel) return FALSE;
1392 if(infoPtr->dwStyle & MCS_MULTISELECT) return FALSE;
1394 if(!MONTHCAL_ValidateDate(curSel)) return FALSE;
1395 /* exit earlier if selection equals current */
1396 if (MONTHCAL_IsDateEqual(&infoPtr->minSel, curSel)) return TRUE;
1398 if(!MONTHCAL_IsDateInValidRange(infoPtr, curSel, FALSE)) return FALSE;
1400 infoPtr->calendars[0].month = *curSel;
1401 infoPtr->minSel = *curSel;
1402 infoPtr->maxSel = *curSel;
1404 /* if selection is still in current month, reduce rectangle */
1406 prev.wDay = curSel->wDay;
1407 if (MONTHCAL_IsDateEqual(&prev, curSel))
1412 MONTHCAL_CalcPosFromDay(infoPtr, &prev, &r_prev);
1413 MONTHCAL_CalcPosFromDay(infoPtr, curSel, &r_new);
1415 InvalidateRect(infoPtr->hwndSelf, &r_prev, FALSE);
1416 InvalidateRect(infoPtr->hwndSelf, &r_new, FALSE);
1419 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1426 MONTHCAL_GetMaxSelCount(const MONTHCAL_INFO *infoPtr)
1428 return infoPtr->maxSelCount;
1433 MONTHCAL_SetMaxSelCount(MONTHCAL_INFO *infoPtr, INT max)
1437 if(!(infoPtr->dwStyle & MCS_MULTISELECT)) return FALSE;
1438 if(max <= 0) return FALSE;
1440 infoPtr->maxSelCount = max;
1447 MONTHCAL_GetSelRange(const MONTHCAL_INFO *infoPtr, SYSTEMTIME *range)
1449 TRACE("%p\n", range);
1451 if(!range) return FALSE;
1453 if(infoPtr->dwStyle & MCS_MULTISELECT)
1455 range[1] = infoPtr->maxSel;
1456 range[0] = infoPtr->minSel;
1457 TRACE("[min,max]=[%d %d]\n", infoPtr->minSel.wDay, infoPtr->maxSel.wDay);
1466 MONTHCAL_SetSelRange(MONTHCAL_INFO *infoPtr, SYSTEMTIME *range)
1468 TRACE("%p\n", range);
1470 if(!range) return FALSE;
1472 if(infoPtr->dwStyle & MCS_MULTISELECT)
1474 SYSTEMTIME old_range[2];
1476 /* adjust timestamps */
1477 if(!MONTHCAL_ValidateTime(&range[0]))
1478 MONTHCAL_CopyTime(&infoPtr->todaysDate, &range[0]);
1479 if(!MONTHCAL_ValidateTime(&range[1]))
1480 MONTHCAL_CopyTime(&infoPtr->todaysDate, &range[1]);
1482 /* maximum range exceeded */
1483 if(!MONTHCAL_IsSelRangeValid(infoPtr, &range[0], &range[1], NULL)) return FALSE;
1485 old_range[0] = infoPtr->minSel;
1486 old_range[1] = infoPtr->maxSel;
1488 /* swap if min > max */
1489 if(MONTHCAL_CompareSystemTime(&range[0], &range[1]) <= 0)
1491 infoPtr->minSel = range[0];
1492 infoPtr->maxSel = range[1];
1496 infoPtr->minSel = range[1];
1497 infoPtr->maxSel = range[0];
1499 infoPtr->calendars[0].month = infoPtr->minSel;
1501 /* update day of week */
1502 MONTHCAL_CalculateDayOfWeek(&infoPtr->minSel, TRUE);
1503 MONTHCAL_CalculateDayOfWeek(&infoPtr->maxSel, TRUE);
1505 /* redraw if bounds changed */
1506 /* FIXME: no actual need to redraw everything */
1507 if(!MONTHCAL_IsDateEqual(&old_range[0], &range[0]) ||
1508 !MONTHCAL_IsDateEqual(&old_range[1], &range[1]))
1510 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1513 TRACE("[min,max]=[%d %d]\n", infoPtr->minSel.wDay, infoPtr->maxSel.wDay);
1522 MONTHCAL_GetToday(const MONTHCAL_INFO *infoPtr, SYSTEMTIME *today)
1524 TRACE("%p\n", today);
1526 if(!today) return FALSE;
1527 *today = infoPtr->todaysDate;
1531 /* Internal helper for MCM_SETTODAY handler and auto update timer handler
1535 * TRUE - today date changed
1536 * FALSE - today date isn't changed
1539 MONTHCAL_UpdateToday(MONTHCAL_INFO *infoPtr, const SYSTEMTIME *today)
1543 if(MONTHCAL_IsDateEqual(today, &infoPtr->todaysDate)) return FALSE;
1545 MONTHCAL_CalcPosFromDay(infoPtr, &infoPtr->todaysDate, &old_r);
1546 MONTHCAL_CalcPosFromDay(infoPtr, today, &new_r);
1548 infoPtr->todaysDate = *today;
1550 /* only two days need redrawing */
1551 InvalidateRect(infoPtr->hwndSelf, &old_r, FALSE);
1552 InvalidateRect(infoPtr->hwndSelf, &new_r, FALSE);
1556 /* MCM_SETTODAT handler */
1558 MONTHCAL_SetToday(MONTHCAL_INFO *infoPtr, const SYSTEMTIME *today)
1560 TRACE("%p\n", today);
1562 if(!today) return FALSE;
1564 /* remember if date was set successfully */
1565 if(MONTHCAL_UpdateToday(infoPtr, today)) infoPtr->todaySet = TRUE;
1570 /* returns calendar index containing specified point, or -1 if it's background */
1571 static INT MONTHCAL_GetCalendarFromPoint(const MONTHCAL_INFO *infoPtr, const POINT *pt)
1576 for (i = 0; i < infoPtr->cal_num; i++)
1578 /* whole bounding rectangle allows some optimization to compute */
1579 r.left = infoPtr->calendars[i].title.left;
1580 r.top = infoPtr->calendars[i].title.top;
1581 r.bottom = infoPtr->calendars[i].days.bottom;
1582 r.right = infoPtr->calendars[i].days.right;
1584 if (PtInRect(&r, *pt)) return i;
1590 static inline UINT fill_hittest_info(const MCHITTESTINFO *src, MCHITTESTINFO *dest)
1592 dest->uHit = src->uHit;
1595 if (dest->cbSize == sizeof(MCHITTESTINFO))
1596 memcpy(&dest->rc, &src->rc, sizeof(MCHITTESTINFO) - MCHITTESTINFO_V1_SIZE);
1602 MONTHCAL_HitTest(const MONTHCAL_INFO *infoPtr, MCHITTESTINFO *lpht)
1604 INT day, wday, wnum, calIdx;
1605 MCHITTESTINFO htinfo;
1606 SYSTEMTIME ht_month;
1609 if(!lpht || lpht->cbSize < MCHITTESTINFO_V1_SIZE) return -1;
1614 htinfo.st = st_null;
1616 /* we should preserve passed fields if hit area doesn't need them */
1617 if (lpht->cbSize == sizeof(MCHITTESTINFO))
1618 memcpy(&htinfo.rc, &lpht->rc, sizeof(MCHITTESTINFO) - MCHITTESTINFO_V1_SIZE);
1620 /* Comment in for debugging...
1621 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,
1622 infoPtr->wdays.left, infoPtr->wdays.right,
1623 infoPtr->wdays.top, infoPtr->wdays.bottom,
1624 infoPtr->days.left, infoPtr->days.right,
1625 infoPtr->days.top, infoPtr->days.bottom,
1626 infoPtr->todayrect.left, infoPtr->todayrect.right,
1627 infoPtr->todayrect.top, infoPtr->todayrect.bottom,
1628 infoPtr->weeknums.left, infoPtr->weeknums.right,
1629 infoPtr->weeknums.top, infoPtr->weeknums.bottom);
1632 /* guess in what calendar we are */
1633 calIdx = MONTHCAL_GetCalendarFromPoint(infoPtr, &lpht->pt);
1636 if (PtInRect(&infoPtr->todayrect, lpht->pt))
1638 htinfo.uHit = MCHT_TODAYLINK;
1639 htinfo.rc = infoPtr->todayrect;
1642 /* outside of calendar area? What's left must be background :-) */
1643 htinfo.uHit = MCHT_CALENDARBK;
1645 return fill_hittest_info(&htinfo, lpht);
1648 ht_month = infoPtr->calendars[calIdx].month;
1650 /* are we in the header? */
1651 if (PtInRect(&infoPtr->calendars[calIdx].title, lpht->pt)) {
1652 /* FIXME: buttons hittesting could be optimized cause maximum
1653 two calendars have buttons */
1654 if (calIdx == 0 && PtInRect(&infoPtr->titlebtnprev, lpht->pt))
1656 htinfo.uHit = MCHT_TITLEBTNPREV;
1657 htinfo.rc = infoPtr->titlebtnprev;
1659 else if (PtInRect(&infoPtr->titlebtnnext, lpht->pt))
1661 htinfo.uHit = MCHT_TITLEBTNNEXT;
1662 htinfo.rc = infoPtr->titlebtnnext;
1664 else if (PtInRect(&infoPtr->calendars[calIdx].titlemonth, lpht->pt))
1666 htinfo.uHit = MCHT_TITLEMONTH;
1667 htinfo.rc = infoPtr->calendars[calIdx].titlemonth;
1668 htinfo.iOffset = calIdx;
1670 else if (PtInRect(&infoPtr->calendars[calIdx].titleyear, lpht->pt))
1672 htinfo.uHit = MCHT_TITLEYEAR;
1673 htinfo.rc = infoPtr->calendars[calIdx].titleyear;
1674 htinfo.iOffset = calIdx;
1678 htinfo.uHit = MCHT_TITLE;
1679 htinfo.rc = infoPtr->calendars[calIdx].title;
1680 htinfo.iOffset = calIdx;
1683 return fill_hittest_info(&htinfo, lpht);
1686 /* days area (including week days and week numbers */
1687 day = MONTHCAL_CalcDayFromPos(infoPtr, x, y, &wday, &wnum);
1688 if (PtInRect(&infoPtr->calendars[calIdx].wdays, lpht->pt))
1690 htinfo.uHit = MCHT_CALENDARDAY;
1691 htinfo.iOffset = calIdx;
1692 htinfo.st.wYear = ht_month.wYear;
1693 htinfo.st.wMonth = (day < 1) ? ht_month.wMonth -1 : ht_month.wMonth;
1694 htinfo.st.wDay = (day < 1) ?
1695 MONTHCAL_MonthLength(ht_month.wMonth-1, ht_month.wYear) - day : day;
1697 MONTHCAL_CalcDayXY(infoPtr, &htinfo.st, &htinfo.iCol, &htinfo.iRow);
1699 else if(PtInRect(&infoPtr->calendars[calIdx].weeknums, lpht->pt))
1701 htinfo.uHit = MCHT_CALENDARWEEKNUM;
1702 htinfo.st.wYear = ht_month.wYear;
1703 htinfo.iOffset = calIdx;
1707 htinfo.st.wMonth = ht_month.wMonth - 1;
1708 htinfo.st.wDay = MONTHCAL_MonthLength(ht_month.wMonth-1, ht_month.wYear) - day;
1710 else if (day > MONTHCAL_MonthLength(ht_month.wMonth, ht_month.wYear))
1712 htinfo.st.wMonth = ht_month.wMonth + 1;
1713 htinfo.st.wDay = day - MONTHCAL_MonthLength(ht_month.wMonth, ht_month.wYear);
1717 htinfo.st.wMonth = ht_month.wMonth;
1718 htinfo.st.wDay = day;
1721 else if(PtInRect(&infoPtr->calendars[calIdx].days, lpht->pt))
1723 htinfo.iOffset = calIdx;
1724 htinfo.st.wYear = ht_month.wYear;
1725 htinfo.st.wMonth = ht_month.wMonth;
1728 htinfo.uHit = MCHT_CALENDARDATEPREV;
1729 MONTHCAL_GetPrevMonth(&htinfo.st);
1730 htinfo.st.wDay = MONTHCAL_MonthLength(lpht->st.wMonth, lpht->st.wYear) + day;
1732 else if (day > MONTHCAL_MonthLength(ht_month.wMonth, ht_month.wYear))
1734 htinfo.uHit = MCHT_CALENDARDATENEXT;
1735 MONTHCAL_GetNextMonth(&htinfo.st);
1736 htinfo.st.wDay = day - MONTHCAL_MonthLength(ht_month.wMonth, ht_month.wYear);
1740 htinfo.uHit = MCHT_CALENDARDATE;
1741 htinfo.st.wDay = day;
1744 MONTHCAL_CalcDayXY(infoPtr, &htinfo.st, &htinfo.iCol, &htinfo.iRow);
1745 MONTHCAL_CalcDayRect(infoPtr, &htinfo.rc, htinfo.iCol, htinfo.iRow);
1746 /* always update day of week */
1747 MONTHCAL_CalculateDayOfWeek(&htinfo.st, TRUE);
1750 return fill_hittest_info(&htinfo, lpht);
1753 /* MCN_GETDAYSTATE notification helper */
1754 static void MONTHCAL_NotifyDayState(MONTHCAL_INFO *infoPtr)
1756 if(infoPtr->dwStyle & MCS_DAYSTATE) {
1759 nmds.nmhdr.hwndFrom = infoPtr->hwndSelf;
1760 nmds.nmhdr.idFrom = GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_ID);
1761 nmds.nmhdr.code = MCN_GETDAYSTATE;
1762 nmds.cDayState = infoPtr->monthRange;
1763 nmds.prgDayState = Alloc(infoPtr->monthRange * sizeof(MONTHDAYSTATE));
1765 nmds.stStart = infoPtr->todaysDate;
1766 nmds.stStart.wYear = infoPtr->minSel.wYear;
1767 nmds.stStart.wMonth = infoPtr->minSel.wMonth;
1768 nmds.stStart.wDay = 1;
1770 SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, nmds.nmhdr.idFrom, (LPARAM)&nmds);
1771 memcpy(infoPtr->monthdayState, nmds.prgDayState, infoPtr->monthRange*sizeof(MONTHDAYSTATE));
1773 Free(nmds.prgDayState);
1777 /* no valid range check performed */
1778 static void MONTHCAL_Scroll(MONTHCAL_INFO *infoPtr, INT delta)
1782 for(i = 0; i < infoPtr->cal_num; i++)
1784 /* save selection position to shift it later */
1785 if (selIdx == -1 && MONTHCAL_CompareMonths(&infoPtr->minSel, &infoPtr->calendars[i].month) == 0)
1788 MONTHCAL_GetMonth(&infoPtr->calendars[i].month, delta);
1791 /* selection is always shifted to first calendar */
1792 if(infoPtr->dwStyle & MCS_MULTISELECT)
1794 SYSTEMTIME range[2];
1796 MONTHCAL_GetSelRange(infoPtr, range);
1797 MONTHCAL_GetMonth(&range[0], delta - selIdx);
1798 MONTHCAL_GetMonth(&range[1], delta - selIdx);
1799 MONTHCAL_SetSelRange(infoPtr, range);
1803 SYSTEMTIME st = infoPtr->minSel;
1805 MONTHCAL_GetMonth(&st, delta - selIdx);
1806 MONTHCAL_SetCurSel(infoPtr, &st);
1810 static void MONTHCAL_GoToMonth(MONTHCAL_INFO *infoPtr, enum nav_direction direction)
1812 INT delta = infoPtr->delta ? infoPtr->delta : infoPtr->cal_num;
1815 TRACE("%s\n", direction == DIRECTION_BACKWARD ? "back" : "fwd");
1817 /* check if change allowed by range set */
1818 if(direction == DIRECTION_BACKWARD)
1820 st = infoPtr->calendars[0].month;
1821 MONTHCAL_GetMonth(&st, -delta);
1825 st = infoPtr->calendars[infoPtr->cal_num-1].month;
1826 MONTHCAL_GetMonth(&st, delta);
1829 if(!MONTHCAL_IsDateInValidRange(infoPtr, &st, FALSE)) return;
1831 MONTHCAL_Scroll(infoPtr, direction == DIRECTION_BACKWARD ? -delta : delta);
1832 MONTHCAL_NotifyDayState(infoPtr);
1833 MONTHCAL_NotifySelectionChange(infoPtr);
1837 MONTHCAL_RButtonUp(MONTHCAL_INFO *infoPtr, LPARAM lParam)
1839 static const WCHAR todayW[] = { 'G','o',' ','t','o',' ','T','o','d','a','y',':',0 };
1844 hMenu = CreatePopupMenu();
1845 if (!LoadStringW(COMCTL32_hModule, IDM_GOTODAY, buf, countof(buf)))
1847 WARN("Can't load resource\n");
1848 strcpyW(buf, todayW);
1850 AppendMenuW(hMenu, MF_STRING|MF_ENABLED, 1, buf);
1851 menupoint.x = (short)LOWORD(lParam);
1852 menupoint.y = (short)HIWORD(lParam);
1853 ClientToScreen(infoPtr->hwndSelf, &menupoint);
1854 if( TrackPopupMenu(hMenu, TPM_RIGHTBUTTON | TPM_NONOTIFY | TPM_RETURNCMD,
1855 menupoint.x, menupoint.y, 0, infoPtr->hwndSelf, NULL))
1857 infoPtr->calendars[0].month = infoPtr->todaysDate;
1858 infoPtr->minSel = infoPtr->todaysDate;
1859 infoPtr->maxSel = infoPtr->todaysDate;
1860 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1868 * Subclassed edit control windproc function
1871 * [I] hwnd : the edit window handle
1872 * [I] uMsg : the message that is to be processed
1873 * [I] wParam : first message parameter
1874 * [I] lParam : second message parameter
1877 static LRESULT CALLBACK EditWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1879 MONTHCAL_INFO *infoPtr = (MONTHCAL_INFO *)GetWindowLongPtrW(GetParent(hwnd), 0);
1881 TRACE("(hwnd=%p, uMsg=%x, wParam=%lx, lParam=%lx)\n",
1882 hwnd, uMsg, wParam, lParam);
1887 return DLGC_WANTARROWS | DLGC_WANTALLKEYS;
1891 WNDPROC editProc = infoPtr->EditWndProc;
1892 infoPtr->EditWndProc = NULL;
1893 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (DWORD_PTR)editProc);
1894 return CallWindowProcW(editProc, hwnd, uMsg, wParam, lParam);
1901 if ((VK_ESCAPE == (INT)wParam) || (VK_RETURN == (INT)wParam))
1905 return CallWindowProcW(infoPtr->EditWndProc, hwnd, uMsg, wParam, lParam);
1908 SendMessageW(infoPtr->hWndYearUpDown, WM_CLOSE, 0, 0);
1909 SendMessageW(hwnd, WM_CLOSE, 0, 0);
1913 /* creates updown control and edit box */
1914 static void MONTHCAL_EditYear(MONTHCAL_INFO *infoPtr, INT calIdx)
1916 RECT *rc = &infoPtr->calendars[calIdx].titleyear;
1917 RECT *title = &infoPtr->calendars[calIdx].title;
1919 infoPtr->hWndYearEdit =
1920 CreateWindowExW(0, WC_EDITW, 0, WS_VISIBLE | WS_CHILD | ES_READONLY,
1921 rc->left + 3, (title->bottom + title->top - infoPtr->textHeight) / 2,
1922 rc->right - rc->left + 4,
1923 infoPtr->textHeight, infoPtr->hwndSelf,
1926 SendMessageW(infoPtr->hWndYearEdit, WM_SETFONT, (WPARAM)infoPtr->hBoldFont, TRUE);
1928 infoPtr->hWndYearUpDown =
1929 CreateWindowExW(0, UPDOWN_CLASSW, 0,
1930 WS_VISIBLE | WS_CHILD | UDS_SETBUDDYINT | UDS_NOTHOUSANDS | UDS_ARROWKEYS,
1931 rc->right + 7, (title->bottom + title->top - infoPtr->textHeight) / 2,
1932 18, infoPtr->textHeight, infoPtr->hwndSelf,
1935 /* attach edit box */
1936 SendMessageW(infoPtr->hWndYearUpDown, UDM_SETRANGE, 0,
1937 MAKELONG(max_allowed_date.wYear, min_allowed_date.wYear));
1938 SendMessageW(infoPtr->hWndYearUpDown, UDM_SETBUDDY, (WPARAM)infoPtr->hWndYearEdit, 0);
1939 SendMessageW(infoPtr->hWndYearUpDown, UDM_SETPOS, 0, infoPtr->calendars[calIdx].month.wYear);
1941 /* subclass edit box */
1942 infoPtr->EditWndProc = (WNDPROC)SetWindowLongPtrW(infoPtr->hWndYearEdit,
1943 GWLP_WNDPROC, (DWORD_PTR)EditWndProc);
1945 SetFocus(infoPtr->hWndYearEdit);
1949 MONTHCAL_LButtonDown(MONTHCAL_INFO *infoPtr, LPARAM lParam)
1954 /* Actually we don't need input focus for calendar, this is used to kill
1955 year updown and its buddy edit box */
1956 if (IsWindow(infoPtr->hWndYearUpDown))
1958 SetFocus(infoPtr->hwndSelf);
1962 SetCapture(infoPtr->hwndSelf);
1964 ht.cbSize = sizeof(MCHITTESTINFO);
1965 ht.pt.x = (short)LOWORD(lParam);
1966 ht.pt.y = (short)HIWORD(lParam);
1968 hit = MONTHCAL_HitTest(infoPtr, &ht);
1970 TRACE("%x at (%d, %d)\n", hit, ht.pt.x, ht.pt.y);
1974 case MCHT_TITLEBTNNEXT:
1975 MONTHCAL_GoToMonth(infoPtr, DIRECTION_FORWARD);
1976 infoPtr->status = MC_NEXTPRESSED;
1977 SetTimer(infoPtr->hwndSelf, MC_PREVNEXTMONTHTIMER, MC_PREVNEXTMONTHDELAY, 0);
1978 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1981 case MCHT_TITLEBTNPREV:
1982 MONTHCAL_GoToMonth(infoPtr, DIRECTION_BACKWARD);
1983 infoPtr->status = MC_PREVPRESSED;
1984 SetTimer(infoPtr->hwndSelf, MC_PREVNEXTMONTHTIMER, MC_PREVNEXTMONTHDELAY, 0);
1985 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1988 case MCHT_TITLEMONTH:
1990 HMENU hMenu = CreatePopupMenu();
1995 for (i = 0; i < 12; i++)
1997 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SMONTHNAME1+i, buf, countof(buf));
1998 AppendMenuW(hMenu, MF_STRING|MF_ENABLED, i + 1, buf);
2000 menupoint.x = ht.pt.x;
2001 menupoint.y = ht.pt.y;
2002 ClientToScreen(infoPtr->hwndSelf, &menupoint);
2003 i = TrackPopupMenu(hMenu,TPM_LEFTALIGN | TPM_NONOTIFY | TPM_RIGHTBUTTON | TPM_RETURNCMD,
2004 menupoint.x, menupoint.y, 0, infoPtr->hwndSelf, NULL);
2006 if ((i > 0) && (i < 13) && infoPtr->calendars[ht.iOffset].month.wMonth != i)
2008 INT delta = i - infoPtr->calendars[ht.iOffset].month.wMonth;
2011 /* check if change allowed by range set */
2012 st = delta < 0 ? infoPtr->calendars[0].month :
2013 infoPtr->calendars[infoPtr->cal_num-1].month;
2014 MONTHCAL_GetMonth(&st, delta);
2016 if (MONTHCAL_IsDateInValidRange(infoPtr, &st, FALSE))
2018 MONTHCAL_Scroll(infoPtr, delta);
2019 MONTHCAL_NotifyDayState(infoPtr);
2020 MONTHCAL_NotifySelectionChange(infoPtr);
2021 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
2026 case MCHT_TITLEYEAR:
2028 MONTHCAL_EditYear(infoPtr, ht.iOffset);
2031 case MCHT_TODAYLINK:
2033 infoPtr->calendars[0].month = infoPtr->todaysDate;
2034 infoPtr->minSel = infoPtr->todaysDate;
2035 infoPtr->maxSel = infoPtr->todaysDate;
2036 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
2038 MONTHCAL_NotifySelectionChange(infoPtr);
2039 MONTHCAL_NotifySelect(infoPtr);
2042 case MCHT_CALENDARDATENEXT:
2043 case MCHT_CALENDARDATEPREV:
2044 case MCHT_CALENDARDATE:
2048 MONTHCAL_CopyDate(&ht.st, &infoPtr->firstSel);
2050 st[0] = st[1] = ht.st;
2051 /* clear selection range */
2052 MONTHCAL_SetSelRange(infoPtr, st);
2054 infoPtr->status = MC_SEL_LBUTDOWN;
2055 MONTHCAL_SetDayFocus(infoPtr, &ht.st);
2065 MONTHCAL_LButtonUp(MONTHCAL_INFO *infoPtr, LPARAM lParam)
2073 if(infoPtr->status & (MC_PREVPRESSED | MC_NEXTPRESSED)) {
2076 KillTimer(infoPtr->hwndSelf, MC_PREVNEXTMONTHTIMER);
2077 r = infoPtr->status & MC_PREVPRESSED ? &infoPtr->titlebtnprev : &infoPtr->titlebtnnext;
2078 infoPtr->status &= ~(MC_PREVPRESSED | MC_NEXTPRESSED);
2080 InvalidateRect(infoPtr->hwndSelf, r, FALSE);
2085 /* always send NM_RELEASEDCAPTURE notification */
2086 nmhdr.hwndFrom = infoPtr->hwndSelf;
2087 nmhdr.idFrom = GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_ID);
2088 nmhdr.code = NM_RELEASEDCAPTURE;
2089 TRACE("Sent notification from %p to %p\n", infoPtr->hwndSelf, infoPtr->hwndNotify);
2091 SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, nmhdr.idFrom, (LPARAM)&nmhdr);
2093 if(!(infoPtr->status & MC_SEL_LBUTDOWN)) return 0;
2095 ht.cbSize = sizeof(MCHITTESTINFO);
2096 ht.pt.x = (short)LOWORD(lParam);
2097 ht.pt.y = (short)HIWORD(lParam);
2098 hit = MONTHCAL_HitTest(infoPtr, &ht);
2100 infoPtr->status = MC_SEL_LBUTUP;
2101 MONTHCAL_SetDayFocus(infoPtr, NULL);
2103 if((hit & MCHT_CALENDARDATE) == MCHT_CALENDARDATE)
2105 SYSTEMTIME sel = infoPtr->minSel;
2107 /* will be invalidated here */
2108 MONTHCAL_SetCurSel(infoPtr, &ht.st);
2110 /* send MCN_SELCHANGE only if new date selected */
2111 if (!MONTHCAL_IsDateEqual(&sel, &ht.st))
2112 MONTHCAL_NotifySelectionChange(infoPtr);
2114 MONTHCAL_NotifySelect(infoPtr);
2122 MONTHCAL_Timer(MONTHCAL_INFO *infoPtr, WPARAM id)
2127 case MC_PREVNEXTMONTHTIMER:
2128 if(infoPtr->status & MC_NEXTPRESSED) MONTHCAL_GoToMonth(infoPtr, DIRECTION_FORWARD);
2129 if(infoPtr->status & MC_PREVPRESSED) MONTHCAL_GoToMonth(infoPtr, DIRECTION_BACKWARD);
2130 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
2132 case MC_TODAYUPDATETIMER:
2136 if(infoPtr->todaySet) return 0;
2139 MONTHCAL_UpdateToday(infoPtr, &st);
2141 /* notification sent anyway */
2142 MONTHCAL_NotifySelectionChange(infoPtr);
2147 ERR("got unknown timer %ld\n", id);
2156 MONTHCAL_MouseMove(MONTHCAL_INFO *infoPtr, LPARAM lParam)
2163 if(!(infoPtr->status & MC_SEL_LBUTDOWN)) return 0;
2165 ht.cbSize = sizeof(MCHITTESTINFO);
2166 ht.pt.x = (short)LOWORD(lParam);
2167 ht.pt.y = (short)HIWORD(lParam);
2169 hit = MONTHCAL_HitTest(infoPtr, &ht);
2171 /* not on the calendar date numbers? bail out */
2172 TRACE("hit:%x\n",hit);
2173 if((hit & MCHT_CALENDARDATE) != MCHT_CALENDARDATE)
2175 MONTHCAL_SetDayFocus(infoPtr, NULL);
2181 /* if pointer is over focused day still there's nothing to do */
2182 if(!MONTHCAL_SetDayFocus(infoPtr, &ht.st)) return 0;
2184 MONTHCAL_CalcPosFromDay(infoPtr, &ht.st, &r);
2186 if(infoPtr->dwStyle & MCS_MULTISELECT) {
2189 MONTHCAL_GetSelRange(infoPtr, st);
2191 /* If we're still at the first selected date and range is empty, return.
2192 If range isn't empty we should change range to a single firstSel */
2193 if(MONTHCAL_IsDateEqual(&infoPtr->firstSel, &st_ht) &&
2194 MONTHCAL_IsDateEqual(&st[0], &st[1])) goto done;
2196 MONTHCAL_IsSelRangeValid(infoPtr, &st_ht, &infoPtr->firstSel, &st_ht);
2198 st[0] = infoPtr->firstSel;
2199 /* we should overwrite timestamp here */
2200 MONTHCAL_CopyDate(&st_ht, &st[1]);
2202 /* bounds will be swapped here if needed */
2203 MONTHCAL_SetSelRange(infoPtr, st);
2210 /* FIXME: this should specify a rectangle containing only the days that changed
2211 using InvalidateRect */
2212 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
2219 MONTHCAL_Paint(MONTHCAL_INFO *infoPtr, HDC hdc_paint)
2226 GetClientRect(infoPtr->hwndSelf, &ps.rcPaint);
2230 hdc = BeginPaint(infoPtr->hwndSelf, &ps);
2232 MONTHCAL_Refresh(infoPtr, hdc, &ps);
2233 if (!hdc_paint) EndPaint(infoPtr->hwndSelf, &ps);
2238 MONTHCAL_EraseBkgnd(const MONTHCAL_INFO *infoPtr, HDC hdc)
2243 if (!GetClipBox(hdc, &rc)) return FALSE;
2245 /* fill background */
2246 hbr = CreateSolidBrush (infoPtr->colors[MCSC_BACKGROUND]);
2247 FillRect(hdc, &rc, hbr);
2254 MONTHCAL_PrintClient(MONTHCAL_INFO *infoPtr, HDC hdc, DWORD options)
2256 FIXME("Partial Stub: (hdc=%p options=0x%08x)\n", hdc, options);
2258 if ((options & PRF_CHECKVISIBLE) && !IsWindowVisible(infoPtr->hwndSelf))
2261 if (options & PRF_ERASEBKGND)
2262 MONTHCAL_EraseBkgnd(infoPtr, hdc);
2264 if (options & PRF_CLIENT)
2265 MONTHCAL_Paint(infoPtr, hdc);
2271 MONTHCAL_SetFocus(const MONTHCAL_INFO *infoPtr)
2275 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
2280 /* sets the size information */
2281 static void MONTHCAL_UpdateSize(MONTHCAL_INFO *infoPtr)
2283 static const WCHAR O0W[] = { '0','0',0 };
2284 HDC hdc = GetDC(infoPtr->hwndSelf);
2285 RECT *title=&infoPtr->calendars[0].title;
2286 RECT *prev=&infoPtr->titlebtnprev;
2287 RECT *next=&infoPtr->titlebtnnext;
2288 RECT *titlemonth=&infoPtr->calendars[0].titlemonth;
2289 RECT *titleyear=&infoPtr->calendars[0].titleyear;
2290 RECT *wdays=&infoPtr->calendars[0].wdays;
2291 RECT *weeknumrect=&infoPtr->calendars[0].weeknums;
2292 RECT *days=&infoPtr->calendars[0].days;
2293 RECT *todayrect=&infoPtr->todayrect;
2297 INT xdiv, dx, dy, i;
2301 GetClientRect(infoPtr->hwndSelf, &rcClient);
2303 currentFont = SelectObject(hdc, infoPtr->hFont);
2305 /* get the height and width of each day's text */
2306 GetTextMetricsW(hdc, &tm);
2307 infoPtr->textHeight = tm.tmHeight + tm.tmExternalLeading + tm.tmInternalLeading;
2309 /* find largest abbreviated day name for current locale */
2310 size.cx = sz.cx = 0;
2311 for (i = 0; i < 7; i++)
2313 if(GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SABBREVDAYNAME1 + i,
2314 buff, countof(buff)))
2316 GetTextExtentPoint32W(hdc, buff, lstrlenW(buff), &sz);
2317 if (sz.cx > size.cx) size.cx = sz.cx;
2319 else /* locale independent fallback on failure */
2321 static const WCHAR SunW[] = { 'S','u','n',0 };
2323 GetTextExtentPoint32W(hdc, SunW, lstrlenW(SunW), &size);
2328 infoPtr->textWidth = size.cx + 2;
2330 /* recalculate the height and width increments and offsets */
2331 GetTextExtentPoint32W(hdc, O0W, 2, &size);
2333 xdiv = (infoPtr->dwStyle & MCS_WEEKNUMBERS) ? 8 : 7;
2335 infoPtr->width_increment = size.cx * 2 + 4;
2336 infoPtr->height_increment = infoPtr->textHeight;
2338 /* calculate title area */
2340 title->bottom = 3 * infoPtr->height_increment / 2;
2342 title->right = infoPtr->width_increment * xdiv;
2344 /* set the dimensions of the next and previous buttons and center */
2345 /* the month text vertically */
2346 prev->top = next->top = title->top + 4;
2347 prev->bottom = next->bottom = title->bottom - 4;
2348 prev->left = title->left + 4;
2349 prev->right = prev->left + (title->bottom - title->top);
2350 next->right = title->right - 4;
2351 next->left = next->right - (title->bottom - title->top);
2353 /* titlemonth->left and right change based upon the current month */
2354 /* and are recalculated in refresh as the current month may change */
2355 /* without the control being resized */
2356 titlemonth->top = titleyear->top = title->top + (infoPtr->height_increment)/2;
2357 titlemonth->bottom = titleyear->bottom = title->bottom - (infoPtr->height_increment)/2;
2359 /* setup the dimensions of the rectangle we draw the names of the */
2360 /* days of the week in */
2361 weeknumrect->left = 0;
2363 if(infoPtr->dwStyle & MCS_WEEKNUMBERS)
2364 weeknumrect->right = prev->right;
2366 weeknumrect->right = weeknumrect->left;
2368 wdays->left = days->left = weeknumrect->right;
2369 wdays->right = days->right = wdays->left + 7 * infoPtr->width_increment;
2370 wdays->top = title->bottom;
2371 wdays->bottom = wdays->top + infoPtr->height_increment;
2373 days->top = weeknumrect->top = wdays->bottom;
2374 days->bottom = weeknumrect->bottom = days->top + 6 * infoPtr->height_increment;
2376 todayrect->left = 0;
2377 todayrect->right = title->right;
2378 todayrect->top = days->bottom;
2379 todayrect->bottom = days->bottom + infoPtr->height_increment;
2381 /* offset all rectangles to center in client area */
2382 dx = (rcClient.right - title->right) / 2;
2383 dy = (rcClient.bottom - todayrect->bottom) / 2;
2385 /* if calendar doesn't fit client area show it at left/top bounds */
2386 if (title->left + dx < 0) dx = 0;
2387 if (title->top + dy < 0) dy = 0;
2389 if (dx != 0 || dy != 0)
2391 OffsetRect(title, dx, dy);
2392 OffsetRect(prev, dx, dy);
2393 OffsetRect(next, dx, dy);
2394 OffsetRect(titlemonth, dx, dy);
2395 OffsetRect(titleyear, dx, dy);
2396 OffsetRect(wdays, dx, dy);
2397 OffsetRect(weeknumrect, dx, dy);
2398 OffsetRect(days, dx, dy);
2399 OffsetRect(todayrect, dx, dy);
2402 TRACE("dx=%d dy=%d client[%s] title[%s] wdays[%s] days[%s] today[%s]\n",
2403 infoPtr->width_increment,infoPtr->height_increment,
2404 wine_dbgstr_rect(&rcClient),
2405 wine_dbgstr_rect(title),
2406 wine_dbgstr_rect(wdays),
2407 wine_dbgstr_rect(days),
2408 wine_dbgstr_rect(todayrect));
2410 /* restore the originally selected font */
2411 SelectObject(hdc, currentFont);
2413 ReleaseDC(infoPtr->hwndSelf, hdc);
2416 static LRESULT MONTHCAL_Size(MONTHCAL_INFO *infoPtr, int Width, int Height)
2418 TRACE("(width=%d, height=%d)\n", Width, Height);
2420 MONTHCAL_UpdateSize(infoPtr);
2421 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
2426 static LRESULT MONTHCAL_GetFont(const MONTHCAL_INFO *infoPtr)
2428 return (LRESULT)infoPtr->hFont;
2431 static LRESULT MONTHCAL_SetFont(MONTHCAL_INFO *infoPtr, HFONT hFont, BOOL redraw)
2436 if (!hFont) return 0;
2438 hOldFont = infoPtr->hFont;
2439 infoPtr->hFont = hFont;
2441 GetObjectW(infoPtr->hFont, sizeof(lf), &lf);
2442 lf.lfWeight = FW_BOLD;
2443 infoPtr->hBoldFont = CreateFontIndirectW(&lf);
2445 MONTHCAL_UpdateSize(infoPtr);
2448 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
2450 return (LRESULT)hOldFont;
2453 /* update theme after a WM_THEMECHANGED message */
2454 static LRESULT theme_changed (const MONTHCAL_INFO* infoPtr)
2456 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
2457 CloseThemeData (theme);
2458 OpenThemeData (infoPtr->hwndSelf, themeClass);
2462 static INT MONTHCAL_StyleChanged(MONTHCAL_INFO *infoPtr, WPARAM wStyleType,
2463 const STYLESTRUCT *lpss)
2465 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
2466 wStyleType, lpss->styleOld, lpss->styleNew);
2468 if (wStyleType != GWL_STYLE) return 0;
2470 infoPtr->dwStyle = lpss->styleNew;
2472 /* make room for week numbers */
2473 if ((lpss->styleNew ^ lpss->styleOld) & MCS_WEEKNUMBERS)
2474 MONTHCAL_UpdateSize(infoPtr);
2479 static INT MONTHCAL_StyleChanging(MONTHCAL_INFO *infoPtr, WPARAM wStyleType,
2482 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
2483 wStyleType, lpss->styleOld, lpss->styleNew);
2485 /* block MCS_MULTISELECT change */
2486 if ((lpss->styleNew ^ lpss->styleOld) & MCS_MULTISELECT)
2488 if (lpss->styleOld & MCS_MULTISELECT)
2489 lpss->styleNew |= MCS_MULTISELECT;
2491 lpss->styleNew &= ~MCS_MULTISELECT;
2497 /* FIXME: check whether dateMin/dateMax need to be adjusted. */
2499 MONTHCAL_Create(HWND hwnd, LPCREATESTRUCTW lpcs)
2501 MONTHCAL_INFO *infoPtr;
2503 /* allocate memory for info structure */
2504 infoPtr = Alloc(sizeof(MONTHCAL_INFO));
2505 SetWindowLongPtrW(hwnd, 0, (DWORD_PTR)infoPtr);
2507 if (infoPtr == NULL) {
2508 ERR("could not allocate info memory!\n");
2512 infoPtr->hwndSelf = hwnd;
2513 infoPtr->hwndNotify = lpcs->hwndParent;
2514 infoPtr->dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
2515 infoPtr->calendars = Alloc(sizeof(CALENDAR_INFO));
2516 if (!infoPtr->calendars) goto fail;
2518 infoPtr->cal_num = 1;
2520 MONTHCAL_SetFont(infoPtr, GetStockObject(DEFAULT_GUI_FONT), FALSE);
2522 /* initialize info structure */
2523 /* FIXME: calculate systemtime ->> localtime(substract timezoneinfo) */
2525 GetLocalTime(&infoPtr->todaysDate);
2526 MONTHCAL_SetFirstDayOfWeek(infoPtr, -1);
2528 infoPtr->maxSelCount = (infoPtr->dwStyle & MCS_MULTISELECT) ? 7 : 1;
2529 infoPtr->monthRange = 3;
2531 infoPtr->monthdayState = Alloc(infoPtr->monthRange * sizeof(MONTHDAYSTATE));
2532 if (!infoPtr->monthdayState) goto fail;
2534 infoPtr->colors[MCSC_BACKGROUND] = comctl32_color.clrWindow;
2535 infoPtr->colors[MCSC_TEXT] = comctl32_color.clrWindowText;
2536 infoPtr->colors[MCSC_TITLEBK] = comctl32_color.clrActiveCaption;
2537 infoPtr->colors[MCSC_TITLETEXT] = comctl32_color.clrWindow;
2538 infoPtr->colors[MCSC_MONTHBK] = comctl32_color.clrWindow;
2539 infoPtr->colors[MCSC_TRAILINGTEXT] = comctl32_color.clrGrayText;
2541 infoPtr->minSel = infoPtr->todaysDate;
2542 infoPtr->maxSel = infoPtr->todaysDate;
2543 infoPtr->calendars[0].month = infoPtr->todaysDate;
2544 infoPtr->isUnicode = TRUE;
2546 /* call MONTHCAL_UpdateSize to set all of the dimensions */
2547 /* of the control */
2548 MONTHCAL_UpdateSize(infoPtr);
2550 /* today auto update timer, to be freed only on control destruction */
2551 SetTimer(infoPtr->hwndSelf, MC_TODAYUPDATETIMER, MC_TODAYUPDATEDELAY, 0);
2553 OpenThemeData (infoPtr->hwndSelf, themeClass);
2558 Free(infoPtr->monthdayState);
2559 Free(infoPtr->calendars);
2565 MONTHCAL_Destroy(MONTHCAL_INFO *infoPtr)
2567 /* free month calendar info data */
2568 Free(infoPtr->monthdayState);
2569 Free(infoPtr->calendars);
2570 SetWindowLongPtrW(infoPtr->hwndSelf, 0, 0);
2572 CloseThemeData (GetWindowTheme (infoPtr->hwndSelf));
2579 * Handler for WM_NOTIFY messages
2582 MONTHCAL_Notify(MONTHCAL_INFO *infoPtr, NMHDR *hdr)
2584 /* notification from year edit updown */
2585 if (hdr->code == UDN_DELTAPOS)
2587 NMUPDOWN *nmud = (NMUPDOWN*)hdr;
2589 if (hdr->hwndFrom == infoPtr->hWndYearUpDown && nmud->iDelta)
2591 /* year value limits are set up explicitly after updown creation */
2592 MONTHCAL_Scroll(infoPtr, 12 * nmud->iDelta);
2593 MONTHCAL_NotifyDayState(infoPtr);
2594 MONTHCAL_NotifySelectionChange(infoPtr);
2601 MONTHCAL_SetUnicodeFormat(MONTHCAL_INFO *infoPtr, BOOL isUnicode)
2603 BOOL prev = infoPtr->isUnicode;
2604 infoPtr->isUnicode = isUnicode;
2609 MONTHCAL_GetUnicodeFormat(const MONTHCAL_INFO *infoPtr)
2611 return infoPtr->isUnicode;
2614 static LRESULT WINAPI
2615 MONTHCAL_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2617 MONTHCAL_INFO *infoPtr = (MONTHCAL_INFO *)GetWindowLongPtrW(hwnd, 0);
2619 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n", hwnd, uMsg, wParam, lParam);
2621 if (!infoPtr && (uMsg != WM_CREATE))
2622 return DefWindowProcW(hwnd, uMsg, wParam, lParam);
2626 return MONTHCAL_GetCurSel(infoPtr, (LPSYSTEMTIME)lParam);
2629 return MONTHCAL_SetCurSel(infoPtr, (LPSYSTEMTIME)lParam);
2631 case MCM_GETMAXSELCOUNT:
2632 return MONTHCAL_GetMaxSelCount(infoPtr);
2634 case MCM_SETMAXSELCOUNT:
2635 return MONTHCAL_SetMaxSelCount(infoPtr, wParam);
2637 case MCM_GETSELRANGE:
2638 return MONTHCAL_GetSelRange(infoPtr, (LPSYSTEMTIME)lParam);
2640 case MCM_SETSELRANGE:
2641 return MONTHCAL_SetSelRange(infoPtr, (LPSYSTEMTIME)lParam);
2643 case MCM_GETMONTHRANGE:
2644 return MONTHCAL_GetMonthRange(infoPtr, wParam, (SYSTEMTIME*)lParam);
2646 case MCM_SETDAYSTATE:
2647 return MONTHCAL_SetDayState(infoPtr, (INT)wParam, (LPMONTHDAYSTATE)lParam);
2649 case MCM_GETMINREQRECT:
2650 return MONTHCAL_GetMinReqRect(infoPtr, (LPRECT)lParam);
2653 return MONTHCAL_GetColor(infoPtr, wParam);
2656 return MONTHCAL_SetColor(infoPtr, wParam, (COLORREF)lParam);
2659 return MONTHCAL_GetToday(infoPtr, (LPSYSTEMTIME)lParam);
2662 return MONTHCAL_SetToday(infoPtr, (LPSYSTEMTIME)lParam);
2665 return MONTHCAL_HitTest(infoPtr, (PMCHITTESTINFO)lParam);
2667 case MCM_GETFIRSTDAYOFWEEK:
2668 return MONTHCAL_GetFirstDayOfWeek(infoPtr);
2670 case MCM_SETFIRSTDAYOFWEEK:
2671 return MONTHCAL_SetFirstDayOfWeek(infoPtr, (INT)lParam);
2674 return MONTHCAL_GetRange(infoPtr, (LPSYSTEMTIME)lParam);
2677 return MONTHCAL_SetRange(infoPtr, (SHORT)wParam, (LPSYSTEMTIME)lParam);
2679 case MCM_GETMONTHDELTA:
2680 return MONTHCAL_GetMonthDelta(infoPtr);
2682 case MCM_SETMONTHDELTA:
2683 return MONTHCAL_SetMonthDelta(infoPtr, wParam);
2685 case MCM_GETMAXTODAYWIDTH:
2686 return MONTHCAL_GetMaxTodayWidth(infoPtr);
2688 case MCM_SETUNICODEFORMAT:
2689 return MONTHCAL_SetUnicodeFormat(infoPtr, (BOOL)wParam);
2691 case MCM_GETUNICODEFORMAT:
2692 return MONTHCAL_GetUnicodeFormat(infoPtr);
2695 return DLGC_WANTARROWS | DLGC_WANTCHARS;
2698 return MONTHCAL_RButtonUp(infoPtr, lParam);
2700 case WM_LBUTTONDOWN:
2701 return MONTHCAL_LButtonDown(infoPtr, lParam);
2704 return MONTHCAL_MouseMove(infoPtr, lParam);
2707 return MONTHCAL_LButtonUp(infoPtr, lParam);
2710 return MONTHCAL_Paint(infoPtr, (HDC)wParam);
2712 case WM_PRINTCLIENT:
2713 return MONTHCAL_PrintClient(infoPtr, (HDC)wParam, (DWORD)lParam);
2716 return MONTHCAL_EraseBkgnd(infoPtr, (HDC)wParam);
2719 return MONTHCAL_SetFocus(infoPtr);
2722 return MONTHCAL_Size(infoPtr, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
2725 return MONTHCAL_Notify(infoPtr, (NMHDR*)lParam);
2728 return MONTHCAL_Create(hwnd, (LPCREATESTRUCTW)lParam);
2731 return MONTHCAL_SetFont(infoPtr, (HFONT)wParam, (BOOL)lParam);
2734 return MONTHCAL_GetFont(infoPtr);
2737 return MONTHCAL_Timer(infoPtr, wParam);
2739 case WM_THEMECHANGED:
2740 return theme_changed (infoPtr);
2743 return MONTHCAL_Destroy(infoPtr);
2745 case WM_SYSCOLORCHANGE:
2746 COMCTL32_RefreshSysColors();
2749 case WM_STYLECHANGED:
2750 return MONTHCAL_StyleChanged(infoPtr, wParam, (LPSTYLESTRUCT)lParam);
2752 case WM_STYLECHANGING:
2753 return MONTHCAL_StyleChanging(infoPtr, wParam, (LPSTYLESTRUCT)lParam);
2756 if ((uMsg >= WM_USER) && (uMsg < WM_APP) && !COMCTL32_IsReflectedMessage(uMsg))
2757 ERR( "unknown msg %04x wp=%08lx lp=%08lx\n", uMsg, wParam, lParam);
2758 return DefWindowProcW(hwnd, uMsg, wParam, lParam);
2764 MONTHCAL_Register(void)
2768 ZeroMemory(&wndClass, sizeof(WNDCLASSW));
2769 wndClass.style = CS_GLOBALCLASS;
2770 wndClass.lpfnWndProc = MONTHCAL_WindowProc;
2771 wndClass.cbClsExtra = 0;
2772 wndClass.cbWndExtra = sizeof(MONTHCAL_INFO *);
2773 wndClass.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
2774 wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
2775 wndClass.lpszClassName = MONTHCAL_CLASSW;
2777 RegisterClassW(&wndClass);
2782 MONTHCAL_Unregister(void)
2784 UnregisterClassW(MONTHCAL_CLASSW, NULL);