1 /* 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>
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 * This code was audited for completeness against the documented features
27 * of Comctl32.dll version 6.0 on Oct. 20, 2004, by Dimitrie O. Paun.
29 * Unless otherwise noted, we believe this code to be complete, as per
30 * the specification mentioned above.
31 * If you discover missing features, or bugs, please note them below.
34 * -- MCM_[GS]ETUNICODEFORMAT
35 * -- MONTHCAL_GetMonthRange
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_NEXTMONTHDELAY 350 /* when continuously pressing `next */
67 /* month', wait 500 ms before going */
68 /* to the next month */
69 #define MC_NEXTMONTHTIMER 1 /* Timer ID's */
70 #define MC_PREVMONTHTIMER 2
72 #define countof(arr) (sizeof(arr)/sizeof(arr[0]))
77 DWORD dwStyle; /* cached GWL_STYLE */
90 int firstDayplace; /* place of the first day of the current month */
91 INT delta; /* scroll rate; # of months that the */
92 /* control moves when user clicks a scroll button */
93 int visible; /* # of months visible */
94 int firstDay; /* Start month calendar with firstDay's day */
95 int firstDayHighWord; /* High word only used externally */
97 MONTHDAYSTATE *monthdayState;
98 SYSTEMTIME todaysDate;
99 int status; /* See MC_SEL flags */
100 int firstSelDay; /* first selected day */
104 SYSTEMTIME curSel; /* contains currently selected year, month and day */
109 RECT title; /* rect for the header above the calendar */
110 RECT titlebtnnext; /* the `next month' button in the header */
111 RECT titlebtnprev; /* the `prev month' button in the header */
112 RECT titlemonth; /* the `month name' txt in the header */
113 RECT titleyear; /* the `year number' txt in the header */
114 RECT wdays; /* week days at top */
115 RECT days; /* calendar area */
116 RECT weeknums; /* week numbers at left side */
117 RECT todayrect; /* `today: xx/xx/xx' text rect */
118 HWND hwndNotify; /* Window to receive the notifications */
119 HWND hWndYearEdit; /* Window Handle of edit box to handle years */
120 HWND hWndYearUpDown;/* Window Handle of updown box to handle years */
121 } MONTHCAL_INFO, *LPMONTHCAL_INFO;
124 /* Offsets of days in the week to the weekday of january 1 in a leap year */
125 static const int DayOfWeekTable[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
127 static const WCHAR themeClass[] = { 'S','c','r','o','l','l','b','a','r',0 };
129 #define MONTHCAL_GetInfoPtr(hwnd) ((MONTHCAL_INFO *)GetWindowLongPtrW(hwnd, 0))
131 /* helper functions */
133 /* returns the number of days in any given month, checking for leap days */
134 /* january is 1, december is 12 */
135 int MONTHCAL_MonthLength(int month, int year)
137 const int mdays[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 0};
138 /*Wrap around, this eases handling*/
144 /* if we have a leap year add 1 day to February */
145 /* a leap year is a year either divisible by 400 */
146 /* or divisible by 4 and not by 100 */
147 if(month == 2) { /* February */
148 return mdays[month - 1] + ((year%400 == 0) ? 1 : ((year%100 != 0) &&
149 (year%4 == 0)) ? 1 : 0);
152 return mdays[month - 1];
156 /* compares timestamps using date part only */
157 static inline BOOL MONTHCAL_IsDateEqual(const SYSTEMTIME *first, const SYSTEMTIME *second)
159 return (first->wYear == second->wYear) && (first->wMonth == second->wMonth) &&
160 (first->wDay == second->wDay);
163 /* make sure that date fields are valid */
164 static BOOL MONTHCAL_ValidateDate(const SYSTEMTIME *time)
166 if(time->wMonth < 1 || time->wMonth > 12 ) return FALSE;
167 if(time->wDayOfWeek > 6) return FALSE;
168 if(time->wDay > MONTHCAL_MonthLength(time->wMonth, time->wYear))
174 /* Used in MCM_SETRANGE/MCM_SETSELRANGE to determine resulting time part.
175 Milliseconds are intentionaly not validated. */
176 static BOOL MONTHCAL_ValidateTime(const SYSTEMTIME *time)
178 if((time->wHour > 24) || (time->wMinute > 59) || (time->wSecond > 59))
184 /* Copies timestamp part only. Milliseconds are intentionaly not copied
185 cause it matches required behaviour for current use of this helper */
186 static void MONTHCAL_CopyTime(const SYSTEMTIME *from, SYSTEMTIME *to)
188 to->wHour = from->wHour;
189 to->wMinute = from->wMinute;
190 to->wSecond = from->wSecond;
193 /* Note:Depending on DST, this may be offset by a day.
194 Need to find out if we're on a DST place & adjust the clock accordingly.
195 Above function assumes we have a valid data.
196 Valid for year>1752; 1 <= d <= 31, 1 <= m <= 12.
200 /* returns the day in the week(0 == sunday, 6 == saturday) */
201 /* day(1 == 1st, 2 == 2nd... etc), year is the year value */
202 static int MONTHCAL_CalculateDayOfWeek(DWORD day, DWORD month, DWORD year)
206 return((year + year/4 - year/100 + year/400 +
207 DayOfWeekTable[month-1] + day ) % 7);
210 /* From a given point, calculate the row (weekpos), column(daypos)
211 and day in the calendar. day== 0 mean the last day of tha last month
213 static int MONTHCAL_CalcDayFromPos(const MONTHCAL_INFO *infoPtr, int x, int y,
214 int *daypos,int *weekpos)
216 int retval, firstDay;
219 GetClientRect(infoPtr->hwndSelf, &rcClient);
221 /* if the point is outside the x bounds of the window put
222 it at the boundary */
223 if (x > rcClient.right)
227 *daypos = (x - infoPtr->days.left ) / infoPtr->width_increment;
228 *weekpos = (y - infoPtr->days.top ) / infoPtr->height_increment;
230 firstDay = (MONTHCAL_CalculateDayOfWeek(1, infoPtr->curSel.wMonth, infoPtr->curSel.wYear)+6 - infoPtr->firstDay)%7;
231 retval = *daypos + (7 * *weekpos) - firstDay;
235 /* day is the day of the month, 1 == 1st day of the month */
236 /* sets x and y to be the position of the day */
237 /* x == day, y == week where(0,0) == firstDay, 1st week */
238 static void MONTHCAL_CalcDayXY(const MONTHCAL_INFO *infoPtr, int day, int month,
241 int firstDay, prevMonth;
243 firstDay = (MONTHCAL_CalculateDayOfWeek(1, infoPtr->curSel.wMonth, infoPtr->curSel.wYear) +6 - infoPtr->firstDay)%7;
245 if(month==infoPtr->curSel.wMonth) {
246 *x = (day + firstDay) % 7;
247 *y = (day + firstDay - *x) / 7;
250 if(month < infoPtr->curSel.wMonth) {
251 prevMonth = month - 1;
255 *x = (MONTHCAL_MonthLength(prevMonth, infoPtr->curSel.wYear) - firstDay) % 7;
260 *y = MONTHCAL_MonthLength(month, infoPtr->curSel.wYear - 1) / 7;
261 *x = (day + firstDay + MONTHCAL_MonthLength(month,
262 infoPtr->curSel.wYear)) % 7;
266 /* x: column(day), y: row(week) */
267 static void MONTHCAL_CalcDayRect(const MONTHCAL_INFO *infoPtr, RECT *r, int x, int y)
269 r->left = infoPtr->days.left + x * infoPtr->width_increment;
270 r->right = r->left + infoPtr->width_increment;
271 r->top = infoPtr->days.top + y * infoPtr->height_increment;
272 r->bottom = r->top + infoPtr->textHeight;
276 /* sets the RECT struct r to the rectangle around the day and month */
277 /* day is the day value of the month(1 == 1st), month is the month */
278 /* value(january == 1, december == 12) */
279 static inline void MONTHCAL_CalcPosFromDay(const MONTHCAL_INFO *infoPtr,
280 int day, int month, RECT *r)
284 MONTHCAL_CalcDayXY(infoPtr, day, month, &x, &y);
285 MONTHCAL_CalcDayRect(infoPtr, r, x, y);
289 /* day is the day in the month(1 == 1st of the month) */
290 /* month is the month value(1 == january, 12 == december) */
291 static void MONTHCAL_CircleDay(const MONTHCAL_INFO *infoPtr, HDC hdc, int day, int month)
293 HPEN hRedPen = CreatePen(PS_SOLID, 1, RGB(255, 0, 0));
294 HPEN hOldPen2 = SelectObject(hdc, hRedPen);
298 MONTHCAL_CalcPosFromDay(infoPtr, day, month, &day_rect);
300 hOldBrush = SelectObject(hdc, GetStockObject(NULL_BRUSH));
301 Rectangle(hdc, day_rect.left, day_rect.top, day_rect.right, day_rect.bottom);
303 SelectObject(hdc, hOldBrush);
304 DeleteObject(hRedPen);
305 SelectObject(hdc, hOldPen2);
308 static void MONTHCAL_DrawDay(const MONTHCAL_INFO *infoPtr, HDC hdc, int day, int month,
309 int x, int y, int bold)
311 static const WCHAR fmtW[] = { '%','d',0 };
314 static BOOL haveBoldFont, haveSelectedDay = FALSE;
319 wsprintfW(buf, fmtW, day);
321 /* No need to check styles: when selection is not valid, it is set to zero.
322 * 1<day<31, so everything is OK.
325 MONTHCAL_CalcDayRect(infoPtr, &r, x, y);
327 if((day>=infoPtr->minSel.wDay) && (day<=infoPtr->maxSel.wDay)
328 && (month == infoPtr->curSel.wMonth)) {
331 TRACE("%d %d %d\n",day, infoPtr->minSel.wDay, infoPtr->maxSel.wDay);
332 TRACE("%s\n", wine_dbgstr_rect(&r));
333 oldCol = SetTextColor(hdc, infoPtr->monthbk);
334 oldBk = SetBkColor(hdc, infoPtr->trailingtxt);
335 hbr = GetSysColorBrush(COLOR_HIGHLIGHT);
336 FillRect(hdc, &r, hbr);
338 /* FIXME: this may need to be changed now b/c of the other
339 drawing changes 11/3/99 CMM */
340 r2.left = r.left - 0.25 * infoPtr->textWidth;
342 r2.right = r.left + 0.5 * infoPtr->textWidth;
343 r2.bottom = r.bottom;
344 if(haveSelectedDay) FillRect(hdc, &r2, hbr);
345 haveSelectedDay = TRUE;
347 haveSelectedDay = FALSE;
350 /* need to add some code for multiple selections */
352 if((bold) &&(!haveBoldFont)) {
353 SelectObject(hdc, infoPtr->hBoldFont);
356 if((!bold) &&(haveBoldFont)) {
357 SelectObject(hdc, infoPtr->hFont);
358 haveBoldFont = FALSE;
361 SetBkMode(hdc,TRANSPARENT);
362 DrawTextW(hdc, buf, -1, &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE );
364 if(haveSelectedDay) {
365 SetTextColor(hdc, oldCol);
366 SetBkColor(hdc, oldBk);
369 /* draw a rectangle around the currently selected days text */
370 if((day == infoPtr->curSel.wDay) && (month == infoPtr->curSel.wMonth))
371 DrawFocusRect(hdc, &r);
375 static void paint_button (const MONTHCAL_INFO *infoPtr, HDC hdc, BOOL btnNext,
376 BOOL pressed, RECT* r)
378 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
382 static const int states[] = {
384 ABS_LEFTNORMAL, ABS_LEFTPRESSED, ABS_LEFTDISABLED,
386 ABS_RIGHTNORMAL, ABS_RIGHTPRESSED, ABS_RIGHTDISABLED
388 int stateNum = btnNext ? 3 : 0;
393 if (infoPtr->dwStyle & WS_DISABLED) stateNum += 2;
395 DrawThemeBackground (theme, hdc, SBP_ARROWBTN, states[stateNum], r, NULL);
399 int style = btnNext ? DFCS_SCROLLRIGHT : DFCS_SCROLLLEFT;
401 style |= DFCS_PUSHED;
404 if (infoPtr->dwStyle & WS_DISABLED) style |= DFCS_INACTIVE;
407 DrawFrameControl(hdc, r, DFC_SCROLL, style);
412 static void MONTHCAL_Refresh(MONTHCAL_INFO *infoPtr, HDC hdc, const PAINTSTRUCT *ps)
414 static const WCHAR todayW[] = { 'T','o','d','a','y',':',0 };
415 static const WCHAR fmt1W[] = { '%','s',' ','%','l','d',0 };
416 static const WCHAR fmt2W[] = { '%','s',' ','%','s',0 };
417 static const WCHAR fmt3W[] = { '%','d',0 };
418 RECT *title=&infoPtr->title;
419 RECT *prev=&infoPtr->titlebtnprev;
420 RECT *next=&infoPtr->titlebtnnext;
421 RECT *titlemonth=&infoPtr->titlemonth;
422 RECT *titleyear=&infoPtr->titleyear;
426 int i, j, m, mask, day, firstDay, weeknum, weeknum1,prevMonth;
427 int textHeight = infoPtr->textHeight;
434 COLORREF oldTextColor, oldBkColor;
436 RECT rcDay; /* used in MONTHCAL_CalcDayRect() */
437 SYSTEMTIME localtime;
440 oldTextColor = SetTextColor(hdc, comctl32_color.clrWindowText);
442 /* fill background */
443 hbr = CreateSolidBrush (infoPtr->bk);
444 FillRect(hdc, &ps->rcPaint, hbr);
448 if(IntersectRect(&rcTemp, &(ps->rcPaint), title))
450 hbr = CreateSolidBrush(infoPtr->titlebk);
451 FillRect(hdc, title, hbr);
455 /* if the previous button is pressed draw it depressed */
456 if(IntersectRect(&rcTemp, &(ps->rcPaint), prev))
457 paint_button (infoPtr, hdc, FALSE, infoPtr->status & MC_PREVPRESSED, prev);
459 /* if next button is depressed draw it depressed */
460 if(IntersectRect(&rcTemp, &(ps->rcPaint), next))
461 paint_button (infoPtr, hdc, TRUE, infoPtr->status & MC_NEXTPRESSED, next);
463 oldBkColor = SetBkColor(hdc, infoPtr->titlebk);
464 SetTextColor(hdc, infoPtr->titletxt);
465 currentFont = SelectObject(hdc, infoPtr->hBoldFont);
467 GetLocaleInfoW( LOCALE_USER_DEFAULT,LOCALE_SMONTHNAME1+infoPtr->curSel.wMonth -1,
469 wsprintfW(buf, fmt1W, buf1, infoPtr->curSel.wYear);
471 if(IntersectRect(&rcTemp, &(ps->rcPaint), title))
473 DrawTextW(hdc, buf, strlenW(buf), title,
474 DT_CENTER | DT_VCENTER | DT_SINGLELINE);
477 /* titlemonth left/right contained rect for whole titletxt('June 1999')
478 * MCM_HitTestInfo wants month & year rects, so prepare these now.
479 *(no, we can't draw them separately; the whole text is centered)
481 GetTextExtentPoint32W(hdc, buf, strlenW(buf), &size);
482 titlemonth->left = title->right / 2 + title->left / 2 - size.cx / 2;
483 titleyear->right = title->right / 2 + title->left / 2 + size.cx / 2;
484 GetTextExtentPoint32W(hdc, buf1, strlenW(buf1), &size);
485 titlemonth->right = titlemonth->left + size.cx;
486 titleyear->left = titlemonth->right;
488 /* draw month area */
489 rcTemp.top=infoPtr->wdays.top;
490 rcTemp.left=infoPtr->wdays.left;
491 rcTemp.bottom=infoPtr->todayrect.bottom;
492 rcTemp.right =infoPtr->todayrect.right;
493 if(IntersectRect(&rcTemp, &(ps->rcPaint), &rcTemp))
495 hbr = CreateSolidBrush(infoPtr->monthbk);
496 FillRect(hdc, &rcTemp, hbr);
500 /* draw line under day abbreviations */
502 MoveToEx(hdc, infoPtr->days.left + 3, title->bottom + textHeight + 1, NULL);
503 LineTo(hdc, infoPtr->days.right - 3, title->bottom + textHeight + 1);
505 prevMonth = infoPtr->curSel.wMonth - 1;
506 if(prevMonth == 0) /* if curSel.wMonth is january(1) prevMonth is */
507 prevMonth = 12; /* december(12) of the previous year */
509 infoPtr->wdays.left = infoPtr->days.left = infoPtr->weeknums.right;
510 /* draw day abbreviations */
512 SelectObject(hdc, infoPtr->hFont);
513 SetBkColor(hdc, infoPtr->monthbk);
514 SetTextColor(hdc, infoPtr->trailingtxt);
516 /* copy this rect so we can change the values without changing */
517 /* the original version */
518 days->left = infoPtr->wdays.left;
519 days->right = days->left + infoPtr->width_increment;
520 days->top = infoPtr->wdays.top;
521 days->bottom = infoPtr->wdays.bottom;
523 i = infoPtr->firstDay;
526 GetLocaleInfoW( LOCALE_USER_DEFAULT,LOCALE_SABBREVDAYNAME1 + (i+j+6)%7, buf, countof(buf));
527 DrawTextW(hdc, buf, strlenW(buf), days, DT_CENTER | DT_VCENTER | DT_SINGLELINE );
528 days->left+=infoPtr->width_increment;
529 days->right+=infoPtr->width_increment;
532 /* draw day numbers; first, the previous month */
534 firstDay = MONTHCAL_CalculateDayOfWeek(1, infoPtr->curSel.wMonth, infoPtr->curSel.wYear);
536 day = MONTHCAL_MonthLength(prevMonth, infoPtr->curSel.wYear) +
537 (infoPtr->firstDay + 7 - firstDay)%7 + 1;
538 if (day > MONTHCAL_MonthLength(prevMonth, infoPtr->curSel.wYear))
540 startofprescal = day;
545 while(day <= MONTHCAL_MonthLength(prevMonth, infoPtr->curSel.wYear)) {
546 MONTHCAL_CalcDayRect(infoPtr, &rcDay, i, 0);
547 if(IntersectRect(&rcTemp, &(ps->rcPaint), &rcDay))
549 MONTHCAL_DrawDay(infoPtr, hdc, day, prevMonth, i, 0,
550 infoPtr->monthdayState[m] & mask);
558 /* draw `current' month */
560 day = 1; /* start at the beginning of the current month */
562 infoPtr->firstDayplace = i;
563 SetTextColor(hdc, infoPtr->txt);
567 /* draw the first week of the current month */
569 MONTHCAL_CalcDayRect(infoPtr, &rcDay, i, 0);
570 if(IntersectRect(&rcTemp, &(ps->rcPaint), &rcDay))
573 MONTHCAL_DrawDay(infoPtr, hdc, day, infoPtr->curSel.wMonth, i, 0,
574 infoPtr->monthdayState[m] & mask);
576 if((infoPtr->curSel.wMonth == infoPtr->todaysDate.wMonth) &&
577 (day==infoPtr->todaysDate.wDay) &&
578 (infoPtr->curSel.wYear == infoPtr->todaysDate.wYear)) {
579 if(!(infoPtr->dwStyle & MCS_NOTODAYCIRCLE))
580 MONTHCAL_CircleDay(infoPtr, hdc, day, infoPtr->curSel.wMonth);
589 j = 1; /* move to the 2nd week of the current month */
590 i = 0; /* move back to sunday */
591 while(day <= MONTHCAL_MonthLength(infoPtr->curSel.wMonth, infoPtr->curSel.wYear)) {
592 MONTHCAL_CalcDayRect(infoPtr, &rcDay, i, j);
593 if(IntersectRect(&rcTemp, &(ps->rcPaint), &rcDay))
595 MONTHCAL_DrawDay(infoPtr, hdc, day, infoPtr->curSel.wMonth, i, j,
596 infoPtr->monthdayState[m] & mask);
598 if((infoPtr->curSel.wMonth == infoPtr->todaysDate.wMonth) &&
599 (day==infoPtr->todaysDate.wDay) &&
600 (infoPtr->curSel.wYear == infoPtr->todaysDate.wYear))
601 if(!(infoPtr->dwStyle & MCS_NOTODAYCIRCLE))
602 MONTHCAL_CircleDay(infoPtr, hdc, day, infoPtr->curSel.wMonth);
607 if(i>6) { /* past saturday, goto the next weeks sunday */
613 /* draw `next' month */
615 day = 1; /* start at the first day of the next month */
619 SetTextColor(hdc, infoPtr->trailingtxt);
620 while((i<7) &&(j<6)) {
621 MONTHCAL_CalcDayRect(infoPtr, &rcDay, i, j);
622 if(IntersectRect(&rcTemp, &(ps->rcPaint), &rcDay))
624 MONTHCAL_DrawDay(infoPtr, hdc, day, infoPtr->curSel.wMonth + 1, i, j,
625 infoPtr->monthdayState[m] & mask);
631 if(i==7) { /* past saturday, go to next week's sunday */
636 SetTextColor(hdc, infoPtr->txt);
639 /* draw `today' date if style allows it, and draw a circle before today's
640 * date if necessary */
642 if(!(infoPtr->dwStyle & MCS_NOTODAY)) {
643 if(!(infoPtr->dwStyle & MCS_NOTODAYCIRCLE)) {
644 /*day is the number of days from nextmonth we put on the calendar */
645 MONTHCAL_CircleDay(infoPtr, hdc,
646 day+MONTHCAL_MonthLength(infoPtr->curSel.wMonth, infoPtr->curSel.wYear),
647 infoPtr->curSel.wMonth);
649 if (!LoadStringW(COMCTL32_hModule,IDM_TODAY,buf1,countof(buf1)))
651 WARN("Can't load resource\n");
652 strcpyW(buf1, todayW);
654 MONTHCAL_CalcDayRect(infoPtr, &rtoday, 1, 6);
655 localtime = infoPtr->todaysDate;
656 GetDateFormatW(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&localtime,NULL,buf2,countof(buf2));
657 wsprintfW(buf, fmt2W, buf1, buf2);
658 SelectObject(hdc, infoPtr->hBoldFont);
660 DrawTextW(hdc, buf, -1, &rtoday, DT_CALCRECT | DT_LEFT | DT_VCENTER | DT_SINGLELINE);
661 if(IntersectRect(&rcTemp, &(ps->rcPaint), &rtoday))
663 DrawTextW(hdc, buf, -1, &rtoday, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
665 SelectObject(hdc, infoPtr->hFont);
668 /*eventually draw week numbers*/
669 if(infoPtr->dwStyle & MCS_WEEKNUMBERS) {
670 /* display weeknumbers*/
673 /* Rules what week to call the first week of a new year:
674 LOCALE_IFIRSTWEEKOFYEAR == 0 (e.g US?):
675 The week containing Jan 1 is the first week of year
676 LOCALE_IFIRSTWEEKOFYEAR == 2 (e.g. Germany):
677 First week of year must contain 4 days of the new year
678 LOCALE_IFIRSTWEEKOFYEAR == 1 (what contries?)
679 The first week of the year must contain only days of the new year
681 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_IFIRSTWEEKOFYEAR, buf, countof(buf));
682 weeknum = atoiW(buf);
693 if (infoPtr->curSel.wMonth < 2)
695 /* calculate all those exceptions for january */
696 weeknum1=MONTHCAL_CalculateDayOfWeek(1, 1, infoPtr->curSel.wYear);
697 if ((infoPtr->firstDay +7 - weeknum1)%7 > mindays)
703 weeknum+=MONTHCAL_MonthLength(i+1, infoPtr->curSel.wYear - 1);
704 weeknum +=startofprescal+ 7;
706 weeknum1=MONTHCAL_CalculateDayOfWeek(1, 1, infoPtr->curSel.wYear - 1);
707 if ((infoPtr->firstDay + 7 - weeknum1)%7 > mindays)
714 for(i=0; i<prevMonth-1; i++)
715 weeknum+=MONTHCAL_MonthLength(i+1, infoPtr->curSel.wYear);
716 weeknum +=startofprescal+ 7;
718 weeknum1=MONTHCAL_CalculateDayOfWeek(1,1,infoPtr->curSel.wYear);
719 if ((infoPtr->firstDay + 7 - weeknum1)%7 > mindays)
722 days->left = infoPtr->weeknums.left;
723 days->right = infoPtr->weeknums.right;
724 days->top = infoPtr->weeknums.top;
725 days->bottom = days->top +infoPtr->height_increment;
727 if((i==0)&&(weeknum>50))
729 wsprintfW(buf, fmt3W, weeknum);
732 else if((i==5)&&(weeknum>47))
734 wsprintfW(buf, fmt3W, 1);
737 wsprintfW(buf, fmt3W, weeknum + i);
738 DrawTextW(hdc, buf, -1, days, DT_CENTER | DT_VCENTER | DT_SINGLELINE );
739 days->top+=infoPtr->height_increment;
740 days->bottom+=infoPtr->height_increment;
743 MoveToEx(hdc, infoPtr->weeknums.right, infoPtr->weeknums.top + 3 , NULL);
744 LineTo(hdc, infoPtr->weeknums.right, infoPtr->weeknums.bottom );
747 /* currentFont was font at entering Refresh */
749 SetBkColor(hdc, oldBkColor);
750 SelectObject(hdc, currentFont);
751 SetTextColor(hdc, oldTextColor);
756 MONTHCAL_GetMinReqRect(const MONTHCAL_INFO *infoPtr, LPRECT lpRect)
758 TRACE("rect %p\n", lpRect);
760 if(!lpRect) return FALSE;
762 lpRect->left = infoPtr->title.left;
763 lpRect->top = infoPtr->title.top;
764 lpRect->right = infoPtr->title.right;
765 lpRect->bottom = infoPtr->todayrect.bottom;
767 AdjustWindowRect(lpRect, infoPtr->dwStyle, FALSE);
769 /* minimal rectangle is zero based */
770 OffsetRect(lpRect, -lpRect->left, -lpRect->top);
772 TRACE("%s\n", wine_dbgstr_rect(lpRect));
779 MONTHCAL_GetColor(const MONTHCAL_INFO *infoPtr, INT index)
784 case MCSC_BACKGROUND:
789 return infoPtr->titlebk;
791 return infoPtr->titletxt;
793 return infoPtr->monthbk;
794 case MCSC_TRAILINGTEXT:
795 return infoPtr->trailingtxt;
803 MONTHCAL_SetColor(MONTHCAL_INFO *infoPtr, INT index, COLORREF color)
807 TRACE("%d: color %08x\n", index, color);
810 case MCSC_BACKGROUND:
816 infoPtr->txt = color;
819 prev = infoPtr->titlebk;
820 infoPtr->titlebk = color;
823 prev=infoPtr->titletxt;
824 infoPtr->titletxt = color;
827 prev = infoPtr->monthbk;
828 infoPtr->monthbk = color;
830 case MCSC_TRAILINGTEXT:
831 prev = infoPtr->trailingtxt;
832 infoPtr->trailingtxt = color;
836 InvalidateRect(infoPtr->hwndSelf, NULL, index == MCSC_BACKGROUND ? TRUE : FALSE);
842 MONTHCAL_GetMonthDelta(const MONTHCAL_INFO *infoPtr)
847 return infoPtr->delta;
849 return infoPtr->visible;
854 MONTHCAL_SetMonthDelta(MONTHCAL_INFO *infoPtr, INT delta)
856 INT prev = infoPtr->delta;
858 TRACE("delta %d\n", delta);
860 infoPtr->delta = delta;
866 MONTHCAL_GetFirstDayOfWeek(const MONTHCAL_INFO *infoPtr)
868 return MAKELONG(infoPtr->firstDay, infoPtr->firstDayHighWord);
872 /* sets the first day of the week that will appear in the control */
873 /* 0 == Sunday, 6 == Saturday */
874 /* FIXME: this needs to be implemented properly in MONTHCAL_Refresh() */
875 /* FIXME: we need more error checking here */
877 MONTHCAL_SetFirstDayOfWeek(MONTHCAL_INFO *infoPtr, INT day)
879 int prev = MAKELONG(infoPtr->firstDay, infoPtr->firstDayHighWord);
883 TRACE("day %d\n", day);
885 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_IFIRSTDAYOFWEEK, buf, countof(buf));
886 TRACE("%s %d\n", debugstr_w(buf), strlenW(buf));
888 localFirstDay = atoiW(buf);
892 infoPtr->firstDay = localFirstDay;
893 infoPtr->firstDayHighWord = FALSE;
897 infoPtr->firstDay = 6; /* max first day allowed */
898 infoPtr->firstDayHighWord = TRUE;
902 infoPtr->firstDay = day;
903 infoPtr->firstDayHighWord = TRUE;
911 MONTHCAL_GetMonthRange(const MONTHCAL_INFO *infoPtr)
915 return infoPtr->monthRange;
920 MONTHCAL_GetMaxTodayWidth(const MONTHCAL_INFO *infoPtr)
922 return(infoPtr->todayrect.right - infoPtr->todayrect.left);
927 MONTHCAL_SetRange(MONTHCAL_INFO *infoPtr, SHORT limits, SYSTEMTIME *range)
929 FILETIME ft_min, ft_max;
931 TRACE("%x %p\n", limits, range);
933 if ((limits & GDTR_MIN && !MONTHCAL_ValidateDate(&range[0])) ||
934 (limits & GDTR_MAX && !MONTHCAL_ValidateDate(&range[1])))
937 if (limits & GDTR_MIN)
939 if (!MONTHCAL_ValidateTime(&range[0]))
940 MONTHCAL_CopyTime(&infoPtr->todaysDate, &range[0]);
942 infoPtr->minDate = range[0];
943 infoPtr->rangeValid |= GDTR_MIN;
945 if (limits & GDTR_MAX)
947 if (!MONTHCAL_ValidateTime(&range[1]))
948 MONTHCAL_CopyTime(&infoPtr->todaysDate, &range[1]);
950 infoPtr->maxDate = range[1];
951 infoPtr->rangeValid |= GDTR_MAX;
954 /* Only one limit set - we are done */
955 if ((infoPtr->rangeValid & (GDTR_MIN | GDTR_MAX)) != (GDTR_MIN | GDTR_MAX))
958 SystemTimeToFileTime(&infoPtr->maxDate, &ft_max);
959 SystemTimeToFileTime(&infoPtr->minDate, &ft_min);
961 if (CompareFileTime(&ft_min, &ft_max) >= 0)
963 if ((limits & (GDTR_MIN | GDTR_MAX)) == (GDTR_MIN | GDTR_MAX))
965 /* Native swaps limits only when both limits are being set. */
966 SYSTEMTIME st_tmp = infoPtr->minDate;
967 infoPtr->minDate = infoPtr->maxDate;
968 infoPtr->maxDate = st_tmp;
972 static const SYSTEMTIME zero;
974 /* reset the other limit */
975 if (limits & GDTR_MIN) infoPtr->maxDate = zero;
976 if (limits & GDTR_MAX) infoPtr->minDate = zero;
977 infoPtr->rangeValid &= limits & GDTR_MIN ? ~GDTR_MAX : ~GDTR_MIN ;
986 MONTHCAL_GetRange(const MONTHCAL_INFO *infoPtr, SYSTEMTIME *range)
988 TRACE("%p\n", range);
990 if(!range) return FALSE;
992 range[1] = infoPtr->maxDate;
993 range[0] = infoPtr->minDate;
995 return infoPtr->rangeValid;
1000 MONTHCAL_SetDayState(const MONTHCAL_INFO *infoPtr, INT months, MONTHDAYSTATE *states)
1004 TRACE("%d %p\n", months, states);
1005 if(months != infoPtr->monthRange) return 0;
1007 for(i = 0; i < months; i++)
1008 infoPtr->monthdayState[i] = states[i];
1014 MONTHCAL_GetCurSel(const MONTHCAL_INFO *infoPtr, SYSTEMTIME *curSel)
1016 TRACE("%p\n", curSel);
1017 if(!curSel) return FALSE;
1018 if(infoPtr->dwStyle & MCS_MULTISELECT) return FALSE;
1020 *curSel = infoPtr->minSel;
1021 TRACE("%d/%d/%d\n", curSel->wYear, curSel->wMonth, curSel->wDay);
1025 /* FIXME: if the specified date is not visible, make it visible */
1026 /* FIXME: redraw? */
1028 MONTHCAL_SetCurSel(MONTHCAL_INFO *infoPtr, SYSTEMTIME *curSel)
1030 TRACE("%p\n", curSel);
1031 if(!curSel) return FALSE;
1032 if(infoPtr->dwStyle & MCS_MULTISELECT) return FALSE;
1034 if(!MONTHCAL_ValidateDate(curSel)) return FALSE;
1036 infoPtr->minSel = *curSel;
1037 infoPtr->maxSel = *curSel;
1039 /* exit earlier if selection equals current */
1040 if (MONTHCAL_IsDateEqual(&infoPtr->curSel, curSel)) return TRUE;
1042 infoPtr->curSel = *curSel;
1044 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1051 MONTHCAL_GetMaxSelCount(const MONTHCAL_INFO *infoPtr)
1053 return infoPtr->maxSelCount;
1058 MONTHCAL_SetMaxSelCount(MONTHCAL_INFO *infoPtr, INT max)
1062 if(infoPtr->dwStyle & MCS_MULTISELECT) {
1063 infoPtr->maxSelCount = max;
1071 MONTHCAL_GetSelRange(const MONTHCAL_INFO *infoPtr, SYSTEMTIME *range)
1073 TRACE("%p\n", range);
1075 if(!range) return FALSE;
1077 if(infoPtr->dwStyle & MCS_MULTISELECT)
1079 range[1] = infoPtr->maxSel;
1080 range[0] = infoPtr->minSel;
1081 TRACE("[min,max]=[%d %d]\n", infoPtr->minSel.wDay, infoPtr->maxSel.wDay);
1090 MONTHCAL_SetSelRange(MONTHCAL_INFO *infoPtr, SYSTEMTIME *range)
1092 TRACE("%p\n", range);
1094 if(!range) return FALSE;
1096 if(infoPtr->dwStyle & MCS_MULTISELECT)
1098 /* adjust timestamps */
1099 if(!MONTHCAL_ValidateTime(&range[0]))
1100 MONTHCAL_CopyTime(&infoPtr->todaysDate, &range[0]);
1101 if(!MONTHCAL_ValidateTime(&range[1]))
1102 MONTHCAL_CopyTime(&infoPtr->todaysDate, &range[1]);
1104 infoPtr->minSel = range[0];
1105 infoPtr->maxSel = range[1];
1107 TRACE("[min,max]=[%d %d]\n", infoPtr->minSel.wDay, infoPtr->maxSel.wDay);
1116 MONTHCAL_GetToday(const MONTHCAL_INFO *infoPtr, SYSTEMTIME *today)
1118 TRACE("%p\n", today);
1120 if(!today) return FALSE;
1121 *today = infoPtr->todaysDate;
1127 MONTHCAL_SetToday(MONTHCAL_INFO *infoPtr, SYSTEMTIME *today)
1129 TRACE("%p\n", today);
1131 if(!today) return FALSE;
1133 if(MONTHCAL_IsDateEqual(today, &infoPtr->todaysDate)) return TRUE;
1135 infoPtr->todaysDate = *today;
1136 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1142 MONTHCAL_HitTest(const MONTHCAL_INFO *infoPtr, MCHITTESTINFO *lpht)
1148 if(!lpht || lpht->cbSize < MCHITTESTINFO_V1_SIZE) return -1;
1153 ZeroMemory(&lpht->st, sizeof(lpht->st));
1155 /* Comment in for debugging...
1156 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,
1157 infoPtr->wdays.left, infoPtr->wdays.right,
1158 infoPtr->wdays.top, infoPtr->wdays.bottom,
1159 infoPtr->days.left, infoPtr->days.right,
1160 infoPtr->days.top, infoPtr->days.bottom,
1161 infoPtr->todayrect.left, infoPtr->todayrect.right,
1162 infoPtr->todayrect.top, infoPtr->todayrect.bottom,
1163 infoPtr->weeknums.left, infoPtr->weeknums.right,
1164 infoPtr->weeknums.top, infoPtr->weeknums.bottom);
1167 /* are we in the header? */
1169 if(PtInRect(&infoPtr->title, lpht->pt)) {
1170 if(PtInRect(&infoPtr->titlebtnprev, lpht->pt)) {
1171 retval = MCHT_TITLEBTNPREV;
1174 if(PtInRect(&infoPtr->titlebtnnext, lpht->pt)) {
1175 retval = MCHT_TITLEBTNNEXT;
1178 if(PtInRect(&infoPtr->titlemonth, lpht->pt)) {
1179 retval = MCHT_TITLEMONTH;
1182 if(PtInRect(&infoPtr->titleyear, lpht->pt)) {
1183 retval = MCHT_TITLEYEAR;
1187 retval = MCHT_TITLE;
1191 day = MONTHCAL_CalcDayFromPos(infoPtr,x,y,&wday,&wnum);
1192 if(PtInRect(&infoPtr->wdays, lpht->pt)) {
1193 retval = MCHT_CALENDARDAY;
1194 lpht->st.wYear = infoPtr->curSel.wYear;
1195 lpht->st.wMonth = (day < 1)? infoPtr->curSel.wMonth -1 : infoPtr->curSel.wMonth;
1196 lpht->st.wDay = (day < 1)?
1197 MONTHCAL_MonthLength(infoPtr->curSel.wMonth-1, infoPtr->curSel.wYear) -day : day;
1200 if(PtInRect(&infoPtr->weeknums, lpht->pt)) {
1201 retval = MCHT_CALENDARWEEKNUM;
1202 lpht->st.wYear = infoPtr->curSel.wYear;
1203 lpht->st.wMonth = (day < 1) ? infoPtr->curSel.wMonth -1 :
1204 (day > MONTHCAL_MonthLength(infoPtr->curSel.wMonth,infoPtr->curSel.wYear)) ?
1205 infoPtr->curSel.wMonth +1 :infoPtr->curSel.wMonth;
1206 lpht->st.wDay = (day < 1 ) ?
1207 MONTHCAL_MonthLength(infoPtr->curSel.wMonth-1,infoPtr->curSel.wYear) -day :
1208 (day > MONTHCAL_MonthLength(infoPtr->curSel.wMonth,infoPtr->curSel.wYear)) ?
1209 day - MONTHCAL_MonthLength(infoPtr->curSel.wMonth,infoPtr->curSel.wYear) : day;
1212 if(PtInRect(&infoPtr->days, lpht->pt))
1214 lpht->st.wYear = infoPtr->curSel.wYear;
1217 retval = MCHT_CALENDARDATEPREV;
1218 lpht->st.wMonth = infoPtr->curSel.wMonth - 1;
1219 if (lpht->st.wMonth < 1)
1221 lpht->st.wMonth = 12;
1224 lpht->st.wDay = MONTHCAL_MonthLength(lpht->st.wMonth,lpht->st.wYear) + day;
1226 else if (day > MONTHCAL_MonthLength(infoPtr->curSel.wMonth,infoPtr->curSel.wYear))
1228 retval = MCHT_CALENDARDATENEXT;
1229 lpht->st.wMonth = infoPtr->curSel.wMonth + 1;
1230 if (lpht->st.wMonth > 12)
1232 lpht->st.wMonth = 1;
1235 lpht->st.wDay = day - MONTHCAL_MonthLength(infoPtr->curSel.wMonth,infoPtr->curSel.wYear);
1238 retval = MCHT_CALENDARDATE;
1239 lpht->st.wMonth = infoPtr->curSel.wMonth;
1240 lpht->st.wDay = day;
1241 lpht->st.wDayOfWeek = MONTHCAL_CalculateDayOfWeek(day,lpht->st.wMonth,lpht->st.wYear);
1245 if(PtInRect(&infoPtr->todayrect, lpht->pt)) {
1246 retval = MCHT_TODAYLINK;
1251 /* Hit nothing special? What's left must be background :-) */
1253 retval = MCHT_CALENDARBK;
1255 lpht->uHit = retval;
1259 /* MCN_GETDAYSTATE notification helper */
1260 static void MONTHCAL_NotifyDayState(MONTHCAL_INFO *infoPtr)
1262 if(infoPtr->dwStyle & MCS_DAYSTATE) {
1266 nmds.nmhdr.hwndFrom = infoPtr->hwndSelf;
1267 nmds.nmhdr.idFrom = GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_ID);
1268 nmds.nmhdr.code = MCN_GETDAYSTATE;
1269 nmds.cDayState = infoPtr->monthRange;
1270 nmds.prgDayState = Alloc(infoPtr->monthRange * sizeof(MONTHDAYSTATE));
1272 nmds.stStart = infoPtr->todaysDate;
1273 nmds.stStart.wYear = infoPtr->curSel.wYear;
1274 nmds.stStart.wMonth = infoPtr->curSel.wMonth;
1275 nmds.stStart.wDay = 1;
1277 SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, nmds.nmhdr.idFrom, (LPARAM)&nmds);
1278 for(i = 0; i < infoPtr->monthRange; i++)
1279 infoPtr->monthdayState[i] = nmds.prgDayState[i];
1281 Free(nmds.prgDayState);
1285 static void MONTHCAL_GoToNextMonth(MONTHCAL_INFO *infoPtr)
1287 SYSTEMTIME next = infoPtr->curSel;
1292 if(next.wMonth > 12) {
1297 /* prevent max range exceeding */
1298 if(infoPtr->rangeValid & GDTR_MAX)
1300 FILETIME ft_next, ft_max;
1302 SystemTimeToFileTime(&infoPtr->maxDate, &ft_max);
1303 SystemTimeToFileTime(&next, &ft_next);
1305 if (CompareFileTime(&ft_next, &ft_max) > 0) return;
1308 infoPtr->curSel = next;
1310 MONTHCAL_NotifyDayState(infoPtr);
1314 static void MONTHCAL_GoToPrevMonth(MONTHCAL_INFO *infoPtr)
1316 SYSTEMTIME prev = infoPtr->curSel;
1321 if(prev.wMonth < 1) {
1326 /* prevent min range exceeding */
1327 if(infoPtr->rangeValid & GDTR_MIN)
1329 FILETIME ft_prev, ft_min;
1331 SystemTimeToFileTime(&infoPtr->minDate, &ft_min);
1332 SystemTimeToFileTime(&prev, &ft_prev);
1334 if (CompareFileTime(&ft_prev, &ft_min) < 0) return;
1337 infoPtr->curSel = prev;
1339 MONTHCAL_NotifyDayState(infoPtr);
1343 MONTHCAL_RButtonUp(MONTHCAL_INFO *infoPtr, LPARAM lParam)
1345 static const WCHAR todayW[] = { 'G','o',' ','t','o',' ','T','o','d','a','y',':',0 };
1350 hMenu = CreatePopupMenu();
1351 if (!LoadStringW(COMCTL32_hModule, IDM_GOTODAY, buf, countof(buf)))
1353 WARN("Can't load resource\n");
1354 strcpyW(buf, todayW);
1356 AppendMenuW(hMenu, MF_STRING|MF_ENABLED, 1, buf);
1357 menupoint.x = (short)LOWORD(lParam);
1358 menupoint.y = (short)HIWORD(lParam);
1359 ClientToScreen(infoPtr->hwndSelf, &menupoint);
1360 if( TrackPopupMenu(hMenu, TPM_RIGHTBUTTON | TPM_NONOTIFY | TPM_RETURNCMD,
1361 menupoint.x, menupoint.y, 0, infoPtr->hwndSelf, NULL))
1363 infoPtr->curSel = infoPtr->todaysDate;
1364 infoPtr->minSel = infoPtr->todaysDate;
1365 infoPtr->maxSel = infoPtr->todaysDate;
1366 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1372 /* creates updown control and edit box */
1373 static void MONTHCAL_EditYear(MONTHCAL_INFO *infoPtr)
1375 static const WCHAR EditW[] = { 'E','D','I','T',0 };
1377 infoPtr->hWndYearEdit =
1378 CreateWindowExW(0, EditW, 0, WS_VISIBLE | WS_CHILD | ES_READONLY,
1379 infoPtr->titleyear.left + 3, infoPtr->titlebtnnext.top,
1380 infoPtr->titleyear.right - infoPtr->titleyear.left + 4,
1381 infoPtr->textHeight, infoPtr->hwndSelf,
1384 SendMessageW(infoPtr->hWndYearEdit, WM_SETFONT, (WPARAM)infoPtr->hBoldFont, TRUE);
1386 infoPtr->hWndYearUpDown =
1387 CreateWindowExW(0, UPDOWN_CLASSW, 0,
1388 WS_VISIBLE | WS_CHILD | UDS_SETBUDDYINT | UDS_NOTHOUSANDS | UDS_ARROWKEYS,
1389 infoPtr->titleyear.right + 7, infoPtr->titlebtnnext.top,
1390 18, infoPtr->textHeight, infoPtr->hwndSelf,
1393 /* attach edit box */
1394 SendMessageW(infoPtr->hWndYearUpDown, UDM_SETRANGE, 0, MAKELONG(9999, 1753));
1395 SendMessageW(infoPtr->hWndYearUpDown, UDM_SETBUDDY, (WPARAM)infoPtr->hWndYearEdit, 0);
1396 SendMessageW(infoPtr->hWndYearUpDown, UDM_SETPOS, 0, infoPtr->curSel.wYear);
1400 MONTHCAL_LButtonDown(MONTHCAL_INFO *infoPtr, LPARAM lParam)
1405 if (infoPtr->hWndYearUpDown)
1407 infoPtr->curSel.wYear = SendMessageW(infoPtr->hWndYearUpDown, UDM_SETPOS, 0, 0);
1408 if(!DestroyWindow(infoPtr->hWndYearUpDown))
1410 FIXME("Can't destroy Updown Control\n");
1413 infoPtr->hWndYearUpDown = 0;
1415 if(!DestroyWindow(infoPtr->hWndYearEdit))
1417 FIXME("Can't destroy Updown Control\n");
1420 infoPtr->hWndYearEdit = 0;
1422 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1425 ht.cbSize = sizeof(MCHITTESTINFO);
1426 ht.pt.x = (short)LOWORD(lParam);
1427 ht.pt.y = (short)HIWORD(lParam);
1428 TRACE("(%d, %d)\n", ht.pt.x, ht.pt.y);
1430 hit = MONTHCAL_HitTest(infoPtr, &ht);
1434 case MCHT_TITLEBTNNEXT:
1435 MONTHCAL_GoToNextMonth(infoPtr);
1436 infoPtr->status = MC_NEXTPRESSED;
1437 SetTimer(infoPtr->hwndSelf, MC_NEXTMONTHTIMER, MC_NEXTMONTHDELAY, 0);
1438 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1441 case MCHT_TITLEBTNPREV:
1442 MONTHCAL_GoToPrevMonth(infoPtr);
1443 infoPtr->status = MC_PREVPRESSED;
1444 SetTimer(infoPtr->hwndSelf, MC_PREVMONTHTIMER, MC_NEXTMONTHDELAY, 0);
1445 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1448 case MCHT_TITLEMONTH:
1450 HMENU hMenu = CreatePopupMenu();
1455 for (i = 0; i < 12; i++)
1457 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SMONTHNAME1+i, buf, countof(buf));
1458 AppendMenuW(hMenu, MF_STRING|MF_ENABLED, i + 1, buf);
1460 menupoint.x = ht.pt.x;
1461 menupoint.y = ht.pt.y;
1462 ClientToScreen(infoPtr->hwndSelf, &menupoint);
1463 i = TrackPopupMenu(hMenu,TPM_LEFTALIGN | TPM_NONOTIFY | TPM_RIGHTBUTTON | TPM_RETURNCMD,
1464 menupoint.x, menupoint.y, 0, infoPtr->hwndSelf, NULL);
1466 if ((i > 0) && (i < 13))
1468 infoPtr->curSel.wMonth = i;
1469 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1473 case MCHT_TITLEYEAR:
1475 MONTHCAL_EditYear(infoPtr);
1478 case MCHT_TODAYLINK:
1482 infoPtr->firstSelDay = infoPtr->todaysDate.wDay;
1483 infoPtr->curSel = infoPtr->todaysDate;
1484 infoPtr->minSel = infoPtr->todaysDate;
1485 infoPtr->maxSel = infoPtr->todaysDate;
1486 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1488 nmsc.nmhdr.hwndFrom = infoPtr->hwndSelf;
1489 nmsc.nmhdr.idFrom = GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_ID);
1490 nmsc.nmhdr.code = MCN_SELCHANGE;
1491 nmsc.stSelStart = infoPtr->minSel;
1492 nmsc.stSelEnd = infoPtr->maxSel;
1493 SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, nmsc.nmhdr.idFrom, (LPARAM)&nmsc);
1495 nmsc.nmhdr.code = MCN_SELECT;
1496 SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, nmsc.nmhdr.idFrom, (LPARAM)&nmsc);
1499 case MCHT_CALENDARDATE:
1501 RECT rcDay; /* used in determining area to invalidate */
1502 SYSTEMTIME selArray[2];
1505 selArray[0] = ht.st;
1506 selArray[1] = ht.st;
1507 MONTHCAL_SetSelRange(infoPtr, selArray);
1508 MONTHCAL_SetCurSel(infoPtr, &selArray[0]);
1509 TRACE("MCHT_CALENDARDATE\n");
1510 nmsc.nmhdr.hwndFrom = infoPtr->hwndSelf;
1511 nmsc.nmhdr.idFrom = GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_ID);
1512 nmsc.nmhdr.code = MCN_SELCHANGE;
1513 nmsc.stSelStart = infoPtr->minSel;
1514 nmsc.stSelEnd = infoPtr->maxSel;
1516 SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, nmsc.nmhdr.idFrom, (LPARAM)&nmsc);
1518 /* redraw both old and new days if the selected day changed */
1519 if(infoPtr->curSel.wDay != ht.st.wDay) {
1520 MONTHCAL_CalcPosFromDay(infoPtr, ht.st.wDay, ht.st.wMonth, &rcDay);
1521 InvalidateRect(infoPtr->hwndSelf, &rcDay, TRUE);
1523 MONTHCAL_CalcPosFromDay(infoPtr, infoPtr->curSel.wDay, infoPtr->curSel.wMonth, &rcDay);
1524 InvalidateRect(infoPtr->hwndSelf, &rcDay, TRUE);
1527 infoPtr->firstSelDay = ht.st.wDay;
1528 infoPtr->curSel.wDay = ht.st.wDay;
1529 infoPtr->status = MC_SEL_LBUTDOWN;
1539 MONTHCAL_LButtonUp(MONTHCAL_INFO *infoPtr, LPARAM lParam)
1543 BOOL redraw = FALSE;
1549 if(infoPtr->status & MC_NEXTPRESSED) {
1550 KillTimer(infoPtr->hwndSelf, MC_NEXTMONTHTIMER);
1551 infoPtr->status &= ~MC_NEXTPRESSED;
1554 if(infoPtr->status & MC_PREVPRESSED) {
1555 KillTimer(infoPtr->hwndSelf, MC_PREVMONTHTIMER);
1556 infoPtr->status &= ~MC_PREVPRESSED;
1560 ht.cbSize = sizeof(MCHITTESTINFO);
1561 ht.pt.x = (short)LOWORD(lParam);
1562 ht.pt.y = (short)HIWORD(lParam);
1563 hit = MONTHCAL_HitTest(infoPtr, &ht);
1565 infoPtr->status = MC_SEL_LBUTUP;
1567 if(hit == MCHT_CALENDARDATENEXT) {
1568 MONTHCAL_GoToNextMonth(infoPtr);
1569 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1572 if(hit == MCHT_CALENDARDATEPREV){
1573 MONTHCAL_GoToPrevMonth(infoPtr);
1574 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1577 nmhdr.hwndFrom = infoPtr->hwndSelf;
1578 nmhdr.idFrom = GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_ID);
1579 nmhdr.code = NM_RELEASEDCAPTURE;
1580 TRACE("Sent notification from %p to %p\n", infoPtr->hwndSelf, infoPtr->hwndNotify);
1582 SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, nmhdr.idFrom, (LPARAM)&nmhdr);
1583 /* redraw if necessary */
1585 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1586 /* only send MCN_SELECT if currently displayed month's day was selected */
1587 if(hit == MCHT_CALENDARDATE) {
1588 nmsc.nmhdr.hwndFrom = infoPtr->hwndSelf;
1589 nmsc.nmhdr.idFrom = GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_ID);
1590 nmsc.nmhdr.code = MCN_SELECT;
1591 nmsc.stSelStart = infoPtr->minSel;
1592 nmsc.stSelEnd = infoPtr->maxSel;
1594 SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, nmsc.nmhdr.idFrom, (LPARAM)&nmsc);
1602 MONTHCAL_Timer(MONTHCAL_INFO *infoPtr, WPARAM wParam)
1604 BOOL redraw = FALSE;
1606 TRACE("%ld\n", wParam);
1609 case MC_NEXTMONTHTIMER:
1611 MONTHCAL_GoToNextMonth(infoPtr);
1613 case MC_PREVMONTHTIMER:
1615 MONTHCAL_GoToPrevMonth(infoPtr);
1618 ERR("got unknown timer\n");
1622 /* redraw only if necessary */
1624 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1631 MONTHCAL_MouseMove(MONTHCAL_INFO *infoPtr, LPARAM lParam)
1634 int oldselday, selday, hit;
1637 if(!(infoPtr->status & MC_SEL_LBUTDOWN)) return 0;
1639 ht.cbSize = sizeof(MCHITTESTINFO);
1640 ht.pt.x = (short)LOWORD(lParam);
1641 ht.pt.y = (short)HIWORD(lParam);
1643 hit = MONTHCAL_HitTest(infoPtr, &ht);
1645 /* not on the calendar date numbers? bail out */
1646 TRACE("hit:%x\n",hit);
1647 if((hit & MCHT_CALENDARDATE) != MCHT_CALENDARDATE) return 0;
1649 selday = ht.st.wDay;
1650 oldselday = infoPtr->curSel.wDay;
1651 infoPtr->curSel.wDay = selday;
1652 MONTHCAL_CalcPosFromDay(infoPtr, selday, ht.st. wMonth, &r);
1654 if(infoPtr->dwStyle & MCS_MULTISELECT) {
1655 SYSTEMTIME selArray[2];
1658 MONTHCAL_GetSelRange(infoPtr, selArray);
1660 if(infoPtr->firstSelDay==selArray[0].wDay) i=1;
1661 TRACE("oldRange:%d %d %d %d\n", infoPtr->firstSelDay, selArray[0].wDay, selArray[1].wDay, i);
1662 if(infoPtr->firstSelDay==selArray[1].wDay) {
1663 /* 1st time we get here: selArray[0]=selArray[1]) */
1664 /* if we're still at the first selected date, return */
1665 if(infoPtr->firstSelDay==selday) goto done;
1666 if(selday<infoPtr->firstSelDay) i = 0;
1669 if(abs(infoPtr->firstSelDay - selday) >= infoPtr->maxSelCount) {
1670 if(selday>infoPtr->firstSelDay)
1671 selday = infoPtr->firstSelDay + infoPtr->maxSelCount;
1673 selday = infoPtr->firstSelDay - infoPtr->maxSelCount;
1676 if(selArray[i].wDay!=selday) {
1677 TRACE("newRange:%d %d %d %d\n", infoPtr->firstSelDay, selArray[0].wDay, selArray[1].wDay, i);
1679 selArray[i].wDay = selday;
1681 if(selArray[0].wDay>selArray[1].wDay) {
1683 tempday = selArray[1].wDay;
1684 selArray[1].wDay = selArray[0].wDay;
1685 selArray[0].wDay = tempday;
1688 MONTHCAL_SetSelRange(infoPtr, selArray);
1694 /* only redraw if the currently selected day changed */
1695 /* FIXME: this should specify a rectangle containing only the days that changed */
1696 /* using InvalidateRect */
1697 if(oldselday != infoPtr->curSel.wDay)
1698 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1705 MONTHCAL_Paint(MONTHCAL_INFO *infoPtr, HDC hdc_paint)
1712 GetClientRect(infoPtr->hwndSelf, &ps.rcPaint);
1716 hdc = BeginPaint(infoPtr->hwndSelf, &ps);
1718 MONTHCAL_Refresh(infoPtr, hdc, &ps);
1719 if (!hdc_paint) EndPaint(infoPtr->hwndSelf, &ps);
1725 MONTHCAL_KillFocus(const MONTHCAL_INFO *infoPtr, HWND hFocusWnd)
1729 if (infoPtr->hwndNotify != hFocusWnd)
1730 ShowWindow(infoPtr->hwndSelf, SW_HIDE);
1732 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
1739 MONTHCAL_SetFocus(const MONTHCAL_INFO *infoPtr)
1743 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1748 /* sets the size information */
1749 static void MONTHCAL_UpdateSize(MONTHCAL_INFO *infoPtr)
1751 static const WCHAR SunW[] = { 'S','u','n',0 };
1752 static const WCHAR O0W[] = { '0','0',0 };
1753 HDC hdc = GetDC(infoPtr->hwndSelf);
1754 RECT *title=&infoPtr->title;
1755 RECT *prev=&infoPtr->titlebtnprev;
1756 RECT *next=&infoPtr->titlebtnnext;
1757 RECT *titlemonth=&infoPtr->titlemonth;
1758 RECT *titleyear=&infoPtr->titleyear;
1759 RECT *wdays=&infoPtr->wdays;
1760 RECT *weeknumrect=&infoPtr->weeknums;
1761 RECT *days=&infoPtr->days;
1762 RECT *todayrect=&infoPtr->todayrect;
1769 GetClientRect(infoPtr->hwndSelf, &rcClient);
1771 currentFont = SelectObject(hdc, infoPtr->hFont);
1773 /* get the height and width of each day's text */
1774 GetTextMetricsW(hdc, &tm);
1775 infoPtr->textHeight = tm.tmHeight + tm.tmExternalLeading + tm.tmInternalLeading;
1776 GetTextExtentPoint32W(hdc, SunW, 3, &size);
1777 infoPtr->textWidth = size.cx + 2;
1779 /* recalculate the height and width increments and offsets */
1780 GetTextExtentPoint32W(hdc, O0W, 2, &size);
1782 xdiv = (infoPtr->dwStyle & MCS_WEEKNUMBERS) ? 8 : 7;
1784 infoPtr->width_increment = size.cx * 2 + 4;
1785 infoPtr->height_increment = infoPtr->textHeight;
1787 /* calculate title area */
1789 title->bottom = 3 * infoPtr->height_increment / 2;
1791 title->right = infoPtr->width_increment * xdiv;
1793 /* set the dimensions of the next and previous buttons and center */
1794 /* the month text vertically */
1795 prev->top = next->top = title->top + 4;
1796 prev->bottom = next->bottom = title->bottom - 4;
1797 prev->left = title->left + 4;
1798 prev->right = prev->left + (title->bottom - title->top);
1799 next->right = title->right - 4;
1800 next->left = next->right - (title->bottom - title->top);
1802 /* titlemonth->left and right change based upon the current month */
1803 /* and are recalculated in refresh as the current month may change */
1804 /* without the control being resized */
1805 titlemonth->top = titleyear->top = title->top + (infoPtr->height_increment)/2;
1806 titlemonth->bottom = titleyear->bottom = title->bottom - (infoPtr->height_increment)/2;
1808 /* setup the dimensions of the rectangle we draw the names of the */
1809 /* days of the week in */
1810 weeknumrect->left = 0;
1812 if(infoPtr->dwStyle & MCS_WEEKNUMBERS)
1813 weeknumrect->right = prev->right;
1815 weeknumrect->right = weeknumrect->left;
1817 wdays->left = days->left = weeknumrect->right;
1818 wdays->right = days->right = wdays->left + 7 * infoPtr->width_increment;
1819 wdays->top = title->bottom;
1820 wdays->bottom = wdays->top + infoPtr->height_increment;
1822 days->top = weeknumrect->top = wdays->bottom;
1823 days->bottom = weeknumrect->bottom = days->top + 6 * infoPtr->height_increment;
1825 todayrect->left = 0;
1826 todayrect->right = title->right;
1827 todayrect->top = days->bottom;
1828 todayrect->bottom = days->bottom + infoPtr->height_increment;
1830 /* offset all rectangles to center in client area */
1831 dx = (rcClient.right - title->right) / 2;
1832 dy = (rcClient.bottom - todayrect->bottom) / 2;
1834 /* if calendar doesn't fit client area show it at left/top bounds */
1835 if (title->left + dx < 0) dx = 0;
1836 if (title->top + dy < 0) dy = 0;
1838 if (dx != 0 || dy != 0)
1840 OffsetRect(title, dx, dy);
1841 OffsetRect(prev, dx, dy);
1842 OffsetRect(next, dx, dy);
1843 OffsetRect(titlemonth, dx, dy);
1844 OffsetRect(titleyear, dx, dy);
1845 OffsetRect(wdays, dx, dy);
1846 OffsetRect(weeknumrect, dx, dy);
1847 OffsetRect(days, dx, dy);
1848 OffsetRect(todayrect, dx, dy);
1851 TRACE("dx=%d dy=%d client[%s] title[%s] wdays[%s] days[%s] today[%s]\n",
1852 infoPtr->width_increment,infoPtr->height_increment,
1853 wine_dbgstr_rect(&rcClient),
1854 wine_dbgstr_rect(title),
1855 wine_dbgstr_rect(wdays),
1856 wine_dbgstr_rect(days),
1857 wine_dbgstr_rect(todayrect));
1859 /* restore the originally selected font */
1860 SelectObject(hdc, currentFont);
1862 ReleaseDC(infoPtr->hwndSelf, hdc);
1865 static LRESULT MONTHCAL_Size(MONTHCAL_INFO *infoPtr, int Width, int Height)
1867 TRACE("(width=%d, height=%d)\n", Width, Height);
1869 MONTHCAL_UpdateSize(infoPtr);
1871 /* invalidate client area and erase background */
1872 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
1877 static LRESULT MONTHCAL_GetFont(const MONTHCAL_INFO *infoPtr)
1879 return (LRESULT)infoPtr->hFont;
1882 static LRESULT MONTHCAL_SetFont(MONTHCAL_INFO *infoPtr, HFONT hFont, BOOL redraw)
1887 if (!hFont) return 0;
1889 hOldFont = infoPtr->hFont;
1890 infoPtr->hFont = hFont;
1892 GetObjectW(infoPtr->hFont, sizeof(lf), &lf);
1893 lf.lfWeight = FW_BOLD;
1894 infoPtr->hBoldFont = CreateFontIndirectW(&lf);
1896 MONTHCAL_UpdateSize(infoPtr);
1899 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1901 return (LRESULT)hOldFont;
1904 /* update theme after a WM_THEMECHANGED message */
1905 static LRESULT theme_changed (const MONTHCAL_INFO* infoPtr)
1907 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
1908 CloseThemeData (theme);
1909 OpenThemeData (infoPtr->hwndSelf, themeClass);
1913 static INT MONTHCAL_StyleChanged(MONTHCAL_INFO *infoPtr, WPARAM wStyleType,
1914 const STYLESTRUCT *lpss)
1916 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
1917 wStyleType, lpss->styleOld, lpss->styleNew);
1919 if (wStyleType != GWL_STYLE) return 0;
1921 infoPtr->dwStyle = lpss->styleNew;
1926 /* FIXME: check whether dateMin/dateMax need to be adjusted. */
1928 MONTHCAL_Create(HWND hwnd, LPCREATESTRUCTW lpcs)
1930 MONTHCAL_INFO *infoPtr;
1932 /* allocate memory for info structure */
1933 infoPtr = Alloc(sizeof(MONTHCAL_INFO));
1934 SetWindowLongPtrW(hwnd, 0, (DWORD_PTR)infoPtr);
1936 if(infoPtr == NULL) {
1937 ERR( "could not allocate info memory!\n");
1941 infoPtr->hwndSelf = hwnd;
1942 infoPtr->hwndNotify = lpcs->hwndParent;
1943 infoPtr->dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
1945 MONTHCAL_SetFont(infoPtr, GetStockObject(DEFAULT_GUI_FONT), FALSE);
1947 /* initialize info structure */
1948 /* FIXME: calculate systemtime ->> localtime(substract timezoneinfo) */
1950 GetLocalTime(&infoPtr->todaysDate);
1951 infoPtr->firstDayHighWord = FALSE;
1952 MONTHCAL_SetFirstDayOfWeek(infoPtr, -1);
1954 infoPtr->maxSelCount = 7;
1955 infoPtr->monthRange = 3;
1956 infoPtr->monthdayState = Alloc(infoPtr->monthRange * sizeof(MONTHDAYSTATE));
1957 infoPtr->titlebk = comctl32_color.clrActiveCaption;
1958 infoPtr->titletxt = comctl32_color.clrWindow;
1959 infoPtr->monthbk = comctl32_color.clrWindow;
1960 infoPtr->trailingtxt = comctl32_color.clrGrayText;
1961 infoPtr->bk = comctl32_color.clrWindow;
1962 infoPtr->txt = comctl32_color.clrWindowText;
1964 infoPtr->minSel = infoPtr->todaysDate;
1965 infoPtr->maxSel = infoPtr->todaysDate;
1966 infoPtr->curSel = infoPtr->todaysDate;
1968 /* call MONTHCAL_UpdateSize to set all of the dimensions */
1969 /* of the control */
1970 MONTHCAL_UpdateSize(infoPtr);
1972 OpenThemeData (infoPtr->hwndSelf, themeClass);
1979 MONTHCAL_Destroy(MONTHCAL_INFO *infoPtr)
1981 /* free month calendar info data */
1982 Free(infoPtr->monthdayState);
1983 SetWindowLongPtrW(infoPtr->hwndSelf, 0, 0);
1985 CloseThemeData (GetWindowTheme (infoPtr->hwndSelf));
1992 static LRESULT WINAPI
1993 MONTHCAL_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1995 MONTHCAL_INFO *infoPtr;
1997 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n", hwnd, uMsg, wParam, lParam);
1999 infoPtr = MONTHCAL_GetInfoPtr(hwnd);
2000 if (!infoPtr && (uMsg != WM_CREATE))
2001 return DefWindowProcW(hwnd, uMsg, wParam, lParam);
2005 return MONTHCAL_GetCurSel(infoPtr, (LPSYSTEMTIME)lParam);
2008 return MONTHCAL_SetCurSel(infoPtr, (LPSYSTEMTIME)lParam);
2010 case MCM_GETMAXSELCOUNT:
2011 return MONTHCAL_GetMaxSelCount(infoPtr);
2013 case MCM_SETMAXSELCOUNT:
2014 return MONTHCAL_SetMaxSelCount(infoPtr, wParam);
2016 case MCM_GETSELRANGE:
2017 return MONTHCAL_GetSelRange(infoPtr, (LPSYSTEMTIME)lParam);
2019 case MCM_SETSELRANGE:
2020 return MONTHCAL_SetSelRange(infoPtr, (LPSYSTEMTIME)lParam);
2022 case MCM_GETMONTHRANGE:
2023 return MONTHCAL_GetMonthRange(infoPtr);
2025 case MCM_SETDAYSTATE:
2026 return MONTHCAL_SetDayState(infoPtr, (INT)wParam, (LPMONTHDAYSTATE)lParam);
2028 case MCM_GETMINREQRECT:
2029 return MONTHCAL_GetMinReqRect(infoPtr, (LPRECT)lParam);
2032 return MONTHCAL_GetColor(infoPtr, wParam);
2035 return MONTHCAL_SetColor(infoPtr, wParam, (COLORREF)lParam);
2038 return MONTHCAL_GetToday(infoPtr, (LPSYSTEMTIME)lParam);
2041 return MONTHCAL_SetToday(infoPtr, (LPSYSTEMTIME)lParam);
2044 return MONTHCAL_HitTest(infoPtr, (PMCHITTESTINFO)lParam);
2046 case MCM_GETFIRSTDAYOFWEEK:
2047 return MONTHCAL_GetFirstDayOfWeek(infoPtr);
2049 case MCM_SETFIRSTDAYOFWEEK:
2050 return MONTHCAL_SetFirstDayOfWeek(infoPtr, (INT)lParam);
2053 return MONTHCAL_GetRange(infoPtr, (LPSYSTEMTIME)lParam);
2056 return MONTHCAL_SetRange(infoPtr, (SHORT)wParam, (LPSYSTEMTIME)lParam);
2058 case MCM_GETMONTHDELTA:
2059 return MONTHCAL_GetMonthDelta(infoPtr);
2061 case MCM_SETMONTHDELTA:
2062 return MONTHCAL_SetMonthDelta(infoPtr, wParam);
2064 case MCM_GETMAXTODAYWIDTH:
2065 return MONTHCAL_GetMaxTodayWidth(infoPtr);
2068 return DLGC_WANTARROWS | DLGC_WANTCHARS;
2071 return MONTHCAL_KillFocus(infoPtr, (HWND)wParam);
2074 return MONTHCAL_RButtonUp(infoPtr, lParam);
2076 case WM_LBUTTONDOWN:
2077 return MONTHCAL_LButtonDown(infoPtr, lParam);
2080 return MONTHCAL_MouseMove(infoPtr, lParam);
2083 return MONTHCAL_LButtonUp(infoPtr, lParam);
2085 case WM_PRINTCLIENT:
2087 return MONTHCAL_Paint(infoPtr, (HDC)wParam);
2090 return MONTHCAL_SetFocus(infoPtr);
2093 return MONTHCAL_Size(infoPtr, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
2096 return MONTHCAL_Create(hwnd, (LPCREATESTRUCTW)lParam);
2099 return MONTHCAL_SetFont(infoPtr, (HFONT)wParam, (BOOL)lParam);
2102 return MONTHCAL_GetFont(infoPtr);
2105 return MONTHCAL_Timer(infoPtr, wParam);
2107 case WM_THEMECHANGED:
2108 return theme_changed (infoPtr);
2111 return MONTHCAL_Destroy(infoPtr);
2113 case WM_SYSCOLORCHANGE:
2114 COMCTL32_RefreshSysColors();
2117 case WM_STYLECHANGED:
2118 return MONTHCAL_StyleChanged(infoPtr, wParam, (LPSTYLESTRUCT)lParam);
2121 if ((uMsg >= WM_USER) && (uMsg < WM_APP) && !COMCTL32_IsReflectedMessage(uMsg))
2122 ERR( "unknown msg %04x wp=%08lx lp=%08lx\n", uMsg, wParam, lParam);
2123 return DefWindowProcW(hwnd, uMsg, wParam, lParam);
2129 MONTHCAL_Register(void)
2133 ZeroMemory(&wndClass, sizeof(WNDCLASSW));
2134 wndClass.style = CS_GLOBALCLASS;
2135 wndClass.lpfnWndProc = MONTHCAL_WindowProc;
2136 wndClass.cbClsExtra = 0;
2137 wndClass.cbWndExtra = sizeof(MONTHCAL_INFO *);
2138 wndClass.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
2139 wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
2140 wndClass.lpszClassName = MONTHCAL_CLASSW;
2142 RegisterClassW(&wndClass);
2147 MONTHCAL_Unregister(void)
2149 UnregisterClassW(MONTHCAL_CLASSW, NULL);