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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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
36 * -- handle resources better (doesn't work now);
37 * -- take care of internationalization.
38 * -- keyboard handling.
57 #include "wine/unicode.h"
58 #include "wine/debug.h"
60 WINE_DEFAULT_DEBUG_CHANNEL(monthcal
);
62 #define MC_SEL_LBUTUP 1 /* Left button released */
63 #define MC_SEL_LBUTDOWN 2 /* Left button pressed in calendar */
64 #define MC_PREVPRESSED 4 /* Prev month button pressed */
65 #define MC_NEXTPRESSED 8 /* Next month button pressed */
66 #define MC_NEXTMONTHDELAY 350 /* when continuously pressing `next */
67 /* month', wait 500 ms before going */
68 /* to the next month */
69 #define MC_NEXTMONTHTIMER 1 /* Timer ID's */
70 #define MC_PREVMONTHTIMER 2
72 #define countof(arr) (sizeof(arr)/sizeof(arr[0]))
77 DWORD dwStyle
; /* cached GWL_STYLE */
90 int firstDayplace
; /* place of the first day of the current month */
91 INT delta
; /* scroll rate; # of months that the */
92 /* control moves when user clicks a scroll button */
93 int visible
; /* # of months visible */
94 int firstDay
; /* Start month calendar with firstDay's day */
95 int firstDayHighWord
; /* High word only used externally */
97 MONTHDAYSTATE
*monthdayState
;
98 SYSTEMTIME todaysDate
;
99 int status
; /* See MC_SEL flags */
100 int firstSelDay
; /* first selected day */
104 SYSTEMTIME curSel
; /* contains currently selected year, month and day */
109 RECT title
; /* rect for the header above the calendar */
110 RECT titlebtnnext
; /* the `next month' button in the header */
111 RECT titlebtnprev
; /* the `prev month' button in the header */
112 RECT titlemonth
; /* the `month name' txt in the header */
113 RECT titleyear
; /* the `year number' txt in the header */
114 RECT wdays
; /* week days at top */
115 RECT days
; /* calendar area */
116 RECT weeknums
; /* week numbers at left side */
117 RECT todayrect
; /* `today: xx/xx/xx' text rect */
118 HWND hwndNotify
; /* Window to receive the notifications */
119 HWND hWndYearEdit
; /* Window Handle of edit box to handle years */
120 HWND hWndYearUpDown
;/* Window Handle of updown box to handle years */
121 } MONTHCAL_INFO
, *LPMONTHCAL_INFO
;
124 /* Offsets of days in the week to the weekday of january 1 in a leap year */
125 static const int DayOfWeekTable
[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
127 static const WCHAR themeClass
[] = { 'S','c','r','o','l','l','b','a','r',0 };
129 #define MONTHCAL_GetInfoPtr(hwnd) ((MONTHCAL_INFO *)GetWindowLongPtrW(hwnd, 0))
131 /* helper functions */
133 /* returns the number of days in any given month, checking for leap days */
134 /* january is 1, december is 12 */
135 int MONTHCAL_MonthLength(int month
, int year
)
137 const int mdays
[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 0};
138 /*Wrap around, this eases handling*/
144 /* if we have a leap year add 1 day to February */
145 /* a leap year is a year either divisible by 400 */
146 /* or divisible by 4 and not by 100 */
147 if(month
== 2) { /* February */
148 return mdays
[month
- 1] + ((year
%400 == 0) ? 1 : ((year
%100 != 0) &&
149 (year
%4 == 0)) ? 1 : 0);
152 return mdays
[month
- 1];
156 /* compares timestamps using date part only */
157 static inline BOOL
MONTHCAL_IsDateEqual(const SYSTEMTIME
*first
, const SYSTEMTIME
*second
)
159 return (first
->wYear
== second
->wYear
) && (first
->wMonth
== second
->wMonth
) &&
160 (first
->wDay
== second
->wDay
);
163 /* make sure that date fields are valid */
164 static BOOL
MONTHCAL_ValidateDate(const SYSTEMTIME
*time
)
166 if(time
->wMonth
< 1 || time
->wMonth
> 12 ) return FALSE
;
167 if(time
->wDayOfWeek
> 6) return FALSE
;
168 if(time
->wDay
> MONTHCAL_MonthLength(time
->wMonth
, time
->wYear
))
174 /* Used in MCM_SETRANGE/MCM_SETSELRANGE to determine resulting time part.
175 Milliseconds are intentionaly not validated. */
176 static BOOL
MONTHCAL_ValidateTime(const SYSTEMTIME
*time
)
178 if((time
->wHour
> 24) || (time
->wMinute
> 59) || (time
->wSecond
> 59))
184 /* Copies timestamp part only. Milliseconds are intentionaly not copied
185 cause it matches required behaviour for current use of this helper */
186 static void MONTHCAL_CopyTime(const SYSTEMTIME
*from
, SYSTEMTIME
*to
)
188 to
->wHour
= from
->wHour
;
189 to
->wMinute
= from
->wMinute
;
190 to
->wSecond
= from
->wSecond
;
193 /* Note:Depending on DST, this may be offset by a day.
194 Need to find out if we're on a DST place & adjust the clock accordingly.
195 Above function assumes we have a valid data.
196 Valid for year>1752; 1 <= d <= 31, 1 <= m <= 12.
200 /* returns the day in the week(0 == sunday, 6 == saturday) */
201 /* day(1 == 1st, 2 == 2nd... etc), year is the year value */
202 static int MONTHCAL_CalculateDayOfWeek(DWORD day
, DWORD month
, DWORD year
)
206 return((year
+ year
/4 - year
/100 + year
/400 +
207 DayOfWeekTable
[month
-1] + day
) % 7);
210 /* From a given point, calculate the row (weekpos), column(daypos)
211 and day in the calendar. day== 0 mean the last day of tha last month
213 static int MONTHCAL_CalcDayFromPos(const MONTHCAL_INFO
*infoPtr
, int x
, int y
,
214 int *daypos
,int *weekpos
)
216 int retval
, firstDay
;
219 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
221 /* if the point is outside the x bounds of the window put
222 it at the boundary */
223 if (x
> rcClient
.right
)
227 *daypos
= (x
- infoPtr
->days
.left
) / infoPtr
->width_increment
;
228 *weekpos
= (y
- infoPtr
->days
.top
) / infoPtr
->height_increment
;
230 firstDay
= (MONTHCAL_CalculateDayOfWeek(1, infoPtr
->curSel
.wMonth
, infoPtr
->curSel
.wYear
)+6 - infoPtr
->firstDay
)%7;
231 retval
= *daypos
+ (7 * *weekpos
) - firstDay
;
235 /* day is the day of the month, 1 == 1st day of the month */
236 /* sets x and y to be the position of the day */
237 /* x == day, y == week where(0,0) == firstDay, 1st week */
238 static void MONTHCAL_CalcDayXY(const MONTHCAL_INFO
*infoPtr
, int day
, int month
,
241 int firstDay
, prevMonth
;
243 firstDay
= (MONTHCAL_CalculateDayOfWeek(1, infoPtr
->curSel
.wMonth
, infoPtr
->curSel
.wYear
) +6 - infoPtr
->firstDay
)%7;
245 if(month
==infoPtr
->curSel
.wMonth
) {
246 *x
= (day
+ firstDay
) % 7;
247 *y
= (day
+ firstDay
- *x
) / 7;
250 if(month
< infoPtr
->curSel
.wMonth
) {
251 prevMonth
= month
- 1;
255 *x
= (MONTHCAL_MonthLength(prevMonth
, infoPtr
->curSel
.wYear
) - firstDay
) % 7;
260 *y
= MONTHCAL_MonthLength(month
, infoPtr
->curSel
.wYear
- 1) / 7;
261 *x
= (day
+ firstDay
+ MONTHCAL_MonthLength(month
,
262 infoPtr
->curSel
.wYear
)) % 7;
266 /* x: column(day), y: row(week) */
267 static void MONTHCAL_CalcDayRect(const MONTHCAL_INFO
*infoPtr
, RECT
*r
, int x
, int y
)
269 r
->left
= infoPtr
->days
.left
+ x
* infoPtr
->width_increment
;
270 r
->right
= r
->left
+ infoPtr
->width_increment
;
271 r
->top
= infoPtr
->days
.top
+ y
* infoPtr
->height_increment
;
272 r
->bottom
= r
->top
+ infoPtr
->textHeight
;
276 /* sets the RECT struct r to the rectangle around the day and month */
277 /* day is the day value of the month(1 == 1st), month is the month */
278 /* value(january == 1, december == 12) */
279 static inline void MONTHCAL_CalcPosFromDay(const MONTHCAL_INFO
*infoPtr
,
280 int day
, int month
, RECT
*r
)
284 MONTHCAL_CalcDayXY(infoPtr
, day
, month
, &x
, &y
);
285 MONTHCAL_CalcDayRect(infoPtr
, r
, x
, y
);
289 /* day is the day in the month(1 == 1st of the month) */
290 /* month is the month value(1 == january, 12 == december) */
291 static void MONTHCAL_CircleDay(const MONTHCAL_INFO
*infoPtr
, HDC hdc
, int day
, int month
)
293 HPEN hRedPen
= CreatePen(PS_SOLID
, 1, RGB(255, 0, 0));
294 HPEN hOldPen2
= SelectObject(hdc
, hRedPen
);
298 MONTHCAL_CalcPosFromDay(infoPtr
, day
, month
, &day_rect
);
300 hOldBrush
= SelectObject(hdc
, GetStockObject(NULL_BRUSH
));
301 Rectangle(hdc
, day_rect
.left
, day_rect
.top
, day_rect
.right
, day_rect
.bottom
);
303 SelectObject(hdc
, hOldBrush
);
304 DeleteObject(hRedPen
);
305 SelectObject(hdc
, hOldPen2
);
308 static void MONTHCAL_DrawDay(const MONTHCAL_INFO
*infoPtr
, HDC hdc
, int day
, int month
,
309 int x
, int y
, int bold
)
311 static const WCHAR fmtW
[] = { '%','d',0 };
314 static BOOL haveBoldFont
, haveSelectedDay
= FALSE
;
319 wsprintfW(buf
, fmtW
, day
);
321 /* No need to check styles: when selection is not valid, it is set to zero.
322 * 1<day<31, so everything is OK.
325 MONTHCAL_CalcDayRect(infoPtr
, &r
, x
, y
);
327 if((day
>=infoPtr
->minSel
.wDay
) && (day
<=infoPtr
->maxSel
.wDay
)
328 && (month
== infoPtr
->curSel
.wMonth
)) {
331 TRACE("%d %d %d\n",day
, infoPtr
->minSel
.wDay
, infoPtr
->maxSel
.wDay
);
332 TRACE("%s\n", wine_dbgstr_rect(&r
));
333 oldCol
= SetTextColor(hdc
, infoPtr
->monthbk
);
334 oldBk
= SetBkColor(hdc
, infoPtr
->trailingtxt
);
335 hbr
= GetSysColorBrush(COLOR_HIGHLIGHT
);
336 FillRect(hdc
, &r
, hbr
);
338 /* FIXME: this may need to be changed now b/c of the other
339 drawing changes 11/3/99 CMM */
340 r2
.left
= r
.left
- 0.25 * infoPtr
->textWidth
;
342 r2
.right
= r
.left
+ 0.5 * infoPtr
->textWidth
;
343 r2
.bottom
= r
.bottom
;
344 if(haveSelectedDay
) FillRect(hdc
, &r2
, hbr
);
345 haveSelectedDay
= TRUE
;
347 haveSelectedDay
= FALSE
;
350 /* need to add some code for multiple selections */
352 if((bold
) &&(!haveBoldFont
)) {
353 SelectObject(hdc
, infoPtr
->hBoldFont
);
356 if((!bold
) &&(haveBoldFont
)) {
357 SelectObject(hdc
, infoPtr
->hFont
);
358 haveBoldFont
= FALSE
;
361 SetBkMode(hdc
,TRANSPARENT
);
362 DrawTextW(hdc
, buf
, -1, &r
, DT_CENTER
| DT_VCENTER
| DT_SINGLELINE
);
364 if(haveSelectedDay
) {
365 SetTextColor(hdc
, oldCol
);
366 SetBkColor(hdc
, oldBk
);
369 /* draw a rectangle around the currently selected days text */
370 if((day
== infoPtr
->curSel
.wDay
) && (month
== infoPtr
->curSel
.wMonth
))
371 DrawFocusRect(hdc
, &r
);
375 static void paint_button (const MONTHCAL_INFO
*infoPtr
, HDC hdc
, BOOL btnNext
,
376 BOOL pressed
, RECT
* r
)
378 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
382 static const int states
[] = {
384 ABS_LEFTNORMAL
, ABS_LEFTPRESSED
, ABS_LEFTDISABLED
,
386 ABS_RIGHTNORMAL
, ABS_RIGHTPRESSED
, ABS_RIGHTDISABLED
388 int stateNum
= btnNext
? 3 : 0;
393 if (infoPtr
->dwStyle
& WS_DISABLED
) stateNum
+= 2;
395 DrawThemeBackground (theme
, hdc
, SBP_ARROWBTN
, states
[stateNum
], r
, NULL
);
399 int style
= btnNext
? DFCS_SCROLLRIGHT
: DFCS_SCROLLLEFT
;
401 style
|= DFCS_PUSHED
;
404 if (infoPtr
->dwStyle
& WS_DISABLED
) style
|= DFCS_INACTIVE
;
407 DrawFrameControl(hdc
, r
, DFC_SCROLL
, style
);
412 static void MONTHCAL_Refresh(MONTHCAL_INFO
*infoPtr
, HDC hdc
, const PAINTSTRUCT
*ps
)
414 static const WCHAR todayW
[] = { 'T','o','d','a','y',':',0 };
415 static const WCHAR fmt1W
[] = { '%','s',' ','%','l','d',0 };
416 static const WCHAR fmt2W
[] = { '%','s',' ','%','s',0 };
417 static const WCHAR fmt3W
[] = { '%','d',0 };
418 RECT
*title
=&infoPtr
->title
;
419 RECT
*prev
=&infoPtr
->titlebtnprev
;
420 RECT
*next
=&infoPtr
->titlebtnnext
;
421 RECT
*titlemonth
=&infoPtr
->titlemonth
;
422 RECT
*titleyear
=&infoPtr
->titleyear
;
426 int i
, j
, m
, mask
, day
, firstDay
, weeknum
, weeknum1
,prevMonth
;
427 int textHeight
= infoPtr
->textHeight
;
434 COLORREF oldTextColor
, oldBkColor
;
436 RECT rcDay
; /* used in MONTHCAL_CalcDayRect() */
437 SYSTEMTIME localtime
;
440 oldTextColor
= SetTextColor(hdc
, comctl32_color
.clrWindowText
);
442 /* fill background */
443 hbr
= CreateSolidBrush (infoPtr
->bk
);
444 FillRect(hdc
, &ps
->rcPaint
, hbr
);
448 if(IntersectRect(&rcTemp
, &(ps
->rcPaint
), title
))
450 hbr
= CreateSolidBrush(infoPtr
->titlebk
);
451 FillRect(hdc
, title
, hbr
);
455 /* if the previous button is pressed draw it depressed */
456 if(IntersectRect(&rcTemp
, &(ps
->rcPaint
), prev
))
457 paint_button (infoPtr
, hdc
, FALSE
, infoPtr
->status
& MC_PREVPRESSED
, prev
);
459 /* if next button is depressed draw it depressed */
460 if(IntersectRect(&rcTemp
, &(ps
->rcPaint
), next
))
461 paint_button (infoPtr
, hdc
, TRUE
, infoPtr
->status
& MC_NEXTPRESSED
, next
);
463 oldBkColor
= SetBkColor(hdc
, infoPtr
->titlebk
);
464 SetTextColor(hdc
, infoPtr
->titletxt
);
465 currentFont
= SelectObject(hdc
, infoPtr
->hBoldFont
);
467 GetLocaleInfoW( LOCALE_USER_DEFAULT
,LOCALE_SMONTHNAME1
+infoPtr
->curSel
.wMonth
-1,
469 wsprintfW(buf
, fmt1W
, buf1
, infoPtr
->curSel
.wYear
);
471 if(IntersectRect(&rcTemp
, &(ps
->rcPaint
), title
))
473 DrawTextW(hdc
, buf
, strlenW(buf
), title
,
474 DT_CENTER
| DT_VCENTER
| DT_SINGLELINE
);
477 /* titlemonth left/right contained rect for whole titletxt('June 1999')
478 * MCM_HitTestInfo wants month & year rects, so prepare these now.
479 *(no, we can't draw them separately; the whole text is centered)
481 GetTextExtentPoint32W(hdc
, buf
, strlenW(buf
), &size
);
482 titlemonth
->left
= title
->right
/ 2 + title
->left
/ 2 - size
.cx
/ 2;
483 titleyear
->right
= title
->right
/ 2 + title
->left
/ 2 + size
.cx
/ 2;
484 GetTextExtentPoint32W(hdc
, buf1
, strlenW(buf1
), &size
);
485 titlemonth
->right
= titlemonth
->left
+ size
.cx
;
486 titleyear
->left
= titlemonth
->right
;
488 /* draw month area */
489 rcTemp
.top
=infoPtr
->wdays
.top
;
490 rcTemp
.left
=infoPtr
->wdays
.left
;
491 rcTemp
.bottom
=infoPtr
->todayrect
.bottom
;
492 rcTemp
.right
=infoPtr
->todayrect
.right
;
493 if(IntersectRect(&rcTemp
, &(ps
->rcPaint
), &rcTemp
))
495 hbr
= CreateSolidBrush(infoPtr
->monthbk
);
496 FillRect(hdc
, &rcTemp
, hbr
);
500 /* draw line under day abbreviations */
502 MoveToEx(hdc
, infoPtr
->days
.left
+ 3, title
->bottom
+ textHeight
+ 1, NULL
);
503 LineTo(hdc
, infoPtr
->days
.right
- 3, title
->bottom
+ textHeight
+ 1);
505 prevMonth
= infoPtr
->curSel
.wMonth
- 1;
506 if(prevMonth
== 0) /* if curSel.wMonth is january(1) prevMonth is */
507 prevMonth
= 12; /* december(12) of the previous year */
509 infoPtr
->wdays
.left
= infoPtr
->days
.left
= infoPtr
->weeknums
.right
;
510 /* draw day abbreviations */
512 SelectObject(hdc
, infoPtr
->hFont
);
513 SetBkColor(hdc
, infoPtr
->monthbk
);
514 SetTextColor(hdc
, infoPtr
->trailingtxt
);
516 /* copy this rect so we can change the values without changing */
517 /* the original version */
518 days
->left
= infoPtr
->wdays
.left
;
519 days
->right
= days
->left
+ infoPtr
->width_increment
;
520 days
->top
= infoPtr
->wdays
.top
;
521 days
->bottom
= infoPtr
->wdays
.bottom
;
523 i
= infoPtr
->firstDay
;
526 GetLocaleInfoW( LOCALE_USER_DEFAULT
,LOCALE_SABBREVDAYNAME1
+ (i
+j
+6)%7, buf
, countof(buf
));
527 DrawTextW(hdc
, buf
, strlenW(buf
), days
, DT_CENTER
| DT_VCENTER
| DT_SINGLELINE
);
528 days
->left
+=infoPtr
->width_increment
;
529 days
->right
+=infoPtr
->width_increment
;
532 /* draw day numbers; first, the previous month */
534 firstDay
= MONTHCAL_CalculateDayOfWeek(1, infoPtr
->curSel
.wMonth
, infoPtr
->curSel
.wYear
);
536 day
= MONTHCAL_MonthLength(prevMonth
, infoPtr
->curSel
.wYear
) +
537 (infoPtr
->firstDay
+ 7 - firstDay
)%7 + 1;
538 if (day
> MONTHCAL_MonthLength(prevMonth
, infoPtr
->curSel
.wYear
))
540 startofprescal
= day
;
545 while(day
<= MONTHCAL_MonthLength(prevMonth
, infoPtr
->curSel
.wYear
)) {
546 MONTHCAL_CalcDayRect(infoPtr
, &rcDay
, i
, 0);
547 if(IntersectRect(&rcTemp
, &(ps
->rcPaint
), &rcDay
))
549 MONTHCAL_DrawDay(infoPtr
, hdc
, day
, prevMonth
, i
, 0,
550 infoPtr
->monthdayState
[m
] & mask
);
558 /* draw `current' month */
560 day
= 1; /* start at the beginning of the current month */
562 infoPtr
->firstDayplace
= i
;
563 SetTextColor(hdc
, infoPtr
->txt
);
567 /* draw the first week of the current month */
569 MONTHCAL_CalcDayRect(infoPtr
, &rcDay
, i
, 0);
570 if(IntersectRect(&rcTemp
, &(ps
->rcPaint
), &rcDay
))
573 MONTHCAL_DrawDay(infoPtr
, hdc
, day
, infoPtr
->curSel
.wMonth
, i
, 0,
574 infoPtr
->monthdayState
[m
] & mask
);
576 if((infoPtr
->curSel
.wMonth
== infoPtr
->todaysDate
.wMonth
) &&
577 (day
==infoPtr
->todaysDate
.wDay
) &&
578 (infoPtr
->curSel
.wYear
== infoPtr
->todaysDate
.wYear
)) {
579 if(!(infoPtr
->dwStyle
& MCS_NOTODAYCIRCLE
))
580 MONTHCAL_CircleDay(infoPtr
, hdc
, day
, infoPtr
->curSel
.wMonth
);
589 j
= 1; /* move to the 2nd week of the current month */
590 i
= 0; /* move back to sunday */
591 while(day
<= MONTHCAL_MonthLength(infoPtr
->curSel
.wMonth
, infoPtr
->curSel
.wYear
)) {
592 MONTHCAL_CalcDayRect(infoPtr
, &rcDay
, i
, j
);
593 if(IntersectRect(&rcTemp
, &(ps
->rcPaint
), &rcDay
))
595 MONTHCAL_DrawDay(infoPtr
, hdc
, day
, infoPtr
->curSel
.wMonth
, i
, j
,
596 infoPtr
->monthdayState
[m
] & mask
);
598 if((infoPtr
->curSel
.wMonth
== infoPtr
->todaysDate
.wMonth
) &&
599 (day
==infoPtr
->todaysDate
.wDay
) &&
600 (infoPtr
->curSel
.wYear
== infoPtr
->todaysDate
.wYear
))
601 if(!(infoPtr
->dwStyle
& MCS_NOTODAYCIRCLE
))
602 MONTHCAL_CircleDay(infoPtr
, hdc
, day
, infoPtr
->curSel
.wMonth
);
607 if(i
>6) { /* past saturday, goto the next weeks sunday */
613 /* draw `next' month */
615 day
= 1; /* start at the first day of the next month */
619 SetTextColor(hdc
, infoPtr
->trailingtxt
);
620 while((i
<7) &&(j
<6)) {
621 MONTHCAL_CalcDayRect(infoPtr
, &rcDay
, i
, j
);
622 if(IntersectRect(&rcTemp
, &(ps
->rcPaint
), &rcDay
))
624 MONTHCAL_DrawDay(infoPtr
, hdc
, day
, infoPtr
->curSel
.wMonth
+ 1, i
, j
,
625 infoPtr
->monthdayState
[m
] & mask
);
631 if(i
==7) { /* past saturday, go to next week's sunday */
636 SetTextColor(hdc
, infoPtr
->txt
);
639 /* draw `today' date if style allows it, and draw a circle before today's
640 * date if necessary */
642 if(!(infoPtr
->dwStyle
& MCS_NOTODAY
)) {
643 if(!(infoPtr
->dwStyle
& MCS_NOTODAYCIRCLE
)) {
644 /*day is the number of days from nextmonth we put on the calendar */
645 MONTHCAL_CircleDay(infoPtr
, hdc
,
646 day
+MONTHCAL_MonthLength(infoPtr
->curSel
.wMonth
, infoPtr
->curSel
.wYear
),
647 infoPtr
->curSel
.wMonth
);
649 if (!LoadStringW(COMCTL32_hModule
,IDM_TODAY
,buf1
,countof(buf1
)))
651 WARN("Can't load resource\n");
652 strcpyW(buf1
, todayW
);
654 MONTHCAL_CalcDayRect(infoPtr
, &rtoday
, 1, 6);
655 localtime
= infoPtr
->todaysDate
;
656 GetDateFormatW(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
,&localtime
,NULL
,buf2
,countof(buf2
));
657 wsprintfW(buf
, fmt2W
, buf1
, buf2
);
658 SelectObject(hdc
, infoPtr
->hBoldFont
);
660 DrawTextW(hdc
, buf
, -1, &rtoday
, DT_CALCRECT
| DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
);
661 if(IntersectRect(&rcTemp
, &(ps
->rcPaint
), &rtoday
))
663 DrawTextW(hdc
, buf
, -1, &rtoday
, DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
);
665 SelectObject(hdc
, infoPtr
->hFont
);
668 /*eventually draw week numbers*/
669 if(infoPtr
->dwStyle
& MCS_WEEKNUMBERS
) {
670 /* display weeknumbers*/
673 /* Rules what week to call the first week of a new year:
674 LOCALE_IFIRSTWEEKOFYEAR == 0 (e.g US?):
675 The week containing Jan 1 is the first week of year
676 LOCALE_IFIRSTWEEKOFYEAR == 2 (e.g. Germany):
677 First week of year must contain 4 days of the new year
678 LOCALE_IFIRSTWEEKOFYEAR == 1 (what contries?)
679 The first week of the year must contain only days of the new year
681 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_IFIRSTWEEKOFYEAR
, buf
, countof(buf
));
682 weeknum
= atoiW(buf
);
693 if (infoPtr
->curSel
.wMonth
< 2)
695 /* calculate all those exceptions for january */
696 weeknum1
=MONTHCAL_CalculateDayOfWeek(1, 1, infoPtr
->curSel
.wYear
);
697 if ((infoPtr
->firstDay
+7 - weeknum1
)%7 > mindays
)
703 weeknum
+=MONTHCAL_MonthLength(i
+1, infoPtr
->curSel
.wYear
- 1);
704 weeknum
+=startofprescal
+ 7;
706 weeknum1
=MONTHCAL_CalculateDayOfWeek(1, 1, infoPtr
->curSel
.wYear
- 1);
707 if ((infoPtr
->firstDay
+ 7 - weeknum1
)%7 > mindays
)
714 for(i
=0; i
<prevMonth
-1; i
++)
715 weeknum
+=MONTHCAL_MonthLength(i
+1, infoPtr
->curSel
.wYear
);
716 weeknum
+=startofprescal
+ 7;
718 weeknum1
=MONTHCAL_CalculateDayOfWeek(1,1,infoPtr
->curSel
.wYear
);
719 if ((infoPtr
->firstDay
+ 7 - weeknum1
)%7 > mindays
)
722 days
->left
= infoPtr
->weeknums
.left
;
723 days
->right
= infoPtr
->weeknums
.right
;
724 days
->top
= infoPtr
->weeknums
.top
;
725 days
->bottom
= days
->top
+infoPtr
->height_increment
;
727 if((i
==0)&&(weeknum
>50))
729 wsprintfW(buf
, fmt3W
, weeknum
);
732 else if((i
==5)&&(weeknum
>47))
734 wsprintfW(buf
, fmt3W
, 1);
737 wsprintfW(buf
, fmt3W
, weeknum
+ i
);
738 DrawTextW(hdc
, buf
, -1, days
, DT_CENTER
| DT_VCENTER
| DT_SINGLELINE
);
739 days
->top
+=infoPtr
->height_increment
;
740 days
->bottom
+=infoPtr
->height_increment
;
743 MoveToEx(hdc
, infoPtr
->weeknums
.right
, infoPtr
->weeknums
.top
+ 3 , NULL
);
744 LineTo(hdc
, infoPtr
->weeknums
.right
, infoPtr
->weeknums
.bottom
);
747 /* currentFont was font at entering Refresh */
749 SetBkColor(hdc
, oldBkColor
);
750 SelectObject(hdc
, currentFont
);
751 SetTextColor(hdc
, oldTextColor
);
756 MONTHCAL_GetMinReqRect(const MONTHCAL_INFO
*infoPtr
, LPRECT lpRect
)
758 TRACE("rect %p\n", lpRect
);
760 if(!lpRect
) return FALSE
;
762 lpRect
->left
= infoPtr
->title
.left
;
763 lpRect
->top
= infoPtr
->title
.top
;
764 lpRect
->right
= infoPtr
->title
.right
;
765 lpRect
->bottom
= infoPtr
->todayrect
.bottom
;
766 AdjustWindowRect(lpRect
, infoPtr
->dwStyle
, FALSE
);
768 TRACE("%s\n", wine_dbgstr_rect(lpRect
));
775 MONTHCAL_GetColor(const MONTHCAL_INFO
*infoPtr
, INT index
)
780 case MCSC_BACKGROUND
:
785 return infoPtr
->titlebk
;
787 return infoPtr
->titletxt
;
789 return infoPtr
->monthbk
;
790 case MCSC_TRAILINGTEXT
:
791 return infoPtr
->trailingtxt
;
799 MONTHCAL_SetColor(MONTHCAL_INFO
*infoPtr
, INT index
, COLORREF color
)
803 TRACE("%d: color %08x\n", index
, color
);
806 case MCSC_BACKGROUND
:
812 infoPtr
->txt
= color
;
815 prev
= infoPtr
->titlebk
;
816 infoPtr
->titlebk
= color
;
819 prev
=infoPtr
->titletxt
;
820 infoPtr
->titletxt
= color
;
823 prev
= infoPtr
->monthbk
;
824 infoPtr
->monthbk
= color
;
826 case MCSC_TRAILINGTEXT
:
827 prev
= infoPtr
->trailingtxt
;
828 infoPtr
->trailingtxt
= color
;
832 InvalidateRect(infoPtr
->hwndSelf
, NULL
, index
== MCSC_BACKGROUND
? TRUE
: FALSE
);
838 MONTHCAL_GetMonthDelta(const MONTHCAL_INFO
*infoPtr
)
843 return infoPtr
->delta
;
845 return infoPtr
->visible
;
850 MONTHCAL_SetMonthDelta(MONTHCAL_INFO
*infoPtr
, INT delta
)
852 INT prev
= infoPtr
->delta
;
854 TRACE("delta %d\n", delta
);
856 infoPtr
->delta
= delta
;
862 MONTHCAL_GetFirstDayOfWeek(const MONTHCAL_INFO
*infoPtr
)
864 return MAKELONG(infoPtr
->firstDay
, infoPtr
->firstDayHighWord
);
868 /* sets the first day of the week that will appear in the control */
869 /* 0 == Sunday, 6 == Saturday */
870 /* FIXME: this needs to be implemented properly in MONTHCAL_Refresh() */
871 /* FIXME: we need more error checking here */
873 MONTHCAL_SetFirstDayOfWeek(MONTHCAL_INFO
*infoPtr
, INT day
)
875 int prev
= MAKELONG(infoPtr
->firstDay
, infoPtr
->firstDayHighWord
);
879 TRACE("day %d\n", day
);
881 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_IFIRSTDAYOFWEEK
, buf
, countof(buf
));
882 TRACE("%s %d\n", debugstr_w(buf
), strlenW(buf
));
884 localFirstDay
= atoiW(buf
);
888 infoPtr
->firstDay
= localFirstDay
;
889 infoPtr
->firstDayHighWord
= FALSE
;
893 infoPtr
->firstDay
= 6; /* max first day allowed */
894 infoPtr
->firstDayHighWord
= TRUE
;
898 infoPtr
->firstDay
= day
;
899 infoPtr
->firstDayHighWord
= TRUE
;
907 MONTHCAL_GetMonthRange(const MONTHCAL_INFO
*infoPtr
)
911 return infoPtr
->monthRange
;
916 MONTHCAL_GetMaxTodayWidth(const MONTHCAL_INFO
*infoPtr
)
918 return(infoPtr
->todayrect
.right
- infoPtr
->todayrect
.left
);
923 MONTHCAL_SetRange(MONTHCAL_INFO
*infoPtr
, SHORT limits
, SYSTEMTIME
*range
)
925 FILETIME ft_min
, ft_max
;
927 TRACE("%x %p\n", limits
, range
);
929 if ((limits
& GDTR_MIN
&& !MONTHCAL_ValidateDate(&range
[0])) ||
930 (limits
& GDTR_MAX
&& !MONTHCAL_ValidateDate(&range
[1])))
933 if (limits
& GDTR_MIN
)
935 if (!MONTHCAL_ValidateTime(&range
[0]))
936 MONTHCAL_CopyTime(&infoPtr
->todaysDate
, &range
[0]);
938 infoPtr
->minDate
= range
[0];
939 infoPtr
->rangeValid
|= GDTR_MIN
;
941 if (limits
& GDTR_MAX
)
943 if (!MONTHCAL_ValidateTime(&range
[1]))
944 MONTHCAL_CopyTime(&infoPtr
->todaysDate
, &range
[1]);
946 infoPtr
->maxDate
= range
[1];
947 infoPtr
->rangeValid
|= GDTR_MAX
;
950 /* Only one limit set - we are done */
951 if ((infoPtr
->rangeValid
& (GDTR_MIN
| GDTR_MAX
)) != (GDTR_MIN
| GDTR_MAX
))
954 SystemTimeToFileTime(&infoPtr
->maxDate
, &ft_max
);
955 SystemTimeToFileTime(&infoPtr
->minDate
, &ft_min
);
957 if (CompareFileTime(&ft_min
, &ft_max
) >= 0)
959 if ((limits
& (GDTR_MIN
| GDTR_MAX
)) == (GDTR_MIN
| GDTR_MAX
))
961 /* Native swaps limits only when both limits are being set. */
962 SYSTEMTIME st_tmp
= infoPtr
->minDate
;
963 infoPtr
->minDate
= infoPtr
->maxDate
;
964 infoPtr
->maxDate
= st_tmp
;
968 static const SYSTEMTIME zero
;
970 /* reset the other limit */
971 if (limits
& GDTR_MIN
) infoPtr
->maxDate
= zero
;
972 if (limits
& GDTR_MAX
) infoPtr
->minDate
= zero
;
973 infoPtr
->rangeValid
&= limits
& GDTR_MIN
? ~GDTR_MAX
: ~GDTR_MIN
;
982 MONTHCAL_GetRange(const MONTHCAL_INFO
*infoPtr
, SYSTEMTIME
*range
)
984 TRACE("%p\n", range
);
986 if(!range
) return FALSE
;
988 range
[1] = infoPtr
->maxDate
;
989 range
[0] = infoPtr
->minDate
;
991 return infoPtr
->rangeValid
;
996 MONTHCAL_SetDayState(const MONTHCAL_INFO
*infoPtr
, INT months
, MONTHDAYSTATE
*states
)
1000 TRACE("%d %p\n", months
, states
);
1001 if(months
!= infoPtr
->monthRange
) return 0;
1003 for(i
= 0; i
< months
; i
++)
1004 infoPtr
->monthdayState
[i
] = states
[i
];
1010 MONTHCAL_GetCurSel(const MONTHCAL_INFO
*infoPtr
, SYSTEMTIME
*curSel
)
1012 TRACE("%p\n", curSel
);
1013 if(!curSel
) return FALSE
;
1014 if(infoPtr
->dwStyle
& MCS_MULTISELECT
) return FALSE
;
1016 *curSel
= infoPtr
->minSel
;
1017 TRACE("%d/%d/%d\n", curSel
->wYear
, curSel
->wMonth
, curSel
->wDay
);
1021 /* FIXME: if the specified date is not visible, make it visible */
1022 /* FIXME: redraw? */
1024 MONTHCAL_SetCurSel(MONTHCAL_INFO
*infoPtr
, SYSTEMTIME
*curSel
)
1026 TRACE("%p\n", curSel
);
1027 if(!curSel
) return FALSE
;
1028 if(infoPtr
->dwStyle
& MCS_MULTISELECT
) return FALSE
;
1030 if(!MONTHCAL_ValidateDate(curSel
)) return FALSE
;
1032 infoPtr
->minSel
= *curSel
;
1033 infoPtr
->maxSel
= *curSel
;
1035 /* exit earlier if selection equals current */
1036 if (MONTHCAL_IsDateEqual(&infoPtr
->curSel
, curSel
)) return TRUE
;
1038 infoPtr
->curSel
= *curSel
;
1040 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1047 MONTHCAL_GetMaxSelCount(const MONTHCAL_INFO
*infoPtr
)
1049 return infoPtr
->maxSelCount
;
1054 MONTHCAL_SetMaxSelCount(MONTHCAL_INFO
*infoPtr
, INT max
)
1058 if(infoPtr
->dwStyle
& MCS_MULTISELECT
) {
1059 infoPtr
->maxSelCount
= max
;
1067 MONTHCAL_GetSelRange(const MONTHCAL_INFO
*infoPtr
, SYSTEMTIME
*range
)
1069 TRACE("%p\n", range
);
1071 if(!range
) return FALSE
;
1073 if(infoPtr
->dwStyle
& MCS_MULTISELECT
)
1075 range
[1] = infoPtr
->maxSel
;
1076 range
[0] = infoPtr
->minSel
;
1077 TRACE("[min,max]=[%d %d]\n", infoPtr
->minSel
.wDay
, infoPtr
->maxSel
.wDay
);
1086 MONTHCAL_SetSelRange(MONTHCAL_INFO
*infoPtr
, SYSTEMTIME
*range
)
1088 TRACE("%p\n", range
);
1090 if(!range
) return FALSE
;
1092 if(infoPtr
->dwStyle
& MCS_MULTISELECT
)
1094 /* adjust timestamps */
1095 if(!MONTHCAL_ValidateTime(&range
[0]))
1096 MONTHCAL_CopyTime(&infoPtr
->todaysDate
, &range
[0]);
1097 if(!MONTHCAL_ValidateTime(&range
[1]))
1098 MONTHCAL_CopyTime(&infoPtr
->todaysDate
, &range
[1]);
1100 infoPtr
->minSel
= range
[0];
1101 infoPtr
->maxSel
= range
[1];
1103 TRACE("[min,max]=[%d %d]\n", infoPtr
->minSel
.wDay
, infoPtr
->maxSel
.wDay
);
1112 MONTHCAL_GetToday(const MONTHCAL_INFO
*infoPtr
, SYSTEMTIME
*today
)
1114 TRACE("%p\n", today
);
1116 if(!today
) return FALSE
;
1117 *today
= infoPtr
->todaysDate
;
1123 MONTHCAL_SetToday(MONTHCAL_INFO
*infoPtr
, SYSTEMTIME
*today
)
1125 TRACE("%p\n", today
);
1127 if(!today
) return FALSE
;
1129 if(MONTHCAL_IsDateEqual(today
, &infoPtr
->todaysDate
)) return TRUE
;
1131 infoPtr
->todaysDate
= *today
;
1132 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1138 MONTHCAL_HitTest(const MONTHCAL_INFO
*infoPtr
, MCHITTESTINFO
*lpht
)
1144 if(!lpht
|| lpht
->cbSize
< MCHITTESTINFO_V1_SIZE
) return -1;
1149 ZeroMemory(&lpht
->st
, sizeof(lpht
->st
));
1151 /* Comment in for debugging...
1152 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,
1153 infoPtr->wdays.left, infoPtr->wdays.right,
1154 infoPtr->wdays.top, infoPtr->wdays.bottom,
1155 infoPtr->days.left, infoPtr->days.right,
1156 infoPtr->days.top, infoPtr->days.bottom,
1157 infoPtr->todayrect.left, infoPtr->todayrect.right,
1158 infoPtr->todayrect.top, infoPtr->todayrect.bottom,
1159 infoPtr->weeknums.left, infoPtr->weeknums.right,
1160 infoPtr->weeknums.top, infoPtr->weeknums.bottom);
1163 /* are we in the header? */
1165 if(PtInRect(&infoPtr
->title
, lpht
->pt
)) {
1166 if(PtInRect(&infoPtr
->titlebtnprev
, lpht
->pt
)) {
1167 retval
= MCHT_TITLEBTNPREV
;
1170 if(PtInRect(&infoPtr
->titlebtnnext
, lpht
->pt
)) {
1171 retval
= MCHT_TITLEBTNNEXT
;
1174 if(PtInRect(&infoPtr
->titlemonth
, lpht
->pt
)) {
1175 retval
= MCHT_TITLEMONTH
;
1178 if(PtInRect(&infoPtr
->titleyear
, lpht
->pt
)) {
1179 retval
= MCHT_TITLEYEAR
;
1183 retval
= MCHT_TITLE
;
1187 day
= MONTHCAL_CalcDayFromPos(infoPtr
,x
,y
,&wday
,&wnum
);
1188 if(PtInRect(&infoPtr
->wdays
, lpht
->pt
)) {
1189 retval
= MCHT_CALENDARDAY
;
1190 lpht
->st
.wYear
= infoPtr
->curSel
.wYear
;
1191 lpht
->st
.wMonth
= (day
< 1)? infoPtr
->curSel
.wMonth
-1 : infoPtr
->curSel
.wMonth
;
1192 lpht
->st
.wDay
= (day
< 1)?
1193 MONTHCAL_MonthLength(infoPtr
->curSel
.wMonth
-1, infoPtr
->curSel
.wYear
) -day
: day
;
1196 if(PtInRect(&infoPtr
->weeknums
, lpht
->pt
)) {
1197 retval
= MCHT_CALENDARWEEKNUM
;
1198 lpht
->st
.wYear
= infoPtr
->curSel
.wYear
;
1199 lpht
->st
.wMonth
= (day
< 1) ? infoPtr
->curSel
.wMonth
-1 :
1200 (day
> MONTHCAL_MonthLength(infoPtr
->curSel
.wMonth
,infoPtr
->curSel
.wYear
)) ?
1201 infoPtr
->curSel
.wMonth
+1 :infoPtr
->curSel
.wMonth
;
1202 lpht
->st
.wDay
= (day
< 1 ) ?
1203 MONTHCAL_MonthLength(infoPtr
->curSel
.wMonth
-1,infoPtr
->curSel
.wYear
) -day
:
1204 (day
> MONTHCAL_MonthLength(infoPtr
->curSel
.wMonth
,infoPtr
->curSel
.wYear
)) ?
1205 day
- MONTHCAL_MonthLength(infoPtr
->curSel
.wMonth
,infoPtr
->curSel
.wYear
) : day
;
1208 if(PtInRect(&infoPtr
->days
, lpht
->pt
))
1210 lpht
->st
.wYear
= infoPtr
->curSel
.wYear
;
1213 retval
= MCHT_CALENDARDATEPREV
;
1214 lpht
->st
.wMonth
= infoPtr
->curSel
.wMonth
- 1;
1215 if (lpht
->st
.wMonth
<1)
1217 lpht
->st
.wMonth
= 12;
1220 lpht
->st
.wDay
= MONTHCAL_MonthLength(lpht
->st
.wMonth
,lpht
->st
.wYear
) -day
;
1222 else if (day
> MONTHCAL_MonthLength(infoPtr
->curSel
.wMonth
,infoPtr
->curSel
.wYear
))
1224 retval
= MCHT_CALENDARDATENEXT
;
1225 lpht
->st
.wMonth
= infoPtr
->curSel
.wMonth
+ 1;
1226 if (lpht
->st
.wMonth
<12)
1228 lpht
->st
.wMonth
= 1;
1231 lpht
->st
.wDay
= day
- MONTHCAL_MonthLength(infoPtr
->curSel
.wMonth
,infoPtr
->curSel
.wYear
) ;
1234 retval
= MCHT_CALENDARDATE
;
1235 lpht
->st
.wMonth
= infoPtr
->curSel
.wMonth
;
1236 lpht
->st
.wDay
= day
;
1237 lpht
->st
.wDayOfWeek
= MONTHCAL_CalculateDayOfWeek(day
,lpht
->st
.wMonth
,lpht
->st
.wYear
);
1241 if(PtInRect(&infoPtr
->todayrect
, lpht
->pt
)) {
1242 retval
= MCHT_TODAYLINK
;
1247 /* Hit nothing special? What's left must be background :-) */
1249 retval
= MCHT_CALENDARBK
;
1251 lpht
->uHit
= retval
;
1255 /* MCN_GETDAYSTATE notification helper */
1256 static void MONTHCAL_NotifyDayState(MONTHCAL_INFO
*infoPtr
)
1258 if(infoPtr
->dwStyle
& MCS_DAYSTATE
) {
1262 nmds
.nmhdr
.hwndFrom
= infoPtr
->hwndSelf
;
1263 nmds
.nmhdr
.idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1264 nmds
.nmhdr
.code
= MCN_GETDAYSTATE
;
1265 nmds
.cDayState
= infoPtr
->monthRange
;
1266 nmds
.prgDayState
= Alloc(infoPtr
->monthRange
* sizeof(MONTHDAYSTATE
));
1268 nmds
.stStart
= infoPtr
->todaysDate
;
1269 nmds
.stStart
.wYear
= infoPtr
->curSel
.wYear
;
1270 nmds
.stStart
.wMonth
= infoPtr
->curSel
.wMonth
;
1271 nmds
.stStart
.wDay
= 1;
1273 SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, nmds
.nmhdr
.idFrom
, (LPARAM
)&nmds
);
1274 for(i
= 0; i
< infoPtr
->monthRange
; i
++)
1275 infoPtr
->monthdayState
[i
] = nmds
.prgDayState
[i
];
1277 Free(nmds
.prgDayState
);
1281 static void MONTHCAL_GoToNextMonth(MONTHCAL_INFO
*infoPtr
)
1283 SYSTEMTIME next
= infoPtr
->curSel
;
1288 if(next
.wMonth
> 12) {
1293 /* prevent max range exceeding */
1294 if(infoPtr
->rangeValid
& GDTR_MAX
)
1296 FILETIME ft_next
, ft_max
;
1298 SystemTimeToFileTime(&infoPtr
->maxDate
, &ft_max
);
1299 SystemTimeToFileTime(&next
, &ft_next
);
1301 if (CompareFileTime(&ft_next
, &ft_max
) > 0) return;
1304 infoPtr
->curSel
= next
;
1306 MONTHCAL_NotifyDayState(infoPtr
);
1310 static void MONTHCAL_GoToPrevMonth(MONTHCAL_INFO
*infoPtr
)
1312 SYSTEMTIME prev
= infoPtr
->curSel
;
1317 if(prev
.wMonth
< 1) {
1322 /* prevent min range exceeding */
1323 if(infoPtr
->rangeValid
& GDTR_MIN
)
1325 FILETIME ft_prev
, ft_min
;
1327 SystemTimeToFileTime(&infoPtr
->minDate
, &ft_min
);
1328 SystemTimeToFileTime(&prev
, &ft_prev
);
1330 if (CompareFileTime(&ft_prev
, &ft_min
) < 0) return;
1333 infoPtr
->curSel
= prev
;
1335 MONTHCAL_NotifyDayState(infoPtr
);
1339 MONTHCAL_RButtonDown(MONTHCAL_INFO
*infoPtr
, LPARAM lParam
)
1341 static const WCHAR todayW
[] = { 'G','o',' ','t','o',' ','T','o','d','a','y',':',0 };
1346 hMenu
= CreatePopupMenu();
1347 if (!LoadStringW(COMCTL32_hModule
, IDM_GOTODAY
, buf
, countof(buf
)))
1349 WARN("Can't load resource\n");
1350 strcpyW(buf
, todayW
);
1352 AppendMenuW(hMenu
, MF_STRING
|MF_ENABLED
, 1, buf
);
1353 menupoint
.x
= (short)LOWORD(lParam
);
1354 menupoint
.y
= (short)HIWORD(lParam
);
1355 ClientToScreen(infoPtr
->hwndSelf
, &menupoint
);
1356 if( TrackPopupMenu(hMenu
, TPM_RIGHTBUTTON
| TPM_NONOTIFY
| TPM_RETURNCMD
,
1357 menupoint
.x
, menupoint
.y
, 0, infoPtr
->hwndSelf
, NULL
))
1359 infoPtr
->curSel
= infoPtr
->todaysDate
;
1360 infoPtr
->minSel
= infoPtr
->todaysDate
;
1361 infoPtr
->maxSel
= infoPtr
->todaysDate
;
1362 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1368 /* creates updown control and edit box */
1369 static void MONTHCAL_EditYear(MONTHCAL_INFO
*infoPtr
)
1371 static const WCHAR EditW
[] = { 'E','D','I','T',0 };
1373 infoPtr
->hWndYearEdit
=
1374 CreateWindowExW(0, EditW
, 0, WS_VISIBLE
| WS_CHILD
| ES_READONLY
,
1375 infoPtr
->titleyear
.left
+ 3, infoPtr
->titlebtnnext
.top
,
1376 infoPtr
->titleyear
.right
- infoPtr
->titleyear
.left
+ 4,
1377 infoPtr
->textHeight
, infoPtr
->hwndSelf
,
1380 SendMessageW(infoPtr
->hWndYearEdit
, WM_SETFONT
, (WPARAM
)infoPtr
->hBoldFont
, TRUE
);
1382 infoPtr
->hWndYearUpDown
=
1383 CreateWindowExW(0, UPDOWN_CLASSW
, 0,
1384 WS_VISIBLE
| WS_CHILD
| UDS_SETBUDDYINT
| UDS_NOTHOUSANDS
| UDS_ARROWKEYS
,
1385 infoPtr
->titleyear
.right
+ 7, infoPtr
->titlebtnnext
.top
,
1386 18, infoPtr
->textHeight
, infoPtr
->hwndSelf
,
1389 /* attach edit box */
1390 SendMessageW(infoPtr
->hWndYearUpDown
, UDM_SETRANGE
, 0, MAKELONG(9999, 1753));
1391 SendMessageW(infoPtr
->hWndYearUpDown
, UDM_SETBUDDY
, (WPARAM
)infoPtr
->hWndYearEdit
, 0);
1392 SendMessageW(infoPtr
->hWndYearUpDown
, UDM_SETPOS
, 0, infoPtr
->curSel
.wYear
);
1396 MONTHCAL_LButtonDown(MONTHCAL_INFO
*infoPtr
, LPARAM lParam
)
1401 if (infoPtr
->hWndYearUpDown
)
1403 infoPtr
->curSel
.wYear
= SendMessageW(infoPtr
->hWndYearUpDown
, UDM_SETPOS
, 0, 0);
1404 if(!DestroyWindow(infoPtr
->hWndYearUpDown
))
1406 FIXME("Can't destroy Updown Control\n");
1409 infoPtr
->hWndYearUpDown
= 0;
1411 if(!DestroyWindow(infoPtr
->hWndYearEdit
))
1413 FIXME("Can't destroy Updown Control\n");
1416 infoPtr
->hWndYearEdit
= 0;
1418 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1421 ht
.cbSize
= sizeof(MCHITTESTINFO
);
1422 ht
.pt
.x
= (short)LOWORD(lParam
);
1423 ht
.pt
.y
= (short)HIWORD(lParam
);
1424 TRACE("(%d, %d)\n", ht
.pt
.x
, ht
.pt
.y
);
1426 hit
= MONTHCAL_HitTest(infoPtr
, &ht
);
1430 case MCHT_TITLEBTNNEXT
:
1431 MONTHCAL_GoToNextMonth(infoPtr
);
1432 infoPtr
->status
= MC_NEXTPRESSED
;
1433 SetTimer(infoPtr
->hwndSelf
, MC_NEXTMONTHTIMER
, MC_NEXTMONTHDELAY
, 0);
1434 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1437 case MCHT_TITLEBTNPREV
:
1438 MONTHCAL_GoToPrevMonth(infoPtr
);
1439 infoPtr
->status
= MC_PREVPRESSED
;
1440 SetTimer(infoPtr
->hwndSelf
, MC_PREVMONTHTIMER
, MC_NEXTMONTHDELAY
, 0);
1441 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1444 case MCHT_TITLEMONTH
:
1446 HMENU hMenu
= CreatePopupMenu();
1451 for (i
= 0; i
< 12; i
++)
1453 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SMONTHNAME1
+i
, buf
, countof(buf
));
1454 AppendMenuW(hMenu
, MF_STRING
|MF_ENABLED
, i
+ 1, buf
);
1456 menupoint
.x
= infoPtr
->titlemonth
.right
;
1457 menupoint
.y
= infoPtr
->titlemonth
.bottom
;
1458 ClientToScreen(infoPtr
->hwndSelf
, &menupoint
);
1459 i
= TrackPopupMenu(hMenu
,TPM_LEFTALIGN
| TPM_NONOTIFY
| TPM_RIGHTBUTTON
| TPM_RETURNCMD
,
1460 menupoint
.x
, menupoint
.y
, 0, infoPtr
->hwndSelf
, NULL
);
1462 if ((i
> 0) && (i
< 13))
1464 infoPtr
->curSel
.wMonth
= i
;
1465 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1468 case MCHT_TITLEYEAR
:
1470 MONTHCAL_EditYear(infoPtr
);
1473 case MCHT_TODAYLINK
:
1477 infoPtr
->firstSelDay
= infoPtr
->todaysDate
.wDay
;
1478 infoPtr
->curSel
= infoPtr
->todaysDate
;
1479 infoPtr
->minSel
= infoPtr
->todaysDate
;
1480 infoPtr
->maxSel
= infoPtr
->todaysDate
;
1481 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1483 nmsc
.nmhdr
.hwndFrom
= infoPtr
->hwndSelf
;
1484 nmsc
.nmhdr
.idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1485 nmsc
.nmhdr
.code
= MCN_SELCHANGE
;
1486 nmsc
.stSelStart
= infoPtr
->minSel
;
1487 nmsc
.stSelEnd
= infoPtr
->maxSel
;
1488 SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, nmsc
.nmhdr
.idFrom
, (LPARAM
)&nmsc
);
1490 nmsc
.nmhdr
.code
= MCN_SELECT
;
1491 SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, nmsc
.nmhdr
.idFrom
, (LPARAM
)&nmsc
);
1494 case MCHT_CALENDARDATE
:
1496 RECT rcDay
; /* used in determining area to invalidate */
1497 SYSTEMTIME selArray
[2];
1500 selArray
[0] = ht
.st
;
1501 selArray
[1] = ht
.st
;
1502 MONTHCAL_SetSelRange(infoPtr
, selArray
);
1503 MONTHCAL_SetCurSel(infoPtr
, &selArray
[0]);
1504 TRACE("MCHT_CALENDARDATE\n");
1505 nmsc
.nmhdr
.hwndFrom
= infoPtr
->hwndSelf
;
1506 nmsc
.nmhdr
.idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1507 nmsc
.nmhdr
.code
= MCN_SELCHANGE
;
1508 nmsc
.stSelStart
= infoPtr
->minSel
;
1509 nmsc
.stSelEnd
= infoPtr
->maxSel
;
1511 SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, nmsc
.nmhdr
.idFrom
, (LPARAM
)&nmsc
);
1513 /* redraw both old and new days if the selected day changed */
1514 if(infoPtr
->curSel
.wDay
!= ht
.st
.wDay
) {
1515 MONTHCAL_CalcPosFromDay(infoPtr
, ht
.st
.wDay
, ht
.st
.wMonth
, &rcDay
);
1516 InvalidateRect(infoPtr
->hwndSelf
, &rcDay
, TRUE
);
1518 MONTHCAL_CalcPosFromDay(infoPtr
, infoPtr
->curSel
.wDay
, infoPtr
->curSel
.wMonth
, &rcDay
);
1519 InvalidateRect(infoPtr
->hwndSelf
, &rcDay
, TRUE
);
1522 infoPtr
->firstSelDay
= ht
.st
.wDay
;
1523 infoPtr
->curSel
.wDay
= ht
.st
.wDay
;
1524 infoPtr
->status
= MC_SEL_LBUTDOWN
;
1534 MONTHCAL_LButtonUp(MONTHCAL_INFO
*infoPtr
, LPARAM lParam
)
1538 BOOL redraw
= FALSE
;
1544 if(infoPtr
->status
& MC_NEXTPRESSED
) {
1545 KillTimer(infoPtr
->hwndSelf
, MC_NEXTMONTHTIMER
);
1546 infoPtr
->status
&= ~MC_NEXTPRESSED
;
1549 if(infoPtr
->status
& MC_PREVPRESSED
) {
1550 KillTimer(infoPtr
->hwndSelf
, MC_PREVMONTHTIMER
);
1551 infoPtr
->status
&= ~MC_PREVPRESSED
;
1555 ht
.cbSize
= sizeof(MCHITTESTINFO
);
1556 ht
.pt
.x
= (short)LOWORD(lParam
);
1557 ht
.pt
.y
= (short)HIWORD(lParam
);
1558 hit
= MONTHCAL_HitTest(infoPtr
, &ht
);
1560 infoPtr
->status
= MC_SEL_LBUTUP
;
1562 if(hit
== MCHT_CALENDARDATENEXT
) {
1563 MONTHCAL_GoToNextMonth(infoPtr
);
1564 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1567 if(hit
== MCHT_CALENDARDATEPREV
){
1568 MONTHCAL_GoToPrevMonth(infoPtr
);
1569 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1572 nmhdr
.hwndFrom
= infoPtr
->hwndSelf
;
1573 nmhdr
.idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1574 nmhdr
.code
= NM_RELEASEDCAPTURE
;
1575 TRACE("Sent notification from %p to %p\n", infoPtr
->hwndSelf
, infoPtr
->hwndNotify
);
1577 SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, nmhdr
.idFrom
, (LPARAM
)&nmhdr
);
1578 /* redraw if necessary */
1580 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1581 /* only send MCN_SELECT if currently displayed month's day was selected */
1582 if(hit
== MCHT_CALENDARDATE
) {
1583 nmsc
.nmhdr
.hwndFrom
= infoPtr
->hwndSelf
;
1584 nmsc
.nmhdr
.idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1585 nmsc
.nmhdr
.code
= MCN_SELECT
;
1586 nmsc
.stSelStart
= infoPtr
->minSel
;
1587 nmsc
.stSelEnd
= infoPtr
->maxSel
;
1589 SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, nmsc
.nmhdr
.idFrom
, (LPARAM
)&nmsc
);
1597 MONTHCAL_Timer(MONTHCAL_INFO
*infoPtr
, WPARAM wParam
)
1599 BOOL redraw
= FALSE
;
1601 TRACE("%ld\n", wParam
);
1604 case MC_NEXTMONTHTIMER
:
1606 MONTHCAL_GoToNextMonth(infoPtr
);
1608 case MC_PREVMONTHTIMER
:
1610 MONTHCAL_GoToPrevMonth(infoPtr
);
1613 ERR("got unknown timer\n");
1617 /* redraw only if necessary */
1619 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1626 MONTHCAL_MouseMove(MONTHCAL_INFO
*infoPtr
, LPARAM lParam
)
1629 int oldselday
, selday
, hit
;
1632 if(!(infoPtr
->status
& MC_SEL_LBUTDOWN
)) return 0;
1634 ht
.cbSize
= sizeof(MCHITTESTINFO
);
1635 ht
.pt
.x
= (short)LOWORD(lParam
);
1636 ht
.pt
.y
= (short)HIWORD(lParam
);
1638 hit
= MONTHCAL_HitTest(infoPtr
, &ht
);
1640 /* not on the calendar date numbers? bail out */
1641 TRACE("hit:%x\n",hit
);
1642 if((hit
& MCHT_CALENDARDATE
) != MCHT_CALENDARDATE
) return 0;
1644 selday
= ht
.st
.wDay
;
1645 oldselday
= infoPtr
->curSel
.wDay
;
1646 infoPtr
->curSel
.wDay
= selday
;
1647 MONTHCAL_CalcPosFromDay(infoPtr
, selday
, ht
.st
. wMonth
, &r
);
1649 if(infoPtr
->dwStyle
& MCS_MULTISELECT
) {
1650 SYSTEMTIME selArray
[2];
1653 MONTHCAL_GetSelRange(infoPtr
, selArray
);
1655 if(infoPtr
->firstSelDay
==selArray
[0].wDay
) i
=1;
1656 TRACE("oldRange:%d %d %d %d\n", infoPtr
->firstSelDay
, selArray
[0].wDay
, selArray
[1].wDay
, i
);
1657 if(infoPtr
->firstSelDay
==selArray
[1].wDay
) {
1658 /* 1st time we get here: selArray[0]=selArray[1]) */
1659 /* if we're still at the first selected date, return */
1660 if(infoPtr
->firstSelDay
==selday
) goto done
;
1661 if(selday
<infoPtr
->firstSelDay
) i
= 0;
1664 if(abs(infoPtr
->firstSelDay
- selday
) >= infoPtr
->maxSelCount
) {
1665 if(selday
>infoPtr
->firstSelDay
)
1666 selday
= infoPtr
->firstSelDay
+ infoPtr
->maxSelCount
;
1668 selday
= infoPtr
->firstSelDay
- infoPtr
->maxSelCount
;
1671 if(selArray
[i
].wDay
!=selday
) {
1672 TRACE("newRange:%d %d %d %d\n", infoPtr
->firstSelDay
, selArray
[0].wDay
, selArray
[1].wDay
, i
);
1674 selArray
[i
].wDay
= selday
;
1676 if(selArray
[0].wDay
>selArray
[1].wDay
) {
1678 tempday
= selArray
[1].wDay
;
1679 selArray
[1].wDay
= selArray
[0].wDay
;
1680 selArray
[0].wDay
= tempday
;
1683 MONTHCAL_SetSelRange(infoPtr
, selArray
);
1689 /* only redraw if the currently selected day changed */
1690 /* FIXME: this should specify a rectangle containing only the days that changed */
1691 /* using InvalidateRect */
1692 if(oldselday
!= infoPtr
->curSel
.wDay
)
1693 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1700 MONTHCAL_Paint(MONTHCAL_INFO
*infoPtr
, HDC hdc_paint
)
1707 GetClientRect(infoPtr
->hwndSelf
, &ps
.rcPaint
);
1711 hdc
= BeginPaint(infoPtr
->hwndSelf
, &ps
);
1713 MONTHCAL_Refresh(infoPtr
, hdc
, &ps
);
1714 if (!hdc_paint
) EndPaint(infoPtr
->hwndSelf
, &ps
);
1720 MONTHCAL_KillFocus(const MONTHCAL_INFO
*infoPtr
, HWND hFocusWnd
)
1724 if (infoPtr
->hwndNotify
!= hFocusWnd
)
1725 ShowWindow(infoPtr
->hwndSelf
, SW_HIDE
);
1727 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1734 MONTHCAL_SetFocus(const MONTHCAL_INFO
*infoPtr
)
1738 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1743 /* sets the size information */
1744 static void MONTHCAL_UpdateSize(MONTHCAL_INFO
*infoPtr
)
1746 static const WCHAR SunW
[] = { 'S','u','n',0 };
1747 static const WCHAR O0W
[] = { '0','0',0 };
1748 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
1749 RECT
*title
=&infoPtr
->title
;
1750 RECT
*prev
=&infoPtr
->titlebtnprev
;
1751 RECT
*next
=&infoPtr
->titlebtnnext
;
1752 RECT
*titlemonth
=&infoPtr
->titlemonth
;
1753 RECT
*titleyear
=&infoPtr
->titleyear
;
1754 RECT
*wdays
=&infoPtr
->wdays
;
1755 RECT
*weeknumrect
=&infoPtr
->weeknums
;
1756 RECT
*days
=&infoPtr
->days
;
1757 RECT
*todayrect
=&infoPtr
->todayrect
;
1761 int xdiv
, left_offset
;
1764 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
1766 currentFont
= SelectObject(hdc
, infoPtr
->hFont
);
1768 /* get the height and width of each day's text */
1769 GetTextMetricsW(hdc
, &tm
);
1770 infoPtr
->textHeight
= tm
.tmHeight
+ tm
.tmExternalLeading
+ tm
.tmInternalLeading
;
1771 GetTextExtentPoint32W(hdc
, SunW
, 3, &size
);
1772 infoPtr
->textWidth
= size
.cx
+ 2;
1774 /* recalculate the height and width increments and offsets */
1775 GetTextExtentPoint32W(hdc
, O0W
, 2, &size
);
1777 xdiv
= (infoPtr
->dwStyle
& MCS_WEEKNUMBERS
) ? 8 : 7;
1779 infoPtr
->width_increment
= size
.cx
* 2 + 4;
1780 infoPtr
->height_increment
= infoPtr
->textHeight
;
1781 left_offset
= (rcClient
.right
- rcClient
.left
) - (infoPtr
->width_increment
* xdiv
);
1783 /* calculate title area */
1784 title
->top
= rcClient
.top
;
1785 title
->bottom
= title
->top
+ 3 * infoPtr
->height_increment
/ 2;
1786 title
->left
= left_offset
;
1787 title
->right
= rcClient
.right
;
1789 /* set the dimensions of the next and previous buttons and center */
1790 /* the month text vertically */
1791 prev
->top
= next
->top
= title
->top
+ 4;
1792 prev
->bottom
= next
->bottom
= title
->bottom
- 4;
1793 prev
->left
= title
->left
+ 4;
1794 prev
->right
= prev
->left
+ (title
->bottom
- title
->top
) ;
1795 next
->right
= title
->right
- 4;
1796 next
->left
= next
->right
- (title
->bottom
- title
->top
);
1798 /* titlemonth->left and right change based upon the current month */
1799 /* and are recalculated in refresh as the current month may change */
1800 /* without the control being resized */
1801 titlemonth
->top
= titleyear
->top
= title
->top
+ (infoPtr
->height_increment
)/2;
1802 titlemonth
->bottom
= titleyear
->bottom
= title
->bottom
- (infoPtr
->height_increment
)/2;
1804 /* setup the dimensions of the rectangle we draw the names of the */
1805 /* days of the week in */
1806 weeknumrect
->left
= left_offset
;
1807 if(infoPtr
->dwStyle
& MCS_WEEKNUMBERS
)
1808 weeknumrect
->right
=prev
->right
;
1810 weeknumrect
->right
=weeknumrect
->left
;
1811 wdays
->left
= days
->left
= weeknumrect
->right
;
1812 wdays
->right
= days
->right
= wdays
->left
+ 7 * infoPtr
->width_increment
;
1813 wdays
->top
= title
->bottom
;
1814 wdays
->bottom
= wdays
->top
+ infoPtr
->height_increment
;
1816 days
->top
= weeknumrect
->top
= wdays
->bottom
;
1817 days
->bottom
= weeknumrect
->bottom
= days
->top
+ 6 * infoPtr
->height_increment
;
1819 todayrect
->left
= rcClient
.left
;
1820 todayrect
->right
= rcClient
.right
;
1821 todayrect
->top
= days
->bottom
;
1822 todayrect
->bottom
= days
->bottom
+ infoPtr
->height_increment
;
1824 TRACE("dx=%d dy=%d client[%s] title[%s] wdays[%s] days[%s] today[%s]\n",
1825 infoPtr
->width_increment
,infoPtr
->height_increment
,
1826 wine_dbgstr_rect(&rcClient
),
1827 wine_dbgstr_rect(title
),
1828 wine_dbgstr_rect(wdays
),
1829 wine_dbgstr_rect(days
),
1830 wine_dbgstr_rect(todayrect
));
1832 /* restore the originally selected font */
1833 SelectObject(hdc
, currentFont
);
1835 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
1838 static LRESULT
MONTHCAL_Size(MONTHCAL_INFO
*infoPtr
, int Width
, int Height
)
1840 TRACE("(width=%d, height=%d)\n", Width
, Height
);
1842 MONTHCAL_UpdateSize(infoPtr
);
1844 /* invalidate client area and erase background */
1845 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1850 static LRESULT
MONTHCAL_GetFont(const MONTHCAL_INFO
*infoPtr
)
1852 return (LRESULT
)infoPtr
->hFont
;
1855 static LRESULT
MONTHCAL_SetFont(MONTHCAL_INFO
*infoPtr
, HFONT hFont
, BOOL redraw
)
1860 if (!hFont
) return 0;
1862 hOldFont
= infoPtr
->hFont
;
1863 infoPtr
->hFont
= hFont
;
1865 GetObjectW(infoPtr
->hFont
, sizeof(lf
), &lf
);
1866 lf
.lfWeight
= FW_BOLD
;
1867 infoPtr
->hBoldFont
= CreateFontIndirectW(&lf
);
1869 MONTHCAL_UpdateSize(infoPtr
);
1872 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1874 return (LRESULT
)hOldFont
;
1877 /* update theme after a WM_THEMECHANGED message */
1878 static LRESULT
theme_changed (const MONTHCAL_INFO
* infoPtr
)
1880 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
1881 CloseThemeData (theme
);
1882 OpenThemeData (infoPtr
->hwndSelf
, themeClass
);
1886 static INT
MONTHCAL_StyleChanged(MONTHCAL_INFO
*infoPtr
, WPARAM wStyleType
,
1887 const STYLESTRUCT
*lpss
)
1889 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
1890 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
1892 if (wStyleType
!= GWL_STYLE
) return 0;
1894 infoPtr
->dwStyle
= lpss
->styleNew
;
1899 /* FIXME: check whether dateMin/dateMax need to be adjusted. */
1901 MONTHCAL_Create(HWND hwnd
, LPCREATESTRUCTW lpcs
)
1903 MONTHCAL_INFO
*infoPtr
;
1905 /* allocate memory for info structure */
1906 infoPtr
= Alloc(sizeof(MONTHCAL_INFO
));
1907 SetWindowLongPtrW(hwnd
, 0, (DWORD_PTR
)infoPtr
);
1909 if(infoPtr
== NULL
) {
1910 ERR( "could not allocate info memory!\n");
1914 infoPtr
->hwndSelf
= hwnd
;
1915 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
1916 infoPtr
->dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
1918 MONTHCAL_SetFont(infoPtr
, GetStockObject(DEFAULT_GUI_FONT
), FALSE
);
1920 /* initialize info structure */
1921 /* FIXME: calculate systemtime ->> localtime(substract timezoneinfo) */
1923 GetLocalTime(&infoPtr
->todaysDate
);
1924 infoPtr
->firstDayHighWord
= FALSE
;
1925 MONTHCAL_SetFirstDayOfWeek(infoPtr
, -1);
1927 infoPtr
->maxSelCount
= 7;
1928 infoPtr
->monthRange
= 3;
1929 infoPtr
->monthdayState
= Alloc(infoPtr
->monthRange
* sizeof(MONTHDAYSTATE
));
1930 infoPtr
->titlebk
= comctl32_color
.clrActiveCaption
;
1931 infoPtr
->titletxt
= comctl32_color
.clrWindow
;
1932 infoPtr
->monthbk
= comctl32_color
.clrWindow
;
1933 infoPtr
->trailingtxt
= comctl32_color
.clrGrayText
;
1934 infoPtr
->bk
= comctl32_color
.clrWindow
;
1935 infoPtr
->txt
= comctl32_color
.clrWindowText
;
1937 infoPtr
->minSel
= infoPtr
->todaysDate
;
1938 infoPtr
->maxSel
= infoPtr
->todaysDate
;
1939 infoPtr
->curSel
= infoPtr
->todaysDate
;
1941 /* call MONTHCAL_UpdateSize to set all of the dimensions */
1942 /* of the control */
1943 MONTHCAL_UpdateSize(infoPtr
);
1945 OpenThemeData (infoPtr
->hwndSelf
, themeClass
);
1952 MONTHCAL_Destroy(MONTHCAL_INFO
*infoPtr
)
1954 /* free month calendar info data */
1955 Free(infoPtr
->monthdayState
);
1956 SetWindowLongPtrW(infoPtr
->hwndSelf
, 0, 0);
1958 CloseThemeData (GetWindowTheme (infoPtr
->hwndSelf
));
1965 static LRESULT WINAPI
1966 MONTHCAL_WindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1968 MONTHCAL_INFO
*infoPtr
;
1970 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n", hwnd
, uMsg
, wParam
, lParam
);
1972 infoPtr
= MONTHCAL_GetInfoPtr(hwnd
);
1973 if (!infoPtr
&& (uMsg
!= WM_CREATE
))
1974 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
1978 return MONTHCAL_GetCurSel(infoPtr
, (LPSYSTEMTIME
)lParam
);
1981 return MONTHCAL_SetCurSel(infoPtr
, (LPSYSTEMTIME
)lParam
);
1983 case MCM_GETMAXSELCOUNT
:
1984 return MONTHCAL_GetMaxSelCount(infoPtr
);
1986 case MCM_SETMAXSELCOUNT
:
1987 return MONTHCAL_SetMaxSelCount(infoPtr
, wParam
);
1989 case MCM_GETSELRANGE
:
1990 return MONTHCAL_GetSelRange(infoPtr
, (LPSYSTEMTIME
)lParam
);
1992 case MCM_SETSELRANGE
:
1993 return MONTHCAL_SetSelRange(infoPtr
, (LPSYSTEMTIME
)lParam
);
1995 case MCM_GETMONTHRANGE
:
1996 return MONTHCAL_GetMonthRange(infoPtr
);
1998 case MCM_SETDAYSTATE
:
1999 return MONTHCAL_SetDayState(infoPtr
, (INT
)wParam
, (LPMONTHDAYSTATE
)lParam
);
2001 case MCM_GETMINREQRECT
:
2002 return MONTHCAL_GetMinReqRect(infoPtr
, (LPRECT
)lParam
);
2005 return MONTHCAL_GetColor(infoPtr
, wParam
);
2008 return MONTHCAL_SetColor(infoPtr
, wParam
, (COLORREF
)lParam
);
2011 return MONTHCAL_GetToday(infoPtr
, (LPSYSTEMTIME
)lParam
);
2014 return MONTHCAL_SetToday(infoPtr
, (LPSYSTEMTIME
)lParam
);
2017 return MONTHCAL_HitTest(infoPtr
, (PMCHITTESTINFO
)lParam
);
2019 case MCM_GETFIRSTDAYOFWEEK
:
2020 return MONTHCAL_GetFirstDayOfWeek(infoPtr
);
2022 case MCM_SETFIRSTDAYOFWEEK
:
2023 return MONTHCAL_SetFirstDayOfWeek(infoPtr
, (INT
)lParam
);
2026 return MONTHCAL_GetRange(infoPtr
, (LPSYSTEMTIME
)lParam
);
2029 return MONTHCAL_SetRange(infoPtr
, (SHORT
)wParam
, (LPSYSTEMTIME
)lParam
);
2031 case MCM_GETMONTHDELTA
:
2032 return MONTHCAL_GetMonthDelta(infoPtr
);
2034 case MCM_SETMONTHDELTA
:
2035 return MONTHCAL_SetMonthDelta(infoPtr
, wParam
);
2037 case MCM_GETMAXTODAYWIDTH
:
2038 return MONTHCAL_GetMaxTodayWidth(infoPtr
);
2041 return DLGC_WANTARROWS
| DLGC_WANTCHARS
;
2044 return MONTHCAL_KillFocus(infoPtr
, (HWND
)wParam
);
2046 case WM_RBUTTONDOWN
:
2047 return MONTHCAL_RButtonDown(infoPtr
, lParam
);
2049 case WM_LBUTTONDOWN
:
2050 return MONTHCAL_LButtonDown(infoPtr
, lParam
);
2053 return MONTHCAL_MouseMove(infoPtr
, lParam
);
2056 return MONTHCAL_LButtonUp(infoPtr
, lParam
);
2058 case WM_PRINTCLIENT
:
2060 return MONTHCAL_Paint(infoPtr
, (HDC
)wParam
);
2063 return MONTHCAL_SetFocus(infoPtr
);
2066 return MONTHCAL_Size(infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
2069 return MONTHCAL_Create(hwnd
, (LPCREATESTRUCTW
)lParam
);
2072 return MONTHCAL_SetFont(infoPtr
, (HFONT
)wParam
, (BOOL
)lParam
);
2075 return MONTHCAL_GetFont(infoPtr
);
2078 return MONTHCAL_Timer(infoPtr
, wParam
);
2080 case WM_THEMECHANGED
:
2081 return theme_changed (infoPtr
);
2084 return MONTHCAL_Destroy(infoPtr
);
2086 case WM_SYSCOLORCHANGE
:
2087 COMCTL32_RefreshSysColors();
2090 case WM_STYLECHANGED
:
2091 return MONTHCAL_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
2094 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
2095 ERR( "unknown msg %04x wp=%08lx lp=%08lx\n", uMsg
, wParam
, lParam
);
2096 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
2102 MONTHCAL_Register(void)
2106 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
2107 wndClass
.style
= CS_GLOBALCLASS
;
2108 wndClass
.lpfnWndProc
= MONTHCAL_WindowProc
;
2109 wndClass
.cbClsExtra
= 0;
2110 wndClass
.cbWndExtra
= sizeof(MONTHCAL_INFO
*);
2111 wndClass
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
2112 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
2113 wndClass
.lpszClassName
= MONTHCAL_CLASSW
;
2115 RegisterClassW(&wndClass
);
2120 MONTHCAL_Unregister(void)
2122 UnregisterClassW(MONTHCAL_CLASSW
, NULL
);