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(MONTHCAL_INFO
*infoPtr
, HDC hdc
, int day
, int month
)
284 HPEN hRedPen
= CreatePen(PS_SOLID
, 2, RGB(255, 0, 0));
285 HPEN hOldPen2
= SelectObject(hdc
, hRedPen
);
291 MONTHCAL_CalcPosFromDay(infoPtr
, day
, month
, &day_rect
);
298 points
[1].x
= x
+ 0.8 * infoPtr
->width_increment
;
300 points
[2].x
= x
+ 0.9 * infoPtr
->width_increment
;
302 points
[3].x
= x
+ infoPtr
->width_increment
;
303 points
[3].y
= y
+ 0.5 * infoPtr
->height_increment
;
305 points
[4].x
= x
+ infoPtr
->width_increment
;
306 points
[4].y
= y
+ 0.9 * infoPtr
->height_increment
;
307 points
[5].x
= x
+ 0.6 * infoPtr
->width_increment
;
308 points
[5].y
= y
+ 0.9 * infoPtr
->height_increment
;
309 points
[6].x
= x
+ 0.5 * infoPtr
->width_increment
;
310 points
[6].y
= y
+ 0.9 * infoPtr
->height_increment
; /* bring the bottom up just
311 a hair to fit inside the day rectangle */
313 points
[7].x
= x
+ 0.2 * infoPtr
->width_increment
;
314 points
[7].y
= y
+ 0.8 * infoPtr
->height_increment
;
315 points
[8].x
= x
+ 0.1 * infoPtr
->width_increment
;
316 points
[8].y
= y
+ 0.8 * infoPtr
->height_increment
;
318 points
[9].y
= y
+ 0.5 * infoPtr
->height_increment
;
320 points
[10].x
= x
+ 0.1 * infoPtr
->width_increment
;
321 points
[10].y
= y
+ 0.2 * infoPtr
->height_increment
;
322 points
[11].x
= x
+ 0.2 * infoPtr
->width_increment
;
323 points
[11].y
= y
+ 0.3 * infoPtr
->height_increment
;
324 points
[12].x
= x
+ 0.4 * infoPtr
->width_increment
;
325 points
[12].y
= y
+ 0.2 * infoPtr
->height_increment
;
327 PolyBezier(hdc
, points
, 13);
328 DeleteObject(hRedPen
);
329 SelectObject(hdc
, hOldPen2
);
333 static void MONTHCAL_DrawDay(MONTHCAL_INFO
*infoPtr
, HDC hdc
, int day
, int month
,
334 int x
, int y
, int bold
)
338 static int haveBoldFont
, haveSelectedDay
= FALSE
;
343 sprintf(buf
, "%d", day
);
345 /* No need to check styles: when selection is not valid, it is set to zero.
346 * 1<day<31, so evertyhing's OK.
349 MONTHCAL_CalcDayRect(infoPtr
, &r
, x
, y
);
351 if((day
>=infoPtr
->minSel
.wDay
) && (day
<=infoPtr
->maxSel
.wDay
)
352 && (month
==infoPtr
->currentMonth
)) {
356 TRACE("%d %d %d\n",day
, infoPtr
->minSel
.wDay
, infoPtr
->maxSel
.wDay
);
357 TRACE("%ld %ld %ld %ld\n", r
.left
, r
.top
, r
.right
, r
.bottom
);
358 oldCol
= SetTextColor(hdc
, infoPtr
->monthbk
);
359 oldBk
= SetBkColor(hdc
, infoPtr
->trailingtxt
);
360 hbr
= GetSysColorBrush(COLOR_GRAYTEXT
);
361 hrgn
= CreateEllipticRgn(r
.left
, r
.top
, r
.right
, r
.bottom
);
362 FillRgn(hdc
, hrgn
, hbr
);
364 /* FIXME: this may need to be changed now b/c of the other
365 drawing changes 11/3/99 CMM */
366 r2
.left
= r
.left
- 0.25 * infoPtr
->textWidth
;
368 r2
.right
= r
.left
+ 0.5 * infoPtr
->textWidth
;
369 r2
.bottom
= r
.bottom
;
370 if(haveSelectedDay
) FillRect(hdc
, &r2
, hbr
);
371 haveSelectedDay
= TRUE
;
373 haveSelectedDay
= FALSE
;
376 /* need to add some code for multiple selections */
378 if((bold
) &&(!haveBoldFont
)) {
379 SelectObject(hdc
, infoPtr
->hBoldFont
);
382 if((!bold
) &&(haveBoldFont
)) {
383 SelectObject(hdc
, infoPtr
->hFont
);
384 haveBoldFont
= FALSE
;
387 if(haveSelectedDay
) {
388 SetTextColor(hdc
, oldCol
);
389 SetBkColor(hdc
, oldBk
);
392 SetBkMode(hdc
,TRANSPARENT
);
393 DrawTextA(hdc
, buf
, -1, &r
, DT_CENTER
| DT_VCENTER
| DT_SINGLELINE
);
395 /* draw a rectangle around the currently selected days text */
396 if((day
==infoPtr
->curSelDay
) && (month
==infoPtr
->currentMonth
))
397 DrawFocusRect(hdc
, &r
);
401 static void MONTHCAL_Refresh(MONTHCAL_INFO
*infoPtr
, HDC hdc
, PAINTSTRUCT
* ps
)
403 RECT
*title
=&infoPtr
->title
;
404 RECT
*prev
=&infoPtr
->titlebtnprev
;
405 RECT
*next
=&infoPtr
->titlebtnnext
;
406 RECT
*titlemonth
=&infoPtr
->titlemonth
;
407 RECT
*titleyear
=&infoPtr
->titleyear
;
411 int i
, j
, m
, mask
, day
, firstDay
, weeknum
, weeknum1
,prevMonth
;
412 int textHeight
= infoPtr
->textHeight
, textWidth
= infoPtr
->textWidth
;
419 COLORREF oldTextColor
, oldBkColor
;
420 DWORD dwStyle
= GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
);
422 RECT rcDay
; /* used in MONTHCAL_CalcDayRect() */
423 SYSTEMTIME localtime
;
426 oldTextColor
= SetTextColor(hdc
, GetSysColor(COLOR_WINDOWTEXT
));
428 /* fill background */
429 hbr
= CreateSolidBrush (infoPtr
->bk
);
430 FillRect(hdc
, &ps
->rcPaint
, hbr
);
434 if(IntersectRect(&rcTemp
, &(ps
->rcPaint
), title
))
436 hbr
= CreateSolidBrush(infoPtr
->titlebk
);
437 FillRect(hdc
, title
, hbr
);
441 /* if the previous button is pressed draw it depressed */
442 if(IntersectRect(&rcTemp
, &(ps
->rcPaint
), prev
))
444 if((infoPtr
->status
& MC_PREVPRESSED
))
445 DrawFrameControl(hdc
, prev
, DFC_SCROLL
,
446 DFCS_SCROLLLEFT
| DFCS_PUSHED
|
447 (dwStyle
& WS_DISABLED
? DFCS_INACTIVE
: 0));
448 else /* if the previous button is pressed draw it depressed */
449 DrawFrameControl(hdc
, prev
, DFC_SCROLL
,
450 DFCS_SCROLLLEFT
|(dwStyle
& WS_DISABLED
? DFCS_INACTIVE
: 0));
453 /* if next button is depressed draw it depressed */
454 if(IntersectRect(&rcTemp
, &(ps
->rcPaint
), next
))
456 if((infoPtr
->status
& MC_NEXTPRESSED
))
457 DrawFrameControl(hdc
, next
, DFC_SCROLL
,
458 DFCS_SCROLLRIGHT
| DFCS_PUSHED
|
459 (dwStyle
& WS_DISABLED
? DFCS_INACTIVE
: 0));
460 else /* if the next button is pressed draw it depressed */
461 DrawFrameControl(hdc
, next
, DFC_SCROLL
,
462 DFCS_SCROLLRIGHT
|(dwStyle
& WS_DISABLED
? DFCS_INACTIVE
: 0));
465 oldBkColor
= SetBkColor(hdc
, infoPtr
->titlebk
);
466 SetTextColor(hdc
, infoPtr
->titletxt
);
467 currentFont
= SelectObject(hdc
, infoPtr
->hBoldFont
);
469 /* titlemonth->left and right are set in MONTHCAL_UpdateSize */
470 titlemonth
->left
= title
->left
;
471 titlemonth
->right
= title
->right
;
473 GetLocaleInfoA( LOCALE_USER_DEFAULT
,LOCALE_SMONTHNAME1
+infoPtr
->currentMonth
-1,
475 sprintf(buf
, "%s %ld", buf1
, infoPtr
->currentYear
);
477 if(IntersectRect(&rcTemp
, &(ps
->rcPaint
), titlemonth
))
479 DrawTextA(hdc
, buf
, strlen(buf
), titlemonth
,
480 DT_CENTER
| DT_VCENTER
| DT_SINGLELINE
);
483 SelectObject(hdc
, infoPtr
->hFont
);
485 /* titlemonth left/right contained rect for whole titletxt('June 1999')
486 * MCM_HitTestInfo wants month & year rects, so prepare these now.
487 *(no, we can't draw them separately; the whole text is centered)
489 GetTextExtentPoint32A(hdc
, buf
, strlen(buf
), &size
);
490 titlemonth
->left
= title
->right
/ 2 - size
.cx
/ 2;
491 titleyear
->right
= title
->right
/ 2 + size
.cx
/ 2;
492 GetTextExtentPoint32A(hdc
, buf1
, strlen(buf1
), &size
);
493 titlemonth
->right
= titlemonth
->left
+ size
.cx
;
494 titleyear
->left
= titlemonth
->right
;
496 /* draw month area */
497 rcTemp
.top
=infoPtr
->wdays
.top
;
498 rcTemp
.left
=infoPtr
->wdays
.left
;
499 rcTemp
.bottom
=infoPtr
->todayrect
.bottom
;
500 rcTemp
.right
=infoPtr
->todayrect
.right
;
501 if(IntersectRect(&rcTemp
, &(ps
->rcPaint
), &rcTemp
))
503 hbr
= CreateSolidBrush(infoPtr
->monthbk
);
504 FillRect(hdc
, &rcTemp
, hbr
);
508 /* draw line under day abbreviatons */
510 MoveToEx(hdc
, infoPtr
->days
.left
+ 3, title
->bottom
+ textHeight
+ 1, NULL
);
511 LineTo(hdc
, infoPtr
->days
.right
- 3, title
->bottom
+ textHeight
+ 1);
513 prevMonth
= infoPtr
->currentMonth
- 1;
514 if(prevMonth
== 0) /* if currentMonth is january(1) prevMonth is */
515 prevMonth
= 12; /* december(12) of the previous year */
517 infoPtr
->wdays
.left
= infoPtr
->days
.left
= infoPtr
->weeknums
.right
;
518 /* draw day abbreviations */
520 SetBkColor(hdc
, infoPtr
->monthbk
);
521 SetTextColor(hdc
, infoPtr
->trailingtxt
);
523 /* copy this rect so we can change the values without changing */
524 /* the original version */
525 days
->left
= infoPtr
->wdays
.left
;
526 days
->right
= days
->left
+ infoPtr
->width_increment
;
527 days
->top
= infoPtr
->wdays
.top
;
528 days
->bottom
= infoPtr
->wdays
.bottom
;
530 i
= infoPtr
->firstDay
;
533 GetLocaleInfoA( LOCALE_USER_DEFAULT
,LOCALE_SABBREVDAYNAME1
+ (i
+j
)%7,
535 DrawTextA(hdc
, buf
, strlen(buf
), days
,
536 DT_CENTER
| DT_VCENTER
| DT_SINGLELINE
);
537 days
->left
+=infoPtr
->width_increment
;
538 days
->right
+=infoPtr
->width_increment
;
541 /* draw day numbers; first, the previous month */
543 firstDay
= MONTHCAL_CalculateDayOfWeek(1, infoPtr
->currentMonth
, infoPtr
->currentYear
);
545 day
= MONTHCAL_MonthLength(prevMonth
, infoPtr
->currentYear
) +
546 (infoPtr
->firstDay
+ 7 - firstDay
)%7 + 1;
547 if (day
> MONTHCAL_MonthLength(prevMonth
, infoPtr
->currentYear
))
549 startofprescal
= day
;
554 while(day
<= MONTHCAL_MonthLength(prevMonth
, infoPtr
->currentYear
)) {
555 MONTHCAL_CalcDayRect(infoPtr
, &rcDay
, i
, 0);
556 if(IntersectRect(&rcTemp
, &(ps
->rcPaint
), &rcDay
))
558 MONTHCAL_DrawDay(infoPtr
, hdc
, day
, prevMonth
, i
, 0,
559 infoPtr
->monthdayState
[m
] & mask
);
567 /* draw `current' month */
569 day
= 1; /* start at the beginning of the current month */
571 infoPtr
->firstDayplace
= i
;
572 SetTextColor(hdc
, infoPtr
->txt
);
576 /* draw the first week of the current month */
578 MONTHCAL_CalcDayRect(infoPtr
, &rcDay
, i
, 0);
579 if(IntersectRect(&rcTemp
, &(ps
->rcPaint
), &rcDay
))
582 MONTHCAL_DrawDay(infoPtr
, hdc
, day
, infoPtr
->currentMonth
, i
, 0,
583 infoPtr
->monthdayState
[m
] & mask
);
585 if((infoPtr
->currentMonth
==infoPtr
->todaysDate
.wMonth
) &&
586 (day
==infoPtr
->todaysDate
.wDay
) &&
587 (infoPtr
->currentYear
== infoPtr
->todaysDate
.wYear
)) {
588 if(!(dwStyle
& MCS_NOTODAYCIRCLE
))
589 MONTHCAL_CircleDay(infoPtr
, hdc
, day
, infoPtr
->currentMonth
);
598 j
= 1; /* move to the 2nd week of the current month */
599 i
= 0; /* move back to sunday */
600 while(day
<= MONTHCAL_MonthLength(infoPtr
->currentMonth
, infoPtr
->currentYear
)) {
601 MONTHCAL_CalcDayRect(infoPtr
, &rcDay
, i
, j
);
602 if(IntersectRect(&rcTemp
, &(ps
->rcPaint
), &rcDay
))
604 MONTHCAL_DrawDay(infoPtr
, hdc
, day
, infoPtr
->currentMonth
, i
, j
,
605 infoPtr
->monthdayState
[m
] & mask
);
607 if((infoPtr
->currentMonth
==infoPtr
->todaysDate
.wMonth
) &&
608 (day
==infoPtr
->todaysDate
.wDay
) &&
609 (infoPtr
->currentYear
== infoPtr
->todaysDate
.wYear
))
610 if(!(dwStyle
& MCS_NOTODAYCIRCLE
))
611 MONTHCAL_CircleDay(infoPtr
, hdc
, day
, infoPtr
->currentMonth
);
616 if(i
>6) { /* past saturday, goto the next weeks sunday */
622 /* draw `next' month */
624 day
= 1; /* start at the first day of the next month */
628 SetTextColor(hdc
, infoPtr
->trailingtxt
);
629 while((i
<7) &&(j
<6)) {
630 MONTHCAL_CalcDayRect(infoPtr
, &rcDay
, i
, j
);
631 if(IntersectRect(&rcTemp
, &(ps
->rcPaint
), &rcDay
))
633 MONTHCAL_DrawDay(infoPtr
, hdc
, day
, infoPtr
->currentMonth
+ 1, i
, j
,
634 infoPtr
->monthdayState
[m
] & mask
);
640 if(i
==7) { /* past saturday, go to next week's sunday */
645 SetTextColor(hdc
, infoPtr
->txt
);
648 /* draw `today' date if style allows it, and draw a circle before today's
649 * date if necessary */
651 if(!(dwStyle
& MCS_NOTODAY
)) {
653 if(!(dwStyle
& MCS_NOTODAYCIRCLE
)) {
654 /*day is the number of days from nextmonth we put on the calendar */
655 MONTHCAL_CircleDay(infoPtr
, hdc
,
656 day
+MONTHCAL_MonthLength(infoPtr
->currentMonth
,infoPtr
->currentYear
),
657 infoPtr
->currentMonth
);
660 if (!LoadStringA(COMCTL32_hModule
,IDM_TODAY
,buf1
,sizeof(buf1
)))
662 WARN("Can't load resource\n");
663 strcpy(buf1
,"Today:");
665 MONTHCAL_CalcDayRect(infoPtr
, &rtoday
, 1, 6);
666 MONTHCAL_CopyTime(&infoPtr
->todaysDate
,&localtime
);
667 GetDateFormatA(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
,&localtime
,NULL
,buf2
,sizeof(buf2
));
668 sprintf(buf
, "%s %s", buf1
,buf2
);
669 SelectObject(hdc
, infoPtr
->hBoldFont
);
671 if(IntersectRect(&rcTemp
, &(ps
->rcPaint
), &rtoday
))
673 DrawTextA(hdc
, buf
, -1, &rtoday
, DT_CALCRECT
| DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
);
674 DrawTextA(hdc
, buf
, -1, &rtoday
, DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
);
676 SelectObject(hdc
, infoPtr
->hFont
);
679 /*eventually draw week numbers*/
680 if(dwStyle
& MCS_WEEKNUMBERS
) {
681 /* display weeknumbers*/
684 /* Rules what week to call the first week of a new year:
685 LOCALE_IFIRSTWEEKOFYEAR == 0 (e.g US?):
686 The week containing Jan 1 is the first week of year
687 LOCALE_IFIRSTWEEKOFYEAR == 2 (e.g. Germany):
688 First week of year must contain 4 days of the new year
689 LOCALE_IFIRSTWEEKOFYEAR == 1 (what contries?)
690 The first week of the year must contain only days of the new year
692 GetLocaleInfoA(LOCALE_USER_DEFAULT
, LOCALE_IFIRSTWEEKOFYEAR
,
694 sscanf(buf
, "%d", &weeknum
);
705 if (infoPtr
->currentMonth
< 2)
707 /* calculate all those exceptions for january */
708 weeknum1
=MONTHCAL_CalculateDayOfWeek(1,1,infoPtr
->currentYear
);
709 if ((infoPtr
->firstDay
+7 - weeknum1
)%7 > mindays
)
715 weeknum
+=MONTHCAL_MonthLength(i
+1, infoPtr
->currentYear
-1);
716 weeknum
+=startofprescal
+ 7;
718 weeknum1
=MONTHCAL_CalculateDayOfWeek(1,1,infoPtr
->currentYear
-1);
719 if ((infoPtr
->firstDay
+ 7 - weeknum1
)%7 > mindays
)
726 for(i
=0; i
<prevMonth
-1; i
++)
727 weeknum
+=MONTHCAL_MonthLength(i
+1, infoPtr
->currentYear
);
728 weeknum
+=startofprescal
+ 7;
730 weeknum1
=MONTHCAL_CalculateDayOfWeek(1,1,infoPtr
->currentYear
);
731 if ((infoPtr
->firstDay
+ 7 - weeknum1
)%7 > mindays
)
734 days
->left
= infoPtr
->weeknums
.left
;
735 days
->right
= infoPtr
->weeknums
.right
;
736 days
->top
= infoPtr
->weeknums
.top
;
737 days
->bottom
= days
->top
+infoPtr
->height_increment
;
739 if((i
==0)&&(weeknum
>50))
741 sprintf(buf
, "%d", weeknum
);
744 else if((i
==5)&&(weeknum
>47))
746 sprintf(buf
, "%d", 1);
749 sprintf(buf
, "%d", weeknum
+ i
);
750 DrawTextA(hdc
, buf
, -1, days
, DT_CENTER
| DT_VCENTER
| DT_SINGLELINE
);
751 days
->top
+=infoPtr
->height_increment
;
752 days
->bottom
+=infoPtr
->height_increment
;
755 MoveToEx(hdc
, infoPtr
->weeknums
.right
, infoPtr
->weeknums
.top
+ 3 , NULL
);
756 LineTo(hdc
, infoPtr
->weeknums
.right
, infoPtr
->weeknums
.bottom
);
759 /* currentFont was font at entering Refresh */
761 SetBkColor(hdc
, oldBkColor
);
762 SelectObject(hdc
, currentFont
);
763 SetTextColor(hdc
, oldTextColor
);
768 MONTHCAL_GetMinReqRect(MONTHCAL_INFO
*infoPtr
, LPARAM lParam
)
770 LPRECT lpRect
= (LPRECT
) lParam
;
772 TRACE("rect %p\n", lpRect
);
774 /* validate parameters */
776 if((infoPtr
==NULL
) ||(lpRect
== NULL
) ) return FALSE
;
778 lpRect
->left
= infoPtr
->title
.left
;
779 lpRect
->top
= infoPtr
->title
.top
;
780 lpRect
->right
= infoPtr
->title
.right
;
781 lpRect
->bottom
= infoPtr
->todayrect
.bottom
;
782 AdjustWindowRect(lpRect
, GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
), FALSE
);
784 TRACE("%s\n", wine_dbgstr_rect(lpRect
));
791 MONTHCAL_GetColor(MONTHCAL_INFO
*infoPtr
, WPARAM wParam
)
795 switch((int)wParam
) {
796 case MCSC_BACKGROUND
:
801 return infoPtr
->titlebk
;
803 return infoPtr
->titletxt
;
805 return infoPtr
->monthbk
;
806 case MCSC_TRAILINGTEXT
:
807 return infoPtr
->trailingtxt
;
815 MONTHCAL_SetColor(MONTHCAL_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
819 TRACE("%d: color %08lx\n", wParam
, lParam
);
821 switch((int)wParam
) {
822 case MCSC_BACKGROUND
:
824 infoPtr
->bk
= (COLORREF
)lParam
;
828 infoPtr
->txt
= (COLORREF
)lParam
;
831 prev
= infoPtr
->titlebk
;
832 infoPtr
->titlebk
= (COLORREF
)lParam
;
835 prev
=infoPtr
->titletxt
;
836 infoPtr
->titletxt
= (COLORREF
)lParam
;
839 prev
= infoPtr
->monthbk
;
840 infoPtr
->monthbk
= (COLORREF
)lParam
;
842 case MCSC_TRAILINGTEXT
:
843 prev
= infoPtr
->trailingtxt
;
844 infoPtr
->trailingtxt
= (COLORREF
)lParam
;
848 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
854 MONTHCAL_GetMonthDelta(MONTHCAL_INFO
*infoPtr
)
859 return infoPtr
->delta
;
861 return infoPtr
->visible
;
866 MONTHCAL_SetMonthDelta(MONTHCAL_INFO
*infoPtr
, WPARAM wParam
)
868 int prev
= infoPtr
->delta
;
870 TRACE("delta %d\n", wParam
);
872 infoPtr
->delta
= (int)wParam
;
878 MONTHCAL_GetFirstDayOfWeek(MONTHCAL_INFO
*infoPtr
)
880 return infoPtr
->firstDay
;
884 /* sets the first day of the week that will appear in the control */
885 /* 0 == Monday, 6 == Sunday */
886 /* FIXME: this needs to be implemented properly in MONTHCAL_Refresh() */
887 /* FIXME: we need more error checking here */
889 MONTHCAL_SetFirstDayOfWeek(MONTHCAL_INFO
*infoPtr
, LPARAM lParam
)
891 int prev
= infoPtr
->firstDay
;
895 TRACE("day %ld\n", lParam
);
897 if((lParam
>= 0) && (lParam
< 7)) {
898 infoPtr
->firstDay
= (int)lParam
;
902 GetLocaleInfoA(LOCALE_USER_DEFAULT
, LOCALE_IFIRSTDAYOFWEEK
,
904 TRACE("%s %d\n", buf
, strlen(buf
));
905 if(sscanf(buf
, "%d", &day
) == 1)
906 infoPtr
->firstDay
= day
;
908 infoPtr
->firstDay
= 0;
915 MONTHCAL_GetMonthRange(MONTHCAL_INFO
*infoPtr
)
919 return infoPtr
->monthRange
;
924 MONTHCAL_GetMaxTodayWidth(MONTHCAL_INFO
*infoPtr
)
926 return(infoPtr
->todayrect
.right
- infoPtr
->todayrect
.left
);
930 /* FIXME: are validated times taken from current date/time or simply
932 * FIXME: check whether MCM_GETMONTHRANGE shows correct result after
933 * adjusting range with MCM_SETRANGE
937 MONTHCAL_SetRange(MONTHCAL_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
939 SYSTEMTIME
*lprgSysTimeArray
=(SYSTEMTIME
*)lParam
;
942 TRACE("%x %lx\n", wParam
, lParam
);
944 if(wParam
& GDTR_MAX
) {
945 if(MONTHCAL_ValidateTime(lprgSysTimeArray
[1])){
946 MONTHCAL_CopyTime(&lprgSysTimeArray
[1], &infoPtr
->maxDate
);
947 infoPtr
->rangeValid
|=GDTR_MAX
;
949 GetSystemTime(&infoPtr
->todaysDate
);
950 MONTHCAL_CopyTime(&infoPtr
->todaysDate
, &infoPtr
->maxDate
);
953 if(wParam
& GDTR_MIN
) {
954 if(MONTHCAL_ValidateTime(lprgSysTimeArray
[0])) {
955 MONTHCAL_CopyTime(&lprgSysTimeArray
[0], &infoPtr
->minDate
);
956 infoPtr
->rangeValid
|=GDTR_MIN
;
958 GetSystemTime(&infoPtr
->todaysDate
);
959 MONTHCAL_CopyTime(&infoPtr
->todaysDate
, &infoPtr
->minDate
);
963 prev
= infoPtr
->monthRange
;
964 infoPtr
->monthRange
= infoPtr
->maxDate
.wMonth
- infoPtr
->minDate
.wMonth
;
966 if(infoPtr
->monthRange
!=prev
) {
967 infoPtr
->monthdayState
= ReAlloc(infoPtr
->monthdayState
,
968 infoPtr
->monthRange
* sizeof(MONTHDAYSTATE
));
976 MONTHCAL_GetRange(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
978 MONTHCAL_INFO
*infoPtr
= MONTHCAL_GetInfoPtr(hwnd
);
979 SYSTEMTIME
*lprgSysTimeArray
= (SYSTEMTIME
*)lParam
;
981 /* validate parameters */
983 if((infoPtr
==NULL
) || (lprgSysTimeArray
==NULL
)) return FALSE
;
985 MONTHCAL_CopyTime(&infoPtr
->maxDate
, &lprgSysTimeArray
[1]);
986 MONTHCAL_CopyTime(&infoPtr
->minDate
, &lprgSysTimeArray
[0]);
988 return infoPtr
->rangeValid
;
993 MONTHCAL_SetDayState(MONTHCAL_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
996 int i
, iMonths
= (int)wParam
;
997 MONTHDAYSTATE
*dayStates
= (LPMONTHDAYSTATE
)lParam
;
999 TRACE("%x %lx\n", wParam
, lParam
);
1000 if(iMonths
!=infoPtr
->monthRange
) return 0;
1002 for(i
=0; i
<iMonths
; i
++)
1003 infoPtr
->monthdayState
[i
] = dayStates
[i
];
1008 MONTHCAL_GetCurSel(MONTHCAL_INFO
*infoPtr
, LPARAM lParam
)
1010 SYSTEMTIME
*lpSel
= (SYSTEMTIME
*) lParam
;
1012 TRACE("%lx\n", lParam
);
1013 if((infoPtr
==NULL
) ||(lpSel
==NULL
)) return FALSE
;
1014 if(GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
) & MCS_MULTISELECT
) return FALSE
;
1016 MONTHCAL_CopyTime(&infoPtr
->minSel
, lpSel
);
1017 TRACE("%d/%d/%d\n", lpSel
->wYear
, lpSel
->wMonth
, lpSel
->wDay
);
1021 /* FIXME: if the specified date is not visible, make it visible */
1022 /* FIXME: redraw? */
1024 MONTHCAL_SetCurSel(MONTHCAL_INFO
*infoPtr
, LPARAM lParam
)
1026 SYSTEMTIME
*lpSel
= (SYSTEMTIME
*)lParam
;
1028 TRACE("%lx\n", lParam
);
1029 if((infoPtr
==NULL
) ||(lpSel
==NULL
)) return FALSE
;
1030 if(GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
) & MCS_MULTISELECT
) return FALSE
;
1032 infoPtr
->currentMonth
=lpSel
->wMonth
;
1033 infoPtr
->currentYear
=lpSel
->wYear
;
1035 MONTHCAL_CopyTime(lpSel
, &infoPtr
->minSel
);
1036 MONTHCAL_CopyTime(lpSel
, &infoPtr
->maxSel
);
1038 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1045 MONTHCAL_GetMaxSelCount(MONTHCAL_INFO
*infoPtr
)
1047 return infoPtr
->maxSelCount
;
1052 MONTHCAL_SetMaxSelCount(MONTHCAL_INFO
*infoPtr
, WPARAM wParam
)
1054 TRACE("%x\n", wParam
);
1056 if(GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
) & MCS_MULTISELECT
) {
1057 infoPtr
->maxSelCount
= wParam
;
1065 MONTHCAL_GetSelRange(MONTHCAL_INFO
*infoPtr
, LPARAM lParam
)
1067 SYSTEMTIME
*lprgSysTimeArray
= (SYSTEMTIME
*) lParam
;
1069 TRACE("%lx\n", lParam
);
1071 /* validate parameters */
1073 if((infoPtr
==NULL
) ||(lprgSysTimeArray
==NULL
)) return FALSE
;
1075 if(GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
) & MCS_MULTISELECT
)
1077 MONTHCAL_CopyTime(&infoPtr
->maxSel
, &lprgSysTimeArray
[1]);
1078 MONTHCAL_CopyTime(&infoPtr
->minSel
, &lprgSysTimeArray
[0]);
1079 TRACE("[min,max]=[%d %d]\n", infoPtr
->minSel
.wDay
, infoPtr
->maxSel
.wDay
);
1088 MONTHCAL_SetSelRange(MONTHCAL_INFO
*infoPtr
, LPARAM lParam
)
1090 SYSTEMTIME
*lprgSysTimeArray
= (SYSTEMTIME
*) lParam
;
1092 TRACE("%lx\n", lParam
);
1094 /* validate parameters */
1096 if((infoPtr
==NULL
) ||(lprgSysTimeArray
==NULL
)) return FALSE
;
1098 if(GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
) & MCS_MULTISELECT
)
1100 MONTHCAL_CopyTime(&lprgSysTimeArray
[1], &infoPtr
->maxSel
);
1101 MONTHCAL_CopyTime(&lprgSysTimeArray
[0], &infoPtr
->minSel
);
1102 TRACE("[min,max]=[%d %d]\n", infoPtr
->minSel
.wDay
, infoPtr
->maxSel
.wDay
);
1111 MONTHCAL_GetToday(MONTHCAL_INFO
*infoPtr
, LPARAM lParam
)
1113 SYSTEMTIME
*lpToday
= (SYSTEMTIME
*) lParam
;
1115 TRACE("%lx\n", lParam
);
1117 /* validate parameters */
1119 if((infoPtr
==NULL
) || (lpToday
==NULL
)) return FALSE
;
1120 MONTHCAL_CopyTime(&infoPtr
->todaysDate
, lpToday
);
1126 MONTHCAL_SetToday(MONTHCAL_INFO
*infoPtr
, LPARAM lParam
)
1128 SYSTEMTIME
*lpToday
= (SYSTEMTIME
*) lParam
;
1130 TRACE("%lx\n", lParam
);
1132 /* validate parameters */
1134 if((infoPtr
==NULL
) ||(lpToday
==NULL
)) return FALSE
;
1135 MONTHCAL_CopyTime(lpToday
, &infoPtr
->todaysDate
);
1136 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1142 MONTHCAL_HitTest(MONTHCAL_INFO
*infoPtr
, LPARAM lParam
)
1144 PMCHITTESTINFO lpht
= (PMCHITTESTINFO
)lParam
;
1152 retval
= MCHT_NOWHERE
;
1155 /* Comment in for debugging...
1156 TRACE("%d %d wd[%d %d %d %d] d[%d %d %d %d] t[%d %d %d %d] wn[%d %d %d %d]\n", x, y,
1157 infoPtr->wdays.left, infoPtr->wdays.right,
1158 infoPtr->wdays.top, infoPtr->wdays.bottom,
1159 infoPtr->days.left, infoPtr->days.right,
1160 infoPtr->days.top, infoPtr->days.bottom,
1161 infoPtr->todayrect.left, infoPtr->todayrect.right,
1162 infoPtr->todayrect.top, infoPtr->todayrect.bottom,
1163 infoPtr->weeknums.left, infoPtr->weeknums.right,
1164 infoPtr->weeknums.top, infoPtr->weeknums.bottom);
1167 /* are we in the header? */
1169 if(PtInRect(&infoPtr
->title
, lpht
->pt
)) {
1170 if(PtInRect(&infoPtr
->titlebtnprev
, lpht
->pt
)) {
1171 retval
= MCHT_TITLEBTNPREV
;
1174 if(PtInRect(&infoPtr
->titlebtnnext
, lpht
->pt
)) {
1175 retval
= MCHT_TITLEBTNNEXT
;
1178 if(PtInRect(&infoPtr
->titlemonth
, lpht
->pt
)) {
1179 retval
= MCHT_TITLEMONTH
;
1182 if(PtInRect(&infoPtr
->titleyear
, lpht
->pt
)) {
1183 retval
= MCHT_TITLEYEAR
;
1187 retval
= MCHT_TITLE
;
1191 day
= MONTHCAL_CalcDayFromPos(infoPtr
,x
,y
,&wday
,&wnum
);
1192 if(PtInRect(&infoPtr
->wdays
, lpht
->pt
)) {
1193 retval
= MCHT_CALENDARDAY
;
1194 lpht
->st
.wYear
= infoPtr
->currentYear
;
1195 lpht
->st
.wMonth
= (day
< 1)? infoPtr
->currentMonth
-1 : infoPtr
->currentMonth
;
1196 lpht
->st
.wDay
= (day
< 1)?
1197 MONTHCAL_MonthLength(infoPtr
->currentMonth
-1,infoPtr
->currentYear
) -day
: day
;
1200 if(PtInRect(&infoPtr
->weeknums
, lpht
->pt
)) {
1201 retval
= MCHT_CALENDARWEEKNUM
;
1202 lpht
->st
.wYear
= infoPtr
->currentYear
;
1203 lpht
->st
.wMonth
= (day
< 1) ? infoPtr
->currentMonth
-1 :
1204 (day
> MONTHCAL_MonthLength(infoPtr
->currentMonth
,infoPtr
->currentYear
)) ?
1205 infoPtr
->currentMonth
+1 :infoPtr
->currentMonth
;
1206 lpht
->st
.wDay
= (day
< 1 ) ?
1207 MONTHCAL_MonthLength(infoPtr
->currentMonth
-1,infoPtr
->currentYear
) -day
:
1208 (day
> MONTHCAL_MonthLength(infoPtr
->currentMonth
,infoPtr
->currentYear
)) ?
1209 day
- MONTHCAL_MonthLength(infoPtr
->currentMonth
,infoPtr
->currentYear
) : day
;
1212 if(PtInRect(&infoPtr
->days
, lpht
->pt
))
1214 lpht
->st
.wYear
= infoPtr
->currentYear
;
1217 retval
= MCHT_CALENDARDATEPREV
;
1218 lpht
->st
.wMonth
= infoPtr
->currentMonth
- 1;
1219 if (lpht
->st
.wMonth
<1)
1221 lpht
->st
.wMonth
= 12;
1224 lpht
->st
.wDay
= MONTHCAL_MonthLength(lpht
->st
.wMonth
,lpht
->st
.wYear
) -day
;
1226 else if (day
> MONTHCAL_MonthLength(infoPtr
->currentMonth
,infoPtr
->currentYear
))
1228 retval
= MCHT_CALENDARDATENEXT
;
1229 lpht
->st
.wMonth
= infoPtr
->currentMonth
+ 1;
1230 if (lpht
->st
.wMonth
<12)
1232 lpht
->st
.wMonth
= 1;
1235 lpht
->st
.wDay
= day
- MONTHCAL_MonthLength(infoPtr
->currentMonth
,infoPtr
->currentYear
) ;
1238 retval
= MCHT_CALENDARDATE
;
1239 lpht
->st
.wMonth
= infoPtr
->currentMonth
;
1240 lpht
->st
.wDay
= day
;
1244 if(PtInRect(&infoPtr
->todayrect
, lpht
->pt
)) {
1245 retval
= MCHT_TODAYLINK
;
1250 /* Hit nothing special? What's left must be background :-) */
1252 retval
= MCHT_CALENDARBK
;
1254 lpht
->uHit
= retval
;
1259 static void MONTHCAL_GoToNextMonth(MONTHCAL_INFO
*infoPtr
)
1261 DWORD dwStyle
= GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
);
1263 TRACE("MONTHCAL_GoToNextMonth\n");
1265 infoPtr
->currentMonth
++;
1266 if(infoPtr
->currentMonth
> 12) {
1267 infoPtr
->currentYear
++;
1268 infoPtr
->currentMonth
= 1;
1271 if(dwStyle
& MCS_DAYSTATE
) {
1275 nmds
.nmhdr
.hwndFrom
= infoPtr
->hwndSelf
;
1276 nmds
.nmhdr
.idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1277 nmds
.nmhdr
.code
= MCN_GETDAYSTATE
;
1278 nmds
.cDayState
= infoPtr
->monthRange
;
1279 nmds
.prgDayState
= Alloc(infoPtr
->monthRange
* sizeof(MONTHDAYSTATE
));
1281 SendMessageA(infoPtr
->hwndNotify
, WM_NOTIFY
,
1282 (WPARAM
)nmds
.nmhdr
.idFrom
, (LPARAM
)&nmds
);
1283 for(i
=0; i
<infoPtr
->monthRange
; i
++)
1284 infoPtr
->monthdayState
[i
] = nmds
.prgDayState
[i
];
1289 static void MONTHCAL_GoToPrevMonth(MONTHCAL_INFO
*infoPtr
)
1291 DWORD dwStyle
= GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
);
1295 infoPtr
->currentMonth
--;
1296 if(infoPtr
->currentMonth
< 1) {
1297 infoPtr
->currentYear
--;
1298 infoPtr
->currentMonth
= 12;
1301 if(dwStyle
& MCS_DAYSTATE
) {
1305 nmds
.nmhdr
.hwndFrom
= infoPtr
->hwndSelf
;
1306 nmds
.nmhdr
.idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1307 nmds
.nmhdr
.code
= MCN_GETDAYSTATE
;
1308 nmds
.cDayState
= infoPtr
->monthRange
;
1309 nmds
.prgDayState
= Alloc
1310 (infoPtr
->monthRange
* sizeof(MONTHDAYSTATE
));
1312 SendMessageA(infoPtr
->hwndNotify
, WM_NOTIFY
,
1313 (WPARAM
)nmds
.nmhdr
.idFrom
, (LPARAM
)&nmds
);
1314 for(i
=0; i
<infoPtr
->monthRange
; i
++)
1315 infoPtr
->monthdayState
[i
] = nmds
.prgDayState
[i
];
1320 MONTHCAL_RButtonDown(MONTHCAL_INFO
*infoPtr
, LPARAM lParam
)
1326 hMenu
= CreatePopupMenu();
1327 if (!LoadStringA(COMCTL32_hModule
,IDM_GOTODAY
,buf
,sizeof(buf
)))
1329 WARN("Can't load resource\n");
1330 strcpy(buf
,"Go to Today:");
1332 AppendMenuA(hMenu
, MF_STRING
|MF_ENABLED
,1, buf
);
1333 menupoint
.x
=(INT
)LOWORD(lParam
);
1334 menupoint
.y
=(INT
)HIWORD(lParam
);
1335 ClientToScreen(infoPtr
->hwndSelf
, &menupoint
);
1336 if( TrackPopupMenu(hMenu
,TPM_RIGHTBUTTON
| TPM_NONOTIFY
|TPM_RETURNCMD
,
1337 menupoint
.x
, menupoint
.y
, 0, infoPtr
->hwndSelf
, NULL
))
1339 infoPtr
->currentMonth
=infoPtr
->todaysDate
.wMonth
;
1340 infoPtr
->currentYear
=infoPtr
->todaysDate
.wYear
;
1341 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1347 MONTHCAL_LButtonDown(MONTHCAL_INFO
*infoPtr
, LPARAM lParam
)
1352 RECT rcDay
; /* used in determining area to invalidate */
1357 TRACE("%lx\n", lParam
);
1359 if (infoPtr
->hWndYearUpDown
)
1361 infoPtr
->currentYear
=SendMessageA( infoPtr
->hWndYearUpDown
, UDM_SETPOS
, (WPARAM
) 0,(LPARAM
)0);
1362 if(!DestroyWindow(infoPtr
->hWndYearUpDown
))
1364 FIXME("Can't destroy Updown Control\n");
1367 infoPtr
->hWndYearUpDown
=0;
1368 if(!DestroyWindow(infoPtr
->hWndYearEdit
))
1370 FIXME("Can't destroy Updown Control\n");
1373 infoPtr
->hWndYearEdit
=0;
1374 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1377 ht
.pt
.x
= (INT
)LOWORD(lParam
);
1378 ht
.pt
.y
= (INT
)HIWORD(lParam
);
1379 hit
= MONTHCAL_HitTest(infoPtr
, (LPARAM
)&ht
);
1381 /* FIXME: these flags should be checked by */
1382 /*((hit & MCHT_XXX) == MCHT_XXX) b/c some of the flags are */
1384 if(hit
==MCHT_TITLEBTNNEXT
) {
1385 MONTHCAL_GoToNextMonth(infoPtr
);
1386 infoPtr
->status
= MC_NEXTPRESSED
;
1387 SetTimer(infoPtr
->hwndSelf
, MC_NEXTMONTHTIMER
, MC_NEXTMONTHDELAY
, 0);
1388 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1391 if(hit
== MCHT_TITLEBTNPREV
){
1392 MONTHCAL_GoToPrevMonth(infoPtr
);
1393 infoPtr
->status
= MC_PREVPRESSED
;
1394 SetTimer(infoPtr
->hwndSelf
, MC_PREVMONTHTIMER
, MC_NEXTMONTHDELAY
, 0);
1395 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1399 if(hit
== MCHT_TITLEMONTH
) {
1400 hMenu
= CreatePopupMenu();
1404 GetLocaleInfoA( LOCALE_USER_DEFAULT
,LOCALE_SMONTHNAME1
+i
,
1406 AppendMenuA(hMenu
, MF_STRING
|MF_ENABLED
,i
+1, buf
);
1408 menupoint
.x
=infoPtr
->titlemonth
.right
;
1409 menupoint
.y
=infoPtr
->titlemonth
.bottom
;
1410 ClientToScreen(infoPtr
->hwndSelf
, &menupoint
);
1411 i
= TrackPopupMenu(hMenu
,TPM_LEFTALIGN
| TPM_NONOTIFY
| TPM_RIGHTBUTTON
| TPM_RETURNCMD
,
1412 menupoint
.x
, menupoint
.y
, 0, infoPtr
->hwndSelf
, NULL
);
1413 if ((i
>0) && (i
<13))
1415 infoPtr
->currentMonth
=i
;
1416 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1419 if(hit
== MCHT_TITLEYEAR
) {
1420 infoPtr
->hWndYearEdit
=CreateWindowExA(0,
1423 WS_VISIBLE
| WS_CHILD
|UDS_SETBUDDYINT
,
1424 infoPtr
->titleyear
.left
+3,infoPtr
->titlebtnnext
.top
,
1425 infoPtr
->titleyear
.right
-infoPtr
->titleyear
.left
,
1426 infoPtr
->textHeight
,
1431 infoPtr
->hWndYearUpDown
=CreateWindowExA(0,
1434 WS_VISIBLE
| WS_CHILD
|UDS_SETBUDDYINT
|UDS_NOTHOUSANDS
|UDS_ARROWKEYS
,
1435 infoPtr
->titleyear
.right
+6,infoPtr
->titlebtnnext
.top
,
1437 infoPtr
->textHeight
,
1442 SendMessageA( infoPtr
->hWndYearUpDown
, UDM_SETRANGE
, (WPARAM
) 0, MAKELONG (9999, 1753));
1443 SendMessageA( infoPtr
->hWndYearUpDown
, UDM_SETBUDDY
, (WPARAM
) infoPtr
->hWndYearEdit
, (LPARAM
)0 );
1444 SendMessageA( infoPtr
->hWndYearUpDown
, UDM_SETPOS
, (WPARAM
) 0,(LPARAM
)infoPtr
->currentYear
);
1448 if(hit
== MCHT_TODAYLINK
) {
1449 infoPtr
->currentMonth
=infoPtr
->todaysDate
.wMonth
;
1450 infoPtr
->currentYear
=infoPtr
->todaysDate
.wYear
;
1451 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1454 if(hit
== MCHT_CALENDARDATE
) {
1455 SYSTEMTIME selArray
[2];
1458 MONTHCAL_CopyTime(&ht
.st
, &selArray
[0]);
1459 MONTHCAL_CopyTime(&ht
.st
, &selArray
[1]);
1460 MONTHCAL_SetSelRange(infoPtr
, (LPARAM
)&selArray
);
1461 MONTHCAL_SetCurSel(infoPtr
, (LPARAM
)&selArray
);
1462 TRACE("MCHT_CALENDARDATE\n");
1463 nmsc
.nmhdr
.hwndFrom
= infoPtr
->hwndSelf
;
1464 nmsc
.nmhdr
.idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1465 nmsc
.nmhdr
.code
= MCN_SELCHANGE
;
1466 MONTHCAL_CopyTime(&infoPtr
->minSel
,&nmsc
.stSelStart
);
1467 MONTHCAL_CopyTime(&infoPtr
->maxSel
,&nmsc
.stSelEnd
);
1469 SendMessageA(infoPtr
->hwndNotify
, WM_NOTIFY
,
1470 (WPARAM
)nmsc
.nmhdr
.idFrom
,(LPARAM
)&nmsc
);
1473 /* redraw both old and new days if the selected day changed */
1474 if(infoPtr
->curSelDay
!= ht
.st
.wDay
) {
1475 MONTHCAL_CalcPosFromDay(infoPtr
, ht
.st
.wDay
, ht
.st
.wMonth
, &rcDay
);
1476 InvalidateRect(infoPtr
->hwndSelf
, &rcDay
, TRUE
);
1478 MONTHCAL_CalcPosFromDay(infoPtr
, infoPtr
->curSelDay
, infoPtr
->currentMonth
, &rcDay
);
1479 InvalidateRect(infoPtr
->hwndSelf
, &rcDay
, TRUE
);
1482 infoPtr
->firstSelDay
= ht
.st
.wDay
;
1483 infoPtr
->curSelDay
= ht
.st
.wDay
;
1484 infoPtr
->status
= MC_SEL_LBUTDOWN
;
1493 MONTHCAL_LButtonUp(MONTHCAL_INFO
*infoPtr
, LPARAM lParam
)
1497 BOOL redraw
= FALSE
;
1503 if(infoPtr
->status
& MC_NEXTPRESSED
) {
1504 KillTimer(infoPtr
->hwndSelf
, MC_NEXTMONTHTIMER
);
1505 infoPtr
->status
&= ~MC_NEXTPRESSED
;
1508 if(infoPtr
->status
& MC_PREVPRESSED
) {
1509 KillTimer(infoPtr
->hwndSelf
, MC_PREVMONTHTIMER
);
1510 infoPtr
->status
&= ~MC_PREVPRESSED
;
1514 ht
.pt
.x
= (INT
)LOWORD(lParam
);
1515 ht
.pt
.y
= (INT
)HIWORD(lParam
);
1516 hit
= MONTHCAL_HitTest(infoPtr
, (LPARAM
)&ht
);
1518 infoPtr
->status
= MC_SEL_LBUTUP
;
1520 if(hit
==MCHT_CALENDARDATENEXT
) {
1521 MONTHCAL_GoToNextMonth(infoPtr
);
1522 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1525 if(hit
== MCHT_CALENDARDATEPREV
){
1526 MONTHCAL_GoToPrevMonth(infoPtr
);
1527 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1530 nmhdr
.hwndFrom
= infoPtr
->hwndSelf
;
1531 nmhdr
.idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1532 nmhdr
.code
= NM_RELEASEDCAPTURE
;
1533 TRACE("Sent notification from %p to %p\n", infoPtr
->hwndSelf
, infoPtr
->hwndNotify
);
1535 SendMessageA(infoPtr
->hwndNotify
, WM_NOTIFY
,
1536 (WPARAM
)nmhdr
.idFrom
, (LPARAM
)&nmhdr
);
1537 /* redraw if necessary */
1539 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1540 /* only send MCN_SELECT if currently displayed month's day was selected */
1541 if(hit
== MCHT_CALENDARDATE
) {
1542 nmsc
.nmhdr
.hwndFrom
= infoPtr
->hwndSelf
;
1543 nmsc
.nmhdr
.idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1544 nmsc
.nmhdr
.code
= MCN_SELECT
;
1545 MONTHCAL_CopyTime(&infoPtr
->minSel
, &nmsc
.stSelStart
);
1546 MONTHCAL_CopyTime(&infoPtr
->maxSel
, &nmsc
.stSelEnd
);
1548 SendMessageA(infoPtr
->hwndNotify
, WM_NOTIFY
,
1549 (WPARAM
)nmsc
.nmhdr
.idFrom
, (LPARAM
)&nmsc
);
1557 MONTHCAL_Timer(MONTHCAL_INFO
*infoPtr
, WPARAM wParam
)
1559 BOOL redraw
= FALSE
;
1561 TRACE("%d\n", wParam
);
1564 case MC_NEXTMONTHTIMER
:
1566 MONTHCAL_GoToNextMonth(infoPtr
);
1568 case MC_PREVMONTHTIMER
:
1570 MONTHCAL_GoToPrevMonth(infoPtr
);
1573 ERR("got unknown timer\n");
1577 /* redraw only if necessary */
1579 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1586 MONTHCAL_MouseMove(MONTHCAL_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
1589 int oldselday
, selday
, hit
;
1592 if(!(infoPtr
->status
& MC_SEL_LBUTDOWN
)) return 0;
1594 ht
.pt
.x
= LOWORD(lParam
);
1595 ht
.pt
.y
= HIWORD(lParam
);
1597 hit
= MONTHCAL_HitTest(infoPtr
, (LPARAM
)&ht
);
1599 /* not on the calendar date numbers? bail out */
1600 TRACE("hit:%x\n",hit
);
1601 if((hit
& MCHT_CALENDARDATE
) != MCHT_CALENDARDATE
) return 0;
1603 selday
= ht
.st
.wDay
;
1604 oldselday
= infoPtr
->curSelDay
;
1605 infoPtr
->curSelDay
= selday
;
1606 MONTHCAL_CalcPosFromDay(infoPtr
, selday
, ht
.st
. wMonth
, &r
);
1608 if(GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
) & MCS_MULTISELECT
) {
1609 SYSTEMTIME selArray
[2];
1612 MONTHCAL_GetSelRange(infoPtr
, (LPARAM
)&selArray
);
1614 if(infoPtr
->firstSelDay
==selArray
[0].wDay
) i
=1;
1615 TRACE("oldRange:%d %d %d %d\n", infoPtr
->firstSelDay
, selArray
[0].wDay
, selArray
[1].wDay
, i
);
1616 if(infoPtr
->firstSelDay
==selArray
[1].wDay
) {
1617 /* 1st time we get here: selArray[0]=selArray[1]) */
1618 /* if we're still at the first selected date, return */
1619 if(infoPtr
->firstSelDay
==selday
) goto done
;
1620 if(selday
<infoPtr
->firstSelDay
) i
= 0;
1623 if(abs(infoPtr
->firstSelDay
- selday
) >= infoPtr
->maxSelCount
) {
1624 if(selday
>infoPtr
->firstSelDay
)
1625 selday
= infoPtr
->firstSelDay
+ infoPtr
->maxSelCount
;
1627 selday
= infoPtr
->firstSelDay
- infoPtr
->maxSelCount
;
1630 if(selArray
[i
].wDay
!=selday
) {
1631 TRACE("newRange:%d %d %d %d\n", infoPtr
->firstSelDay
, selArray
[0].wDay
, selArray
[1].wDay
, i
);
1633 selArray
[i
].wDay
= selday
;
1635 if(selArray
[0].wDay
>selArray
[1].wDay
) {
1637 tempday
= selArray
[1].wDay
;
1638 selArray
[1].wDay
= selArray
[0].wDay
;
1639 selArray
[0].wDay
= tempday
;
1642 MONTHCAL_SetSelRange(infoPtr
, (LPARAM
)&selArray
);
1648 /* only redraw if the currently selected day changed */
1649 /* FIXME: this should specify a rectangle containing only the days that changed */
1650 /* using InvalidateRect */
1651 if(oldselday
!= infoPtr
->curSelDay
)
1652 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1659 MONTHCAL_Paint(MONTHCAL_INFO
*infoPtr
, WPARAM wParam
)
1666 GetClientRect(infoPtr
->hwndSelf
, &ps
.rcPaint
);
1670 hdc
= BeginPaint(infoPtr
->hwndSelf
, &ps
);
1672 MONTHCAL_Refresh(infoPtr
, hdc
, &ps
);
1673 if (!wParam
) EndPaint(infoPtr
->hwndSelf
, &ps
);
1679 MONTHCAL_KillFocus(MONTHCAL_INFO
*infoPtr
)
1683 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1690 MONTHCAL_SetFocus(MONTHCAL_INFO
*infoPtr
)
1694 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1699 /* sets the size information */
1700 static void MONTHCAL_UpdateSize(MONTHCAL_INFO
*infoPtr
)
1702 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
1703 RECT
*title
=&infoPtr
->title
;
1704 RECT
*prev
=&infoPtr
->titlebtnprev
;
1705 RECT
*next
=&infoPtr
->titlebtnnext
;
1706 RECT
*titlemonth
=&infoPtr
->titlemonth
;
1707 RECT
*titleyear
=&infoPtr
->titleyear
;
1708 RECT
*wdays
=&infoPtr
->wdays
;
1709 RECT
*weeknumrect
=&infoPtr
->weeknums
;
1710 RECT
*days
=&infoPtr
->days
;
1711 RECT
*todayrect
=&infoPtr
->todayrect
;
1714 DWORD dwStyle
= GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
);
1716 int xdiv
, left_offset
;
1719 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
1721 currentFont
= SelectObject(hdc
, infoPtr
->hFont
);
1723 /* get the height and width of each day's text */
1724 GetTextMetricsA(hdc
, &tm
);
1725 infoPtr
->textHeight
= tm
.tmHeight
+ tm
.tmExternalLeading
+ tm
.tmInternalLeading
;
1726 GetTextExtentPoint32A(hdc
, "Sun", 3, &size
);
1727 infoPtr
->textWidth
= size
.cx
+ 2;
1729 /* recalculate the height and width increments and offsets */
1730 GetTextExtentPoint32A(hdc
, "00", 2, &size
);
1732 xdiv
= (dwStyle
& MCS_WEEKNUMBERS
) ? 8 : 7;
1734 infoPtr
->width_increment
= size
.cx
* 2;
1735 infoPtr
->height_increment
= infoPtr
->textHeight
;
1736 left_offset
= (rcClient
.right
- rcClient
.left
) - (infoPtr
->width_increment
* xdiv
);
1738 /* calculate title area */
1739 title
->top
= rcClient
.top
;
1740 title
->bottom
= title
->top
+ 3 * infoPtr
->height_increment
/ 2;
1741 title
->left
= left_offset
;
1742 title
->right
= rcClient
.right
;
1744 /* set the dimensions of the next and previous buttons and center */
1745 /* the month text vertically */
1746 prev
->top
= next
->top
= title
->top
+ 4;
1747 prev
->bottom
= next
->bottom
= title
->bottom
- 4;
1748 prev
->left
= title
->left
+ 4;
1749 prev
->right
= prev
->left
+ (title
->bottom
- title
->top
) ;
1750 next
->right
= title
->right
- 4;
1751 next
->left
= next
->right
- (title
->bottom
- title
->top
);
1753 /* titlemonth->left and right change based upon the current month */
1754 /* and are recalculated in refresh as the current month may change */
1755 /* without the control being resized */
1756 titlemonth
->top
= titleyear
->top
= title
->top
+ (infoPtr
->height_increment
)/2;
1757 titlemonth
->bottom
= titleyear
->bottom
= title
->bottom
- (infoPtr
->height_increment
)/2;
1759 /* setup the dimensions of the rectangle we draw the names of the */
1760 /* days of the week in */
1761 weeknumrect
->left
= left_offset
;
1762 if(dwStyle
& MCS_WEEKNUMBERS
)
1763 weeknumrect
->right
=prev
->right
;
1765 weeknumrect
->right
=weeknumrect
->left
;
1766 wdays
->left
= days
->left
= weeknumrect
->right
;
1767 wdays
->right
= days
->right
= wdays
->left
+ 7 * infoPtr
->width_increment
;
1768 wdays
->top
= title
->bottom
;
1769 wdays
->bottom
= wdays
->top
+ infoPtr
->height_increment
;
1771 days
->top
= weeknumrect
->top
= wdays
->bottom
;
1772 days
->bottom
= weeknumrect
->bottom
= days
->top
+ 6 * infoPtr
->height_increment
;
1774 todayrect
->left
= rcClient
.left
;
1775 todayrect
->right
= rcClient
.right
;
1776 todayrect
->top
= days
->bottom
;
1777 todayrect
->bottom
= days
->bottom
+ infoPtr
->height_increment
;
1779 TRACE("dx=%d dy=%d client[%s] title[%s] wdays[%s] days[%s] today[%s]\n",
1780 infoPtr
->width_increment
,infoPtr
->height_increment
,
1781 wine_dbgstr_rect(&rcClient
),
1782 wine_dbgstr_rect(title
),
1783 wine_dbgstr_rect(wdays
),
1784 wine_dbgstr_rect(days
),
1785 wine_dbgstr_rect(todayrect
));
1787 /* restore the originally selected font */
1788 SelectObject(hdc
, currentFont
);
1790 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
1793 static LRESULT
MONTHCAL_Size(MONTHCAL_INFO
*infoPtr
, int Width
, int Height
)
1795 TRACE("(width=%d, height=%d)\n", Width
, Height
);
1797 MONTHCAL_UpdateSize(infoPtr
);
1799 /* invalidate client area and erase background */
1800 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1805 static LRESULT
MONTHCAL_GetFont(MONTHCAL_INFO
*infoPtr
)
1807 return (LRESULT
)infoPtr
->hFont
;
1810 static LRESULT
MONTHCAL_SetFont(MONTHCAL_INFO
*infoPtr
, HFONT hFont
, BOOL redraw
)
1815 if (!hFont
) return 0;
1817 hOldFont
= infoPtr
->hFont
;
1818 infoPtr
->hFont
= hFont
;
1820 GetObjectW(infoPtr
->hFont
, sizeof(lf
), &lf
);
1821 lf
.lfWeight
= FW_BOLD
;
1822 infoPtr
->hBoldFont
= CreateFontIndirectW(&lf
);
1825 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1827 return (LRESULT
)hOldFont
;
1830 /* FIXME: check whether dateMin/dateMax need to be adjusted. */
1832 MONTHCAL_Create(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1834 MONTHCAL_INFO
*infoPtr
;
1836 /* allocate memory for info structure */
1837 infoPtr
=(MONTHCAL_INFO
*)Alloc(sizeof(MONTHCAL_INFO
));
1838 SetWindowLongPtrW(hwnd
, 0, (DWORD_PTR
)infoPtr
);
1840 if(infoPtr
== NULL
) {
1841 ERR( "could not allocate info memory!\n");
1845 infoPtr
->hwndSelf
= hwnd
;
1846 infoPtr
->hwndNotify
= ((LPCREATESTRUCTW
)lParam
)->hwndParent
;
1848 MONTHCAL_SetFont(infoPtr
, GetStockObject(DEFAULT_GUI_FONT
), FALSE
);
1850 /* initialize info structure */
1851 /* FIXME: calculate systemtime ->> localtime(substract timezoneinfo) */
1853 GetSystemTime(&infoPtr
->todaysDate
);
1854 MONTHCAL_SetFirstDayOfWeek(infoPtr
, (LPARAM
)-1);
1855 infoPtr
->currentMonth
= infoPtr
->todaysDate
.wMonth
;
1856 infoPtr
->currentYear
= infoPtr
->todaysDate
.wYear
;
1857 MONTHCAL_CopyTime(&infoPtr
->todaysDate
, &infoPtr
->minDate
);
1858 MONTHCAL_CopyTime(&infoPtr
->todaysDate
, &infoPtr
->maxDate
);
1859 infoPtr
->maxDate
.wYear
=2050;
1860 infoPtr
->minDate
.wYear
=1950;
1861 infoPtr
->maxSelCount
= 7;
1862 infoPtr
->monthRange
= 3;
1863 infoPtr
->monthdayState
= Alloc
1864 (infoPtr
->monthRange
* sizeof(MONTHDAYSTATE
));
1865 infoPtr
->titlebk
= GetSysColor(COLOR_ACTIVECAPTION
);
1866 infoPtr
->titletxt
= GetSysColor(COLOR_WINDOW
);
1867 infoPtr
->monthbk
= GetSysColor(COLOR_WINDOW
);
1868 infoPtr
->trailingtxt
= GetSysColor(COLOR_GRAYTEXT
);
1869 infoPtr
->bk
= GetSysColor(COLOR_WINDOW
);
1870 infoPtr
->txt
= GetSysColor(COLOR_WINDOWTEXT
);
1872 /* call MONTHCAL_UpdateSize to set all of the dimensions */
1873 /* of the control */
1874 MONTHCAL_UpdateSize(infoPtr
);
1881 MONTHCAL_Destroy(MONTHCAL_INFO
*infoPtr
)
1883 /* free month calendar info data */
1884 if(infoPtr
->monthdayState
)
1885 Free(infoPtr
->monthdayState
);
1886 SetWindowLongPtrW(infoPtr
->hwndSelf
, 0, 0);
1892 static LRESULT WINAPI
1893 MONTHCAL_WindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1895 MONTHCAL_INFO
*infoPtr
;
1897 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n", hwnd
, uMsg
, wParam
, lParam
);
1899 infoPtr
= MONTHCAL_GetInfoPtr(hwnd
);
1900 if (!infoPtr
&& (uMsg
!= WM_CREATE
))
1901 return DefWindowProcA(hwnd
, uMsg
, wParam
, lParam
);
1905 return MONTHCAL_GetCurSel(infoPtr
, lParam
);
1908 return MONTHCAL_SetCurSel(infoPtr
, lParam
);
1910 case MCM_GETMAXSELCOUNT
:
1911 return MONTHCAL_GetMaxSelCount(infoPtr
);
1913 case MCM_SETMAXSELCOUNT
:
1914 return MONTHCAL_SetMaxSelCount(infoPtr
, wParam
);
1916 case MCM_GETSELRANGE
:
1917 return MONTHCAL_GetSelRange(infoPtr
, lParam
);
1919 case MCM_SETSELRANGE
:
1920 return MONTHCAL_SetSelRange(infoPtr
, lParam
);
1922 case MCM_GETMONTHRANGE
:
1923 return MONTHCAL_GetMonthRange(infoPtr
);
1925 case MCM_SETDAYSTATE
:
1926 return MONTHCAL_SetDayState(infoPtr
, wParam
, lParam
);
1928 case MCM_GETMINREQRECT
:
1929 return MONTHCAL_GetMinReqRect(infoPtr
, lParam
);
1932 return MONTHCAL_GetColor(infoPtr
, wParam
);
1935 return MONTHCAL_SetColor(infoPtr
, wParam
, lParam
);
1938 return MONTHCAL_GetToday(infoPtr
, lParam
);
1941 return MONTHCAL_SetToday(infoPtr
, lParam
);
1944 return MONTHCAL_HitTest(infoPtr
, lParam
);
1946 case MCM_GETFIRSTDAYOFWEEK
:
1947 return MONTHCAL_GetFirstDayOfWeek(infoPtr
);
1949 case MCM_SETFIRSTDAYOFWEEK
:
1950 return MONTHCAL_SetFirstDayOfWeek(infoPtr
, lParam
);
1953 return MONTHCAL_GetRange(hwnd
, wParam
, lParam
);
1956 return MONTHCAL_SetRange(infoPtr
, wParam
, lParam
);
1958 case MCM_GETMONTHDELTA
:
1959 return MONTHCAL_GetMonthDelta(infoPtr
);
1961 case MCM_SETMONTHDELTA
:
1962 return MONTHCAL_SetMonthDelta(infoPtr
, wParam
);
1964 case MCM_GETMAXTODAYWIDTH
:
1965 return MONTHCAL_GetMaxTodayWidth(infoPtr
);
1968 return DLGC_WANTARROWS
| DLGC_WANTCHARS
;
1971 return MONTHCAL_KillFocus(infoPtr
);
1973 case WM_RBUTTONDOWN
:
1974 return MONTHCAL_RButtonDown(infoPtr
, lParam
);
1976 case WM_LBUTTONDOWN
:
1977 return MONTHCAL_LButtonDown(infoPtr
, lParam
);
1980 return MONTHCAL_MouseMove(infoPtr
, wParam
, lParam
);
1983 return MONTHCAL_LButtonUp(infoPtr
, lParam
);
1986 return MONTHCAL_Paint(infoPtr
, wParam
);
1989 return MONTHCAL_SetFocus(infoPtr
);
1992 return MONTHCAL_Size(infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
1995 return MONTHCAL_Create(hwnd
, wParam
, lParam
);
1998 return MONTHCAL_SetFont(infoPtr
, (HFONT
)wParam
, (BOOL
)lParam
);
2001 return MONTHCAL_GetFont(infoPtr
);
2004 return MONTHCAL_Timer(infoPtr
, wParam
);
2007 return MONTHCAL_Destroy(infoPtr
);
2010 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
))
2011 ERR( "unknown msg %04x wp=%08x lp=%08lx\n", uMsg
, wParam
, lParam
);
2012 return DefWindowProcA(hwnd
, uMsg
, wParam
, lParam
);
2018 MONTHCAL_Register(void)
2022 ZeroMemory(&wndClass
, sizeof(WNDCLASSA
));
2023 wndClass
.style
= CS_GLOBALCLASS
;
2024 wndClass
.lpfnWndProc
= MONTHCAL_WindowProc
;
2025 wndClass
.cbClsExtra
= 0;
2026 wndClass
.cbWndExtra
= sizeof(MONTHCAL_INFO
*);
2027 wndClass
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
2028 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
2029 wndClass
.lpszClassName
= MONTHCAL_CLASSA
;
2031 RegisterClassA(&wndClass
);
2036 MONTHCAL_Unregister(void)
2038 UnregisterClassA(MONTHCAL_CLASSA
, NULL
);