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 */
102 COLORREF trailingtxt;
107 int height_increment;
109 INT delta; /* scroll rate; # of months that the */
110 /* control moves when user clicks a scroll button */
111 int visible; /* # of months visible */
112 int firstDay; /* Start month calendar with firstDay's day,
113 stored in SYSTEMTIME format */
114 BOOL firstDaySet; /* first week day differs from locale defined */
116 BOOL isUnicode; /* value set with MCM_SETUNICODE format */
119 MONTHDAYSTATE *monthdayState;
120 SYSTEMTIME todaysDate;
121 BOOL todaySet; /* Today was forced with MCM_SETTODAY */
122 int status; /* See MC_SEL flags */
123 SYSTEMTIME firstSel; /* first selected day */
125 SYSTEMTIME minSel; /* contains single selection when used without MCS_MULTISELECT */
127 SYSTEMTIME focusedSel; /* date currently focused with mouse movement */
132 RECT titlebtnnext; /* the `next month' button in the header */
133 RECT titlebtnprev; /* the `prev month' button in the header */
134 RECT todayrect; /* `today: xx/xx/xx' text rect */
135 HWND hwndNotify; /* Window to receive the notifications */
136 HWND hWndYearEdit; /* Window Handle of edit box to handle years */
137 HWND hWndYearUpDown;/* Window Handle of updown box to handle years */
138 WNDPROC EditWndProc; /* original Edit window procedure */
140 CALENDAR_INFO *calendars;
142 } MONTHCAL_INFO, *LPMONTHCAL_INFO;
144 static const WCHAR themeClass[] = { 'S','c','r','o','l','l','b','a','r',0 };
146 /* empty SYSTEMTIME const */
147 static const SYSTEMTIME st_null;
148 /* valid date limits */
149 static const SYSTEMTIME max_allowed_date = { .wYear = 9999, .wMonth = 12, .wDay = 31 };
150 static const SYSTEMTIME min_allowed_date = { .wYear = 1752, .wMonth = 9, .wDay = 14 };
152 /* Prev/Next buttons */
159 /* helper functions */
161 /* send a single MCN_SELCHANGE notification */
162 static inline void MONTHCAL_NotifySelectionChange(const MONTHCAL_INFO *infoPtr)
166 nmsc.nmhdr.hwndFrom = infoPtr->hwndSelf;
167 nmsc.nmhdr.idFrom = GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_ID);
168 nmsc.nmhdr.code = MCN_SELCHANGE;
169 nmsc.stSelStart = infoPtr->minSel;
170 nmsc.stSelEnd = infoPtr->maxSel;
171 SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, nmsc.nmhdr.idFrom, (LPARAM)&nmsc);
174 /* send a single MCN_SELECT notification */
175 static inline void MONTHCAL_NotifySelect(const MONTHCAL_INFO *infoPtr)
179 nmsc.nmhdr.hwndFrom = infoPtr->hwndSelf;
180 nmsc.nmhdr.idFrom = GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_ID);
181 nmsc.nmhdr.code = MCN_SELECT;
182 nmsc.stSelStart = infoPtr->minSel;
183 nmsc.stSelEnd = infoPtr->maxSel;
185 SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, nmsc.nmhdr.idFrom, (LPARAM)&nmsc);
188 /* returns the number of days in any given month, checking for leap days */
189 /* january is 1, december is 12 */
190 int MONTHCAL_MonthLength(int month, int year)
192 const int mdays[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
193 /* Wrap around, this eases handling. Getting length only we shouldn't care
194 about year change here cause January and December have
195 the same day quantity */
201 /* special case for calendar transition year */
202 if(month == min_allowed_date.wMonth && year == min_allowed_date.wYear) return 19;
204 /* if we have a leap year add 1 day to February */
205 /* a leap year is a year either divisible by 400 */
206 /* or divisible by 4 and not by 100 */
207 if(month == 2) { /* February */
208 return mdays[month - 1] + ((year%400 == 0) ? 1 : ((year%100 != 0) &&
209 (year%4 == 0)) ? 1 : 0);
212 return mdays[month - 1];
216 /* compares timestamps using date part only */
217 static inline BOOL MONTHCAL_IsDateEqual(const SYSTEMTIME *first, const SYSTEMTIME *second)
219 return (first->wYear == second->wYear) && (first->wMonth == second->wMonth) &&
220 (first->wDay == second->wDay);
223 /* make sure that date fields are valid */
224 static BOOL MONTHCAL_ValidateDate(const SYSTEMTIME *time)
226 if(time->wMonth < 1 || time->wMonth > 12 ) return FALSE;
227 if(time->wDayOfWeek > 6) return FALSE;
228 if(time->wDay > MONTHCAL_MonthLength(time->wMonth, time->wYear))
234 /* Copies timestamp part only.
238 * [I] from : source date
241 static void MONTHCAL_CopyTime(const SYSTEMTIME *from, SYSTEMTIME *to)
243 to->wHour = from->wHour;
244 to->wMinute = from->wMinute;
245 to->wSecond = from->wSecond;
248 /* Copies date part only.
252 * [I] from : source date
255 static void MONTHCAL_CopyDate(const SYSTEMTIME *from, SYSTEMTIME *to)
257 to->wYear = from->wYear;
258 to->wMonth = from->wMonth;
259 to->wDay = from->wDay;
260 to->wDayOfWeek = from->wDayOfWeek;
263 /* Compares two dates in SYSTEMTIME format
267 * [I] first : pointer to valid first date data to compare
268 * [I] second : pointer to valid second date data to compare
272 * -1 : first < second
273 * 0 : first == second
276 * Note that no date validation performed, alreadt validated values expected.
278 static LONG MONTHCAL_CompareSystemTime(const SYSTEMTIME *first, const SYSTEMTIME *second)
280 FILETIME ft_first, ft_second;
282 SystemTimeToFileTime(first, &ft_first);
283 SystemTimeToFileTime(second, &ft_second);
285 return CompareFileTime(&ft_first, &ft_second);
288 static LONG MONTHCAL_CompareMonths(const SYSTEMTIME *first, const SYSTEMTIME *second)
290 SYSTEMTIME st_first, st_second;
292 st_first = st_second = st_null;
293 MONTHCAL_CopyDate(first, &st_first);
294 MONTHCAL_CopyDate(second, &st_second);
295 st_first.wDay = st_second.wDay = 1;
297 return MONTHCAL_CompareSystemTime(&st_first, &st_second);
300 static LONG MONTHCAL_CompareDate(const SYSTEMTIME *first, const SYSTEMTIME *second)
302 SYSTEMTIME st_first, st_second;
304 st_first = st_second = st_null;
305 MONTHCAL_CopyDate(first, &st_first);
306 MONTHCAL_CopyDate(second, &st_second);
308 return MONTHCAL_CompareSystemTime(&st_first, &st_second);
311 /* Checks largest possible date range and configured one
315 * [I] infoPtr : valid pointer to control data
316 * [I] date : pointer to valid date data to check
317 * [I] fix : make date fit valid range
321 * TRUE - date whithin largest and configured range
322 * FALSE - date is outside largest or configured range
324 static BOOL MONTHCAL_IsDateInValidRange(const MONTHCAL_INFO *infoPtr,
325 SYSTEMTIME *date, BOOL fix)
327 const SYSTEMTIME *fix_st = NULL;
329 if(MONTHCAL_CompareSystemTime(date, &max_allowed_date) == 1) {
330 fix_st = &max_allowed_date;
332 else if(MONTHCAL_CompareSystemTime(date, &min_allowed_date) == -1) {
333 fix_st = &min_allowed_date;
335 else if(infoPtr->rangeValid & GDTR_MAX) {
336 if((MONTHCAL_CompareSystemTime(date, &infoPtr->maxDate) == 1)) {
337 fix_st = &infoPtr->maxDate;
340 else if(infoPtr->rangeValid & GDTR_MIN) {
341 if((MONTHCAL_CompareSystemTime(date, &infoPtr->minDate) == -1)) {
342 fix_st = &infoPtr->minDate;
347 date->wYear = fix_st->wYear;
348 date->wMonth = fix_st->wMonth;
351 return fix_st ? FALSE : TRUE;
354 /* Checks passed range width with configured maximum selection count
358 * [I] infoPtr : valid pointer to control data
359 * [I] range0 : pointer to valid date data (requested bound)
360 * [I] range1 : pointer to valid date data (primary bound)
361 * [O] adjust : returns adjusted range bound to fit maximum range (optional)
363 * Adjust value computed basing on primary bound and current maximum selection
364 * count. For simple range check (without adjusted value required) (range0, range1)
365 * relation means nothing.
369 * TRUE - range is shorter or equal to maximum
370 * FALSE - range is larger than maximum
372 static BOOL MONTHCAL_IsSelRangeValid(const MONTHCAL_INFO *infoPtr,
373 const SYSTEMTIME *range0,
374 const SYSTEMTIME *range1,
377 ULARGE_INTEGER ul_range0, ul_range1, ul_diff;
378 FILETIME ft_range0, ft_range1;
381 SystemTimeToFileTime(range0, &ft_range0);
382 SystemTimeToFileTime(range1, &ft_range1);
384 ul_range0.u.LowPart = ft_range0.dwLowDateTime;
385 ul_range0.u.HighPart = ft_range0.dwHighDateTime;
386 ul_range1.u.LowPart = ft_range1.dwLowDateTime;
387 ul_range1.u.HighPart = ft_range1.dwHighDateTime;
389 cmp = CompareFileTime(&ft_range0, &ft_range1);
392 ul_diff.QuadPart = ul_range0.QuadPart - ul_range1.QuadPart;
394 ul_diff.QuadPart = -ul_range0.QuadPart + ul_range1.QuadPart;
396 if(ul_diff.QuadPart >= DAYSTO100NSECS(infoPtr->maxSelCount)) {
400 ul_range0.QuadPart = ul_range1.QuadPart + DAYSTO100NSECS(infoPtr->maxSelCount - 1);
402 ul_range0.QuadPart = ul_range1.QuadPart - DAYSTO100NSECS(infoPtr->maxSelCount - 1);
404 ft_range0.dwLowDateTime = ul_range0.u.LowPart;
405 ft_range0.dwHighDateTime = ul_range0.u.HighPart;
406 FileTimeToSystemTime(&ft_range0, adjust);
414 /* Used in MCM_SETRANGE/MCM_SETSELRANGE to determine resulting time part.
415 Milliseconds are intentionally not validated. */
416 static BOOL MONTHCAL_ValidateTime(const SYSTEMTIME *time)
418 if((time->wHour > 24) || (time->wMinute > 59) || (time->wSecond > 59))
424 /* Note:Depending on DST, this may be offset by a day.
425 Need to find out if we're on a DST place & adjust the clock accordingly.
426 Above function assumes we have a valid data.
427 Valid for year>1752; 1 <= d <= 31, 1 <= m <= 12.
431 /* Returns the day in the week
434 * [i] date : input date
435 * [I] inplace : set calculated value back to date structure
438 * day of week in SYSTEMTIME format: (0 == sunday,..., 6 == saturday)
440 int MONTHCAL_CalculateDayOfWeek(SYSTEMTIME *date, BOOL inplace)
442 SYSTEMTIME st = st_null;
445 MONTHCAL_CopyDate(date, &st);
447 SystemTimeToFileTime(&st, &ft);
448 FileTimeToSystemTime(&ft, &st);
450 if (inplace) date->wDayOfWeek = st.wDayOfWeek;
452 return st.wDayOfWeek;
455 /* add/substract 'months' from date */
456 static inline void MONTHCAL_GetMonth(SYSTEMTIME *date, INT months)
458 INT length, m = date->wMonth + months;
460 date->wYear += m > 0 ? (m - 1) / 12 : m / 12 - 1;
461 date->wMonth = m > 0 ? (m - 1) % 12 + 1 : 12 + m % 12;
462 /* fix moving from last day in a month */
463 length = MONTHCAL_MonthLength(date->wMonth, date->wYear);
464 if(date->wDay > length) date->wDay = length;
465 MONTHCAL_CalculateDayOfWeek(date, TRUE);
468 /* properly updates date to point on next month */
469 static inline void MONTHCAL_GetNextMonth(SYSTEMTIME *date)
471 return MONTHCAL_GetMonth(date, 1);
474 /* properly updates date to point on prev month */
475 static inline void MONTHCAL_GetPrevMonth(SYSTEMTIME *date)
477 return MONTHCAL_GetMonth(date, -1);
480 /* Returns full date for a first currently visible day */
481 static void MONTHCAL_GetMinDate(const MONTHCAL_INFO *infoPtr, SYSTEMTIME *date)
483 /* zero indexed calendar has the earliest date */
484 SYSTEMTIME st_first = infoPtr->calendars[0].month;
488 firstDay = MONTHCAL_CalculateDayOfWeek(&st_first, FALSE);
490 *date = infoPtr->calendars[0].month;
491 MONTHCAL_GetPrevMonth(date);
493 date->wDay = MONTHCAL_MonthLength(date->wMonth, date->wYear) +
494 (infoPtr->firstDay - firstDay) % 7 + 1;
496 if(date->wDay > MONTHCAL_MonthLength(date->wMonth, date->wYear))
499 /* fix day of week */
500 MONTHCAL_CalculateDayOfWeek(date, TRUE);
503 /* Returns full date for a last currently visible day */
504 static void MONTHCAL_GetMaxDate(const MONTHCAL_INFO *infoPtr, SYSTEMTIME *date)
506 /* the latest date is in latest calendar */
507 SYSTEMTIME st, lt_month = infoPtr->calendars[infoPtr->cal_num-1].month;
510 MONTHCAL_GetNextMonth(date);
512 MONTHCAL_GetMinDate(infoPtr, &st);
513 /* Use month length to get max day. 42 means max day count in calendar area */
514 date->wDay = 42 - (MONTHCAL_MonthLength(st.wMonth, st.wYear) - st.wDay + 1) -
515 MONTHCAL_MonthLength(lt_month.wMonth, lt_month.wYear);
517 /* fix day of week */
518 MONTHCAL_CalculateDayOfWeek(date, TRUE);
521 /* From a given point, calculate the row (weekpos), column(daypos)
522 and day in the calendar. day== 0 mean the last day of tha last month
524 static int MONTHCAL_CalcDayFromPos(const MONTHCAL_INFO *infoPtr, int x, int y,
525 int *daypos, int *weekpos)
527 int retval, firstDay;
529 SYSTEMTIME st = infoPtr->minSel;
531 GetClientRect(infoPtr->hwndSelf, &rcClient);
533 /* if the point is outside the x bounds of the window put
534 it at the boundary */
535 if (x > rcClient.right)
538 *daypos = (x - infoPtr->calendars[0].days.left ) / infoPtr->width_increment;
539 *weekpos = (y - infoPtr->calendars[0].days.top ) / infoPtr->height_increment;
542 firstDay = (MONTHCAL_CalculateDayOfWeek(&st, FALSE) + 6 - infoPtr->firstDay) % 7;
543 retval = *daypos + (7 * *weekpos) - firstDay;
547 /* Sets the RECT struct r to the rectangle around the date
551 * [I] infoPtr : pointer to control data
552 * [I] date : date value
553 * [O] x : day column (zero based)
554 * [O] y : week column (zero based)
556 static void MONTHCAL_CalcDayXY(const MONTHCAL_INFO *infoPtr,
557 const SYSTEMTIME *date, INT *x, INT *y)
559 SYSTEMTIME st = infoPtr->minSel;
564 first = (MONTHCAL_CalculateDayOfWeek(&st, FALSE) + 6 - infoPtr->firstDay) % 7;
566 cmp = MONTHCAL_CompareMonths(date, &infoPtr->minSel);
570 *x = (first - MONTHCAL_MonthLength(date->wMonth, infoPtr->minSel.wYear) + date->wDay) % 7;
575 /* next month calculation is same as for current,
576 just add current month length */
578 first += MONTHCAL_MonthLength(infoPtr->minSel.wMonth, infoPtr->minSel.wYear);
581 *x = (date->wDay + first) % 7;
582 *y = (date->wDay + first - *x) / 7;
586 /* x: column(day), y: row(week) */
587 static inline void MONTHCAL_CalcDayRect(const MONTHCAL_INFO *infoPtr, RECT *r, int x, int y)
589 r->left = infoPtr->calendars[0].days.left + x * infoPtr->width_increment;
590 r->right = r->left + infoPtr->width_increment;
591 r->top = infoPtr->calendars[0].days.top + y * infoPtr->height_increment;
592 r->bottom = r->top + infoPtr->textHeight;
596 /* Sets the RECT struct r to the rectangle around the date */
597 static inline void MONTHCAL_CalcPosFromDay(const MONTHCAL_INFO *infoPtr,
598 const SYSTEMTIME *date, RECT *r)
602 MONTHCAL_CalcDayXY(infoPtr, date, &x, &y);
603 MONTHCAL_CalcDayRect(infoPtr, r, x, y);
606 /* Focused day helper:
608 - set focused date to given value;
609 - reset to zero value if NULL passed;
610 - invalidate previous and new day rectangle only if needed.
612 Returns TRUE if focused day changed, FALSE otherwise.
614 static BOOL MONTHCAL_SetDayFocus(MONTHCAL_INFO *infoPtr, const SYSTEMTIME *st)
620 /* there's nothing to do if it's the same date,
621 mouse move within same date rectangle case */
622 if(MONTHCAL_IsDateEqual(&infoPtr->focusedSel, st)) return FALSE;
624 /* invalidate old focused day */
625 MONTHCAL_CalcPosFromDay(infoPtr, &infoPtr->focusedSel, &r);
626 InvalidateRect(infoPtr->hwndSelf, &r, FALSE);
628 infoPtr->focusedSel = *st;
631 MONTHCAL_CalcPosFromDay(infoPtr, &infoPtr->focusedSel, &r);
633 if(!st && MONTHCAL_ValidateDate(&infoPtr->focusedSel))
634 infoPtr->focusedSel = st_null;
636 /* on set invalidates new day, on reset clears previous focused day */
637 InvalidateRect(infoPtr->hwndSelf, &r, FALSE);
642 /* Draw today day mark rectangle
644 * [I] hdc : context to draw in
645 * [I] day : day to mark with rectangle
648 static void MONTHCAL_CircleDay(const MONTHCAL_INFO *infoPtr, HDC hdc,
649 const SYSTEMTIME *date)
651 HPEN hRedPen = CreatePen(PS_SOLID, 1, RGB(255, 0, 0));
652 HPEN hOldPen2 = SelectObject(hdc, hRedPen);
656 MONTHCAL_CalcPosFromDay(infoPtr, date, &day_rect);
658 hOldBrush = SelectObject(hdc, GetStockObject(NULL_BRUSH));
659 Rectangle(hdc, day_rect.left, day_rect.top, day_rect.right, day_rect.bottom);
661 SelectObject(hdc, hOldBrush);
662 DeleteObject(hRedPen);
663 SelectObject(hdc, hOldPen2);
666 static void MONTHCAL_DrawDay(const MONTHCAL_INFO *infoPtr, HDC hdc, const SYSTEMTIME *st,
667 int bold, const PAINTSTRUCT *ps)
669 static const WCHAR fmtW[] = { '%','d',0 };
672 static BOOL bold_selected;
673 BOOL selected_day = FALSE;
678 /* No need to check styles: when selection is not valid, it is set to zero.
679 * 1<day<31, so everything is OK.
682 MONTHCAL_CalcPosFromDay(infoPtr, st, &r);
683 if(!IntersectRect(&r_temp, &(ps->rcPaint), &r)) return;
685 if ((MONTHCAL_CompareDate(st, &infoPtr->minSel) >= 0) &&
686 (MONTHCAL_CompareDate(st, &infoPtr->maxSel) <= 0)) {
688 TRACE("%d %d %d\n", st->wDay, infoPtr->minSel.wDay, infoPtr->maxSel.wDay);
689 TRACE("%s\n", wine_dbgstr_rect(&r));
690 oldCol = SetTextColor(hdc, infoPtr->monthbk);
691 oldBk = SetBkColor(hdc, infoPtr->trailingtxt);
692 hbr = GetSysColorBrush(COLOR_HIGHLIGHT);
693 FillRect(hdc, &r, hbr);
698 if(bold && !bold_selected) {
699 SelectObject(hdc, infoPtr->hBoldFont);
700 bold_selected = TRUE;
702 if(!bold && bold_selected) {
703 SelectObject(hdc, infoPtr->hFont);
704 bold_selected = FALSE;
707 SetBkMode(hdc,TRANSPARENT);
708 wsprintfW(buf, fmtW, st->wDay);
709 DrawTextW(hdc, buf, -1, &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE );
712 SetTextColor(hdc, oldCol);
713 SetBkColor(hdc, oldBk);
718 static void MONTHCAL_PaintButton(MONTHCAL_INFO *infoPtr, HDC hdc, BOOL btnNext)
720 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
721 RECT *r = btnNext ? &infoPtr->titlebtnnext : &infoPtr->titlebtnprev;
722 BOOL pressed = btnNext ? (infoPtr->status & MC_NEXTPRESSED) :
723 (infoPtr->status & MC_PREVPRESSED);
726 static const int states[] = {
728 ABS_LEFTNORMAL, ABS_LEFTPRESSED, ABS_LEFTDISABLED,
730 ABS_RIGHTNORMAL, ABS_RIGHTPRESSED, ABS_RIGHTDISABLED
732 int stateNum = btnNext ? 3 : 0;
737 if (infoPtr->dwStyle & WS_DISABLED) stateNum += 2;
739 DrawThemeBackground (theme, hdc, SBP_ARROWBTN, states[stateNum], r, NULL);
743 int style = btnNext ? DFCS_SCROLLRIGHT : DFCS_SCROLLLEFT;
745 style |= DFCS_PUSHED;
748 if (infoPtr->dwStyle & WS_DISABLED) style |= DFCS_INACTIVE;
751 DrawFrameControl(hdc, r, DFC_SCROLL, style);
754 /* paint a title with buttons and month/year string */
755 static void MONTHCAL_PaintTitle(MONTHCAL_INFO *infoPtr, HDC hdc, const PAINTSTRUCT *ps, INT calIdx)
757 static const WCHAR fmt_monthW[] = { '%','s',' ','%','l','d',0 };
758 RECT *title = &infoPtr->calendars[calIdx].title;
759 const SYSTEMTIME *st = &infoPtr->calendars[calIdx].month;
760 WCHAR buf_month[80], buf_fmt[80];
764 /* fill header box */
765 hbr = CreateSolidBrush(infoPtr->titlebk);
766 FillRect(hdc, title, hbr);
769 /* month/year string */
770 SetBkColor(hdc, infoPtr->titlebk);
771 SetTextColor(hdc, infoPtr->titletxt);
772 SelectObject(hdc, infoPtr->hBoldFont);
774 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SMONTHNAME1 + st->wMonth - 1,
775 buf_month, countof(buf_month));
777 wsprintfW(buf_fmt, fmt_monthW, buf_month, st->wYear);
778 DrawTextW(hdc, buf_fmt, strlenW(buf_fmt), title,
779 DT_CENTER | DT_VCENTER | DT_SINGLELINE);
781 /* update title rectangles with current month - used while testing hits */
782 GetTextExtentPoint32W(hdc, buf_fmt, strlenW(buf_fmt), &sz);
783 infoPtr->calendars[calIdx].titlemonth.left = title->right / 2 + title->left / 2 - sz.cx / 2;
784 infoPtr->calendars[calIdx].titleyear.right = title->right / 2 + title->left / 2 + sz.cx / 2;
786 GetTextExtentPoint32W(hdc, buf_month, strlenW(buf_month), &sz);
787 infoPtr->calendars[calIdx].titlemonth.right = infoPtr->calendars[calIdx].titlemonth.left + sz.cx;
788 infoPtr->calendars[calIdx].titleyear.left = infoPtr->calendars[calIdx].titlemonth.right;
791 static void MONTHCAL_PaintWeeknumbers(const MONTHCAL_INFO *infoPtr, HDC hdc, const PAINTSTRUCT *ps, INT calIdx)
793 const SYSTEMTIME *date = &infoPtr->calendars[calIdx].month;
794 static const WCHAR fmt_weekW[] = { '%','d',0 };
795 INT mindays, weeknum, weeknum1, startofprescal;
802 if (!(infoPtr->dwStyle & MCS_WEEKNUMBERS)) return;
804 MONTHCAL_GetMinDate(infoPtr, &st);
805 startofprescal = st.wDay;
808 prev_month = date->wMonth - 1;
809 if(prev_month == 0) prev_month = 12;
812 Rules what week to call the first week of a new year:
813 LOCALE_IFIRSTWEEKOFYEAR == 0 (e.g US?):
814 The week containing Jan 1 is the first week of year
815 LOCALE_IFIRSTWEEKOFYEAR == 2 (e.g. Germany):
816 First week of year must contain 4 days of the new year
817 LOCALE_IFIRSTWEEKOFYEAR == 1 (what contries?)
818 The first week of the year must contain only days of the new year
820 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_IFIRSTWEEKOFYEAR, buf, countof(buf));
821 weeknum = atoiW(buf);
831 WARN("Unknown LOCALE_IFIRSTWEEKOFYEAR value %d, defaulting to 0\n", weeknum);
835 if (date->wMonth == 1)
837 /* calculate all those exceptions for january */
838 st.wDay = st.wMonth = 1;
839 weeknum1 = MONTHCAL_CalculateDayOfWeek(&st, FALSE);
840 if ((infoPtr->firstDay - weeknum1) % 7 > mindays)
845 for(i = 0; i < 11; i++)
846 weeknum += MONTHCAL_MonthLength(i+1, date->wYear - 1);
848 weeknum += startofprescal + 7;
851 weeknum1 = MONTHCAL_CalculateDayOfWeek(&st, FALSE);
852 if ((infoPtr->firstDay - weeknum1) % 7 > mindays) weeknum++;
858 for(i = 0; i < prev_month - 1; i++)
859 weeknum += MONTHCAL_MonthLength(i+1, date->wYear);
861 weeknum += startofprescal + 7;
863 st.wDay = st.wMonth = 1;
864 weeknum1 = MONTHCAL_CalculateDayOfWeek(&st, FALSE);
865 if ((infoPtr->firstDay - weeknum1) % 7 > mindays) weeknum++;
868 r = infoPtr->calendars[calIdx].weeknums;
870 /* erase whole week numbers area */
871 hbr = CreateSolidBrush(infoPtr->monthbk);
872 FillRect(hdc, &r, hbr);
875 /* reduce rectangle to one week number */
876 r.bottom = r.top + infoPtr->height_increment;
878 for(i = 0; i < 6; i++) {
879 if((i == 0) && (weeknum > 50))
881 wsprintfW(buf, fmt_weekW, weeknum);
884 else if((i == 5) && (weeknum > 47))
886 wsprintfW(buf, fmt_weekW, 1);
889 wsprintfW(buf, fmt_weekW, weeknum + i);
891 DrawTextW(hdc, buf, -1, &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
892 OffsetRect(&r, 0, infoPtr->height_increment);
895 /* line separator for week numbers column */
896 MoveToEx(hdc, infoPtr->calendars[calIdx].weeknums.right, infoPtr->calendars[calIdx].weeknums.top + 3 , NULL);
897 LineTo(hdc, infoPtr->calendars[calIdx].weeknums.right, infoPtr->calendars[calIdx].weeknums.bottom);
900 /* bottom today date */
901 static void MONTHCAL_PaintTodayTitle(const MONTHCAL_INFO *infoPtr, HDC hdc, const PAINTSTRUCT *ps)
903 if(!(infoPtr->dwStyle & MCS_NOTODAY)) {
904 static const WCHAR todayW[] = { 'T','o','d','a','y',':',0 };
905 static const WCHAR fmt_todayW[] = { '%','s',' ','%','s',0 };
906 WCHAR buf_todayW[30], buf_dateW[20], buf[80];
909 if(!(infoPtr->dwStyle & MCS_NOTODAYCIRCLE)) {
912 MONTHCAL_GetMaxDate(infoPtr, &fake_st);
913 /* this is always safe cause next month will never fully fit calendar */
915 MONTHCAL_CircleDay(infoPtr, hdc, &fake_st);
917 if (!LoadStringW(COMCTL32_hModule, IDM_TODAY, buf_todayW, countof(buf_todayW)))
919 WARN("Can't load resource\n");
920 strcpyW(buf_todayW, todayW);
922 MONTHCAL_CalcDayRect(infoPtr, &rtoday, 1, 6);
923 GetDateFormatW(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &infoPtr->todaysDate, NULL,
924 buf_dateW, countof(buf_dateW));
925 SelectObject(hdc, infoPtr->hBoldFont);
927 wsprintfW(buf, fmt_todayW, buf_todayW, buf_dateW);
928 DrawTextW(hdc, buf, -1, &rtoday, DT_CALCRECT | DT_LEFT | DT_VCENTER | DT_SINGLELINE);
929 DrawTextW(hdc, buf, -1, &rtoday, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
931 SelectObject(hdc, infoPtr->hFont);
935 /* today mark + focus */
936 static void MONTHCAL_PaintFocusAndCircle(const MONTHCAL_INFO *infoPtr, HDC hdc, const PAINTSTRUCT *ps)
938 if((infoPtr->minSel.wMonth == infoPtr->todaysDate.wMonth) &&
939 (infoPtr->minSel.wYear == infoPtr->todaysDate.wYear) &&
940 !(infoPtr->dwStyle & MCS_NOTODAYCIRCLE))
942 MONTHCAL_CircleDay(infoPtr, hdc, &infoPtr->todaysDate);
945 if(!MONTHCAL_IsDateEqual(&infoPtr->focusedSel, &st_null))
948 MONTHCAL_CalcPosFromDay(infoPtr, &infoPtr->focusedSel, &r);
949 DrawFocusRect(hdc, &r);
953 /* paint a calendar area */
954 static void MONTHCAL_PaintCalendar(const MONTHCAL_INFO *infoPtr, HDC hdc, const PAINTSTRUCT *ps, INT calIdx)
956 const SYSTEMTIME *date = &infoPtr->calendars[calIdx].month;
957 INT prev_month, i, j, length;
958 RECT r, fill_bk_rect;
964 /* fill whole days area - from week days area to today note rectangle */
965 fill_bk_rect = infoPtr->calendars[calIdx].wdays;
966 fill_bk_rect.bottom = infoPtr->calendars[calIdx].days.bottom +
967 (infoPtr->todayrect.bottom - infoPtr->todayrect.top);
969 hbr = CreateSolidBrush(infoPtr->monthbk);
970 FillRect(hdc, &fill_bk_rect, hbr);
973 /* draw line under day abbreviations */
974 MoveToEx(hdc, infoPtr->calendars[calIdx].days.left + 3,
975 infoPtr->calendars[calIdx].title.bottom + infoPtr->textHeight + 1, NULL);
976 LineTo(hdc, infoPtr->calendars[calIdx].days.right - 3,
977 infoPtr->calendars[calIdx].title.bottom + infoPtr->textHeight + 1);
979 prev_month = date->wMonth - 1;
980 if (prev_month == 0) prev_month = 12;
982 infoPtr->calendars[calIdx].wdays.left = infoPtr->calendars[calIdx].days.left =
983 infoPtr->calendars[calIdx].weeknums.right;
985 /* 1. draw day abbreviations */
986 SelectObject(hdc, infoPtr->hFont);
987 SetBkColor(hdc, infoPtr->monthbk);
988 SetTextColor(hdc, infoPtr->trailingtxt);
989 /* rectangle to draw a single day abbreviation within */
990 r = infoPtr->calendars[calIdx].wdays;
991 r.right = r.left + infoPtr->width_increment;
993 i = infoPtr->firstDay;
994 for(j = 0; j < 7; j++) {
995 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SABBREVDAYNAME1 + (i+j+6)%7, buf, countof(buf));
996 DrawTextW(hdc, buf, strlenW(buf), &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
997 OffsetRect(&r, infoPtr->width_increment, 0);
1000 /* 2. previous and next months */
1001 if (!(infoPtr->dwStyle & MCS_NOTRAILINGDATES) && (calIdx == 0 || calIdx == infoPtr->cal_num - 1))
1005 SetTextColor(hdc, infoPtr->trailingtxt);
1007 /* draw prev month */
1010 MONTHCAL_GetMinDate(infoPtr, &st);
1011 mask = 1 << (st.wDay-1);
1012 length = MONTHCAL_MonthLength(prev_month, date->wYear);
1014 while(st.wDay <= length)
1016 MONTHCAL_DrawDay(infoPtr, hdc, &st, infoPtr->monthdayState[0] & mask, ps);
1022 /* draw next month */
1023 if (calIdx == infoPtr->cal_num - 1)
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);
1040 /* 3. current month */
1041 SetTextColor(hdc, infoPtr->txt);
1045 length = MONTHCAL_MonthLength(date->wMonth, date->wYear);
1046 while(st.wDay <= length)
1048 MONTHCAL_DrawDay(infoPtr, hdc, &st, infoPtr->monthdayState[1] & mask, ps);
1054 static void MONTHCAL_Refresh(MONTHCAL_INFO *infoPtr, HDC hdc, const PAINTSTRUCT *ps)
1056 COLORREF old_text_clr, old_bk_clr;
1060 old_text_clr = SetTextColor(hdc, comctl32_color.clrWindowText);
1061 old_bk_clr = GetBkColor(hdc);
1062 old_font = GetCurrentObject(hdc, OBJ_FONT);
1064 for (i = 0; i < infoPtr->cal_num; i++)
1066 RECT *title = &infoPtr->calendars[i].title;
1069 /* draw title, redraw all its elements */
1070 if (IntersectRect(&r, &(ps->rcPaint), title))
1071 MONTHCAL_PaintTitle(infoPtr, hdc, ps, i);
1073 /* draw calendar area */
1074 UnionRect(&r, &infoPtr->calendars[i].wdays, &infoPtr->todayrect);
1075 if (IntersectRect(&r, &(ps->rcPaint), &r))
1076 MONTHCAL_PaintCalendar(infoPtr, hdc, ps, i);
1079 MONTHCAL_PaintWeeknumbers(infoPtr, hdc, ps, i);
1082 /* focus and today rectangle */
1083 MONTHCAL_PaintFocusAndCircle(infoPtr, hdc, ps);
1085 /* today at the bottom left */
1086 MONTHCAL_PaintTodayTitle(infoPtr, hdc, ps);
1088 /* navigation buttons */
1089 MONTHCAL_PaintButton(infoPtr, hdc, FALSE);
1090 MONTHCAL_PaintButton(infoPtr, hdc, TRUE);
1092 /* restore context */
1093 SetBkColor(hdc, old_bk_clr);
1094 SelectObject(hdc, old_font);
1095 SetTextColor(hdc, old_text_clr);
1099 MONTHCAL_GetMinReqRect(const MONTHCAL_INFO *infoPtr, LPRECT lpRect)
1101 TRACE("rect %p\n", lpRect);
1103 if(!lpRect) return FALSE;
1105 lpRect->left = infoPtr->calendars[0].title.left;
1106 lpRect->top = infoPtr->calendars[0].title.top;
1107 lpRect->right = infoPtr->calendars[0].title.right;
1108 lpRect->bottom = infoPtr->todayrect.bottom;
1110 AdjustWindowRect(lpRect, infoPtr->dwStyle, FALSE);
1112 /* minimal rectangle is zero based */
1113 OffsetRect(lpRect, -lpRect->left, -lpRect->top);
1115 TRACE("%s\n", wine_dbgstr_rect(lpRect));
1122 MONTHCAL_GetColor(const MONTHCAL_INFO *infoPtr, INT index)
1127 case MCSC_BACKGROUND:
1130 return infoPtr->txt;
1132 return infoPtr->titlebk;
1133 case MCSC_TITLETEXT:
1134 return infoPtr->titletxt;
1136 return infoPtr->monthbk;
1137 case MCSC_TRAILINGTEXT:
1138 return infoPtr->trailingtxt;
1146 MONTHCAL_SetColor(MONTHCAL_INFO *infoPtr, INT index, COLORREF color)
1150 TRACE("%d: color %08x\n", index, color);
1153 case MCSC_BACKGROUND:
1155 infoPtr->bk = color;
1158 prev = infoPtr->txt;
1159 infoPtr->txt = color;
1162 prev = infoPtr->titlebk;
1163 infoPtr->titlebk = color;
1165 case MCSC_TITLETEXT:
1166 prev=infoPtr->titletxt;
1167 infoPtr->titletxt = color;
1170 prev = infoPtr->monthbk;
1171 infoPtr->monthbk = color;
1173 case MCSC_TRAILINGTEXT:
1174 prev = infoPtr->trailingtxt;
1175 infoPtr->trailingtxt = color;
1179 InvalidateRect(infoPtr->hwndSelf, NULL, index == MCSC_BACKGROUND ? TRUE : FALSE);
1185 MONTHCAL_GetMonthDelta(const MONTHCAL_INFO *infoPtr)
1190 return infoPtr->delta;
1192 return infoPtr->visible;
1197 MONTHCAL_SetMonthDelta(MONTHCAL_INFO *infoPtr, INT delta)
1199 INT prev = infoPtr->delta;
1201 TRACE("delta %d\n", delta);
1203 infoPtr->delta = delta;
1208 static inline LRESULT
1209 MONTHCAL_GetFirstDayOfWeek(const MONTHCAL_INFO *infoPtr)
1213 /* convert from SYSTEMTIME to locale format */
1214 day = (infoPtr->firstDay >= 0) ? (infoPtr->firstDay+6)%7 : infoPtr->firstDay;
1216 return MAKELONG(day, infoPtr->firstDaySet);
1220 /* Sets the first day of the week that will appear in the control
1224 * [I] infoPtr : valid pointer to control data
1225 * [I] day : day number to set as new first day (0 == Monday,...,6 == Sunday)
1229 * Low word contains previous first day,
1230 * high word indicates was first day forced with this message before or is
1231 * locale difined (TRUE - was forced, FALSE - wasn't).
1233 * FIXME: this needs to be implemented properly in MONTHCAL_Refresh()
1234 * FIXME: we need more error checking here
1237 MONTHCAL_SetFirstDayOfWeek(MONTHCAL_INFO *infoPtr, INT day)
1239 LRESULT prev = MONTHCAL_GetFirstDayOfWeek(infoPtr);
1248 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_IFIRSTDAYOFWEEK, buf, countof(buf));
1249 TRACE("%s %d\n", debugstr_w(buf), strlenW(buf));
1251 new_day = atoiW(buf);
1253 infoPtr->firstDaySet = FALSE;
1257 new_day = 6; /* max first day allowed */
1258 infoPtr->firstDaySet = TRUE;
1262 /* Native behaviour for that case is broken: invalid date number >31
1263 got displayed at (0,0) position, current month starts always from
1264 (1,0) position. Should be implemented here as well only if there's
1265 nothing else to do. */
1267 FIXME("No bug compatibility for day=%d\n", day);
1270 infoPtr->firstDaySet = TRUE;
1273 /* convert from locale to SYSTEMTIME format */
1274 infoPtr->firstDay = (new_day >= 0) ? (++new_day) % 7 : new_day;
1276 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1283 MONTHCAL_GetMonthRange(const MONTHCAL_INFO *infoPtr, DWORD flag, SYSTEMTIME *st)
1285 TRACE("flag=%d, st=%p\n", flag, st);
1292 st[0] = infoPtr->calendars[0].month;
1293 st[1] = infoPtr->calendars[infoPtr->cal_num-1].month;
1295 if (st[0].wMonth == min_allowed_date.wMonth &&
1296 st[0].wYear == min_allowed_date.wYear)
1298 st[0].wDay = min_allowed_date.wDay;
1302 MONTHCAL_CalculateDayOfWeek(&st[0], TRUE);
1304 st[1].wDay = MONTHCAL_MonthLength(st[1].wMonth, st[1].wYear);
1305 MONTHCAL_CalculateDayOfWeek(&st[1], TRUE);
1307 return infoPtr->cal_num;
1311 /*FIXME: currently multicalendar feature isn't implemented,
1312 min date from previous month and max date from next one returned */
1313 MONTHCAL_GetMinDate(infoPtr, &st[0]);
1314 MONTHCAL_GetMaxDate(infoPtr, &st[1]);
1318 WARN("Unknown flag value, got %d\n", flag);
1322 return infoPtr->monthRange;
1327 MONTHCAL_GetMaxTodayWidth(const MONTHCAL_INFO *infoPtr)
1329 return(infoPtr->todayrect.right - infoPtr->todayrect.left);
1334 MONTHCAL_SetRange(MONTHCAL_INFO *infoPtr, SHORT limits, SYSTEMTIME *range)
1336 FILETIME ft_min, ft_max;
1338 TRACE("%x %p\n", limits, range);
1340 if ((limits & GDTR_MIN && !MONTHCAL_ValidateDate(&range[0])) ||
1341 (limits & GDTR_MAX && !MONTHCAL_ValidateDate(&range[1])))
1344 if (limits & GDTR_MIN)
1346 if (!MONTHCAL_ValidateTime(&range[0]))
1347 MONTHCAL_CopyTime(&infoPtr->todaysDate, &range[0]);
1349 infoPtr->minDate = range[0];
1350 infoPtr->rangeValid |= GDTR_MIN;
1352 if (limits & GDTR_MAX)
1354 if (!MONTHCAL_ValidateTime(&range[1]))
1355 MONTHCAL_CopyTime(&infoPtr->todaysDate, &range[1]);
1357 infoPtr->maxDate = range[1];
1358 infoPtr->rangeValid |= GDTR_MAX;
1361 /* Only one limit set - we are done */
1362 if ((infoPtr->rangeValid & (GDTR_MIN | GDTR_MAX)) != (GDTR_MIN | GDTR_MAX))
1365 SystemTimeToFileTime(&infoPtr->maxDate, &ft_max);
1366 SystemTimeToFileTime(&infoPtr->minDate, &ft_min);
1368 if (CompareFileTime(&ft_min, &ft_max) >= 0)
1370 if ((limits & (GDTR_MIN | GDTR_MAX)) == (GDTR_MIN | GDTR_MAX))
1372 /* Native swaps limits only when both limits are being set. */
1373 SYSTEMTIME st_tmp = infoPtr->minDate;
1374 infoPtr->minDate = infoPtr->maxDate;
1375 infoPtr->maxDate = st_tmp;
1379 /* reset the other limit */
1380 if (limits & GDTR_MIN) infoPtr->maxDate = st_null;
1381 if (limits & GDTR_MAX) infoPtr->minDate = st_null;
1382 infoPtr->rangeValid &= limits & GDTR_MIN ? ~GDTR_MAX : ~GDTR_MIN;
1391 MONTHCAL_GetRange(const MONTHCAL_INFO *infoPtr, SYSTEMTIME *range)
1393 TRACE("%p\n", range);
1395 if(!range) return FALSE;
1397 range[1] = infoPtr->maxDate;
1398 range[0] = infoPtr->minDate;
1400 return infoPtr->rangeValid;
1405 MONTHCAL_SetDayState(const MONTHCAL_INFO *infoPtr, INT months, MONTHDAYSTATE *states)
1407 TRACE("%p %d %p\n", infoPtr, months, states);
1408 if(months != infoPtr->monthRange) return 0;
1410 memcpy(infoPtr->monthdayState, states, months*sizeof(MONTHDAYSTATE));
1416 MONTHCAL_GetCurSel(const MONTHCAL_INFO *infoPtr, SYSTEMTIME *curSel)
1418 TRACE("%p\n", curSel);
1419 if(!curSel) return FALSE;
1420 if(infoPtr->dwStyle & MCS_MULTISELECT) return FALSE;
1422 *curSel = infoPtr->minSel;
1423 TRACE("%d/%d/%d\n", curSel->wYear, curSel->wMonth, curSel->wDay);
1428 MONTHCAL_SetCurSel(MONTHCAL_INFO *infoPtr, SYSTEMTIME *curSel)
1430 SYSTEMTIME prev = infoPtr->minSel;
1433 TRACE("%p\n", curSel);
1434 if(!curSel) return FALSE;
1435 if(infoPtr->dwStyle & MCS_MULTISELECT) return FALSE;
1437 if(!MONTHCAL_ValidateDate(curSel)) return FALSE;
1438 /* exit earlier if selection equals current */
1439 if (MONTHCAL_IsDateEqual(&infoPtr->minSel, curSel)) return TRUE;
1441 if(!MONTHCAL_IsDateInValidRange(infoPtr, curSel, FALSE)) return FALSE;
1443 infoPtr->calendars[0].month = *curSel;
1444 infoPtr->minSel = *curSel;
1445 infoPtr->maxSel = *curSel;
1447 /* if selection is still in current month, reduce rectangle */
1449 prev.wDay = curSel->wDay;
1450 if (MONTHCAL_IsDateEqual(&prev, curSel))
1455 MONTHCAL_CalcPosFromDay(infoPtr, &prev, &r_prev);
1456 MONTHCAL_CalcPosFromDay(infoPtr, curSel, &r_new);
1458 InvalidateRect(infoPtr->hwndSelf, &r_prev, FALSE);
1459 InvalidateRect(infoPtr->hwndSelf, &r_new, FALSE);
1462 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1469 MONTHCAL_GetMaxSelCount(const MONTHCAL_INFO *infoPtr)
1471 return infoPtr->maxSelCount;
1476 MONTHCAL_SetMaxSelCount(MONTHCAL_INFO *infoPtr, INT max)
1480 if(!(infoPtr->dwStyle & MCS_MULTISELECT)) return FALSE;
1481 if(max <= 0) return FALSE;
1483 infoPtr->maxSelCount = max;
1490 MONTHCAL_GetSelRange(const MONTHCAL_INFO *infoPtr, SYSTEMTIME *range)
1492 TRACE("%p\n", range);
1494 if(!range) return FALSE;
1496 if(infoPtr->dwStyle & MCS_MULTISELECT)
1498 range[1] = infoPtr->maxSel;
1499 range[0] = infoPtr->minSel;
1500 TRACE("[min,max]=[%d %d]\n", infoPtr->minSel.wDay, infoPtr->maxSel.wDay);
1509 MONTHCAL_SetSelRange(MONTHCAL_INFO *infoPtr, SYSTEMTIME *range)
1511 TRACE("%p\n", range);
1513 if(!range) return FALSE;
1515 if(infoPtr->dwStyle & MCS_MULTISELECT)
1517 SYSTEMTIME old_range[2];
1519 /* adjust timestamps */
1520 if(!MONTHCAL_ValidateTime(&range[0]))
1521 MONTHCAL_CopyTime(&infoPtr->todaysDate, &range[0]);
1522 if(!MONTHCAL_ValidateTime(&range[1]))
1523 MONTHCAL_CopyTime(&infoPtr->todaysDate, &range[1]);
1525 /* maximum range exceeded */
1526 if(!MONTHCAL_IsSelRangeValid(infoPtr, &range[0], &range[1], NULL)) return FALSE;
1528 old_range[0] = infoPtr->minSel;
1529 old_range[1] = infoPtr->maxSel;
1531 /* swap if min > max */
1532 if(MONTHCAL_CompareSystemTime(&range[0], &range[1]) <= 0)
1534 infoPtr->minSel = range[0];
1535 infoPtr->maxSel = range[1];
1539 infoPtr->minSel = range[1];
1540 infoPtr->maxSel = range[0];
1542 infoPtr->calendars[0].month = infoPtr->minSel;
1544 /* update day of week */
1545 MONTHCAL_CalculateDayOfWeek(&infoPtr->minSel, TRUE);
1546 MONTHCAL_CalculateDayOfWeek(&infoPtr->maxSel, TRUE);
1548 /* redraw if bounds changed */
1549 /* FIXME: no actual need to redraw everything */
1550 if(!MONTHCAL_IsDateEqual(&old_range[0], &range[0]) ||
1551 !MONTHCAL_IsDateEqual(&old_range[1], &range[1]))
1553 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1556 TRACE("[min,max]=[%d %d]\n", infoPtr->minSel.wDay, infoPtr->maxSel.wDay);
1565 MONTHCAL_GetToday(const MONTHCAL_INFO *infoPtr, SYSTEMTIME *today)
1567 TRACE("%p\n", today);
1569 if(!today) return FALSE;
1570 *today = infoPtr->todaysDate;
1574 /* Internal helper for MCM_SETTODAY handler and auto update timer handler
1578 * TRUE - today date changed
1579 * FALSE - today date isn't changed
1582 MONTHCAL_UpdateToday(MONTHCAL_INFO *infoPtr, const SYSTEMTIME *today)
1586 if(MONTHCAL_IsDateEqual(today, &infoPtr->todaysDate)) return FALSE;
1588 MONTHCAL_CalcPosFromDay(infoPtr, &infoPtr->todaysDate, &old_r);
1589 MONTHCAL_CalcPosFromDay(infoPtr, today, &new_r);
1591 infoPtr->todaysDate = *today;
1593 /* only two days need redrawing */
1594 InvalidateRect(infoPtr->hwndSelf, &old_r, FALSE);
1595 InvalidateRect(infoPtr->hwndSelf, &new_r, FALSE);
1599 /* MCM_SETTODAT handler */
1601 MONTHCAL_SetToday(MONTHCAL_INFO *infoPtr, const SYSTEMTIME *today)
1603 TRACE("%p\n", today);
1605 if(!today) return FALSE;
1607 /* remember if date was set successfully */
1608 if(MONTHCAL_UpdateToday(infoPtr, today)) infoPtr->todaySet = TRUE;
1613 /* returns calendar index containing specified point, or -1 if it's background */
1614 static INT MONTHCAL_GetCalendarFromPoint(const MONTHCAL_INFO *infoPtr, const POINT *pt)
1619 for (i = 0; i < infoPtr->cal_num; i++)
1621 /* whole bounding rectangle allows some optimization to compute */
1622 r.left = infoPtr->calendars[i].title.left;
1623 r.top = infoPtr->calendars[i].title.top;
1624 r.bottom = infoPtr->calendars[i].days.bottom;
1625 r.right = infoPtr->calendars[i].days.right;
1627 if (PtInRect(&r, *pt)) return i;
1633 static inline UINT fill_hittest_info(const MCHITTESTINFO *src, MCHITTESTINFO *dest)
1635 dest->uHit = src->uHit;
1638 if (dest->cbSize == sizeof(MCHITTESTINFO))
1639 memcpy(&dest->rc, &src->rc, sizeof(MCHITTESTINFO) - MCHITTESTINFO_V1_SIZE);
1645 MONTHCAL_HitTest(const MONTHCAL_INFO *infoPtr, MCHITTESTINFO *lpht)
1647 INT day, wday, wnum, calIdx;
1648 MCHITTESTINFO htinfo;
1649 SYSTEMTIME ht_month;
1652 if(!lpht || lpht->cbSize < MCHITTESTINFO_V1_SIZE) return -1;
1657 htinfo.st = st_null;
1659 /* we should preserve passed fields if hit area doesn't need them */
1660 if (lpht->cbSize == sizeof(MCHITTESTINFO))
1661 memcpy(&htinfo.rc, &lpht->rc, sizeof(MCHITTESTINFO) - MCHITTESTINFO_V1_SIZE);
1663 /* Comment in for debugging...
1664 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,
1665 infoPtr->wdays.left, infoPtr->wdays.right,
1666 infoPtr->wdays.top, infoPtr->wdays.bottom,
1667 infoPtr->days.left, infoPtr->days.right,
1668 infoPtr->days.top, infoPtr->days.bottom,
1669 infoPtr->todayrect.left, infoPtr->todayrect.right,
1670 infoPtr->todayrect.top, infoPtr->todayrect.bottom,
1671 infoPtr->weeknums.left, infoPtr->weeknums.right,
1672 infoPtr->weeknums.top, infoPtr->weeknums.bottom);
1675 /* guess in what calendar we are */
1676 calIdx = MONTHCAL_GetCalendarFromPoint(infoPtr, &lpht->pt);
1679 if (PtInRect(&infoPtr->todayrect, lpht->pt))
1681 htinfo.uHit = MCHT_TODAYLINK;
1682 htinfo.rc = infoPtr->todayrect;
1685 /* outside of calendar area? What's left must be background :-) */
1686 htinfo.uHit = MCHT_CALENDARBK;
1688 return fill_hittest_info(&htinfo, lpht);
1691 ht_month = infoPtr->calendars[calIdx].month;
1693 /* are we in the header? */
1694 if (PtInRect(&infoPtr->calendars[calIdx].title, lpht->pt)) {
1695 /* FIXME: buttons hittesting could be optimized cause maximum
1696 two calendars have buttons */
1697 if (calIdx == 0 && PtInRect(&infoPtr->titlebtnprev, lpht->pt))
1699 htinfo.uHit = MCHT_TITLEBTNPREV;
1700 htinfo.rc = infoPtr->titlebtnprev;
1702 else if (PtInRect(&infoPtr->titlebtnnext, lpht->pt))
1704 htinfo.uHit = MCHT_TITLEBTNNEXT;
1705 htinfo.rc = infoPtr->titlebtnnext;
1707 else if (PtInRect(&infoPtr->calendars[calIdx].titlemonth, lpht->pt))
1709 htinfo.uHit = MCHT_TITLEMONTH;
1710 htinfo.rc = infoPtr->calendars[calIdx].titlemonth;
1711 htinfo.iOffset = calIdx;
1713 else if (PtInRect(&infoPtr->calendars[calIdx].titleyear, lpht->pt))
1715 htinfo.uHit = MCHT_TITLEYEAR;
1716 htinfo.rc = infoPtr->calendars[calIdx].titleyear;
1717 htinfo.iOffset = calIdx;
1721 htinfo.uHit = MCHT_TITLE;
1722 htinfo.rc = infoPtr->calendars[calIdx].title;
1723 htinfo.iOffset = calIdx;
1726 return fill_hittest_info(&htinfo, lpht);
1729 /* days area (including week days and week numbers */
1730 day = MONTHCAL_CalcDayFromPos(infoPtr, x, y, &wday, &wnum);
1731 if (PtInRect(&infoPtr->calendars[calIdx].wdays, lpht->pt))
1733 htinfo.uHit = MCHT_CALENDARDAY;
1734 htinfo.iOffset = calIdx;
1735 htinfo.st.wYear = ht_month.wYear;
1736 htinfo.st.wMonth = (day < 1) ? ht_month.wMonth -1 : ht_month.wMonth;
1737 htinfo.st.wDay = (day < 1) ?
1738 MONTHCAL_MonthLength(ht_month.wMonth-1, ht_month.wYear) - day : day;
1740 MONTHCAL_CalcDayXY(infoPtr, &htinfo.st, &htinfo.iCol, &htinfo.iRow);
1742 else if(PtInRect(&infoPtr->calendars[calIdx].weeknums, lpht->pt))
1744 htinfo.uHit = MCHT_CALENDARWEEKNUM;
1745 htinfo.st.wYear = ht_month.wYear;
1746 htinfo.iOffset = calIdx;
1750 htinfo.st.wMonth = ht_month.wMonth - 1;
1751 htinfo.st.wDay = MONTHCAL_MonthLength(ht_month.wMonth-1, ht_month.wYear) - day;
1753 else if (day > MONTHCAL_MonthLength(ht_month.wMonth, ht_month.wYear))
1755 htinfo.st.wMonth = ht_month.wMonth + 1;
1756 htinfo.st.wDay = day - MONTHCAL_MonthLength(ht_month.wMonth, ht_month.wYear);
1760 htinfo.st.wMonth = ht_month.wMonth;
1761 htinfo.st.wDay = day;
1764 else if(PtInRect(&infoPtr->calendars[calIdx].days, lpht->pt))
1766 htinfo.iOffset = calIdx;
1767 htinfo.st.wYear = ht_month.wYear;
1768 htinfo.st.wMonth = ht_month.wMonth;
1771 htinfo.uHit = MCHT_CALENDARDATEPREV;
1772 MONTHCAL_GetPrevMonth(&htinfo.st);
1773 htinfo.st.wDay = MONTHCAL_MonthLength(lpht->st.wMonth, lpht->st.wYear) + day;
1775 else if (day > MONTHCAL_MonthLength(ht_month.wMonth, ht_month.wYear))
1777 htinfo.uHit = MCHT_CALENDARDATENEXT;
1778 MONTHCAL_GetNextMonth(&htinfo.st);
1779 htinfo.st.wDay = day - MONTHCAL_MonthLength(ht_month.wMonth, ht_month.wYear);
1783 htinfo.uHit = MCHT_CALENDARDATE;
1784 htinfo.st.wDay = day;
1787 MONTHCAL_CalcDayXY(infoPtr, &htinfo.st, &htinfo.iCol, &htinfo.iRow);
1788 MONTHCAL_CalcDayRect(infoPtr, &htinfo.rc, htinfo.iCol, htinfo.iRow);
1789 /* always update day of week */
1790 MONTHCAL_CalculateDayOfWeek(&htinfo.st, TRUE);
1793 return fill_hittest_info(&htinfo, lpht);
1796 /* MCN_GETDAYSTATE notification helper */
1797 static void MONTHCAL_NotifyDayState(MONTHCAL_INFO *infoPtr)
1799 if(infoPtr->dwStyle & MCS_DAYSTATE) {
1802 nmds.nmhdr.hwndFrom = infoPtr->hwndSelf;
1803 nmds.nmhdr.idFrom = GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_ID);
1804 nmds.nmhdr.code = MCN_GETDAYSTATE;
1805 nmds.cDayState = infoPtr->monthRange;
1806 nmds.prgDayState = Alloc(infoPtr->monthRange * sizeof(MONTHDAYSTATE));
1808 nmds.stStart = infoPtr->todaysDate;
1809 nmds.stStart.wYear = infoPtr->minSel.wYear;
1810 nmds.stStart.wMonth = infoPtr->minSel.wMonth;
1811 nmds.stStart.wDay = 1;
1813 SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, nmds.nmhdr.idFrom, (LPARAM)&nmds);
1814 memcpy(infoPtr->monthdayState, nmds.prgDayState, infoPtr->monthRange*sizeof(MONTHDAYSTATE));
1816 Free(nmds.prgDayState);
1820 /* no valid range check performed */
1821 static void MONTHCAL_Scroll(MONTHCAL_INFO *infoPtr, INT delta)
1825 for(i = 0; i < infoPtr->cal_num; i++)
1827 /* save selection position to shift it later */
1828 if (selIdx == -1 && MONTHCAL_CompareMonths(&infoPtr->minSel, &infoPtr->calendars[i].month) == 0)
1831 MONTHCAL_GetMonth(&infoPtr->calendars[i].month, delta);
1834 /* selection is always shifted to first calendar */
1835 if(infoPtr->dwStyle & MCS_MULTISELECT)
1837 SYSTEMTIME range[2];
1839 MONTHCAL_GetSelRange(infoPtr, range);
1840 MONTHCAL_GetMonth(&range[0], delta - selIdx);
1841 MONTHCAL_GetMonth(&range[1], delta - selIdx);
1842 MONTHCAL_SetSelRange(infoPtr, range);
1846 SYSTEMTIME st = infoPtr->minSel;
1848 MONTHCAL_GetMonth(&st, delta - selIdx);
1849 MONTHCAL_SetCurSel(infoPtr, &st);
1853 static void MONTHCAL_GoToMonth(MONTHCAL_INFO *infoPtr, enum nav_direction direction)
1855 INT delta = infoPtr->delta ? infoPtr->delta : infoPtr->cal_num;
1858 TRACE("%s\n", direction == DIRECTION_BACKWARD ? "back" : "fwd");
1860 /* check if change allowed by range set */
1861 if(direction == DIRECTION_BACKWARD)
1863 st = infoPtr->calendars[0].month;
1864 MONTHCAL_GetMonth(&st, -delta);
1868 st = infoPtr->calendars[infoPtr->cal_num-1].month;
1869 MONTHCAL_GetMonth(&st, delta);
1872 if(!MONTHCAL_IsDateInValidRange(infoPtr, &st, FALSE)) return;
1874 MONTHCAL_Scroll(infoPtr, direction == DIRECTION_BACKWARD ? -delta : delta);
1875 MONTHCAL_NotifyDayState(infoPtr);
1876 MONTHCAL_NotifySelectionChange(infoPtr);
1880 MONTHCAL_RButtonUp(MONTHCAL_INFO *infoPtr, LPARAM lParam)
1882 static const WCHAR todayW[] = { 'G','o',' ','t','o',' ','T','o','d','a','y',':',0 };
1887 hMenu = CreatePopupMenu();
1888 if (!LoadStringW(COMCTL32_hModule, IDM_GOTODAY, buf, countof(buf)))
1890 WARN("Can't load resource\n");
1891 strcpyW(buf, todayW);
1893 AppendMenuW(hMenu, MF_STRING|MF_ENABLED, 1, buf);
1894 menupoint.x = (short)LOWORD(lParam);
1895 menupoint.y = (short)HIWORD(lParam);
1896 ClientToScreen(infoPtr->hwndSelf, &menupoint);
1897 if( TrackPopupMenu(hMenu, TPM_RIGHTBUTTON | TPM_NONOTIFY | TPM_RETURNCMD,
1898 menupoint.x, menupoint.y, 0, infoPtr->hwndSelf, NULL))
1900 infoPtr->calendars[0].month = infoPtr->todaysDate;
1901 infoPtr->minSel = infoPtr->todaysDate;
1902 infoPtr->maxSel = infoPtr->todaysDate;
1903 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1911 * Subclassed edit control windproc function
1914 * [I] hwnd : the edit window handle
1915 * [I] uMsg : the message that is to be processed
1916 * [I] wParam : first message parameter
1917 * [I] lParam : second message parameter
1920 static LRESULT CALLBACK EditWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1922 MONTHCAL_INFO *infoPtr = (MONTHCAL_INFO *)GetWindowLongPtrW(GetParent(hwnd), 0);
1924 TRACE("(hwnd=%p, uMsg=%x, wParam=%lx, lParam=%lx)\n",
1925 hwnd, uMsg, wParam, lParam);
1930 return DLGC_WANTARROWS | DLGC_WANTALLKEYS;
1934 WNDPROC editProc = infoPtr->EditWndProc;
1935 infoPtr->EditWndProc = NULL;
1936 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (DWORD_PTR)editProc);
1937 return CallWindowProcW(editProc, hwnd, uMsg, wParam, lParam);
1944 if ((VK_ESCAPE == (INT)wParam) || (VK_RETURN == (INT)wParam))
1948 return CallWindowProcW(infoPtr->EditWndProc, hwnd, uMsg, wParam, lParam);
1951 SendMessageW(infoPtr->hWndYearUpDown, WM_CLOSE, 0, 0);
1952 SendMessageW(hwnd, WM_CLOSE, 0, 0);
1956 /* creates updown control and edit box */
1957 static void MONTHCAL_EditYear(MONTHCAL_INFO *infoPtr, INT calIdx)
1959 RECT *rc = &infoPtr->calendars[calIdx].titleyear;
1960 RECT *title = &infoPtr->calendars[calIdx].title;
1962 infoPtr->hWndYearEdit =
1963 CreateWindowExW(0, WC_EDITW, 0, WS_VISIBLE | WS_CHILD | ES_READONLY,
1964 rc->left + 3, (title->bottom + title->top - infoPtr->textHeight) / 2,
1965 rc->right - rc->left + 4,
1966 infoPtr->textHeight, infoPtr->hwndSelf,
1969 SendMessageW(infoPtr->hWndYearEdit, WM_SETFONT, (WPARAM)infoPtr->hBoldFont, TRUE);
1971 infoPtr->hWndYearUpDown =
1972 CreateWindowExW(0, UPDOWN_CLASSW, 0,
1973 WS_VISIBLE | WS_CHILD | UDS_SETBUDDYINT | UDS_NOTHOUSANDS | UDS_ARROWKEYS,
1974 rc->right + 7, (title->bottom + title->top - infoPtr->textHeight) / 2,
1975 18, infoPtr->textHeight, infoPtr->hwndSelf,
1978 /* attach edit box */
1979 SendMessageW(infoPtr->hWndYearUpDown, UDM_SETRANGE, 0,
1980 MAKELONG(max_allowed_date.wYear, min_allowed_date.wYear));
1981 SendMessageW(infoPtr->hWndYearUpDown, UDM_SETBUDDY, (WPARAM)infoPtr->hWndYearEdit, 0);
1982 SendMessageW(infoPtr->hWndYearUpDown, UDM_SETPOS, 0, infoPtr->calendars[calIdx].month.wYear);
1984 /* subclass edit box */
1985 infoPtr->EditWndProc = (WNDPROC)SetWindowLongPtrW(infoPtr->hWndYearEdit,
1986 GWLP_WNDPROC, (DWORD_PTR)EditWndProc);
1988 SetFocus(infoPtr->hWndYearEdit);
1992 MONTHCAL_LButtonDown(MONTHCAL_INFO *infoPtr, LPARAM lParam)
1997 /* Actually we don't need input focus for calendar, this is used to kill
1998 year updown and its buddy edit box */
1999 if (IsWindow(infoPtr->hWndYearUpDown))
2001 SetFocus(infoPtr->hwndSelf);
2005 SetCapture(infoPtr->hwndSelf);
2007 ht.cbSize = sizeof(MCHITTESTINFO);
2008 ht.pt.x = (short)LOWORD(lParam);
2009 ht.pt.y = (short)HIWORD(lParam);
2011 hit = MONTHCAL_HitTest(infoPtr, &ht);
2013 TRACE("%x at (%d, %d)\n", hit, ht.pt.x, ht.pt.y);
2017 case MCHT_TITLEBTNNEXT:
2018 MONTHCAL_GoToMonth(infoPtr, DIRECTION_FORWARD);
2019 infoPtr->status = MC_NEXTPRESSED;
2020 SetTimer(infoPtr->hwndSelf, MC_PREVNEXTMONTHTIMER, MC_PREVNEXTMONTHDELAY, 0);
2021 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
2024 case MCHT_TITLEBTNPREV:
2025 MONTHCAL_GoToMonth(infoPtr, DIRECTION_BACKWARD);
2026 infoPtr->status = MC_PREVPRESSED;
2027 SetTimer(infoPtr->hwndSelf, MC_PREVNEXTMONTHTIMER, MC_PREVNEXTMONTHDELAY, 0);
2028 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
2031 case MCHT_TITLEMONTH:
2033 HMENU hMenu = CreatePopupMenu();
2038 for (i = 0; i < 12; i++)
2040 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SMONTHNAME1+i, buf, countof(buf));
2041 AppendMenuW(hMenu, MF_STRING|MF_ENABLED, i + 1, buf);
2043 menupoint.x = ht.pt.x;
2044 menupoint.y = ht.pt.y;
2045 ClientToScreen(infoPtr->hwndSelf, &menupoint);
2046 i = TrackPopupMenu(hMenu,TPM_LEFTALIGN | TPM_NONOTIFY | TPM_RIGHTBUTTON | TPM_RETURNCMD,
2047 menupoint.x, menupoint.y, 0, infoPtr->hwndSelf, NULL);
2049 if ((i > 0) && (i < 13) && infoPtr->calendars[ht.iOffset].month.wMonth != i)
2051 INT delta = i - infoPtr->calendars[ht.iOffset].month.wMonth;
2054 /* check if change allowed by range set */
2055 st = delta < 0 ? infoPtr->calendars[0].month :
2056 infoPtr->calendars[infoPtr->cal_num-1].month;
2057 MONTHCAL_GetMonth(&st, delta);
2059 if (MONTHCAL_IsDateInValidRange(infoPtr, &st, FALSE))
2061 MONTHCAL_Scroll(infoPtr, delta);
2062 MONTHCAL_NotifyDayState(infoPtr);
2063 MONTHCAL_NotifySelectionChange(infoPtr);
2064 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
2069 case MCHT_TITLEYEAR:
2071 MONTHCAL_EditYear(infoPtr, ht.iOffset);
2074 case MCHT_TODAYLINK:
2076 infoPtr->calendars[0].month = infoPtr->todaysDate;
2077 infoPtr->minSel = infoPtr->todaysDate;
2078 infoPtr->maxSel = infoPtr->todaysDate;
2079 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
2081 MONTHCAL_NotifySelectionChange(infoPtr);
2082 MONTHCAL_NotifySelect(infoPtr);
2085 case MCHT_CALENDARDATENEXT:
2086 case MCHT_CALENDARDATEPREV:
2087 case MCHT_CALENDARDATE:
2091 MONTHCAL_CopyDate(&ht.st, &infoPtr->firstSel);
2093 st[0] = st[1] = ht.st;
2094 /* clear selection range */
2095 MONTHCAL_SetSelRange(infoPtr, st);
2097 infoPtr->status = MC_SEL_LBUTDOWN;
2098 MONTHCAL_SetDayFocus(infoPtr, &ht.st);
2108 MONTHCAL_LButtonUp(MONTHCAL_INFO *infoPtr, LPARAM lParam)
2116 if(infoPtr->status & (MC_PREVPRESSED | MC_NEXTPRESSED)) {
2119 KillTimer(infoPtr->hwndSelf, MC_PREVNEXTMONTHTIMER);
2120 r = infoPtr->status & MC_PREVPRESSED ? &infoPtr->titlebtnprev : &infoPtr->titlebtnnext;
2121 infoPtr->status &= ~(MC_PREVPRESSED | MC_NEXTPRESSED);
2123 InvalidateRect(infoPtr->hwndSelf, r, FALSE);
2128 /* always send NM_RELEASEDCAPTURE notification */
2129 nmhdr.hwndFrom = infoPtr->hwndSelf;
2130 nmhdr.idFrom = GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_ID);
2131 nmhdr.code = NM_RELEASEDCAPTURE;
2132 TRACE("Sent notification from %p to %p\n", infoPtr->hwndSelf, infoPtr->hwndNotify);
2134 SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, nmhdr.idFrom, (LPARAM)&nmhdr);
2136 if(!(infoPtr->status & MC_SEL_LBUTDOWN)) return 0;
2138 ht.cbSize = sizeof(MCHITTESTINFO);
2139 ht.pt.x = (short)LOWORD(lParam);
2140 ht.pt.y = (short)HIWORD(lParam);
2141 hit = MONTHCAL_HitTest(infoPtr, &ht);
2143 infoPtr->status = MC_SEL_LBUTUP;
2144 MONTHCAL_SetDayFocus(infoPtr, NULL);
2146 if((hit & MCHT_CALENDARDATE) == MCHT_CALENDARDATE)
2148 SYSTEMTIME sel = infoPtr->minSel;
2150 /* will be invalidated here */
2151 MONTHCAL_SetCurSel(infoPtr, &ht.st);
2153 /* send MCN_SELCHANGE only if new date selected */
2154 if (!MONTHCAL_IsDateEqual(&sel, &ht.st))
2155 MONTHCAL_NotifySelectionChange(infoPtr);
2157 MONTHCAL_NotifySelect(infoPtr);
2165 MONTHCAL_Timer(MONTHCAL_INFO *infoPtr, WPARAM id)
2170 case MC_PREVNEXTMONTHTIMER:
2171 if(infoPtr->status & MC_NEXTPRESSED) MONTHCAL_GoToMonth(infoPtr, DIRECTION_FORWARD);
2172 if(infoPtr->status & MC_PREVPRESSED) MONTHCAL_GoToMonth(infoPtr, DIRECTION_BACKWARD);
2173 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
2175 case MC_TODAYUPDATETIMER:
2179 if(infoPtr->todaySet) return 0;
2182 MONTHCAL_UpdateToday(infoPtr, &st);
2184 /* notification sent anyway */
2185 MONTHCAL_NotifySelectionChange(infoPtr);
2190 ERR("got unknown timer %ld\n", id);
2199 MONTHCAL_MouseMove(MONTHCAL_INFO *infoPtr, LPARAM lParam)
2206 if(!(infoPtr->status & MC_SEL_LBUTDOWN)) return 0;
2208 ht.cbSize = sizeof(MCHITTESTINFO);
2209 ht.pt.x = (short)LOWORD(lParam);
2210 ht.pt.y = (short)HIWORD(lParam);
2212 hit = MONTHCAL_HitTest(infoPtr, &ht);
2214 /* not on the calendar date numbers? bail out */
2215 TRACE("hit:%x\n",hit);
2216 if((hit & MCHT_CALENDARDATE) != MCHT_CALENDARDATE)
2218 MONTHCAL_SetDayFocus(infoPtr, NULL);
2224 /* if pointer is over focused day still there's nothing to do */
2225 if(!MONTHCAL_SetDayFocus(infoPtr, &ht.st)) return 0;
2227 MONTHCAL_CalcPosFromDay(infoPtr, &ht.st, &r);
2229 if(infoPtr->dwStyle & MCS_MULTISELECT) {
2232 MONTHCAL_GetSelRange(infoPtr, st);
2234 /* If we're still at the first selected date and range is empty, return.
2235 If range isn't empty we should change range to a single firstSel */
2236 if(MONTHCAL_IsDateEqual(&infoPtr->firstSel, &st_ht) &&
2237 MONTHCAL_IsDateEqual(&st[0], &st[1])) goto done;
2239 MONTHCAL_IsSelRangeValid(infoPtr, &st_ht, &infoPtr->firstSel, &st_ht);
2241 st[0] = infoPtr->firstSel;
2242 /* we should overwrite timestamp here */
2243 MONTHCAL_CopyDate(&st_ht, &st[1]);
2245 /* bounds will be swapped here if needed */
2246 MONTHCAL_SetSelRange(infoPtr, st);
2253 /* FIXME: this should specify a rectangle containing only the days that changed
2254 using InvalidateRect */
2255 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
2262 MONTHCAL_Paint(MONTHCAL_INFO *infoPtr, HDC hdc_paint)
2269 GetClientRect(infoPtr->hwndSelf, &ps.rcPaint);
2273 hdc = BeginPaint(infoPtr->hwndSelf, &ps);
2275 MONTHCAL_Refresh(infoPtr, hdc, &ps);
2276 if (!hdc_paint) EndPaint(infoPtr->hwndSelf, &ps);
2281 MONTHCAL_EraseBkgnd(const MONTHCAL_INFO *infoPtr, HDC hdc)
2286 if (!GetClipBox(hdc, &rc)) return FALSE;
2288 /* fill background */
2289 hbr = CreateSolidBrush (infoPtr->bk);
2290 FillRect(hdc, &rc, hbr);
2297 MONTHCAL_PrintClient(MONTHCAL_INFO *infoPtr, HDC hdc, DWORD options)
2299 FIXME("Partial Stub: (hdc=%p options=0x%08x)\n", hdc, options);
2301 if ((options & PRF_CHECKVISIBLE) && !IsWindowVisible(infoPtr->hwndSelf))
2304 if (options & PRF_ERASEBKGND)
2305 MONTHCAL_EraseBkgnd(infoPtr, hdc);
2307 if (options & PRF_CLIENT)
2308 MONTHCAL_Paint(infoPtr, hdc);
2314 MONTHCAL_SetFocus(const MONTHCAL_INFO *infoPtr)
2318 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
2323 /* sets the size information */
2324 static void MONTHCAL_UpdateSize(MONTHCAL_INFO *infoPtr)
2326 static const WCHAR O0W[] = { '0','0',0 };
2327 HDC hdc = GetDC(infoPtr->hwndSelf);
2328 RECT *title=&infoPtr->calendars[0].title;
2329 RECT *prev=&infoPtr->titlebtnprev;
2330 RECT *next=&infoPtr->titlebtnnext;
2331 RECT *titlemonth=&infoPtr->calendars[0].titlemonth;
2332 RECT *titleyear=&infoPtr->calendars[0].titleyear;
2333 RECT *wdays=&infoPtr->calendars[0].wdays;
2334 RECT *weeknumrect=&infoPtr->calendars[0].weeknums;
2335 RECT *days=&infoPtr->calendars[0].days;
2336 RECT *todayrect=&infoPtr->todayrect;
2340 INT xdiv, dx, dy, i;
2344 GetClientRect(infoPtr->hwndSelf, &rcClient);
2346 currentFont = SelectObject(hdc, infoPtr->hFont);
2348 /* get the height and width of each day's text */
2349 GetTextMetricsW(hdc, &tm);
2350 infoPtr->textHeight = tm.tmHeight + tm.tmExternalLeading + tm.tmInternalLeading;
2352 /* find largest abbreviated day name for current locale */
2353 size.cx = sz.cx = 0;
2354 for (i = 0; i < 7; i++)
2356 if(GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SABBREVDAYNAME1 + i,
2357 buff, countof(buff)))
2359 GetTextExtentPoint32W(hdc, buff, lstrlenW(buff), &sz);
2360 if (sz.cx > size.cx) size.cx = sz.cx;
2362 else /* locale independent fallback on failure */
2364 static const WCHAR SunW[] = { 'S','u','n',0 };
2366 GetTextExtentPoint32W(hdc, SunW, lstrlenW(SunW), &size);
2371 infoPtr->textWidth = size.cx + 2;
2373 /* recalculate the height and width increments and offsets */
2374 GetTextExtentPoint32W(hdc, O0W, 2, &size);
2376 xdiv = (infoPtr->dwStyle & MCS_WEEKNUMBERS) ? 8 : 7;
2378 infoPtr->width_increment = size.cx * 2 + 4;
2379 infoPtr->height_increment = infoPtr->textHeight;
2381 /* calculate title area */
2383 title->bottom = 3 * infoPtr->height_increment / 2;
2385 title->right = infoPtr->width_increment * xdiv;
2387 /* set the dimensions of the next and previous buttons and center */
2388 /* the month text vertically */
2389 prev->top = next->top = title->top + 4;
2390 prev->bottom = next->bottom = title->bottom - 4;
2391 prev->left = title->left + 4;
2392 prev->right = prev->left + (title->bottom - title->top);
2393 next->right = title->right - 4;
2394 next->left = next->right - (title->bottom - title->top);
2396 /* titlemonth->left and right change based upon the current month */
2397 /* and are recalculated in refresh as the current month may change */
2398 /* without the control being resized */
2399 titlemonth->top = titleyear->top = title->top + (infoPtr->height_increment)/2;
2400 titlemonth->bottom = titleyear->bottom = title->bottom - (infoPtr->height_increment)/2;
2402 /* setup the dimensions of the rectangle we draw the names of the */
2403 /* days of the week in */
2404 weeknumrect->left = 0;
2406 if(infoPtr->dwStyle & MCS_WEEKNUMBERS)
2407 weeknumrect->right = prev->right;
2409 weeknumrect->right = weeknumrect->left;
2411 wdays->left = days->left = weeknumrect->right;
2412 wdays->right = days->right = wdays->left + 7 * infoPtr->width_increment;
2413 wdays->top = title->bottom;
2414 wdays->bottom = wdays->top + infoPtr->height_increment;
2416 days->top = weeknumrect->top = wdays->bottom;
2417 days->bottom = weeknumrect->bottom = days->top + 6 * infoPtr->height_increment;
2419 todayrect->left = 0;
2420 todayrect->right = title->right;
2421 todayrect->top = days->bottom;
2422 todayrect->bottom = days->bottom + infoPtr->height_increment;
2424 /* offset all rectangles to center in client area */
2425 dx = (rcClient.right - title->right) / 2;
2426 dy = (rcClient.bottom - todayrect->bottom) / 2;
2428 /* if calendar doesn't fit client area show it at left/top bounds */
2429 if (title->left + dx < 0) dx = 0;
2430 if (title->top + dy < 0) dy = 0;
2432 if (dx != 0 || dy != 0)
2434 OffsetRect(title, dx, dy);
2435 OffsetRect(prev, dx, dy);
2436 OffsetRect(next, dx, dy);
2437 OffsetRect(titlemonth, dx, dy);
2438 OffsetRect(titleyear, dx, dy);
2439 OffsetRect(wdays, dx, dy);
2440 OffsetRect(weeknumrect, dx, dy);
2441 OffsetRect(days, dx, dy);
2442 OffsetRect(todayrect, dx, dy);
2445 TRACE("dx=%d dy=%d client[%s] title[%s] wdays[%s] days[%s] today[%s]\n",
2446 infoPtr->width_increment,infoPtr->height_increment,
2447 wine_dbgstr_rect(&rcClient),
2448 wine_dbgstr_rect(title),
2449 wine_dbgstr_rect(wdays),
2450 wine_dbgstr_rect(days),
2451 wine_dbgstr_rect(todayrect));
2453 /* restore the originally selected font */
2454 SelectObject(hdc, currentFont);
2456 ReleaseDC(infoPtr->hwndSelf, hdc);
2459 static LRESULT MONTHCAL_Size(MONTHCAL_INFO *infoPtr, int Width, int Height)
2461 TRACE("(width=%d, height=%d)\n", Width, Height);
2463 MONTHCAL_UpdateSize(infoPtr);
2465 /* invalidate client area and erase background */
2466 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
2471 static LRESULT MONTHCAL_GetFont(const MONTHCAL_INFO *infoPtr)
2473 return (LRESULT)infoPtr->hFont;
2476 static LRESULT MONTHCAL_SetFont(MONTHCAL_INFO *infoPtr, HFONT hFont, BOOL redraw)
2481 if (!hFont) return 0;
2483 hOldFont = infoPtr->hFont;
2484 infoPtr->hFont = hFont;
2486 GetObjectW(infoPtr->hFont, sizeof(lf), &lf);
2487 lf.lfWeight = FW_BOLD;
2488 infoPtr->hBoldFont = CreateFontIndirectW(&lf);
2490 MONTHCAL_UpdateSize(infoPtr);
2493 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
2495 return (LRESULT)hOldFont;
2498 /* update theme after a WM_THEMECHANGED message */
2499 static LRESULT theme_changed (const MONTHCAL_INFO* infoPtr)
2501 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
2502 CloseThemeData (theme);
2503 OpenThemeData (infoPtr->hwndSelf, themeClass);
2507 static INT MONTHCAL_StyleChanged(MONTHCAL_INFO *infoPtr, WPARAM wStyleType,
2508 const STYLESTRUCT *lpss)
2510 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
2511 wStyleType, lpss->styleOld, lpss->styleNew);
2513 if (wStyleType != GWL_STYLE) return 0;
2515 infoPtr->dwStyle = lpss->styleNew;
2517 /* make room for week numbers */
2518 if ((lpss->styleNew ^ lpss->styleOld) & MCS_WEEKNUMBERS)
2519 MONTHCAL_UpdateSize(infoPtr);
2524 static INT MONTHCAL_StyleChanging(MONTHCAL_INFO *infoPtr, WPARAM wStyleType,
2527 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
2528 wStyleType, lpss->styleOld, lpss->styleNew);
2530 /* block MCS_MULTISELECT change */
2531 if ((lpss->styleNew ^ lpss->styleOld) & MCS_MULTISELECT)
2533 if (lpss->styleOld & MCS_MULTISELECT)
2534 lpss->styleNew |= MCS_MULTISELECT;
2536 lpss->styleNew &= ~MCS_MULTISELECT;
2542 /* FIXME: check whether dateMin/dateMax need to be adjusted. */
2544 MONTHCAL_Create(HWND hwnd, LPCREATESTRUCTW lpcs)
2546 MONTHCAL_INFO *infoPtr;
2548 /* allocate memory for info structure */
2549 infoPtr = Alloc(sizeof(MONTHCAL_INFO));
2550 SetWindowLongPtrW(hwnd, 0, (DWORD_PTR)infoPtr);
2552 if (infoPtr == NULL) {
2553 ERR("could not allocate info memory!\n");
2557 infoPtr->hwndSelf = hwnd;
2558 infoPtr->hwndNotify = lpcs->hwndParent;
2559 infoPtr->dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
2560 infoPtr->calendars = Alloc(sizeof(CALENDAR_INFO));
2561 if (!infoPtr->calendars) goto fail;
2563 infoPtr->cal_num = 1;
2565 MONTHCAL_SetFont(infoPtr, GetStockObject(DEFAULT_GUI_FONT), FALSE);
2567 /* initialize info structure */
2568 /* FIXME: calculate systemtime ->> localtime(substract timezoneinfo) */
2570 GetLocalTime(&infoPtr->todaysDate);
2571 MONTHCAL_SetFirstDayOfWeek(infoPtr, -1);
2573 infoPtr->maxSelCount = (infoPtr->dwStyle & MCS_MULTISELECT) ? 7 : 1;
2574 infoPtr->monthRange = 3;
2576 infoPtr->monthdayState = Alloc(infoPtr->monthRange * sizeof(MONTHDAYSTATE));
2577 if (!infoPtr->monthdayState) goto fail;
2579 infoPtr->titlebk = comctl32_color.clrActiveCaption;
2580 infoPtr->titletxt = comctl32_color.clrWindow;
2581 infoPtr->monthbk = comctl32_color.clrWindow;
2582 infoPtr->trailingtxt = comctl32_color.clrGrayText;
2583 infoPtr->bk = comctl32_color.clrWindow;
2584 infoPtr->txt = comctl32_color.clrWindowText;
2586 infoPtr->minSel = infoPtr->todaysDate;
2587 infoPtr->maxSel = infoPtr->todaysDate;
2588 infoPtr->calendars[0].month = infoPtr->todaysDate;
2589 infoPtr->isUnicode = TRUE;
2591 /* call MONTHCAL_UpdateSize to set all of the dimensions */
2592 /* of the control */
2593 MONTHCAL_UpdateSize(infoPtr);
2595 /* today auto update timer, to be freed only on control destruction */
2596 SetTimer(infoPtr->hwndSelf, MC_TODAYUPDATETIMER, MC_TODAYUPDATEDELAY, 0);
2598 OpenThemeData (infoPtr->hwndSelf, themeClass);
2603 Free(infoPtr->monthdayState);
2604 Free(infoPtr->calendars);
2610 MONTHCAL_Destroy(MONTHCAL_INFO *infoPtr)
2612 /* free month calendar info data */
2613 Free(infoPtr->monthdayState);
2614 Free(infoPtr->calendars);
2615 SetWindowLongPtrW(infoPtr->hwndSelf, 0, 0);
2617 CloseThemeData (GetWindowTheme (infoPtr->hwndSelf));
2624 * Handler for WM_NOTIFY messages
2627 MONTHCAL_Notify(MONTHCAL_INFO *infoPtr, NMHDR *hdr)
2629 /* notification from year edit updown */
2630 if (hdr->code == UDN_DELTAPOS)
2632 NMUPDOWN *nmud = (NMUPDOWN*)hdr;
2634 if (hdr->hwndFrom == infoPtr->hWndYearUpDown && nmud->iDelta)
2636 /* year value limits are set up explicitly after updown creation */
2637 MONTHCAL_Scroll(infoPtr, 12 * nmud->iDelta);
2638 MONTHCAL_NotifyDayState(infoPtr);
2639 MONTHCAL_NotifySelectionChange(infoPtr);
2646 MONTHCAL_SetUnicodeFormat(MONTHCAL_INFO *infoPtr, BOOL isUnicode)
2648 BOOL prev = infoPtr->isUnicode;
2649 infoPtr->isUnicode = isUnicode;
2654 MONTHCAL_GetUnicodeFormat(const MONTHCAL_INFO *infoPtr)
2656 return infoPtr->isUnicode;
2659 static LRESULT WINAPI
2660 MONTHCAL_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2662 MONTHCAL_INFO *infoPtr = (MONTHCAL_INFO *)GetWindowLongPtrW(hwnd, 0);
2664 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n", hwnd, uMsg, wParam, lParam);
2666 if (!infoPtr && (uMsg != WM_CREATE))
2667 return DefWindowProcW(hwnd, uMsg, wParam, lParam);
2671 return MONTHCAL_GetCurSel(infoPtr, (LPSYSTEMTIME)lParam);
2674 return MONTHCAL_SetCurSel(infoPtr, (LPSYSTEMTIME)lParam);
2676 case MCM_GETMAXSELCOUNT:
2677 return MONTHCAL_GetMaxSelCount(infoPtr);
2679 case MCM_SETMAXSELCOUNT:
2680 return MONTHCAL_SetMaxSelCount(infoPtr, wParam);
2682 case MCM_GETSELRANGE:
2683 return MONTHCAL_GetSelRange(infoPtr, (LPSYSTEMTIME)lParam);
2685 case MCM_SETSELRANGE:
2686 return MONTHCAL_SetSelRange(infoPtr, (LPSYSTEMTIME)lParam);
2688 case MCM_GETMONTHRANGE:
2689 return MONTHCAL_GetMonthRange(infoPtr, wParam, (SYSTEMTIME*)lParam);
2691 case MCM_SETDAYSTATE:
2692 return MONTHCAL_SetDayState(infoPtr, (INT)wParam, (LPMONTHDAYSTATE)lParam);
2694 case MCM_GETMINREQRECT:
2695 return MONTHCAL_GetMinReqRect(infoPtr, (LPRECT)lParam);
2698 return MONTHCAL_GetColor(infoPtr, wParam);
2701 return MONTHCAL_SetColor(infoPtr, wParam, (COLORREF)lParam);
2704 return MONTHCAL_GetToday(infoPtr, (LPSYSTEMTIME)lParam);
2707 return MONTHCAL_SetToday(infoPtr, (LPSYSTEMTIME)lParam);
2710 return MONTHCAL_HitTest(infoPtr, (PMCHITTESTINFO)lParam);
2712 case MCM_GETFIRSTDAYOFWEEK:
2713 return MONTHCAL_GetFirstDayOfWeek(infoPtr);
2715 case MCM_SETFIRSTDAYOFWEEK:
2716 return MONTHCAL_SetFirstDayOfWeek(infoPtr, (INT)lParam);
2719 return MONTHCAL_GetRange(infoPtr, (LPSYSTEMTIME)lParam);
2722 return MONTHCAL_SetRange(infoPtr, (SHORT)wParam, (LPSYSTEMTIME)lParam);
2724 case MCM_GETMONTHDELTA:
2725 return MONTHCAL_GetMonthDelta(infoPtr);
2727 case MCM_SETMONTHDELTA:
2728 return MONTHCAL_SetMonthDelta(infoPtr, wParam);
2730 case MCM_GETMAXTODAYWIDTH:
2731 return MONTHCAL_GetMaxTodayWidth(infoPtr);
2733 case MCM_SETUNICODEFORMAT:
2734 return MONTHCAL_SetUnicodeFormat(infoPtr, (BOOL)wParam);
2736 case MCM_GETUNICODEFORMAT:
2737 return MONTHCAL_GetUnicodeFormat(infoPtr);
2740 return DLGC_WANTARROWS | DLGC_WANTCHARS;
2743 return MONTHCAL_RButtonUp(infoPtr, lParam);
2745 case WM_LBUTTONDOWN:
2746 return MONTHCAL_LButtonDown(infoPtr, lParam);
2749 return MONTHCAL_MouseMove(infoPtr, lParam);
2752 return MONTHCAL_LButtonUp(infoPtr, lParam);
2755 return MONTHCAL_Paint(infoPtr, (HDC)wParam);
2757 case WM_PRINTCLIENT:
2758 return MONTHCAL_PrintClient(infoPtr, (HDC)wParam, (DWORD)lParam);
2761 return MONTHCAL_EraseBkgnd(infoPtr, (HDC)wParam);
2764 return MONTHCAL_SetFocus(infoPtr);
2767 return MONTHCAL_Size(infoPtr, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
2770 return MONTHCAL_Notify(infoPtr, (NMHDR*)lParam);
2773 return MONTHCAL_Create(hwnd, (LPCREATESTRUCTW)lParam);
2776 return MONTHCAL_SetFont(infoPtr, (HFONT)wParam, (BOOL)lParam);
2779 return MONTHCAL_GetFont(infoPtr);
2782 return MONTHCAL_Timer(infoPtr, wParam);
2784 case WM_THEMECHANGED:
2785 return theme_changed (infoPtr);
2788 return MONTHCAL_Destroy(infoPtr);
2790 case WM_SYSCOLORCHANGE:
2791 COMCTL32_RefreshSysColors();
2794 case WM_STYLECHANGED:
2795 return MONTHCAL_StyleChanged(infoPtr, wParam, (LPSTYLESTRUCT)lParam);
2797 case WM_STYLECHANGING:
2798 return MONTHCAL_StyleChanging(infoPtr, wParam, (LPSTYLESTRUCT)lParam);
2801 if ((uMsg >= WM_USER) && (uMsg < WM_APP) && !COMCTL32_IsReflectedMessage(uMsg))
2802 ERR( "unknown msg %04x wp=%08lx lp=%08lx\n", uMsg, wParam, lParam);
2803 return DefWindowProcW(hwnd, uMsg, wParam, lParam);
2809 MONTHCAL_Register(void)
2813 ZeroMemory(&wndClass, sizeof(WNDCLASSW));
2814 wndClass.style = CS_GLOBALCLASS;
2815 wndClass.lpfnWndProc = MONTHCAL_WindowProc;
2816 wndClass.cbClsExtra = 0;
2817 wndClass.cbWndExtra = sizeof(MONTHCAL_INFO *);
2818 wndClass.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
2819 wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
2820 wndClass.lpszClassName = MONTHCAL_CLASSW;
2822 RegisterClassW(&wndClass);
2827 MONTHCAL_Unregister(void)
2829 UnregisterClassW(MONTHCAL_CLASSW, NULL);