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: refresh should ask for rect of required length. (?)
14 * FIXME: handle resources better (doesn't work now); also take care
15 of internationalization.
16 * FIXME: keyboard handling.
29 #include "debugtools.h"
31 DEFAULT_DEBUG_CHANNEL(monthcal
)
33 /* take #days/month from ole/parsedt.c;
34 * we want full month-names, and abbreviated weekdays, so these are
39 char *monthtxt
[] = {"January", "February", "March", "April", "May",
40 "June", "July", "August", "September", "October",
41 "November", "December"};
42 char *daytxt
[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
43 int DayOfWeekTable
[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
46 #define MONTHCAL_GetInfoPtr(hwnd) ((MONTHCAL_INFO *)GetWindowLongA(hwnd, 0))
48 /* helper functions */
50 /* returns the number of days in any given month */
51 /* january is 1, december is 12 */
52 static int MONTHCAL_MonthLength(int month
, int year
)
54 /* if we have a leap year add 1 day to February */
55 /* a leap year is a year either divisible by 400 */
56 /* or divisible by 4 and not by 100 */
57 if(month
== 2) { /* February */
58 return mdays
[month
- 1] + ((year
%400 == 0) ? 1 : ((year
%100 != 0) &&
59 (year
%4 == 0)) ? 1 : 0);
62 return mdays
[month
- 1];
67 /* make sure that time is valid */
68 static int MONTHCAL_ValidateTime(SYSTEMTIME time
)
70 if(time
.wMonth
> 12) return FALSE
;
71 if(time
.wDayOfWeek
> 6) return FALSE
;
72 if(time
.wDay
> MONTHCAL_MonthLength(time
.wMonth
, time
.wYear
))
74 if(time
.wHour
> 23) return FALSE
;
75 if(time
.wMinute
> 59) return FALSE
;
76 if(time
.wSecond
> 59) return FALSE
;
77 if(time
.wMilliseconds
> 999) return FALSE
;
83 void MONTHCAL_CopyTime(const SYSTEMTIME
*from
, SYSTEMTIME
*to
)
85 to
->wYear
= from
->wYear
;
86 to
->wMonth
= from
->wMonth
;
87 to
->wDayOfWeek
= from
->wDayOfWeek
;
88 to
->wDay
= from
->wDay
;
89 to
->wHour
= from
->wHour
;
90 to
->wMinute
= from
->wMinute
;
91 to
->wSecond
= from
->wSecond
;
92 to
->wMilliseconds
= from
->wMilliseconds
;
96 /* Note:Depending on DST, this may be offset by a day.
97 Need to find out if we're on a DST place & adjust the clock accordingly.
98 Above function assumes we have a valid data.
99 Valid for year>1752; 1 <= d <= 31, 1 <= m <= 12.
103 /* returns the day in the week(0 == sunday, 6 == saturday) */
104 /* day(1 == 1st, 2 == 2nd... etc), year is the year value */
105 int MONTHCAL_CalculateDayOfWeek(DWORD day
, DWORD month
, DWORD year
)
109 return((year
+ year
/4 - year
/100 + year
/400 +
110 DayOfWeekTable
[month
-1] + day
- 1 ) % 7);
114 static int MONTHCAL_CalcDayFromPos(MONTHCAL_INFO
*infoPtr
, int x
, int y
)
116 int daypos
, weekpos
, retval
, firstDay
;
118 /* if the point is outside the x bounds of the window put
120 if(x
> (infoPtr
->width_increment
* 7.0)) {
121 x
= infoPtr
->rcClient
.right
- infoPtr
->rcClient
.left
- infoPtr
->left_offset
;
124 daypos
= (x
-(infoPtr
->prevmonth
.left
+ infoPtr
->left_offset
)) / infoPtr
->width_increment
;
125 weekpos
= (y
- infoPtr
->days
.bottom
- infoPtr
->rcClient
.top
) / infoPtr
->height_increment
;
127 firstDay
= MONTHCAL_CalculateDayOfWeek(1, infoPtr
->currentMonth
, infoPtr
->currentYear
);
128 retval
= daypos
+ (7 * weekpos
) - firstDay
;
129 TRACE("%d %d %d\n", daypos
, weekpos
, retval
);
133 /* day is the day of the month, 1 == 1st day of the month */
134 /* sets x and y to be the position of the day */
135 /* x == day, y == week where(0,0) == sunday, 1st week */
136 static void MONTHCAL_CalcDayXY(MONTHCAL_INFO
*infoPtr
, int day
, int month
,
139 int firstDay
, prevMonth
;
141 firstDay
= MONTHCAL_CalculateDayOfWeek(1, infoPtr
->currentMonth
, infoPtr
->currentYear
);
143 if(month
==infoPtr
->currentMonth
) {
144 *x
= (day
+ firstDay
) % 7;
145 *y
= (day
+ firstDay
- *x
) / 7;
148 if(month
< infoPtr
->currentMonth
) {
149 prevMonth
= month
- 1;
153 *x
= (MONTHCAL_MonthLength(prevMonth
, infoPtr
->currentYear
) - firstDay
) % 7;
158 *y
= MONTHCAL_MonthLength(month
, infoPtr
->currentYear
- 1) / 7;
159 *x
= (day
+ firstDay
+ MONTHCAL_MonthLength(month
,
160 infoPtr
->currentYear
)) % 7;
164 /* x: column(day), y: row(week) */
165 static void MONTHCAL_CalcDayRect(MONTHCAL_INFO
*infoPtr
, RECT
*r
, int x
, int y
)
167 r
->left
= infoPtr
->prevmonth
.left
+ x
* infoPtr
->width_increment
+ infoPtr
->left_offset
;
168 r
->right
= r
->left
+ infoPtr
->width_increment
;
169 r
->top
= infoPtr
->height_increment
* y
+ infoPtr
->days
.bottom
+ infoPtr
->top_offset
;
170 r
->bottom
= r
->top
+ infoPtr
->textHeight
;
174 /* sets the RECT struct r to the rectangle around the day and month */
175 /* day is the day value of the month(1 == 1st), month is the month */
176 /* value(january == 1, december == 12) */
177 static inline void MONTHCAL_CalcPosFromDay(MONTHCAL_INFO
*infoPtr
,
178 int day
, int month
, RECT
*r
)
182 MONTHCAL_CalcDayXY(infoPtr
, day
, month
, &x
, &y
);
183 MONTHCAL_CalcDayRect(infoPtr
, r
, x
, y
);
187 /* day is the day in the month(1 == 1st of the month) */
188 /* month is the month value(1 == january, 12 == december) */
189 static void MONTHCAL_CircleDay(HDC hdc
, MONTHCAL_INFO
*infoPtr
, int day
,
192 HPEN hRedPen
= CreatePen(PS_SOLID
, 2, RGB(255, 0, 0));
193 HPEN hOldPen2
= SelectObject(hdc
, hRedPen
);
198 /* use prevmonth to calculate position because it contains the extra width
199 * from MCS_WEEKNUMBERS
202 MONTHCAL_CalcPosFromDay(infoPtr
, day
, month
, &day_rect
);
209 points
[1].x
= x
+ 0.8 * infoPtr
->width_increment
;
211 points
[2].x
= x
+ 0.9 * infoPtr
->width_increment
;
213 points
[3].x
= x
+ infoPtr
->width_increment
;
214 points
[3].y
= y
+ 0.5 * infoPtr
->textHeight
;
216 points
[4].x
= x
+ infoPtr
->width_increment
;
217 points
[4].y
= y
+ 0.9 * infoPtr
->textHeight
;
218 points
[5].x
= x
+ 0.6 * infoPtr
->width_increment
;
219 points
[5].y
= y
+ 0.9 * infoPtr
->textHeight
;
220 points
[6].x
= x
+ 0.5 * infoPtr
->width_increment
;
221 points
[6].y
= y
+ 0.9 * infoPtr
->textHeight
; /* bring the bottom up just
222 a hair to fit inside the day rectangle */
224 points
[7].x
= x
+ 0.2 * infoPtr
->width_increment
;
225 points
[7].y
= y
+ 0.8 * infoPtr
->textHeight
;
226 points
[8].x
= x
+ 0.1 * infoPtr
->width_increment
;
227 points
[8].y
= y
+ 0.8 * infoPtr
->textHeight
;
229 points
[9].y
= y
+ 0.5 * infoPtr
->textHeight
;
231 points
[10].x
= x
+ 0.1 * infoPtr
->width_increment
;
232 points
[10].y
= y
+ 0.2 * infoPtr
->textHeight
;
233 points
[11].x
= x
+ 0.2 * infoPtr
->width_increment
;
234 points
[11].y
= y
+ 0.3 * infoPtr
->textHeight
;
235 points
[12].x
= x
+ 0.5 * infoPtr
->width_increment
;
236 points
[12].y
= y
+ 0.3 * infoPtr
->textHeight
;
238 PolyBezier(hdc
, points
, 13);
239 DeleteObject(hRedPen
);
240 SelectObject(hdc
, hOldPen2
);
244 static void MONTHCAL_DrawDay(HDC hdc
, MONTHCAL_INFO
*infoPtr
,
245 int day
, int month
, int x
, int y
, int bold
)
249 static int haveBoldFont
, haveSelectedDay
= FALSE
;
251 HPEN hNewPen
, hOldPen
= 0;
255 sprintf(buf
, "%d", day
);
257 /* No need to check styles: when selection is not valid, it is set to zero.
258 * 1<day<31, so evertyhing's OK.
261 MONTHCAL_CalcDayRect(infoPtr
, &r
, x
, y
);
263 if((day
>=infoPtr
->minSel
.wDay
) && (day
<=infoPtr
->maxSel
.wDay
)
264 && (month
==infoPtr
->currentMonth
)) {
268 TRACE("%d %d %d\n",day
, infoPtr
->minSel
.wDay
, infoPtr
->maxSel
.wDay
);
269 TRACE("%d %d %d %d\n", r
.left
, r
.top
, r
.right
, r
.bottom
);
270 oldCol
= SetTextColor(hdc
, infoPtr
->monthbk
);
271 oldBk
= SetBkColor(hdc
, infoPtr
->trailingtxt
);
272 hbr
= GetSysColorBrush(COLOR_GRAYTEXT
);
273 hrgn
= CreateEllipticRgn(r
.left
, r
.top
, r
.right
, r
.bottom
);
274 FillRgn(hdc
, hrgn
, hbr
);
276 /* FIXME: this may need to be changed now b/c of the other
277 drawing changes 11/3/99 CMM */
278 r2
.left
= r
.left
- 0.25 * infoPtr
->textWidth
;
280 r2
.right
= r
.left
+ 0.5 * infoPtr
->textWidth
;
281 r2
.bottom
= r
.bottom
;
282 if(haveSelectedDay
) FillRect(hdc
, &r2
, hbr
);
283 haveSelectedDay
= TRUE
;
285 haveSelectedDay
= FALSE
;
288 /* need to add some code for multiple selections */
290 if((bold
) &&(!haveBoldFont
)) {
291 SelectObject(hdc
, infoPtr
->hBoldFont
);
294 if((!bold
) &&(haveBoldFont
)) {
295 SelectObject(hdc
, infoPtr
->hFont
);
296 haveBoldFont
= FALSE
;
299 if(haveSelectedDay
) {
300 SetTextColor(hdc
, oldCol
);
301 SetBkColor(hdc
, oldBk
);
304 DrawTextA(hdc
, buf
, lstrlenA(buf
), &r
,
305 DT_CENTER
| DT_VCENTER
| DT_SINGLELINE
);
307 /* draw a rectangle around the currently selected days text */
308 if((day
==infoPtr
->curSelDay
) && (month
==infoPtr
->currentMonth
)) {
309 hNewPen
= CreatePen(PS_DOT
, 0, GetSysColor(COLOR_WINDOWTEXT
) );
310 hbr
= GetSysColorBrush(COLOR_WINDOWTEXT
);
311 FrameRect(hdc
, &r
, hbr
);
312 SelectObject(hdc
, hOldPen
);
317 /* CHECKME: For `todays date', do we need to check the locale?*/
318 static void MONTHCAL_Refresh(HWND hwnd
, HDC hdc
)
320 MONTHCAL_INFO
*infoPtr
=MONTHCAL_GetInfoPtr(hwnd
);
321 RECT
*rcClient
=&infoPtr
->rcClient
;
322 RECT
*rcDraw
=&infoPtr
->rcDraw
;
323 RECT
*title
=&infoPtr
->title
;
324 RECT
*prev
=&infoPtr
->titlebtnprev
;
325 RECT
*next
=&infoPtr
->titlebtnnext
;
326 RECT
*titlemonth
=&infoPtr
->titlemonth
;
327 RECT
*titleyear
=&infoPtr
->titleyear
;
328 RECT
*prevmonth
=&infoPtr
->prevmonth
;
329 RECT
*nextmonth
=&infoPtr
->nextmonth
;
332 RECT
*weeknums
=&infoPtr
->weeknums
;
333 RECT
*rtoday
=&infoPtr
->today
;
334 int i
, j
, m
, mask
, day
, firstDay
, weeknum
, prevMonth
;
335 int textHeight
= infoPtr
->textHeight
, textWidth
= infoPtr
->textWidth
;
339 /* LOGFONTA logFont; */
340 char buf
[20], *thisMonthtxt
;
341 COLORREF oldTextColor
, oldBkColor
;
342 DWORD dwStyle
= GetWindowLongA(hwnd
, GWL_STYLE
);
345 oldTextColor
= SetTextColor(hdc
, GetSysColor(COLOR_WINDOWTEXT
));
347 /* draw control edge */
348 hbr
= CreateSolidBrush(RGB(255, 255, 255));
349 FillRect(hdc
, rcClient
, hbr
);
350 DrawEdge(hdc
, rcClient
, EDGE_SUNKEN
, BF_RECT
);
355 hbr
= CreateSolidBrush(infoPtr
->titlebk
);
356 FillRect(hdc
, title
, hbr
);
358 /* if the previous button is pressed draw it depressed */
359 if((infoPtr
->status
& MC_PREVPRESSED
))
360 DrawFrameControl(hdc
, prev
, DFC_SCROLL
,
361 DFCS_SCROLLLEFT
| DFCS_PUSHED
|
362 (dwStyle
& WS_DISABLED
? DFCS_INACTIVE
: 0));
363 else /* if the previous button is pressed draw it depressed */
364 DrawFrameControl(hdc
, prev
, DFC_SCROLL
,
365 DFCS_SCROLLLEFT
|(dwStyle
& WS_DISABLED
? DFCS_INACTIVE
: 0));
367 /* if next button is depressed draw it depressed */
368 if((infoPtr
->status
& MC_NEXTPRESSED
))
369 DrawFrameControl(hdc
, next
, DFC_SCROLL
,
370 DFCS_SCROLLRIGHT
| DFCS_PUSHED
|
371 (dwStyle
& WS_DISABLED
? DFCS_INACTIVE
: 0));
372 else /* if the next button is pressed draw it depressed */
373 DrawFrameControl(hdc
, next
, DFC_SCROLL
,
374 DFCS_SCROLLRIGHT
|(dwStyle
& WS_DISABLED
? DFCS_INACTIVE
: 0));
376 oldBkColor
= SetBkColor(hdc
, infoPtr
->titlebk
);
377 SetTextColor(hdc
, infoPtr
->titletxt
);
378 currentFont
= SelectObject(hdc
, infoPtr
->hBoldFont
);
380 /* titlemonth->left and right are set in MONTHCAL_UpdateSize */
381 titlemonth
->left
= title
->left
;
382 titlemonth
->right
= title
->right
;
384 thisMonthtxt
= monthtxt
[infoPtr
->currentMonth
- 1];
385 sprintf(buf
, "%s %ld", thisMonthtxt
, infoPtr
->currentYear
);
386 DrawTextA(hdc
, buf
, strlen(buf
), titlemonth
,
387 DT_CENTER
| DT_VCENTER
| DT_SINGLELINE
);
388 SelectObject(hdc
, infoPtr
->hFont
);
390 /* titlemonth left/right contained rect for whole titletxt('June 1999')
391 * MCM_HitTestInfo wants month & year rects, so prepare these now.
392 *(no, we can't draw them separately; the whole text is centered)
394 GetTextExtentPoint32A(hdc
, buf
, lstrlenA(buf
), &size
);
395 titlemonth
->left
= title
->right
/ 2 - size
.cx
/ 2;
396 titleyear
->right
= title
->right
/ 2 + size
.cx
/ 2;
397 GetTextExtentPoint32A(hdc
, thisMonthtxt
, lstrlenA(thisMonthtxt
), &size
);
398 titlemonth
->right
= titlemonth
->left
+ size
.cx
;
399 titleyear
->right
= titlemonth
->right
;
402 /* draw line under day abbreviatons */
404 if(dwStyle
& MCS_WEEKNUMBERS
)
405 MoveToEx(hdc
, rcDraw
->left
+ textWidth
+ 3, title
->bottom
+ textHeight
+ 2, NULL
);
407 MoveToEx(hdc
, rcDraw
->left
+ 3, title
->bottom
+ textHeight
+ 2, NULL
);
409 LineTo(hdc
, rcDraw
->right
- 3, title
->bottom
+ textHeight
+ 2);
411 /* draw day abbreviations */
413 SetBkColor(hdc
, infoPtr
->monthbk
);
414 SetTextColor(hdc
, infoPtr
->trailingtxt
);
416 /* copy this rect so we can change the values without changing */
417 /* the original version */
418 days
->left
= infoPtr
->days
.left
;
419 days
->right
= infoPtr
->days
.right
;
420 days
->top
= infoPtr
->days
.top
;
421 days
->bottom
= infoPtr
->days
.bottom
;
423 i
= infoPtr
->firstDay
;
426 DrawTextA(hdc
, daytxt
[i
], strlen(daytxt
[i
]), days
,
427 DT_CENTER
| DT_VCENTER
| DT_SINGLELINE
);
429 days
->left
+=infoPtr
->width_increment
;
430 days
->right
+=infoPtr
->width_increment
;
433 days
->left
= rcDraw
->left
+ j
;
434 if(dwStyle
& MCS_WEEKNUMBERS
) days
->left
+=textWidth
;
435 /* FIXME: this may need to be changed now 11/10/99 CMM */
436 days
->right
= rcDraw
->left
+ (j
+1) * textWidth
- 2;
438 /* draw day numbers; first, the previous month */
440 firstDay
= MONTHCAL_CalculateDayOfWeek(1, infoPtr
->currentMonth
, infoPtr
->currentYear
);
442 prevMonth
= infoPtr
->currentMonth
- 1;
443 if(prevMonth
== 0) /* if currentMonth is january(1) prevMonth is */
444 prevMonth
= 12; /* december(12) of the previous year */
446 day
= MONTHCAL_MonthLength(prevMonth
, infoPtr
->currentYear
) - firstDay
;
451 while(day
<= MONTHCAL_MonthLength(prevMonth
, infoPtr
->currentYear
)) {
452 MONTHCAL_DrawDay(hdc
, infoPtr
, day
, prevMonth
, i
, 0,
453 infoPtr
->monthdayState
[m
] & mask
);
460 if(dwStyle
& MCS_WEEKNUMBERS
) prevmonth
->left
= textWidth
;
461 prevmonth
->right
= prevmonth
->left
+ i
* textWidth
;
462 prevmonth
->top
= days
->bottom
;
463 prevmonth
->bottom
= prevmonth
->top
+ textHeight
;
465 /* draw `current' month */
467 day
= 1; /* start at the beginning of the current month */
469 infoPtr
->firstDayplace
= i
;
470 SetTextColor(hdc
, infoPtr
->txt
);
474 /* draw the first week of the current month */
476 MONTHCAL_DrawDay(hdc
, infoPtr
, day
, infoPtr
->currentMonth
, i
, 0,
477 infoPtr
->monthdayState
[m
] & mask
);
479 if((infoPtr
->currentMonth
==infoPtr
->todaysDate
.wMonth
) &&
480 (day
==infoPtr
->todaysDate
.wDay
) &&
481 (infoPtr
->currentYear
== infoPtr
->todaysDate
.wYear
)) {
482 MONTHCAL_CircleDay(hdc
, infoPtr
, day
, infoPtr
->currentMonth
);
490 j
= 1; /* move to the 2nd week of the current month */
491 i
= 0; /* move back to sunday */
492 while(day
<= MONTHCAL_MonthLength(infoPtr
->currentMonth
, infoPtr
->currentYear
)) {
493 MONTHCAL_DrawDay(hdc
, infoPtr
, day
, infoPtr
->currentMonth
, i
, j
,
494 infoPtr
->monthdayState
[m
] & mask
);
496 if((infoPtr
->currentMonth
==infoPtr
->todaysDate
.wMonth
) &&
497 (day
==infoPtr
->todaysDate
.wDay
) &&
498 (infoPtr
->currentYear
== infoPtr
->todaysDate
.wYear
))
499 MONTHCAL_CircleDay(hdc
, infoPtr
, day
, infoPtr
->currentMonth
);
504 if(i
>6) { /* past saturday, goto the next weeks sunday */
510 /* draw `next' month */
512 /* note: the nextmonth rect only hints for the `half-week' that needs to be
513 * drawn to complete the current week. An eventual next week that needs to
514 * be drawn to complete the month calendar is not taken into account in
515 * this rect -- HitTest knows about this.*/
517 nextmonth
->left
= prevmonth
->left
+ i
* textWidth
;
518 nextmonth
->right
= rcDraw
->right
;
519 nextmonth
->top
= days
->bottom
+ (j
+1) * textHeight
;
520 nextmonth
->bottom
= nextmonth
->top
+ textHeight
;
522 day
= 1; /* start at the first day of the next month */
526 SetTextColor(hdc
, infoPtr
->trailingtxt
);
527 while((i
<7) &&(j
<6)) {
528 MONTHCAL_DrawDay(hdc
, infoPtr
, day
, infoPtr
->currentMonth
+ 1, i
, j
,
529 infoPtr
->monthdayState
[m
] & mask
);
534 if(i
==7) { /* past saturday, go to next week's sunday */
539 SetTextColor(hdc
, infoPtr
->txt
);
542 /* draw `today' date if style allows it, and draw a circle before today's
543 * date if necessary */
545 if(!(dwStyle
& MCS_NOTODAY
)) {
547 if(!(dwStyle
& MCS_NOTODAYCIRCLE
)) {
548 MONTHCAL_CircleDay(hdc
, infoPtr
, day
, infoPtr
->currentMonth
+ 1);
551 MONTHCAL_CalcDayRect(infoPtr
, rtoday
, offset
==textWidth
, 6);
552 sprintf(buf
, "Today: %d/%d/%d", infoPtr
->todaysDate
.wMonth
,
553 infoPtr
->todaysDate
.wDay
, infoPtr
->todaysDate
.wYear
% 100);
554 rtoday
->right
= rcDraw
->right
;
555 SelectObject(hdc
, infoPtr
->hBoldFont
);
556 DrawTextA(hdc
, buf
, lstrlenA(buf
), rtoday
,
557 DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
);
558 SelectObject(hdc
, infoPtr
->hFont
);
561 if(dwStyle
& MCS_WEEKNUMBERS
) {
562 /* display weeknumbers*/
564 weeknums
->right
= textWidth
;
565 weeknums
->top
= days
->bottom
+ 2;
566 weeknums
->bottom
= days
->bottom
+ 2 + textHeight
;
569 for(i
=0; i
<infoPtr
->currentMonth
-1; i
++)
570 weeknum
+=MONTHCAL_MonthLength(i
, infoPtr
->currentYear
);
574 sprintf(buf
, "%d", weeknum
+ i
);
575 DrawTextA(hdc
, buf
, lstrlenA(buf
), weeknums
,
576 DT_CENTER
| DT_BOTTOM
| DT_SINGLELINE
);
577 weeknums
->top
+=textHeight
* 1.25;
578 weeknums
->bottom
+=textHeight
* 1.25;
581 MoveToEx(hdc
, weeknums
->right
, days
->bottom
+ 5 , NULL
);
582 LineTo(hdc
, weeknums
->right
, weeknums
->bottom
- 1.25 * textHeight
- 5);
586 /* currentFont was font at entering Refresh */
588 SetBkColor(hdc
, oldBkColor
);
589 SelectObject(hdc
, currentFont
);
590 SetTextColor(hdc
, oldTextColor
);
595 MONTHCAL_GetMinReqRect(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
597 MONTHCAL_INFO
*infoPtr
= MONTHCAL_GetInfoPtr(hwnd
);
598 LPRECT lpRect
= (LPRECT
) lParam
;
599 TRACE("%x %lx\n", wParam
, lParam
);
601 /* validate parameters */
603 if((infoPtr
==NULL
) ||(lpRect
== NULL
) ) return FALSE
;
605 lpRect
->left
= infoPtr
->rcClient
.left
;
606 lpRect
->right
= infoPtr
->rcClient
.right
;
607 lpRect
->top
= infoPtr
->rcClient
.top
;
608 lpRect
->bottom
= infoPtr
->rcClient
.bottom
;
613 MONTHCAL_GetColor(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
615 MONTHCAL_INFO
*infoPtr
= MONTHCAL_GetInfoPtr(hwnd
);
617 TRACE("%x %lx\n", wParam
, lParam
);
619 switch((int)wParam
) {
620 case MCSC_BACKGROUND
:
625 return infoPtr
->titlebk
;
627 return infoPtr
->titletxt
;
629 return infoPtr
->monthbk
;
630 case MCSC_TRAILINGTEXT
:
631 return infoPtr
->trailingtxt
;
638 MONTHCAL_SetColor(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
640 MONTHCAL_INFO
*infoPtr
= MONTHCAL_GetInfoPtr(hwnd
);
643 TRACE("%x %lx\n", wParam
, lParam
);
645 switch((int)wParam
) {
646 case MCSC_BACKGROUND
:
648 infoPtr
->bk
= (COLORREF
)lParam
;
652 infoPtr
->txt
= (COLORREF
)lParam
;
655 prev
= infoPtr
->titlebk
;
656 infoPtr
->titlebk
= (COLORREF
)lParam
;
659 prev
=infoPtr
->titletxt
;
660 infoPtr
->titletxt
= (COLORREF
)lParam
;
663 prev
= infoPtr
->monthbk
;
664 infoPtr
->monthbk
= (COLORREF
)lParam
;
666 case MCSC_TRAILINGTEXT
:
667 prev
= infoPtr
->trailingtxt
;
668 infoPtr
->trailingtxt
= (COLORREF
)lParam
;
676 MONTHCAL_GetMonthDelta(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
678 MONTHCAL_INFO
*infoPtr
= MONTHCAL_GetInfoPtr(hwnd
);
680 TRACE("%x %lx\n", wParam
, lParam
);
683 return infoPtr
->delta
;
685 return infoPtr
->visible
;
689 MONTHCAL_SetMonthDelta(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
691 MONTHCAL_INFO
*infoPtr
= MONTHCAL_GetInfoPtr(hwnd
);
692 int prev
= infoPtr
->delta
;
694 TRACE("%x %lx\n", wParam
, lParam
);
696 infoPtr
->delta
= (int)wParam
;
702 MONTHCAL_GetFirstDayOfWeek(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
704 MONTHCAL_INFO
*infoPtr
= MONTHCAL_GetInfoPtr(hwnd
);
706 return infoPtr
->firstDay
;
710 /* sets the first day of the week that will appear in the control */
711 /* 0 == Monday, 6 == Sunday */
712 /* FIXME: this needs to be implemented properly in MONTHCAL_Refresh() */
713 /* FIXME: we need more error checking here */
715 MONTHCAL_SetFirstDayOfWeek(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
717 MONTHCAL_INFO
*infoPtr
= MONTHCAL_GetInfoPtr(hwnd
);
718 int prev
= infoPtr
->firstDay
;
722 TRACE("%x %lx\n", wParam
, lParam
);
724 if((lParam
>= 0) && (lParam
< 7)) {
725 infoPtr
->firstDay
= (int)lParam
;
726 GetLocaleInfoA(LOCALE_USER_DEFAULT
, LOCALE_IFIRSTDAYOFWEEK
,
728 TRACE("%s %d\n", buf
, strlen(buf
));
729 if((sscanf(buf
, "%d", &day
) == 1) &&(infoPtr
->firstDay
!= day
))
730 infoPtr
->firstDay
= day
;
736 /* FIXME: fill this in */
738 MONTHCAL_GetMonthRange(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
740 MONTHCAL_INFO
*infoPtr
= MONTHCAL_GetInfoPtr(hwnd
);
742 TRACE("%x %lx\n", wParam
, lParam
);
745 return infoPtr
->monthRange
;
750 MONTHCAL_GetMaxTodayWidth(HWND hwnd
)
752 MONTHCAL_INFO
*infoPtr
= MONTHCAL_GetInfoPtr(hwnd
);
754 return(infoPtr
->today
.right
- infoPtr
->today
.left
);
758 /* FIXME: are validated times taken from current date/time or simply
760 * FIXME: check whether MCM_GETMONTHRANGE shows correct result after
761 * adjusting range with MCM_SETRANGE
765 MONTHCAL_SetRange(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
767 MONTHCAL_INFO
*infoPtr
= MONTHCAL_GetInfoPtr(hwnd
);
768 SYSTEMTIME lprgSysTimeArray
[1];
771 TRACE("%x %lx\n", wParam
, lParam
);
773 if(wParam
& GDTR_MAX
) {
774 if(MONTHCAL_ValidateTime(lprgSysTimeArray
[1])){
775 MONTHCAL_CopyTime(&lprgSysTimeArray
[1], &infoPtr
->maxDate
);
776 infoPtr
->rangeValid
|=GDTR_MAX
;
778 GetSystemTime(&infoPtr
->todaysDate
);
779 MONTHCAL_CopyTime(&infoPtr
->todaysDate
, &infoPtr
->maxDate
);
782 if(wParam
& GDTR_MIN
) {
783 if(MONTHCAL_ValidateTime(lprgSysTimeArray
[0])) {
784 MONTHCAL_CopyTime(&lprgSysTimeArray
[0], &infoPtr
->maxDate
);
785 infoPtr
->rangeValid
|=GDTR_MIN
;
787 GetSystemTime(&infoPtr
->todaysDate
);
788 MONTHCAL_CopyTime(&infoPtr
->todaysDate
, &infoPtr
->maxDate
);
792 prev
= infoPtr
->monthRange
;
793 infoPtr
->monthRange
= infoPtr
->maxDate
.wMonth
- infoPtr
->minDate
.wMonth
;
795 if(infoPtr
->monthRange
!=prev
) {
796 COMCTL32_ReAlloc(infoPtr
->monthdayState
,
797 infoPtr
->monthRange
* sizeof(MONTHDAYSTATE
));
804 /* CHECKME: At the moment, we copy ranges anyway,regardless of
805 * infoPtr->rangeValid; a invalid range is simply filled with zeros in
806 * SetRange. Is this the right behavior?
810 MONTHCAL_GetRange(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
812 MONTHCAL_INFO
*infoPtr
= MONTHCAL_GetInfoPtr(hwnd
);
813 SYSTEMTIME
*lprgSysTimeArray
= (SYSTEMTIME
*)lParam
;
815 /* validate parameters */
817 if((infoPtr
==NULL
) || (lprgSysTimeArray
==NULL
)) return FALSE
;
819 MONTHCAL_CopyTime(&infoPtr
->maxDate
, &lprgSysTimeArray
[1]);
820 MONTHCAL_CopyTime(&infoPtr
->minDate
, &lprgSysTimeArray
[0]);
822 return infoPtr
->rangeValid
;
827 MONTHCAL_SetDayState(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
830 MONTHCAL_INFO
*infoPtr
= MONTHCAL_GetInfoPtr(hwnd
);
831 int i
, iMonths
= (int)wParam
;
832 MONTHDAYSTATE
*dayStates
= (LPMONTHDAYSTATE
)lParam
;
834 TRACE("%x %lx\n", wParam
, lParam
);
835 if(iMonths
!=infoPtr
->monthRange
) return 0;
837 for(i
=0; i
<iMonths
; i
++)
838 infoPtr
->monthdayState
[i
] = dayStates
[i
];
844 MONTHCAL_GetCurSel(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
846 MONTHCAL_INFO
*infoPtr
= MONTHCAL_GetInfoPtr(hwnd
);
847 SYSTEMTIME
*lpSel
= (SYSTEMTIME
*) lParam
;
849 TRACE("%x %lx\n", wParam
, lParam
);
850 if((infoPtr
==NULL
) ||(lpSel
==NULL
)) return FALSE
;
851 if(GetWindowLongA(hwnd
, GWL_STYLE
) & MCS_MULTISELECT
) return FALSE
;
853 MONTHCAL_CopyTime(&infoPtr
->minSel
, lpSel
);
858 /* FIXME: if the specified date is not visible, make it visible */
861 MONTHCAL_SetCurSel(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
863 MONTHCAL_INFO
*infoPtr
= MONTHCAL_GetInfoPtr(hwnd
);
864 SYSTEMTIME
*lpSel
= (SYSTEMTIME
*)lParam
;
866 TRACE("%x %lx\n", wParam
, lParam
);
867 if((infoPtr
==NULL
) ||(lpSel
==NULL
)) return FALSE
;
868 if(GetWindowLongA(hwnd
, GWL_STYLE
) & MCS_MULTISELECT
) return FALSE
;
870 TRACE("%d %d\n", lpSel
->wMonth
, lpSel
->wDay
);
872 MONTHCAL_CopyTime(lpSel
, &infoPtr
->minSel
);
873 MONTHCAL_CopyTime(lpSel
, &infoPtr
->maxSel
);
880 MONTHCAL_GetMaxSelCount(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
882 MONTHCAL_INFO
*infoPtr
= MONTHCAL_GetInfoPtr(hwnd
);
884 TRACE("%x %lx\n", wParam
, lParam
);
885 return infoPtr
->maxSelCount
;
890 MONTHCAL_SetMaxSelCount(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
892 MONTHCAL_INFO
*infoPtr
= MONTHCAL_GetInfoPtr(hwnd
);
894 TRACE("%x %lx\n", wParam
, lParam
);
895 if(GetWindowLongA(hwnd
, GWL_STYLE
) & MCS_MULTISELECT
) {
896 infoPtr
->maxSelCount
= wParam
;
904 MONTHCAL_GetSelRange(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
906 MONTHCAL_INFO
*infoPtr
= MONTHCAL_GetInfoPtr(hwnd
);
907 SYSTEMTIME
*lprgSysTimeArray
= (SYSTEMTIME
*) lParam
;
909 TRACE("%x %lx\n", wParam
, lParam
);
911 /* validate parameters */
913 if((infoPtr
==NULL
) ||(lprgSysTimeArray
==NULL
)) return FALSE
;
915 if(GetWindowLongA(hwnd
, GWL_STYLE
) & MCS_MULTISELECT
)
917 MONTHCAL_CopyTime(&infoPtr
->maxSel
, &lprgSysTimeArray
[1]);
918 MONTHCAL_CopyTime(&infoPtr
->minSel
, &lprgSysTimeArray
[0]);
919 TRACE("[min,max]=[%d %d]\n", infoPtr
->minSel
.wDay
, infoPtr
->maxSel
.wDay
);
928 MONTHCAL_SetSelRange(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
930 MONTHCAL_INFO
*infoPtr
= MONTHCAL_GetInfoPtr(hwnd
);
931 SYSTEMTIME
*lprgSysTimeArray
= (SYSTEMTIME
*) lParam
;
933 TRACE("%x %lx\n", wParam
, lParam
);
935 /* validate parameters */
937 if((infoPtr
==NULL
) ||(lprgSysTimeArray
==NULL
)) return FALSE
;
939 if(GetWindowLongA( hwnd
, GWL_STYLE
) & MCS_MULTISELECT
)
941 MONTHCAL_CopyTime(&lprgSysTimeArray
[1], &infoPtr
->maxSel
);
942 MONTHCAL_CopyTime(&lprgSysTimeArray
[0], &infoPtr
->minSel
);
943 TRACE("[min,max]=[%d %d]\n", infoPtr
->minSel
.wDay
, infoPtr
->maxSel
.wDay
);
952 MONTHCAL_GetToday(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
954 MONTHCAL_INFO
*infoPtr
= MONTHCAL_GetInfoPtr(hwnd
);
955 SYSTEMTIME
*lpToday
= (SYSTEMTIME
*) lParam
;
957 TRACE("%x %lx\n", wParam
, lParam
);
959 /* validate parameters */
961 if((infoPtr
==NULL
) || (lpToday
==NULL
)) return FALSE
;
962 MONTHCAL_CopyTime(&infoPtr
->todaysDate
, lpToday
);
968 MONTHCAL_SetToday(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
970 MONTHCAL_INFO
*infoPtr
= MONTHCAL_GetInfoPtr(hwnd
);
971 SYSTEMTIME
*lpToday
= (SYSTEMTIME
*) lParam
;
973 TRACE("%x %lx\n", wParam
, lParam
);
975 /* validate parameters */
977 if((infoPtr
==NULL
) ||(lpToday
==NULL
)) return FALSE
;
978 MONTHCAL_CopyTime(lpToday
, &infoPtr
->todaysDate
);
984 MONTHCAL_HitTest(HWND hwnd
, LPARAM lParam
)
986 MONTHCAL_INFO
*infoPtr
= MONTHCAL_GetInfoPtr(hwnd
);
987 PMCHITTESTINFO lpht
= (PMCHITTESTINFO
)lParam
;
993 retval
= MCHT_NOWHERE
;
996 /* are we in the header? */
998 if(PtInRect(&infoPtr
->title
, lpht
->pt
)) {
999 if(PtInRect(&infoPtr
->titlebtnprev
, lpht
->pt
)) {
1000 retval
= MCHT_TITLEBTNPREV
;
1003 if(PtInRect(&infoPtr
->titlebtnnext
, lpht
->pt
)) {
1004 retval
= MCHT_TITLEBTNNEXT
;
1007 if(PtInRect(&infoPtr
->titlemonth
, lpht
->pt
)) {
1008 retval
= MCHT_TITLEMONTH
;
1011 if(PtInRect(&infoPtr
->titleyear
, lpht
->pt
)) {
1012 retval
= MCHT_TITLEYEAR
;
1016 retval
= MCHT_TITLE
;
1020 if(PtInRect(&infoPtr
->days
, lpht
->pt
)) {
1021 retval
= MCHT_CALENDARDAY
; /* FIXME: find out which day we're on */
1024 if(PtInRect(&infoPtr
->weeknums
, lpht
->pt
)) {
1025 retval
= MCHT_CALENDARWEEKNUM
; /* FIXME: find out which day we're on */
1028 if(PtInRect(&infoPtr
->prevmonth
, lpht
->pt
)) {
1029 retval
= MCHT_CALENDARDATEPREV
;
1033 if(PtInRect(&infoPtr
->nextmonth
, lpht
->pt
) ||
1034 ((x
>infoPtr
->nextmonth
.left
) &&(x
<infoPtr
->nextmonth
.right
) &&
1035 (y
>infoPtr
->nextmonth
.bottom
) &&(y
<infoPtr
->today
.top
))) {
1036 retval
= MCHT_CALENDARDATENEXT
;
1040 if(PtInRect(&infoPtr
->today
, lpht
->pt
)) {
1041 retval
= MCHT_TODAYLINK
;
1045 /* MCHT_CALENDARDATE determination: since the next & previous month have
1046 * been handled already(MCHT_CALENDARDATEPREV/NEXT), we only have to check
1047 * whether we're in the calendar area. infoPtr->prevMonth.left handles the
1048 * MCS_WEEKNUMBERS style nicely.
1052 TRACE("%d %d [%d %d %d %d] [%d %d %d %d]\n", x
, y
,
1053 infoPtr
->prevmonth
.left
, infoPtr
->prevmonth
.right
,
1054 infoPtr
->prevmonth
.top
, infoPtr
->prevmonth
.bottom
,
1055 infoPtr
->nextmonth
.left
, infoPtr
->nextmonth
.right
,
1056 infoPtr
->nextmonth
.top
, infoPtr
->nextmonth
.bottom
);
1057 if((x
>infoPtr
->prevmonth
.left
) &&(x
<infoPtr
->nextmonth
.right
) &&
1058 (y
>infoPtr
->prevmonth
.top
) &&(y
<infoPtr
->nextmonth
.bottom
)) {
1059 lpht
->st
.wYear
= infoPtr
->currentYear
;
1060 lpht
->st
.wMonth
= infoPtr
->currentMonth
;
1062 lpht
->st
.wDay
= MONTHCAL_CalcDayFromPos(infoPtr
, x
, y
);
1064 TRACE("day hit: %d\n", lpht
->st
.wDay
);
1065 retval
= MCHT_CALENDARDATE
;
1070 /* Hit nothing special? What's left must be background :-) */
1072 retval
= MCHT_CALENDARBK
;
1074 lpht
->uHit
= retval
;
1079 static void MONTHCAL_GoToNextMonth(HWND hwnd
, MONTHCAL_INFO
*infoPtr
)
1081 DWORD dwStyle
= GetWindowLongA(hwnd
, GWL_STYLE
);
1083 TRACE("MONTHCAL_GoToNextMonth\n");
1085 infoPtr
->currentMonth
++;
1086 if(infoPtr
->currentMonth
> 12) {
1087 infoPtr
->currentYear
++;
1088 infoPtr
->currentMonth
= 1;
1091 if(dwStyle
& MCS_DAYSTATE
) {
1095 nmds
.nmhdr
.hwndFrom
= hwnd
;
1096 nmds
.nmhdr
.idFrom
= GetWindowLongA(hwnd
, GWL_ID
);
1097 nmds
.nmhdr
.code
= MCN_GETDAYSTATE
;
1098 nmds
.cDayState
= infoPtr
->monthRange
;
1099 nmds
.prgDayState
= COMCTL32_Alloc(infoPtr
->monthRange
* sizeof(MONTHDAYSTATE
));
1101 SendMessageA(GetParent(hwnd
), WM_NOTIFY
,
1102 (WPARAM
)nmds
.nmhdr
.idFrom
, (LPARAM
)&nmds
);
1103 for(i
=0; i
<infoPtr
->monthRange
; i
++)
1104 infoPtr
->monthdayState
[i
] = nmds
.prgDayState
[i
];
1109 static void MONTHCAL_GoToPrevMonth(HWND hwnd
, MONTHCAL_INFO
*infoPtr
)
1111 DWORD dwStyle
= GetWindowLongA(hwnd
, GWL_STYLE
);
1113 TRACE("MONTHCAL_GoToPrevMonth\n");
1115 infoPtr
->currentMonth
--;
1116 if(infoPtr
->currentMonth
< 1) {
1117 infoPtr
->currentYear
--;
1118 infoPtr
->currentMonth
= 12;
1121 if(dwStyle
& MCS_DAYSTATE
) {
1125 nmds
.nmhdr
.hwndFrom
= hwnd
;
1126 nmds
.nmhdr
.idFrom
= GetWindowLongA(hwnd
, GWL_ID
);
1127 nmds
.nmhdr
.code
= MCN_GETDAYSTATE
;
1128 nmds
.cDayState
= infoPtr
->monthRange
;
1129 nmds
.prgDayState
= COMCTL32_Alloc
1130 (infoPtr
->monthRange
* sizeof(MONTHDAYSTATE
));
1132 SendMessageA(GetParent(hwnd
), WM_NOTIFY
,
1133 (WPARAM
)nmds
.nmhdr
.idFrom
, (LPARAM
)&nmds
);
1134 for(i
=0; i
<infoPtr
->monthRange
; i
++)
1135 infoPtr
->monthdayState
[i
] = nmds
.prgDayState
[i
];
1141 MONTHCAL_LButtonDown(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1143 MONTHCAL_INFO
*infoPtr
= MONTHCAL_GetInfoPtr(hwnd
);
1149 BOOL redraw
= FALSE
;
1152 TRACE("%x %lx\n", wParam
, lParam
);
1154 ht
.pt
.x
= (INT
)LOWORD(lParam
);
1155 ht
.pt
.y
= (INT
)HIWORD(lParam
);
1156 hit
= MONTHCAL_HitTest(hwnd
, (LPARAM
)&ht
);
1158 /* FIXME: these flags should be checked by */
1159 /*((hit & MCHT_XXX) == MCHT_XXX) b/c some of the flags are */
1161 if(hit
& MCHT_NEXT
) {
1163 MONTHCAL_GoToNextMonth(hwnd
, infoPtr
);
1164 infoPtr
->status
= MC_NEXTPRESSED
;
1165 SetTimer(hwnd
, MC_NEXTMONTHTIMER
, MC_NEXTMONTHDELAY
, 0);
1167 if(hit
& MCHT_PREV
) {
1169 MONTHCAL_GoToPrevMonth(hwnd
, infoPtr
);
1170 infoPtr
->status
= MC_PREVPRESSED
;
1171 SetTimer(hwnd
, MC_PREVMONTHTIMER
, MC_NEXTMONTHDELAY
, 0);
1174 if(hit
== MCHT_TITLEMONTH
) {
1176 HRSRC hrsrc = FindResourceA( COMCTL32_hModule, MAKEINTRESOURCEA(IDD_MCMONTHMENU), RT_MENUA );
1178 TRACE("returning zero\n");
1181 TRACE("resource is:%x\n",hrsrc);
1182 hMenu = LoadMenuIndirectA((LPCVOID)LoadResource( COMCTL32_hModule, hrsrc ));
1184 TRACE("menu is:%x\n",hMenu);
1187 hMenu
= CreateMenu();
1188 AppendMenuA(hMenu
, MF_STRING
,IDM_JAN
, "January");
1189 AppendMenuA(hMenu
, MF_STRING
,IDM_FEB
, "February");
1190 AppendMenuA(hMenu
, MF_STRING
,IDM_MAR
, "March");
1192 retval
= CreateWindowA(POPUPMENU_CLASS_ATOM
, NULL
,
1193 WS_CHILD
| WS_VISIBLE
, 0, 0 ,100 , 220,
1194 hwnd
, hMenu
, GetWindowLongA(hwnd
, GWL_HINSTANCE
), NULL
);
1195 TRACE("hwnd returned:%x\n", retval
);
1198 if(hit
== MCHT_TITLEYEAR
) {
1199 FIXME("create updown for yearselection\n");
1201 if(hit
== MCHT_TODAYLINK
) {
1202 FIXME("set currentday\n");
1204 if(hit
== MCHT_CALENDARDATE
) {
1205 SYSTEMTIME selArray
[2];
1209 nmsc
.nmhdr
.hwndFrom
= hwnd
;
1210 nmsc
.nmhdr
.idFrom
= GetWindowLongA(hwnd
, GWL_ID
);
1211 nmsc
.nmhdr
.code
= MCN_SELCHANGE
;
1212 MONTHCAL_CopyTime(&nmsc
.stSelStart
, &infoPtr
->minSel
);
1213 MONTHCAL_CopyTime(&nmsc
.stSelEnd
, &infoPtr
->maxSel
);
1215 SendMessageA(GetParent(hwnd
), WM_NOTIFY
,
1216 (WPARAM
)nmsc
.nmhdr
.idFrom
,(LPARAM
)&nmsc
);
1218 MONTHCAL_CopyTime(&ht
.st
, &selArray
[0]);
1219 MONTHCAL_CopyTime(&ht
.st
, &selArray
[1]);
1220 MONTHCAL_SetSelRange(hwnd
,0,(LPARAM
) &selArray
);
1222 /* redraw if the selected day changed */
1223 if(infoPtr
->curSelDay
!= ht
.st
.wDay
) {
1227 infoPtr
->firstSelDay
= ht
.st
.wDay
;
1228 infoPtr
->curSelDay
= ht
.st
.wDay
;
1229 infoPtr
->status
= MC_SEL_LBUTDOWN
;
1232 /* redraw only if the control changed */
1235 MONTHCAL_Refresh(hwnd
, hdc
);
1236 ReleaseDC(hwnd
, hdc
);
1244 MONTHCAL_LButtonUp(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1246 MONTHCAL_INFO
*infoPtr
= MONTHCAL_GetInfoPtr(hwnd
);
1250 BOOL redraw
= FALSE
;
1254 if(infoPtr
->status
& MC_NEXTPRESSED
) {
1255 KillTimer(hwnd
, MC_NEXTMONTHTIMER
);
1258 if(infoPtr
->status
& MC_PREVPRESSED
) {
1259 KillTimer(hwnd
, MC_PREVMONTHTIMER
);
1263 infoPtr
->status
= MC_SEL_LBUTUP
;
1265 nmhdr
.hwndFrom
= hwnd
;
1266 nmhdr
.idFrom
= GetWindowLongA( hwnd
, GWL_ID
);
1267 nmhdr
.code
= NM_RELEASEDCAPTURE
;
1268 TRACE("Sent notification from %x to %x\n", hwnd
, GetParent(hwnd
));
1270 SendMessageA(GetParent(hwnd
), WM_NOTIFY
,
1271 (WPARAM
)nmhdr
.idFrom
, (LPARAM
)&nmhdr
);
1273 nmsc
.nmhdr
.hwndFrom
= hwnd
;
1274 nmsc
.nmhdr
.idFrom
= GetWindowLongA(hwnd
, GWL_ID
);
1275 nmsc
.nmhdr
.code
= MCN_SELECT
;
1276 MONTHCAL_CopyTime(&nmsc
.stSelStart
, &infoPtr
->minSel
);
1277 MONTHCAL_CopyTime(&nmsc
.stSelEnd
, &infoPtr
->maxSel
);
1279 SendMessageA(GetParent(hwnd
), WM_NOTIFY
,
1280 (WPARAM
)nmsc
.nmhdr
.idFrom
, (LPARAM
)&nmsc
);
1282 /* redraw if necessary */
1285 MONTHCAL_Refresh(hwnd
, hdc
);
1286 ReleaseDC(hwnd
, hdc
);
1294 MONTHCAL_Timer(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1296 MONTHCAL_INFO
*infoPtr
= MONTHCAL_GetInfoPtr(hwnd
);
1298 BOOL redraw
= FALSE
;
1300 TRACE(" %d\n", wParam
);
1301 if(!infoPtr
) return 0;
1304 case MC_NEXTMONTHTIMER
:
1306 MONTHCAL_GoToNextMonth(hwnd
, infoPtr
);
1308 case MC_PREVMONTHTIMER
:
1310 MONTHCAL_GoToPrevMonth(hwnd
, infoPtr
);
1313 ERR("got unknown timer\n");
1316 /* redraw only if necessary */
1319 MONTHCAL_Refresh(hwnd
, hdc
);
1320 ReleaseDC(hwnd
, hdc
);
1328 MONTHCAL_MouseMove(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1330 MONTHCAL_INFO
*infoPtr
= MONTHCAL_GetInfoPtr(hwnd
);
1333 int oldselday
, selday
, hit
;
1336 if(!(infoPtr
->status
& MC_SEL_LBUTDOWN
)) return 0;
1338 ht
.pt
.x
= LOWORD(lParam
);
1339 ht
.pt
.y
= HIWORD(lParam
);
1341 hit
= MONTHCAL_HitTest(hwnd
, (LPARAM
)&ht
);
1343 /* not on the calendar date numbers? bail out */
1344 TRACE("hit:%x\n",hit
);
1345 if((hit
& MCHT_CALENDARDATE
) != MCHT_CALENDARDATE
) return 0;
1347 selday
= ht
.st
.wDay
;
1348 oldselday
= infoPtr
->curSelDay
;
1349 infoPtr
->curSelDay
= selday
;
1350 MONTHCAL_CalcPosFromDay(infoPtr
, selday
, ht
.st
. wMonth
, &r
);
1352 if(GetWindowLongA(hwnd
, GWL_STYLE
) & MCS_MULTISELECT
) {
1353 SYSTEMTIME selArray
[2];
1356 MONTHCAL_GetSelRange(hwnd
, 0, (LPARAM
)&selArray
);
1358 if(infoPtr
->firstSelDay
==selArray
[0].wDay
) i
=1;
1359 TRACE("oldRange:%d %d %d %d\n", infoPtr
->firstSelDay
, selArray
[0].wDay
, selArray
[1].wDay
, i
);
1360 if(infoPtr
->firstSelDay
==selArray
[1].wDay
) {
1361 /* 1st time we get here: selArray[0]=selArray[1]) */
1362 /* if we're still at the first selected date, return */
1363 if(infoPtr
->firstSelDay
==selday
) goto done
;
1364 if(selday
<infoPtr
->firstSelDay
) i
= 0;
1367 if(abs(infoPtr
->firstSelDay
- selday
) >= infoPtr
->maxSelCount
) {
1368 if(selday
>infoPtr
->firstSelDay
)
1369 selday
= infoPtr
->firstSelDay
+ infoPtr
->maxSelCount
;
1371 selday
= infoPtr
->firstSelDay
- infoPtr
->maxSelCount
;
1374 if(selArray
[i
].wDay
!=selday
) {
1375 TRACE("newRange:%d %d %d %d\n", infoPtr
->firstSelDay
, selArray
[0].wDay
, selArray
[1].wDay
, i
);
1377 selArray
[i
].wDay
= selday
;
1379 if(selArray
[0].wDay
>selArray
[1].wDay
) {
1381 tempday
= selArray
[1].wDay
;
1382 selArray
[1].wDay
= selArray
[0].wDay
;
1383 selArray
[0].wDay
= tempday
;
1386 MONTHCAL_SetSelRange(hwnd
, 0, (LPARAM
)&selArray
);
1392 /* only redraw if the currently selected day changed */
1393 if(oldselday
!= infoPtr
->curSelDay
) {
1395 MONTHCAL_Refresh(hwnd
, hdc
);
1396 ReleaseDC(hwnd
, hdc
);
1404 MONTHCAL_Paint(HWND hwnd
, WPARAM wParam
)
1409 hdc
= (wParam
==0 ? BeginPaint(hwnd
, &ps
) : (HDC
)wParam
);
1410 MONTHCAL_Refresh(hwnd
, hdc
);
1411 if(!wParam
) EndPaint(hwnd
, &ps
);
1417 MONTHCAL_KillFocus(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1424 MONTHCAL_Refresh(hwnd
, hdc
);
1425 ReleaseDC(hwnd
, hdc
);
1426 InvalidateRect(hwnd
, NULL
, TRUE
);
1433 MONTHCAL_SetFocus(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1440 MONTHCAL_Refresh(hwnd
, hdc
);
1441 ReleaseDC(hwnd
, hdc
);
1446 /* sets the size information */
1447 static void MONTHCAL_UpdateSize(HWND hwnd
)
1449 HDC hdc
= GetDC(hwnd
);
1450 MONTHCAL_INFO
*infoPtr
= MONTHCAL_GetInfoPtr(hwnd
);
1451 RECT
*rcClient
=&infoPtr
->rcClient
;
1452 RECT
*rcDraw
=&infoPtr
->rcDraw
;
1453 RECT
*title
=&infoPtr
->title
;
1454 RECT
*prev
=&infoPtr
->titlebtnprev
;
1455 RECT
*next
=&infoPtr
->titlebtnnext
;
1456 RECT
*titlemonth
=&infoPtr
->titlemonth
;
1457 RECT
*titleyear
=&infoPtr
->titleyear
;
1458 RECT
*days
=&infoPtr
->days
;
1461 DWORD dwStyle
= GetWindowLongA(hwnd
, GWL_STYLE
);
1464 currentFont
= SelectObject(hdc
, infoPtr
->hFont
);
1466 /* FIXME: need a way to determine current font, without setting it */
1468 if(infoPtr->hFont!=currentFont) {
1469 SelectObject(hdc, currentFont);
1470 infoPtr->hFont=currentFont;
1471 GetObjectA(currentFont, sizeof(LOGFONTA), &logFont);
1472 logFont.lfWeight=FW_BOLD;
1473 infoPtr->hBoldFont = CreateFontIndirectA(&logFont);
1477 /* get the height and width of each day's text */
1478 GetTextMetricsA(hdc
, &tm
);
1479 infoPtr
->textHeight
= tm
.tmHeight
+ tm
.tmExternalLeading
;
1480 GetTextExtentPoint32A(hdc
, "Sun", 3, &size
);
1481 infoPtr
->textWidth
= size
.cx
+ 2;
1483 /* retrieve the controls client rectangle info infoPtr->rcClient */
1484 GetClientRect(hwnd
, rcClient
);
1486 if(dwStyle
& MCS_WEEKNUMBERS
)
1487 infoPtr
->rcClient
.right
+=infoPtr
->textWidth
;
1489 /* rcDraw is the rectangle the control is drawn in */
1490 rcDraw
->left
= rcClient
->left
;
1491 rcDraw
->right
= rcClient
->right
;
1492 rcDraw
->top
= rcClient
->top
;
1493 rcDraw
->bottom
= rcClient
->bottom
;
1495 /* use DrawEdge to adjust the size of rcClient such that we */
1496 /* do not overwrite the border when drawing the control */
1497 DrawEdge((HDC
)NULL
, rcDraw
, EDGE_SUNKEN
, BF_RECT
| BF_ADJUST
);
1500 /* this is correct, the control does NOT expand vertically */
1501 /* like it does horizontally */
1502 /* make sure we don't move the controls bottom out of the client */
1504 if((rcDraw
->top
+ 8 * infoPtr
->textHeight
+ 5) < rcDraw
->bottom
) {
1505 rcDraw
->bottom
= rcDraw
->top
+ 8 * infoPtr
->textHeight
+ 5;
1508 /* calculate title area */
1509 title
->top
= rcClient
->top
+ 1;
1510 title
->bottom
= title
->top
+ 2 * infoPtr
->textHeight
+ 4;
1511 title
->left
= rcClient
->left
+ 1;
1512 title
->right
= rcClient
->right
- 1;
1514 /* recalculate the height and width increments and offsets */
1515 infoPtr
->width_increment
= (infoPtr
->rcDraw
.right
- infoPtr
->rcDraw
.left
) / 7.0;
1516 infoPtr
->height_increment
= (infoPtr
->rcDraw
.bottom
- infoPtr
->rcDraw
.top
) / 7.0;
1517 infoPtr
->left_offset
= (infoPtr
->rcDraw
.right
- infoPtr
->rcDraw
.left
) - (infoPtr
->width_increment
* 7.0);
1518 infoPtr
->top_offset
= (infoPtr
->rcDraw
.bottom
- infoPtr
->rcDraw
.top
) - (infoPtr
->height_increment
* 7.0);
1520 /* set the dimensions of the next and previous buttons and center */
1521 /* the month text vertically */
1522 prev
->top
= next
->top
= title
->top
+ 6;
1523 prev
->bottom
= next
->bottom
= title
->top
+ 2 * infoPtr
->textHeight
- 3;
1524 prev
->right
= title
->left
+ 28;
1525 prev
->left
= title
->left
+ 4;
1526 next
->left
= title
->right
- 28;
1527 next
->right
= title
->right
- 4;
1529 /* titlemonth->left and right change based upon the current month */
1530 /* and are recalculated in refresh as the current month may change */
1531 /* without the control being resized */
1532 titlemonth
->bottom
= titleyear
->bottom
= prev
->top
+ 2 * infoPtr
->textHeight
- 3;
1533 titlemonth
->top
= titleyear
->top
= title
->top
;
1535 /* setup the dimensions of the rectangle we draw the names of the */
1536 /* days of the week in */
1537 days
->left
= infoPtr
->left_offset
;
1538 if(dwStyle
& MCS_WEEKNUMBERS
) days
->left
+=infoPtr
->textWidth
;
1539 days
->right
= days
->left
+ infoPtr
->width_increment
;
1540 days
->top
= title
->bottom
+ 2;
1541 days
->bottom
= title
->bottom
+ infoPtr
->textHeight
+ 2;
1543 /* restore the originally selected font */
1544 SelectObject(hdc
, currentFont
);
1546 ReleaseDC(hwnd
, hdc
);
1549 static LRESULT
MONTHCAL_Size(HWND hwnd
, int Width
, int Height
)
1551 TRACE("(hwnd=%x, width=%d, height=%d)\n", hwnd
, Width
, Height
);
1553 MONTHCAL_UpdateSize(hwnd
);
1555 /* invalidate client area and erase background */
1556 InvalidateRect(hwnd
, NULL
, TRUE
);
1561 /* FIXME: check whether dateMin/dateMax need to be adjusted. */
1563 MONTHCAL_Create(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1565 MONTHCAL_INFO
*infoPtr
;
1568 /* allocate memory for info structure */
1569 infoPtr
=(MONTHCAL_INFO
*)COMCTL32_Alloc(sizeof(MONTHCAL_INFO
));
1570 SetWindowLongA(hwnd
, 0, (DWORD
)infoPtr
);
1572 if(infoPtr
== NULL
) {
1573 ERR( "could not allocate info memory!\n");
1576 if((MONTHCAL_INFO
*)GetWindowLongA(hwnd
, 0) != infoPtr
) {
1577 ERR( "pointer assignment error!\n");
1581 infoPtr
->hFont
= GetStockObject(DEFAULT_GUI_FONT
);
1582 GetObjectA(infoPtr
->hFont
, sizeof(LOGFONTA
), &logFont
);
1583 logFont
.lfWeight
= FW_BOLD
;
1584 infoPtr
->hBoldFont
= CreateFontIndirectA(&logFont
);
1586 /* initialize info structure */
1587 /* FIXME: calculate systemtime ->> localtime(substract timezoneinfo) */
1589 GetSystemTime(&infoPtr
->todaysDate
);
1590 infoPtr
->firstDay
= 0;
1591 infoPtr
->currentMonth
= infoPtr
->todaysDate
.wMonth
;
1592 infoPtr
->currentYear
= infoPtr
->todaysDate
.wYear
;
1593 MONTHCAL_CopyTime(&infoPtr
->todaysDate
, &infoPtr
->minDate
);
1594 MONTHCAL_CopyTime(&infoPtr
->todaysDate
, &infoPtr
->maxDate
);
1595 infoPtr
->maxSelCount
= 6;
1596 infoPtr
->monthRange
= 3;
1597 infoPtr
->monthdayState
= COMCTL32_Alloc
1598 (infoPtr
->monthRange
* sizeof(MONTHDAYSTATE
));
1599 infoPtr
->titlebk
= GetSysColor(COLOR_ACTIVECAPTION
);
1600 infoPtr
->titletxt
= GetSysColor(COLOR_WINDOW
);
1601 infoPtr
->monthbk
= GetSysColor(COLOR_WINDOW
);
1602 infoPtr
->trailingtxt
= GetSysColor(COLOR_GRAYTEXT
);
1603 infoPtr
->bk
= GetSysColor(COLOR_WINDOW
);
1604 infoPtr
->txt
= GetSysColor(COLOR_WINDOWTEXT
);
1606 /* call MONTHCAL_UpdateSize to set all of the dimensions */
1607 /* of the control */
1608 MONTHCAL_UpdateSize(hwnd
);
1615 MONTHCAL_Destroy(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1617 MONTHCAL_INFO
*infoPtr
= MONTHCAL_GetInfoPtr(hwnd
);
1619 /* free month calendar info data */
1620 COMCTL32_Free(infoPtr
);
1626 static LRESULT WINAPI
1627 MONTHCAL_WindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1632 return MONTHCAL_GetCurSel(hwnd
, wParam
, lParam
);
1635 return MONTHCAL_SetCurSel(hwnd
, wParam
, lParam
);
1637 case MCM_GETMAXSELCOUNT
:
1638 return MONTHCAL_GetMaxSelCount(hwnd
, wParam
, lParam
);
1640 case MCM_SETMAXSELCOUNT
:
1641 return MONTHCAL_SetMaxSelCount(hwnd
, wParam
, lParam
);
1643 case MCM_GETSELRANGE
:
1644 return MONTHCAL_GetSelRange(hwnd
, wParam
, lParam
);
1646 case MCM_SETSELRANGE
:
1647 return MONTHCAL_SetSelRange(hwnd
, wParam
, lParam
);
1649 case MCM_GETMONTHRANGE
:
1650 return MONTHCAL_GetMonthRange(hwnd
, wParam
, lParam
);
1652 case MCM_SETDAYSTATE
:
1653 return MONTHCAL_SetDayState(hwnd
, wParam
, lParam
);
1655 case MCM_GETMINREQRECT
:
1656 return MONTHCAL_GetMinReqRect(hwnd
, wParam
, lParam
);
1659 return MONTHCAL_GetColor(hwnd
, wParam
, lParam
);
1662 return MONTHCAL_SetColor(hwnd
, wParam
, lParam
);
1665 return MONTHCAL_GetToday(hwnd
, wParam
, lParam
);
1668 return MONTHCAL_SetToday(hwnd
, wParam
, lParam
);
1671 return MONTHCAL_HitTest(hwnd
,lParam
);
1673 case MCM_GETFIRSTDAYOFWEEK
:
1674 return MONTHCAL_GetFirstDayOfWeek(hwnd
, wParam
, lParam
);
1676 case MCM_SETFIRSTDAYOFWEEK
:
1677 return MONTHCAL_SetFirstDayOfWeek(hwnd
, wParam
, lParam
);
1680 return MONTHCAL_GetRange(hwnd
, wParam
, lParam
);
1683 return MONTHCAL_SetRange(hwnd
, wParam
, lParam
);
1685 case MCM_GETMONTHDELTA
:
1686 return MONTHCAL_GetMonthDelta(hwnd
, wParam
, lParam
);
1688 case MCM_SETMONTHDELTA
:
1689 return MONTHCAL_SetMonthDelta(hwnd
, wParam
, lParam
);
1691 case MCM_GETMAXTODAYWIDTH
:
1692 return MONTHCAL_GetMaxTodayWidth(hwnd
);
1695 return DLGC_WANTARROWS
| DLGC_WANTCHARS
;
1698 return MONTHCAL_KillFocus(hwnd
, wParam
, lParam
);
1700 case WM_LBUTTONDOWN
:
1701 return MONTHCAL_LButtonDown(hwnd
, wParam
, lParam
);
1704 return MONTHCAL_MouseMove(hwnd
, wParam
, lParam
);
1707 return MONTHCAL_LButtonUp(hwnd
, wParam
, lParam
);
1710 return MONTHCAL_Paint(hwnd
, wParam
);
1713 return MONTHCAL_SetFocus(hwnd
, wParam
, lParam
);
1716 return MONTHCAL_Size(hwnd
, (int)SLOWORD(lParam
), (int)SHIWORD(lParam
));
1719 return MONTHCAL_Create(hwnd
, wParam
, lParam
);
1722 return MONTHCAL_Timer(hwnd
, wParam
, lParam
);
1725 return MONTHCAL_Destroy(hwnd
, wParam
, lParam
);
1729 ERR( "unknown msg %04x wp=%08x lp=%08lx\n", uMsg
, wParam
, lParam
);
1730 return DefWindowProcA(hwnd
, uMsg
, wParam
, lParam
);
1737 MONTHCAL_Register(void)
1741 if(GlobalFindAtomA(MONTHCAL_CLASSA
)) return;
1743 ZeroMemory(&wndClass
, sizeof(WNDCLASSA
));
1744 wndClass
.style
= CS_GLOBALCLASS
;
1745 wndClass
.lpfnWndProc
= (WNDPROC
)MONTHCAL_WindowProc
;
1746 wndClass
.cbClsExtra
= 0;
1747 wndClass
.cbWndExtra
= sizeof(MONTHCAL_INFO
*);
1748 wndClass
.hCursor
= LoadCursorA(0, IDC_ARROWA
);
1749 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
1750 wndClass
.lpszClassName
= MONTHCAL_CLASSA
;
1752 RegisterClassA(&wndClass
);
1757 MONTHCAL_Unregister(void)
1759 if(GlobalFindAtomA(MONTHCAL_CLASSA
))
1760 UnregisterClassA(MONTHCAL_CLASSA
, (HINSTANCE
)NULL
);