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
28 * FIXME: handle resources better (doesn't work now); also take care
29 of internationalization.
30 * FIXME: keyboard handling.
45 #include "wine/debug.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(monthcal);
49 #define MC_SEL_LBUTUP 1 /* Left button released */
50 #define MC_SEL_LBUTDOWN 2 /* Left button pressed in calendar */
51 #define MC_PREVPRESSED 4 /* Prev month button pressed */
52 #define MC_NEXTPRESSED 8 /* Next month button pressed */
53 #define MC_NEXTMONTHDELAY 350 /* when continuously pressing `next */
54 /* month', wait 500 ms before going */
55 /* to the next month */
56 #define MC_NEXTMONTHTIMER 1 /* Timer ID's */
57 #define MC_PREVMONTHTIMER 2
75 int firstDayplace; /* place of the first day of the current month */
76 int delta; /* scroll rate; # of months that the */
77 /* control moves when user clicks a scroll button */
78 int visible; /* # of months visible */
79 int firstDay; /* Start month calendar with firstDay's day */
81 MONTHDAYSTATE *monthdayState;
82 SYSTEMTIME todaysDate;
85 int status; /* See MC_SEL flags */
86 int curSelDay; /* current selected day */
87 int firstSelDay; /* first selected day */
95 RECT rcClient; /* rect for whole client area */
96 RECT rcDraw; /* rect for drawable portion of client area */
97 RECT title; /* rect for the header above the calendar */
98 RECT titlebtnnext; /* the `next month' button in the header */
99 RECT titlebtnprev; /* the `prev month' button in the header */
100 RECT titlemonth; /* the `month name' txt in the header */
101 RECT titleyear; /* the `year number' txt in the header */
102 RECT wdays; /* week days at top */
103 RECT days; /* calendar area */
104 RECT weeknums; /* week numbers at left side */
105 RECT todayrect; /* `today: xx/xx/xx' text rect */
106 HWND hWndYearEdit; /* Window Handle of edit box to handle years */
107 HWND hWndYearUpDown;/* Window Handle of updown box to handle years */
108 } MONTHCAL_INFO, *LPMONTHCAL_INFO;
111 /* Offsets of days in the week to the weekday of january 1. */
112 static const int DayOfWeekTable[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
115 #define MONTHCAL_GetInfoPtr(hwnd) ((MONTHCAL_INFO *)GetWindowLongA(hwnd, 0))
117 /* helper functions */
119 /* returns the number of days in any given month, checking for leap days */
120 /* january is 1, december is 12 */
121 int MONTHCAL_MonthLength(int month, int year)
123 const int mdays[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 0};
124 /*Wrap around, this eases handling*/
130 /* if we have a leap year add 1 day to February */
131 /* a leap year is a year either divisible by 400 */
132 /* or divisible by 4 and not by 100 */
133 if(month == 2) { /* February */
134 return mdays[month - 1] + ((year%400 == 0) ? 1 : ((year%100 != 0) &&
135 (year%4 == 0)) ? 1 : 0);
138 return mdays[month - 1];
143 /* make sure that time is valid */
144 static int MONTHCAL_ValidateTime(SYSTEMTIME time)
146 if(time.wMonth > 12) return FALSE;
147 if(time.wDayOfWeek > 6) return FALSE;
148 if(time.wDay > MONTHCAL_MonthLength(time.wMonth, time.wYear))
150 if(time.wHour > 23) return FALSE;
151 if(time.wMinute > 59) return FALSE;
152 if(time.wSecond > 59) return FALSE;
153 if(time.wMilliseconds > 999) return FALSE;
159 void MONTHCAL_CopyTime(const SYSTEMTIME *from, SYSTEMTIME *to)
161 to->wYear = from->wYear;
162 to->wMonth = from->wMonth;
163 to->wDayOfWeek = from->wDayOfWeek;
164 to->wDay = from->wDay;
165 to->wHour = from->wHour;
166 to->wMinute = from->wMinute;
167 to->wSecond = from->wSecond;
168 to->wMilliseconds = from->wMilliseconds;
172 /* Note:Depending on DST, this may be offset by a day.
173 Need to find out if we're on a DST place & adjust the clock accordingly.
174 Above function assumes we have a valid data.
175 Valid for year>1752; 1 <= d <= 31, 1 <= m <= 12.
179 /* returns the day in the week(0 == monday, 6 == sunday) */
180 /* day(1 == 1st, 2 == 2nd... etc), year is the year value */
181 static int MONTHCAL_CalculateDayOfWeek(DWORD day, DWORD month, DWORD year)
185 return((year + year/4 - year/100 + year/400 +
186 DayOfWeekTable[month-1] + day - 1 ) % 7);
189 /* From a given point, calculate the row (weekpos), column(daypos)
190 and day in the calendar. day== 0 mean the last day of tha last month
192 static int MONTHCAL_CalcDayFromPos(MONTHCAL_INFO *infoPtr, int x, int y,
193 int *daypos,int *weekpos)
195 int retval, firstDay;
197 /* if the point is outside the x bounds of the window put
199 if(x > infoPtr->rcClient.right) {
200 x = infoPtr->rcClient.right ;
203 *daypos = (x - infoPtr->days.left ) / infoPtr->width_increment;
204 *weekpos = (y - infoPtr->days.top ) / infoPtr->height_increment;
206 firstDay = (MONTHCAL_CalculateDayOfWeek(1, infoPtr->currentMonth, infoPtr->currentYear)+6 - infoPtr->firstDay)%7;
207 retval = *daypos + (7 * *weekpos) - firstDay;
211 /* day is the day of the month, 1 == 1st day of the month */
212 /* sets x and y to be the position of the day */
213 /* x == day, y == week where(0,0) == firstDay, 1st week */
214 static void MONTHCAL_CalcDayXY(MONTHCAL_INFO *infoPtr, int day, int month,
217 int firstDay, prevMonth;
219 firstDay = (MONTHCAL_CalculateDayOfWeek(1, infoPtr->currentMonth, infoPtr->currentYear) +6 - infoPtr->firstDay)%7;
221 if(month==infoPtr->currentMonth) {
222 *x = (day + firstDay) % 7;
223 *y = (day + firstDay - *x) / 7;
226 if(month < infoPtr->currentMonth) {
227 prevMonth = month - 1;
231 *x = (MONTHCAL_MonthLength(prevMonth, infoPtr->currentYear) - firstDay) % 7;
236 *y = MONTHCAL_MonthLength(month, infoPtr->currentYear - 1) / 7;
237 *x = (day + firstDay + MONTHCAL_MonthLength(month,
238 infoPtr->currentYear)) % 7;
242 /* x: column(day), y: row(week) */
243 static void MONTHCAL_CalcDayRect(MONTHCAL_INFO *infoPtr, RECT *r, int x, int y)
245 r->left = infoPtr->days.left + x * infoPtr->width_increment;
246 r->right = r->left + infoPtr->width_increment;
247 r->top = infoPtr->days.top + y * infoPtr->height_increment;
248 r->bottom = r->top + infoPtr->textHeight;
252 /* sets the RECT struct r to the rectangle around the day and month */
253 /* day is the day value of the month(1 == 1st), month is the month */
254 /* value(january == 1, december == 12) */
255 static inline void MONTHCAL_CalcPosFromDay(MONTHCAL_INFO *infoPtr,
256 int day, int month, RECT *r)
260 MONTHCAL_CalcDayXY(infoPtr, day, month, &x, &y);
261 MONTHCAL_CalcDayRect(infoPtr, r, x, y);
265 /* day is the day in the month(1 == 1st of the month) */
266 /* month is the month value(1 == january, 12 == december) */
267 static void MONTHCAL_CircleDay(HDC hdc, MONTHCAL_INFO *infoPtr, int day,
270 HPEN hRedPen = CreatePen(PS_SOLID, 2, RGB(255, 0, 0));
271 HPEN hOldPen2 = SelectObject(hdc, hRedPen);
277 MONTHCAL_CalcPosFromDay(infoPtr, day, month, &day_rect);
284 points[1].x = x + 0.8 * infoPtr->width_increment;
286 points[2].x = x + 0.9 * infoPtr->width_increment;
288 points[3].x = x + infoPtr->width_increment;
289 points[3].y = y + 0.5 * infoPtr->height_increment;
291 points[4].x = x + infoPtr->width_increment;
292 points[4].y = y + 0.9 * infoPtr->height_increment;
293 points[5].x = x + 0.6 * infoPtr->width_increment;
294 points[5].y = y + 0.9 * infoPtr->height_increment;
295 points[6].x = x + 0.5 * infoPtr->width_increment;
296 points[6].y = y + 0.9 * infoPtr->height_increment; /* bring the bottom up just
297 a hair to fit inside the day rectangle */
299 points[7].x = x + 0.2 * infoPtr->width_increment;
300 points[7].y = y + 0.8 * infoPtr->height_increment;
301 points[8].x = x + 0.1 * infoPtr->width_increment;
302 points[8].y = y + 0.8 * infoPtr->height_increment;
304 points[9].y = y + 0.5 * infoPtr->height_increment;
306 points[10].x = x + 0.1 * infoPtr->width_increment;
307 points[10].y = y + 0.2 * infoPtr->height_increment;
308 points[11].x = x + 0.2 * infoPtr->width_increment;
309 points[11].y = y + 0.3 * infoPtr->height_increment;
310 points[12].x = x + 0.4 * infoPtr->width_increment;
311 points[12].y = y + 0.2 * infoPtr->height_increment;
313 PolyBezier(hdc, points, 13);
314 DeleteObject(hRedPen);
315 SelectObject(hdc, hOldPen2);
319 static void MONTHCAL_DrawDay(HDC hdc, MONTHCAL_INFO *infoPtr, int day, int month,
320 int x, int y, int bold)
324 static int haveBoldFont, haveSelectedDay = FALSE;
326 HPEN hNewPen, hOldPen = 0;
330 sprintf(buf, "%d", day);
332 /* No need to check styles: when selection is not valid, it is set to zero.
333 * 1<day<31, so evertyhing's OK.
336 MONTHCAL_CalcDayRect(infoPtr, &r, x, y);
338 if((day>=infoPtr->minSel.wDay) && (day<=infoPtr->maxSel.wDay)
339 && (month==infoPtr->currentMonth)) {
343 TRACE("%d %d %d\n",day, infoPtr->minSel.wDay, infoPtr->maxSel.wDay);
344 TRACE("%ld %ld %ld %ld\n", r.left, r.top, r.right, r.bottom);
345 oldCol = SetTextColor(hdc, infoPtr->monthbk);
346 oldBk = SetBkColor(hdc, infoPtr->trailingtxt);
347 hbr = GetSysColorBrush(COLOR_GRAYTEXT);
348 hrgn = CreateEllipticRgn(r.left, r.top, r.right, r.bottom);
349 FillRgn(hdc, hrgn, hbr);
351 /* FIXME: this may need to be changed now b/c of the other
352 drawing changes 11/3/99 CMM */
353 r2.left = r.left - 0.25 * infoPtr->textWidth;
355 r2.right = r.left + 0.5 * infoPtr->textWidth;
356 r2.bottom = r.bottom;
357 if(haveSelectedDay) FillRect(hdc, &r2, hbr);
358 haveSelectedDay = TRUE;
360 haveSelectedDay = FALSE;
363 /* need to add some code for multiple selections */
365 if((bold) &&(!haveBoldFont)) {
366 SelectObject(hdc, infoPtr->hBoldFont);
369 if((!bold) &&(haveBoldFont)) {
370 SelectObject(hdc, infoPtr->hFont);
371 haveBoldFont = FALSE;
374 if(haveSelectedDay) {
375 SetTextColor(hdc, oldCol);
376 SetBkColor(hdc, oldBk);
379 SetBkMode(hdc,TRANSPARENT);
380 DrawTextA(hdc, buf, -1, &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE );
382 /* draw a rectangle around the currently selected days text */
383 if((day==infoPtr->curSelDay) && (month==infoPtr->currentMonth)) {
384 hNewPen = CreatePen(PS_ALTERNATE, 0, GetSysColor(COLOR_WINDOWTEXT) );
385 hbr = GetSysColorBrush(COLOR_WINDOWTEXT);
386 FrameRect(hdc, &r, hbr);
387 SelectObject(hdc, hOldPen);
392 /* CHECKME: For `todays date', do we need to check the locale?*/
393 static void MONTHCAL_Refresh(HWND hwnd, HDC hdc, PAINTSTRUCT* ps)
395 MONTHCAL_INFO *infoPtr=MONTHCAL_GetInfoPtr(hwnd);
396 RECT *rcClient=&infoPtr->rcClient;
397 RECT *rcDraw=&infoPtr->rcDraw;
398 RECT *title=&infoPtr->title;
399 RECT *prev=&infoPtr->titlebtnprev;
400 RECT *next=&infoPtr->titlebtnnext;
401 RECT *titlemonth=&infoPtr->titlemonth;
402 RECT *titleyear=&infoPtr->titleyear;
406 int i, j, m, mask, day, firstDay, weeknum, weeknum1,prevMonth;
407 int textHeight = infoPtr->textHeight, textWidth = infoPtr->textWidth;
411 /* LOGFONTA logFont; */
415 COLORREF oldTextColor, oldBkColor;
416 DWORD dwStyle = GetWindowLongA(hwnd, GWL_STYLE);
418 RECT rcDay; /* used in MONTHCAL_CalcDayRect() */
419 SYSTEMTIME localtime;
422 oldTextColor = SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
425 /* fill background */
426 hbr = CreateSolidBrush (infoPtr->bk);
427 FillRect(hdc, rcClient, hbr);
431 if(IntersectRect(&rcTemp, &(ps->rcPaint), title))
433 hbr = CreateSolidBrush(infoPtr->titlebk);
434 FillRect(hdc, title, hbr);
438 /* if the previous button is pressed draw it depressed */
439 if(IntersectRect(&rcTemp, &(ps->rcPaint), prev))
441 if((infoPtr->status & MC_PREVPRESSED))
442 DrawFrameControl(hdc, prev, DFC_SCROLL,
443 DFCS_SCROLLLEFT | DFCS_PUSHED |
444 (dwStyle & WS_DISABLED ? DFCS_INACTIVE : 0));
445 else /* if the previous button is pressed draw it depressed */
446 DrawFrameControl(hdc, prev, DFC_SCROLL,
447 DFCS_SCROLLLEFT |(dwStyle & WS_DISABLED ? DFCS_INACTIVE : 0));
450 /* if next button is depressed draw it depressed */
451 if(IntersectRect(&rcTemp, &(ps->rcPaint), next))
453 if((infoPtr->status & MC_NEXTPRESSED))
454 DrawFrameControl(hdc, next, DFC_SCROLL,
455 DFCS_SCROLLRIGHT | DFCS_PUSHED |
456 (dwStyle & WS_DISABLED ? DFCS_INACTIVE : 0));
457 else /* if the next button is pressed draw it depressed */
458 DrawFrameControl(hdc, next, DFC_SCROLL,
459 DFCS_SCROLLRIGHT |(dwStyle & WS_DISABLED ? DFCS_INACTIVE : 0));
462 oldBkColor = SetBkColor(hdc, infoPtr->titlebk);
463 SetTextColor(hdc, infoPtr->titletxt);
464 currentFont = SelectObject(hdc, infoPtr->hBoldFont);
466 /* titlemonth->left and right are set in MONTHCAL_UpdateSize */
467 titlemonth->left = title->left;
468 titlemonth->right = title->right;
470 GetLocaleInfoA( LOCALE_USER_DEFAULT,LOCALE_SMONTHNAME1+infoPtr->currentMonth -1,
472 sprintf(buf, "%s %ld", buf1, infoPtr->currentYear);
474 if(IntersectRect(&rcTemp, &(ps->rcPaint), titlemonth))
476 DrawTextA(hdc, buf, strlen(buf), titlemonth,
477 DT_CENTER | DT_VCENTER | DT_SINGLELINE);
480 SelectObject(hdc, infoPtr->hFont);
482 /* titlemonth left/right contained rect for whole titletxt('June 1999')
483 * MCM_HitTestInfo wants month & year rects, so prepare these now.
484 *(no, we can't draw them separately; the whole text is centered)
486 GetTextExtentPoint32A(hdc, buf, strlen(buf), &size);
487 titlemonth->left = title->right / 2 - size.cx / 2;
488 titleyear->right = title->right / 2 + size.cx / 2;
489 GetTextExtentPoint32A(hdc, buf1, strlen(buf1), &size);
490 titlemonth->right = titlemonth->left + size.cx;
491 titleyear->left = titlemonth->right;
493 /* draw month area */
494 rcTemp.top=infoPtr->wdays.top;
495 rcTemp.left=infoPtr->wdays.left;
496 rcTemp.bottom=infoPtr->todayrect.bottom;
497 rcTemp.right =infoPtr->todayrect.right;
498 if(IntersectRect(&rcTemp, &(ps->rcPaint), &rcTemp))
500 hbr = CreateSolidBrush(infoPtr->monthbk);
501 FillRect(hdc, &rcTemp, hbr);
505 /* draw line under day abbreviatons */
507 MoveToEx(hdc, infoPtr->days.left + 3, title->bottom + textHeight + 1, NULL);
509 LineTo(hdc, rcDraw->right - 3, title->bottom + textHeight + 1);
511 prevMonth = infoPtr->currentMonth - 1;
512 if(prevMonth == 0) /* if currentMonth is january(1) prevMonth is */
513 prevMonth = 12; /* december(12) of the previous year */
515 infoPtr->wdays.left = infoPtr->days.left = infoPtr->weeknums.right;
516 /* draw day abbreviations */
518 SetBkColor(hdc, infoPtr->monthbk);
519 SetTextColor(hdc, infoPtr->trailingtxt);
521 /* copy this rect so we can change the values without changing */
522 /* the original version */
523 days->left = infoPtr->wdays.left;
524 days->right = days->left + infoPtr->width_increment;
525 days->top = infoPtr->wdays.top;
526 days->bottom = infoPtr->wdays.bottom;
528 i = infoPtr->firstDay;
531 GetLocaleInfoA( LOCALE_USER_DEFAULT,LOCALE_SABBREVDAYNAME1 + (i +j)%7,
533 DrawTextA(hdc, buf, strlen(buf), days,
534 DT_CENTER | DT_VCENTER | DT_SINGLELINE );
535 days->left+=infoPtr->width_increment;
536 days->right+=infoPtr->width_increment;
539 /* draw day numbers; first, the previous month */
541 firstDay = MONTHCAL_CalculateDayOfWeek(1, infoPtr->currentMonth, infoPtr->currentYear);
543 day = MONTHCAL_MonthLength(prevMonth, infoPtr->currentYear) +
544 (infoPtr->firstDay + 7 - firstDay)%7 + 1;
545 if (day > MONTHCAL_MonthLength(prevMonth, infoPtr->currentYear))
547 startofprescal = day;
552 while(day <= MONTHCAL_MonthLength(prevMonth, infoPtr->currentYear)) {
553 MONTHCAL_CalcDayRect(infoPtr, &rcDay, i, 0);
554 if(IntersectRect(&rcTemp, &(ps->rcPaint), &rcDay))
556 MONTHCAL_DrawDay(hdc, infoPtr, day, prevMonth, i, 0,
557 infoPtr->monthdayState[m] & mask);
565 /* draw `current' month */
567 day = 1; /* start at the beginning of the current month */
569 infoPtr->firstDayplace = i;
570 SetTextColor(hdc, infoPtr->txt);
574 /* draw the first week of the current month */
576 MONTHCAL_CalcDayRect(infoPtr, &rcDay, i, 0);
577 if(IntersectRect(&rcTemp, &(ps->rcPaint), &rcDay))
580 MONTHCAL_DrawDay(hdc, infoPtr, day, infoPtr->currentMonth, i, 0,
581 infoPtr->monthdayState[m] & mask);
583 if((infoPtr->currentMonth==infoPtr->todaysDate.wMonth) &&
584 (day==infoPtr->todaysDate.wDay) &&
585 (infoPtr->currentYear == infoPtr->todaysDate.wYear)) {
586 if(!(dwStyle & MCS_NOTODAYCIRCLE))
587 MONTHCAL_CircleDay(hdc, infoPtr, day, infoPtr->currentMonth);
596 j = 1; /* move to the 2nd week of the current month */
597 i = 0; /* move back to sunday */
598 while(day <= MONTHCAL_MonthLength(infoPtr->currentMonth, infoPtr->currentYear)) {
599 MONTHCAL_CalcDayRect(infoPtr, &rcDay, i, j);
600 if(IntersectRect(&rcTemp, &(ps->rcPaint), &rcDay))
602 MONTHCAL_DrawDay(hdc, infoPtr, day, infoPtr->currentMonth, i, j,
603 infoPtr->monthdayState[m] & mask);
605 if((infoPtr->currentMonth==infoPtr->todaysDate.wMonth) &&
606 (day==infoPtr->todaysDate.wDay) &&
607 (infoPtr->currentYear == infoPtr->todaysDate.wYear))
608 if(!(dwStyle & MCS_NOTODAYCIRCLE))
609 MONTHCAL_CircleDay(hdc, infoPtr, day, infoPtr->currentMonth);
614 if(i>6) { /* past saturday, goto the next weeks sunday */
620 /* draw `next' month */
622 day = 1; /* start at the first day of the next month */
626 SetTextColor(hdc, infoPtr->trailingtxt);
627 while((i<7) &&(j<6)) {
628 MONTHCAL_CalcDayRect(infoPtr, &rcDay, i, j);
629 if(IntersectRect(&rcTemp, &(ps->rcPaint), &rcDay))
631 MONTHCAL_DrawDay(hdc, infoPtr, day, infoPtr->currentMonth + 1, i, j,
632 infoPtr->monthdayState[m] & mask);
638 if(i==7) { /* past saturday, go to next week's sunday */
643 SetTextColor(hdc, infoPtr->txt);
646 /* draw `today' date if style allows it, and draw a circle before today's
647 * date if necessary */
649 if(!(dwStyle & MCS_NOTODAY)) {
651 if(!(dwStyle & MCS_NOTODAYCIRCLE)) {
652 /*day is the number of days from nextmonth we put on the calendar */
653 MONTHCAL_CircleDay(hdc, infoPtr,
654 day+MONTHCAL_MonthLength(infoPtr->currentMonth,infoPtr->currentYear),
655 infoPtr->currentMonth);
658 if (!LoadStringA(COMCTL32_hModule,IDM_TODAY,buf1,sizeof(buf1)))
660 WARN("Can't load resource\n");
661 strcpy(buf1,"Today:");
663 MONTHCAL_CalcDayRect(infoPtr, &rtoday, 1, 6);
664 MONTHCAL_CopyTime(&infoPtr->todaysDate,&localtime);
665 GetDateFormatA(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&localtime,NULL,buf2,sizeof(buf2));
666 sprintf(buf, "%s %s", buf1,buf2);
667 SelectObject(hdc, infoPtr->hBoldFont);
669 if(IntersectRect(&rcTemp, &(ps->rcPaint), &rtoday))
671 DrawTextA(hdc, buf, -1, &rtoday, DT_CALCRECT | DT_LEFT | DT_VCENTER | DT_SINGLELINE);
672 DrawTextA(hdc, buf, -1, &rtoday, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
674 SelectObject(hdc, infoPtr->hFont);
677 /*eventually draw week numbers*/
678 if(dwStyle & MCS_WEEKNUMBERS) {
679 /* display weeknumbers*/
682 /* Rules what week to call the first week of a new year:
683 LOCALE_IFIRSTWEEKOFYEAR == 0 (e.g US?):
684 The week containing Jan 1 is the first week of year
685 LOCALE_IFIRSTWEEKOFYEAR == 2 (e.g. Germany):
686 First week of year must contain 4 days of the new year
687 LOCALE_IFIRSTWEEKOFYEAR == 1 (what contries?)
688 The first week of the year must contain only days of the new year
690 GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_IFIRSTWEEKOFYEAR,
692 sscanf(buf, "%d", &weeknum);
703 if (infoPtr->currentMonth < 2)
705 /* calculate all those exceptions for january */
706 weeknum1=MONTHCAL_CalculateDayOfWeek(1,1,infoPtr->currentYear);
707 if ((infoPtr->firstDay +7 - weeknum1)%7 > mindays)
713 weeknum+=MONTHCAL_MonthLength(i+1, infoPtr->currentYear-1);
714 weeknum +=startofprescal+ 7;
716 weeknum1=MONTHCAL_CalculateDayOfWeek(1,1,infoPtr->currentYear-1);
717 if ((infoPtr->firstDay + 7 - weeknum1)%7 > mindays)
724 for(i=0; i<prevMonth-1; i++)
725 weeknum+=MONTHCAL_MonthLength(i+1, infoPtr->currentYear);
726 weeknum +=startofprescal+ 7;
728 weeknum1=MONTHCAL_CalculateDayOfWeek(1,1,infoPtr->currentYear);
729 if ((infoPtr->firstDay + 7 - weeknum1)%7 > mindays)
732 days->left = infoPtr->weeknums.left;
733 days->right = infoPtr->weeknums.right;
734 days->top = infoPtr->weeknums.top;
735 days->bottom = days->top +infoPtr->height_increment;
737 if((i==0)&&(weeknum>50))
739 sprintf(buf, "%d", weeknum);
742 else if((i==5)&&(weeknum>47))
744 sprintf(buf, "%d", 1);
747 sprintf(buf, "%d", weeknum + i);
748 DrawTextA(hdc, buf, -1, days, DT_CENTER | DT_VCENTER | DT_SINGLELINE );
749 days->top+=infoPtr->height_increment;
750 days->bottom+=infoPtr->height_increment;
753 MoveToEx(hdc, infoPtr->weeknums.right, infoPtr->weeknums.top + 3 , NULL);
754 LineTo(hdc, infoPtr->weeknums.right, infoPtr->weeknums.bottom );
757 /* currentFont was font at entering Refresh */
759 SetBkColor(hdc, oldBkColor);
760 SelectObject(hdc, currentFont);
761 SetTextColor(hdc, oldTextColor);
766 MONTHCAL_GetMinReqRect(HWND hwnd, WPARAM wParam, LPARAM lParam)
768 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
769 LPRECT lpRect = (LPRECT) lParam;
770 TRACE("%x %lx\n", wParam, lParam);
772 /* validate parameters */
774 if((infoPtr==NULL) ||(lpRect == NULL) ) return FALSE;
776 lpRect->left = infoPtr->rcClient.left;
777 lpRect->right = infoPtr->rcClient.right;
778 lpRect->top = infoPtr->rcClient.top;
779 lpRect->bottom = infoPtr->rcClient.bottom;
785 MONTHCAL_GetColor(HWND hwnd, WPARAM wParam, LPARAM lParam)
787 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
789 TRACE("%x %lx\n", wParam, lParam);
791 switch((int)wParam) {
792 case MCSC_BACKGROUND:
797 return infoPtr->titlebk;
799 return infoPtr->titletxt;
801 return infoPtr->monthbk;
802 case MCSC_TRAILINGTEXT:
803 return infoPtr->trailingtxt;
811 MONTHCAL_SetColor(HWND hwnd, WPARAM wParam, LPARAM lParam)
813 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
816 TRACE("%x %lx\n", wParam, lParam);
818 switch((int)wParam) {
819 case MCSC_BACKGROUND:
821 infoPtr->bk = (COLORREF)lParam;
825 infoPtr->txt = (COLORREF)lParam;
828 prev = infoPtr->titlebk;
829 infoPtr->titlebk = (COLORREF)lParam;
832 prev=infoPtr->titletxt;
833 infoPtr->titletxt = (COLORREF)lParam;
836 prev = infoPtr->monthbk;
837 infoPtr->monthbk = (COLORREF)lParam;
839 case MCSC_TRAILINGTEXT:
840 prev = infoPtr->trailingtxt;
841 infoPtr->trailingtxt = (COLORREF)lParam;
845 InvalidateRect(hwnd, NULL, FALSE);
851 MONTHCAL_GetMonthDelta(HWND hwnd, WPARAM wParam, LPARAM lParam)
853 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
855 TRACE("%x %lx\n", wParam, lParam);
858 return infoPtr->delta;
860 return infoPtr->visible;
865 MONTHCAL_SetMonthDelta(HWND hwnd, WPARAM wParam, LPARAM lParam)
867 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
868 int prev = infoPtr->delta;
870 TRACE("%x %lx\n", wParam, lParam);
872 infoPtr->delta = (int)wParam;
878 MONTHCAL_GetFirstDayOfWeek(HWND hwnd, WPARAM wParam, LPARAM lParam)
880 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
882 return infoPtr->firstDay;
886 /* sets the first day of the week that will appear in the control */
887 /* 0 == Monday, 6 == Sunday */
888 /* FIXME: this needs to be implemented properly in MONTHCAL_Refresh() */
889 /* FIXME: we need more error checking here */
891 MONTHCAL_SetFirstDayOfWeek(HWND hwnd, WPARAM wParam, LPARAM lParam)
893 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
894 int prev = infoPtr->firstDay;
898 TRACE("%x %lx\n", wParam, lParam);
900 if((lParam >= 0) && (lParam < 7)) {
901 infoPtr->firstDay = (int)lParam;
905 GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_IFIRSTDAYOFWEEK,
907 TRACE("%s %d\n", buf, strlen(buf));
908 if(sscanf(buf, "%d", &day) == 1)
909 infoPtr->firstDay = day;
911 infoPtr->firstDay = 0;
917 /* FIXME: fill this in */
919 MONTHCAL_GetMonthRange(HWND hwnd, WPARAM wParam, LPARAM lParam)
921 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
923 TRACE("%x %lx\n", wParam, lParam);
926 return infoPtr->monthRange;
931 MONTHCAL_GetMaxTodayWidth(HWND hwnd)
933 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
935 return(infoPtr->todayrect.right - infoPtr->todayrect.left);
939 /* FIXME: are validated times taken from current date/time or simply
941 * FIXME: check whether MCM_GETMONTHRANGE shows correct result after
942 * adjusting range with MCM_SETRANGE
946 MONTHCAL_SetRange(HWND hwnd, WPARAM wParam, LPARAM lParam)
948 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
949 SYSTEMTIME lprgSysTimeArray[1];
952 TRACE("%x %lx\n", wParam, lParam);
954 if(wParam & GDTR_MAX) {
955 if(MONTHCAL_ValidateTime(lprgSysTimeArray[1])){
956 MONTHCAL_CopyTime(&lprgSysTimeArray[1], &infoPtr->maxDate);
957 infoPtr->rangeValid|=GDTR_MAX;
959 GetSystemTime(&infoPtr->todaysDate);
960 MONTHCAL_CopyTime(&infoPtr->todaysDate, &infoPtr->maxDate);
963 if(wParam & GDTR_MIN) {
964 if(MONTHCAL_ValidateTime(lprgSysTimeArray[0])) {
965 MONTHCAL_CopyTime(&lprgSysTimeArray[0], &infoPtr->maxDate);
966 infoPtr->rangeValid|=GDTR_MIN;
968 GetSystemTime(&infoPtr->todaysDate);
969 MONTHCAL_CopyTime(&infoPtr->todaysDate, &infoPtr->maxDate);
973 prev = infoPtr->monthRange;
974 infoPtr->monthRange = infoPtr->maxDate.wMonth - infoPtr->minDate.wMonth;
976 if(infoPtr->monthRange!=prev) {
977 infoPtr->monthdayState = COMCTL32_ReAlloc(infoPtr->monthdayState,
978 infoPtr->monthRange * sizeof(MONTHDAYSTATE));
985 /* CHECKME: At the moment, we copy ranges anyway,regardless of
986 * infoPtr->rangeValid; a invalid range is simply filled with zeros in
987 * SetRange. Is this the right behavior?
991 MONTHCAL_GetRange(HWND hwnd, WPARAM wParam, LPARAM lParam)
993 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
994 SYSTEMTIME *lprgSysTimeArray = (SYSTEMTIME *)lParam;
996 /* validate parameters */
998 if((infoPtr==NULL) || (lprgSysTimeArray==NULL)) return FALSE;
1000 MONTHCAL_CopyTime(&infoPtr->maxDate, &lprgSysTimeArray[1]);
1001 MONTHCAL_CopyTime(&infoPtr->minDate, &lprgSysTimeArray[0]);
1003 return infoPtr->rangeValid;
1008 MONTHCAL_SetDayState(HWND hwnd, WPARAM wParam, LPARAM lParam)
1011 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
1012 int i, iMonths = (int)wParam;
1013 MONTHDAYSTATE *dayStates = (LPMONTHDAYSTATE)lParam;
1015 TRACE("%x %lx\n", wParam, lParam);
1016 if(iMonths!=infoPtr->monthRange) return 0;
1018 for(i=0; i<iMonths; i++)
1019 infoPtr->monthdayState[i] = dayStates[i];
1024 MONTHCAL_GetCurSel(HWND hwnd, WPARAM wParam, LPARAM lParam)
1026 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
1027 SYSTEMTIME *lpSel = (SYSTEMTIME *) lParam;
1029 TRACE("%x %lx\n", wParam, lParam);
1030 if((infoPtr==NULL) ||(lpSel==NULL)) return FALSE;
1031 if(GetWindowLongA(hwnd, GWL_STYLE) & MCS_MULTISELECT) return FALSE;
1033 MONTHCAL_CopyTime(&infoPtr->minSel, lpSel);
1037 /* FIXME: if the specified date is not visible, make it visible */
1038 /* FIXME: redraw? */
1040 MONTHCAL_SetCurSel(HWND hwnd, WPARAM wParam, LPARAM lParam)
1042 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
1043 SYSTEMTIME *lpSel = (SYSTEMTIME *)lParam;
1045 TRACE("%x %lx\n", wParam, lParam);
1046 if((infoPtr==NULL) ||(lpSel==NULL)) return FALSE;
1047 if(GetWindowLongA(hwnd, GWL_STYLE) & MCS_MULTISELECT) return FALSE;
1049 TRACE("%d %d\n", lpSel->wMonth, lpSel->wDay);
1051 MONTHCAL_CopyTime(lpSel, &infoPtr->minSel);
1052 MONTHCAL_CopyTime(lpSel, &infoPtr->maxSel);
1054 InvalidateRect(hwnd, NULL, FALSE);
1061 MONTHCAL_GetMaxSelCount(HWND hwnd, WPARAM wParam, LPARAM lParam)
1063 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
1065 TRACE("%x %lx\n", wParam, lParam);
1066 return infoPtr->maxSelCount;
1071 MONTHCAL_SetMaxSelCount(HWND hwnd, WPARAM wParam, LPARAM lParam)
1073 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
1075 TRACE("%x %lx\n", wParam, lParam);
1076 if(GetWindowLongA(hwnd, GWL_STYLE) & MCS_MULTISELECT) {
1077 infoPtr->maxSelCount = wParam;
1085 MONTHCAL_GetSelRange(HWND hwnd, WPARAM wParam, LPARAM lParam)
1087 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
1088 SYSTEMTIME *lprgSysTimeArray = (SYSTEMTIME *) lParam;
1090 TRACE("%x %lx\n", wParam, lParam);
1092 /* validate parameters */
1094 if((infoPtr==NULL) ||(lprgSysTimeArray==NULL)) return FALSE;
1096 if(GetWindowLongA(hwnd, GWL_STYLE) & MCS_MULTISELECT)
1098 MONTHCAL_CopyTime(&infoPtr->maxSel, &lprgSysTimeArray[1]);
1099 MONTHCAL_CopyTime(&infoPtr->minSel, &lprgSysTimeArray[0]);
1100 TRACE("[min,max]=[%d %d]\n", infoPtr->minSel.wDay, infoPtr->maxSel.wDay);
1109 MONTHCAL_SetSelRange(HWND hwnd, WPARAM wParam, LPARAM lParam)
1111 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
1112 SYSTEMTIME *lprgSysTimeArray = (SYSTEMTIME *) lParam;
1114 TRACE("%x %lx\n", wParam, lParam);
1116 /* validate parameters */
1118 if((infoPtr==NULL) ||(lprgSysTimeArray==NULL)) return FALSE;
1120 if(GetWindowLongA( hwnd, GWL_STYLE) & MCS_MULTISELECT)
1122 MONTHCAL_CopyTime(&lprgSysTimeArray[1], &infoPtr->maxSel);
1123 MONTHCAL_CopyTime(&lprgSysTimeArray[0], &infoPtr->minSel);
1124 TRACE("[min,max]=[%d %d]\n", infoPtr->minSel.wDay, infoPtr->maxSel.wDay);
1133 MONTHCAL_GetToday(HWND hwnd, WPARAM wParam, LPARAM lParam)
1135 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
1136 SYSTEMTIME *lpToday = (SYSTEMTIME *) lParam;
1138 TRACE("%x %lx\n", wParam, lParam);
1140 /* validate parameters */
1142 if((infoPtr==NULL) || (lpToday==NULL)) return FALSE;
1143 MONTHCAL_CopyTime(&infoPtr->todaysDate, lpToday);
1149 MONTHCAL_SetToday(HWND hwnd, WPARAM wParam, LPARAM lParam)
1151 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
1152 SYSTEMTIME *lpToday = (SYSTEMTIME *) lParam;
1154 TRACE("%x %lx\n", wParam, lParam);
1156 /* validate parameters */
1158 if((infoPtr==NULL) ||(lpToday==NULL)) return FALSE;
1159 MONTHCAL_CopyTime(lpToday, &infoPtr->todaysDate);
1160 InvalidateRect(hwnd, NULL, FALSE);
1166 MONTHCAL_HitTest(HWND hwnd, LPARAM lParam)
1168 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
1169 PMCHITTESTINFO lpht = (PMCHITTESTINFO)lParam;
1177 retval = MCHT_NOWHERE;
1180 /* Comment in for debugging...
1181 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,
1182 infoPtr->wdays.left, infoPtr->wdays.right,
1183 infoPtr->wdays.top, infoPtr->wdays.bottom,
1184 infoPtr->days.left, infoPtr->days.right,
1185 infoPtr->days.top, infoPtr->days.bottom,
1186 infoPtr->todayrect.left, infoPtr->todayrect.right,
1187 infoPtr->todayrect.top, infoPtr->todayrect.bottom,
1188 infoPtr->weeknums.left, infoPtr->weeknums.right,
1189 infoPtr->weeknums.top, infoPtr->weeknums.bottom);
1192 /* are we in the header? */
1194 if(PtInRect(&infoPtr->title, lpht->pt)) {
1195 if(PtInRect(&infoPtr->titlebtnprev, lpht->pt)) {
1196 retval = MCHT_TITLEBTNPREV;
1199 if(PtInRect(&infoPtr->titlebtnnext, lpht->pt)) {
1200 retval = MCHT_TITLEBTNNEXT;
1203 if(PtInRect(&infoPtr->titlemonth, lpht->pt)) {
1204 retval = MCHT_TITLEMONTH;
1207 if(PtInRect(&infoPtr->titleyear, lpht->pt)) {
1208 retval = MCHT_TITLEYEAR;
1212 retval = MCHT_TITLE;
1216 day = MONTHCAL_CalcDayFromPos(infoPtr,x,y,&wday,&wnum);
1217 if(PtInRect(&infoPtr->wdays, lpht->pt)) {
1218 retval = MCHT_CALENDARDAY;
1219 lpht->st.wYear = infoPtr->currentYear;
1220 lpht->st.wMonth = (day < 1)? infoPtr->currentMonth -1 : infoPtr->currentMonth;
1221 lpht->st.wDay = (day < 1)?
1222 MONTHCAL_MonthLength(infoPtr->currentMonth-1,infoPtr->currentYear) -day : day;
1225 if(PtInRect(&infoPtr->weeknums, lpht->pt)) {
1226 retval = MCHT_CALENDARWEEKNUM;
1227 lpht->st.wYear = infoPtr->currentYear;
1228 lpht->st.wMonth = (day < 1) ? infoPtr->currentMonth -1 :
1229 (day > MONTHCAL_MonthLength(infoPtr->currentMonth,infoPtr->currentYear)) ?
1230 infoPtr->currentMonth +1 :infoPtr->currentMonth;
1231 lpht->st.wDay = (day < 1 ) ?
1232 MONTHCAL_MonthLength(infoPtr->currentMonth-1,infoPtr->currentYear) -day :
1233 (day > MONTHCAL_MonthLength(infoPtr->currentMonth,infoPtr->currentYear)) ?
1234 day - MONTHCAL_MonthLength(infoPtr->currentMonth,infoPtr->currentYear) : day;
1237 if(PtInRect(&infoPtr->days, lpht->pt))
1239 lpht->st.wYear = infoPtr->currentYear;
1242 retval = MCHT_CALENDARDATEPREV;
1243 lpht->st.wMonth = infoPtr->currentMonth - 1;
1244 if (lpht->st.wMonth <1)
1246 lpht->st.wMonth = 12;
1249 lpht->st.wDay = MONTHCAL_MonthLength(lpht->st.wMonth,lpht->st.wYear) -day;
1251 else if (day > MONTHCAL_MonthLength(infoPtr->currentMonth,infoPtr->currentYear))
1253 retval = MCHT_CALENDARDATENEXT;
1254 lpht->st.wMonth = infoPtr->currentMonth + 1;
1255 if (lpht->st.wMonth <12)
1257 lpht->st.wMonth = 1;
1260 lpht->st.wDay = day - MONTHCAL_MonthLength(infoPtr->currentMonth,infoPtr->currentYear) ;
1263 retval = MCHT_CALENDARDATE;
1264 lpht->st.wMonth = infoPtr->currentMonth;
1265 lpht->st.wDay = day;
1269 if(PtInRect(&infoPtr->todayrect, lpht->pt)) {
1270 retval = MCHT_TODAYLINK;
1275 /* Hit nothing special? What's left must be background :-) */
1277 retval = MCHT_CALENDARBK;
1279 lpht->uHit = retval;
1284 static void MONTHCAL_GoToNextMonth(HWND hwnd, MONTHCAL_INFO *infoPtr)
1286 DWORD dwStyle = GetWindowLongA(hwnd, GWL_STYLE);
1288 TRACE("MONTHCAL_GoToNextMonth\n");
1290 infoPtr->currentMonth++;
1291 if(infoPtr->currentMonth > 12) {
1292 infoPtr->currentYear++;
1293 infoPtr->currentMonth = 1;
1296 if(dwStyle & MCS_DAYSTATE) {
1300 nmds.nmhdr.hwndFrom = hwnd;
1301 nmds.nmhdr.idFrom = GetWindowLongA(hwnd, GWL_ID);
1302 nmds.nmhdr.code = MCN_GETDAYSTATE;
1303 nmds.cDayState = infoPtr->monthRange;
1304 nmds.prgDayState = COMCTL32_Alloc(infoPtr->monthRange * sizeof(MONTHDAYSTATE));
1306 SendMessageA(GetParent(hwnd), WM_NOTIFY,
1307 (WPARAM)nmds.nmhdr.idFrom, (LPARAM)&nmds);
1308 for(i=0; i<infoPtr->monthRange; i++)
1309 infoPtr->monthdayState[i] = nmds.prgDayState[i];
1314 static void MONTHCAL_GoToPrevMonth(HWND hwnd, MONTHCAL_INFO *infoPtr)
1316 DWORD dwStyle = GetWindowLongA(hwnd, GWL_STYLE);
1318 TRACE("MONTHCAL_GoToPrevMonth\n");
1320 infoPtr->currentMonth--;
1321 if(infoPtr->currentMonth < 1) {
1322 infoPtr->currentYear--;
1323 infoPtr->currentMonth = 12;
1326 if(dwStyle & MCS_DAYSTATE) {
1330 nmds.nmhdr.hwndFrom = hwnd;
1331 nmds.nmhdr.idFrom = GetWindowLongA(hwnd, GWL_ID);
1332 nmds.nmhdr.code = MCN_GETDAYSTATE;
1333 nmds.cDayState = infoPtr->monthRange;
1334 nmds.prgDayState = COMCTL32_Alloc
1335 (infoPtr->monthRange * sizeof(MONTHDAYSTATE));
1337 SendMessageA(GetParent(hwnd), WM_NOTIFY,
1338 (WPARAM)nmds.nmhdr.idFrom, (LPARAM)&nmds);
1339 for(i=0; i<infoPtr->monthRange; i++)
1340 infoPtr->monthdayState[i] = nmds.prgDayState[i];
1345 MONTHCAL_RButtonDown(HWND hwnd, WPARAM wParam, LPARAM lParam)
1347 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
1352 hMenu = CreatePopupMenu();
1353 if (!LoadStringA(COMCTL32_hModule,IDM_GOTODAY,buf,sizeof(buf)))
1355 WARN("Can't load resource\n");
1356 strcpy(buf,"Go to Today:");
1358 AppendMenuA(hMenu, MF_STRING|MF_ENABLED,1, buf);
1359 menupoint.x=(INT)LOWORD(lParam);
1360 menupoint.y=(INT)HIWORD(lParam);
1361 ClientToScreen(hwnd, &menupoint);
1362 if( TrackPopupMenu(hMenu,TPM_RIGHTBUTTON| TPM_NONOTIFY|TPM_RETURNCMD,
1363 menupoint.x,menupoint.y,0,hwnd,NULL))
1365 infoPtr->currentMonth=infoPtr->todaysDate.wMonth;
1366 infoPtr->currentYear=infoPtr->todaysDate.wYear;
1367 InvalidateRect(hwnd, NULL, FALSE);
1373 MONTHCAL_LButtonDown(HWND hwnd, WPARAM wParam, LPARAM lParam)
1375 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
1379 RECT rcDay; /* used in determining area to invalidate */
1383 TRACE("%x %lx\n", wParam, lParam);
1385 if (infoPtr->hWndYearUpDown)
1387 infoPtr->currentYear=SendMessageA( infoPtr->hWndYearUpDown, UDM_SETPOS, (WPARAM) 0,(LPARAM)0);
1388 if(!DestroyWindow(infoPtr->hWndYearUpDown))
1390 FIXME("Can't destroy Updown Control\n");
1393 infoPtr->hWndYearUpDown=0;
1394 if(!DestroyWindow(infoPtr->hWndYearEdit))
1396 FIXME("Can't destroy Updown Control\n");
1399 infoPtr->hWndYearEdit=0;
1400 InvalidateRect(hwnd, NULL, FALSE);
1403 ht.pt.x = (INT)LOWORD(lParam);
1404 ht.pt.y = (INT)HIWORD(lParam);
1405 hit = MONTHCAL_HitTest(hwnd, (LPARAM)&ht);
1407 /* FIXME: these flags should be checked by */
1408 /*((hit & MCHT_XXX) == MCHT_XXX) b/c some of the flags are */
1410 if(hit ==MCHT_TITLEBTNNEXT) {
1411 MONTHCAL_GoToNextMonth(hwnd, infoPtr);
1412 infoPtr->status = MC_NEXTPRESSED;
1413 SetTimer(hwnd, MC_NEXTMONTHTIMER, MC_NEXTMONTHDELAY, 0);
1414 InvalidateRect(hwnd, NULL, FALSE);
1417 if(hit == MCHT_TITLEBTNPREV){
1418 MONTHCAL_GoToPrevMonth(hwnd, infoPtr);
1419 infoPtr->status = MC_PREVPRESSED;
1420 SetTimer(hwnd, MC_PREVMONTHTIMER, MC_NEXTMONTHDELAY, 0);
1421 InvalidateRect(hwnd, NULL, FALSE);
1425 if(hit == MCHT_TITLEMONTH) {
1426 hMenu = CreatePopupMenu();
1430 GetLocaleInfoA( LOCALE_USER_DEFAULT,LOCALE_SMONTHNAME1+i,
1432 AppendMenuA(hMenu, MF_STRING|MF_ENABLED,i+1, buf);
1434 menupoint.x=infoPtr->titlemonth.right;
1435 menupoint.y=infoPtr->titlemonth.bottom;
1436 ClientToScreen(hwnd, &menupoint);
1437 i= TrackPopupMenu(hMenu,TPM_LEFTALIGN | TPM_NONOTIFY | TPM_RIGHTBUTTON | TPM_RETURNCMD,
1438 menupoint.x,menupoint.y,0,hwnd,NULL);
1439 if ((i>0) && (i<13))
1441 infoPtr->currentMonth=i;
1442 InvalidateRect(hwnd, NULL, FALSE);
1445 if(hit == MCHT_TITLEYEAR) {
1446 infoPtr->hWndYearEdit=CreateWindowExA(0,
1449 WS_VISIBLE | WS_CHILD |UDS_SETBUDDYINT,
1450 infoPtr->titleyear.left+3,infoPtr->titlebtnnext.top,
1451 infoPtr->titleyear.right-infoPtr->titleyear.left,
1452 infoPtr->textHeight,
1457 infoPtr->hWndYearUpDown=CreateWindowExA(0,
1460 WS_VISIBLE | WS_CHILD |UDS_SETBUDDYINT|UDS_NOTHOUSANDS|UDS_ARROWKEYS,
1461 infoPtr->titleyear.right+6,infoPtr->titlebtnnext.top,
1463 infoPtr->textHeight,
1468 SendMessageA( infoPtr->hWndYearUpDown, UDM_SETRANGE, (WPARAM) 0, MAKELONG (9999, 1753));
1469 SendMessageA( infoPtr->hWndYearUpDown, UDM_SETBUDDY, (WPARAM) infoPtr->hWndYearEdit, (LPARAM)0 );
1470 SendMessageA( infoPtr->hWndYearUpDown, UDM_SETPOS, (WPARAM) 0,(LPARAM)infoPtr->currentYear );
1474 if(hit == MCHT_TODAYLINK) {
1475 infoPtr->currentMonth=infoPtr->todaysDate.wMonth;
1476 infoPtr->currentYear=infoPtr->todaysDate.wYear;
1477 InvalidateRect(hwnd, NULL, FALSE);
1480 if(hit && MCHT_CALENDARDATE) {
1481 SYSTEMTIME selArray[2];
1484 TRACE("MCHT_CALENDARDATE\n");
1485 nmsc.nmhdr.hwndFrom = hwnd;
1486 nmsc.nmhdr.idFrom = GetWindowLongA(hwnd, GWL_ID);
1487 nmsc.nmhdr.code = MCN_SELCHANGE;
1488 MONTHCAL_CopyTime(&nmsc.stSelStart, &infoPtr->minSel);
1489 MONTHCAL_CopyTime(&nmsc.stSelEnd, &infoPtr->maxSel);
1491 SendMessageA(GetParent(hwnd), WM_NOTIFY,
1492 (WPARAM)nmsc.nmhdr.idFrom,(LPARAM)&nmsc);
1494 MONTHCAL_CopyTime(&ht.st, &selArray[0]);
1495 MONTHCAL_CopyTime(&ht.st, &selArray[1]);
1496 MONTHCAL_SetSelRange(hwnd,0,(LPARAM) &selArray);
1498 /* redraw both old and new days if the selected day changed */
1499 if(infoPtr->curSelDay != ht.st.wDay) {
1500 MONTHCAL_CalcPosFromDay(infoPtr, ht.st.wDay, ht.st.wMonth, &rcDay);
1501 InvalidateRect(hwnd, &rcDay, TRUE);
1503 MONTHCAL_CalcPosFromDay(infoPtr, infoPtr->curSelDay, infoPtr->currentMonth, &rcDay);
1504 InvalidateRect(hwnd, &rcDay, TRUE);
1507 infoPtr->firstSelDay = ht.st.wDay;
1508 infoPtr->curSelDay = ht.st.wDay;
1509 infoPtr->status = MC_SEL_LBUTDOWN;
1518 MONTHCAL_LButtonUp(HWND hwnd, WPARAM wParam, LPARAM lParam)
1520 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
1523 BOOL redraw = FALSE;
1529 if(infoPtr->status & MC_NEXTPRESSED) {
1530 KillTimer(hwnd, MC_NEXTMONTHTIMER);
1533 if(infoPtr->status & MC_PREVPRESSED) {
1534 KillTimer(hwnd, MC_PREVMONTHTIMER);
1538 ht.pt.x = (INT)LOWORD(lParam);
1539 ht.pt.y = (INT)HIWORD(lParam);
1540 hit = MONTHCAL_HitTest(hwnd, (LPARAM)&ht);
1542 infoPtr->status = MC_SEL_LBUTUP;
1544 if(hit ==MCHT_CALENDARDATENEXT) {
1545 MONTHCAL_GoToNextMonth(hwnd, infoPtr);
1546 InvalidateRect(hwnd, NULL, FALSE);
1549 if(hit == MCHT_CALENDARDATEPREV){
1550 MONTHCAL_GoToPrevMonth(hwnd, infoPtr);
1551 InvalidateRect(hwnd, NULL, FALSE);
1554 nmhdr.hwndFrom = hwnd;
1555 nmhdr.idFrom = GetWindowLongA( hwnd, GWL_ID);
1556 nmhdr.code = NM_RELEASEDCAPTURE;
1557 TRACE("Sent notification from %p to %p\n", hwnd, GetParent(hwnd));
1559 SendMessageA(GetParent(hwnd), WM_NOTIFY,
1560 (WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr);
1562 nmsc.nmhdr.hwndFrom = hwnd;
1563 nmsc.nmhdr.idFrom = GetWindowLongA(hwnd, GWL_ID);
1564 nmsc.nmhdr.code = MCN_SELECT;
1565 MONTHCAL_CopyTime(&nmsc.stSelStart, &infoPtr->minSel);
1566 MONTHCAL_CopyTime(&nmsc.stSelEnd, &infoPtr->maxSel);
1568 SendMessageA(GetParent(hwnd), WM_NOTIFY,
1569 (WPARAM)nmsc.nmhdr.idFrom, (LPARAM)&nmsc);
1571 /* redraw if necessary */
1573 InvalidateRect(hwnd, NULL, FALSE);
1580 MONTHCAL_Timer(HWND hwnd, WPARAM wParam, LPARAM lParam)
1582 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
1583 BOOL redraw = FALSE;
1585 TRACE(" %d\n", wParam);
1586 if(!infoPtr) return 0;
1589 case MC_NEXTMONTHTIMER:
1591 MONTHCAL_GoToNextMonth(hwnd, infoPtr);
1593 case MC_PREVMONTHTIMER:
1595 MONTHCAL_GoToPrevMonth(hwnd, infoPtr);
1598 ERR("got unknown timer\n");
1601 /* redraw only if necessary */
1603 InvalidateRect(hwnd, NULL, FALSE);
1610 MONTHCAL_MouseMove(HWND hwnd, WPARAM wParam, LPARAM lParam)
1612 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
1614 int oldselday, selday, hit;
1617 if(!(infoPtr->status & MC_SEL_LBUTDOWN)) return 0;
1619 ht.pt.x = LOWORD(lParam);
1620 ht.pt.y = HIWORD(lParam);
1622 hit = MONTHCAL_HitTest(hwnd, (LPARAM)&ht);
1624 /* not on the calendar date numbers? bail out */
1625 TRACE("hit:%x\n",hit);
1626 if((hit & MCHT_CALENDARDATE) != MCHT_CALENDARDATE) return 0;
1628 selday = ht.st.wDay;
1629 oldselday = infoPtr->curSelDay;
1630 infoPtr->curSelDay = selday;
1631 MONTHCAL_CalcPosFromDay(infoPtr, selday, ht.st. wMonth, &r);
1633 if(GetWindowLongA(hwnd, GWL_STYLE) & MCS_MULTISELECT) {
1634 SYSTEMTIME selArray[2];
1637 MONTHCAL_GetSelRange(hwnd, 0, (LPARAM)&selArray);
1639 if(infoPtr->firstSelDay==selArray[0].wDay) i=1;
1640 TRACE("oldRange:%d %d %d %d\n", infoPtr->firstSelDay, selArray[0].wDay, selArray[1].wDay, i);
1641 if(infoPtr->firstSelDay==selArray[1].wDay) {
1642 /* 1st time we get here: selArray[0]=selArray[1]) */
1643 /* if we're still at the first selected date, return */
1644 if(infoPtr->firstSelDay==selday) goto done;
1645 if(selday<infoPtr->firstSelDay) i = 0;
1648 if(abs(infoPtr->firstSelDay - selday) >= infoPtr->maxSelCount) {
1649 if(selday>infoPtr->firstSelDay)
1650 selday = infoPtr->firstSelDay + infoPtr->maxSelCount;
1652 selday = infoPtr->firstSelDay - infoPtr->maxSelCount;
1655 if(selArray[i].wDay!=selday) {
1656 TRACE("newRange:%d %d %d %d\n", infoPtr->firstSelDay, selArray[0].wDay, selArray[1].wDay, i);
1658 selArray[i].wDay = selday;
1660 if(selArray[0].wDay>selArray[1].wDay) {
1662 tempday = selArray[1].wDay;
1663 selArray[1].wDay = selArray[0].wDay;
1664 selArray[0].wDay = tempday;
1667 MONTHCAL_SetSelRange(hwnd, 0, (LPARAM)&selArray);
1673 /* only redraw if the currently selected day changed */
1674 /* FIXME: this should specify a rectangle containing only the days that changed */
1675 /* using InvalidateRect */
1676 if(oldselday != infoPtr->curSelDay)
1677 InvalidateRect(hwnd, NULL, FALSE);
1684 MONTHCAL_Paint(HWND hwnd, WPARAM wParam)
1686 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
1690 /* fill ps.rcPaint with a default rect */
1691 memcpy(&(ps.rcPaint), &(infoPtr->rcClient), sizeof(infoPtr->rcClient));
1693 hdc = (wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam);
1694 MONTHCAL_Refresh(hwnd, hdc, &ps);
1695 if(!wParam) EndPaint(hwnd, &ps);
1701 MONTHCAL_KillFocus(HWND hwnd, WPARAM wParam, LPARAM lParam)
1705 InvalidateRect(hwnd, NULL, TRUE);
1712 MONTHCAL_SetFocus(HWND hwnd, WPARAM wParam, LPARAM lParam)
1716 InvalidateRect(hwnd, NULL, FALSE);
1721 /* sets the size information */
1722 static void MONTHCAL_UpdateSize(HWND hwnd)
1724 HDC hdc = GetDC(hwnd);
1725 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
1726 RECT *rcClient=&infoPtr->rcClient;
1727 RECT *rcDraw=&infoPtr->rcDraw;
1728 RECT *title=&infoPtr->title;
1729 RECT *prev=&infoPtr->titlebtnprev;
1730 RECT *next=&infoPtr->titlebtnnext;
1731 RECT *titlemonth=&infoPtr->titlemonth;
1732 RECT *titleyear=&infoPtr->titleyear;
1733 RECT *wdays=&infoPtr->wdays;
1734 RECT *weeknumrect=&infoPtr->weeknums;
1735 RECT *days=&infoPtr->days;
1736 RECT *todayrect=&infoPtr->todayrect;
1739 DWORD dwStyle = GetWindowLongA(hwnd, GWL_STYLE);
1743 currentFont = SelectObject(hdc, infoPtr->hFont);
1745 /* FIXME: need a way to determine current font, without setting it */
1747 if(infoPtr->hFont!=currentFont) {
1748 SelectObject(hdc, currentFont);
1749 infoPtr->hFont=currentFont;
1750 GetObjectA(currentFont, sizeof(LOGFONTA), &logFont);
1751 logFont.lfWeight=FW_BOLD;
1752 infoPtr->hBoldFont = CreateFontIndirectA(&logFont);
1756 /* get the height and width of each day's text */
1757 GetTextMetricsA(hdc, &tm);
1758 infoPtr->textHeight = tm.tmHeight + tm.tmExternalLeading;
1759 GetTextExtentPoint32A(hdc, "Sun", 3, &size);
1760 infoPtr->textWidth = size.cx + 2;
1762 /* retrieve the controls client rectangle info infoPtr->rcClient */
1763 GetClientRect(hwnd, rcClient);
1765 /* rcDraw is the rectangle the control is drawn in */
1766 rcDraw->left = rcClient->left;
1767 rcDraw->right = rcClient->right;
1768 rcDraw->top = rcClient->top;
1769 rcDraw->bottom = rcClient->bottom;
1771 /* recalculate the height and width increments and offsets */
1772 /* FIXME: We use up all available width. This will inhibit having multiple
1773 calendars in a row, like win doesn
1775 if(dwStyle & MCS_WEEKNUMBERS)
1779 infoPtr->width_increment = (infoPtr->rcDraw.right - infoPtr->rcDraw.left) / xdiv;
1780 infoPtr->height_increment = (infoPtr->rcDraw.bottom - infoPtr->rcDraw.top) / 10.0;
1781 infoPtr->left_offset = (infoPtr->rcDraw.right - infoPtr->rcDraw.left) - (infoPtr->width_increment * xdiv);
1782 infoPtr->top_offset = (infoPtr->rcDraw.bottom - infoPtr->rcDraw.top) - (infoPtr->height_increment * 10.0);
1784 rcDraw->bottom = rcDraw->top + 10 * infoPtr->height_increment;
1785 /* this is correct, the control does NOT expand vertically */
1786 /* like it does horizontally */
1787 /* make sure we don't move the controls bottom out of the client */
1789 /* title line has about 3 text heights, abrev days line, 6 weeksline and today circle line*/
1790 /*if((rcDraw->top + 9 * infoPtr->textHeight + 5) < rcDraw->bottom) {
1791 rcDraw->bottom = rcDraw->top + 9 * infoPtr->textHeight + 5;
1794 /* calculate title area */
1795 title->top = rcClient->top;
1796 title->bottom = title->top + 2 * infoPtr->height_increment;
1797 title->left = rcClient->left;
1798 title->right = rcClient->right;
1800 /* set the dimensions of the next and previous buttons and center */
1801 /* the month text vertically */
1802 prev->top = next->top = title->top + 6;
1803 prev->bottom = next->bottom = title->bottom - 6;
1804 prev->left = title->left + 6;
1805 prev->right = prev->left + (title->bottom - title->top) ;
1806 next->right = title->right - 6;
1807 next->left = next->right - (title->bottom - title->top);
1809 /* titlemonth->left and right change based upon the current month */
1810 /* and are recalculated in refresh as the current month may change */
1811 /* without the control being resized */
1812 titlemonth->top = titleyear->top = title->top + (infoPtr->height_increment)/2;
1813 titlemonth->bottom = titleyear->bottom = title->bottom - (infoPtr->height_increment)/2;
1815 /* setup the dimensions of the rectangle we draw the names of the */
1816 /* days of the week in */
1817 weeknumrect->left =infoPtr->left_offset;
1818 if(dwStyle & MCS_WEEKNUMBERS)
1819 weeknumrect->right=prev->right;
1821 weeknumrect->right=weeknumrect->left;
1822 wdays->left = days->left = weeknumrect->right;
1823 wdays->right = days->right = wdays->left + 7 * infoPtr->width_increment;
1824 wdays->top = title->bottom ;
1825 wdays->bottom = wdays->top + infoPtr->height_increment;
1827 days->top = weeknumrect->top = wdays->bottom ;
1828 days->bottom = weeknumrect->bottom = days->top + 6 * infoPtr->height_increment;
1830 todayrect->left = rcClient->left;
1831 todayrect->right = rcClient->right;
1832 todayrect->top = days->bottom;
1833 todayrect->bottom = days->bottom + infoPtr->height_increment;
1835 /* uncomment for excessive debugging
1836 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",
1837 infoPtr->width_increment,infoPtr->height_increment,
1838 rcClient->left, rcClient->right, rcClient->top, rcClient->bottom,
1839 title->left, title->right, title->top, title->bottom,
1840 wdays->left, wdays->right, wdays->top, wdays->bottom,
1841 days->left, days->right, days->top, days->bottom,
1842 todayrect->left,todayrect->right,todayrect->top,todayrect->bottom);
1845 /* restore the originally selected font */
1846 SelectObject(hdc, currentFont);
1848 ReleaseDC(hwnd, hdc);
1851 static LRESULT MONTHCAL_Size(HWND hwnd, int Width, int Height)
1853 TRACE("(hwnd=%p, width=%d, height=%d)\n", hwnd, Width, Height);
1855 MONTHCAL_UpdateSize(hwnd);
1857 /* invalidate client area and erase background */
1858 InvalidateRect(hwnd, NULL, TRUE);
1863 /* FIXME: check whether dateMin/dateMax need to be adjusted. */
1865 MONTHCAL_Create(HWND hwnd, WPARAM wParam, LPARAM lParam)
1867 MONTHCAL_INFO *infoPtr;
1870 /* allocate memory for info structure */
1871 infoPtr =(MONTHCAL_INFO*)COMCTL32_Alloc(sizeof(MONTHCAL_INFO));
1872 SetWindowLongA(hwnd, 0, (DWORD)infoPtr);
1874 if(infoPtr == NULL) {
1875 ERR( "could not allocate info memory!\n");
1878 if((MONTHCAL_INFO*)GetWindowLongA(hwnd, 0) != infoPtr) {
1879 ERR( "pointer assignment error!\n");
1883 infoPtr->hFont = GetStockObject(DEFAULT_GUI_FONT);
1884 GetObjectA(infoPtr->hFont, sizeof(LOGFONTA), &logFont);
1885 logFont.lfWeight = FW_BOLD;
1886 infoPtr->hBoldFont = CreateFontIndirectA(&logFont);
1888 /* initialize info structure */
1889 /* FIXME: calculate systemtime ->> localtime(substract timezoneinfo) */
1891 GetSystemTime(&infoPtr->todaysDate);
1892 MONTHCAL_SetFirstDayOfWeek(hwnd,0,(LPARAM)-1);
1893 infoPtr->currentMonth = infoPtr->todaysDate.wMonth;
1894 infoPtr->currentYear = infoPtr->todaysDate.wYear;
1895 MONTHCAL_CopyTime(&infoPtr->todaysDate, &infoPtr->minDate);
1896 MONTHCAL_CopyTime(&infoPtr->todaysDate, &infoPtr->maxDate);
1897 infoPtr->maxSelCount = 7;
1898 infoPtr->monthRange = 3;
1899 infoPtr->monthdayState = COMCTL32_Alloc
1900 (infoPtr->monthRange * sizeof(MONTHDAYSTATE));
1901 infoPtr->titlebk = GetSysColor(COLOR_ACTIVECAPTION);
1902 infoPtr->titletxt = GetSysColor(COLOR_WINDOW);
1903 infoPtr->monthbk = GetSysColor(COLOR_WINDOW);
1904 infoPtr->trailingtxt = GetSysColor(COLOR_GRAYTEXT);
1905 infoPtr->bk = GetSysColor(COLOR_WINDOW);
1906 infoPtr->txt = GetSysColor(COLOR_WINDOWTEXT);
1908 /* call MONTHCAL_UpdateSize to set all of the dimensions */
1909 /* of the control */
1910 MONTHCAL_UpdateSize(hwnd);
1917 MONTHCAL_Destroy(HWND hwnd, WPARAM wParam, LPARAM lParam)
1919 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
1921 /* free month calendar info data */
1922 if(infoPtr->monthdayState)
1923 COMCTL32_Free(infoPtr->monthdayState);
1924 COMCTL32_Free(infoPtr);
1925 SetWindowLongA(hwnd, 0, 0);
1930 static LRESULT WINAPI
1931 MONTHCAL_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1933 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n", hwnd, uMsg, wParam, lParam);
1934 if (!MONTHCAL_GetInfoPtr(hwnd) && (uMsg != WM_CREATE))
1935 return DefWindowProcA(hwnd, uMsg, wParam, lParam);
1939 return MONTHCAL_GetCurSel(hwnd, wParam, lParam);
1942 return MONTHCAL_SetCurSel(hwnd, wParam, lParam);
1944 case MCM_GETMAXSELCOUNT:
1945 return MONTHCAL_GetMaxSelCount(hwnd, wParam, lParam);
1947 case MCM_SETMAXSELCOUNT:
1948 return MONTHCAL_SetMaxSelCount(hwnd, wParam, lParam);
1950 case MCM_GETSELRANGE:
1951 return MONTHCAL_GetSelRange(hwnd, wParam, lParam);
1953 case MCM_SETSELRANGE:
1954 return MONTHCAL_SetSelRange(hwnd, wParam, lParam);
1956 case MCM_GETMONTHRANGE:
1957 return MONTHCAL_GetMonthRange(hwnd, wParam, lParam);
1959 case MCM_SETDAYSTATE:
1960 return MONTHCAL_SetDayState(hwnd, wParam, lParam);
1962 case MCM_GETMINREQRECT:
1963 return MONTHCAL_GetMinReqRect(hwnd, wParam, lParam);
1966 return MONTHCAL_GetColor(hwnd, wParam, lParam);
1969 return MONTHCAL_SetColor(hwnd, wParam, lParam);
1972 return MONTHCAL_GetToday(hwnd, wParam, lParam);
1975 return MONTHCAL_SetToday(hwnd, wParam, lParam);
1978 return MONTHCAL_HitTest(hwnd,lParam);
1980 case MCM_GETFIRSTDAYOFWEEK:
1981 return MONTHCAL_GetFirstDayOfWeek(hwnd, wParam, lParam);
1983 case MCM_SETFIRSTDAYOFWEEK:
1984 return MONTHCAL_SetFirstDayOfWeek(hwnd, wParam, lParam);
1987 return MONTHCAL_GetRange(hwnd, wParam, lParam);
1990 return MONTHCAL_SetRange(hwnd, wParam, lParam);
1992 case MCM_GETMONTHDELTA:
1993 return MONTHCAL_GetMonthDelta(hwnd, wParam, lParam);
1995 case MCM_SETMONTHDELTA:
1996 return MONTHCAL_SetMonthDelta(hwnd, wParam, lParam);
1998 case MCM_GETMAXTODAYWIDTH:
1999 return MONTHCAL_GetMaxTodayWidth(hwnd);
2002 return DLGC_WANTARROWS | DLGC_WANTCHARS;
2005 return MONTHCAL_KillFocus(hwnd, wParam, lParam);
2007 case WM_RBUTTONDOWN:
2008 return MONTHCAL_RButtonDown(hwnd, wParam, lParam);
2010 case WM_LBUTTONDOWN:
2011 return MONTHCAL_LButtonDown(hwnd, wParam, lParam);
2014 return MONTHCAL_MouseMove(hwnd, wParam, lParam);
2017 return MONTHCAL_LButtonUp(hwnd, wParam, lParam);
2020 return MONTHCAL_Paint(hwnd, wParam);
2023 return MONTHCAL_SetFocus(hwnd, wParam, lParam);
2026 return MONTHCAL_Size(hwnd, (int)SLOWORD(lParam), (int)SHIWORD(lParam));
2029 return MONTHCAL_Create(hwnd, wParam, lParam);
2032 return MONTHCAL_Timer(hwnd, wParam, lParam);
2035 return MONTHCAL_Destroy(hwnd, wParam, lParam);
2038 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
2039 ERR( "unknown msg %04x wp=%08x lp=%08lx\n", uMsg, wParam, lParam);
2040 return DefWindowProcA(hwnd, uMsg, wParam, lParam);
2047 MONTHCAL_Register(void)
2051 ZeroMemory(&wndClass, sizeof(WNDCLASSA));
2052 wndClass.style = CS_GLOBALCLASS;
2053 wndClass.lpfnWndProc = (WNDPROC)MONTHCAL_WindowProc;
2054 wndClass.cbClsExtra = 0;
2055 wndClass.cbWndExtra = sizeof(MONTHCAL_INFO *);
2056 wndClass.hCursor = LoadCursorA(0, IDC_ARROWA);
2057 wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
2058 wndClass.lpszClassName = MONTHCAL_CLASSA;
2060 RegisterClassA(&wndClass);
2065 MONTHCAL_Unregister(void)
2067 UnregisterClassA(MONTHCAL_CLASSA, NULL);