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
88 int firstDayplace; /* place of the first day of the current month */
89 int delta; /* scroll rate; # of months that the */
90 /* control moves when user clicks a scroll button */
91 int visible; /* # of months visible */
92 int firstDay; /* Start month calendar with firstDay's day */
94 MONTHDAYSTATE *monthdayState;
95 SYSTEMTIME todaysDate;
98 int status; /* See MC_SEL flags */
99 int curSelDay; /* current selected day */
100 int firstSelDay; /* first selected day */
108 RECT title; /* rect for the header above the calendar */
109 RECT titlebtnnext; /* the `next month' button in the header */
110 RECT titlebtnprev; /* the `prev month' button in the header */
111 RECT titlemonth; /* the `month name' txt in the header */
112 RECT titleyear; /* the `year number' txt in the header */
113 RECT wdays; /* week days at top */
114 RECT days; /* calendar area */
115 RECT weeknums; /* week numbers at left side */
116 RECT todayrect; /* `today: xx/xx/xx' text rect */
117 HWND hwndNotify; /* Window to receive the notifications */
118 HWND hWndYearEdit; /* Window Handle of edit box to handle years */
119 HWND hWndYearUpDown;/* Window Handle of updown box to handle years */
120 } MONTHCAL_INFO, *LPMONTHCAL_INFO;
123 /* Offsets of days in the week to the weekday of january 1. */
124 static const int DayOfWeekTable[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
127 #define MONTHCAL_GetInfoPtr(hwnd) ((MONTHCAL_INFO *)GetWindowLongPtrW(hwnd, 0))
129 /* helper functions */
131 /* returns the number of days in any given month, checking for leap days */
132 /* january is 1, december is 12 */
133 int MONTHCAL_MonthLength(int month, int year)
135 const int mdays[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 0};
136 /*Wrap around, this eases handling*/
142 /* if we have a leap year add 1 day to February */
143 /* a leap year is a year either divisible by 400 */
144 /* or divisible by 4 and not by 100 */
145 if(month == 2) { /* February */
146 return mdays[month - 1] + ((year%400 == 0) ? 1 : ((year%100 != 0) &&
147 (year%4 == 0)) ? 1 : 0);
150 return mdays[month - 1];
155 /* make sure that time is valid */
156 static int MONTHCAL_ValidateTime(SYSTEMTIME time)
158 if(time.wMonth > 12) return FALSE;
159 if(time.wDayOfWeek > 6) return FALSE;
160 if(time.wDay > MONTHCAL_MonthLength(time.wMonth, time.wYear))
162 if(time.wHour > 23) return FALSE;
163 if(time.wMinute > 59) return FALSE;
164 if(time.wSecond > 59) return FALSE;
165 if(time.wMilliseconds > 999) return FALSE;
171 void MONTHCAL_CopyTime(const SYSTEMTIME *from, SYSTEMTIME *to)
173 to->wYear = from->wYear;
174 to->wMonth = from->wMonth;
175 to->wDayOfWeek = from->wDayOfWeek;
176 to->wDay = from->wDay;
177 to->wHour = from->wHour;
178 to->wMinute = from->wMinute;
179 to->wSecond = from->wSecond;
180 to->wMilliseconds = from->wMilliseconds;
184 /* Note:Depending on DST, this may be offset by a day.
185 Need to find out if we're on a DST place & adjust the clock accordingly.
186 Above function assumes we have a valid data.
187 Valid for year>1752; 1 <= d <= 31, 1 <= m <= 12.
191 /* returns the day in the week(0 == monday, 6 == sunday) */
192 /* day(1 == 1st, 2 == 2nd... etc), year is the year value */
193 static int MONTHCAL_CalculateDayOfWeek(DWORD day, DWORD month, DWORD year)
197 return((year + year/4 - year/100 + year/400 +
198 DayOfWeekTable[month-1] + day - 1 ) % 7);
201 /* From a given point, calculate the row (weekpos), column(daypos)
202 and day in the calendar. day== 0 mean the last day of tha last month
204 static int MONTHCAL_CalcDayFromPos(MONTHCAL_INFO *infoPtr, int x, int y,
205 int *daypos,int *weekpos)
207 int retval, firstDay;
210 GetClientRect(infoPtr->hwndSelf, &rcClient);
212 /* if the point is outside the x bounds of the window put
214 if (x > 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 *title=&infoPtr->title;
411 RECT *prev=&infoPtr->titlebtnprev;
412 RECT *next=&infoPtr->titlebtnnext;
413 RECT *titlemonth=&infoPtr->titlemonth;
414 RECT *titleyear=&infoPtr->titleyear;
418 int i, j, m, mask, day, firstDay, weeknum, weeknum1,prevMonth;
419 int textHeight = infoPtr->textHeight, textWidth = infoPtr->textWidth;
423 /* LOGFONTA logFont; */
427 COLORREF oldTextColor, oldBkColor;
428 DWORD dwStyle = GetWindowLongA(hwnd, GWL_STYLE);
430 RECT rcDay; /* used in MONTHCAL_CalcDayRect() */
431 SYSTEMTIME localtime;
434 oldTextColor = SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
436 /* fill background */
437 hbr = CreateSolidBrush (infoPtr->bk);
438 FillRect(hdc, &ps->rcPaint, hbr);
442 if(IntersectRect(&rcTemp, &(ps->rcPaint), title))
444 hbr = CreateSolidBrush(infoPtr->titlebk);
445 FillRect(hdc, title, hbr);
449 /* if the previous button is pressed draw it depressed */
450 if(IntersectRect(&rcTemp, &(ps->rcPaint), prev))
452 if((infoPtr->status & MC_PREVPRESSED))
453 DrawFrameControl(hdc, prev, DFC_SCROLL,
454 DFCS_SCROLLLEFT | DFCS_PUSHED |
455 (dwStyle & WS_DISABLED ? DFCS_INACTIVE : 0));
456 else /* if the previous button is pressed draw it depressed */
457 DrawFrameControl(hdc, prev, DFC_SCROLL,
458 DFCS_SCROLLLEFT |(dwStyle & WS_DISABLED ? DFCS_INACTIVE : 0));
461 /* if next button is depressed draw it depressed */
462 if(IntersectRect(&rcTemp, &(ps->rcPaint), next))
464 if((infoPtr->status & MC_NEXTPRESSED))
465 DrawFrameControl(hdc, next, DFC_SCROLL,
466 DFCS_SCROLLRIGHT | DFCS_PUSHED |
467 (dwStyle & WS_DISABLED ? DFCS_INACTIVE : 0));
468 else /* if the next button is pressed draw it depressed */
469 DrawFrameControl(hdc, next, DFC_SCROLL,
470 DFCS_SCROLLRIGHT |(dwStyle & WS_DISABLED ? DFCS_INACTIVE : 0));
473 oldBkColor = SetBkColor(hdc, infoPtr->titlebk);
474 SetTextColor(hdc, infoPtr->titletxt);
475 currentFont = SelectObject(hdc, infoPtr->hBoldFont);
477 /* titlemonth->left and right are set in MONTHCAL_UpdateSize */
478 titlemonth->left = title->left;
479 titlemonth->right = title->right;
481 GetLocaleInfoA( LOCALE_USER_DEFAULT,LOCALE_SMONTHNAME1+infoPtr->currentMonth -1,
483 sprintf(buf, "%s %ld", buf1, infoPtr->currentYear);
485 if(IntersectRect(&rcTemp, &(ps->rcPaint), titlemonth))
487 DrawTextA(hdc, buf, strlen(buf), titlemonth,
488 DT_CENTER | DT_VCENTER | DT_SINGLELINE);
491 SelectObject(hdc, infoPtr->hFont);
493 /* titlemonth left/right contained rect for whole titletxt('June 1999')
494 * MCM_HitTestInfo wants month & year rects, so prepare these now.
495 *(no, we can't draw them separately; the whole text is centered)
497 GetTextExtentPoint32A(hdc, buf, strlen(buf), &size);
498 titlemonth->left = title->right / 2 - size.cx / 2;
499 titleyear->right = title->right / 2 + size.cx / 2;
500 GetTextExtentPoint32A(hdc, buf1, strlen(buf1), &size);
501 titlemonth->right = titlemonth->left + size.cx;
502 titleyear->left = titlemonth->right;
504 /* draw month area */
505 rcTemp.top=infoPtr->wdays.top;
506 rcTemp.left=infoPtr->wdays.left;
507 rcTemp.bottom=infoPtr->todayrect.bottom;
508 rcTemp.right =infoPtr->todayrect.right;
509 if(IntersectRect(&rcTemp, &(ps->rcPaint), &rcTemp))
511 hbr = CreateSolidBrush(infoPtr->monthbk);
512 FillRect(hdc, &rcTemp, hbr);
516 /* draw line under day abbreviatons */
518 MoveToEx(hdc, infoPtr->days.left + 3, title->bottom + textHeight + 1, NULL);
519 LineTo(hdc, infoPtr->days.right - 3, title->bottom + textHeight + 1);
521 prevMonth = infoPtr->currentMonth - 1;
522 if(prevMonth == 0) /* if currentMonth is january(1) prevMonth is */
523 prevMonth = 12; /* december(12) of the previous year */
525 infoPtr->wdays.left = infoPtr->days.left = infoPtr->weeknums.right;
526 /* draw day abbreviations */
528 SetBkColor(hdc, infoPtr->monthbk);
529 SetTextColor(hdc, infoPtr->trailingtxt);
531 /* copy this rect so we can change the values without changing */
532 /* the original version */
533 days->left = infoPtr->wdays.left;
534 days->right = days->left + infoPtr->width_increment;
535 days->top = infoPtr->wdays.top;
536 days->bottom = infoPtr->wdays.bottom;
538 i = infoPtr->firstDay;
541 GetLocaleInfoA( LOCALE_USER_DEFAULT,LOCALE_SABBREVDAYNAME1 + (i +j)%7,
543 DrawTextA(hdc, buf, strlen(buf), days,
544 DT_CENTER | DT_VCENTER | DT_SINGLELINE );
545 days->left+=infoPtr->width_increment;
546 days->right+=infoPtr->width_increment;
549 /* draw day numbers; first, the previous month */
551 firstDay = MONTHCAL_CalculateDayOfWeek(1, infoPtr->currentMonth, infoPtr->currentYear);
553 day = MONTHCAL_MonthLength(prevMonth, infoPtr->currentYear) +
554 (infoPtr->firstDay + 7 - firstDay)%7 + 1;
555 if (day > MONTHCAL_MonthLength(prevMonth, infoPtr->currentYear))
557 startofprescal = day;
562 while(day <= MONTHCAL_MonthLength(prevMonth, infoPtr->currentYear)) {
563 MONTHCAL_CalcDayRect(infoPtr, &rcDay, i, 0);
564 if(IntersectRect(&rcTemp, &(ps->rcPaint), &rcDay))
566 MONTHCAL_DrawDay(hdc, infoPtr, day, prevMonth, i, 0,
567 infoPtr->monthdayState[m] & mask);
575 /* draw `current' month */
577 day = 1; /* start at the beginning of the current month */
579 infoPtr->firstDayplace = i;
580 SetTextColor(hdc, infoPtr->txt);
584 /* draw the first week of the current month */
586 MONTHCAL_CalcDayRect(infoPtr, &rcDay, i, 0);
587 if(IntersectRect(&rcTemp, &(ps->rcPaint), &rcDay))
590 MONTHCAL_DrawDay(hdc, infoPtr, day, infoPtr->currentMonth, i, 0,
591 infoPtr->monthdayState[m] & mask);
593 if((infoPtr->currentMonth==infoPtr->todaysDate.wMonth) &&
594 (day==infoPtr->todaysDate.wDay) &&
595 (infoPtr->currentYear == infoPtr->todaysDate.wYear)) {
596 if(!(dwStyle & MCS_NOTODAYCIRCLE))
597 MONTHCAL_CircleDay(hdc, infoPtr, day, infoPtr->currentMonth);
606 j = 1; /* move to the 2nd week of the current month */
607 i = 0; /* move back to sunday */
608 while(day <= MONTHCAL_MonthLength(infoPtr->currentMonth, infoPtr->currentYear)) {
609 MONTHCAL_CalcDayRect(infoPtr, &rcDay, i, j);
610 if(IntersectRect(&rcTemp, &(ps->rcPaint), &rcDay))
612 MONTHCAL_DrawDay(hdc, infoPtr, day, infoPtr->currentMonth, i, j,
613 infoPtr->monthdayState[m] & mask);
615 if((infoPtr->currentMonth==infoPtr->todaysDate.wMonth) &&
616 (day==infoPtr->todaysDate.wDay) &&
617 (infoPtr->currentYear == infoPtr->todaysDate.wYear))
618 if(!(dwStyle & MCS_NOTODAYCIRCLE))
619 MONTHCAL_CircleDay(hdc, infoPtr, day, infoPtr->currentMonth);
624 if(i>6) { /* past saturday, goto the next weeks sunday */
630 /* draw `next' month */
632 day = 1; /* start at the first day of the next month */
636 SetTextColor(hdc, infoPtr->trailingtxt);
637 while((i<7) &&(j<6)) {
638 MONTHCAL_CalcDayRect(infoPtr, &rcDay, i, j);
639 if(IntersectRect(&rcTemp, &(ps->rcPaint), &rcDay))
641 MONTHCAL_DrawDay(hdc, infoPtr, day, infoPtr->currentMonth + 1, i, j,
642 infoPtr->monthdayState[m] & mask);
648 if(i==7) { /* past saturday, go to next week's sunday */
653 SetTextColor(hdc, infoPtr->txt);
656 /* draw `today' date if style allows it, and draw a circle before today's
657 * date if necessary */
659 if(!(dwStyle & MCS_NOTODAY)) {
661 if(!(dwStyle & MCS_NOTODAYCIRCLE)) {
662 /*day is the number of days from nextmonth we put on the calendar */
663 MONTHCAL_CircleDay(hdc, infoPtr,
664 day+MONTHCAL_MonthLength(infoPtr->currentMonth,infoPtr->currentYear),
665 infoPtr->currentMonth);
668 if (!LoadStringA(COMCTL32_hModule,IDM_TODAY,buf1,sizeof(buf1)))
670 WARN("Can't load resource\n");
671 strcpy(buf1,"Today:");
673 MONTHCAL_CalcDayRect(infoPtr, &rtoday, 1, 6);
674 MONTHCAL_CopyTime(&infoPtr->todaysDate,&localtime);
675 GetDateFormatA(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&localtime,NULL,buf2,sizeof(buf2));
676 sprintf(buf, "%s %s", buf1,buf2);
677 SelectObject(hdc, infoPtr->hBoldFont);
679 if(IntersectRect(&rcTemp, &(ps->rcPaint), &rtoday))
681 DrawTextA(hdc, buf, -1, &rtoday, DT_CALCRECT | DT_LEFT | DT_VCENTER | DT_SINGLELINE);
682 DrawTextA(hdc, buf, -1, &rtoday, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
684 SelectObject(hdc, infoPtr->hFont);
687 /*eventually draw week numbers*/
688 if(dwStyle & MCS_WEEKNUMBERS) {
689 /* display weeknumbers*/
692 /* Rules what week to call the first week of a new year:
693 LOCALE_IFIRSTWEEKOFYEAR == 0 (e.g US?):
694 The week containing Jan 1 is the first week of year
695 LOCALE_IFIRSTWEEKOFYEAR == 2 (e.g. Germany):
696 First week of year must contain 4 days of the new year
697 LOCALE_IFIRSTWEEKOFYEAR == 1 (what contries?)
698 The first week of the year must contain only days of the new year
700 GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_IFIRSTWEEKOFYEAR,
702 sscanf(buf, "%d", &weeknum);
713 if (infoPtr->currentMonth < 2)
715 /* calculate all those exceptions for january */
716 weeknum1=MONTHCAL_CalculateDayOfWeek(1,1,infoPtr->currentYear);
717 if ((infoPtr->firstDay +7 - weeknum1)%7 > mindays)
723 weeknum+=MONTHCAL_MonthLength(i+1, infoPtr->currentYear-1);
724 weeknum +=startofprescal+ 7;
726 weeknum1=MONTHCAL_CalculateDayOfWeek(1,1,infoPtr->currentYear-1);
727 if ((infoPtr->firstDay + 7 - weeknum1)%7 > mindays)
734 for(i=0; i<prevMonth-1; i++)
735 weeknum+=MONTHCAL_MonthLength(i+1, infoPtr->currentYear);
736 weeknum +=startofprescal+ 7;
738 weeknum1=MONTHCAL_CalculateDayOfWeek(1,1,infoPtr->currentYear);
739 if ((infoPtr->firstDay + 7 - weeknum1)%7 > mindays)
742 days->left = infoPtr->weeknums.left;
743 days->right = infoPtr->weeknums.right;
744 days->top = infoPtr->weeknums.top;
745 days->bottom = days->top +infoPtr->height_increment;
747 if((i==0)&&(weeknum>50))
749 sprintf(buf, "%d", weeknum);
752 else if((i==5)&&(weeknum>47))
754 sprintf(buf, "%d", 1);
757 sprintf(buf, "%d", weeknum + i);
758 DrawTextA(hdc, buf, -1, days, DT_CENTER | DT_VCENTER | DT_SINGLELINE );
759 days->top+=infoPtr->height_increment;
760 days->bottom+=infoPtr->height_increment;
763 MoveToEx(hdc, infoPtr->weeknums.right, infoPtr->weeknums.top + 3 , NULL);
764 LineTo(hdc, infoPtr->weeknums.right, infoPtr->weeknums.bottom );
767 /* currentFont was font at entering Refresh */
769 SetBkColor(hdc, oldBkColor);
770 SelectObject(hdc, currentFont);
771 SetTextColor(hdc, oldTextColor);
776 MONTHCAL_GetMinReqRect(HWND hwnd, WPARAM wParam, LPARAM lParam)
778 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
779 LPRECT lpRect = (LPRECT) lParam;
780 TRACE("%x %lx\n", wParam, lParam);
782 /* validate parameters */
784 if((infoPtr==NULL) ||(lpRect == NULL) ) return FALSE;
786 lpRect->left = infoPtr->title.left;
787 lpRect->top = infoPtr->title.top;
788 lpRect->right = infoPtr->title.right;
789 lpRect->bottom = infoPtr->todayrect.bottom;
790 AdjustWindowRect(lpRect, GetWindowLongW(hwnd, GWL_STYLE), FALSE);
792 TRACE("%s\n", wine_dbgstr_rect(lpRect));
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)
1705 GetClientRect(hwnd, &ps.rcPaint);
1709 hdc = BeginPaint(hwnd, &ps);
1711 MONTHCAL_Refresh(hwnd, hdc, &ps);
1712 if(!wParam) EndPaint(hwnd, &ps);
1718 MONTHCAL_KillFocus(HWND hwnd, WPARAM wParam, LPARAM lParam)
1722 InvalidateRect(hwnd, NULL, TRUE);
1729 MONTHCAL_SetFocus(HWND hwnd, WPARAM wParam, LPARAM lParam)
1733 InvalidateRect(hwnd, NULL, FALSE);
1738 /* sets the size information */
1739 static void MONTHCAL_UpdateSize(HWND hwnd)
1741 HDC hdc = GetDC(hwnd);
1742 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
1743 RECT *title=&infoPtr->title;
1744 RECT *prev=&infoPtr->titlebtnprev;
1745 RECT *next=&infoPtr->titlebtnnext;
1746 RECT *titlemonth=&infoPtr->titlemonth;
1747 RECT *titleyear=&infoPtr->titleyear;
1748 RECT *wdays=&infoPtr->wdays;
1749 RECT *weeknumrect=&infoPtr->weeknums;
1750 RECT *days=&infoPtr->days;
1751 RECT *todayrect=&infoPtr->todayrect;
1754 DWORD dwStyle = GetWindowLongA(hwnd, GWL_STYLE);
1756 int xdiv, left_offset;
1759 GetClientRect(hwnd, &rcClient);
1761 currentFont = SelectObject(hdc, infoPtr->hFont);
1763 /* get the height and width of each day's text */
1764 GetTextMetricsA(hdc, &tm);
1765 infoPtr->textHeight = tm.tmHeight + tm.tmExternalLeading + tm.tmInternalLeading;
1766 GetTextExtentPoint32A(hdc, "Sun", 3, &size);
1767 infoPtr->textWidth = size.cx + 2;
1769 /* recalculate the height and width increments and offsets */
1770 GetTextExtentPoint32A(hdc, "00", 2, &size);
1772 xdiv = (dwStyle & MCS_WEEKNUMBERS) ? 8 : 7;
1774 infoPtr->width_increment = size.cx * 2;
1775 infoPtr->height_increment = infoPtr->textHeight;
1776 left_offset = (rcClient.right - rcClient.left) - (infoPtr->width_increment * xdiv);
1778 /* calculate title area */
1779 title->top = rcClient.top;
1780 title->bottom = title->top + 3 * infoPtr->height_increment / 2;
1781 title->left = left_offset;
1782 title->right = rcClient.right;
1784 /* set the dimensions of the next and previous buttons and center */
1785 /* the month text vertically */
1786 prev->top = next->top = title->top + 4;
1787 prev->bottom = next->bottom = title->bottom - 4;
1788 prev->left = title->left + 4;
1789 prev->right = prev->left + (title->bottom - title->top) ;
1790 next->right = title->right - 4;
1791 next->left = next->right - (title->bottom - title->top);
1793 /* titlemonth->left and right change based upon the current month */
1794 /* and are recalculated in refresh as the current month may change */
1795 /* without the control being resized */
1796 titlemonth->top = titleyear->top = title->top + (infoPtr->height_increment)/2;
1797 titlemonth->bottom = titleyear->bottom = title->bottom - (infoPtr->height_increment)/2;
1799 /* setup the dimensions of the rectangle we draw the names of the */
1800 /* days of the week in */
1801 weeknumrect->left = left_offset;
1802 if(dwStyle & MCS_WEEKNUMBERS)
1803 weeknumrect->right=prev->right;
1805 weeknumrect->right=weeknumrect->left;
1806 wdays->left = days->left = weeknumrect->right;
1807 wdays->right = days->right = wdays->left + 7 * infoPtr->width_increment;
1808 wdays->top = title->bottom ;
1809 wdays->bottom = wdays->top + infoPtr->height_increment;
1811 days->top = weeknumrect->top = wdays->bottom ;
1812 days->bottom = weeknumrect->bottom = days->top + 6 * infoPtr->height_increment;
1814 todayrect->left = rcClient.left;
1815 todayrect->right = rcClient.right;
1816 todayrect->top = days->bottom;
1817 todayrect->bottom = days->bottom + infoPtr->height_increment;
1819 TRACE("dx=%d dy=%d client[%s] title[%s] wdays[%s] days[%s] today[%s]\n",
1820 infoPtr->width_increment,infoPtr->height_increment,
1821 wine_dbgstr_rect(&rcClient),
1822 wine_dbgstr_rect(title),
1823 wine_dbgstr_rect(wdays),
1824 wine_dbgstr_rect(days),
1825 wine_dbgstr_rect(todayrect));
1827 /* restore the originally selected font */
1828 SelectObject(hdc, currentFont);
1830 ReleaseDC(hwnd, hdc);
1833 static LRESULT MONTHCAL_Size(HWND hwnd, int Width, int Height)
1835 TRACE("(hwnd=%p, width=%d, height=%d)\n", hwnd, Width, Height);
1837 MONTHCAL_UpdateSize(hwnd);
1839 /* invalidate client area and erase background */
1840 InvalidateRect(hwnd, NULL, TRUE);
1845 /* FIXME: check whether dateMin/dateMax need to be adjusted. */
1847 MONTHCAL_Create(HWND hwnd, WPARAM wParam, LPARAM lParam)
1849 MONTHCAL_INFO *infoPtr;
1852 /* allocate memory for info structure */
1853 infoPtr =(MONTHCAL_INFO*)Alloc(sizeof(MONTHCAL_INFO));
1854 SetWindowLongPtrW(hwnd, 0, (DWORD_PTR)infoPtr);
1856 if(infoPtr == NULL) {
1857 ERR( "could not allocate info memory!\n");
1861 infoPtr->hwndSelf = hwnd;
1862 infoPtr->hwndNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
1864 infoPtr->hFont = GetStockObject(DEFAULT_GUI_FONT);
1865 GetObjectA(infoPtr->hFont, sizeof(LOGFONTA), &logFont);
1866 logFont.lfWeight = FW_BOLD;
1867 infoPtr->hBoldFont = CreateFontIndirectA(&logFont);
1869 /* initialize info structure */
1870 /* FIXME: calculate systemtime ->> localtime(substract timezoneinfo) */
1872 GetSystemTime(&infoPtr->todaysDate);
1873 MONTHCAL_SetFirstDayOfWeek(hwnd,0,(LPARAM)-1);
1874 infoPtr->currentMonth = infoPtr->todaysDate.wMonth;
1875 infoPtr->currentYear = infoPtr->todaysDate.wYear;
1876 MONTHCAL_CopyTime(&infoPtr->todaysDate, &infoPtr->minDate);
1877 MONTHCAL_CopyTime(&infoPtr->todaysDate, &infoPtr->maxDate);
1878 infoPtr->maxDate.wYear=2050;
1879 infoPtr->minDate.wYear=1950;
1880 infoPtr->maxSelCount = 7;
1881 infoPtr->monthRange = 3;
1882 infoPtr->monthdayState = Alloc
1883 (infoPtr->monthRange * sizeof(MONTHDAYSTATE));
1884 infoPtr->titlebk = GetSysColor(COLOR_ACTIVECAPTION);
1885 infoPtr->titletxt = GetSysColor(COLOR_WINDOW);
1886 infoPtr->monthbk = GetSysColor(COLOR_WINDOW);
1887 infoPtr->trailingtxt = GetSysColor(COLOR_GRAYTEXT);
1888 infoPtr->bk = GetSysColor(COLOR_WINDOW);
1889 infoPtr->txt = GetSysColor(COLOR_WINDOWTEXT);
1891 /* call MONTHCAL_UpdateSize to set all of the dimensions */
1892 /* of the control */
1893 MONTHCAL_UpdateSize(hwnd);
1900 MONTHCAL_Destroy(HWND hwnd, WPARAM wParam, LPARAM lParam)
1902 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
1904 /* free month calendar info data */
1905 if(infoPtr->monthdayState)
1906 Free(infoPtr->monthdayState);
1908 SetWindowLongPtrW(hwnd, 0, 0);
1913 static LRESULT WINAPI
1914 MONTHCAL_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1916 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n", hwnd, uMsg, wParam, lParam);
1917 if (!MONTHCAL_GetInfoPtr(hwnd) && (uMsg != WM_CREATE))
1918 return DefWindowProcA(hwnd, uMsg, wParam, lParam);
1922 return MONTHCAL_GetCurSel(hwnd, wParam, lParam);
1925 return MONTHCAL_SetCurSel(hwnd, wParam, lParam);
1927 case MCM_GETMAXSELCOUNT:
1928 return MONTHCAL_GetMaxSelCount(hwnd, wParam, lParam);
1930 case MCM_SETMAXSELCOUNT:
1931 return MONTHCAL_SetMaxSelCount(hwnd, wParam, lParam);
1933 case MCM_GETSELRANGE:
1934 return MONTHCAL_GetSelRange(hwnd, wParam, lParam);
1936 case MCM_SETSELRANGE:
1937 return MONTHCAL_SetSelRange(hwnd, wParam, lParam);
1939 case MCM_GETMONTHRANGE:
1940 return MONTHCAL_GetMonthRange(hwnd, wParam, lParam);
1942 case MCM_SETDAYSTATE:
1943 return MONTHCAL_SetDayState(hwnd, wParam, lParam);
1945 case MCM_GETMINREQRECT:
1946 return MONTHCAL_GetMinReqRect(hwnd, wParam, lParam);
1949 return MONTHCAL_GetColor(hwnd, wParam, lParam);
1952 return MONTHCAL_SetColor(hwnd, wParam, lParam);
1955 return MONTHCAL_GetToday(hwnd, wParam, lParam);
1958 return MONTHCAL_SetToday(hwnd, wParam, lParam);
1961 return MONTHCAL_HitTest(hwnd,lParam);
1963 case MCM_GETFIRSTDAYOFWEEK:
1964 return MONTHCAL_GetFirstDayOfWeek(hwnd, wParam, lParam);
1966 case MCM_SETFIRSTDAYOFWEEK:
1967 return MONTHCAL_SetFirstDayOfWeek(hwnd, wParam, lParam);
1970 return MONTHCAL_GetRange(hwnd, wParam, lParam);
1973 return MONTHCAL_SetRange(hwnd, wParam, lParam);
1975 case MCM_GETMONTHDELTA:
1976 return MONTHCAL_GetMonthDelta(hwnd, wParam, lParam);
1978 case MCM_SETMONTHDELTA:
1979 return MONTHCAL_SetMonthDelta(hwnd, wParam, lParam);
1981 case MCM_GETMAXTODAYWIDTH:
1982 return MONTHCAL_GetMaxTodayWidth(hwnd);
1985 return DLGC_WANTARROWS | DLGC_WANTCHARS;
1988 return MONTHCAL_KillFocus(hwnd, wParam, lParam);
1990 case WM_RBUTTONDOWN:
1991 return MONTHCAL_RButtonDown(hwnd, wParam, lParam);
1993 case WM_LBUTTONDOWN:
1994 return MONTHCAL_LButtonDown(hwnd, wParam, lParam);
1997 return MONTHCAL_MouseMove(hwnd, wParam, lParam);
2000 return MONTHCAL_LButtonUp(hwnd, wParam, lParam);
2003 return MONTHCAL_Paint(hwnd, wParam);
2006 return MONTHCAL_SetFocus(hwnd, wParam, lParam);
2009 return MONTHCAL_Size(hwnd, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
2012 return MONTHCAL_Create(hwnd, wParam, lParam);
2015 return MONTHCAL_Timer(hwnd, wParam, lParam);
2018 return MONTHCAL_Destroy(hwnd, wParam, lParam);
2021 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
2022 ERR( "unknown msg %04x wp=%08x lp=%08lx\n", uMsg, wParam, lParam);
2023 return DefWindowProcA(hwnd, uMsg, wParam, lParam);
2030 MONTHCAL_Register(void)
2034 ZeroMemory(&wndClass, sizeof(WNDCLASSA));
2035 wndClass.style = CS_GLOBALCLASS;
2036 wndClass.lpfnWndProc = MONTHCAL_WindowProc;
2037 wndClass.cbClsExtra = 0;
2038 wndClass.cbWndExtra = sizeof(MONTHCAL_INFO *);
2039 wndClass.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
2040 wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
2041 wndClass.lpszClassName = MONTHCAL_CLASSA;
2043 RegisterClassA(&wndClass);
2048 MONTHCAL_Unregister(void)
2050 UnregisterClassA(MONTHCAL_CLASSA, NULL);