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>
13 * FIXME: handle resources better (doesn't work now); also take care
14 of internationalization.
15 * FIXME: keyboard handling.
30 #include "debugtools.h"
32 DEFAULT_DEBUG_CHANNEL(monthcal);
34 /* take #days/month from ole/parsedt.c;
35 * we want full month-names, and abbreviated weekdays, so these are
38 const int mdays[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 0};
40 const char * const monthtxt[] = {"January", "February", "March", "April", "May",
41 "June", "July", "August", "September", "October",
42 "November", "December"};
43 const char * const daytxt[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
44 static const int DayOfWeekTable[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
47 #define MONTHCAL_GetInfoPtr(hwnd) ((MONTHCAL_INFO *)GetWindowLongA(hwnd, 0))
49 /* helper functions */
51 /* returns the number of days in any given month */
52 /* january is 1, december is 12 */
53 static int MONTHCAL_MonthLength(int month, int year)
55 /* if we have a leap year add 1 day to February */
56 /* a leap year is a year either divisible by 400 */
57 /* or divisible by 4 and not by 100 */
58 if(month == 2) { /* February */
59 return mdays[month - 1] + ((year%400 == 0) ? 1 : ((year%100 != 0) &&
60 (year%4 == 0)) ? 1 : 0);
63 return mdays[month - 1];
68 /* make sure that time is valid */
69 static int MONTHCAL_ValidateTime(SYSTEMTIME time)
71 if(time.wMonth > 12) return FALSE;
72 if(time.wDayOfWeek > 6) return FALSE;
73 if(time.wDay > MONTHCAL_MonthLength(time.wMonth, time.wYear))
75 if(time.wHour > 23) return FALSE;
76 if(time.wMinute > 59) return FALSE;
77 if(time.wSecond > 59) return FALSE;
78 if(time.wMilliseconds > 999) return FALSE;
84 void MONTHCAL_CopyTime(const SYSTEMTIME *from, SYSTEMTIME *to)
86 to->wYear = from->wYear;
87 to->wMonth = from->wMonth;
88 to->wDayOfWeek = from->wDayOfWeek;
89 to->wDay = from->wDay;
90 to->wHour = from->wHour;
91 to->wMinute = from->wMinute;
92 to->wSecond = from->wSecond;
93 to->wMilliseconds = from->wMilliseconds;
97 /* Note:Depending on DST, this may be offset by a day.
98 Need to find out if we're on a DST place & adjust the clock accordingly.
99 Above function assumes we have a valid data.
100 Valid for year>1752; 1 <= d <= 31, 1 <= m <= 12.
104 /* returns the day in the week(0 == sunday, 6 == saturday) */
105 /* day(1 == 1st, 2 == 2nd... etc), year is the year value */
106 int MONTHCAL_CalculateDayOfWeek(DWORD day, DWORD month, DWORD year)
110 return((year + year/4 - year/100 + year/400 +
111 DayOfWeekTable[month-1] + day - 1 ) % 7);
115 static int MONTHCAL_CalcDayFromPos(MONTHCAL_INFO *infoPtr, int x, int y)
117 int daypos, weekpos, retval, firstDay;
119 /* if the point is outside the x bounds of the window put
121 if(x > (infoPtr->width_increment * 7.0)) {
122 x = infoPtr->rcClient.right - infoPtr->rcClient.left - infoPtr->left_offset;
125 daypos = (x -(infoPtr->prevmonth.left + infoPtr->left_offset)) / infoPtr->width_increment;
126 weekpos = (y - infoPtr->days.bottom - infoPtr->rcClient.top) / infoPtr->height_increment;
128 firstDay = MONTHCAL_CalculateDayOfWeek(1, infoPtr->currentMonth, infoPtr->currentYear);
129 retval = daypos + (7 * weekpos) - firstDay;
130 TRACE("%d %d %d\n", daypos, weekpos, retval);
134 /* day is the day of the month, 1 == 1st day of the month */
135 /* sets x and y to be the position of the day */
136 /* x == day, y == week where(0,0) == sunday, 1st week */
137 static void MONTHCAL_CalcDayXY(MONTHCAL_INFO *infoPtr, int day, int month,
140 int firstDay, prevMonth;
142 firstDay = MONTHCAL_CalculateDayOfWeek(1, infoPtr->currentMonth, infoPtr->currentYear);
144 if(month==infoPtr->currentMonth) {
145 *x = (day + firstDay) % 7;
146 *y = (day + firstDay - *x) / 7;
149 if(month < infoPtr->currentMonth) {
150 prevMonth = month - 1;
154 *x = (MONTHCAL_MonthLength(prevMonth, infoPtr->currentYear) - firstDay) % 7;
159 *y = MONTHCAL_MonthLength(month, infoPtr->currentYear - 1) / 7;
160 *x = (day + firstDay + MONTHCAL_MonthLength(month,
161 infoPtr->currentYear)) % 7;
165 /* x: column(day), y: row(week) */
166 static void MONTHCAL_CalcDayRect(MONTHCAL_INFO *infoPtr, RECT *r, int x, int y)
168 r->left = infoPtr->prevmonth.left + x * infoPtr->width_increment + infoPtr->left_offset;
169 r->right = r->left + infoPtr->width_increment;
170 r->top = infoPtr->height_increment * y + infoPtr->days.bottom + infoPtr->top_offset;
171 r->bottom = r->top + infoPtr->textHeight;
175 /* sets the RECT struct r to the rectangle around the day and month */
176 /* day is the day value of the month(1 == 1st), month is the month */
177 /* value(january == 1, december == 12) */
178 static inline void MONTHCAL_CalcPosFromDay(MONTHCAL_INFO *infoPtr,
179 int day, int month, RECT *r)
183 MONTHCAL_CalcDayXY(infoPtr, day, month, &x, &y);
184 MONTHCAL_CalcDayRect(infoPtr, r, x, y);
188 /* day is the day in the month(1 == 1st of the month) */
189 /* month is the month value(1 == january, 12 == december) */
190 static void MONTHCAL_CircleDay(HDC hdc, MONTHCAL_INFO *infoPtr, int day,
193 HPEN hRedPen = CreatePen(PS_SOLID, 2, RGB(255, 0, 0));
194 HPEN hOldPen2 = SelectObject(hdc, hRedPen);
199 /* use prevmonth to calculate position because it contains the extra width
200 * from MCS_WEEKNUMBERS
203 MONTHCAL_CalcPosFromDay(infoPtr, day, month, &day_rect);
210 points[1].x = x + 0.8 * infoPtr->width_increment;
212 points[2].x = x + 0.9 * infoPtr->width_increment;
214 points[3].x = x + infoPtr->width_increment;
215 points[3].y = y + 0.5 * infoPtr->textHeight;
217 points[4].x = x + infoPtr->width_increment;
218 points[4].y = y + 0.9 * infoPtr->textHeight;
219 points[5].x = x + 0.6 * infoPtr->width_increment;
220 points[5].y = y + 0.9 * infoPtr->textHeight;
221 points[6].x = x + 0.5 * infoPtr->width_increment;
222 points[6].y = y + 0.9 * infoPtr->textHeight; /* bring the bottom up just
223 a hair to fit inside the day rectangle */
225 points[7].x = x + 0.2 * infoPtr->width_increment;
226 points[7].y = y + 0.8 * infoPtr->textHeight;
227 points[8].x = x + 0.1 * infoPtr->width_increment;
228 points[8].y = y + 0.8 * infoPtr->textHeight;
230 points[9].y = y + 0.5 * infoPtr->textHeight;
232 points[10].x = x + 0.1 * infoPtr->width_increment;
233 points[10].y = y + 0.2 * infoPtr->textHeight;
234 points[11].x = x + 0.2 * infoPtr->width_increment;
235 points[11].y = y + 0.3 * infoPtr->textHeight;
236 points[12].x = x + 0.5 * infoPtr->width_increment;
237 points[12].y = y + 0.3 * infoPtr->textHeight;
239 PolyBezier(hdc, points, 13);
240 DeleteObject(hRedPen);
241 SelectObject(hdc, hOldPen2);
245 static void MONTHCAL_DrawDay(HDC hdc, MONTHCAL_INFO *infoPtr, int day, int month,
246 int x, int y, int bold)
250 static int haveBoldFont, haveSelectedDay = FALSE;
252 HPEN hNewPen, hOldPen = 0;
256 sprintf(buf, "%d", day);
258 /* No need to check styles: when selection is not valid, it is set to zero.
259 * 1<day<31, so evertyhing's OK.
262 MONTHCAL_CalcDayRect(infoPtr, &r, x, y);
264 if((day>=infoPtr->minSel.wDay) && (day<=infoPtr->maxSel.wDay)
265 && (month==infoPtr->currentMonth)) {
269 TRACE("%d %d %d\n",day, infoPtr->minSel.wDay, infoPtr->maxSel.wDay);
270 TRACE("%d %d %d %d\n", r.left, r.top, r.right, r.bottom);
271 oldCol = SetTextColor(hdc, infoPtr->monthbk);
272 oldBk = SetBkColor(hdc, infoPtr->trailingtxt);
273 hbr = GetSysColorBrush(COLOR_GRAYTEXT);
274 hrgn = CreateEllipticRgn(r.left, r.top, r.right, r.bottom);
275 FillRgn(hdc, hrgn, hbr);
277 /* FIXME: this may need to be changed now b/c of the other
278 drawing changes 11/3/99 CMM */
279 r2.left = r.left - 0.25 * infoPtr->textWidth;
281 r2.right = r.left + 0.5 * infoPtr->textWidth;
282 r2.bottom = r.bottom;
283 if(haveSelectedDay) FillRect(hdc, &r2, hbr);
284 haveSelectedDay = TRUE;
286 haveSelectedDay = FALSE;
289 /* need to add some code for multiple selections */
291 if((bold) &&(!haveBoldFont)) {
292 SelectObject(hdc, infoPtr->hBoldFont);
295 if((!bold) &&(haveBoldFont)) {
296 SelectObject(hdc, infoPtr->hFont);
297 haveBoldFont = FALSE;
300 if(haveSelectedDay) {
301 SetTextColor(hdc, oldCol);
302 SetBkColor(hdc, oldBk);
305 DrawTextA(hdc, buf, lstrlenA(buf), &r,
306 DT_CENTER | DT_VCENTER | DT_SINGLELINE );
308 /* draw a rectangle around the currently selected days text */
309 if((day==infoPtr->curSelDay) && (month==infoPtr->currentMonth)) {
310 hNewPen = CreatePen(PS_DOT, 0, GetSysColor(COLOR_WINDOWTEXT) );
311 hbr = GetSysColorBrush(COLOR_WINDOWTEXT);
312 FrameRect(hdc, &r, hbr);
313 SelectObject(hdc, hOldPen);
318 /* CHECKME: For `todays date', do we need to check the locale?*/
319 static void MONTHCAL_Refresh(HWND hwnd, HDC hdc, PAINTSTRUCT* ps)
321 MONTHCAL_INFO *infoPtr=MONTHCAL_GetInfoPtr(hwnd);
322 RECT *rcClient=&infoPtr->rcClient;
323 RECT *rcDraw=&infoPtr->rcDraw;
324 RECT *title=&infoPtr->title;
325 RECT *prev=&infoPtr->titlebtnprev;
326 RECT *next=&infoPtr->titlebtnnext;
327 RECT *titlemonth=&infoPtr->titlemonth;
328 RECT *titleyear=&infoPtr->titleyear;
329 RECT *prevmonth=&infoPtr->prevmonth;
330 RECT *nextmonth=&infoPtr->nextmonth;
333 RECT *weeknums=&infoPtr->weeknums;
334 RECT *rtoday=&infoPtr->today;
335 int i, j, m, mask, day, firstDay, weeknum, prevMonth;
336 int textHeight = infoPtr->textHeight, textWidth = infoPtr->textWidth;
340 /* LOGFONTA logFont; */
342 const char *thisMonthtxt;
343 COLORREF oldTextColor, oldBkColor;
344 DWORD dwStyle = GetWindowLongA(hwnd, GWL_STYLE);
346 RECT rcDay; /* used in MONTHCAL_CalcDayRect() */
348 oldTextColor = SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
351 /* fill background */
352 hbr = CreateSolidBrush (infoPtr->bk);
353 FillRect(hdc, rcClient, hbr);
357 if(IntersectRect(&rcTemp, &(ps->rcPaint), title))
359 hbr = CreateSolidBrush(infoPtr->titlebk);
360 FillRect(hdc, title, hbr);
364 /* if the previous button is pressed draw it depressed */
365 if(IntersectRect(&rcTemp, &(ps->rcPaint), prev))
367 if((infoPtr->status & MC_PREVPRESSED))
368 DrawFrameControl(hdc, prev, DFC_SCROLL,
369 DFCS_SCROLLLEFT | DFCS_PUSHED |
370 (dwStyle & WS_DISABLED ? DFCS_INACTIVE : 0));
371 else /* if the previous button is pressed draw it depressed */
372 DrawFrameControl(hdc, prev, DFC_SCROLL,
373 DFCS_SCROLLLEFT |(dwStyle & WS_DISABLED ? DFCS_INACTIVE : 0));
376 /* if next button is depressed draw it depressed */
377 if(IntersectRect(&rcTemp, &(ps->rcPaint), next))
379 if((infoPtr->status & MC_NEXTPRESSED))
380 DrawFrameControl(hdc, next, DFC_SCROLL,
381 DFCS_SCROLLRIGHT | DFCS_PUSHED |
382 (dwStyle & WS_DISABLED ? DFCS_INACTIVE : 0));
383 else /* if the next button is pressed draw it depressed */
384 DrawFrameControl(hdc, next, DFC_SCROLL,
385 DFCS_SCROLLRIGHT |(dwStyle & WS_DISABLED ? DFCS_INACTIVE : 0));
388 oldBkColor = SetBkColor(hdc, infoPtr->titlebk);
389 SetTextColor(hdc, infoPtr->titletxt);
390 currentFont = SelectObject(hdc, infoPtr->hBoldFont);
392 /* titlemonth->left and right are set in MONTHCAL_UpdateSize */
393 titlemonth->left = title->left;
394 titlemonth->right = title->right;
396 thisMonthtxt = monthtxt[infoPtr->currentMonth - 1];
397 sprintf(buf, "%s %ld", thisMonthtxt, infoPtr->currentYear);
399 if(IntersectRect(&rcTemp, &(ps->rcPaint), titlemonth))
401 DrawTextA(hdc, buf, strlen(buf), titlemonth,
402 DT_CENTER | DT_VCENTER | DT_SINGLELINE);
405 SelectObject(hdc, infoPtr->hFont);
407 /* titlemonth left/right contained rect for whole titletxt('June 1999')
408 * MCM_HitTestInfo wants month & year rects, so prepare these now.
409 *(no, we can't draw them separately; the whole text is centered)
411 GetTextExtentPoint32A(hdc, buf, lstrlenA(buf), &size);
412 titlemonth->left = title->right / 2 - size.cx / 2;
413 titleyear->right = title->right / 2 + size.cx / 2;
414 GetTextExtentPoint32A(hdc, thisMonthtxt, lstrlenA(thisMonthtxt), &size);
415 titlemonth->right = titlemonth->left + size.cx;
416 titleyear->right = titlemonth->right;
418 /* draw line under day abbreviatons */
420 if(dwStyle & MCS_WEEKNUMBERS)
421 MoveToEx(hdc, rcDraw->left + textWidth + 3, title->bottom + textHeight + 2, NULL);
423 MoveToEx(hdc, rcDraw->left + 3, title->bottom + textHeight + 2, NULL);
425 LineTo(hdc, rcDraw->right - 3, title->bottom + textHeight + 2);
427 /* draw day abbreviations */
429 SetBkColor(hdc, infoPtr->monthbk);
430 SetTextColor(hdc, infoPtr->trailingtxt);
432 /* copy this rect so we can change the values without changing */
433 /* the original version */
434 days->left = infoPtr->days.left;
435 days->right = infoPtr->days.right;
436 days->top = infoPtr->days.top;
437 days->bottom = infoPtr->days.bottom;
439 i = infoPtr->firstDay;
442 DrawTextA(hdc, daytxt[i], strlen(daytxt[i]), days,
443 DT_CENTER | DT_VCENTER | DT_SINGLELINE );
445 days->left+=infoPtr->width_increment;
446 days->right+=infoPtr->width_increment;
449 days->left = rcDraw->left + j;
450 if(dwStyle & MCS_WEEKNUMBERS) days->left+=textWidth;
451 /* FIXME: this may need to be changed now 11/10/99 CMM */
452 days->right = rcDraw->left + (j+1) * textWidth - 2;
454 /* draw day numbers; first, the previous month */
456 firstDay = MONTHCAL_CalculateDayOfWeek(1, infoPtr->currentMonth, infoPtr->currentYear);
458 prevMonth = infoPtr->currentMonth - 1;
459 if(prevMonth == 0) /* if currentMonth is january(1) prevMonth is */
460 prevMonth = 12; /* december(12) of the previous year */
462 day = MONTHCAL_MonthLength(prevMonth, infoPtr->currentYear) - firstDay;
467 while(day <= MONTHCAL_MonthLength(prevMonth, infoPtr->currentYear)) {
468 MONTHCAL_CalcDayRect(infoPtr, &rcDay, i, 0);
469 if(IntersectRect(&rcTemp, &(ps->rcPaint), &rcDay))
471 MONTHCAL_DrawDay(hdc, infoPtr, day, prevMonth, i, 0,
472 infoPtr->monthdayState[m] & mask);
481 if(dwStyle & MCS_WEEKNUMBERS) prevmonth->left = textWidth;
482 prevmonth->right = prevmonth->left + (i * infoPtr->width_increment) +
483 infoPtr->left_offset;
484 prevmonth->top = days->bottom;
485 prevmonth->bottom = prevmonth->top + textHeight;
487 /* draw `current' month */
489 day = 1; /* start at the beginning of the current month */
491 infoPtr->firstDayplace = i;
492 SetTextColor(hdc, infoPtr->txt);
496 /* draw the first week of the current month */
498 MONTHCAL_CalcDayRect(infoPtr, &rcDay, i, 0);
499 if(IntersectRect(&rcTemp, &(ps->rcPaint), &rcDay))
502 MONTHCAL_DrawDay(hdc, infoPtr, day, infoPtr->currentMonth, i, 0,
503 infoPtr->monthdayState[m] & mask);
505 if((infoPtr->currentMonth==infoPtr->todaysDate.wMonth) &&
506 (day==infoPtr->todaysDate.wDay) &&
507 (infoPtr->currentYear == infoPtr->todaysDate.wYear)) {
508 MONTHCAL_CircleDay(hdc, infoPtr, day, infoPtr->currentMonth);
517 j = 1; /* move to the 2nd week of the current month */
518 i = 0; /* move back to sunday */
519 while(day <= MONTHCAL_MonthLength(infoPtr->currentMonth, infoPtr->currentYear)) {
520 MONTHCAL_CalcDayRect(infoPtr, &rcDay, i, j);
521 if(IntersectRect(&rcTemp, &(ps->rcPaint), &rcDay))
523 MONTHCAL_DrawDay(hdc, infoPtr, day, infoPtr->currentMonth, i, j,
524 infoPtr->monthdayState[m] & mask);
526 if((infoPtr->currentMonth==infoPtr->todaysDate.wMonth) &&
527 (day==infoPtr->todaysDate.wDay) &&
528 (infoPtr->currentYear == infoPtr->todaysDate.wYear))
529 MONTHCAL_CircleDay(hdc, infoPtr, day, infoPtr->currentMonth);
534 if(i>6) { /* past saturday, goto the next weeks sunday */
540 /* draw `next' month */
542 /* note: the nextmonth rect only hints for the `half-week' that needs to be
543 * drawn to complete the current week. An eventual next week that needs to
544 * be drawn to complete the month calendar is not taken into account in
545 * this rect -- HitTest knows about this.*/
546 nextmonth->left = rcDraw->left + (i * infoPtr->width_increment) +
547 infoPtr->left_offset;
548 nextmonth->right = rcDraw->right;
549 nextmonth->top = days->bottom + (j+1) * textHeight;
550 nextmonth->bottom = nextmonth->top + textHeight;
552 day = 1; /* start at the first day of the next month */
556 SetTextColor(hdc, infoPtr->trailingtxt);
557 while((i<7) &&(j<6)) {
558 MONTHCAL_CalcDayRect(infoPtr, &rcDay, i, j);
559 if(IntersectRect(&rcTemp, &(ps->rcPaint), &rcDay))
561 MONTHCAL_DrawDay(hdc, infoPtr, day, infoPtr->currentMonth + 1, i, j,
562 infoPtr->monthdayState[m] & mask);
568 if(i==7) { /* past saturday, go to next week's sunday */
573 SetTextColor(hdc, infoPtr->txt);
576 /* draw `today' date if style allows it, and draw a circle before today's
577 * date if necessary */
579 if(!(dwStyle & MCS_NOTODAY)) {
581 if(!(dwStyle & MCS_NOTODAYCIRCLE)) {
582 day = MONTHCAL_CalcDayFromPos(infoPtr, 0, nextmonth->bottom + textHeight);
583 MONTHCAL_CircleDay(hdc, infoPtr, day, infoPtr->currentMonth);
586 MONTHCAL_CalcDayRect(infoPtr, rtoday, 1, 6);
587 sprintf(buf, "Today: %d/%d/%d", infoPtr->todaysDate.wMonth,
588 infoPtr->todaysDate.wDay, infoPtr->todaysDate.wYear);
589 rtoday->left = rtoday->left + 3; /* move text slightly away from circle */
590 rtoday->right = rcDraw->right;
591 SelectObject(hdc, infoPtr->hBoldFont);
593 if(IntersectRect(&rcTemp, &(ps->rcPaint), rtoday))
595 DrawTextA(hdc, buf, lstrlenA(buf), rtoday,
596 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
598 SelectObject(hdc, infoPtr->hFont);
601 if(dwStyle & MCS_WEEKNUMBERS) {
602 /* display weeknumbers*/
604 weeknums->right = textWidth;
605 weeknums->top = days->bottom + 2;
606 weeknums->bottom = days->bottom + 2 + textHeight;
609 for(i=0; i<infoPtr->currentMonth-1; i++)
610 weeknum+=MONTHCAL_MonthLength(i, infoPtr->currentYear);
614 sprintf(buf, "%d", weeknum + i);
615 DrawTextA(hdc, buf, lstrlenA(buf), weeknums,
616 DT_CENTER | DT_BOTTOM | DT_SINGLELINE );
617 weeknums->top+=textHeight * 1.25;
618 weeknums->bottom+=textHeight * 1.25;
621 MoveToEx(hdc, weeknums->right, days->bottom + 5 , NULL);
622 LineTo(hdc, weeknums->right, weeknums->bottom - 1.25 * textHeight - 5);
626 /* currentFont was font at entering Refresh */
628 SetBkColor(hdc, oldBkColor);
629 SelectObject(hdc, currentFont);
630 SetTextColor(hdc, oldTextColor);
635 MONTHCAL_GetMinReqRect(HWND hwnd, WPARAM wParam, LPARAM lParam)
637 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
638 LPRECT lpRect = (LPRECT) lParam;
639 TRACE("%x %lx\n", wParam, lParam);
641 /* validate parameters */
643 if((infoPtr==NULL) ||(lpRect == NULL) ) return FALSE;
645 lpRect->left = infoPtr->rcClient.left;
646 lpRect->right = infoPtr->rcClient.right;
647 lpRect->top = infoPtr->rcClient.top;
648 lpRect->bottom = infoPtr->rcClient.bottom;
654 MONTHCAL_GetColor(HWND hwnd, WPARAM wParam, LPARAM lParam)
656 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
658 TRACE("%x %lx\n", wParam, lParam);
660 switch((int)wParam) {
661 case MCSC_BACKGROUND:
666 return infoPtr->titlebk;
668 return infoPtr->titletxt;
670 return infoPtr->monthbk;
671 case MCSC_TRAILINGTEXT:
672 return infoPtr->trailingtxt;
680 MONTHCAL_SetColor(HWND hwnd, WPARAM wParam, LPARAM lParam)
682 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
685 TRACE("%x %lx\n", wParam, lParam);
687 switch((int)wParam) {
688 case MCSC_BACKGROUND:
690 infoPtr->bk = (COLORREF)lParam;
694 infoPtr->txt = (COLORREF)lParam;
697 prev = infoPtr->titlebk;
698 infoPtr->titlebk = (COLORREF)lParam;
701 prev=infoPtr->titletxt;
702 infoPtr->titletxt = (COLORREF)lParam;
705 prev = infoPtr->monthbk;
706 infoPtr->monthbk = (COLORREF)lParam;
708 case MCSC_TRAILINGTEXT:
709 prev = infoPtr->trailingtxt;
710 infoPtr->trailingtxt = (COLORREF)lParam;
719 MONTHCAL_GetMonthDelta(HWND hwnd, WPARAM wParam, LPARAM lParam)
721 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
723 TRACE("%x %lx\n", wParam, lParam);
726 return infoPtr->delta;
728 return infoPtr->visible;
733 MONTHCAL_SetMonthDelta(HWND hwnd, WPARAM wParam, LPARAM lParam)
735 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
736 int prev = infoPtr->delta;
738 TRACE("%x %lx\n", wParam, lParam);
740 infoPtr->delta = (int)wParam;
746 MONTHCAL_GetFirstDayOfWeek(HWND hwnd, WPARAM wParam, LPARAM lParam)
748 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
750 return infoPtr->firstDay;
754 /* sets the first day of the week that will appear in the control */
755 /* 0 == Monday, 6 == Sunday */
756 /* FIXME: this needs to be implemented properly in MONTHCAL_Refresh() */
757 /* FIXME: we need more error checking here */
759 MONTHCAL_SetFirstDayOfWeek(HWND hwnd, WPARAM wParam, LPARAM lParam)
761 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
762 int prev = infoPtr->firstDay;
766 TRACE("%x %lx\n", wParam, lParam);
768 if((lParam >= 0) && (lParam < 7)) {
769 infoPtr->firstDay = (int)lParam;
770 GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_IFIRSTDAYOFWEEK,
772 TRACE("%s %d\n", buf, strlen(buf));
773 if((sscanf(buf, "%d", &day) == 1) &&(infoPtr->firstDay != day))
774 infoPtr->firstDay = day;
780 /* FIXME: fill this in */
782 MONTHCAL_GetMonthRange(HWND hwnd, WPARAM wParam, LPARAM lParam)
784 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
786 TRACE("%x %lx\n", wParam, lParam);
789 return infoPtr->monthRange;
794 MONTHCAL_GetMaxTodayWidth(HWND hwnd)
796 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
798 return(infoPtr->today.right - infoPtr->today.left);
802 /* FIXME: are validated times taken from current date/time or simply
804 * FIXME: check whether MCM_GETMONTHRANGE shows correct result after
805 * adjusting range with MCM_SETRANGE
809 MONTHCAL_SetRange(HWND hwnd, WPARAM wParam, LPARAM lParam)
811 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
812 SYSTEMTIME lprgSysTimeArray[1];
815 TRACE("%x %lx\n", wParam, lParam);
817 if(wParam & GDTR_MAX) {
818 if(MONTHCAL_ValidateTime(lprgSysTimeArray[1])){
819 MONTHCAL_CopyTime(&lprgSysTimeArray[1], &infoPtr->maxDate);
820 infoPtr->rangeValid|=GDTR_MAX;
822 GetSystemTime(&infoPtr->todaysDate);
823 MONTHCAL_CopyTime(&infoPtr->todaysDate, &infoPtr->maxDate);
826 if(wParam & GDTR_MIN) {
827 if(MONTHCAL_ValidateTime(lprgSysTimeArray[0])) {
828 MONTHCAL_CopyTime(&lprgSysTimeArray[0], &infoPtr->maxDate);
829 infoPtr->rangeValid|=GDTR_MIN;
831 GetSystemTime(&infoPtr->todaysDate);
832 MONTHCAL_CopyTime(&infoPtr->todaysDate, &infoPtr->maxDate);
836 prev = infoPtr->monthRange;
837 infoPtr->monthRange = infoPtr->maxDate.wMonth - infoPtr->minDate.wMonth;
839 if(infoPtr->monthRange!=prev) {
840 COMCTL32_ReAlloc(infoPtr->monthdayState,
841 infoPtr->monthRange * sizeof(MONTHDAYSTATE));
848 /* CHECKME: At the moment, we copy ranges anyway,regardless of
849 * infoPtr->rangeValid; a invalid range is simply filled with zeros in
850 * SetRange. Is this the right behavior?
854 MONTHCAL_GetRange(HWND hwnd, WPARAM wParam, LPARAM lParam)
856 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
857 SYSTEMTIME *lprgSysTimeArray = (SYSTEMTIME *)lParam;
859 /* validate parameters */
861 if((infoPtr==NULL) || (lprgSysTimeArray==NULL)) return FALSE;
863 MONTHCAL_CopyTime(&infoPtr->maxDate, &lprgSysTimeArray[1]);
864 MONTHCAL_CopyTime(&infoPtr->minDate, &lprgSysTimeArray[0]);
866 return infoPtr->rangeValid;
871 MONTHCAL_SetDayState(HWND hwnd, WPARAM wParam, LPARAM lParam)
874 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
875 int i, iMonths = (int)wParam;
876 MONTHDAYSTATE *dayStates = (LPMONTHDAYSTATE)lParam;
878 TRACE("%x %lx\n", wParam, lParam);
879 if(iMonths!=infoPtr->monthRange) return 0;
881 for(i=0; i<iMonths; i++)
882 infoPtr->monthdayState[i] = dayStates[i];
888 MONTHCAL_GetCurSel(HWND hwnd, WPARAM wParam, LPARAM lParam)
890 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
891 SYSTEMTIME *lpSel = (SYSTEMTIME *) lParam;
893 TRACE("%x %lx\n", wParam, lParam);
894 if((infoPtr==NULL) ||(lpSel==NULL)) return FALSE;
895 if(GetWindowLongA(hwnd, GWL_STYLE) & MCS_MULTISELECT) return FALSE;
897 MONTHCAL_CopyTime(&infoPtr->minSel, lpSel);
902 /* FIXME: if the specified date is not visible, make it visible */
905 MONTHCAL_SetCurSel(HWND hwnd, WPARAM wParam, LPARAM lParam)
907 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
908 SYSTEMTIME *lpSel = (SYSTEMTIME *)lParam;
910 TRACE("%x %lx\n", wParam, lParam);
911 if((infoPtr==NULL) ||(lpSel==NULL)) return FALSE;
912 if(GetWindowLongA(hwnd, GWL_STYLE) & MCS_MULTISELECT) return FALSE;
914 TRACE("%d %d\n", lpSel->wMonth, lpSel->wDay);
916 MONTHCAL_CopyTime(lpSel, &infoPtr->minSel);
917 MONTHCAL_CopyTime(lpSel, &infoPtr->maxSel);
919 InvalidateRect(hwnd, NULL, FALSE);
926 MONTHCAL_GetMaxSelCount(HWND hwnd, WPARAM wParam, LPARAM lParam)
928 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
930 TRACE("%x %lx\n", wParam, lParam);
931 return infoPtr->maxSelCount;
936 MONTHCAL_SetMaxSelCount(HWND hwnd, WPARAM wParam, LPARAM lParam)
938 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
940 TRACE("%x %lx\n", wParam, lParam);
941 if(GetWindowLongA(hwnd, GWL_STYLE) & MCS_MULTISELECT) {
942 infoPtr->maxSelCount = wParam;
950 MONTHCAL_GetSelRange(HWND hwnd, WPARAM wParam, LPARAM lParam)
952 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
953 SYSTEMTIME *lprgSysTimeArray = (SYSTEMTIME *) lParam;
955 TRACE("%x %lx\n", wParam, lParam);
957 /* validate parameters */
959 if((infoPtr==NULL) ||(lprgSysTimeArray==NULL)) return FALSE;
961 if(GetWindowLongA(hwnd, GWL_STYLE) & MCS_MULTISELECT)
963 MONTHCAL_CopyTime(&infoPtr->maxSel, &lprgSysTimeArray[1]);
964 MONTHCAL_CopyTime(&infoPtr->minSel, &lprgSysTimeArray[0]);
965 TRACE("[min,max]=[%d %d]\n", infoPtr->minSel.wDay, infoPtr->maxSel.wDay);
974 MONTHCAL_SetSelRange(HWND hwnd, WPARAM wParam, LPARAM lParam)
976 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
977 SYSTEMTIME *lprgSysTimeArray = (SYSTEMTIME *) lParam;
979 TRACE("%x %lx\n", wParam, lParam);
981 /* validate parameters */
983 if((infoPtr==NULL) ||(lprgSysTimeArray==NULL)) return FALSE;
985 if(GetWindowLongA( hwnd, GWL_STYLE) & MCS_MULTISELECT)
987 MONTHCAL_CopyTime(&lprgSysTimeArray[1], &infoPtr->maxSel);
988 MONTHCAL_CopyTime(&lprgSysTimeArray[0], &infoPtr->minSel);
989 TRACE("[min,max]=[%d %d]\n", infoPtr->minSel.wDay, infoPtr->maxSel.wDay);
998 MONTHCAL_GetToday(HWND hwnd, WPARAM wParam, LPARAM lParam)
1000 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
1001 SYSTEMTIME *lpToday = (SYSTEMTIME *) lParam;
1003 TRACE("%x %lx\n", wParam, lParam);
1005 /* validate parameters */
1007 if((infoPtr==NULL) || (lpToday==NULL)) return FALSE;
1008 MONTHCAL_CopyTime(&infoPtr->todaysDate, lpToday);
1014 MONTHCAL_SetToday(HWND hwnd, WPARAM wParam, LPARAM lParam)
1016 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
1017 SYSTEMTIME *lpToday = (SYSTEMTIME *) lParam;
1019 TRACE("%x %lx\n", wParam, lParam);
1021 /* validate parameters */
1023 if((infoPtr==NULL) ||(lpToday==NULL)) return FALSE;
1024 MONTHCAL_CopyTime(lpToday, &infoPtr->todaysDate);
1030 MONTHCAL_HitTest(HWND hwnd, LPARAM lParam)
1032 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
1033 PMCHITTESTINFO lpht = (PMCHITTESTINFO)lParam;
1039 retval = MCHT_NOWHERE;
1042 /* are we in the header? */
1044 if(PtInRect(&infoPtr->title, lpht->pt)) {
1045 if(PtInRect(&infoPtr->titlebtnprev, lpht->pt)) {
1046 retval = MCHT_TITLEBTNPREV;
1049 if(PtInRect(&infoPtr->titlebtnnext, lpht->pt)) {
1050 retval = MCHT_TITLEBTNNEXT;
1053 if(PtInRect(&infoPtr->titlemonth, lpht->pt)) {
1054 retval = MCHT_TITLEMONTH;
1057 if(PtInRect(&infoPtr->titleyear, lpht->pt)) {
1058 retval = MCHT_TITLEYEAR;
1062 retval = MCHT_TITLE;
1066 if(PtInRect(&infoPtr->days, lpht->pt)) {
1067 retval = MCHT_CALENDARDAY; /* FIXME: find out which day we're on */
1070 if(PtInRect(&infoPtr->weeknums, lpht->pt)) {
1071 retval = MCHT_CALENDARWEEKNUM; /* FIXME: find out which day we're on */
1074 if(PtInRect(&infoPtr->prevmonth, lpht->pt)) {
1075 retval = MCHT_CALENDARDATEPREV;
1079 if(PtInRect(&infoPtr->nextmonth, lpht->pt) ||
1080 ((y > infoPtr->nextmonth.bottom) && (y < infoPtr->nextmonth.bottom +
1081 infoPtr->height_increment) && (x < infoPtr->rcClient.right) &&
1082 (x > infoPtr->rcDraw.left))) {
1083 retval = MCHT_CALENDARDATENEXT;
1087 if(PtInRect(&infoPtr->today, lpht->pt)) {
1088 retval = MCHT_TODAYLINK;
1092 /* MCHT_CALENDARDATE determination: since the next & previous month have
1093 * been handled already(MCHT_CALENDARDATEPREV/NEXT), we only have to check
1094 * whether we're in the calendar area. infoPtr->prevMonth.left handles the
1095 * MCS_WEEKNUMBERS style nicely.
1099 TRACE("%d %d [%d %d %d %d] [%d %d %d %d]\n", x, y,
1100 infoPtr->prevmonth.left, infoPtr->prevmonth.right,
1101 infoPtr->prevmonth.top, infoPtr->prevmonth.bottom,
1102 infoPtr->nextmonth.left, infoPtr->nextmonth.right,
1103 infoPtr->nextmonth.top, infoPtr->nextmonth.bottom);
1104 if((x > infoPtr->rcClient.left) && (x < infoPtr->rcClient.right) &&
1105 (y > infoPtr->rcClient.top) && (y < infoPtr->nextmonth.bottom)) {
1106 lpht->st.wYear = infoPtr->currentYear;
1107 lpht->st.wMonth = infoPtr->currentMonth;
1109 lpht->st.wDay = MONTHCAL_CalcDayFromPos(infoPtr, x, y);
1111 TRACE("day hit: %d\n", lpht->st.wDay);
1112 retval = MCHT_CALENDARDATE;
1117 /* Hit nothing special? What's left must be background :-) */
1119 retval = MCHT_CALENDARBK;
1121 lpht->uHit = retval;
1126 static void MONTHCAL_GoToNextMonth(HWND hwnd, MONTHCAL_INFO *infoPtr)
1128 DWORD dwStyle = GetWindowLongA(hwnd, GWL_STYLE);
1130 TRACE("MONTHCAL_GoToNextMonth\n");
1132 infoPtr->currentMonth++;
1133 if(infoPtr->currentMonth > 12) {
1134 infoPtr->currentYear++;
1135 infoPtr->currentMonth = 1;
1138 if(dwStyle & MCS_DAYSTATE) {
1142 nmds.nmhdr.hwndFrom = hwnd;
1143 nmds.nmhdr.idFrom = GetWindowLongA(hwnd, GWL_ID);
1144 nmds.nmhdr.code = MCN_GETDAYSTATE;
1145 nmds.cDayState = infoPtr->monthRange;
1146 nmds.prgDayState = COMCTL32_Alloc(infoPtr->monthRange * sizeof(MONTHDAYSTATE));
1148 SendMessageA(GetParent(hwnd), WM_NOTIFY,
1149 (WPARAM)nmds.nmhdr.idFrom, (LPARAM)&nmds);
1150 for(i=0; i<infoPtr->monthRange; i++)
1151 infoPtr->monthdayState[i] = nmds.prgDayState[i];
1156 static void MONTHCAL_GoToPrevMonth(HWND hwnd, MONTHCAL_INFO *infoPtr)
1158 DWORD dwStyle = GetWindowLongA(hwnd, GWL_STYLE);
1160 TRACE("MONTHCAL_GoToPrevMonth\n");
1162 infoPtr->currentMonth--;
1163 if(infoPtr->currentMonth < 1) {
1164 infoPtr->currentYear--;
1165 infoPtr->currentMonth = 12;
1168 if(dwStyle & MCS_DAYSTATE) {
1172 nmds.nmhdr.hwndFrom = hwnd;
1173 nmds.nmhdr.idFrom = GetWindowLongA(hwnd, GWL_ID);
1174 nmds.nmhdr.code = MCN_GETDAYSTATE;
1175 nmds.cDayState = infoPtr->monthRange;
1176 nmds.prgDayState = COMCTL32_Alloc
1177 (infoPtr->monthRange * sizeof(MONTHDAYSTATE));
1179 SendMessageA(GetParent(hwnd), WM_NOTIFY,
1180 (WPARAM)nmds.nmhdr.idFrom, (LPARAM)&nmds);
1181 for(i=0; i<infoPtr->monthRange; i++)
1182 infoPtr->monthdayState[i] = nmds.prgDayState[i];
1188 MONTHCAL_LButtonDown(HWND hwnd, WPARAM wParam, LPARAM lParam)
1190 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
1195 BOOL redraw = FALSE;
1196 RECT rcDay; /* used in determining area to invalidate */
1198 TRACE("%x %lx\n", wParam, lParam);
1200 ht.pt.x = (INT)LOWORD(lParam);
1201 ht.pt.y = (INT)HIWORD(lParam);
1202 hit = MONTHCAL_HitTest(hwnd, (LPARAM)&ht);
1204 /* FIXME: these flags should be checked by */
1205 /*((hit & MCHT_XXX) == MCHT_XXX) b/c some of the flags are */
1207 if(hit & MCHT_NEXT) {
1209 MONTHCAL_GoToNextMonth(hwnd, infoPtr);
1210 infoPtr->status = MC_NEXTPRESSED;
1211 SetTimer(hwnd, MC_NEXTMONTHTIMER, MC_NEXTMONTHDELAY, 0);
1212 InvalidateRect(hwnd, NULL, FALSE);
1214 if(hit & MCHT_PREV) {
1216 MONTHCAL_GoToPrevMonth(hwnd, infoPtr);
1217 infoPtr->status = MC_PREVPRESSED;
1218 SetTimer(hwnd, MC_PREVMONTHTIMER, MC_NEXTMONTHDELAY, 0);
1219 InvalidateRect(hwnd, NULL, FALSE);
1222 if(hit == MCHT_TITLEMONTH) {
1224 HRSRC hrsrc = FindResourceA( COMCTL32_hModule, MAKEINTRESOURCEA(IDD_MCMONTHMENU), RT_MENUA );
1226 TRACE("returning zero\n");
1229 TRACE("resource is:%x\n",hrsrc);
1230 hMenu = LoadMenuIndirectA((LPCVOID)LoadResource( COMCTL32_hModule, hrsrc ));
1232 TRACE("menu is:%x\n",hMenu);
1235 hMenu = CreateMenu();
1236 AppendMenuA(hMenu, MF_STRING,IDM_JAN, "January");
1237 AppendMenuA(hMenu, MF_STRING,IDM_FEB, "February");
1238 AppendMenuA(hMenu, MF_STRING,IDM_MAR, "March");
1240 retval = CreateWindowA(POPUPMENU_CLASS_ATOM, NULL,
1241 WS_CHILD | WS_VISIBLE, 0, 0 ,100 , 220,
1242 hwnd, hMenu, GetWindowLongA(hwnd, GWL_HINSTANCE), NULL);
1243 TRACE("hwnd returned:%x\n", retval);
1246 if(hit == MCHT_TITLEYEAR) {
1247 FIXME("create updown for yearselection\n");
1249 if(hit == MCHT_TODAYLINK) {
1250 FIXME("set currentday\n");
1252 if(hit == MCHT_CALENDARDATE) {
1253 SYSTEMTIME selArray[2];
1257 nmsc.nmhdr.hwndFrom = hwnd;
1258 nmsc.nmhdr.idFrom = GetWindowLongA(hwnd, GWL_ID);
1259 nmsc.nmhdr.code = MCN_SELCHANGE;
1260 MONTHCAL_CopyTime(&nmsc.stSelStart, &infoPtr->minSel);
1261 MONTHCAL_CopyTime(&nmsc.stSelEnd, &infoPtr->maxSel);
1263 SendMessageA(GetParent(hwnd), WM_NOTIFY,
1264 (WPARAM)nmsc.nmhdr.idFrom,(LPARAM)&nmsc);
1266 MONTHCAL_CopyTime(&ht.st, &selArray[0]);
1267 MONTHCAL_CopyTime(&ht.st, &selArray[1]);
1268 MONTHCAL_SetSelRange(hwnd,0,(LPARAM) &selArray);
1270 /* FIXME: for some reason if RedrawWindow has a NULL instead of zero it gives */
1271 /* a compiler warning */
1272 /* redraw both old and new days if the selected day changed */
1273 if(infoPtr->curSelDay != ht.st.wDay) {
1274 MONTHCAL_CalcPosFromDay(infoPtr, ht.st.wDay, ht.st.wMonth, &rcDay);
1275 RedrawWindow(hwnd, &rcDay, 0, RDW_ERASE|RDW_INVALIDATE);
1277 MONTHCAL_CalcPosFromDay(infoPtr, infoPtr->curSelDay, infoPtr->currentMonth, &rcDay);
1278 RedrawWindow(hwnd, &rcDay, 0, RDW_ERASE|RDW_INVALIDATE);
1281 infoPtr->firstSelDay = ht.st.wDay;
1282 infoPtr->curSelDay = ht.st.wDay;
1283 infoPtr->status = MC_SEL_LBUTDOWN;
1292 MONTHCAL_LButtonUp(HWND hwnd, WPARAM wParam, LPARAM lParam)
1294 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
1297 BOOL redraw = FALSE;
1301 if(infoPtr->status & MC_NEXTPRESSED) {
1302 KillTimer(hwnd, MC_NEXTMONTHTIMER);
1305 if(infoPtr->status & MC_PREVPRESSED) {
1306 KillTimer(hwnd, MC_PREVMONTHTIMER);
1310 infoPtr->status = MC_SEL_LBUTUP;
1312 nmhdr.hwndFrom = hwnd;
1313 nmhdr.idFrom = GetWindowLongA( hwnd, GWL_ID);
1314 nmhdr.code = NM_RELEASEDCAPTURE;
1315 TRACE("Sent notification from %x to %x\n", hwnd, GetParent(hwnd));
1317 SendMessageA(GetParent(hwnd), WM_NOTIFY,
1318 (WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr);
1320 nmsc.nmhdr.hwndFrom = hwnd;
1321 nmsc.nmhdr.idFrom = GetWindowLongA(hwnd, GWL_ID);
1322 nmsc.nmhdr.code = MCN_SELECT;
1323 MONTHCAL_CopyTime(&nmsc.stSelStart, &infoPtr->minSel);
1324 MONTHCAL_CopyTime(&nmsc.stSelEnd, &infoPtr->maxSel);
1326 SendMessageA(GetParent(hwnd), WM_NOTIFY,
1327 (WPARAM)nmsc.nmhdr.idFrom, (LPARAM)&nmsc);
1329 /* redraw if necessary */
1331 InvalidateRect(hwnd, NULL, FALSE);
1338 MONTHCAL_Timer(HWND hwnd, WPARAM wParam, LPARAM lParam)
1340 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
1341 BOOL redraw = FALSE;
1343 TRACE(" %d\n", wParam);
1344 if(!infoPtr) return 0;
1347 case MC_NEXTMONTHTIMER:
1349 MONTHCAL_GoToNextMonth(hwnd, infoPtr);
1351 case MC_PREVMONTHTIMER:
1353 MONTHCAL_GoToPrevMonth(hwnd, infoPtr);
1356 ERR("got unknown timer\n");
1359 /* redraw only if necessary */
1361 InvalidateRect(hwnd, NULL, FALSE);
1368 MONTHCAL_MouseMove(HWND hwnd, WPARAM wParam, LPARAM lParam)
1370 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
1372 int oldselday, selday, hit;
1375 if(!(infoPtr->status & MC_SEL_LBUTDOWN)) return 0;
1377 ht.pt.x = LOWORD(lParam);
1378 ht.pt.y = HIWORD(lParam);
1380 hit = MONTHCAL_HitTest(hwnd, (LPARAM)&ht);
1382 /* not on the calendar date numbers? bail out */
1383 TRACE("hit:%x\n",hit);
1384 if((hit & MCHT_CALENDARDATE) != MCHT_CALENDARDATE) return 0;
1386 selday = ht.st.wDay;
1387 oldselday = infoPtr->curSelDay;
1388 infoPtr->curSelDay = selday;
1389 MONTHCAL_CalcPosFromDay(infoPtr, selday, ht.st. wMonth, &r);
1391 if(GetWindowLongA(hwnd, GWL_STYLE) & MCS_MULTISELECT) {
1392 SYSTEMTIME selArray[2];
1395 MONTHCAL_GetSelRange(hwnd, 0, (LPARAM)&selArray);
1397 if(infoPtr->firstSelDay==selArray[0].wDay) i=1;
1398 TRACE("oldRange:%d %d %d %d\n", infoPtr->firstSelDay, selArray[0].wDay, selArray[1].wDay, i);
1399 if(infoPtr->firstSelDay==selArray[1].wDay) {
1400 /* 1st time we get here: selArray[0]=selArray[1]) */
1401 /* if we're still at the first selected date, return */
1402 if(infoPtr->firstSelDay==selday) goto done;
1403 if(selday<infoPtr->firstSelDay) i = 0;
1406 if(abs(infoPtr->firstSelDay - selday) >= infoPtr->maxSelCount) {
1407 if(selday>infoPtr->firstSelDay)
1408 selday = infoPtr->firstSelDay + infoPtr->maxSelCount;
1410 selday = infoPtr->firstSelDay - infoPtr->maxSelCount;
1413 if(selArray[i].wDay!=selday) {
1414 TRACE("newRange:%d %d %d %d\n", infoPtr->firstSelDay, selArray[0].wDay, selArray[1].wDay, i);
1416 selArray[i].wDay = selday;
1418 if(selArray[0].wDay>selArray[1].wDay) {
1420 tempday = selArray[1].wDay;
1421 selArray[1].wDay = selArray[0].wDay;
1422 selArray[0].wDay = tempday;
1425 MONTHCAL_SetSelRange(hwnd, 0, (LPARAM)&selArray);
1431 /* only redraw if the currently selected day changed */
1432 /* FIXME: this should specify a rectangle containing only the days that changed */
1433 /* using RedrawWindow */
1434 if(oldselday != infoPtr->curSelDay)
1435 InvalidateRect(hwnd, NULL, FALSE);
1442 MONTHCAL_Paint(HWND hwnd, WPARAM wParam)
1444 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
1448 /* fill ps.rcPaint with a default rect */
1449 memcpy(&(ps.rcPaint), &(infoPtr->rcClient), sizeof(infoPtr->rcClient));
1451 hdc = (wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam);
1452 MONTHCAL_Refresh(hwnd, hdc, &ps);
1453 if(!wParam) EndPaint(hwnd, &ps);
1459 MONTHCAL_KillFocus(HWND hwnd, WPARAM wParam, LPARAM lParam)
1463 InvalidateRect(hwnd, NULL, TRUE);
1470 MONTHCAL_SetFocus(HWND hwnd, WPARAM wParam, LPARAM lParam)
1474 InvalidateRect(hwnd, NULL, FALSE);
1479 /* sets the size information */
1480 static void MONTHCAL_UpdateSize(HWND hwnd)
1482 HDC hdc = GetDC(hwnd);
1483 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
1484 RECT *rcClient=&infoPtr->rcClient;
1485 RECT *rcDraw=&infoPtr->rcDraw;
1486 RECT *title=&infoPtr->title;
1487 RECT *prev=&infoPtr->titlebtnprev;
1488 RECT *next=&infoPtr->titlebtnnext;
1489 RECT *titlemonth=&infoPtr->titlemonth;
1490 RECT *titleyear=&infoPtr->titleyear;
1491 RECT *days=&infoPtr->days;
1494 DWORD dwStyle = GetWindowLongA(hwnd, GWL_STYLE);
1497 currentFont = SelectObject(hdc, infoPtr->hFont);
1499 /* FIXME: need a way to determine current font, without setting it */
1501 if(infoPtr->hFont!=currentFont) {
1502 SelectObject(hdc, currentFont);
1503 infoPtr->hFont=currentFont;
1504 GetObjectA(currentFont, sizeof(LOGFONTA), &logFont);
1505 logFont.lfWeight=FW_BOLD;
1506 infoPtr->hBoldFont = CreateFontIndirectA(&logFont);
1510 /* get the height and width of each day's text */
1511 GetTextMetricsA(hdc, &tm);
1512 infoPtr->textHeight = tm.tmHeight + tm.tmExternalLeading;
1513 GetTextExtentPoint32A(hdc, "Sun", 3, &size);
1514 infoPtr->textWidth = size.cx + 2;
1516 /* retrieve the controls client rectangle info infoPtr->rcClient */
1517 GetClientRect(hwnd, rcClient);
1519 if(dwStyle & MCS_WEEKNUMBERS)
1520 infoPtr->rcClient.right+=infoPtr->textWidth;
1522 /* rcDraw is the rectangle the control is drawn in */
1523 rcDraw->left = rcClient->left;
1524 rcDraw->right = rcClient->right;
1525 rcDraw->top = rcClient->top;
1526 rcDraw->bottom = rcClient->bottom;
1528 /* this is correct, the control does NOT expand vertically */
1529 /* like it does horizontally */
1530 /* make sure we don't move the controls bottom out of the client */
1532 if((rcDraw->top + 8 * infoPtr->textHeight + 5) < rcDraw->bottom) {
1533 rcDraw->bottom = rcDraw->top + 8 * infoPtr->textHeight + 5;
1536 /* calculate title area */
1537 title->top = rcClient->top;
1538 title->bottom = title->top + 2 * infoPtr->textHeight + 4;
1539 title->left = rcClient->left;
1540 title->right = rcClient->right;
1542 /* recalculate the height and width increments and offsets */
1543 infoPtr->width_increment = (infoPtr->rcDraw.right - infoPtr->rcDraw.left) / 7.0;
1544 infoPtr->height_increment = (infoPtr->rcDraw.bottom - infoPtr->rcDraw.top) / 7.0;
1545 infoPtr->left_offset = (infoPtr->rcDraw.right - infoPtr->rcDraw.left) - (infoPtr->width_increment * 7.0);
1546 infoPtr->top_offset = (infoPtr->rcDraw.bottom - infoPtr->rcDraw.top) - (infoPtr->height_increment * 7.0);
1548 /* set the dimensions of the next and previous buttons and center */
1549 /* the month text vertically */
1550 prev->top = next->top = title->top + 6;
1551 prev->bottom = next->bottom = title->top + 2 * infoPtr->textHeight - 3;
1552 prev->right = title->left + 28;
1553 prev->left = title->left + 4;
1554 next->left = title->right - 28;
1555 next->right = title->right - 4;
1557 /* titlemonth->left and right change based upon the current month */
1558 /* and are recalculated in refresh as the current month may change */
1559 /* without the control being resized */
1560 titlemonth->bottom = titleyear->bottom = prev->top + 2 * infoPtr->textHeight - 3;
1561 titlemonth->top = titleyear->top = title->top;
1563 /* setup the dimensions of the rectangle we draw the names of the */
1564 /* days of the week in */
1565 days->left = infoPtr->left_offset;
1566 if(dwStyle & MCS_WEEKNUMBERS) days->left+=infoPtr->textWidth;
1567 days->right = days->left + infoPtr->width_increment;
1568 days->top = title->bottom + 2;
1569 days->bottom = title->bottom + infoPtr->textHeight + 2;
1571 /* restore the originally selected font */
1572 SelectObject(hdc, currentFont);
1574 ReleaseDC(hwnd, hdc);
1577 static LRESULT MONTHCAL_Size(HWND hwnd, int Width, int Height)
1579 TRACE("(hwnd=%x, width=%d, height=%d)\n", hwnd, Width, Height);
1581 MONTHCAL_UpdateSize(hwnd);
1583 /* invalidate client area and erase background */
1584 InvalidateRect(hwnd, NULL, TRUE);
1589 /* FIXME: check whether dateMin/dateMax need to be adjusted. */
1591 MONTHCAL_Create(HWND hwnd, WPARAM wParam, LPARAM lParam)
1593 MONTHCAL_INFO *infoPtr;
1596 /* allocate memory for info structure */
1597 infoPtr =(MONTHCAL_INFO*)COMCTL32_Alloc(sizeof(MONTHCAL_INFO));
1598 SetWindowLongA(hwnd, 0, (DWORD)infoPtr);
1600 if(infoPtr == NULL) {
1601 ERR( "could not allocate info memory!\n");
1604 if((MONTHCAL_INFO*)GetWindowLongA(hwnd, 0) != infoPtr) {
1605 ERR( "pointer assignment error!\n");
1609 infoPtr->hFont = GetStockObject(DEFAULT_GUI_FONT);
1610 GetObjectA(infoPtr->hFont, sizeof(LOGFONTA), &logFont);
1611 logFont.lfWeight = FW_BOLD;
1612 infoPtr->hBoldFont = CreateFontIndirectA(&logFont);
1614 /* initialize info structure */
1615 /* FIXME: calculate systemtime ->> localtime(substract timezoneinfo) */
1617 GetSystemTime(&infoPtr->todaysDate);
1618 infoPtr->firstDay = 0;
1619 infoPtr->currentMonth = infoPtr->todaysDate.wMonth;
1620 infoPtr->currentYear = infoPtr->todaysDate.wYear;
1621 MONTHCAL_CopyTime(&infoPtr->todaysDate, &infoPtr->minDate);
1622 MONTHCAL_CopyTime(&infoPtr->todaysDate, &infoPtr->maxDate);
1623 infoPtr->maxSelCount = 6;
1624 infoPtr->monthRange = 3;
1625 infoPtr->monthdayState = COMCTL32_Alloc
1626 (infoPtr->monthRange * sizeof(MONTHDAYSTATE));
1627 infoPtr->titlebk = GetSysColor(COLOR_ACTIVECAPTION);
1628 infoPtr->titletxt = GetSysColor(COLOR_WINDOW);
1629 infoPtr->monthbk = GetSysColor(COLOR_WINDOW);
1630 infoPtr->trailingtxt = GetSysColor(COLOR_GRAYTEXT);
1631 infoPtr->bk = GetSysColor(COLOR_WINDOW);
1632 infoPtr->txt = GetSysColor(COLOR_WINDOWTEXT);
1634 /* call MONTHCAL_UpdateSize to set all of the dimensions */
1635 /* of the control */
1636 MONTHCAL_UpdateSize(hwnd);
1643 MONTHCAL_Destroy(HWND hwnd, WPARAM wParam, LPARAM lParam)
1645 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
1647 /* free month calendar info data */
1648 COMCTL32_Free(infoPtr);
1649 SetWindowLongA(hwnd, 0, 0);
1654 static LRESULT WINAPI
1655 MONTHCAL_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1657 TRACE("hwnd=%x msg=%x wparam=%x lparam=%lx\n", hwnd, uMsg, wParam, lParam);
1658 if (!MONTHCAL_GetInfoPtr(hwnd) && (uMsg != WM_CREATE))
1659 return DefWindowProcA(hwnd, uMsg, wParam, lParam);
1663 return MONTHCAL_GetCurSel(hwnd, wParam, lParam);
1666 return MONTHCAL_SetCurSel(hwnd, wParam, lParam);
1668 case MCM_GETMAXSELCOUNT:
1669 return MONTHCAL_GetMaxSelCount(hwnd, wParam, lParam);
1671 case MCM_SETMAXSELCOUNT:
1672 return MONTHCAL_SetMaxSelCount(hwnd, wParam, lParam);
1674 case MCM_GETSELRANGE:
1675 return MONTHCAL_GetSelRange(hwnd, wParam, lParam);
1677 case MCM_SETSELRANGE:
1678 return MONTHCAL_SetSelRange(hwnd, wParam, lParam);
1680 case MCM_GETMONTHRANGE:
1681 return MONTHCAL_GetMonthRange(hwnd, wParam, lParam);
1683 case MCM_SETDAYSTATE:
1684 return MONTHCAL_SetDayState(hwnd, wParam, lParam);
1686 case MCM_GETMINREQRECT:
1687 return MONTHCAL_GetMinReqRect(hwnd, wParam, lParam);
1690 return MONTHCAL_GetColor(hwnd, wParam, lParam);
1693 return MONTHCAL_SetColor(hwnd, wParam, lParam);
1696 return MONTHCAL_GetToday(hwnd, wParam, lParam);
1699 return MONTHCAL_SetToday(hwnd, wParam, lParam);
1702 return MONTHCAL_HitTest(hwnd,lParam);
1704 case MCM_GETFIRSTDAYOFWEEK:
1705 return MONTHCAL_GetFirstDayOfWeek(hwnd, wParam, lParam);
1707 case MCM_SETFIRSTDAYOFWEEK:
1708 return MONTHCAL_SetFirstDayOfWeek(hwnd, wParam, lParam);
1711 return MONTHCAL_GetRange(hwnd, wParam, lParam);
1714 return MONTHCAL_SetRange(hwnd, wParam, lParam);
1716 case MCM_GETMONTHDELTA:
1717 return MONTHCAL_GetMonthDelta(hwnd, wParam, lParam);
1719 case MCM_SETMONTHDELTA:
1720 return MONTHCAL_SetMonthDelta(hwnd, wParam, lParam);
1722 case MCM_GETMAXTODAYWIDTH:
1723 return MONTHCAL_GetMaxTodayWidth(hwnd);
1726 return DLGC_WANTARROWS | DLGC_WANTCHARS;
1729 return MONTHCAL_KillFocus(hwnd, wParam, lParam);
1731 case WM_LBUTTONDOWN:
1732 return MONTHCAL_LButtonDown(hwnd, wParam, lParam);
1735 return MONTHCAL_MouseMove(hwnd, wParam, lParam);
1738 return MONTHCAL_LButtonUp(hwnd, wParam, lParam);
1741 return MONTHCAL_Paint(hwnd, wParam);
1744 return MONTHCAL_SetFocus(hwnd, wParam, lParam);
1747 return MONTHCAL_Size(hwnd, (int)SLOWORD(lParam), (int)SHIWORD(lParam));
1750 return MONTHCAL_Create(hwnd, wParam, lParam);
1753 return MONTHCAL_Timer(hwnd, wParam, lParam);
1756 return MONTHCAL_Destroy(hwnd, wParam, lParam);
1760 ERR( "unknown msg %04x wp=%08x lp=%08lx\n", uMsg, wParam, lParam);
1761 return DefWindowProcA(hwnd, uMsg, wParam, lParam);
1768 MONTHCAL_Register(void)
1772 ZeroMemory(&wndClass, sizeof(WNDCLASSA));
1773 wndClass.style = CS_GLOBALCLASS;
1774 wndClass.lpfnWndProc = (WNDPROC)MONTHCAL_WindowProc;
1775 wndClass.cbClsExtra = 0;
1776 wndClass.cbWndExtra = sizeof(MONTHCAL_INFO *);
1777 wndClass.hCursor = LoadCursorA(0, IDC_ARROWA);
1778 wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
1779 wndClass.lpszClassName = MONTHCAL_CLASSA;
1781 RegisterClassA(&wndClass);
1786 MONTHCAL_Unregister(void)
1788 UnregisterClassA(MONTHCAL_CLASSA, (HINSTANCE)NULL);