2 * Month calendar control
4 * Copyright 1998, 1999 Eric Kohl (ekohl@abo.rhein-zeitung.de)
5 * Copyright 1999 Alex Priem (alexp@sci.kun.nl)
6 * Copyright 1999 Chris Morgan <cmorgan@wpi.edu> and
7 * James Abbatiello <abbeyj@wpi.edu>
8 * Copyright 2000 Uwe Bonnes <bon@elektron.ikp.physik.tu-darmstadt.de>
9 * Copyright 2009-2011 Nikolay Sivov
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 * This code was audited for completeness against the documented features
28 * of Comctl32.dll version 6.0 on Oct. 20, 2004, by Dimitrie O. Paun.
30 * Unless otherwise noted, we believe this code to be complete, as per
31 * the specification mentioned above.
32 * If you discover missing features, or bugs, please note them below.
35 * -- MCM_[GS]ETUNICODEFORMAT
36 * -- handle resources better (doesn't work now);
37 * -- take care of internationalization.
38 * -- keyboard handling.
57 #include "wine/unicode.h"
58 #include "wine/debug.h"
60 WINE_DEFAULT_DEBUG_CHANNEL(monthcal);
62 #define MC_SEL_LBUTUP 1 /* Left button released */
63 #define MC_SEL_LBUTDOWN 2 /* Left button pressed in calendar */
64 #define MC_PREVPRESSED 4 /* Prev month button pressed */
65 #define MC_NEXTPRESSED 8 /* Next month button pressed */
66 #define MC_PREVNEXTMONTHDELAY 350 /* when continuously pressing `next/prev
67 month', wait 350 ms before going
68 to the next/prev month */
69 #define MC_TODAYUPDATEDELAY 120000 /* time between today check for update (2 min) */
71 #define MC_PREVNEXTMONTHTIMER 1 /* Timer ID's */
72 #define MC_TODAYUPDATETIMER 2
74 #define countof(arr) (sizeof(arr)/sizeof(arr[0]))
76 /* convert from days to 100 nanoseconds unit - used as FILETIME unit */
77 #define DAYSTO100NSECS(days) (((ULONGLONG)(days))*24*60*60*10000000)
79 /* single calendar data */
80 typedef struct _CALENDAR_INFO
82 RECT title; /* rect for the header above the calendar */
83 RECT titlemonth; /* the 'month name' text in the header */
84 RECT titleyear; /* the 'year number' text in the header */
85 RECT wdays; /* week days at top */
86 RECT days; /* calendar area */
87 RECT weeknums; /* week numbers at left side */
89 SYSTEMTIME month;/* contains calendar main month/year */
95 DWORD dwStyle; /* cached GWL_STYLE */
97 COLORREF colors[MCSC_TRAILINGTEXT+1];
98 HBRUSH brushes[MCSC_MONTHBK+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 };
671 INT old_bkmode, selection;
673 /* no need to check styles: when selection is not valid, it is set to zero.
674 1 < day < 31, so everything is OK */
675 MONTHCAL_CalcPosFromDay(infoPtr, st, &r);
676 if(!IntersectRect(&r_temp, &(ps->rcPaint), &r)) return;
678 if ((MONTHCAL_CompareDate(st, &infoPtr->minSel) >= 0) &&
679 (MONTHCAL_CompareDate(st, &infoPtr->maxSel) <= 0))
682 TRACE("%d %d %d\n", st->wDay, infoPtr->minSel.wDay, infoPtr->maxSel.wDay);
683 TRACE("%s\n", wine_dbgstr_rect(&r));
684 oldCol = SetTextColor(hdc, infoPtr->colors[MCSC_MONTHBK]);
685 oldBk = SetBkColor(hdc, infoPtr->colors[MCSC_TRAILINGTEXT]);
686 FillRect(hdc, &r, infoPtr->brushes[MCSC_TITLEBK]);
693 SelectObject(hdc, bold ? infoPtr->hBoldFont : infoPtr->hFont);
695 old_bkmode = SetBkMode(hdc, TRANSPARENT);
696 wsprintfW(buf, fmtW, st->wDay);
697 DrawTextW(hdc, buf, -1, &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE );
698 SetBkMode(hdc, old_bkmode);
702 SetTextColor(hdc, oldCol);
703 SetBkColor(hdc, oldBk);
708 static void MONTHCAL_PaintButton(MONTHCAL_INFO *infoPtr, HDC hdc, enum nav_direction button)
710 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
711 RECT *r = button == DIRECTION_FORWARD ? &infoPtr->titlebtnnext : &infoPtr->titlebtnprev;
712 BOOL pressed = button == DIRECTION_FORWARD ? infoPtr->status & MC_NEXTPRESSED :
713 infoPtr->status & MC_PREVPRESSED;
716 static const int states[] = {
718 ABS_LEFTNORMAL, ABS_LEFTPRESSED, ABS_LEFTDISABLED,
720 ABS_RIGHTNORMAL, ABS_RIGHTPRESSED, ABS_RIGHTDISABLED
722 int stateNum = button == DIRECTION_FORWARD ? 3 : 0;
727 if (infoPtr->dwStyle & WS_DISABLED) stateNum += 2;
729 DrawThemeBackground (theme, hdc, SBP_ARROWBTN, states[stateNum], r, NULL);
733 int style = button == DIRECTION_FORWARD ? DFCS_SCROLLRIGHT : DFCS_SCROLLLEFT;
735 style |= DFCS_PUSHED;
738 if (infoPtr->dwStyle & WS_DISABLED) style |= DFCS_INACTIVE;
741 DrawFrameControl(hdc, r, DFC_SCROLL, style);
744 /* paint a title with buttons and month/year string */
745 static void MONTHCAL_PaintTitle(MONTHCAL_INFO *infoPtr, HDC hdc, const PAINTSTRUCT *ps, INT calIdx)
747 static const WCHAR fmt_monthW[] = { '%','s',' ','%','l','d',0 };
748 RECT *title = &infoPtr->calendars[calIdx].title;
749 const SYSTEMTIME *st = &infoPtr->calendars[calIdx].month;
750 WCHAR buf_month[80], buf_fmt[80];
753 /* fill header box */
754 FillRect(hdc, title, infoPtr->brushes[MCSC_TITLEBK]);
756 /* month/year string */
757 SetBkColor(hdc, infoPtr->colors[MCSC_TITLEBK]);
758 SetTextColor(hdc, infoPtr->colors[MCSC_TITLETEXT]);
759 SelectObject(hdc, infoPtr->hBoldFont);
761 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SMONTHNAME1 + st->wMonth - 1,
762 buf_month, countof(buf_month));
764 wsprintfW(buf_fmt, fmt_monthW, buf_month, st->wYear);
765 DrawTextW(hdc, buf_fmt, strlenW(buf_fmt), title,
766 DT_CENTER | DT_VCENTER | DT_SINGLELINE);
768 /* update title rectangles with current month - used while testing hits */
769 GetTextExtentPoint32W(hdc, buf_fmt, strlenW(buf_fmt), &sz);
770 infoPtr->calendars[calIdx].titlemonth.left = title->right / 2 + title->left / 2 - sz.cx / 2;
771 infoPtr->calendars[calIdx].titleyear.right = title->right / 2 + title->left / 2 + sz.cx / 2;
773 GetTextExtentPoint32W(hdc, buf_month, strlenW(buf_month), &sz);
774 infoPtr->calendars[calIdx].titlemonth.right = infoPtr->calendars[calIdx].titlemonth.left + sz.cx;
775 infoPtr->calendars[calIdx].titleyear.left = infoPtr->calendars[calIdx].titlemonth.right;
778 static void MONTHCAL_PaintWeeknumbers(const MONTHCAL_INFO *infoPtr, HDC hdc, const PAINTSTRUCT *ps, INT calIdx)
780 const SYSTEMTIME *date = &infoPtr->calendars[calIdx].month;
781 static const WCHAR fmt_weekW[] = { '%','d',0 };
782 INT mindays, weeknum, weeknum1, startofprescal;
788 if (!(infoPtr->dwStyle & MCS_WEEKNUMBERS)) return;
790 MONTHCAL_GetMinDate(infoPtr, &st);
791 startofprescal = st.wDay;
794 prev_month = date->wMonth - 1;
795 if(prev_month == 0) prev_month = 12;
798 Rules what week to call the first week of a new year:
799 LOCALE_IFIRSTWEEKOFYEAR == 0 (e.g US?):
800 The week containing Jan 1 is the first week of year
801 LOCALE_IFIRSTWEEKOFYEAR == 2 (e.g. Germany):
802 First week of year must contain 4 days of the new year
803 LOCALE_IFIRSTWEEKOFYEAR == 1 (what contries?)
804 The first week of the year must contain only days of the new year
806 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_IFIRSTWEEKOFYEAR, buf, countof(buf));
807 weeknum = atoiW(buf);
817 WARN("Unknown LOCALE_IFIRSTWEEKOFYEAR value %d, defaulting to 0\n", weeknum);
821 if (date->wMonth == 1)
823 /* calculate all those exceptions for january */
824 st.wDay = st.wMonth = 1;
825 weeknum1 = MONTHCAL_CalculateDayOfWeek(&st, FALSE);
826 if ((infoPtr->firstDay - weeknum1) % 7 > mindays)
831 for(i = 0; i < 11; i++)
832 weeknum += MONTHCAL_MonthLength(i+1, date->wYear - 1);
834 weeknum += startofprescal + 7;
837 weeknum1 = MONTHCAL_CalculateDayOfWeek(&st, FALSE);
838 if ((infoPtr->firstDay - weeknum1) % 7 > mindays) weeknum++;
844 for(i = 0; i < prev_month - 1; i++)
845 weeknum += MONTHCAL_MonthLength(i+1, date->wYear);
847 weeknum += startofprescal + 7;
849 st.wDay = st.wMonth = 1;
850 weeknum1 = MONTHCAL_CalculateDayOfWeek(&st, FALSE);
851 if ((infoPtr->firstDay - weeknum1) % 7 > mindays) weeknum++;
854 r = infoPtr->calendars[calIdx].weeknums;
856 /* erase whole week numbers area */
857 FillRect(hdc, &r, infoPtr->brushes[MCSC_MONTHBK]);
858 SetTextColor(hdc, infoPtr->colors[MCSC_TITLEBK]);
860 /* reduce rectangle to one week number */
861 r.bottom = r.top + infoPtr->height_increment;
863 for(i = 0; i < 6; i++) {
864 if((i == 0) && (weeknum > 50))
866 wsprintfW(buf, fmt_weekW, weeknum);
869 else if((i == 5) && (weeknum > 47))
871 wsprintfW(buf, fmt_weekW, 1);
874 wsprintfW(buf, fmt_weekW, weeknum + i);
876 DrawTextW(hdc, buf, -1, &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
877 OffsetRect(&r, 0, infoPtr->height_increment);
880 /* line separator for week numbers column */
881 MoveToEx(hdc, infoPtr->calendars[calIdx].weeknums.right, infoPtr->calendars[calIdx].weeknums.top + 3 , NULL);
882 LineTo(hdc, infoPtr->calendars[calIdx].weeknums.right, infoPtr->calendars[calIdx].weeknums.bottom);
885 /* bottom today date */
886 static void MONTHCAL_PaintTodayTitle(const MONTHCAL_INFO *infoPtr, HDC hdc, const PAINTSTRUCT *ps)
888 if(!(infoPtr->dwStyle & MCS_NOTODAY)) {
889 static const WCHAR todayW[] = { 'T','o','d','a','y',':',0 };
890 static const WCHAR fmt_todayW[] = { '%','s',' ','%','s',0 };
891 WCHAR buf_todayW[30], buf_dateW[20], buf[80];
894 if(!(infoPtr->dwStyle & MCS_NOTODAYCIRCLE)) {
897 MONTHCAL_GetMaxDate(infoPtr, &fake_st);
898 /* this is always safe cause next month will never fully fit calendar */
900 MONTHCAL_CircleDay(infoPtr, hdc, &fake_st);
902 if (!LoadStringW(COMCTL32_hModule, IDM_TODAY, buf_todayW, countof(buf_todayW)))
904 WARN("Can't load resource\n");
905 strcpyW(buf_todayW, todayW);
907 MONTHCAL_CalcDayRect(infoPtr, &rtoday, 1, 6);
908 GetDateFormatW(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &infoPtr->todaysDate, NULL,
909 buf_dateW, countof(buf_dateW));
910 SelectObject(hdc, infoPtr->hBoldFont);
912 wsprintfW(buf, fmt_todayW, buf_todayW, buf_dateW);
913 DrawTextW(hdc, buf, -1, &rtoday, DT_CALCRECT | DT_LEFT | DT_VCENTER | DT_SINGLELINE);
914 DrawTextW(hdc, buf, -1, &rtoday, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
916 SelectObject(hdc, infoPtr->hFont);
920 /* today mark + focus */
921 static void MONTHCAL_PaintFocusAndCircle(const MONTHCAL_INFO *infoPtr, HDC hdc, const PAINTSTRUCT *ps)
923 if((infoPtr->minSel.wMonth == infoPtr->todaysDate.wMonth) &&
924 (infoPtr->minSel.wYear == infoPtr->todaysDate.wYear) &&
925 !(infoPtr->dwStyle & MCS_NOTODAYCIRCLE))
927 MONTHCAL_CircleDay(infoPtr, hdc, &infoPtr->todaysDate);
930 if(!MONTHCAL_IsDateEqual(&infoPtr->focusedSel, &st_null))
933 MONTHCAL_CalcPosFromDay(infoPtr, &infoPtr->focusedSel, &r);
934 DrawFocusRect(hdc, &r);
938 /* months before first calendar month and after last calendar month */
939 static void MONTHCAL_PaintLeadTrailMonths(const MONTHCAL_INFO *infoPtr, HDC hdc, const PAINTSTRUCT *ps)
942 SYSTEMTIME st_max, st;
944 if (infoPtr->dwStyle & MCS_NOTRAILINGDATES) return;
946 SetTextColor(hdc, infoPtr->colors[MCSC_TRAILINGTEXT]);
948 /* draw prev month */
949 MONTHCAL_GetMinDate(infoPtr, &st);
950 mask = 1 << (st.wDay-1);
951 /* December and January both 31 days long, so no worries if wrapped */
952 length = MONTHCAL_MonthLength(infoPtr->calendars[0].month.wMonth - 1,
953 infoPtr->calendars[0].month.wYear);
954 while(st.wDay <= length)
956 MONTHCAL_DrawDay(infoPtr, hdc, &st, infoPtr->monthdayState[0] & mask, ps);
961 /* draw next month */
962 st = infoPtr->calendars[infoPtr->cal_num-1].month;
964 MONTHCAL_GetNextMonth(&st);
965 MONTHCAL_GetMaxDate(infoPtr, &st_max);
968 while(st.wDay <= st_max.wDay)
970 MONTHCAL_DrawDay(infoPtr, hdc, &st, infoPtr->monthdayState[2] & mask, ps);
976 /* paint a calendar area */
977 static void MONTHCAL_PaintCalendar(const MONTHCAL_INFO *infoPtr, HDC hdc, const PAINTSTRUCT *ps, INT calIdx)
979 const SYSTEMTIME *date = &infoPtr->calendars[calIdx].month;
980 INT prev_month, i, j, length;
981 RECT r, fill_bk_rect;
986 /* fill whole days area - from week days area to today note rectangle */
987 fill_bk_rect = infoPtr->calendars[calIdx].wdays;
988 fill_bk_rect.bottom = infoPtr->calendars[calIdx].days.bottom +
989 (infoPtr->todayrect.bottom - infoPtr->todayrect.top);
991 FillRect(hdc, &fill_bk_rect, infoPtr->brushes[MCSC_MONTHBK]);
993 /* draw line under day abbreviations */
994 MoveToEx(hdc, infoPtr->calendars[calIdx].days.left + 3,
995 infoPtr->calendars[calIdx].title.bottom + infoPtr->textHeight + 1, NULL);
996 LineTo(hdc, infoPtr->calendars[calIdx].days.right - 3,
997 infoPtr->calendars[calIdx].title.bottom + infoPtr->textHeight + 1);
999 prev_month = date->wMonth - 1;
1000 if (prev_month == 0) prev_month = 12;
1002 infoPtr->calendars[calIdx].wdays.left = infoPtr->calendars[calIdx].days.left =
1003 infoPtr->calendars[calIdx].weeknums.right;
1005 /* draw day abbreviations */
1006 SelectObject(hdc, infoPtr->hFont);
1007 SetBkColor(hdc, infoPtr->colors[MCSC_MONTHBK]);
1008 SetTextColor(hdc, infoPtr->colors[MCSC_TITLEBK]);
1009 /* rectangle to draw a single day abbreviation within */
1010 r = infoPtr->calendars[calIdx].wdays;
1011 r.right = r.left + infoPtr->width_increment;
1013 i = infoPtr->firstDay;
1014 for(j = 0; j < 7; j++) {
1015 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SABBREVDAYNAME1 + (i+j+6)%7, buf, countof(buf));
1016 DrawTextW(hdc, buf, strlenW(buf), &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
1017 OffsetRect(&r, infoPtr->width_increment, 0);
1020 /* draw current month */
1021 SetTextColor(hdc, infoPtr->colors[MCSC_TEXT]);
1025 length = MONTHCAL_MonthLength(date->wMonth, date->wYear);
1026 while(st.wDay <= length)
1028 MONTHCAL_DrawDay(infoPtr, hdc, &st, infoPtr->monthdayState[1] & mask, ps);
1034 static void MONTHCAL_Refresh(MONTHCAL_INFO *infoPtr, HDC hdc, const PAINTSTRUCT *ps)
1036 COLORREF old_text_clr, old_bk_clr;
1040 old_text_clr = SetTextColor(hdc, comctl32_color.clrWindowText);
1041 old_bk_clr = GetBkColor(hdc);
1042 old_font = GetCurrentObject(hdc, OBJ_FONT);
1044 for (i = 0; i < infoPtr->cal_num; i++)
1046 RECT *title = &infoPtr->calendars[i].title;
1049 /* draw title, redraw all its elements */
1050 if (IntersectRect(&r, &(ps->rcPaint), title))
1051 MONTHCAL_PaintTitle(infoPtr, hdc, ps, i);
1053 /* draw calendar area */
1054 UnionRect(&r, &infoPtr->calendars[i].wdays, &infoPtr->todayrect);
1055 if (IntersectRect(&r, &(ps->rcPaint), &r))
1056 MONTHCAL_PaintCalendar(infoPtr, hdc, ps, i);
1059 MONTHCAL_PaintWeeknumbers(infoPtr, hdc, ps, i);
1062 /* partially visible months */
1063 MONTHCAL_PaintLeadTrailMonths(infoPtr, hdc, ps);
1065 /* focus and today rectangle */
1066 MONTHCAL_PaintFocusAndCircle(infoPtr, hdc, ps);
1068 /* today at the bottom left */
1069 MONTHCAL_PaintTodayTitle(infoPtr, hdc, ps);
1071 /* navigation buttons */
1072 MONTHCAL_PaintButton(infoPtr, hdc, DIRECTION_BACKWARD);
1073 MONTHCAL_PaintButton(infoPtr, hdc, DIRECTION_FORWARD);
1075 /* restore context */
1076 SetBkColor(hdc, old_bk_clr);
1077 SelectObject(hdc, old_font);
1078 SetTextColor(hdc, old_text_clr);
1082 MONTHCAL_GetMinReqRect(const MONTHCAL_INFO *infoPtr, RECT *rect)
1084 TRACE("rect %p\n", rect);
1086 if(!rect) return FALSE;
1088 *rect = infoPtr->calendars[0].title;
1089 rect->bottom = infoPtr->calendars[0].days.bottom + infoPtr->todayrect.bottom -
1090 infoPtr->todayrect.top;
1092 AdjustWindowRect(rect, infoPtr->dwStyle, FALSE);
1094 /* minimal rectangle is zero based */
1095 OffsetRect(rect, -rect->left, -rect->top);
1097 TRACE("%s\n", wine_dbgstr_rect(rect));
1103 MONTHCAL_GetColor(const MONTHCAL_INFO *infoPtr, UINT index)
1105 TRACE("%p, %d\n", infoPtr, index);
1107 if (index > MCSC_TRAILINGTEXT) return -1;
1108 return infoPtr->colors[index];
1112 MONTHCAL_SetColor(MONTHCAL_INFO *infoPtr, UINT index, COLORREF color)
1116 TRACE("%p, %d: color %08x\n", infoPtr, index, color);
1118 if (index > MCSC_TRAILINGTEXT) return -1;
1120 prev = infoPtr->colors[index];
1121 infoPtr->colors[index] = color;
1123 /* update cached brush */
1124 if (index == MCSC_BACKGROUND || index == MCSC_TITLEBK || index == MCSC_MONTHBK)
1126 DeleteObject(infoPtr->brushes[index]);
1127 infoPtr->brushes[index] = CreateSolidBrush(color);
1130 InvalidateRect(infoPtr->hwndSelf, NULL, index == MCSC_BACKGROUND ? TRUE : FALSE);
1135 MONTHCAL_GetMonthDelta(const MONTHCAL_INFO *infoPtr)
1140 return infoPtr->delta;
1142 return infoPtr->visible;
1147 MONTHCAL_SetMonthDelta(MONTHCAL_INFO *infoPtr, INT delta)
1149 INT prev = infoPtr->delta;
1151 TRACE("delta %d\n", delta);
1153 infoPtr->delta = delta;
1158 static inline LRESULT
1159 MONTHCAL_GetFirstDayOfWeek(const MONTHCAL_INFO *infoPtr)
1163 /* convert from SYSTEMTIME to locale format */
1164 day = (infoPtr->firstDay >= 0) ? (infoPtr->firstDay+6)%7 : infoPtr->firstDay;
1166 return MAKELONG(day, infoPtr->firstDaySet);
1170 /* Sets the first day of the week that will appear in the control
1174 * [I] infoPtr : valid pointer to control data
1175 * [I] day : day number to set as new first day (0 == Monday,...,6 == Sunday)
1179 * Low word contains previous first day,
1180 * high word indicates was first day forced with this message before or is
1181 * locale difined (TRUE - was forced, FALSE - wasn't).
1183 * FIXME: this needs to be implemented properly in MONTHCAL_Refresh()
1184 * FIXME: we need more error checking here
1187 MONTHCAL_SetFirstDayOfWeek(MONTHCAL_INFO *infoPtr, INT day)
1189 LRESULT prev = MONTHCAL_GetFirstDayOfWeek(infoPtr);
1198 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_IFIRSTDAYOFWEEK, buf, countof(buf));
1199 TRACE("%s %d\n", debugstr_w(buf), strlenW(buf));
1201 new_day = atoiW(buf);
1203 infoPtr->firstDaySet = FALSE;
1207 new_day = 6; /* max first day allowed */
1208 infoPtr->firstDaySet = TRUE;
1212 /* Native behaviour for that case is broken: invalid date number >31
1213 got displayed at (0,0) position, current month starts always from
1214 (1,0) position. Should be implemented here as well only if there's
1215 nothing else to do. */
1217 FIXME("No bug compatibility for day=%d\n", day);
1220 infoPtr->firstDaySet = TRUE;
1223 /* convert from locale to SYSTEMTIME format */
1224 infoPtr->firstDay = (new_day >= 0) ? (++new_day) % 7 : new_day;
1226 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1233 MONTHCAL_GetMonthRange(const MONTHCAL_INFO *infoPtr, DWORD flag, SYSTEMTIME *st)
1235 TRACE("flag=%d, st=%p\n", flag, st);
1242 st[0] = infoPtr->calendars[0].month;
1243 st[1] = infoPtr->calendars[infoPtr->cal_num-1].month;
1245 if (st[0].wMonth == min_allowed_date.wMonth &&
1246 st[0].wYear == min_allowed_date.wYear)
1248 st[0].wDay = min_allowed_date.wDay;
1252 MONTHCAL_CalculateDayOfWeek(&st[0], TRUE);
1254 st[1].wDay = MONTHCAL_MonthLength(st[1].wMonth, st[1].wYear);
1255 MONTHCAL_CalculateDayOfWeek(&st[1], TRUE);
1257 return infoPtr->cal_num;
1261 MONTHCAL_GetMinDate(infoPtr, &st[0]);
1262 MONTHCAL_GetMaxDate(infoPtr, &st[1]);
1266 WARN("Unknown flag value, got %d\n", flag);
1270 return infoPtr->monthRange;
1275 MONTHCAL_GetMaxTodayWidth(const MONTHCAL_INFO *infoPtr)
1277 return(infoPtr->todayrect.right - infoPtr->todayrect.left);
1282 MONTHCAL_SetRange(MONTHCAL_INFO *infoPtr, SHORT limits, SYSTEMTIME *range)
1284 FILETIME ft_min, ft_max;
1286 TRACE("%x %p\n", limits, range);
1288 if ((limits & GDTR_MIN && !MONTHCAL_ValidateDate(&range[0])) ||
1289 (limits & GDTR_MAX && !MONTHCAL_ValidateDate(&range[1])))
1292 if (limits & GDTR_MIN)
1294 if (!MONTHCAL_ValidateTime(&range[0]))
1295 MONTHCAL_CopyTime(&infoPtr->todaysDate, &range[0]);
1297 infoPtr->minDate = range[0];
1298 infoPtr->rangeValid |= GDTR_MIN;
1300 if (limits & GDTR_MAX)
1302 if (!MONTHCAL_ValidateTime(&range[1]))
1303 MONTHCAL_CopyTime(&infoPtr->todaysDate, &range[1]);
1305 infoPtr->maxDate = range[1];
1306 infoPtr->rangeValid |= GDTR_MAX;
1309 /* Only one limit set - we are done */
1310 if ((infoPtr->rangeValid & (GDTR_MIN | GDTR_MAX)) != (GDTR_MIN | GDTR_MAX))
1313 SystemTimeToFileTime(&infoPtr->maxDate, &ft_max);
1314 SystemTimeToFileTime(&infoPtr->minDate, &ft_min);
1316 if (CompareFileTime(&ft_min, &ft_max) >= 0)
1318 if ((limits & (GDTR_MIN | GDTR_MAX)) == (GDTR_MIN | GDTR_MAX))
1320 /* Native swaps limits only when both limits are being set. */
1321 SYSTEMTIME st_tmp = infoPtr->minDate;
1322 infoPtr->minDate = infoPtr->maxDate;
1323 infoPtr->maxDate = st_tmp;
1327 /* reset the other limit */
1328 if (limits & GDTR_MIN) infoPtr->maxDate = st_null;
1329 if (limits & GDTR_MAX) infoPtr->minDate = st_null;
1330 infoPtr->rangeValid &= limits & GDTR_MIN ? ~GDTR_MAX : ~GDTR_MIN;
1339 MONTHCAL_GetRange(const MONTHCAL_INFO *infoPtr, SYSTEMTIME *range)
1341 TRACE("%p\n", range);
1343 if(!range) return FALSE;
1345 range[1] = infoPtr->maxDate;
1346 range[0] = infoPtr->minDate;
1348 return infoPtr->rangeValid;
1353 MONTHCAL_SetDayState(const MONTHCAL_INFO *infoPtr, INT months, MONTHDAYSTATE *states)
1355 TRACE("%p %d %p\n", infoPtr, months, states);
1356 if(months != infoPtr->monthRange) return 0;
1358 memcpy(infoPtr->monthdayState, states, months*sizeof(MONTHDAYSTATE));
1364 MONTHCAL_GetCurSel(const MONTHCAL_INFO *infoPtr, SYSTEMTIME *curSel)
1366 TRACE("%p\n", curSel);
1367 if(!curSel) return FALSE;
1368 if(infoPtr->dwStyle & MCS_MULTISELECT) return FALSE;
1370 *curSel = infoPtr->minSel;
1371 TRACE("%d/%d/%d\n", curSel->wYear, curSel->wMonth, curSel->wDay);
1376 MONTHCAL_SetCurSel(MONTHCAL_INFO *infoPtr, SYSTEMTIME *curSel)
1378 SYSTEMTIME prev = infoPtr->minSel;
1381 TRACE("%p\n", curSel);
1382 if(!curSel) return FALSE;
1383 if(infoPtr->dwStyle & MCS_MULTISELECT) return FALSE;
1385 if(!MONTHCAL_ValidateDate(curSel)) return FALSE;
1386 /* exit earlier if selection equals current */
1387 if (MONTHCAL_IsDateEqual(&infoPtr->minSel, curSel)) return TRUE;
1389 if(!MONTHCAL_IsDateInValidRange(infoPtr, curSel, FALSE)) return FALSE;
1391 infoPtr->calendars[0].month = *curSel;
1392 infoPtr->minSel = *curSel;
1393 infoPtr->maxSel = *curSel;
1395 /* if selection is still in current month, reduce rectangle */
1397 prev.wDay = curSel->wDay;
1398 if (MONTHCAL_IsDateEqual(&prev, curSel))
1403 MONTHCAL_CalcPosFromDay(infoPtr, &prev, &r_prev);
1404 MONTHCAL_CalcPosFromDay(infoPtr, curSel, &r_new);
1406 InvalidateRect(infoPtr->hwndSelf, &r_prev, FALSE);
1407 InvalidateRect(infoPtr->hwndSelf, &r_new, FALSE);
1410 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1417 MONTHCAL_GetMaxSelCount(const MONTHCAL_INFO *infoPtr)
1419 return infoPtr->maxSelCount;
1424 MONTHCAL_SetMaxSelCount(MONTHCAL_INFO *infoPtr, INT max)
1428 if(!(infoPtr->dwStyle & MCS_MULTISELECT)) return FALSE;
1429 if(max <= 0) return FALSE;
1431 infoPtr->maxSelCount = max;
1438 MONTHCAL_GetSelRange(const MONTHCAL_INFO *infoPtr, SYSTEMTIME *range)
1440 TRACE("%p\n", range);
1442 if(!range) return FALSE;
1444 if(infoPtr->dwStyle & MCS_MULTISELECT)
1446 range[1] = infoPtr->maxSel;
1447 range[0] = infoPtr->minSel;
1448 TRACE("[min,max]=[%d %d]\n", infoPtr->minSel.wDay, infoPtr->maxSel.wDay);
1457 MONTHCAL_SetSelRange(MONTHCAL_INFO *infoPtr, SYSTEMTIME *range)
1459 TRACE("%p\n", range);
1461 if(!range) return FALSE;
1463 if(infoPtr->dwStyle & MCS_MULTISELECT)
1465 SYSTEMTIME old_range[2];
1467 /* adjust timestamps */
1468 if(!MONTHCAL_ValidateTime(&range[0]))
1469 MONTHCAL_CopyTime(&infoPtr->todaysDate, &range[0]);
1470 if(!MONTHCAL_ValidateTime(&range[1]))
1471 MONTHCAL_CopyTime(&infoPtr->todaysDate, &range[1]);
1473 /* maximum range exceeded */
1474 if(!MONTHCAL_IsSelRangeValid(infoPtr, &range[0], &range[1], NULL)) return FALSE;
1476 old_range[0] = infoPtr->minSel;
1477 old_range[1] = infoPtr->maxSel;
1479 /* swap if min > max */
1480 if(MONTHCAL_CompareSystemTime(&range[0], &range[1]) <= 0)
1482 infoPtr->minSel = range[0];
1483 infoPtr->maxSel = range[1];
1487 infoPtr->minSel = range[1];
1488 infoPtr->maxSel = range[0];
1490 infoPtr->calendars[0].month = infoPtr->minSel;
1492 /* update day of week */
1493 MONTHCAL_CalculateDayOfWeek(&infoPtr->minSel, TRUE);
1494 MONTHCAL_CalculateDayOfWeek(&infoPtr->maxSel, TRUE);
1496 /* redraw if bounds changed */
1497 /* FIXME: no actual need to redraw everything */
1498 if(!MONTHCAL_IsDateEqual(&old_range[0], &range[0]) ||
1499 !MONTHCAL_IsDateEqual(&old_range[1], &range[1]))
1501 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1504 TRACE("[min,max]=[%d %d]\n", infoPtr->minSel.wDay, infoPtr->maxSel.wDay);
1513 MONTHCAL_GetToday(const MONTHCAL_INFO *infoPtr, SYSTEMTIME *today)
1515 TRACE("%p\n", today);
1517 if(!today) return FALSE;
1518 *today = infoPtr->todaysDate;
1522 /* Internal helper for MCM_SETTODAY handler and auto update timer handler
1526 * TRUE - today date changed
1527 * FALSE - today date isn't changed
1530 MONTHCAL_UpdateToday(MONTHCAL_INFO *infoPtr, const SYSTEMTIME *today)
1534 if(MONTHCAL_IsDateEqual(today, &infoPtr->todaysDate)) return FALSE;
1536 MONTHCAL_CalcPosFromDay(infoPtr, &infoPtr->todaysDate, &old_r);
1537 MONTHCAL_CalcPosFromDay(infoPtr, today, &new_r);
1539 infoPtr->todaysDate = *today;
1541 /* only two days need redrawing */
1542 InvalidateRect(infoPtr->hwndSelf, &old_r, FALSE);
1543 InvalidateRect(infoPtr->hwndSelf, &new_r, FALSE);
1547 /* MCM_SETTODAT handler */
1549 MONTHCAL_SetToday(MONTHCAL_INFO *infoPtr, const SYSTEMTIME *today)
1551 TRACE("%p\n", today);
1553 if(!today) return FALSE;
1555 /* remember if date was set successfully */
1556 if(MONTHCAL_UpdateToday(infoPtr, today)) infoPtr->todaySet = TRUE;
1561 /* returns calendar index containing specified point, or -1 if it's background */
1562 static INT MONTHCAL_GetCalendarFromPoint(const MONTHCAL_INFO *infoPtr, const POINT *pt)
1567 for (i = 0; i < infoPtr->cal_num; i++)
1569 /* whole bounding rectangle allows some optimization to compute */
1570 r.left = infoPtr->calendars[i].title.left;
1571 r.top = infoPtr->calendars[i].title.top;
1572 r.bottom = infoPtr->calendars[i].days.bottom;
1573 r.right = infoPtr->calendars[i].days.right;
1575 if (PtInRect(&r, *pt)) return i;
1581 static inline UINT fill_hittest_info(const MCHITTESTINFO *src, MCHITTESTINFO *dest)
1583 dest->uHit = src->uHit;
1586 if (dest->cbSize == sizeof(MCHITTESTINFO))
1587 memcpy(&dest->rc, &src->rc, sizeof(MCHITTESTINFO) - MCHITTESTINFO_V1_SIZE);
1593 MONTHCAL_HitTest(const MONTHCAL_INFO *infoPtr, MCHITTESTINFO *lpht)
1595 INT day, wday, wnum, calIdx;
1596 MCHITTESTINFO htinfo;
1597 SYSTEMTIME ht_month;
1600 if(!lpht || lpht->cbSize < MCHITTESTINFO_V1_SIZE) return -1;
1605 htinfo.st = st_null;
1607 /* we should preserve passed fields if hit area doesn't need them */
1608 if (lpht->cbSize == sizeof(MCHITTESTINFO))
1609 memcpy(&htinfo.rc, &lpht->rc, sizeof(MCHITTESTINFO) - MCHITTESTINFO_V1_SIZE);
1611 /* Comment in for debugging...
1612 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,
1613 infoPtr->wdays.left, infoPtr->wdays.right,
1614 infoPtr->wdays.top, infoPtr->wdays.bottom,
1615 infoPtr->days.left, infoPtr->days.right,
1616 infoPtr->days.top, infoPtr->days.bottom,
1617 infoPtr->todayrect.left, infoPtr->todayrect.right,
1618 infoPtr->todayrect.top, infoPtr->todayrect.bottom,
1619 infoPtr->weeknums.left, infoPtr->weeknums.right,
1620 infoPtr->weeknums.top, infoPtr->weeknums.bottom);
1623 /* guess in what calendar we are */
1624 calIdx = MONTHCAL_GetCalendarFromPoint(infoPtr, &lpht->pt);
1627 if (PtInRect(&infoPtr->todayrect, lpht->pt))
1629 htinfo.uHit = MCHT_TODAYLINK;
1630 htinfo.rc = infoPtr->todayrect;
1633 /* outside of calendar area? What's left must be background :-) */
1634 htinfo.uHit = MCHT_CALENDARBK;
1636 return fill_hittest_info(&htinfo, lpht);
1639 ht_month = infoPtr->calendars[calIdx].month;
1641 /* are we in the header? */
1642 if (PtInRect(&infoPtr->calendars[calIdx].title, lpht->pt)) {
1643 /* FIXME: buttons hittesting could be optimized cause maximum
1644 two calendars have buttons */
1645 if (calIdx == 0 && PtInRect(&infoPtr->titlebtnprev, lpht->pt))
1647 htinfo.uHit = MCHT_TITLEBTNPREV;
1648 htinfo.rc = infoPtr->titlebtnprev;
1650 else if (PtInRect(&infoPtr->titlebtnnext, lpht->pt))
1652 htinfo.uHit = MCHT_TITLEBTNNEXT;
1653 htinfo.rc = infoPtr->titlebtnnext;
1655 else if (PtInRect(&infoPtr->calendars[calIdx].titlemonth, lpht->pt))
1657 htinfo.uHit = MCHT_TITLEMONTH;
1658 htinfo.rc = infoPtr->calendars[calIdx].titlemonth;
1659 htinfo.iOffset = calIdx;
1661 else if (PtInRect(&infoPtr->calendars[calIdx].titleyear, lpht->pt))
1663 htinfo.uHit = MCHT_TITLEYEAR;
1664 htinfo.rc = infoPtr->calendars[calIdx].titleyear;
1665 htinfo.iOffset = calIdx;
1669 htinfo.uHit = MCHT_TITLE;
1670 htinfo.rc = infoPtr->calendars[calIdx].title;
1671 htinfo.iOffset = calIdx;
1674 return fill_hittest_info(&htinfo, lpht);
1677 /* days area (including week days and week numbers */
1678 day = MONTHCAL_CalcDayFromPos(infoPtr, x, y, &wday, &wnum);
1679 if (PtInRect(&infoPtr->calendars[calIdx].wdays, lpht->pt))
1681 htinfo.uHit = MCHT_CALENDARDAY;
1682 htinfo.iOffset = calIdx;
1683 htinfo.st.wYear = ht_month.wYear;
1684 htinfo.st.wMonth = (day < 1) ? ht_month.wMonth -1 : ht_month.wMonth;
1685 htinfo.st.wDay = (day < 1) ?
1686 MONTHCAL_MonthLength(ht_month.wMonth-1, ht_month.wYear) - day : day;
1688 MONTHCAL_CalcDayXY(infoPtr, &htinfo.st, &htinfo.iCol, &htinfo.iRow);
1690 else if(PtInRect(&infoPtr->calendars[calIdx].weeknums, lpht->pt))
1692 htinfo.uHit = MCHT_CALENDARWEEKNUM;
1693 htinfo.st.wYear = ht_month.wYear;
1694 htinfo.iOffset = calIdx;
1698 htinfo.st.wMonth = ht_month.wMonth - 1;
1699 htinfo.st.wDay = MONTHCAL_MonthLength(ht_month.wMonth-1, ht_month.wYear) - day;
1701 else if (day > MONTHCAL_MonthLength(ht_month.wMonth, ht_month.wYear))
1703 htinfo.st.wMonth = ht_month.wMonth + 1;
1704 htinfo.st.wDay = day - MONTHCAL_MonthLength(ht_month.wMonth, ht_month.wYear);
1708 htinfo.st.wMonth = ht_month.wMonth;
1709 htinfo.st.wDay = day;
1712 else if(PtInRect(&infoPtr->calendars[calIdx].days, lpht->pt))
1714 htinfo.iOffset = calIdx;
1715 htinfo.st.wYear = ht_month.wYear;
1716 htinfo.st.wMonth = ht_month.wMonth;
1719 htinfo.uHit = MCHT_CALENDARDATEPREV;
1720 MONTHCAL_GetPrevMonth(&htinfo.st);
1721 htinfo.st.wDay = MONTHCAL_MonthLength(htinfo.st.wMonth, htinfo.st.wYear) + day;
1723 else if (day > MONTHCAL_MonthLength(ht_month.wMonth, ht_month.wYear))
1725 htinfo.uHit = MCHT_CALENDARDATENEXT;
1726 MONTHCAL_GetNextMonth(&htinfo.st);
1727 htinfo.st.wDay = day - MONTHCAL_MonthLength(ht_month.wMonth, ht_month.wYear);
1731 htinfo.uHit = MCHT_CALENDARDATE;
1732 htinfo.st.wDay = day;
1735 MONTHCAL_CalcDayXY(infoPtr, &htinfo.st, &htinfo.iCol, &htinfo.iRow);
1736 MONTHCAL_CalcDayRect(infoPtr, &htinfo.rc, htinfo.iCol, htinfo.iRow);
1737 /* always update day of week */
1738 MONTHCAL_CalculateDayOfWeek(&htinfo.st, TRUE);
1741 return fill_hittest_info(&htinfo, lpht);
1744 /* MCN_GETDAYSTATE notification helper */
1745 static void MONTHCAL_NotifyDayState(MONTHCAL_INFO *infoPtr)
1747 if(infoPtr->dwStyle & MCS_DAYSTATE) {
1750 nmds.nmhdr.hwndFrom = infoPtr->hwndSelf;
1751 nmds.nmhdr.idFrom = GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_ID);
1752 nmds.nmhdr.code = MCN_GETDAYSTATE;
1753 nmds.cDayState = infoPtr->monthRange;
1754 nmds.prgDayState = Alloc(infoPtr->monthRange * sizeof(MONTHDAYSTATE));
1756 nmds.stStart = infoPtr->todaysDate;
1757 nmds.stStart.wYear = infoPtr->minSel.wYear;
1758 nmds.stStart.wMonth = infoPtr->minSel.wMonth;
1759 nmds.stStart.wDay = 1;
1761 SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, nmds.nmhdr.idFrom, (LPARAM)&nmds);
1762 memcpy(infoPtr->monthdayState, nmds.prgDayState, infoPtr->monthRange*sizeof(MONTHDAYSTATE));
1764 Free(nmds.prgDayState);
1768 /* no valid range check performed */
1769 static void MONTHCAL_Scroll(MONTHCAL_INFO *infoPtr, INT delta)
1773 for(i = 0; i < infoPtr->cal_num; i++)
1775 /* save selection position to shift it later */
1776 if (selIdx == -1 && MONTHCAL_CompareMonths(&infoPtr->minSel, &infoPtr->calendars[i].month) == 0)
1779 MONTHCAL_GetMonth(&infoPtr->calendars[i].month, delta);
1782 /* selection is always shifted to first calendar */
1783 if(infoPtr->dwStyle & MCS_MULTISELECT)
1785 SYSTEMTIME range[2];
1787 MONTHCAL_GetSelRange(infoPtr, range);
1788 MONTHCAL_GetMonth(&range[0], delta - selIdx);
1789 MONTHCAL_GetMonth(&range[1], delta - selIdx);
1790 MONTHCAL_SetSelRange(infoPtr, range);
1794 SYSTEMTIME st = infoPtr->minSel;
1796 MONTHCAL_GetMonth(&st, delta - selIdx);
1797 MONTHCAL_SetCurSel(infoPtr, &st);
1801 static void MONTHCAL_GoToMonth(MONTHCAL_INFO *infoPtr, enum nav_direction direction)
1803 INT delta = infoPtr->delta ? infoPtr->delta : infoPtr->cal_num;
1806 TRACE("%s\n", direction == DIRECTION_BACKWARD ? "back" : "fwd");
1808 /* check if change allowed by range set */
1809 if(direction == DIRECTION_BACKWARD)
1811 st = infoPtr->calendars[0].month;
1812 MONTHCAL_GetMonth(&st, -delta);
1816 st = infoPtr->calendars[infoPtr->cal_num-1].month;
1817 MONTHCAL_GetMonth(&st, delta);
1820 if(!MONTHCAL_IsDateInValidRange(infoPtr, &st, FALSE)) return;
1822 MONTHCAL_Scroll(infoPtr, direction == DIRECTION_BACKWARD ? -delta : delta);
1823 MONTHCAL_NotifyDayState(infoPtr);
1824 MONTHCAL_NotifySelectionChange(infoPtr);
1828 MONTHCAL_RButtonUp(MONTHCAL_INFO *infoPtr, LPARAM lParam)
1830 static const WCHAR todayW[] = { 'G','o',' ','t','o',' ','T','o','d','a','y',':',0 };
1835 hMenu = CreatePopupMenu();
1836 if (!LoadStringW(COMCTL32_hModule, IDM_GOTODAY, buf, countof(buf)))
1838 WARN("Can't load resource\n");
1839 strcpyW(buf, todayW);
1841 AppendMenuW(hMenu, MF_STRING|MF_ENABLED, 1, buf);
1842 menupoint.x = (short)LOWORD(lParam);
1843 menupoint.y = (short)HIWORD(lParam);
1844 ClientToScreen(infoPtr->hwndSelf, &menupoint);
1845 if( TrackPopupMenu(hMenu, TPM_RIGHTBUTTON | TPM_NONOTIFY | TPM_RETURNCMD,
1846 menupoint.x, menupoint.y, 0, infoPtr->hwndSelf, NULL))
1848 infoPtr->calendars[0].month = infoPtr->todaysDate;
1849 infoPtr->minSel = infoPtr->todaysDate;
1850 infoPtr->maxSel = infoPtr->todaysDate;
1851 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1859 * Subclassed edit control windproc function
1862 * [I] hwnd : the edit window handle
1863 * [I] uMsg : the message that is to be processed
1864 * [I] wParam : first message parameter
1865 * [I] lParam : second message parameter
1868 static LRESULT CALLBACK EditWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1870 MONTHCAL_INFO *infoPtr = (MONTHCAL_INFO *)GetWindowLongPtrW(GetParent(hwnd), 0);
1872 TRACE("(hwnd=%p, uMsg=%x, wParam=%lx, lParam=%lx)\n",
1873 hwnd, uMsg, wParam, lParam);
1878 return DLGC_WANTARROWS | DLGC_WANTALLKEYS;
1882 WNDPROC editProc = infoPtr->EditWndProc;
1883 infoPtr->EditWndProc = NULL;
1884 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (DWORD_PTR)editProc);
1885 return CallWindowProcW(editProc, hwnd, uMsg, wParam, lParam);
1892 if ((VK_ESCAPE == (INT)wParam) || (VK_RETURN == (INT)wParam))
1896 return CallWindowProcW(infoPtr->EditWndProc, hwnd, uMsg, wParam, lParam);
1899 SendMessageW(infoPtr->hWndYearUpDown, WM_CLOSE, 0, 0);
1900 SendMessageW(hwnd, WM_CLOSE, 0, 0);
1904 /* creates updown control and edit box */
1905 static void MONTHCAL_EditYear(MONTHCAL_INFO *infoPtr, INT calIdx)
1907 RECT *rc = &infoPtr->calendars[calIdx].titleyear;
1908 RECT *title = &infoPtr->calendars[calIdx].title;
1910 infoPtr->hWndYearEdit =
1911 CreateWindowExW(0, WC_EDITW, 0, WS_VISIBLE | WS_CHILD | ES_READONLY,
1912 rc->left + 3, (title->bottom + title->top - infoPtr->textHeight) / 2,
1913 rc->right - rc->left + 4,
1914 infoPtr->textHeight, infoPtr->hwndSelf,
1917 SendMessageW(infoPtr->hWndYearEdit, WM_SETFONT, (WPARAM)infoPtr->hBoldFont, TRUE);
1919 infoPtr->hWndYearUpDown =
1920 CreateWindowExW(0, UPDOWN_CLASSW, 0,
1921 WS_VISIBLE | WS_CHILD | UDS_SETBUDDYINT | UDS_NOTHOUSANDS | UDS_ARROWKEYS,
1922 rc->right + 7, (title->bottom + title->top - infoPtr->textHeight) / 2,
1923 18, infoPtr->textHeight, infoPtr->hwndSelf,
1926 /* attach edit box */
1927 SendMessageW(infoPtr->hWndYearUpDown, UDM_SETRANGE, 0,
1928 MAKELONG(max_allowed_date.wYear, min_allowed_date.wYear));
1929 SendMessageW(infoPtr->hWndYearUpDown, UDM_SETBUDDY, (WPARAM)infoPtr->hWndYearEdit, 0);
1930 SendMessageW(infoPtr->hWndYearUpDown, UDM_SETPOS, 0, infoPtr->calendars[calIdx].month.wYear);
1932 /* subclass edit box */
1933 infoPtr->EditWndProc = (WNDPROC)SetWindowLongPtrW(infoPtr->hWndYearEdit,
1934 GWLP_WNDPROC, (DWORD_PTR)EditWndProc);
1936 SetFocus(infoPtr->hWndYearEdit);
1940 MONTHCAL_LButtonDown(MONTHCAL_INFO *infoPtr, LPARAM lParam)
1945 /* Actually we don't need input focus for calendar, this is used to kill
1946 year updown and its buddy edit box */
1947 if (IsWindow(infoPtr->hWndYearUpDown))
1949 SetFocus(infoPtr->hwndSelf);
1953 SetCapture(infoPtr->hwndSelf);
1955 ht.cbSize = sizeof(MCHITTESTINFO);
1956 ht.pt.x = (short)LOWORD(lParam);
1957 ht.pt.y = (short)HIWORD(lParam);
1959 hit = MONTHCAL_HitTest(infoPtr, &ht);
1961 TRACE("%x at (%d, %d)\n", hit, ht.pt.x, ht.pt.y);
1965 case MCHT_TITLEBTNNEXT:
1966 MONTHCAL_GoToMonth(infoPtr, DIRECTION_FORWARD);
1967 infoPtr->status = MC_NEXTPRESSED;
1968 SetTimer(infoPtr->hwndSelf, MC_PREVNEXTMONTHTIMER, MC_PREVNEXTMONTHDELAY, 0);
1969 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1972 case MCHT_TITLEBTNPREV:
1973 MONTHCAL_GoToMonth(infoPtr, DIRECTION_BACKWARD);
1974 infoPtr->status = MC_PREVPRESSED;
1975 SetTimer(infoPtr->hwndSelf, MC_PREVNEXTMONTHTIMER, MC_PREVNEXTMONTHDELAY, 0);
1976 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1979 case MCHT_TITLEMONTH:
1981 HMENU hMenu = CreatePopupMenu();
1986 for (i = 0; i < 12; i++)
1988 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SMONTHNAME1+i, buf, countof(buf));
1989 AppendMenuW(hMenu, MF_STRING|MF_ENABLED, i + 1, buf);
1991 menupoint.x = ht.pt.x;
1992 menupoint.y = ht.pt.y;
1993 ClientToScreen(infoPtr->hwndSelf, &menupoint);
1994 i = TrackPopupMenu(hMenu,TPM_LEFTALIGN | TPM_NONOTIFY | TPM_RIGHTBUTTON | TPM_RETURNCMD,
1995 menupoint.x, menupoint.y, 0, infoPtr->hwndSelf, NULL);
1997 if ((i > 0) && (i < 13) && infoPtr->calendars[ht.iOffset].month.wMonth != i)
1999 INT delta = i - infoPtr->calendars[ht.iOffset].month.wMonth;
2002 /* check if change allowed by range set */
2003 st = delta < 0 ? infoPtr->calendars[0].month :
2004 infoPtr->calendars[infoPtr->cal_num-1].month;
2005 MONTHCAL_GetMonth(&st, delta);
2007 if (MONTHCAL_IsDateInValidRange(infoPtr, &st, FALSE))
2009 MONTHCAL_Scroll(infoPtr, delta);
2010 MONTHCAL_NotifyDayState(infoPtr);
2011 MONTHCAL_NotifySelectionChange(infoPtr);
2012 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
2017 case MCHT_TITLEYEAR:
2019 MONTHCAL_EditYear(infoPtr, ht.iOffset);
2022 case MCHT_TODAYLINK:
2024 infoPtr->calendars[0].month = infoPtr->todaysDate;
2025 infoPtr->minSel = infoPtr->todaysDate;
2026 infoPtr->maxSel = infoPtr->todaysDate;
2027 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
2029 MONTHCAL_NotifySelectionChange(infoPtr);
2030 MONTHCAL_NotifySelect(infoPtr);
2033 case MCHT_CALENDARDATENEXT:
2034 case MCHT_CALENDARDATEPREV:
2035 case MCHT_CALENDARDATE:
2039 MONTHCAL_CopyDate(&ht.st, &infoPtr->firstSel);
2041 st[0] = st[1] = ht.st;
2042 /* clear selection range */
2043 MONTHCAL_SetSelRange(infoPtr, st);
2045 infoPtr->status = MC_SEL_LBUTDOWN;
2046 MONTHCAL_SetDayFocus(infoPtr, &ht.st);
2056 MONTHCAL_LButtonUp(MONTHCAL_INFO *infoPtr, LPARAM lParam)
2064 if(infoPtr->status & (MC_PREVPRESSED | MC_NEXTPRESSED)) {
2067 KillTimer(infoPtr->hwndSelf, MC_PREVNEXTMONTHTIMER);
2068 r = infoPtr->status & MC_PREVPRESSED ? &infoPtr->titlebtnprev : &infoPtr->titlebtnnext;
2069 infoPtr->status &= ~(MC_PREVPRESSED | MC_NEXTPRESSED);
2071 InvalidateRect(infoPtr->hwndSelf, r, FALSE);
2076 /* always send NM_RELEASEDCAPTURE notification */
2077 nmhdr.hwndFrom = infoPtr->hwndSelf;
2078 nmhdr.idFrom = GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_ID);
2079 nmhdr.code = NM_RELEASEDCAPTURE;
2080 TRACE("Sent notification from %p to %p\n", infoPtr->hwndSelf, infoPtr->hwndNotify);
2082 SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, nmhdr.idFrom, (LPARAM)&nmhdr);
2084 if(!(infoPtr->status & MC_SEL_LBUTDOWN)) return 0;
2086 ht.cbSize = sizeof(MCHITTESTINFO);
2087 ht.pt.x = (short)LOWORD(lParam);
2088 ht.pt.y = (short)HIWORD(lParam);
2089 hit = MONTHCAL_HitTest(infoPtr, &ht);
2091 infoPtr->status = MC_SEL_LBUTUP;
2092 MONTHCAL_SetDayFocus(infoPtr, NULL);
2094 if((hit & MCHT_CALENDARDATE) == MCHT_CALENDARDATE)
2096 SYSTEMTIME sel = infoPtr->minSel;
2098 /* will be invalidated here */
2099 MONTHCAL_SetCurSel(infoPtr, &ht.st);
2101 /* send MCN_SELCHANGE only if new date selected */
2102 if (!MONTHCAL_IsDateEqual(&sel, &ht.st))
2103 MONTHCAL_NotifySelectionChange(infoPtr);
2105 MONTHCAL_NotifySelect(infoPtr);
2113 MONTHCAL_Timer(MONTHCAL_INFO *infoPtr, WPARAM id)
2118 case MC_PREVNEXTMONTHTIMER:
2119 if(infoPtr->status & MC_NEXTPRESSED) MONTHCAL_GoToMonth(infoPtr, DIRECTION_FORWARD);
2120 if(infoPtr->status & MC_PREVPRESSED) MONTHCAL_GoToMonth(infoPtr, DIRECTION_BACKWARD);
2121 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
2123 case MC_TODAYUPDATETIMER:
2127 if(infoPtr->todaySet) return 0;
2130 MONTHCAL_UpdateToday(infoPtr, &st);
2132 /* notification sent anyway */
2133 MONTHCAL_NotifySelectionChange(infoPtr);
2138 ERR("got unknown timer %ld\n", id);
2147 MONTHCAL_MouseMove(MONTHCAL_INFO *infoPtr, LPARAM lParam)
2154 if(!(infoPtr->status & MC_SEL_LBUTDOWN)) return 0;
2156 ht.cbSize = sizeof(MCHITTESTINFO);
2157 ht.pt.x = (short)LOWORD(lParam);
2158 ht.pt.y = (short)HIWORD(lParam);
2160 hit = MONTHCAL_HitTest(infoPtr, &ht);
2162 /* not on the calendar date numbers? bail out */
2163 TRACE("hit:%x\n",hit);
2164 if((hit & MCHT_CALENDARDATE) != MCHT_CALENDARDATE)
2166 MONTHCAL_SetDayFocus(infoPtr, NULL);
2172 /* if pointer is over focused day still there's nothing to do */
2173 if(!MONTHCAL_SetDayFocus(infoPtr, &ht.st)) return 0;
2175 MONTHCAL_CalcPosFromDay(infoPtr, &ht.st, &r);
2177 if(infoPtr->dwStyle & MCS_MULTISELECT) {
2180 MONTHCAL_GetSelRange(infoPtr, st);
2182 /* If we're still at the first selected date and range is empty, return.
2183 If range isn't empty we should change range to a single firstSel */
2184 if(MONTHCAL_IsDateEqual(&infoPtr->firstSel, &st_ht) &&
2185 MONTHCAL_IsDateEqual(&st[0], &st[1])) goto done;
2187 MONTHCAL_IsSelRangeValid(infoPtr, &st_ht, &infoPtr->firstSel, &st_ht);
2189 st[0] = infoPtr->firstSel;
2190 /* we should overwrite timestamp here */
2191 MONTHCAL_CopyDate(&st_ht, &st[1]);
2193 /* bounds will be swapped here if needed */
2194 MONTHCAL_SetSelRange(infoPtr, st);
2201 /* FIXME: this should specify a rectangle containing only the days that changed
2202 using InvalidateRect */
2203 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
2210 MONTHCAL_Paint(MONTHCAL_INFO *infoPtr, HDC hdc_paint)
2217 GetClientRect(infoPtr->hwndSelf, &ps.rcPaint);
2221 hdc = BeginPaint(infoPtr->hwndSelf, &ps);
2223 MONTHCAL_Refresh(infoPtr, hdc, &ps);
2224 if (!hdc_paint) EndPaint(infoPtr->hwndSelf, &ps);
2229 MONTHCAL_EraseBkgnd(const MONTHCAL_INFO *infoPtr, HDC hdc)
2233 if (!GetClipBox(hdc, &rc)) return FALSE;
2235 /* fill background */
2236 FillRect(hdc, &rc, infoPtr->brushes[MCSC_BACKGROUND]);
2242 MONTHCAL_PrintClient(MONTHCAL_INFO *infoPtr, HDC hdc, DWORD options)
2244 FIXME("Partial Stub: (hdc=%p options=0x%08x)\n", hdc, options);
2246 if ((options & PRF_CHECKVISIBLE) && !IsWindowVisible(infoPtr->hwndSelf))
2249 if (options & PRF_ERASEBKGND)
2250 MONTHCAL_EraseBkgnd(infoPtr, hdc);
2252 if (options & PRF_CLIENT)
2253 MONTHCAL_Paint(infoPtr, hdc);
2259 MONTHCAL_SetFocus(const MONTHCAL_INFO *infoPtr)
2263 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
2268 /* sets the size information */
2269 static void MONTHCAL_UpdateSize(MONTHCAL_INFO *infoPtr)
2271 static const WCHAR O0W[] = { '0','0',0 };
2272 HDC hdc = GetDC(infoPtr->hwndSelf);
2273 RECT *title=&infoPtr->calendars[0].title;
2274 RECT *prev=&infoPtr->titlebtnprev;
2275 RECT *next=&infoPtr->titlebtnnext;
2276 RECT *titlemonth=&infoPtr->calendars[0].titlemonth;
2277 RECT *titleyear=&infoPtr->calendars[0].titleyear;
2278 RECT *wdays=&infoPtr->calendars[0].wdays;
2279 RECT *weeknumrect=&infoPtr->calendars[0].weeknums;
2280 RECT *days=&infoPtr->calendars[0].days;
2281 RECT *todayrect=&infoPtr->todayrect;
2285 INT xdiv, dx, dy, i;
2289 GetClientRect(infoPtr->hwndSelf, &rcClient);
2291 currentFont = SelectObject(hdc, infoPtr->hFont);
2293 /* get the height and width of each day's text */
2294 GetTextMetricsW(hdc, &tm);
2295 infoPtr->textHeight = tm.tmHeight + tm.tmExternalLeading + tm.tmInternalLeading;
2297 /* find largest abbreviated day name for current locale */
2298 size.cx = sz.cx = 0;
2299 for (i = 0; i < 7; i++)
2301 if(GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SABBREVDAYNAME1 + i,
2302 buff, countof(buff)))
2304 GetTextExtentPoint32W(hdc, buff, lstrlenW(buff), &sz);
2305 if (sz.cx > size.cx) size.cx = sz.cx;
2307 else /* locale independent fallback on failure */
2309 static const WCHAR SunW[] = { 'S','u','n',0 };
2311 GetTextExtentPoint32W(hdc, SunW, lstrlenW(SunW), &size);
2316 infoPtr->textWidth = size.cx + 2;
2318 /* recalculate the height and width increments and offsets */
2319 GetTextExtentPoint32W(hdc, O0W, 2, &size);
2321 xdiv = (infoPtr->dwStyle & MCS_WEEKNUMBERS) ? 8 : 7;
2323 infoPtr->width_increment = size.cx * 2 + 4;
2324 infoPtr->height_increment = infoPtr->textHeight;
2326 /* calculate title area */
2328 title->bottom = 3 * infoPtr->height_increment / 2;
2330 title->right = infoPtr->width_increment * xdiv;
2332 /* set the dimensions of the next and previous buttons and center */
2333 /* the month text vertically */
2334 prev->top = next->top = title->top + 4;
2335 prev->bottom = next->bottom = title->bottom - 4;
2336 prev->left = title->left + 4;
2337 prev->right = prev->left + (title->bottom - title->top);
2338 next->right = title->right - 4;
2339 next->left = next->right - (title->bottom - title->top);
2341 /* titlemonth->left and right change based upon the current month */
2342 /* and are recalculated in refresh as the current month may change */
2343 /* without the control being resized */
2344 titlemonth->top = titleyear->top = title->top + (infoPtr->height_increment)/2;
2345 titlemonth->bottom = titleyear->bottom = title->bottom - (infoPtr->height_increment)/2;
2347 /* setup the dimensions of the rectangle we draw the names of the */
2348 /* days of the week in */
2349 weeknumrect->left = 0;
2351 if(infoPtr->dwStyle & MCS_WEEKNUMBERS)
2352 weeknumrect->right = prev->right;
2354 weeknumrect->right = weeknumrect->left;
2356 wdays->left = days->left = weeknumrect->right;
2357 wdays->right = days->right = wdays->left + 7 * infoPtr->width_increment;
2358 wdays->top = title->bottom;
2359 wdays->bottom = wdays->top + infoPtr->height_increment;
2361 days->top = weeknumrect->top = wdays->bottom;
2362 days->bottom = weeknumrect->bottom = days->top + 6 * infoPtr->height_increment;
2364 todayrect->left = 0;
2365 todayrect->right = title->right;
2366 todayrect->top = days->bottom;
2367 todayrect->bottom = days->bottom + infoPtr->height_increment;
2369 /* offset all rectangles to center in client area */
2370 dx = (rcClient.right - title->right) / 2;
2371 dy = (rcClient.bottom - todayrect->bottom) / 2;
2373 /* if calendar doesn't fit client area show it at left/top bounds */
2374 if (title->left + dx < 0) dx = 0;
2375 if (title->top + dy < 0) dy = 0;
2377 if (dx != 0 || dy != 0)
2379 OffsetRect(title, dx, dy);
2380 OffsetRect(prev, dx, dy);
2381 OffsetRect(next, dx, dy);
2382 OffsetRect(titlemonth, dx, dy);
2383 OffsetRect(titleyear, dx, dy);
2384 OffsetRect(wdays, dx, dy);
2385 OffsetRect(weeknumrect, dx, dy);
2386 OffsetRect(days, dx, dy);
2387 OffsetRect(todayrect, dx, dy);
2390 TRACE("dx=%d dy=%d client[%s] title[%s] wdays[%s] days[%s] today[%s]\n",
2391 infoPtr->width_increment,infoPtr->height_increment,
2392 wine_dbgstr_rect(&rcClient),
2393 wine_dbgstr_rect(title),
2394 wine_dbgstr_rect(wdays),
2395 wine_dbgstr_rect(days),
2396 wine_dbgstr_rect(todayrect));
2398 /* restore the originally selected font */
2399 SelectObject(hdc, currentFont);
2401 ReleaseDC(infoPtr->hwndSelf, hdc);
2404 static LRESULT MONTHCAL_Size(MONTHCAL_INFO *infoPtr, int Width, int Height)
2406 TRACE("(width=%d, height=%d)\n", Width, Height);
2408 MONTHCAL_UpdateSize(infoPtr);
2409 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
2414 static LRESULT MONTHCAL_GetFont(const MONTHCAL_INFO *infoPtr)
2416 return (LRESULT)infoPtr->hFont;
2419 static LRESULT MONTHCAL_SetFont(MONTHCAL_INFO *infoPtr, HFONT hFont, BOOL redraw)
2424 if (!hFont) return 0;
2426 hOldFont = infoPtr->hFont;
2427 infoPtr->hFont = hFont;
2429 GetObjectW(infoPtr->hFont, sizeof(lf), &lf);
2430 lf.lfWeight = FW_BOLD;
2431 infoPtr->hBoldFont = CreateFontIndirectW(&lf);
2433 MONTHCAL_UpdateSize(infoPtr);
2436 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
2438 return (LRESULT)hOldFont;
2441 /* update theme after a WM_THEMECHANGED message */
2442 static LRESULT theme_changed (const MONTHCAL_INFO* infoPtr)
2444 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
2445 CloseThemeData (theme);
2446 OpenThemeData (infoPtr->hwndSelf, themeClass);
2450 static INT MONTHCAL_StyleChanged(MONTHCAL_INFO *infoPtr, WPARAM wStyleType,
2451 const STYLESTRUCT *lpss)
2453 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
2454 wStyleType, lpss->styleOld, lpss->styleNew);
2456 if (wStyleType != GWL_STYLE) return 0;
2458 infoPtr->dwStyle = lpss->styleNew;
2460 /* make room for week numbers */
2461 if ((lpss->styleNew ^ lpss->styleOld) & MCS_WEEKNUMBERS)
2462 MONTHCAL_UpdateSize(infoPtr);
2467 static INT MONTHCAL_StyleChanging(MONTHCAL_INFO *infoPtr, WPARAM wStyleType,
2470 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
2471 wStyleType, lpss->styleOld, lpss->styleNew);
2473 /* block MCS_MULTISELECT change */
2474 if ((lpss->styleNew ^ lpss->styleOld) & MCS_MULTISELECT)
2476 if (lpss->styleOld & MCS_MULTISELECT)
2477 lpss->styleNew |= MCS_MULTISELECT;
2479 lpss->styleNew &= ~MCS_MULTISELECT;
2485 /* FIXME: check whether dateMin/dateMax need to be adjusted. */
2487 MONTHCAL_Create(HWND hwnd, LPCREATESTRUCTW lpcs)
2489 MONTHCAL_INFO *infoPtr;
2491 /* allocate memory for info structure */
2492 infoPtr = Alloc(sizeof(MONTHCAL_INFO));
2493 SetWindowLongPtrW(hwnd, 0, (DWORD_PTR)infoPtr);
2495 if (infoPtr == NULL) {
2496 ERR("could not allocate info memory!\n");
2500 infoPtr->hwndSelf = hwnd;
2501 infoPtr->hwndNotify = lpcs->hwndParent;
2502 infoPtr->dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
2503 infoPtr->calendars = Alloc(sizeof(CALENDAR_INFO));
2504 if (!infoPtr->calendars) goto fail;
2506 infoPtr->cal_num = 1;
2508 MONTHCAL_SetFont(infoPtr, GetStockObject(DEFAULT_GUI_FONT), FALSE);
2510 /* initialize info structure */
2511 /* FIXME: calculate systemtime ->> localtime(substract timezoneinfo) */
2513 GetLocalTime(&infoPtr->todaysDate);
2514 MONTHCAL_SetFirstDayOfWeek(infoPtr, -1);
2516 infoPtr->maxSelCount = (infoPtr->dwStyle & MCS_MULTISELECT) ? 7 : 1;
2517 infoPtr->monthRange = 3;
2519 infoPtr->monthdayState = Alloc(infoPtr->monthRange * sizeof(MONTHDAYSTATE));
2520 if (!infoPtr->monthdayState) goto fail;
2522 infoPtr->colors[MCSC_BACKGROUND] = comctl32_color.clrWindow;
2523 infoPtr->colors[MCSC_TEXT] = comctl32_color.clrWindowText;
2524 infoPtr->colors[MCSC_TITLEBK] = comctl32_color.clrActiveCaption;
2525 infoPtr->colors[MCSC_TITLETEXT] = comctl32_color.clrWindow;
2526 infoPtr->colors[MCSC_MONTHBK] = comctl32_color.clrWindow;
2527 infoPtr->colors[MCSC_TRAILINGTEXT] = comctl32_color.clrGrayText;
2529 infoPtr->brushes[MCSC_BACKGROUND] = CreateSolidBrush(infoPtr->colors[MCSC_BACKGROUND]);
2530 infoPtr->brushes[MCSC_TITLEBK] = CreateSolidBrush(infoPtr->colors[MCSC_TITLEBK]);
2531 infoPtr->brushes[MCSC_MONTHBK] = CreateSolidBrush(infoPtr->colors[MCSC_MONTHBK]);
2533 infoPtr->minSel = infoPtr->todaysDate;
2534 infoPtr->maxSel = infoPtr->todaysDate;
2535 infoPtr->calendars[0].month = infoPtr->todaysDate;
2536 infoPtr->isUnicode = TRUE;
2538 /* call MONTHCAL_UpdateSize to set all of the dimensions */
2539 /* of the control */
2540 MONTHCAL_UpdateSize(infoPtr);
2542 /* today auto update timer, to be freed only on control destruction */
2543 SetTimer(infoPtr->hwndSelf, MC_TODAYUPDATETIMER, MC_TODAYUPDATEDELAY, 0);
2545 OpenThemeData (infoPtr->hwndSelf, themeClass);
2550 Free(infoPtr->monthdayState);
2551 Free(infoPtr->calendars);
2557 MONTHCAL_Destroy(MONTHCAL_INFO *infoPtr)
2559 /* free month calendar info data */
2560 Free(infoPtr->monthdayState);
2561 Free(infoPtr->calendars);
2562 SetWindowLongPtrW(infoPtr->hwndSelf, 0, 0);
2564 CloseThemeData (GetWindowTheme (infoPtr->hwndSelf));
2566 DeleteObject(infoPtr->brushes[MCSC_BACKGROUND]);
2567 DeleteObject(infoPtr->brushes[MCSC_TITLEBK]);
2568 DeleteObject(infoPtr->brushes[MCSC_MONTHBK]);
2575 * Handler for WM_NOTIFY messages
2578 MONTHCAL_Notify(MONTHCAL_INFO *infoPtr, NMHDR *hdr)
2580 /* notification from year edit updown */
2581 if (hdr->code == UDN_DELTAPOS)
2583 NMUPDOWN *nmud = (NMUPDOWN*)hdr;
2585 if (hdr->hwndFrom == infoPtr->hWndYearUpDown && nmud->iDelta)
2587 /* year value limits are set up explicitly after updown creation */
2588 MONTHCAL_Scroll(infoPtr, 12 * nmud->iDelta);
2589 MONTHCAL_NotifyDayState(infoPtr);
2590 MONTHCAL_NotifySelectionChange(infoPtr);
2597 MONTHCAL_SetUnicodeFormat(MONTHCAL_INFO *infoPtr, BOOL isUnicode)
2599 BOOL prev = infoPtr->isUnicode;
2600 infoPtr->isUnicode = isUnicode;
2605 MONTHCAL_GetUnicodeFormat(const MONTHCAL_INFO *infoPtr)
2607 return infoPtr->isUnicode;
2610 static LRESULT WINAPI
2611 MONTHCAL_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2613 MONTHCAL_INFO *infoPtr = (MONTHCAL_INFO *)GetWindowLongPtrW(hwnd, 0);
2615 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n", hwnd, uMsg, wParam, lParam);
2617 if (!infoPtr && (uMsg != WM_CREATE))
2618 return DefWindowProcW(hwnd, uMsg, wParam, lParam);
2622 return MONTHCAL_GetCurSel(infoPtr, (LPSYSTEMTIME)lParam);
2625 return MONTHCAL_SetCurSel(infoPtr, (LPSYSTEMTIME)lParam);
2627 case MCM_GETMAXSELCOUNT:
2628 return MONTHCAL_GetMaxSelCount(infoPtr);
2630 case MCM_SETMAXSELCOUNT:
2631 return MONTHCAL_SetMaxSelCount(infoPtr, wParam);
2633 case MCM_GETSELRANGE:
2634 return MONTHCAL_GetSelRange(infoPtr, (LPSYSTEMTIME)lParam);
2636 case MCM_SETSELRANGE:
2637 return MONTHCAL_SetSelRange(infoPtr, (LPSYSTEMTIME)lParam);
2639 case MCM_GETMONTHRANGE:
2640 return MONTHCAL_GetMonthRange(infoPtr, wParam, (SYSTEMTIME*)lParam);
2642 case MCM_SETDAYSTATE:
2643 return MONTHCAL_SetDayState(infoPtr, (INT)wParam, (LPMONTHDAYSTATE)lParam);
2645 case MCM_GETMINREQRECT:
2646 return MONTHCAL_GetMinReqRect(infoPtr, (LPRECT)lParam);
2649 return MONTHCAL_GetColor(infoPtr, wParam);
2652 return MONTHCAL_SetColor(infoPtr, wParam, (COLORREF)lParam);
2655 return MONTHCAL_GetToday(infoPtr, (LPSYSTEMTIME)lParam);
2658 return MONTHCAL_SetToday(infoPtr, (LPSYSTEMTIME)lParam);
2661 return MONTHCAL_HitTest(infoPtr, (PMCHITTESTINFO)lParam);
2663 case MCM_GETFIRSTDAYOFWEEK:
2664 return MONTHCAL_GetFirstDayOfWeek(infoPtr);
2666 case MCM_SETFIRSTDAYOFWEEK:
2667 return MONTHCAL_SetFirstDayOfWeek(infoPtr, (INT)lParam);
2670 return MONTHCAL_GetRange(infoPtr, (LPSYSTEMTIME)lParam);
2673 return MONTHCAL_SetRange(infoPtr, (SHORT)wParam, (LPSYSTEMTIME)lParam);
2675 case MCM_GETMONTHDELTA:
2676 return MONTHCAL_GetMonthDelta(infoPtr);
2678 case MCM_SETMONTHDELTA:
2679 return MONTHCAL_SetMonthDelta(infoPtr, wParam);
2681 case MCM_GETMAXTODAYWIDTH:
2682 return MONTHCAL_GetMaxTodayWidth(infoPtr);
2684 case MCM_SETUNICODEFORMAT:
2685 return MONTHCAL_SetUnicodeFormat(infoPtr, (BOOL)wParam);
2687 case MCM_GETUNICODEFORMAT:
2688 return MONTHCAL_GetUnicodeFormat(infoPtr);
2691 return DLGC_WANTARROWS | DLGC_WANTCHARS;
2694 return MONTHCAL_RButtonUp(infoPtr, lParam);
2696 case WM_LBUTTONDOWN:
2697 return MONTHCAL_LButtonDown(infoPtr, lParam);
2700 return MONTHCAL_MouseMove(infoPtr, lParam);
2703 return MONTHCAL_LButtonUp(infoPtr, lParam);
2706 return MONTHCAL_Paint(infoPtr, (HDC)wParam);
2708 case WM_PRINTCLIENT:
2709 return MONTHCAL_PrintClient(infoPtr, (HDC)wParam, (DWORD)lParam);
2712 return MONTHCAL_EraseBkgnd(infoPtr, (HDC)wParam);
2715 return MONTHCAL_SetFocus(infoPtr);
2718 return MONTHCAL_Size(infoPtr, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
2721 return MONTHCAL_Notify(infoPtr, (NMHDR*)lParam);
2724 return MONTHCAL_Create(hwnd, (LPCREATESTRUCTW)lParam);
2727 return MONTHCAL_SetFont(infoPtr, (HFONT)wParam, (BOOL)lParam);
2730 return MONTHCAL_GetFont(infoPtr);
2733 return MONTHCAL_Timer(infoPtr, wParam);
2735 case WM_THEMECHANGED:
2736 return theme_changed (infoPtr);
2739 return MONTHCAL_Destroy(infoPtr);
2741 case WM_SYSCOLORCHANGE:
2742 COMCTL32_RefreshSysColors();
2745 case WM_STYLECHANGED:
2746 return MONTHCAL_StyleChanged(infoPtr, wParam, (LPSTYLESTRUCT)lParam);
2748 case WM_STYLECHANGING:
2749 return MONTHCAL_StyleChanging(infoPtr, wParam, (LPSTYLESTRUCT)lParam);
2752 if ((uMsg >= WM_USER) && (uMsg < WM_APP) && !COMCTL32_IsReflectedMessage(uMsg))
2753 ERR( "unknown msg %04x wp=%08lx lp=%08lx\n", uMsg, wParam, lParam);
2754 return DefWindowProcW(hwnd, uMsg, wParam, lParam);
2760 MONTHCAL_Register(void)
2764 ZeroMemory(&wndClass, sizeof(WNDCLASSW));
2765 wndClass.style = CS_GLOBALCLASS;
2766 wndClass.lpfnWndProc = MONTHCAL_WindowProc;
2767 wndClass.cbClsExtra = 0;
2768 wndClass.cbWndExtra = sizeof(MONTHCAL_INFO *);
2769 wndClass.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
2770 wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
2771 wndClass.lpszClassName = MONTHCAL_CLASSW;
2773 RegisterClassW(&wndClass);
2778 MONTHCAL_Unregister(void)
2780 UnregisterClassW(MONTHCAL_CLASSW, NULL);