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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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
37 * -- handle resources better (doesn't work now);
38 * -- take care of internationalization.
39 * -- keyboard handling.
40 * -- GetRange: At the moment, we copy ranges anyway, regardless of
41 * infoPtr->rangeValid; a invalid range is simply filled
42 * with zeros in SetRange. Is this the right behavior?
59 #include "wine/debug.h"
61 WINE_DEFAULT_DEBUG_CHANNEL(monthcal);
63 #define MC_SEL_LBUTUP 1 /* Left button released */
64 #define MC_SEL_LBUTDOWN 2 /* Left button pressed in calendar */
65 #define MC_PREVPRESSED 4 /* Prev month button pressed */
66 #define MC_NEXTPRESSED 8 /* Next month button pressed */
67 #define MC_NEXTMONTHDELAY 350 /* when continuously pressing `next */
68 /* month', wait 500 ms before going */
69 /* to the next month */
70 #define MC_NEXTMONTHTIMER 1 /* Timer ID's */
71 #define MC_PREVMONTHTIMER 2
89 int firstDayplace; /* place of the first day of the current month */
90 int delta; /* scroll rate; # of months that the */
91 /* control moves when user clicks a scroll button */
92 int visible; /* # of months visible */
93 int firstDay; /* Start month calendar with firstDay's day */
95 MONTHDAYSTATE *monthdayState;
96 SYSTEMTIME todaysDate;
99 int status; /* See MC_SEL flags */
100 int curSelDay; /* current selected day */
101 int firstSelDay; /* first selected day */
109 RECT rcClient; /* rect for whole client area */
110 RECT rcDraw; /* rect for drawable portion of client area */
111 RECT title; /* rect for the header above the calendar */
112 RECT titlebtnnext; /* the `next month' button in the header */
113 RECT titlebtnprev; /* the `prev month' button in the header */
114 RECT titlemonth; /* the `month name' txt in the header */
115 RECT titleyear; /* the `year number' txt in the header */
116 RECT wdays; /* week days at top */
117 RECT days; /* calendar area */
118 RECT weeknums; /* week numbers at left side */
119 RECT todayrect; /* `today: xx/xx/xx' text rect */
120 HWND hwndNotify; /* Window to receive the notifications */
121 HWND hWndYearEdit; /* Window Handle of edit box to handle years */
122 HWND hWndYearUpDown;/* Window Handle of updown box to handle years */
123 } MONTHCAL_INFO, *LPMONTHCAL_INFO;
126 /* Offsets of days in the week to the weekday of january 1. */
127 static const int DayOfWeekTable[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
130 #define MONTHCAL_GetInfoPtr(hwnd) ((MONTHCAL_INFO *)GetWindowLongPtrW(hwnd, 0))
132 /* helper functions */
134 /* returns the number of days in any given month, checking for leap days */
135 /* january is 1, december is 12 */
136 int MONTHCAL_MonthLength(int month, int year)
138 const int mdays[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 0};
139 /*Wrap around, this eases handling*/
145 /* if we have a leap year add 1 day to February */
146 /* a leap year is a year either divisible by 400 */
147 /* or divisible by 4 and not by 100 */
148 if(month == 2) { /* February */
149 return mdays[month - 1] + ((year%400 == 0) ? 1 : ((year%100 != 0) &&
150 (year%4 == 0)) ? 1 : 0);
153 return mdays[month - 1];
158 /* make sure that time is valid */
159 static int MONTHCAL_ValidateTime(SYSTEMTIME time)
161 if(time.wMonth > 12) return FALSE;
162 if(time.wDayOfWeek > 6) return FALSE;
163 if(time.wDay > MONTHCAL_MonthLength(time.wMonth, time.wYear))
165 if(time.wHour > 23) return FALSE;
166 if(time.wMinute > 59) return FALSE;
167 if(time.wSecond > 59) return FALSE;
168 if(time.wMilliseconds > 999) return FALSE;
174 void MONTHCAL_CopyTime(const SYSTEMTIME *from, SYSTEMTIME *to)
176 to->wYear = from->wYear;
177 to->wMonth = from->wMonth;
178 to->wDayOfWeek = from->wDayOfWeek;
179 to->wDay = from->wDay;
180 to->wHour = from->wHour;
181 to->wMinute = from->wMinute;
182 to->wSecond = from->wSecond;
183 to->wMilliseconds = from->wMilliseconds;
187 /* Note:Depending on DST, this may be offset by a day.
188 Need to find out if we're on a DST place & adjust the clock accordingly.
189 Above function assumes we have a valid data.
190 Valid for year>1752; 1 <= d <= 31, 1 <= m <= 12.
194 /* returns the day in the week(0 == monday, 6 == sunday) */
195 /* day(1 == 1st, 2 == 2nd... etc), year is the year value */
196 static int MONTHCAL_CalculateDayOfWeek(DWORD day, DWORD month, DWORD year)
200 return((year + year/4 - year/100 + year/400 +
201 DayOfWeekTable[month-1] + day - 1 ) % 7);
204 /* From a given point, calculate the row (weekpos), column(daypos)
205 and day in the calendar. day== 0 mean the last day of tha last month
207 static int MONTHCAL_CalcDayFromPos(MONTHCAL_INFO *infoPtr, int x, int y,
208 int *daypos,int *weekpos)
210 int retval, firstDay;
212 /* if the point is outside the x bounds of the window put
214 if(x > infoPtr->rcClient.right) {
215 x = infoPtr->rcClient.right ;
218 *daypos = (x - infoPtr->days.left ) / infoPtr->width_increment;
219 *weekpos = (y - infoPtr->days.top ) / infoPtr->height_increment;
221 firstDay = (MONTHCAL_CalculateDayOfWeek(1, infoPtr->currentMonth, infoPtr->currentYear)+6 - infoPtr->firstDay)%7;
222 retval = *daypos + (7 * *weekpos) - firstDay;
226 /* day is the day of the month, 1 == 1st day of the month */
227 /* sets x and y to be the position of the day */
228 /* x == day, y == week where(0,0) == firstDay, 1st week */
229 static void MONTHCAL_CalcDayXY(MONTHCAL_INFO *infoPtr, int day, int month,
232 int firstDay, prevMonth;
234 firstDay = (MONTHCAL_CalculateDayOfWeek(1, infoPtr->currentMonth, infoPtr->currentYear) +6 - infoPtr->firstDay)%7;
236 if(month==infoPtr->currentMonth) {
237 *x = (day + firstDay) % 7;
238 *y = (day + firstDay - *x) / 7;
241 if(month < infoPtr->currentMonth) {
242 prevMonth = month - 1;
246 *x = (MONTHCAL_MonthLength(prevMonth, infoPtr->currentYear) - firstDay) % 7;
251 *y = MONTHCAL_MonthLength(month, infoPtr->currentYear - 1) / 7;
252 *x = (day + firstDay + MONTHCAL_MonthLength(month,
253 infoPtr->currentYear)) % 7;
257 /* x: column(day), y: row(week) */
258 static void MONTHCAL_CalcDayRect(MONTHCAL_INFO *infoPtr, RECT *r, int x, int y)
260 r->left = infoPtr->days.left + x * infoPtr->width_increment;
261 r->right = r->left + infoPtr->width_increment;
262 r->top = infoPtr->days.top + y * infoPtr->height_increment;
263 r->bottom = r->top + infoPtr->textHeight;
267 /* sets the RECT struct r to the rectangle around the day and month */
268 /* day is the day value of the month(1 == 1st), month is the month */
269 /* value(january == 1, december == 12) */
270 static inline void MONTHCAL_CalcPosFromDay(MONTHCAL_INFO *infoPtr,
271 int day, int month, RECT *r)
275 MONTHCAL_CalcDayXY(infoPtr, day, month, &x, &y);
276 MONTHCAL_CalcDayRect(infoPtr, r, x, y);
280 /* day is the day in the month(1 == 1st of the month) */
281 /* month is the month value(1 == january, 12 == december) */
282 static void MONTHCAL_CircleDay(HDC hdc, MONTHCAL_INFO *infoPtr, int day,
285 HPEN hRedPen = CreatePen(PS_SOLID, 2, RGB(255, 0, 0));
286 HPEN hOldPen2 = SelectObject(hdc, hRedPen);
292 MONTHCAL_CalcPosFromDay(infoPtr, day, month, &day_rect);
299 points[1].x = x + 0.8 * infoPtr->width_increment;
301 points[2].x = x + 0.9 * infoPtr->width_increment;
303 points[3].x = x + infoPtr->width_increment;
304 points[3].y = y + 0.5 * infoPtr->height_increment;
306 points[4].x = x + infoPtr->width_increment;
307 points[4].y = y + 0.9 * infoPtr->height_increment;
308 points[5].x = x + 0.6 * infoPtr->width_increment;
309 points[5].y = y + 0.9 * infoPtr->height_increment;
310 points[6].x = x + 0.5 * infoPtr->width_increment;
311 points[6].y = y + 0.9 * infoPtr->height_increment; /* bring the bottom up just
312 a hair to fit inside the day rectangle */
314 points[7].x = x + 0.2 * infoPtr->width_increment;
315 points[7].y = y + 0.8 * infoPtr->height_increment;
316 points[8].x = x + 0.1 * infoPtr->width_increment;
317 points[8].y = y + 0.8 * infoPtr->height_increment;
319 points[9].y = y + 0.5 * infoPtr->height_increment;
321 points[10].x = x + 0.1 * infoPtr->width_increment;
322 points[10].y = y + 0.2 * infoPtr->height_increment;
323 points[11].x = x + 0.2 * infoPtr->width_increment;
324 points[11].y = y + 0.3 * infoPtr->height_increment;
325 points[12].x = x + 0.4 * infoPtr->width_increment;
326 points[12].y = y + 0.2 * infoPtr->height_increment;
328 PolyBezier(hdc, points, 13);
329 DeleteObject(hRedPen);
330 SelectObject(hdc, hOldPen2);
334 static void MONTHCAL_DrawDay(HDC hdc, MONTHCAL_INFO *infoPtr, int day, int month,
335 int x, int y, int bold)
339 static int haveBoldFont, haveSelectedDay = FALSE;
341 HPEN hNewPen, hOldPen = 0;
345 sprintf(buf, "%d", day);
347 /* No need to check styles: when selection is not valid, it is set to zero.
348 * 1<day<31, so evertyhing's OK.
351 MONTHCAL_CalcDayRect(infoPtr, &r, x, y);
353 if((day>=infoPtr->minSel.wDay) && (day<=infoPtr->maxSel.wDay)
354 && (month==infoPtr->currentMonth)) {
358 TRACE("%d %d %d\n",day, infoPtr->minSel.wDay, infoPtr->maxSel.wDay);
359 TRACE("%ld %ld %ld %ld\n", r.left, r.top, r.right, r.bottom);
360 oldCol = SetTextColor(hdc, infoPtr->monthbk);
361 oldBk = SetBkColor(hdc, infoPtr->trailingtxt);
362 hbr = GetSysColorBrush(COLOR_GRAYTEXT);
363 hrgn = CreateEllipticRgn(r.left, r.top, r.right, r.bottom);
364 FillRgn(hdc, hrgn, hbr);
366 /* FIXME: this may need to be changed now b/c of the other
367 drawing changes 11/3/99 CMM */
368 r2.left = r.left - 0.25 * infoPtr->textWidth;
370 r2.right = r.left + 0.5 * infoPtr->textWidth;
371 r2.bottom = r.bottom;
372 if(haveSelectedDay) FillRect(hdc, &r2, hbr);
373 haveSelectedDay = TRUE;
375 haveSelectedDay = FALSE;
378 /* need to add some code for multiple selections */
380 if((bold) &&(!haveBoldFont)) {
381 SelectObject(hdc, infoPtr->hBoldFont);
384 if((!bold) &&(haveBoldFont)) {
385 SelectObject(hdc, infoPtr->hFont);
386 haveBoldFont = FALSE;
389 if(haveSelectedDay) {
390 SetTextColor(hdc, oldCol);
391 SetBkColor(hdc, oldBk);
394 SetBkMode(hdc,TRANSPARENT);
395 DrawTextA(hdc, buf, -1, &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE );
397 /* draw a rectangle around the currently selected days text */
398 if((day==infoPtr->curSelDay) && (month==infoPtr->currentMonth)) {
399 hNewPen = CreatePen(PS_ALTERNATE, 0, GetSysColor(COLOR_WINDOWTEXT) );
400 hbr = GetSysColorBrush(COLOR_WINDOWTEXT);
401 FrameRect(hdc, &r, hbr);
402 SelectObject(hdc, hOldPen);
407 static void MONTHCAL_Refresh(HWND hwnd, HDC hdc, PAINTSTRUCT* ps)
409 MONTHCAL_INFO *infoPtr=MONTHCAL_GetInfoPtr(hwnd);
410 RECT *rcClient=&infoPtr->rcClient;
411 RECT *rcDraw=&infoPtr->rcDraw;
412 RECT *title=&infoPtr->title;
413 RECT *prev=&infoPtr->titlebtnprev;
414 RECT *next=&infoPtr->titlebtnnext;
415 RECT *titlemonth=&infoPtr->titlemonth;
416 RECT *titleyear=&infoPtr->titleyear;
420 int i, j, m, mask, day, firstDay, weeknum, weeknum1,prevMonth;
421 int textHeight = infoPtr->textHeight, textWidth = infoPtr->textWidth;
425 /* LOGFONTA logFont; */
429 COLORREF oldTextColor, oldBkColor;
430 DWORD dwStyle = GetWindowLongA(hwnd, GWL_STYLE);
432 RECT rcDay; /* used in MONTHCAL_CalcDayRect() */
433 SYSTEMTIME localtime;
436 oldTextColor = SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
439 /* fill background */
440 hbr = CreateSolidBrush (infoPtr->bk);
441 FillRect(hdc, rcClient, hbr);
445 if(IntersectRect(&rcTemp, &(ps->rcPaint), title))
447 hbr = CreateSolidBrush(infoPtr->titlebk);
448 FillRect(hdc, title, hbr);
452 /* if the previous button is pressed draw it depressed */
453 if(IntersectRect(&rcTemp, &(ps->rcPaint), prev))
455 if((infoPtr->status & MC_PREVPRESSED))
456 DrawFrameControl(hdc, prev, DFC_SCROLL,
457 DFCS_SCROLLLEFT | DFCS_PUSHED |
458 (dwStyle & WS_DISABLED ? DFCS_INACTIVE : 0));
459 else /* if the previous button is pressed draw it depressed */
460 DrawFrameControl(hdc, prev, DFC_SCROLL,
461 DFCS_SCROLLLEFT |(dwStyle & WS_DISABLED ? DFCS_INACTIVE : 0));
464 /* if next button is depressed draw it depressed */
465 if(IntersectRect(&rcTemp, &(ps->rcPaint), next))
467 if((infoPtr->status & MC_NEXTPRESSED))
468 DrawFrameControl(hdc, next, DFC_SCROLL,
469 DFCS_SCROLLRIGHT | DFCS_PUSHED |
470 (dwStyle & WS_DISABLED ? DFCS_INACTIVE : 0));
471 else /* if the next button is pressed draw it depressed */
472 DrawFrameControl(hdc, next, DFC_SCROLL,
473 DFCS_SCROLLRIGHT |(dwStyle & WS_DISABLED ? DFCS_INACTIVE : 0));
476 oldBkColor = SetBkColor(hdc, infoPtr->titlebk);
477 SetTextColor(hdc, infoPtr->titletxt);
478 currentFont = SelectObject(hdc, infoPtr->hBoldFont);
480 /* titlemonth->left and right are set in MONTHCAL_UpdateSize */
481 titlemonth->left = title->left;
482 titlemonth->right = title->right;
484 GetLocaleInfoA( LOCALE_USER_DEFAULT,LOCALE_SMONTHNAME1+infoPtr->currentMonth -1,
486 sprintf(buf, "%s %ld", buf1, infoPtr->currentYear);
488 if(IntersectRect(&rcTemp, &(ps->rcPaint), titlemonth))
490 DrawTextA(hdc, buf, strlen(buf), titlemonth,
491 DT_CENTER | DT_VCENTER | DT_SINGLELINE);
494 SelectObject(hdc, infoPtr->hFont);
496 /* titlemonth left/right contained rect for whole titletxt('June 1999')
497 * MCM_HitTestInfo wants month & year rects, so prepare these now.
498 *(no, we can't draw them separately; the whole text is centered)
500 GetTextExtentPoint32A(hdc, buf, strlen(buf), &size);
501 titlemonth->left = title->right / 2 - size.cx / 2;
502 titleyear->right = title->right / 2 + size.cx / 2;
503 GetTextExtentPoint32A(hdc, buf1, strlen(buf1), &size);
504 titlemonth->right = titlemonth->left + size.cx;
505 titleyear->left = titlemonth->right;
507 /* draw month area */
508 rcTemp.top=infoPtr->wdays.top;
509 rcTemp.left=infoPtr->wdays.left;
510 rcTemp.bottom=infoPtr->todayrect.bottom;
511 rcTemp.right =infoPtr->todayrect.right;
512 if(IntersectRect(&rcTemp, &(ps->rcPaint), &rcTemp))
514 hbr = CreateSolidBrush(infoPtr->monthbk);
515 FillRect(hdc, &rcTemp, hbr);
519 /* draw line under day abbreviatons */
521 MoveToEx(hdc, infoPtr->days.left + 3, title->bottom + textHeight + 1, NULL);
523 LineTo(hdc, rcDraw->right - 3, title->bottom + textHeight + 1);
525 prevMonth = infoPtr->currentMonth - 1;
526 if(prevMonth == 0) /* if currentMonth is january(1) prevMonth is */
527 prevMonth = 12; /* december(12) of the previous year */
529 infoPtr->wdays.left = infoPtr->days.left = infoPtr->weeknums.right;
530 /* draw day abbreviations */
532 SetBkColor(hdc, infoPtr->monthbk);
533 SetTextColor(hdc, infoPtr->trailingtxt);
535 /* copy this rect so we can change the values without changing */
536 /* the original version */
537 days->left = infoPtr->wdays.left;
538 days->right = days->left + infoPtr->width_increment;
539 days->top = infoPtr->wdays.top;
540 days->bottom = infoPtr->wdays.bottom;
542 i = infoPtr->firstDay;
545 GetLocaleInfoA( LOCALE_USER_DEFAULT,LOCALE_SABBREVDAYNAME1 + (i +j)%7,
547 DrawTextA(hdc, buf, strlen(buf), days,
548 DT_CENTER | DT_VCENTER | DT_SINGLELINE );
549 days->left+=infoPtr->width_increment;
550 days->right+=infoPtr->width_increment;
553 /* draw day numbers; first, the previous month */
555 firstDay = MONTHCAL_CalculateDayOfWeek(1, infoPtr->currentMonth, infoPtr->currentYear);
557 day = MONTHCAL_MonthLength(prevMonth, infoPtr->currentYear) +
558 (infoPtr->firstDay + 7 - firstDay)%7 + 1;
559 if (day > MONTHCAL_MonthLength(prevMonth, infoPtr->currentYear))
561 startofprescal = day;
566 while(day <= MONTHCAL_MonthLength(prevMonth, infoPtr->currentYear)) {
567 MONTHCAL_CalcDayRect(infoPtr, &rcDay, i, 0);
568 if(IntersectRect(&rcTemp, &(ps->rcPaint), &rcDay))
570 MONTHCAL_DrawDay(hdc, infoPtr, day, prevMonth, i, 0,
571 infoPtr->monthdayState[m] & mask);
579 /* draw `current' month */
581 day = 1; /* start at the beginning of the current month */
583 infoPtr->firstDayplace = i;
584 SetTextColor(hdc, infoPtr->txt);
588 /* draw the first week of the current month */
590 MONTHCAL_CalcDayRect(infoPtr, &rcDay, i, 0);
591 if(IntersectRect(&rcTemp, &(ps->rcPaint), &rcDay))
594 MONTHCAL_DrawDay(hdc, infoPtr, day, infoPtr->currentMonth, i, 0,
595 infoPtr->monthdayState[m] & mask);
597 if((infoPtr->currentMonth==infoPtr->todaysDate.wMonth) &&
598 (day==infoPtr->todaysDate.wDay) &&
599 (infoPtr->currentYear == infoPtr->todaysDate.wYear)) {
600 if(!(dwStyle & MCS_NOTODAYCIRCLE))
601 MONTHCAL_CircleDay(hdc, infoPtr, day, infoPtr->currentMonth);
610 j = 1; /* move to the 2nd week of the current month */
611 i = 0; /* move back to sunday */
612 while(day <= MONTHCAL_MonthLength(infoPtr->currentMonth, infoPtr->currentYear)) {
613 MONTHCAL_CalcDayRect(infoPtr, &rcDay, i, j);
614 if(IntersectRect(&rcTemp, &(ps->rcPaint), &rcDay))
616 MONTHCAL_DrawDay(hdc, infoPtr, day, infoPtr->currentMonth, i, j,
617 infoPtr->monthdayState[m] & mask);
619 if((infoPtr->currentMonth==infoPtr->todaysDate.wMonth) &&
620 (day==infoPtr->todaysDate.wDay) &&
621 (infoPtr->currentYear == infoPtr->todaysDate.wYear))
622 if(!(dwStyle & MCS_NOTODAYCIRCLE))
623 MONTHCAL_CircleDay(hdc, infoPtr, day, infoPtr->currentMonth);
628 if(i>6) { /* past saturday, goto the next weeks sunday */
634 /* draw `next' month */
636 day = 1; /* start at the first day of the next month */
640 SetTextColor(hdc, infoPtr->trailingtxt);
641 while((i<7) &&(j<6)) {
642 MONTHCAL_CalcDayRect(infoPtr, &rcDay, i, j);
643 if(IntersectRect(&rcTemp, &(ps->rcPaint), &rcDay))
645 MONTHCAL_DrawDay(hdc, infoPtr, day, infoPtr->currentMonth + 1, i, j,
646 infoPtr->monthdayState[m] & mask);
652 if(i==7) { /* past saturday, go to next week's sunday */
657 SetTextColor(hdc, infoPtr->txt);
660 /* draw `today' date if style allows it, and draw a circle before today's
661 * date if necessary */
663 if(!(dwStyle & MCS_NOTODAY)) {
665 if(!(dwStyle & MCS_NOTODAYCIRCLE)) {
666 /*day is the number of days from nextmonth we put on the calendar */
667 MONTHCAL_CircleDay(hdc, infoPtr,
668 day+MONTHCAL_MonthLength(infoPtr->currentMonth,infoPtr->currentYear),
669 infoPtr->currentMonth);
672 if (!LoadStringA(COMCTL32_hModule,IDM_TODAY,buf1,sizeof(buf1)))
674 WARN("Can't load resource\n");
675 strcpy(buf1,"Today:");
677 MONTHCAL_CalcDayRect(infoPtr, &rtoday, 1, 6);
678 MONTHCAL_CopyTime(&infoPtr->todaysDate,&localtime);
679 GetDateFormatA(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&localtime,NULL,buf2,sizeof(buf2));
680 sprintf(buf, "%s %s", buf1,buf2);
681 SelectObject(hdc, infoPtr->hBoldFont);
683 if(IntersectRect(&rcTemp, &(ps->rcPaint), &rtoday))
685 DrawTextA(hdc, buf, -1, &rtoday, DT_CALCRECT | DT_LEFT | DT_VCENTER | DT_SINGLELINE);
686 DrawTextA(hdc, buf, -1, &rtoday, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
688 SelectObject(hdc, infoPtr->hFont);
691 /*eventually draw week numbers*/
692 if(dwStyle & MCS_WEEKNUMBERS) {
693 /* display weeknumbers*/
696 /* Rules what week to call the first week of a new year:
697 LOCALE_IFIRSTWEEKOFYEAR == 0 (e.g US?):
698 The week containing Jan 1 is the first week of year
699 LOCALE_IFIRSTWEEKOFYEAR == 2 (e.g. Germany):
700 First week of year must contain 4 days of the new year
701 LOCALE_IFIRSTWEEKOFYEAR == 1 (what contries?)
702 The first week of the year must contain only days of the new year
704 GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_IFIRSTWEEKOFYEAR,
706 sscanf(buf, "%d", &weeknum);
717 if (infoPtr->currentMonth < 2)
719 /* calculate all those exceptions for january */
720 weeknum1=MONTHCAL_CalculateDayOfWeek(1,1,infoPtr->currentYear);
721 if ((infoPtr->firstDay +7 - weeknum1)%7 > mindays)
727 weeknum+=MONTHCAL_MonthLength(i+1, infoPtr->currentYear-1);
728 weeknum +=startofprescal+ 7;
730 weeknum1=MONTHCAL_CalculateDayOfWeek(1,1,infoPtr->currentYear-1);
731 if ((infoPtr->firstDay + 7 - weeknum1)%7 > mindays)
738 for(i=0; i<prevMonth-1; i++)
739 weeknum+=MONTHCAL_MonthLength(i+1, infoPtr->currentYear);
740 weeknum +=startofprescal+ 7;
742 weeknum1=MONTHCAL_CalculateDayOfWeek(1,1,infoPtr->currentYear);
743 if ((infoPtr->firstDay + 7 - weeknum1)%7 > mindays)
746 days->left = infoPtr->weeknums.left;
747 days->right = infoPtr->weeknums.right;
748 days->top = infoPtr->weeknums.top;
749 days->bottom = days->top +infoPtr->height_increment;
751 if((i==0)&&(weeknum>50))
753 sprintf(buf, "%d", weeknum);
756 else if((i==5)&&(weeknum>47))
758 sprintf(buf, "%d", 1);
761 sprintf(buf, "%d", weeknum + i);
762 DrawTextA(hdc, buf, -1, days, DT_CENTER | DT_VCENTER | DT_SINGLELINE );
763 days->top+=infoPtr->height_increment;
764 days->bottom+=infoPtr->height_increment;
767 MoveToEx(hdc, infoPtr->weeknums.right, infoPtr->weeknums.top + 3 , NULL);
768 LineTo(hdc, infoPtr->weeknums.right, infoPtr->weeknums.bottom );
771 /* currentFont was font at entering Refresh */
773 SetBkColor(hdc, oldBkColor);
774 SelectObject(hdc, currentFont);
775 SetTextColor(hdc, oldTextColor);
780 MONTHCAL_GetMinReqRect(HWND hwnd, WPARAM wParam, LPARAM lParam)
782 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
783 LPRECT lpRect = (LPRECT) lParam;
784 TRACE("%x %lx\n", wParam, lParam);
786 /* validate parameters */
788 if((infoPtr==NULL) ||(lpRect == NULL) ) return FALSE;
790 lpRect->left = infoPtr->rcClient.left;
791 lpRect->right = infoPtr->rcClient.right;
792 lpRect->top = infoPtr->rcClient.top;
793 lpRect->bottom = infoPtr->rcClient.bottom;
799 MONTHCAL_GetColor(HWND hwnd, WPARAM wParam, LPARAM lParam)
801 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
803 TRACE("%x %lx\n", wParam, lParam);
805 switch((int)wParam) {
806 case MCSC_BACKGROUND:
811 return infoPtr->titlebk;
813 return infoPtr->titletxt;
815 return infoPtr->monthbk;
816 case MCSC_TRAILINGTEXT:
817 return infoPtr->trailingtxt;
825 MONTHCAL_SetColor(HWND hwnd, WPARAM wParam, LPARAM lParam)
827 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
830 TRACE("%x %lx\n", wParam, lParam);
832 switch((int)wParam) {
833 case MCSC_BACKGROUND:
835 infoPtr->bk = (COLORREF)lParam;
839 infoPtr->txt = (COLORREF)lParam;
842 prev = infoPtr->titlebk;
843 infoPtr->titlebk = (COLORREF)lParam;
846 prev=infoPtr->titletxt;
847 infoPtr->titletxt = (COLORREF)lParam;
850 prev = infoPtr->monthbk;
851 infoPtr->monthbk = (COLORREF)lParam;
853 case MCSC_TRAILINGTEXT:
854 prev = infoPtr->trailingtxt;
855 infoPtr->trailingtxt = (COLORREF)lParam;
859 InvalidateRect(hwnd, NULL, FALSE);
865 MONTHCAL_GetMonthDelta(HWND hwnd, WPARAM wParam, LPARAM lParam)
867 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
869 TRACE("%x %lx\n", wParam, lParam);
872 return infoPtr->delta;
874 return infoPtr->visible;
879 MONTHCAL_SetMonthDelta(HWND hwnd, WPARAM wParam, LPARAM lParam)
881 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
882 int prev = infoPtr->delta;
884 TRACE("%x %lx\n", wParam, lParam);
886 infoPtr->delta = (int)wParam;
892 MONTHCAL_GetFirstDayOfWeek(HWND hwnd, WPARAM wParam, LPARAM lParam)
894 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
896 return infoPtr->firstDay;
900 /* sets the first day of the week that will appear in the control */
901 /* 0 == Monday, 6 == Sunday */
902 /* FIXME: this needs to be implemented properly in MONTHCAL_Refresh() */
903 /* FIXME: we need more error checking here */
905 MONTHCAL_SetFirstDayOfWeek(HWND hwnd, WPARAM wParam, LPARAM lParam)
907 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
908 int prev = infoPtr->firstDay;
912 TRACE("%x %lx\n", wParam, lParam);
914 if((lParam >= 0) && (lParam < 7)) {
915 infoPtr->firstDay = (int)lParam;
919 GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_IFIRSTDAYOFWEEK,
921 TRACE("%s %d\n", buf, strlen(buf));
922 if(sscanf(buf, "%d", &day) == 1)
923 infoPtr->firstDay = day;
925 infoPtr->firstDay = 0;
932 MONTHCAL_GetMonthRange(HWND hwnd, WPARAM wParam, LPARAM lParam)
934 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
936 TRACE("%x %lx\n", wParam, lParam);
939 return infoPtr->monthRange;
944 MONTHCAL_GetMaxTodayWidth(HWND hwnd)
946 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
948 return(infoPtr->todayrect.right - infoPtr->todayrect.left);
952 /* FIXME: are validated times taken from current date/time or simply
954 * FIXME: check whether MCM_GETMONTHRANGE shows correct result after
955 * adjusting range with MCM_SETRANGE
959 MONTHCAL_SetRange(HWND hwnd, WPARAM wParam, LPARAM lParam)
961 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
962 SYSTEMTIME *lprgSysTimeArray=(SYSTEMTIME *)lParam;
965 TRACE("%x %lx\n", wParam, lParam);
967 if(wParam & GDTR_MAX) {
968 if(MONTHCAL_ValidateTime(lprgSysTimeArray[1])){
969 MONTHCAL_CopyTime(&lprgSysTimeArray[1], &infoPtr->maxDate);
970 infoPtr->rangeValid|=GDTR_MAX;
972 GetSystemTime(&infoPtr->todaysDate);
973 MONTHCAL_CopyTime(&infoPtr->todaysDate, &infoPtr->maxDate);
976 if(wParam & GDTR_MIN) {
977 if(MONTHCAL_ValidateTime(lprgSysTimeArray[0])) {
978 MONTHCAL_CopyTime(&lprgSysTimeArray[0], &infoPtr->minDate);
979 infoPtr->rangeValid|=GDTR_MIN;
981 GetSystemTime(&infoPtr->todaysDate);
982 MONTHCAL_CopyTime(&infoPtr->todaysDate, &infoPtr->minDate);
986 prev = infoPtr->monthRange;
987 infoPtr->monthRange = infoPtr->maxDate.wMonth - infoPtr->minDate.wMonth;
989 if(infoPtr->monthRange!=prev) {
990 infoPtr->monthdayState = ReAlloc(infoPtr->monthdayState,
991 infoPtr->monthRange * sizeof(MONTHDAYSTATE));
999 MONTHCAL_GetRange(HWND hwnd, WPARAM wParam, LPARAM lParam)
1001 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
1002 SYSTEMTIME *lprgSysTimeArray = (SYSTEMTIME *)lParam;
1004 /* validate parameters */
1006 if((infoPtr==NULL) || (lprgSysTimeArray==NULL)) return FALSE;
1008 MONTHCAL_CopyTime(&infoPtr->maxDate, &lprgSysTimeArray[1]);
1009 MONTHCAL_CopyTime(&infoPtr->minDate, &lprgSysTimeArray[0]);
1011 return infoPtr->rangeValid;
1016 MONTHCAL_SetDayState(HWND hwnd, WPARAM wParam, LPARAM lParam)
1019 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
1020 int i, iMonths = (int)wParam;
1021 MONTHDAYSTATE *dayStates = (LPMONTHDAYSTATE)lParam;
1023 TRACE("%x %lx\n", wParam, lParam);
1024 if(iMonths!=infoPtr->monthRange) return 0;
1026 for(i=0; i<iMonths; i++)
1027 infoPtr->monthdayState[i] = dayStates[i];
1032 MONTHCAL_GetCurSel(HWND hwnd, WPARAM wParam, LPARAM lParam)
1034 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
1035 SYSTEMTIME *lpSel = (SYSTEMTIME *) lParam;
1037 TRACE("%x %lx\n", wParam, lParam);
1038 if((infoPtr==NULL) ||(lpSel==NULL)) return FALSE;
1039 if(GetWindowLongA(hwnd, GWL_STYLE) & MCS_MULTISELECT) return FALSE;
1041 MONTHCAL_CopyTime(&infoPtr->minSel, lpSel);
1042 TRACE("%d/%d/%d\n", lpSel->wYear, lpSel->wMonth, lpSel->wDay);
1046 /* FIXME: if the specified date is not visible, make it visible */
1047 /* FIXME: redraw? */
1049 MONTHCAL_SetCurSel(HWND hwnd, WPARAM wParam, LPARAM lParam)
1051 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
1052 SYSTEMTIME *lpSel = (SYSTEMTIME *)lParam;
1054 TRACE("%x %lx\n", wParam, lParam);
1055 if((infoPtr==NULL) ||(lpSel==NULL)) return FALSE;
1056 if(GetWindowLongA(hwnd, GWL_STYLE) & MCS_MULTISELECT) return FALSE;
1058 infoPtr->currentMonth=lpSel->wMonth;
1059 infoPtr->currentYear=lpSel->wYear;
1061 MONTHCAL_CopyTime(lpSel, &infoPtr->minSel);
1062 MONTHCAL_CopyTime(lpSel, &infoPtr->maxSel);
1064 InvalidateRect(hwnd, NULL, FALSE);
1071 MONTHCAL_GetMaxSelCount(HWND hwnd, WPARAM wParam, LPARAM lParam)
1073 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
1075 TRACE("%x %lx\n", wParam, lParam);
1076 return infoPtr->maxSelCount;
1081 MONTHCAL_SetMaxSelCount(HWND hwnd, WPARAM wParam, LPARAM lParam)
1083 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
1085 TRACE("%x %lx\n", wParam, lParam);
1086 if(GetWindowLongA(hwnd, GWL_STYLE) & MCS_MULTISELECT) {
1087 infoPtr->maxSelCount = wParam;
1095 MONTHCAL_GetSelRange(HWND hwnd, WPARAM wParam, LPARAM lParam)
1097 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
1098 SYSTEMTIME *lprgSysTimeArray = (SYSTEMTIME *) lParam;
1100 TRACE("%x %lx\n", wParam, lParam);
1102 /* validate parameters */
1104 if((infoPtr==NULL) ||(lprgSysTimeArray==NULL)) return FALSE;
1106 if(GetWindowLongA(hwnd, GWL_STYLE) & MCS_MULTISELECT)
1108 MONTHCAL_CopyTime(&infoPtr->maxSel, &lprgSysTimeArray[1]);
1109 MONTHCAL_CopyTime(&infoPtr->minSel, &lprgSysTimeArray[0]);
1110 TRACE("[min,max]=[%d %d]\n", infoPtr->minSel.wDay, infoPtr->maxSel.wDay);
1119 MONTHCAL_SetSelRange(HWND hwnd, WPARAM wParam, LPARAM lParam)
1121 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
1122 SYSTEMTIME *lprgSysTimeArray = (SYSTEMTIME *) lParam;
1124 TRACE("%x %lx\n", wParam, lParam);
1126 /* validate parameters */
1128 if((infoPtr==NULL) ||(lprgSysTimeArray==NULL)) return FALSE;
1130 if(GetWindowLongA( hwnd, GWL_STYLE) & MCS_MULTISELECT)
1132 MONTHCAL_CopyTime(&lprgSysTimeArray[1], &infoPtr->maxSel);
1133 MONTHCAL_CopyTime(&lprgSysTimeArray[0], &infoPtr->minSel);
1134 TRACE("[min,max]=[%d %d]\n", infoPtr->minSel.wDay, infoPtr->maxSel.wDay);
1143 MONTHCAL_GetToday(HWND hwnd, WPARAM wParam, LPARAM lParam)
1145 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
1146 SYSTEMTIME *lpToday = (SYSTEMTIME *) lParam;
1148 TRACE("%x %lx\n", wParam, lParam);
1150 /* validate parameters */
1152 if((infoPtr==NULL) || (lpToday==NULL)) return FALSE;
1153 MONTHCAL_CopyTime(&infoPtr->todaysDate, lpToday);
1159 MONTHCAL_SetToday(HWND hwnd, WPARAM wParam, LPARAM lParam)
1161 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
1162 SYSTEMTIME *lpToday = (SYSTEMTIME *) lParam;
1164 TRACE("%x %lx\n", wParam, lParam);
1166 /* validate parameters */
1168 if((infoPtr==NULL) ||(lpToday==NULL)) return FALSE;
1169 MONTHCAL_CopyTime(lpToday, &infoPtr->todaysDate);
1170 InvalidateRect(hwnd, NULL, FALSE);
1176 MONTHCAL_HitTest(HWND hwnd, LPARAM lParam)
1178 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
1179 PMCHITTESTINFO lpht = (PMCHITTESTINFO)lParam;
1187 retval = MCHT_NOWHERE;
1190 /* Comment in for debugging...
1191 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,
1192 infoPtr->wdays.left, infoPtr->wdays.right,
1193 infoPtr->wdays.top, infoPtr->wdays.bottom,
1194 infoPtr->days.left, infoPtr->days.right,
1195 infoPtr->days.top, infoPtr->days.bottom,
1196 infoPtr->todayrect.left, infoPtr->todayrect.right,
1197 infoPtr->todayrect.top, infoPtr->todayrect.bottom,
1198 infoPtr->weeknums.left, infoPtr->weeknums.right,
1199 infoPtr->weeknums.top, infoPtr->weeknums.bottom);
1202 /* are we in the header? */
1204 if(PtInRect(&infoPtr->title, lpht->pt)) {
1205 if(PtInRect(&infoPtr->titlebtnprev, lpht->pt)) {
1206 retval = MCHT_TITLEBTNPREV;
1209 if(PtInRect(&infoPtr->titlebtnnext, lpht->pt)) {
1210 retval = MCHT_TITLEBTNNEXT;
1213 if(PtInRect(&infoPtr->titlemonth, lpht->pt)) {
1214 retval = MCHT_TITLEMONTH;
1217 if(PtInRect(&infoPtr->titleyear, lpht->pt)) {
1218 retval = MCHT_TITLEYEAR;
1222 retval = MCHT_TITLE;
1226 day = MONTHCAL_CalcDayFromPos(infoPtr,x,y,&wday,&wnum);
1227 if(PtInRect(&infoPtr->wdays, lpht->pt)) {
1228 retval = MCHT_CALENDARDAY;
1229 lpht->st.wYear = infoPtr->currentYear;
1230 lpht->st.wMonth = (day < 1)? infoPtr->currentMonth -1 : infoPtr->currentMonth;
1231 lpht->st.wDay = (day < 1)?
1232 MONTHCAL_MonthLength(infoPtr->currentMonth-1,infoPtr->currentYear) -day : day;
1235 if(PtInRect(&infoPtr->weeknums, lpht->pt)) {
1236 retval = MCHT_CALENDARWEEKNUM;
1237 lpht->st.wYear = infoPtr->currentYear;
1238 lpht->st.wMonth = (day < 1) ? infoPtr->currentMonth -1 :
1239 (day > MONTHCAL_MonthLength(infoPtr->currentMonth,infoPtr->currentYear)) ?
1240 infoPtr->currentMonth +1 :infoPtr->currentMonth;
1241 lpht->st.wDay = (day < 1 ) ?
1242 MONTHCAL_MonthLength(infoPtr->currentMonth-1,infoPtr->currentYear) -day :
1243 (day > MONTHCAL_MonthLength(infoPtr->currentMonth,infoPtr->currentYear)) ?
1244 day - MONTHCAL_MonthLength(infoPtr->currentMonth,infoPtr->currentYear) : day;
1247 if(PtInRect(&infoPtr->days, lpht->pt))
1249 lpht->st.wYear = infoPtr->currentYear;
1252 retval = MCHT_CALENDARDATEPREV;
1253 lpht->st.wMonth = infoPtr->currentMonth - 1;
1254 if (lpht->st.wMonth <1)
1256 lpht->st.wMonth = 12;
1259 lpht->st.wDay = MONTHCAL_MonthLength(lpht->st.wMonth,lpht->st.wYear) -day;
1261 else if (day > MONTHCAL_MonthLength(infoPtr->currentMonth,infoPtr->currentYear))
1263 retval = MCHT_CALENDARDATENEXT;
1264 lpht->st.wMonth = infoPtr->currentMonth + 1;
1265 if (lpht->st.wMonth <12)
1267 lpht->st.wMonth = 1;
1270 lpht->st.wDay = day - MONTHCAL_MonthLength(infoPtr->currentMonth,infoPtr->currentYear) ;
1273 retval = MCHT_CALENDARDATE;
1274 lpht->st.wMonth = infoPtr->currentMonth;
1275 lpht->st.wDay = day;
1279 if(PtInRect(&infoPtr->todayrect, lpht->pt)) {
1280 retval = MCHT_TODAYLINK;
1285 /* Hit nothing special? What's left must be background :-) */
1287 retval = MCHT_CALENDARBK;
1289 lpht->uHit = retval;
1294 static void MONTHCAL_GoToNextMonth(HWND hwnd, MONTHCAL_INFO *infoPtr)
1296 DWORD dwStyle = GetWindowLongA(hwnd, GWL_STYLE);
1298 TRACE("MONTHCAL_GoToNextMonth\n");
1300 infoPtr->currentMonth++;
1301 if(infoPtr->currentMonth > 12) {
1302 infoPtr->currentYear++;
1303 infoPtr->currentMonth = 1;
1306 if(dwStyle & MCS_DAYSTATE) {
1310 nmds.nmhdr.hwndFrom = hwnd;
1311 nmds.nmhdr.idFrom = GetWindowLongPtrW(hwnd, GWLP_ID);
1312 nmds.nmhdr.code = MCN_GETDAYSTATE;
1313 nmds.cDayState = infoPtr->monthRange;
1314 nmds.prgDayState = Alloc(infoPtr->monthRange * sizeof(MONTHDAYSTATE));
1316 SendMessageA(infoPtr->hwndNotify, WM_NOTIFY,
1317 (WPARAM)nmds.nmhdr.idFrom, (LPARAM)&nmds);
1318 for(i=0; i<infoPtr->monthRange; i++)
1319 infoPtr->monthdayState[i] = nmds.prgDayState[i];
1324 static void MONTHCAL_GoToPrevMonth(HWND hwnd, MONTHCAL_INFO *infoPtr)
1326 DWORD dwStyle = GetWindowLongA(hwnd, GWL_STYLE);
1328 TRACE("MONTHCAL_GoToPrevMonth\n");
1330 infoPtr->currentMonth--;
1331 if(infoPtr->currentMonth < 1) {
1332 infoPtr->currentYear--;
1333 infoPtr->currentMonth = 12;
1336 if(dwStyle & MCS_DAYSTATE) {
1340 nmds.nmhdr.hwndFrom = hwnd;
1341 nmds.nmhdr.idFrom = GetWindowLongPtrW(hwnd, GWLP_ID);
1342 nmds.nmhdr.code = MCN_GETDAYSTATE;
1343 nmds.cDayState = infoPtr->monthRange;
1344 nmds.prgDayState = Alloc
1345 (infoPtr->monthRange * sizeof(MONTHDAYSTATE));
1347 SendMessageA(infoPtr->hwndNotify, WM_NOTIFY,
1348 (WPARAM)nmds.nmhdr.idFrom, (LPARAM)&nmds);
1349 for(i=0; i<infoPtr->monthRange; i++)
1350 infoPtr->monthdayState[i] = nmds.prgDayState[i];
1355 MONTHCAL_RButtonDown(HWND hwnd, WPARAM wParam, LPARAM lParam)
1357 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
1362 hMenu = CreatePopupMenu();
1363 if (!LoadStringA(COMCTL32_hModule,IDM_GOTODAY,buf,sizeof(buf)))
1365 WARN("Can't load resource\n");
1366 strcpy(buf,"Go to Today:");
1368 AppendMenuA(hMenu, MF_STRING|MF_ENABLED,1, buf);
1369 menupoint.x=(INT)LOWORD(lParam);
1370 menupoint.y=(INT)HIWORD(lParam);
1371 ClientToScreen(hwnd, &menupoint);
1372 if( TrackPopupMenu(hMenu,TPM_RIGHTBUTTON| TPM_NONOTIFY|TPM_RETURNCMD,
1373 menupoint.x,menupoint.y,0,hwnd,NULL))
1375 infoPtr->currentMonth=infoPtr->todaysDate.wMonth;
1376 infoPtr->currentYear=infoPtr->todaysDate.wYear;
1377 InvalidateRect(hwnd, NULL, FALSE);
1383 MONTHCAL_LButtonDown(HWND hwnd, WPARAM wParam, LPARAM lParam)
1385 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
1389 RECT rcDay; /* used in determining area to invalidate */
1393 TRACE("%x %lx\n", wParam, lParam);
1395 if (infoPtr->hWndYearUpDown)
1397 infoPtr->currentYear=SendMessageA( infoPtr->hWndYearUpDown, UDM_SETPOS, (WPARAM) 0,(LPARAM)0);
1398 if(!DestroyWindow(infoPtr->hWndYearUpDown))
1400 FIXME("Can't destroy Updown Control\n");
1403 infoPtr->hWndYearUpDown=0;
1404 if(!DestroyWindow(infoPtr->hWndYearEdit))
1406 FIXME("Can't destroy Updown Control\n");
1409 infoPtr->hWndYearEdit=0;
1410 InvalidateRect(hwnd, NULL, FALSE);
1413 ht.pt.x = (INT)LOWORD(lParam);
1414 ht.pt.y = (INT)HIWORD(lParam);
1415 hit = MONTHCAL_HitTest(hwnd, (LPARAM)&ht);
1417 /* FIXME: these flags should be checked by */
1418 /*((hit & MCHT_XXX) == MCHT_XXX) b/c some of the flags are */
1420 if(hit ==MCHT_TITLEBTNNEXT) {
1421 MONTHCAL_GoToNextMonth(hwnd, infoPtr);
1422 infoPtr->status = MC_NEXTPRESSED;
1423 SetTimer(hwnd, MC_NEXTMONTHTIMER, MC_NEXTMONTHDELAY, 0);
1424 InvalidateRect(hwnd, NULL, FALSE);
1427 if(hit == MCHT_TITLEBTNPREV){
1428 MONTHCAL_GoToPrevMonth(hwnd, infoPtr);
1429 infoPtr->status = MC_PREVPRESSED;
1430 SetTimer(hwnd, MC_PREVMONTHTIMER, MC_NEXTMONTHDELAY, 0);
1431 InvalidateRect(hwnd, NULL, FALSE);
1435 if(hit == MCHT_TITLEMONTH) {
1436 hMenu = CreatePopupMenu();
1440 GetLocaleInfoA( LOCALE_USER_DEFAULT,LOCALE_SMONTHNAME1+i,
1442 AppendMenuA(hMenu, MF_STRING|MF_ENABLED,i+1, buf);
1444 menupoint.x=infoPtr->titlemonth.right;
1445 menupoint.y=infoPtr->titlemonth.bottom;
1446 ClientToScreen(hwnd, &menupoint);
1447 i= TrackPopupMenu(hMenu,TPM_LEFTALIGN | TPM_NONOTIFY | TPM_RIGHTBUTTON | TPM_RETURNCMD,
1448 menupoint.x,menupoint.y,0,hwnd,NULL);
1449 if ((i>0) && (i<13))
1451 infoPtr->currentMonth=i;
1452 InvalidateRect(hwnd, NULL, FALSE);
1455 if(hit == MCHT_TITLEYEAR) {
1456 infoPtr->hWndYearEdit=CreateWindowExA(0,
1459 WS_VISIBLE | WS_CHILD |UDS_SETBUDDYINT,
1460 infoPtr->titleyear.left+3,infoPtr->titlebtnnext.top,
1461 infoPtr->titleyear.right-infoPtr->titleyear.left,
1462 infoPtr->textHeight,
1467 infoPtr->hWndYearUpDown=CreateWindowExA(0,
1470 WS_VISIBLE | WS_CHILD |UDS_SETBUDDYINT|UDS_NOTHOUSANDS|UDS_ARROWKEYS,
1471 infoPtr->titleyear.right+6,infoPtr->titlebtnnext.top,
1473 infoPtr->textHeight,
1478 SendMessageA( infoPtr->hWndYearUpDown, UDM_SETRANGE, (WPARAM) 0, MAKELONG (9999, 1753));
1479 SendMessageA( infoPtr->hWndYearUpDown, UDM_SETBUDDY, (WPARAM) infoPtr->hWndYearEdit, (LPARAM)0 );
1480 SendMessageA( infoPtr->hWndYearUpDown, UDM_SETPOS, (WPARAM) 0,(LPARAM)infoPtr->currentYear );
1484 if(hit == MCHT_TODAYLINK) {
1485 infoPtr->currentMonth=infoPtr->todaysDate.wMonth;
1486 infoPtr->currentYear=infoPtr->todaysDate.wYear;
1487 InvalidateRect(hwnd, NULL, FALSE);
1490 if(hit == MCHT_CALENDARDATE) {
1491 SYSTEMTIME selArray[2];
1494 MONTHCAL_CopyTime(&ht.st, &selArray[0]);
1495 MONTHCAL_CopyTime(&ht.st, &selArray[1]);
1496 MONTHCAL_SetSelRange(hwnd,0,(LPARAM) &selArray);
1497 MONTHCAL_SetCurSel(hwnd,0,(LPARAM) &selArray);
1498 TRACE("MCHT_CALENDARDATE\n");
1499 nmsc.nmhdr.hwndFrom = hwnd;
1500 nmsc.nmhdr.idFrom = GetWindowLongPtrW(hwnd, GWLP_ID);
1501 nmsc.nmhdr.code = MCN_SELCHANGE;
1502 MONTHCAL_CopyTime(&infoPtr->minSel,&nmsc.stSelStart);
1503 MONTHCAL_CopyTime(&infoPtr->maxSel,&nmsc.stSelEnd);
1505 SendMessageA(infoPtr->hwndNotify, WM_NOTIFY,
1506 (WPARAM)nmsc.nmhdr.idFrom,(LPARAM)&nmsc);
1509 /* redraw both old and new days if the selected day changed */
1510 if(infoPtr->curSelDay != ht.st.wDay) {
1511 MONTHCAL_CalcPosFromDay(infoPtr, ht.st.wDay, ht.st.wMonth, &rcDay);
1512 InvalidateRect(hwnd, &rcDay, TRUE);
1514 MONTHCAL_CalcPosFromDay(infoPtr, infoPtr->curSelDay, infoPtr->currentMonth, &rcDay);
1515 InvalidateRect(hwnd, &rcDay, TRUE);
1518 infoPtr->firstSelDay = ht.st.wDay;
1519 infoPtr->curSelDay = ht.st.wDay;
1520 infoPtr->status = MC_SEL_LBUTDOWN;
1529 MONTHCAL_LButtonUp(HWND hwnd, WPARAM wParam, LPARAM lParam)
1531 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
1534 BOOL redraw = FALSE;
1540 if(infoPtr->status & MC_NEXTPRESSED) {
1541 KillTimer(hwnd, MC_NEXTMONTHTIMER);
1542 infoPtr->status &= ~MC_NEXTPRESSED;
1545 if(infoPtr->status & MC_PREVPRESSED) {
1546 KillTimer(hwnd, MC_PREVMONTHTIMER);
1547 infoPtr->status &= ~MC_PREVPRESSED;
1551 ht.pt.x = (INT)LOWORD(lParam);
1552 ht.pt.y = (INT)HIWORD(lParam);
1553 hit = MONTHCAL_HitTest(hwnd, (LPARAM)&ht);
1555 infoPtr->status = MC_SEL_LBUTUP;
1557 if(hit ==MCHT_CALENDARDATENEXT) {
1558 MONTHCAL_GoToNextMonth(hwnd, infoPtr);
1559 InvalidateRect(hwnd, NULL, FALSE);
1562 if(hit == MCHT_CALENDARDATEPREV){
1563 MONTHCAL_GoToPrevMonth(hwnd, infoPtr);
1564 InvalidateRect(hwnd, NULL, FALSE);
1567 nmhdr.hwndFrom = hwnd;
1568 nmhdr.idFrom = GetWindowLongPtrW( hwnd, GWLP_ID);
1569 nmhdr.code = NM_RELEASEDCAPTURE;
1570 TRACE("Sent notification from %p to %p\n", hwnd, infoPtr->hwndNotify);
1572 SendMessageA(infoPtr->hwndNotify, WM_NOTIFY,
1573 (WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr);
1574 /* redraw if necessary */
1576 InvalidateRect(hwnd, NULL, FALSE);
1577 /* only send MCN_SELECT if currently displayed month's day was selected */
1578 if(hit == MCHT_CALENDARDATE) {
1579 nmsc.nmhdr.hwndFrom = hwnd;
1580 nmsc.nmhdr.idFrom = GetWindowLongPtrW(hwnd, GWLP_ID);
1581 nmsc.nmhdr.code = MCN_SELECT;
1582 MONTHCAL_CopyTime(&infoPtr->minSel, &nmsc.stSelStart);
1583 MONTHCAL_CopyTime(&infoPtr->maxSel, &nmsc.stSelEnd);
1585 SendMessageA(infoPtr->hwndNotify, WM_NOTIFY,
1586 (WPARAM)nmsc.nmhdr.idFrom, (LPARAM)&nmsc);
1594 MONTHCAL_Timer(HWND hwnd, WPARAM wParam, LPARAM lParam)
1596 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
1597 BOOL redraw = FALSE;
1599 TRACE(" %d\n", wParam);
1600 if(!infoPtr) return 0;
1603 case MC_NEXTMONTHTIMER:
1605 MONTHCAL_GoToNextMonth(hwnd, infoPtr);
1607 case MC_PREVMONTHTIMER:
1609 MONTHCAL_GoToPrevMonth(hwnd, infoPtr);
1612 ERR("got unknown timer\n");
1615 /* redraw only if necessary */
1617 InvalidateRect(hwnd, NULL, FALSE);
1624 MONTHCAL_MouseMove(HWND hwnd, WPARAM wParam, LPARAM lParam)
1626 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
1628 int oldselday, selday, hit;
1631 if(!(infoPtr->status & MC_SEL_LBUTDOWN)) return 0;
1633 ht.pt.x = LOWORD(lParam);
1634 ht.pt.y = HIWORD(lParam);
1636 hit = MONTHCAL_HitTest(hwnd, (LPARAM)&ht);
1638 /* not on the calendar date numbers? bail out */
1639 TRACE("hit:%x\n",hit);
1640 if((hit & MCHT_CALENDARDATE) != MCHT_CALENDARDATE) return 0;
1642 selday = ht.st.wDay;
1643 oldselday = infoPtr->curSelDay;
1644 infoPtr->curSelDay = selday;
1645 MONTHCAL_CalcPosFromDay(infoPtr, selday, ht.st. wMonth, &r);
1647 if(GetWindowLongA(hwnd, GWL_STYLE) & MCS_MULTISELECT) {
1648 SYSTEMTIME selArray[2];
1651 MONTHCAL_GetSelRange(hwnd, 0, (LPARAM)&selArray);
1653 if(infoPtr->firstSelDay==selArray[0].wDay) i=1;
1654 TRACE("oldRange:%d %d %d %d\n", infoPtr->firstSelDay, selArray[0].wDay, selArray[1].wDay, i);
1655 if(infoPtr->firstSelDay==selArray[1].wDay) {
1656 /* 1st time we get here: selArray[0]=selArray[1]) */
1657 /* if we're still at the first selected date, return */
1658 if(infoPtr->firstSelDay==selday) goto done;
1659 if(selday<infoPtr->firstSelDay) i = 0;
1662 if(abs(infoPtr->firstSelDay - selday) >= infoPtr->maxSelCount) {
1663 if(selday>infoPtr->firstSelDay)
1664 selday = infoPtr->firstSelDay + infoPtr->maxSelCount;
1666 selday = infoPtr->firstSelDay - infoPtr->maxSelCount;
1669 if(selArray[i].wDay!=selday) {
1670 TRACE("newRange:%d %d %d %d\n", infoPtr->firstSelDay, selArray[0].wDay, selArray[1].wDay, i);
1672 selArray[i].wDay = selday;
1674 if(selArray[0].wDay>selArray[1].wDay) {
1676 tempday = selArray[1].wDay;
1677 selArray[1].wDay = selArray[0].wDay;
1678 selArray[0].wDay = tempday;
1681 MONTHCAL_SetSelRange(hwnd, 0, (LPARAM)&selArray);
1687 /* only redraw if the currently selected day changed */
1688 /* FIXME: this should specify a rectangle containing only the days that changed */
1689 /* using InvalidateRect */
1690 if(oldselday != infoPtr->curSelDay)
1691 InvalidateRect(hwnd, NULL, FALSE);
1698 MONTHCAL_Paint(HWND hwnd, WPARAM wParam)
1700 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
1704 /* fill ps.rcPaint with a default rect */
1705 memcpy(&(ps.rcPaint), &(infoPtr->rcClient), sizeof(infoPtr->rcClient));
1707 hdc = (wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam);
1708 MONTHCAL_Refresh(hwnd, hdc, &ps);
1709 if(!wParam) EndPaint(hwnd, &ps);
1715 MONTHCAL_KillFocus(HWND hwnd, WPARAM wParam, LPARAM lParam)
1719 InvalidateRect(hwnd, NULL, TRUE);
1726 MONTHCAL_SetFocus(HWND hwnd, WPARAM wParam, LPARAM lParam)
1730 InvalidateRect(hwnd, NULL, FALSE);
1735 /* sets the size information */
1736 static void MONTHCAL_UpdateSize(HWND hwnd)
1738 HDC hdc = GetDC(hwnd);
1739 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
1740 RECT *rcClient=&infoPtr->rcClient;
1741 RECT *rcDraw=&infoPtr->rcDraw;
1742 RECT *title=&infoPtr->title;
1743 RECT *prev=&infoPtr->titlebtnprev;
1744 RECT *next=&infoPtr->titlebtnnext;
1745 RECT *titlemonth=&infoPtr->titlemonth;
1746 RECT *titleyear=&infoPtr->titleyear;
1747 RECT *wdays=&infoPtr->wdays;
1748 RECT *weeknumrect=&infoPtr->weeknums;
1749 RECT *days=&infoPtr->days;
1750 RECT *todayrect=&infoPtr->todayrect;
1753 DWORD dwStyle = GetWindowLongA(hwnd, GWL_STYLE);
1757 currentFont = SelectObject(hdc, infoPtr->hFont);
1759 /* FIXME: need a way to determine current font, without setting it */
1761 if(infoPtr->hFont!=currentFont) {
1762 SelectObject(hdc, currentFont);
1763 infoPtr->hFont=currentFont;
1764 GetObjectA(currentFont, sizeof(LOGFONTA), &logFont);
1765 logFont.lfWeight=FW_BOLD;
1766 infoPtr->hBoldFont = CreateFontIndirectA(&logFont);
1770 /* get the height and width of each day's text */
1771 GetTextMetricsA(hdc, &tm);
1772 infoPtr->textHeight = tm.tmHeight + tm.tmExternalLeading;
1773 GetTextExtentPoint32A(hdc, "Sun", 3, &size);
1774 infoPtr->textWidth = size.cx + 2;
1776 /* retrieve the controls client rectangle info infoPtr->rcClient */
1777 GetClientRect(hwnd, rcClient);
1779 /* rcDraw is the rectangle the control is drawn in */
1780 rcDraw->left = rcClient->left;
1781 rcDraw->right = rcClient->right;
1782 rcDraw->top = rcClient->top;
1783 rcDraw->bottom = rcClient->bottom;
1785 /* recalculate the height and width increments and offsets */
1786 /* FIXME: We use up all available width. This will inhibit having multiple
1787 calendars in a row, like win doesn
1789 if(dwStyle & MCS_WEEKNUMBERS)
1793 infoPtr->width_increment = (infoPtr->rcDraw.right - infoPtr->rcDraw.left) / xdiv;
1794 infoPtr->height_increment = (infoPtr->rcDraw.bottom - infoPtr->rcDraw.top) / 10.0;
1795 infoPtr->left_offset = (infoPtr->rcDraw.right - infoPtr->rcDraw.left) - (infoPtr->width_increment * xdiv);
1796 infoPtr->top_offset = (infoPtr->rcDraw.bottom - infoPtr->rcDraw.top) - (infoPtr->height_increment * 10.0);
1798 rcDraw->bottom = rcDraw->top + 10 * infoPtr->height_increment;
1799 /* this is correct, the control does NOT expand vertically */
1800 /* like it does horizontally */
1801 /* make sure we don't move the controls bottom out of the client */
1803 /* title line has about 3 text heights, abrev days line, 6 weeksline and today circle line*/
1804 /*if((rcDraw->top + 9 * infoPtr->textHeight + 5) < rcDraw->bottom) {
1805 rcDraw->bottom = rcDraw->top + 9 * infoPtr->textHeight + 5;
1808 /* calculate title area */
1809 title->top = rcClient->top;
1810 title->bottom = title->top + 2 * infoPtr->height_increment;
1811 title->left = rcClient->left;
1812 title->right = rcClient->right;
1814 /* set the dimensions of the next and previous buttons and center */
1815 /* the month text vertically */
1816 prev->top = next->top = title->top + 6;
1817 prev->bottom = next->bottom = title->bottom - 6;
1818 prev->left = title->left + 6;
1819 prev->right = prev->left + (title->bottom - title->top) ;
1820 next->right = title->right - 6;
1821 next->left = next->right - (title->bottom - title->top);
1823 /* titlemonth->left and right change based upon the current month */
1824 /* and are recalculated in refresh as the current month may change */
1825 /* without the control being resized */
1826 titlemonth->top = titleyear->top = title->top + (infoPtr->height_increment)/2;
1827 titlemonth->bottom = titleyear->bottom = title->bottom - (infoPtr->height_increment)/2;
1829 /* setup the dimensions of the rectangle we draw the names of the */
1830 /* days of the week in */
1831 weeknumrect->left =infoPtr->left_offset;
1832 if(dwStyle & MCS_WEEKNUMBERS)
1833 weeknumrect->right=prev->right;
1835 weeknumrect->right=weeknumrect->left;
1836 wdays->left = days->left = weeknumrect->right;
1837 wdays->right = days->right = wdays->left + 7 * infoPtr->width_increment;
1838 wdays->top = title->bottom ;
1839 wdays->bottom = wdays->top + infoPtr->height_increment;
1841 days->top = weeknumrect->top = wdays->bottom ;
1842 days->bottom = weeknumrect->bottom = days->top + 6 * infoPtr->height_increment;
1844 todayrect->left = rcClient->left;
1845 todayrect->right = rcClient->right;
1846 todayrect->top = days->bottom;
1847 todayrect->bottom = days->bottom + infoPtr->height_increment;
1849 /* uncomment for excessive debugging
1850 TRACE("dx=%d dy=%d rcC[%d %d %d %d] t[%d %d %d %d] wd[%d %d %d %d] w[%d %d %d %d] t[%d %d %d %d]\n",
1851 infoPtr->width_increment,infoPtr->height_increment,
1852 rcClient->left, rcClient->right, rcClient->top, rcClient->bottom,
1853 title->left, title->right, title->top, title->bottom,
1854 wdays->left, wdays->right, wdays->top, wdays->bottom,
1855 days->left, days->right, days->top, days->bottom,
1856 todayrect->left,todayrect->right,todayrect->top,todayrect->bottom);
1859 /* restore the originally selected font */
1860 SelectObject(hdc, currentFont);
1862 ReleaseDC(hwnd, hdc);
1865 static LRESULT MONTHCAL_Size(HWND hwnd, int Width, int Height)
1867 TRACE("(hwnd=%p, width=%d, height=%d)\n", hwnd, Width, Height);
1869 MONTHCAL_UpdateSize(hwnd);
1871 /* invalidate client area and erase background */
1872 InvalidateRect(hwnd, NULL, TRUE);
1877 /* FIXME: check whether dateMin/dateMax need to be adjusted. */
1879 MONTHCAL_Create(HWND hwnd, WPARAM wParam, LPARAM lParam)
1881 MONTHCAL_INFO *infoPtr;
1884 /* allocate memory for info structure */
1885 infoPtr =(MONTHCAL_INFO*)Alloc(sizeof(MONTHCAL_INFO));
1886 SetWindowLongPtrW(hwnd, 0, (DWORD_PTR)infoPtr);
1888 if(infoPtr == NULL) {
1889 ERR( "could not allocate info memory!\n");
1892 if((MONTHCAL_INFO*)GetWindowLongPtrW(hwnd, 0) != infoPtr) {
1893 ERR( "pointer assignment error!\n");
1897 infoPtr->hwndNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
1899 infoPtr->hFont = GetStockObject(DEFAULT_GUI_FONT);
1900 GetObjectA(infoPtr->hFont, sizeof(LOGFONTA), &logFont);
1901 logFont.lfWeight = FW_BOLD;
1902 infoPtr->hBoldFont = CreateFontIndirectA(&logFont);
1904 /* initialize info structure */
1905 /* FIXME: calculate systemtime ->> localtime(substract timezoneinfo) */
1907 GetSystemTime(&infoPtr->todaysDate);
1908 MONTHCAL_SetFirstDayOfWeek(hwnd,0,(LPARAM)-1);
1909 infoPtr->currentMonth = infoPtr->todaysDate.wMonth;
1910 infoPtr->currentYear = infoPtr->todaysDate.wYear;
1911 MONTHCAL_CopyTime(&infoPtr->todaysDate, &infoPtr->minDate);
1912 MONTHCAL_CopyTime(&infoPtr->todaysDate, &infoPtr->maxDate);
1913 infoPtr->maxDate.wYear=2050;
1914 infoPtr->minDate.wYear=1950;
1915 infoPtr->maxSelCount = 7;
1916 infoPtr->monthRange = 3;
1917 infoPtr->monthdayState = Alloc
1918 (infoPtr->monthRange * sizeof(MONTHDAYSTATE));
1919 infoPtr->titlebk = GetSysColor(COLOR_ACTIVECAPTION);
1920 infoPtr->titletxt = GetSysColor(COLOR_WINDOW);
1921 infoPtr->monthbk = GetSysColor(COLOR_WINDOW);
1922 infoPtr->trailingtxt = GetSysColor(COLOR_GRAYTEXT);
1923 infoPtr->bk = GetSysColor(COLOR_WINDOW);
1924 infoPtr->txt = GetSysColor(COLOR_WINDOWTEXT);
1926 /* call MONTHCAL_UpdateSize to set all of the dimensions */
1927 /* of the control */
1928 MONTHCAL_UpdateSize(hwnd);
1935 MONTHCAL_Destroy(HWND hwnd, WPARAM wParam, LPARAM lParam)
1937 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
1939 /* free month calendar info data */
1940 if(infoPtr->monthdayState)
1941 Free(infoPtr->monthdayState);
1943 SetWindowLongPtrW(hwnd, 0, 0);
1948 static LRESULT WINAPI
1949 MONTHCAL_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1951 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n", hwnd, uMsg, wParam, lParam);
1952 if (!MONTHCAL_GetInfoPtr(hwnd) && (uMsg != WM_CREATE))
1953 return DefWindowProcA(hwnd, uMsg, wParam, lParam);
1957 return MONTHCAL_GetCurSel(hwnd, wParam, lParam);
1960 return MONTHCAL_SetCurSel(hwnd, wParam, lParam);
1962 case MCM_GETMAXSELCOUNT:
1963 return MONTHCAL_GetMaxSelCount(hwnd, wParam, lParam);
1965 case MCM_SETMAXSELCOUNT:
1966 return MONTHCAL_SetMaxSelCount(hwnd, wParam, lParam);
1968 case MCM_GETSELRANGE:
1969 return MONTHCAL_GetSelRange(hwnd, wParam, lParam);
1971 case MCM_SETSELRANGE:
1972 return MONTHCAL_SetSelRange(hwnd, wParam, lParam);
1974 case MCM_GETMONTHRANGE:
1975 return MONTHCAL_GetMonthRange(hwnd, wParam, lParam);
1977 case MCM_SETDAYSTATE:
1978 return MONTHCAL_SetDayState(hwnd, wParam, lParam);
1980 case MCM_GETMINREQRECT:
1981 return MONTHCAL_GetMinReqRect(hwnd, wParam, lParam);
1984 return MONTHCAL_GetColor(hwnd, wParam, lParam);
1987 return MONTHCAL_SetColor(hwnd, wParam, lParam);
1990 return MONTHCAL_GetToday(hwnd, wParam, lParam);
1993 return MONTHCAL_SetToday(hwnd, wParam, lParam);
1996 return MONTHCAL_HitTest(hwnd,lParam);
1998 case MCM_GETFIRSTDAYOFWEEK:
1999 return MONTHCAL_GetFirstDayOfWeek(hwnd, wParam, lParam);
2001 case MCM_SETFIRSTDAYOFWEEK:
2002 return MONTHCAL_SetFirstDayOfWeek(hwnd, wParam, lParam);
2005 return MONTHCAL_GetRange(hwnd, wParam, lParam);
2008 return MONTHCAL_SetRange(hwnd, wParam, lParam);
2010 case MCM_GETMONTHDELTA:
2011 return MONTHCAL_GetMonthDelta(hwnd, wParam, lParam);
2013 case MCM_SETMONTHDELTA:
2014 return MONTHCAL_SetMonthDelta(hwnd, wParam, lParam);
2016 case MCM_GETMAXTODAYWIDTH:
2017 return MONTHCAL_GetMaxTodayWidth(hwnd);
2020 return DLGC_WANTARROWS | DLGC_WANTCHARS;
2023 return MONTHCAL_KillFocus(hwnd, wParam, lParam);
2025 case WM_RBUTTONDOWN:
2026 return MONTHCAL_RButtonDown(hwnd, wParam, lParam);
2028 case WM_LBUTTONDOWN:
2029 return MONTHCAL_LButtonDown(hwnd, wParam, lParam);
2032 return MONTHCAL_MouseMove(hwnd, wParam, lParam);
2035 return MONTHCAL_LButtonUp(hwnd, wParam, lParam);
2038 return MONTHCAL_Paint(hwnd, wParam);
2041 return MONTHCAL_SetFocus(hwnd, wParam, lParam);
2044 return MONTHCAL_Size(hwnd, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
2047 return MONTHCAL_Create(hwnd, wParam, lParam);
2050 return MONTHCAL_Timer(hwnd, wParam, lParam);
2053 return MONTHCAL_Destroy(hwnd, wParam, lParam);
2056 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
2057 ERR( "unknown msg %04x wp=%08x lp=%08lx\n", uMsg, wParam, lParam);
2058 return DefWindowProcA(hwnd, uMsg, wParam, lParam);
2065 MONTHCAL_Register(void)
2069 ZeroMemory(&wndClass, sizeof(WNDCLASSA));
2070 wndClass.style = CS_GLOBALCLASS;
2071 wndClass.lpfnWndProc = (WNDPROC)MONTHCAL_WindowProc;
2072 wndClass.cbClsExtra = 0;
2073 wndClass.cbWndExtra = sizeof(MONTHCAL_INFO *);
2074 wndClass.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
2075 wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
2076 wndClass.lpszClassName = MONTHCAL_CLASSA;
2078 RegisterClassA(&wndClass);
2083 MONTHCAL_Unregister(void)
2085 UnregisterClassA(MONTHCAL_CLASSA, NULL);