2 * 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>
9 * Copyright 2009 Nikolay Sivov
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 * This code was audited for completeness against the documented features
28 * of Comctl32.dll version 6.0 on Oct. 20, 2004, by Dimitrie O. Paun.
30 * Unless otherwise noted, we believe this code to be complete, as per
31 * the specification mentioned above.
32 * If you discover missing features, or bugs, please note them below.
35 * -- MCM_[GS]ETUNICODEFORMAT
36 * -- MONTHCAL_GetMonthRange
37 * -- handle resources better (doesn't work now);
38 * -- take care of internationalization.
39 * -- keyboard handling.
58 #include "wine/unicode.h"
59 #include "wine/debug.h"
61 WINE_DEFAULT_DEBUG_CHANNEL(monthcal
);
63 #define MC_SEL_LBUTUP 1 /* Left button released */
64 #define MC_SEL_LBUTDOWN 2 /* Left button pressed in calendar */
65 #define MC_PREVPRESSED 4 /* Prev month button pressed */
66 #define MC_NEXTPRESSED 8 /* Next month button pressed */
67 #define MC_PREVNEXTMONTHDELAY 350 /* when continuously pressing `next/prev
68 month', wait 500 ms before going
69 to the next/prev month */
70 #define MC_TODAYUPDATEDELAY 120000 /* time between today check for update (2 min) */
72 #define MC_PREVNEXTMONTHTIMER 1 /* Timer ID's */
73 #define MC_TODAYUPDATETIMER 2
75 #define countof(arr) (sizeof(arr)/sizeof(arr[0]))
77 /* convert from days to 100 nanoseconds unit - used as FILETIME unit */
78 #define DAYSTO100NSECS(days) (((ULONGLONG)(days))*24*60*60*10000000)
83 DWORD dwStyle
; /* cached GWL_STYLE */
96 INT delta
; /* scroll rate; # of months that the */
97 /* control moves when user clicks a scroll button */
98 int visible
; /* # of months visible */
99 int firstDay
; /* Start month calendar with firstDay's day,
100 stored in SYSTEMTIME format */
101 BOOL firstDaySet
; /* first week day differs from locale defined */
103 BOOL isUnicode
; /* value set with MCM_SETUNICODE format */
106 MONTHDAYSTATE
*monthdayState
;
107 SYSTEMTIME todaysDate
;
108 BOOL todaySet
; /* Today was forced with MCM_SETTODAY */
109 int status
; /* See MC_SEL flags */
110 SYSTEMTIME firstSel
; /* first selected day */
114 SYSTEMTIME curSel
; /* contains currently selected year, month and day */
115 SYSTEMTIME focusedSel
; /* date currently focused with mouse movement */
120 RECT title
; /* rect for the header above the calendar */
121 RECT titlebtnnext
; /* the `next month' button in the header */
122 RECT titlebtnprev
; /* the `prev month' button in the header */
123 RECT titlemonth
; /* the `month name' txt in the header */
124 RECT titleyear
; /* the `year number' txt in the header */
125 RECT wdays
; /* week days at top */
126 RECT days
; /* calendar area */
127 RECT weeknums
; /* week numbers at left side */
128 RECT todayrect
; /* `today: xx/xx/xx' text rect */
129 HWND hwndNotify
; /* Window to receive the notifications */
130 HWND hWndYearEdit
; /* Window Handle of edit box to handle years */
131 HWND hWndYearUpDown
;/* Window Handle of updown box to handle years */
132 WNDPROC EditWndProc
; /* original Edit window procedure */
133 } MONTHCAL_INFO
, *LPMONTHCAL_INFO
;
135 static const WCHAR themeClass
[] = { 'S','c','r','o','l','l','b','a','r',0 };
137 /* empty SYSTEMTIME const */
138 static const SYSTEMTIME st_null
;
139 /* valid date limits */
140 static const SYSTEMTIME max_allowed_date
= { .wYear
= 9999, .wMonth
= 12, .wDay
= 31 };
141 static const SYSTEMTIME min_allowed_date
= { .wYear
= 1752, .wMonth
= 9, .wDay
= 14 };
144 #define MONTHCAL_GetInfoPtr(hwnd) ((MONTHCAL_INFO *)GetWindowLongPtrW(hwnd, 0))
146 /* helper functions */
148 /* send a single MCN_SELCHANGE notification */
149 static inline void MONTHCAL_NotifySelectionChange(const MONTHCAL_INFO
*infoPtr
)
153 nmsc
.nmhdr
.hwndFrom
= infoPtr
->hwndSelf
;
154 nmsc
.nmhdr
.idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
155 nmsc
.nmhdr
.code
= MCN_SELCHANGE
;
156 nmsc
.stSelStart
= infoPtr
->minSel
;
157 nmsc
.stSelEnd
= infoPtr
->maxSel
;
158 SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, nmsc
.nmhdr
.idFrom
, (LPARAM
)&nmsc
);
161 /* send a single MCN_SELECT notification */
162 static inline void MONTHCAL_NotifySelect(const MONTHCAL_INFO
*infoPtr
)
166 nmsc
.nmhdr
.hwndFrom
= infoPtr
->hwndSelf
;
167 nmsc
.nmhdr
.idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
168 nmsc
.nmhdr
.code
= MCN_SELECT
;
169 nmsc
.stSelStart
= infoPtr
->minSel
;
170 nmsc
.stSelEnd
= infoPtr
->maxSel
;
172 SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, nmsc
.nmhdr
.idFrom
, (LPARAM
)&nmsc
);
175 /* returns the number of days in any given month, checking for leap days */
176 /* january is 1, december is 12 */
177 int MONTHCAL_MonthLength(int month
, int year
)
179 const int mdays
[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
180 /* Wrap around, this eases handling. Getting length only we shouldn't care
181 about year change here cause January and December have
182 the same day quantity */
188 /* special case for calendar transition year */
189 if(month
== min_allowed_date
.wMonth
&& year
== min_allowed_date
.wYear
) return 19;
191 /* if we have a leap year add 1 day to February */
192 /* a leap year is a year either divisible by 400 */
193 /* or divisible by 4 and not by 100 */
194 if(month
== 2) { /* February */
195 return mdays
[month
- 1] + ((year
%400 == 0) ? 1 : ((year
%100 != 0) &&
196 (year
%4 == 0)) ? 1 : 0);
199 return mdays
[month
- 1];
203 /* compares timestamps using date part only */
204 static inline BOOL
MONTHCAL_IsDateEqual(const SYSTEMTIME
*first
, const SYSTEMTIME
*second
)
206 return (first
->wYear
== second
->wYear
) && (first
->wMonth
== second
->wMonth
) &&
207 (first
->wDay
== second
->wDay
);
210 /* make sure that date fields are valid */
211 static BOOL
MONTHCAL_ValidateDate(const SYSTEMTIME
*time
)
213 if(time
->wMonth
< 1 || time
->wMonth
> 12 ) return FALSE
;
214 if(time
->wDayOfWeek
> 6) return FALSE
;
215 if(time
->wDay
> MONTHCAL_MonthLength(time
->wMonth
, time
->wYear
))
221 /* Copies timestamp part only.
225 * [I] from : source date
228 static void MONTHCAL_CopyTime(const SYSTEMTIME
*from
, SYSTEMTIME
*to
)
230 to
->wHour
= from
->wHour
;
231 to
->wMinute
= from
->wMinute
;
232 to
->wSecond
= from
->wSecond
;
235 /* Copies date part only.
239 * [I] from : source date
242 static void MONTHCAL_CopyDate(const SYSTEMTIME
*from
, SYSTEMTIME
*to
)
244 to
->wYear
= from
->wYear
;
245 to
->wMonth
= from
->wMonth
;
246 to
->wDay
= from
->wDay
;
247 to
->wDayOfWeek
= from
->wDayOfWeek
;
250 /* Compares two dates in SYSTEMTIME format
254 * [I] first : pointer to valid first date data to compare
255 * [I] second : pointer to valid second date data to compare
259 * -1 : first < second
260 * 0 : first == second
263 * Note that no date validation performed, alreadt validated values expected.
265 static LONG
MONTHCAL_CompareSystemTime(const SYSTEMTIME
*first
, const SYSTEMTIME
*second
)
267 FILETIME ft_first
, ft_second
;
269 SystemTimeToFileTime(first
, &ft_first
);
270 SystemTimeToFileTime(second
, &ft_second
);
272 return CompareFileTime(&ft_first
, &ft_second
);
275 static LONG
MONTHCAL_CompareMonths(const SYSTEMTIME
*first
, const SYSTEMTIME
*second
)
277 SYSTEMTIME st_first
, st_second
;
279 st_first
= st_second
= st_null
;
280 MONTHCAL_CopyDate(first
, &st_first
);
281 MONTHCAL_CopyDate(second
, &st_second
);
282 st_first
.wDay
= st_second
.wDay
= 1;
284 return MONTHCAL_CompareSystemTime(&st_first
, &st_second
);
287 static LONG
MONTHCAL_CompareDate(const SYSTEMTIME
*first
, const SYSTEMTIME
*second
)
289 SYSTEMTIME st_first
, st_second
;
291 st_first
= st_second
= st_null
;
292 MONTHCAL_CopyDate(first
, &st_first
);
293 MONTHCAL_CopyDate(second
, &st_second
);
295 return MONTHCAL_CompareSystemTime(&st_first
, &st_second
);
298 /* Checks largest possible date range and configured one
302 * [I] infoPtr : valid pointer to control data
303 * [I] date : pointer to valid date data to check
304 * [I] fix : make date fit valid range
308 * TRUE - date whithin largest and configured range
309 * FALSE - date is outside largest or configured range
311 static BOOL
MONTHCAL_IsDateInValidRange(const MONTHCAL_INFO
*infoPtr
,
312 SYSTEMTIME
*date
, BOOL fix
)
314 const SYSTEMTIME
*fix_st
= NULL
;
316 if(MONTHCAL_CompareSystemTime(date
, &max_allowed_date
) == 1) {
317 fix_st
= &max_allowed_date
;
319 else if(MONTHCAL_CompareSystemTime(date
, &min_allowed_date
) == -1) {
320 fix_st
= &min_allowed_date
;
322 else if(infoPtr
->rangeValid
& GDTR_MAX
) {
323 if((MONTHCAL_CompareSystemTime(date
, &infoPtr
->maxDate
) == 1)) {
324 fix_st
= &infoPtr
->maxDate
;
327 else if(infoPtr
->rangeValid
& GDTR_MIN
) {
328 if((MONTHCAL_CompareSystemTime(date
, &infoPtr
->minDate
) == -1)) {
329 fix_st
= &infoPtr
->minDate
;
334 date
->wYear
= fix_st
->wYear
;
335 date
->wMonth
= fix_st
->wMonth
;
338 return fix_st
? FALSE
: TRUE
;
341 /* Checks passed range width with configured maximum selection count
345 * [I] infoPtr : valid pointer to control data
346 * [I] range0 : pointer to valid date data (requested bound)
347 * [I] range1 : pointer to valid date data (primary bound)
348 * [O] adjust : returns adjusted range bound to fit maximum range (optional)
350 * Adjust value computed basing on primary bound and current maximum selection
351 * count. For simple range check (without adjusted value required) (range0, range1)
352 * relation means nothing.
356 * TRUE - range is shorter or equal to maximum
357 * FALSE - range is larger than maximum
359 static BOOL
MONTHCAL_IsSelRangeValid(const MONTHCAL_INFO
*infoPtr
,
360 const SYSTEMTIME
*range0
,
361 const SYSTEMTIME
*range1
,
364 ULARGE_INTEGER ul_range0
, ul_range1
, ul_diff
;
365 FILETIME ft_range0
, ft_range1
;
368 SystemTimeToFileTime(range0
, &ft_range0
);
369 SystemTimeToFileTime(range1
, &ft_range1
);
371 ul_range0
.u
.LowPart
= ft_range0
.dwLowDateTime
;
372 ul_range0
.u
.HighPart
= ft_range0
.dwHighDateTime
;
373 ul_range1
.u
.LowPart
= ft_range1
.dwLowDateTime
;
374 ul_range1
.u
.HighPart
= ft_range1
.dwHighDateTime
;
376 cmp
= CompareFileTime(&ft_range0
, &ft_range1
);
379 ul_diff
.QuadPart
= ul_range0
.QuadPart
- ul_range1
.QuadPart
;
381 ul_diff
.QuadPart
= -ul_range0
.QuadPart
+ ul_range1
.QuadPart
;
383 if(ul_diff
.QuadPart
>= DAYSTO100NSECS(infoPtr
->maxSelCount
)) {
387 ul_range0
.QuadPart
= ul_range1
.QuadPart
+ DAYSTO100NSECS(infoPtr
->maxSelCount
- 1);
389 ul_range0
.QuadPart
= ul_range1
.QuadPart
- DAYSTO100NSECS(infoPtr
->maxSelCount
- 1);
391 ft_range0
.dwLowDateTime
= ul_range0
.u
.LowPart
;
392 ft_range0
.dwHighDateTime
= ul_range0
.u
.HighPart
;
393 FileTimeToSystemTime(&ft_range0
, adjust
);
401 /* Used in MCM_SETRANGE/MCM_SETSELRANGE to determine resulting time part.
402 Milliseconds are intentionally not validated. */
403 static BOOL
MONTHCAL_ValidateTime(const SYSTEMTIME
*time
)
405 if((time
->wHour
> 24) || (time
->wMinute
> 59) || (time
->wSecond
> 59))
411 /* Note:Depending on DST, this may be offset by a day.
412 Need to find out if we're on a DST place & adjust the clock accordingly.
413 Above function assumes we have a valid data.
414 Valid for year>1752; 1 <= d <= 31, 1 <= m <= 12.
418 /* Returns the day in the week
421 * [i] date : input date
422 * [I] inplace : set calculated value back to date structure
425 * day of week in SYSTEMTIME format: (0 == sunday,..., 6 == saturday)
427 int MONTHCAL_CalculateDayOfWeek(SYSTEMTIME
*date
, BOOL inplace
)
429 SYSTEMTIME st
= st_null
;
432 MONTHCAL_CopyDate(date
, &st
);
434 SystemTimeToFileTime(&st
, &ft
);
435 FileTimeToSystemTime(&ft
, &st
);
437 if (inplace
) date
->wDayOfWeek
= st
.wDayOfWeek
;
439 return st
.wDayOfWeek
;
442 /* properly updates date to point on next month */
443 static inline void MONTHCAL_GetNextMonth(SYSTEMTIME
*date
)
445 if(++date
->wMonth
> 12)
450 MONTHCAL_CalculateDayOfWeek(date
, TRUE
);
453 /* properly updates date to point on prev month */
454 static inline void MONTHCAL_GetPrevMonth(SYSTEMTIME
*date
)
456 if(--date
->wMonth
< 1)
461 MONTHCAL_CalculateDayOfWeek(date
, TRUE
);
464 /* Returns full date for a first currently visible day */
465 static void MONTHCAL_GetMinDate(const MONTHCAL_INFO
*infoPtr
, SYSTEMTIME
*date
)
467 SYSTEMTIME st_first
= infoPtr
->curSel
;
471 firstDay
= MONTHCAL_CalculateDayOfWeek(&st_first
, FALSE
);
473 *date
= infoPtr
->curSel
;
474 MONTHCAL_GetPrevMonth(date
);
476 date
->wDay
= MONTHCAL_MonthLength(date
->wMonth
, date
->wYear
) +
477 (infoPtr
->firstDay
- firstDay
) % 7 + 1;
479 if(date
->wDay
> MONTHCAL_MonthLength(date
->wMonth
, date
->wYear
))
482 /* fix day of week */
483 MONTHCAL_CalculateDayOfWeek(date
, TRUE
);
486 /* Returns full date for a last currently visible day */
487 static void MONTHCAL_GetMaxDate(const MONTHCAL_INFO
*infoPtr
, SYSTEMTIME
*date
)
491 *date
= infoPtr
->curSel
;
492 MONTHCAL_GetNextMonth(date
);
494 MONTHCAL_GetMinDate(infoPtr
, &st
);
495 /* Use month length to get max day. 42 means max day count in calendar area */
496 date
->wDay
= 42 - (MONTHCAL_MonthLength(st
.wMonth
, st
.wYear
) - st
.wDay
+ 1) -
497 MONTHCAL_MonthLength(infoPtr
->curSel
.wMonth
, infoPtr
->curSel
.wYear
);
499 /* fix day of week */
500 MONTHCAL_CalculateDayOfWeek(date
, TRUE
);
503 /* From a given point, calculate the row (weekpos), column(daypos)
504 and day in the calendar. day== 0 mean the last day of tha last month
506 static int MONTHCAL_CalcDayFromPos(const MONTHCAL_INFO
*infoPtr
, int x
, int y
,
507 int *daypos
,int *weekpos
)
509 int retval
, firstDay
;
511 SYSTEMTIME st
= infoPtr
->curSel
;
513 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
515 /* if the point is outside the x bounds of the window put
516 it at the boundary */
517 if (x
> rcClient
.right
)
521 *daypos
= (x
- infoPtr
->days
.left
) / infoPtr
->width_increment
;
522 *weekpos
= (y
- infoPtr
->days
.top
) / infoPtr
->height_increment
;
525 firstDay
= (MONTHCAL_CalculateDayOfWeek(&st
, FALSE
) + 6 - infoPtr
->firstDay
) % 7;
526 retval
= *daypos
+ (7 * *weekpos
) - firstDay
;
530 /* Sets the RECT struct r to the rectangle around the date
534 * [I] infoPtr : pointer to control data
535 * [I] date : date value
536 * [O] x : day column (zero based)
537 * [O] y : week column (zero based)
539 static void MONTHCAL_CalcDayXY(const MONTHCAL_INFO
*infoPtr
,
540 const SYSTEMTIME
*date
, int *x
, int *y
)
542 SYSTEMTIME st
= infoPtr
->curSel
;
547 first
= (MONTHCAL_CalculateDayOfWeek(&st
, FALSE
) + 6 - infoPtr
->firstDay
) % 7;
549 cmp
= MONTHCAL_CompareMonths(date
, &infoPtr
->curSel
);
553 *x
= (first
- MONTHCAL_MonthLength(date
->wMonth
, infoPtr
->curSel
.wYear
) + date
->wDay
) % 7;
558 /* next month calculation is same as for current,
559 just add current month length */
561 first
+= MONTHCAL_MonthLength(infoPtr
->curSel
.wMonth
, infoPtr
->curSel
.wYear
);
564 *x
= (date
->wDay
+ first
) % 7;
565 *y
= (date
->wDay
+ first
- *x
) / 7;
569 /* x: column(day), y: row(week) */
570 static inline void MONTHCAL_CalcDayRect(const MONTHCAL_INFO
*infoPtr
, RECT
*r
, int x
, int y
)
572 r
->left
= infoPtr
->days
.left
+ x
* infoPtr
->width_increment
;
573 r
->right
= r
->left
+ infoPtr
->width_increment
;
574 r
->top
= infoPtr
->days
.top
+ y
* infoPtr
->height_increment
;
575 r
->bottom
= r
->top
+ infoPtr
->textHeight
;
579 /* Sets the RECT struct r to the rectangle around the date */
580 static inline void MONTHCAL_CalcPosFromDay(const MONTHCAL_INFO
*infoPtr
,
581 const SYSTEMTIME
*date
, RECT
*r
)
585 MONTHCAL_CalcDayXY(infoPtr
, date
, &x
, &y
);
586 MONTHCAL_CalcDayRect(infoPtr
, r
, x
, y
);
589 /* Focused day helper:
591 - set focused date to given value;
592 - reset to zero value if NULL passed;
593 - invalidate previous and new day rectangle only if needed.
595 Returns TRUE if focused day changed, FALSE otherwise.
597 static BOOL
MONTHCAL_SetDayFocus(MONTHCAL_INFO
*infoPtr
, const SYSTEMTIME
*st
)
603 /* there's nothing to do if it's the same date,
604 mouse move within same date rectangle case */
605 if(MONTHCAL_IsDateEqual(&infoPtr
->focusedSel
, st
)) return FALSE
;
607 /* invalidate old focused day */
608 MONTHCAL_CalcPosFromDay(infoPtr
, &infoPtr
->focusedSel
, &r
);
609 InvalidateRect(infoPtr
->hwndSelf
, &r
, FALSE
);
611 infoPtr
->focusedSel
= *st
;
614 MONTHCAL_CalcPosFromDay(infoPtr
, &infoPtr
->focusedSel
, &r
);
616 if(!st
&& MONTHCAL_ValidateDate(&infoPtr
->focusedSel
))
617 infoPtr
->focusedSel
= st_null
;
619 /* on set invalidates new day, on reset clears previous focused day */
620 InvalidateRect(infoPtr
->hwndSelf
, &r
, FALSE
);
625 /* Draw today day mark rectangle
627 * [I] hdc : context to draw in
628 * [I] day : day to mark with rectangle
631 static void MONTHCAL_CircleDay(const MONTHCAL_INFO
*infoPtr
, HDC hdc
,
632 const SYSTEMTIME
*date
)
634 HPEN hRedPen
= CreatePen(PS_SOLID
, 1, RGB(255, 0, 0));
635 HPEN hOldPen2
= SelectObject(hdc
, hRedPen
);
639 MONTHCAL_CalcPosFromDay(infoPtr
, date
, &day_rect
);
641 hOldBrush
= SelectObject(hdc
, GetStockObject(NULL_BRUSH
));
642 Rectangle(hdc
, day_rect
.left
, day_rect
.top
, day_rect
.right
, day_rect
.bottom
);
644 SelectObject(hdc
, hOldBrush
);
645 DeleteObject(hRedPen
);
646 SelectObject(hdc
, hOldPen2
);
649 static void MONTHCAL_DrawDay(const MONTHCAL_INFO
*infoPtr
, HDC hdc
, const SYSTEMTIME
*st
,
650 int bold
, const PAINTSTRUCT
*ps
)
652 static const WCHAR fmtW
[] = { '%','d',0 };
655 static BOOL bold_selected
;
656 BOOL selected_day
= FALSE
;
661 /* No need to check styles: when selection is not valid, it is set to zero.
662 * 1<day<31, so everything is OK.
665 MONTHCAL_CalcPosFromDay(infoPtr
, st
, &r
);
666 if(!IntersectRect(&r_temp
, &(ps
->rcPaint
), &r
)) return;
668 if ((MONTHCAL_CompareDate(st
, &infoPtr
->minSel
) >= 0) &&
669 (MONTHCAL_CompareDate(st
, &infoPtr
->maxSel
) <= 0)) {
671 TRACE("%d %d %d\n", st
->wDay
, infoPtr
->minSel
.wDay
, infoPtr
->maxSel
.wDay
);
672 TRACE("%s\n", wine_dbgstr_rect(&r
));
673 oldCol
= SetTextColor(hdc
, infoPtr
->monthbk
);
674 oldBk
= SetBkColor(hdc
, infoPtr
->trailingtxt
);
675 hbr
= GetSysColorBrush(COLOR_HIGHLIGHT
);
676 FillRect(hdc
, &r
, hbr
);
681 if(bold
&& !bold_selected
) {
682 SelectObject(hdc
, infoPtr
->hBoldFont
);
683 bold_selected
= TRUE
;
685 if(!bold
&& bold_selected
) {
686 SelectObject(hdc
, infoPtr
->hFont
);
687 bold_selected
= FALSE
;
690 SetBkMode(hdc
,TRANSPARENT
);
691 wsprintfW(buf
, fmtW
, st
->wDay
);
692 DrawTextW(hdc
, buf
, -1, &r
, DT_CENTER
| DT_VCENTER
| DT_SINGLELINE
);
695 SetTextColor(hdc
, oldCol
);
696 SetBkColor(hdc
, oldBk
);
701 static void MONTHCAL_PaintButton(MONTHCAL_INFO
*infoPtr
, HDC hdc
, BOOL btnNext
)
703 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
704 RECT
*r
= btnNext
? &infoPtr
->titlebtnnext
: &infoPtr
->titlebtnprev
;
705 BOOL pressed
= btnNext
? (infoPtr
->status
& MC_NEXTPRESSED
) :
706 (infoPtr
->status
& MC_PREVPRESSED
);
709 static const int states
[] = {
711 ABS_LEFTNORMAL
, ABS_LEFTPRESSED
, ABS_LEFTDISABLED
,
713 ABS_RIGHTNORMAL
, ABS_RIGHTPRESSED
, ABS_RIGHTDISABLED
715 int stateNum
= btnNext
? 3 : 0;
720 if (infoPtr
->dwStyle
& WS_DISABLED
) stateNum
+= 2;
722 DrawThemeBackground (theme
, hdc
, SBP_ARROWBTN
, states
[stateNum
], r
, NULL
);
726 int style
= btnNext
? DFCS_SCROLLRIGHT
: DFCS_SCROLLLEFT
;
728 style
|= DFCS_PUSHED
;
731 if (infoPtr
->dwStyle
& WS_DISABLED
) style
|= DFCS_INACTIVE
;
734 DrawFrameControl(hdc
, r
, DFC_SCROLL
, style
);
737 /* paint a title with buttons and month/year string */
738 static void MONTHCAL_PaintTitle(MONTHCAL_INFO
*infoPtr
, HDC hdc
, const PAINTSTRUCT
*ps
)
740 static const WCHAR fmt_monthW
[] = { '%','s',' ','%','l','d',0 };
741 WCHAR buf_month
[80], buf_fmt
[80];
743 RECT
*title
= &infoPtr
->title
;
746 /* fill header box */
747 hbr
= CreateSolidBrush(infoPtr
->titlebk
);
748 FillRect(hdc
, title
, hbr
);
751 /* navigation buttons */
752 MONTHCAL_PaintButton(infoPtr
, hdc
, FALSE
);
753 MONTHCAL_PaintButton(infoPtr
, hdc
, TRUE
);
755 /* month/year string */
756 SetBkColor(hdc
, infoPtr
->titlebk
);
757 SetTextColor(hdc
, infoPtr
->titletxt
);
758 SelectObject(hdc
, infoPtr
->hBoldFont
);
760 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SMONTHNAME1
+infoPtr
->curSel
.wMonth
-1,
761 buf_month
, countof(buf_month
));
763 wsprintfW(buf_fmt
, fmt_monthW
, buf_month
, infoPtr
->curSel
.wYear
);
764 DrawTextW(hdc
, buf_fmt
, strlenW(buf_fmt
), title
,
765 DT_CENTER
| DT_VCENTER
| DT_SINGLELINE
);
767 /* update title rectangles with current month - used while testing hits */
768 GetTextExtentPoint32W(hdc
, buf_fmt
, strlenW(buf_fmt
), &sz
);
769 infoPtr
->titlemonth
.left
= title
->right
/ 2 + title
->left
/ 2 - sz
.cx
/ 2;
770 infoPtr
->titleyear
.right
= title
->right
/ 2 + title
->left
/ 2 + sz
.cx
/ 2;
772 GetTextExtentPoint32W(hdc
, buf_month
, strlenW(buf_month
), &sz
);
773 infoPtr
->titlemonth
.right
= infoPtr
->titlemonth
.left
+ sz
.cx
;
774 infoPtr
->titleyear
.left
= infoPtr
->titlemonth
.right
;
777 static void MONTHCAL_PaintWeeknumbers(MONTHCAL_INFO
*infoPtr
, HDC hdc
, const PAINTSTRUCT
*ps
)
779 static const WCHAR fmt_weekW
[] = { '%','d',0 };
780 INT mindays
, weeknum
, weeknum1
, startofprescal
;
781 SYSTEMTIME st
= infoPtr
->curSel
;
786 if (!(infoPtr
->dwStyle
& MCS_WEEKNUMBERS
)) return;
788 MONTHCAL_GetMinDate(infoPtr
, &st
);
789 startofprescal
= st
.wDay
;
790 st
= infoPtr
->curSel
;
792 prev_month
= infoPtr
->curSel
.wMonth
- 1;
793 if(prev_month
== 0) prev_month
= 12;
796 Rules what week to call the first week of a new year:
797 LOCALE_IFIRSTWEEKOFYEAR == 0 (e.g US?):
798 The week containing Jan 1 is the first week of year
799 LOCALE_IFIRSTWEEKOFYEAR == 2 (e.g. Germany):
800 First week of year must contain 4 days of the new year
801 LOCALE_IFIRSTWEEKOFYEAR == 1 (what contries?)
802 The first week of the year must contain only days of the new year
804 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_IFIRSTWEEKOFYEAR
, buf
, countof(buf
));
805 weeknum
= atoiW(buf
);
815 WARN("Unknown LOCALE_IFIRSTWEEKOFYEAR value %d, defaulting to 0\n", weeknum
);
819 if (infoPtr
->curSel
.wMonth
== 1)
821 /* calculate all those exceptions for january */
822 st
.wDay
= st
.wMonth
= 1;
823 weeknum1
= MONTHCAL_CalculateDayOfWeek(&st
, FALSE
);
824 if ((infoPtr
->firstDay
- weeknum1
) % 7 > mindays
)
829 for(i
= 0; i
< 11; i
++)
830 weeknum
+= MONTHCAL_MonthLength(i
+1, infoPtr
->curSel
.wYear
- 1);
832 weeknum
+= startofprescal
+ 7;
835 weeknum1
= MONTHCAL_CalculateDayOfWeek(&st
, FALSE
);
836 if ((infoPtr
->firstDay
- weeknum1
) % 7 > mindays
) weeknum
++;
842 for(i
= 0; i
< prev_month
- 1; i
++)
843 weeknum
+= MONTHCAL_MonthLength(i
+1, infoPtr
->curSel
.wYear
);
845 weeknum
+= startofprescal
+ 7;
847 st
.wDay
= st
.wMonth
= 1;
848 weeknum1
= MONTHCAL_CalculateDayOfWeek(&st
, FALSE
);
849 if ((infoPtr
->firstDay
- weeknum1
) % 7 > mindays
) weeknum
++;
852 r
= infoPtr
->weeknums
;
853 r
.bottom
= r
.top
+ infoPtr
->height_increment
;
855 for(i
= 0; i
< 6; i
++) {
856 if((i
== 0) && (weeknum
> 50))
858 wsprintfW(buf
, fmt_weekW
, weeknum
);
861 else if((i
== 5) && (weeknum
> 47))
863 wsprintfW(buf
, fmt_weekW
, 1);
866 wsprintfW(buf
, fmt_weekW
, weeknum
+ i
);
868 DrawTextW(hdc
, buf
, -1, &r
, DT_CENTER
| DT_VCENTER
| DT_SINGLELINE
);
869 OffsetRect(&r
, 0, infoPtr
->height_increment
);
872 /* line separator for week numbers column */
873 MoveToEx(hdc
, infoPtr
->weeknums
.right
, infoPtr
->weeknums
.top
+ 3 , NULL
);
874 LineTo(hdc
, infoPtr
->weeknums
.right
, infoPtr
->weeknums
.bottom
);
877 /* paint a calendar area */
878 static void MONTHCAL_PaintCalendar(MONTHCAL_INFO
*infoPtr
, HDC hdc
, const PAINTSTRUCT
*ps
)
880 INT prev_month
, i
, j
;
887 UnionRect(&r
, &infoPtr
->wdays
, &infoPtr
->todayrect
);
889 hbr
= CreateSolidBrush(infoPtr
->monthbk
);
890 FillRect(hdc
, &r
, hbr
);
893 /* draw line under day abbreviations */
894 MoveToEx(hdc
, infoPtr
->days
.left
+ 3,
895 infoPtr
->title
.bottom
+ infoPtr
->textHeight
+ 1, NULL
);
896 LineTo(hdc
, infoPtr
->days
.right
- 3,
897 infoPtr
->title
.bottom
+ infoPtr
->textHeight
+ 1);
899 prev_month
= infoPtr
->curSel
.wMonth
- 1;
900 if(prev_month
== 0) prev_month
= 12;
902 infoPtr
->wdays
.left
= infoPtr
->days
.left
= infoPtr
->weeknums
.right
;
904 /* 1. draw day abbreviations */
905 SelectObject(hdc
, infoPtr
->hFont
);
906 SetBkColor(hdc
, infoPtr
->monthbk
);
907 SetTextColor(hdc
, infoPtr
->trailingtxt
);
908 /* rectangle to draw a single day abbreviation within */
910 r
.right
= r
.left
+ infoPtr
->width_increment
;
912 i
= infoPtr
->firstDay
;
913 for(j
= 0; j
< 7; j
++) {
914 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SABBREVDAYNAME1
+ (i
+j
+6)%7, buf
, countof(buf
));
915 DrawTextW(hdc
, buf
, strlenW(buf
), &r
, DT_CENTER
| DT_VCENTER
| DT_SINGLELINE
);
916 OffsetRect(&r
, infoPtr
->width_increment
, 0);
919 /* 2. previous and next months */
920 if (!(infoPtr
->dwStyle
& MCS_NOTRAILINGDATES
))
924 SetTextColor(hdc
, infoPtr
->trailingtxt
);
926 MONTHCAL_GetMinDate(infoPtr
, &st
);
928 /* draw prev month */
929 mask
= 1 << (st
.wDay
-1);
930 while(st
.wDay
<= MONTHCAL_MonthLength(prev_month
, infoPtr
->curSel
.wYear
)) {
931 MONTHCAL_DrawDay(infoPtr
, hdc
, &st
, infoPtr
->monthdayState
[0] & mask
, ps
);
936 /* draw next month */
937 st
= infoPtr
->curSel
;
939 MONTHCAL_GetNextMonth(&st
);
940 MONTHCAL_GetMaxDate(infoPtr
, &st_max
);
942 while(st
.wDay
<= st_max
.wDay
) {
943 MONTHCAL_DrawDay(infoPtr
, hdc
, &st
, infoPtr
->monthdayState
[2] & mask
, ps
);
949 /* 3. current month */
950 SetTextColor(hdc
, infoPtr
->txt
);
951 st
= infoPtr
->curSel
;
954 while(st
.wDay
<= MONTHCAL_MonthLength(infoPtr
->curSel
.wMonth
, infoPtr
->curSel
.wYear
)) {
955 MONTHCAL_DrawDay(infoPtr
, hdc
, &st
, infoPtr
->monthdayState
[1] & mask
,
961 /* 4. bottom today date */
962 if(!(infoPtr
->dwStyle
& MCS_NOTODAY
)) {
963 static const WCHAR todayW
[] = { 'T','o','d','a','y',':',0 };
964 static const WCHAR fmt_todayW
[] = { '%','s',' ','%','s',0 };
965 WCHAR buf_todayW
[30], buf_dateW
[20];
968 if(!(infoPtr
->dwStyle
& MCS_NOTODAYCIRCLE
)) {
971 MONTHCAL_GetMaxDate(infoPtr
, &fake_st
);
972 /* this is always safe cause next month will never fully fit calendar */
974 MONTHCAL_CircleDay(infoPtr
, hdc
, &fake_st
);
976 if (!LoadStringW(COMCTL32_hModule
, IDM_TODAY
, buf_todayW
, countof(buf_todayW
)))
978 WARN("Can't load resource\n");
979 strcpyW(buf_todayW
, todayW
);
981 MONTHCAL_CalcDayRect(infoPtr
, &rtoday
, 1, 6);
982 GetDateFormatW(LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, &infoPtr
->todaysDate
, NULL
,
983 buf_dateW
, countof(buf_dateW
));
984 SelectObject(hdc
, infoPtr
->hBoldFont
);
986 wsprintfW(buf
, fmt_todayW
, buf_todayW
, buf_dateW
);
987 DrawTextW(hdc
, buf
, -1, &rtoday
, DT_CALCRECT
| DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
);
988 DrawTextW(hdc
, buf
, -1, &rtoday
, DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
);
990 SelectObject(hdc
, infoPtr
->hFont
);
993 /* 5. today mark + focus */
994 if((infoPtr
->curSel
.wMonth
== infoPtr
->todaysDate
.wMonth
) &&
995 (infoPtr
->curSel
.wYear
== infoPtr
->todaysDate
.wYear
) &&
996 !(infoPtr
->dwStyle
& MCS_NOTODAYCIRCLE
))
998 MONTHCAL_CircleDay(infoPtr
, hdc
, &infoPtr
->todaysDate
);
1001 if(!MONTHCAL_IsDateEqual(&infoPtr
->focusedSel
, &st_null
))
1003 MONTHCAL_CalcPosFromDay(infoPtr
, &infoPtr
->focusedSel
, &r
);
1004 DrawFocusRect(hdc
, &r
);
1008 static void MONTHCAL_Refresh(MONTHCAL_INFO
*infoPtr
, HDC hdc
, const PAINTSTRUCT
*ps
)
1010 RECT
*title
= &infoPtr
->title
;
1011 COLORREF old_text_clr
, old_bk_clr
;
1015 old_text_clr
= SetTextColor(hdc
, comctl32_color
.clrWindowText
);
1016 old_bk_clr
= GetBkColor(hdc
);
1017 old_font
= GetCurrentObject(hdc
, OBJ_FONT
);
1019 /* draw title, redraw all its elements */
1020 if(IntersectRect(&r_temp
, &(ps
->rcPaint
), title
))
1021 MONTHCAL_PaintTitle(infoPtr
, hdc
, ps
);
1023 /* draw calendar area */
1024 UnionRect(&r_temp
, &infoPtr
->wdays
, &infoPtr
->todayrect
);
1025 if(IntersectRect(&r_temp
, &(ps
->rcPaint
), &r_temp
))
1026 MONTHCAL_PaintCalendar(infoPtr
, hdc
, ps
);
1029 MONTHCAL_PaintWeeknumbers(infoPtr
, hdc
, ps
);
1031 /* restore context */
1032 SetBkColor(hdc
, old_bk_clr
);
1033 SelectObject(hdc
, old_font
);
1034 SetTextColor(hdc
, old_text_clr
);
1038 MONTHCAL_GetMinReqRect(const MONTHCAL_INFO
*infoPtr
, LPRECT lpRect
)
1040 TRACE("rect %p\n", lpRect
);
1042 if(!lpRect
) return FALSE
;
1044 lpRect
->left
= infoPtr
->title
.left
;
1045 lpRect
->top
= infoPtr
->title
.top
;
1046 lpRect
->right
= infoPtr
->title
.right
;
1047 lpRect
->bottom
= infoPtr
->todayrect
.bottom
;
1049 AdjustWindowRect(lpRect
, infoPtr
->dwStyle
, FALSE
);
1051 /* minimal rectangle is zero based */
1052 OffsetRect(lpRect
, -lpRect
->left
, -lpRect
->top
);
1054 TRACE("%s\n", wine_dbgstr_rect(lpRect
));
1061 MONTHCAL_GetColor(const MONTHCAL_INFO
*infoPtr
, INT index
)
1066 case MCSC_BACKGROUND
:
1069 return infoPtr
->txt
;
1071 return infoPtr
->titlebk
;
1072 case MCSC_TITLETEXT
:
1073 return infoPtr
->titletxt
;
1075 return infoPtr
->monthbk
;
1076 case MCSC_TRAILINGTEXT
:
1077 return infoPtr
->trailingtxt
;
1085 MONTHCAL_SetColor(MONTHCAL_INFO
*infoPtr
, INT index
, COLORREF color
)
1089 TRACE("%d: color %08x\n", index
, color
);
1092 case MCSC_BACKGROUND
:
1094 infoPtr
->bk
= color
;
1097 prev
= infoPtr
->txt
;
1098 infoPtr
->txt
= color
;
1101 prev
= infoPtr
->titlebk
;
1102 infoPtr
->titlebk
= color
;
1104 case MCSC_TITLETEXT
:
1105 prev
=infoPtr
->titletxt
;
1106 infoPtr
->titletxt
= color
;
1109 prev
= infoPtr
->monthbk
;
1110 infoPtr
->monthbk
= color
;
1112 case MCSC_TRAILINGTEXT
:
1113 prev
= infoPtr
->trailingtxt
;
1114 infoPtr
->trailingtxt
= color
;
1118 InvalidateRect(infoPtr
->hwndSelf
, NULL
, index
== MCSC_BACKGROUND
? TRUE
: FALSE
);
1124 MONTHCAL_GetMonthDelta(const MONTHCAL_INFO
*infoPtr
)
1129 return infoPtr
->delta
;
1131 return infoPtr
->visible
;
1136 MONTHCAL_SetMonthDelta(MONTHCAL_INFO
*infoPtr
, INT delta
)
1138 INT prev
= infoPtr
->delta
;
1140 TRACE("delta %d\n", delta
);
1142 infoPtr
->delta
= delta
;
1147 static inline LRESULT
1148 MONTHCAL_GetFirstDayOfWeek(const MONTHCAL_INFO
*infoPtr
)
1152 /* convert from SYSTEMTIME to locale format */
1153 day
= (infoPtr
->firstDay
>= 0) ? (infoPtr
->firstDay
+6)%7 : infoPtr
->firstDay
;
1155 return MAKELONG(day
, infoPtr
->firstDaySet
);
1159 /* Sets the first day of the week that will appear in the control
1163 * [I] infoPtr : valid pointer to control data
1164 * [I] day : day number to set as new first day (0 == Monday,...,6 == Sunday)
1168 * Low word contains previous first day,
1169 * high word indicates was first day forced with this message before or is
1170 * locale difined (TRUE - was forced, FALSE - wasn't).
1172 * FIXME: this needs to be implemented properly in MONTHCAL_Refresh()
1173 * FIXME: we need more error checking here
1176 MONTHCAL_SetFirstDayOfWeek(MONTHCAL_INFO
*infoPtr
, INT day
)
1178 LRESULT prev
= MONTHCAL_GetFirstDayOfWeek(infoPtr
);
1187 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_IFIRSTDAYOFWEEK
, buf
, countof(buf
));
1188 TRACE("%s %d\n", debugstr_w(buf
), strlenW(buf
));
1190 new_day
= atoiW(buf
);
1192 infoPtr
->firstDaySet
= FALSE
;
1196 new_day
= 6; /* max first day allowed */
1197 infoPtr
->firstDaySet
= TRUE
;
1201 /* Native behaviour for that case is broken: invalid date number >31
1202 got displayed at (0,0) position, current month starts always from
1203 (1,0) position. Should be implemnted here as well. */
1205 FIXME("No bug compatibility for day=%d\n", day
);
1208 infoPtr
->firstDaySet
= TRUE
;
1211 /* convert from locale to SYSTEMTIME format */
1212 infoPtr
->firstDay
= (new_day
>= 0) ? (++new_day
) % 7 : new_day
;
1214 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1221 MONTHCAL_GetMonthRange(const MONTHCAL_INFO
*infoPtr
, DWORD flag
, SYSTEMTIME
*st
)
1230 /*FIXME: currently multicalendar feature isn't implemented, so entirely
1231 visible month is current */
1232 st
[0] = st
[1] = infoPtr
->curSel
;
1234 if (infoPtr
->curSel
.wMonth
== min_allowed_date
.wMonth
&&
1235 infoPtr
->curSel
.wYear
== min_allowed_date
.wYear
)
1237 st
[0].wDay
= min_allowed_date
.wDay
;
1241 MONTHCAL_CalculateDayOfWeek(&st
[0], TRUE
);
1243 st
[1].wDay
= MONTHCAL_MonthLength(st
[1].wMonth
, st
[1].wYear
);
1244 MONTHCAL_CalculateDayOfWeek(&st
[1], TRUE
);
1245 /* a single current month used */
1250 /*FIXME: currently multicalendar feature isn't implemented,
1251 min date from previous month and max date from next one returned */
1252 MONTHCAL_GetMinDate(infoPtr
, &st
[0]);
1253 MONTHCAL_GetMaxDate(infoPtr
, &st
[1]);
1257 WARN("Unknown flag value, got %d\n", flag
);
1261 return infoPtr
->monthRange
;
1266 MONTHCAL_GetMaxTodayWidth(const MONTHCAL_INFO
*infoPtr
)
1268 return(infoPtr
->todayrect
.right
- infoPtr
->todayrect
.left
);
1273 MONTHCAL_SetRange(MONTHCAL_INFO
*infoPtr
, SHORT limits
, SYSTEMTIME
*range
)
1275 FILETIME ft_min
, ft_max
;
1277 TRACE("%x %p\n", limits
, range
);
1279 if ((limits
& GDTR_MIN
&& !MONTHCAL_ValidateDate(&range
[0])) ||
1280 (limits
& GDTR_MAX
&& !MONTHCAL_ValidateDate(&range
[1])))
1283 if (limits
& GDTR_MIN
)
1285 if (!MONTHCAL_ValidateTime(&range
[0]))
1286 MONTHCAL_CopyTime(&infoPtr
->todaysDate
, &range
[0]);
1288 infoPtr
->minDate
= range
[0];
1289 infoPtr
->rangeValid
|= GDTR_MIN
;
1291 if (limits
& GDTR_MAX
)
1293 if (!MONTHCAL_ValidateTime(&range
[1]))
1294 MONTHCAL_CopyTime(&infoPtr
->todaysDate
, &range
[1]);
1296 infoPtr
->maxDate
= range
[1];
1297 infoPtr
->rangeValid
|= GDTR_MAX
;
1300 /* Only one limit set - we are done */
1301 if ((infoPtr
->rangeValid
& (GDTR_MIN
| GDTR_MAX
)) != (GDTR_MIN
| GDTR_MAX
))
1304 SystemTimeToFileTime(&infoPtr
->maxDate
, &ft_max
);
1305 SystemTimeToFileTime(&infoPtr
->minDate
, &ft_min
);
1307 if (CompareFileTime(&ft_min
, &ft_max
) >= 0)
1309 if ((limits
& (GDTR_MIN
| GDTR_MAX
)) == (GDTR_MIN
| GDTR_MAX
))
1311 /* Native swaps limits only when both limits are being set. */
1312 SYSTEMTIME st_tmp
= infoPtr
->minDate
;
1313 infoPtr
->minDate
= infoPtr
->maxDate
;
1314 infoPtr
->maxDate
= st_tmp
;
1318 /* reset the other limit */
1319 if (limits
& GDTR_MIN
) infoPtr
->maxDate
= st_null
;
1320 if (limits
& GDTR_MAX
) infoPtr
->minDate
= st_null
;
1321 infoPtr
->rangeValid
&= limits
& GDTR_MIN
? ~GDTR_MAX
: ~GDTR_MIN
;
1330 MONTHCAL_GetRange(const MONTHCAL_INFO
*infoPtr
, SYSTEMTIME
*range
)
1332 TRACE("%p\n", range
);
1334 if(!range
) return FALSE
;
1336 range
[1] = infoPtr
->maxDate
;
1337 range
[0] = infoPtr
->minDate
;
1339 return infoPtr
->rangeValid
;
1344 MONTHCAL_SetDayState(const MONTHCAL_INFO
*infoPtr
, INT months
, MONTHDAYSTATE
*states
)
1348 TRACE("%d %p\n", months
, states
);
1349 if(months
!= infoPtr
->monthRange
) return 0;
1351 for(i
= 0; i
< months
; i
++)
1352 infoPtr
->monthdayState
[i
] = states
[i
];
1358 MONTHCAL_GetCurSel(const MONTHCAL_INFO
*infoPtr
, SYSTEMTIME
*curSel
)
1360 TRACE("%p\n", curSel
);
1361 if(!curSel
) return FALSE
;
1362 if(infoPtr
->dwStyle
& MCS_MULTISELECT
) return FALSE
;
1364 *curSel
= infoPtr
->curSel
;
1365 TRACE("%d/%d/%d\n", curSel
->wYear
, curSel
->wMonth
, curSel
->wDay
);
1370 MONTHCAL_SetCurSel(MONTHCAL_INFO
*infoPtr
, SYSTEMTIME
*curSel
)
1372 SYSTEMTIME prev
= infoPtr
->curSel
;
1374 TRACE("%p\n", curSel
);
1375 if(!curSel
) return FALSE
;
1376 if(infoPtr
->dwStyle
& MCS_MULTISELECT
) return FALSE
;
1378 if(!MONTHCAL_ValidateDate(curSel
)) return FALSE
;
1379 /* exit earlier if selection equals current */
1380 if (MONTHCAL_IsDateEqual(&infoPtr
->curSel
, curSel
)) return TRUE
;
1382 if(!MONTHCAL_IsDateInValidRange(infoPtr
, curSel
, FALSE
)) return FALSE
;
1384 infoPtr
->minSel
= *curSel
;
1385 infoPtr
->maxSel
= *curSel
;
1387 /* if selection is still in current month, reduce rectangle */
1388 prev
.wDay
= curSel
->wDay
;
1389 if (MONTHCAL_IsDateEqual(&prev
, curSel
))
1393 /* note that infoPtr->curSel isn't updated yet */
1394 MONTHCAL_CalcPosFromDay(infoPtr
, &infoPtr
->curSel
, &r_prev
);
1395 MONTHCAL_CalcPosFromDay(infoPtr
, curSel
, &r_new
);
1397 InvalidateRect(infoPtr
->hwndSelf
, &r_prev
, FALSE
);
1398 InvalidateRect(infoPtr
->hwndSelf
, &r_new
, FALSE
);
1401 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1403 infoPtr
->curSel
= *curSel
;
1410 MONTHCAL_GetMaxSelCount(const MONTHCAL_INFO
*infoPtr
)
1412 return infoPtr
->maxSelCount
;
1417 MONTHCAL_SetMaxSelCount(MONTHCAL_INFO
*infoPtr
, INT max
)
1421 if(!(infoPtr
->dwStyle
& MCS_MULTISELECT
)) return FALSE
;
1422 if(max
<= 0) return FALSE
;
1424 infoPtr
->maxSelCount
= max
;
1431 MONTHCAL_GetSelRange(const MONTHCAL_INFO
*infoPtr
, SYSTEMTIME
*range
)
1433 TRACE("%p\n", range
);
1435 if(!range
) return FALSE
;
1437 if(infoPtr
->dwStyle
& MCS_MULTISELECT
)
1439 range
[1] = infoPtr
->maxSel
;
1440 range
[0] = infoPtr
->minSel
;
1441 TRACE("[min,max]=[%d %d]\n", infoPtr
->minSel
.wDay
, infoPtr
->maxSel
.wDay
);
1450 MONTHCAL_SetSelRange(MONTHCAL_INFO
*infoPtr
, SYSTEMTIME
*range
)
1452 TRACE("%p\n", range
);
1454 if(!range
) return FALSE
;
1456 if(infoPtr
->dwStyle
& MCS_MULTISELECT
)
1458 SYSTEMTIME old_range
[2];
1460 /* adjust timestamps */
1461 if(!MONTHCAL_ValidateTime(&range
[0]))
1462 MONTHCAL_CopyTime(&infoPtr
->todaysDate
, &range
[0]);
1463 if(!MONTHCAL_ValidateTime(&range
[1]))
1464 MONTHCAL_CopyTime(&infoPtr
->todaysDate
, &range
[1]);
1466 /* maximum range exceeded */
1467 if(!MONTHCAL_IsSelRangeValid(infoPtr
, &range
[0], &range
[1], NULL
)) return FALSE
;
1469 old_range
[0] = infoPtr
->minSel
;
1470 old_range
[1] = infoPtr
->maxSel
;
1472 /* swap if min > max */
1473 if(MONTHCAL_CompareSystemTime(&range
[0], &range
[1]) <= 0)
1475 infoPtr
->minSel
= range
[0];
1476 infoPtr
->maxSel
= range
[1];
1480 infoPtr
->minSel
= range
[1];
1481 infoPtr
->maxSel
= range
[0];
1483 infoPtr
->curSel
= infoPtr
->minSel
;
1485 /* update day of week */
1486 MONTHCAL_CalculateDayOfWeek(&infoPtr
->minSel
, TRUE
);
1487 MONTHCAL_CalculateDayOfWeek(&infoPtr
->maxSel
, TRUE
);
1488 MONTHCAL_CalculateDayOfWeek(&infoPtr
->curSel
, TRUE
);
1490 /* redraw if bounds changed */
1491 /* FIXME: no actual need to redraw everything */
1492 if(!MONTHCAL_IsDateEqual(&old_range
[0], &range
[0]) ||
1493 !MONTHCAL_IsDateEqual(&old_range
[1], &range
[1]))
1495 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1498 TRACE("[min,max]=[%d %d]\n", infoPtr
->minSel
.wDay
, infoPtr
->maxSel
.wDay
);
1507 MONTHCAL_GetToday(const MONTHCAL_INFO
*infoPtr
, SYSTEMTIME
*today
)
1509 TRACE("%p\n", today
);
1511 if(!today
) return FALSE
;
1512 *today
= infoPtr
->todaysDate
;
1516 /* Internal helper for MCM_SETTODAY handler and auto update timer handler
1520 * TRUE - today date changed
1521 * FALSE - today date isn't changed
1524 MONTHCAL_UpdateToday(MONTHCAL_INFO
*infoPtr
, const SYSTEMTIME
*today
)
1528 if(MONTHCAL_IsDateEqual(today
, &infoPtr
->todaysDate
)) return FALSE
;
1530 MONTHCAL_CalcPosFromDay(infoPtr
, &infoPtr
->todaysDate
, &old_r
);
1531 MONTHCAL_CalcPosFromDay(infoPtr
, today
, &new_r
);
1533 infoPtr
->todaysDate
= *today
;
1535 /* only two days need redrawing */
1536 InvalidateRect(infoPtr
->hwndSelf
, &old_r
, FALSE
);
1537 InvalidateRect(infoPtr
->hwndSelf
, &new_r
, FALSE
);
1541 /* MCM_SETTODAT handler */
1543 MONTHCAL_SetToday(MONTHCAL_INFO
*infoPtr
, const SYSTEMTIME
*today
)
1545 TRACE("%p\n", today
);
1547 if(!today
) return FALSE
;
1549 /* remember if date was set successfully */
1550 if(MONTHCAL_UpdateToday(infoPtr
, today
)) infoPtr
->todaySet
= TRUE
;
1556 MONTHCAL_HitTest(const MONTHCAL_INFO
*infoPtr
, MCHITTESTINFO
*lpht
)
1562 if(!lpht
|| lpht
->cbSize
< MCHITTESTINFO_V1_SIZE
) return -1;
1567 ZeroMemory(&lpht
->st
, sizeof(lpht
->st
));
1569 /* Comment in for debugging...
1570 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,
1571 infoPtr->wdays.left, infoPtr->wdays.right,
1572 infoPtr->wdays.top, infoPtr->wdays.bottom,
1573 infoPtr->days.left, infoPtr->days.right,
1574 infoPtr->days.top, infoPtr->days.bottom,
1575 infoPtr->todayrect.left, infoPtr->todayrect.right,
1576 infoPtr->todayrect.top, infoPtr->todayrect.bottom,
1577 infoPtr->weeknums.left, infoPtr->weeknums.right,
1578 infoPtr->weeknums.top, infoPtr->weeknums.bottom);
1581 /* are we in the header? */
1583 if(PtInRect(&infoPtr
->title
, lpht
->pt
)) {
1584 if(PtInRect(&infoPtr
->titlebtnprev
, lpht
->pt
)) {
1585 retval
= MCHT_TITLEBTNPREV
;
1588 if(PtInRect(&infoPtr
->titlebtnnext
, lpht
->pt
)) {
1589 retval
= MCHT_TITLEBTNNEXT
;
1592 if(PtInRect(&infoPtr
->titlemonth
, lpht
->pt
)) {
1593 retval
= MCHT_TITLEMONTH
;
1596 if(PtInRect(&infoPtr
->titleyear
, lpht
->pt
)) {
1597 retval
= MCHT_TITLEYEAR
;
1601 retval
= MCHT_TITLE
;
1605 day
= MONTHCAL_CalcDayFromPos(infoPtr
,x
,y
,&wday
,&wnum
);
1606 if(PtInRect(&infoPtr
->wdays
, lpht
->pt
)) {
1607 retval
= MCHT_CALENDARDAY
;
1608 lpht
->st
.wYear
= infoPtr
->curSel
.wYear
;
1609 lpht
->st
.wMonth
= (day
< 1)? infoPtr
->curSel
.wMonth
-1 : infoPtr
->curSel
.wMonth
;
1610 lpht
->st
.wDay
= (day
< 1)?
1611 MONTHCAL_MonthLength(infoPtr
->curSel
.wMonth
-1, infoPtr
->curSel
.wYear
) -day
: day
;
1614 if(PtInRect(&infoPtr
->weeknums
, lpht
->pt
)) {
1615 retval
= MCHT_CALENDARWEEKNUM
;
1616 lpht
->st
.wYear
= infoPtr
->curSel
.wYear
;
1617 lpht
->st
.wMonth
= (day
< 1) ? infoPtr
->curSel
.wMonth
-1 :
1618 (day
> MONTHCAL_MonthLength(infoPtr
->curSel
.wMonth
,infoPtr
->curSel
.wYear
)) ?
1619 infoPtr
->curSel
.wMonth
+1 :infoPtr
->curSel
.wMonth
;
1620 lpht
->st
.wDay
= (day
< 1 ) ?
1621 MONTHCAL_MonthLength(infoPtr
->curSel
.wMonth
-1,infoPtr
->curSel
.wYear
) -day
:
1622 (day
> MONTHCAL_MonthLength(infoPtr
->curSel
.wMonth
,infoPtr
->curSel
.wYear
)) ?
1623 day
- MONTHCAL_MonthLength(infoPtr
->curSel
.wMonth
,infoPtr
->curSel
.wYear
) : day
;
1626 if(PtInRect(&infoPtr
->days
, lpht
->pt
))
1628 lpht
->st
.wYear
= infoPtr
->curSel
.wYear
;
1629 lpht
->st
.wMonth
= infoPtr
->curSel
.wMonth
;
1632 retval
= MCHT_CALENDARDATEPREV
;
1633 MONTHCAL_GetPrevMonth(&lpht
->st
);
1634 lpht
->st
.wDay
= MONTHCAL_MonthLength(lpht
->st
.wMonth
, lpht
->st
.wYear
) + day
;
1636 else if (day
> MONTHCAL_MonthLength(infoPtr
->curSel
.wMonth
, infoPtr
->curSel
.wYear
))
1638 retval
= MCHT_CALENDARDATENEXT
;
1639 MONTHCAL_GetNextMonth(&lpht
->st
);
1640 lpht
->st
.wDay
= day
- MONTHCAL_MonthLength(infoPtr
->curSel
.wMonth
, infoPtr
->curSel
.wYear
);
1643 retval
= MCHT_CALENDARDATE
;
1644 lpht
->st
.wDay
= day
;
1646 /* always update day of week */
1647 MONTHCAL_CalculateDayOfWeek(&lpht
->st
, TRUE
);
1650 if(PtInRect(&infoPtr
->todayrect
, lpht
->pt
)) {
1651 retval
= MCHT_TODAYLINK
;
1656 /* Hit nothing special? What's left must be background :-) */
1658 retval
= MCHT_CALENDARBK
;
1660 lpht
->uHit
= retval
;
1664 /* MCN_GETDAYSTATE notification helper */
1665 static void MONTHCAL_NotifyDayState(MONTHCAL_INFO
*infoPtr
)
1667 if(infoPtr
->dwStyle
& MCS_DAYSTATE
) {
1671 nmds
.nmhdr
.hwndFrom
= infoPtr
->hwndSelf
;
1672 nmds
.nmhdr
.idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1673 nmds
.nmhdr
.code
= MCN_GETDAYSTATE
;
1674 nmds
.cDayState
= infoPtr
->monthRange
;
1675 nmds
.prgDayState
= Alloc(infoPtr
->monthRange
* sizeof(MONTHDAYSTATE
));
1677 nmds
.stStart
= infoPtr
->todaysDate
;
1678 nmds
.stStart
.wYear
= infoPtr
->curSel
.wYear
;
1679 nmds
.stStart
.wMonth
= infoPtr
->curSel
.wMonth
;
1680 nmds
.stStart
.wDay
= 1;
1682 SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, nmds
.nmhdr
.idFrom
, (LPARAM
)&nmds
);
1683 for(i
= 0; i
< infoPtr
->monthRange
; i
++)
1684 infoPtr
->monthdayState
[i
] = nmds
.prgDayState
[i
];
1686 Free(nmds
.prgDayState
);
1690 static void MONTHCAL_GoToPrevNextMonth(MONTHCAL_INFO
*infoPtr
, BOOL prev
)
1692 SYSTEMTIME st
= infoPtr
->curSel
;
1694 TRACE("%s\n", prev
? "prev" : "next");
1696 if(prev
) MONTHCAL_GetPrevMonth(&st
); else MONTHCAL_GetNextMonth(&st
);
1698 if(!MONTHCAL_IsDateInValidRange(infoPtr
, &st
, FALSE
)) return;
1700 if(infoPtr
->dwStyle
& MCS_MULTISELECT
)
1702 SYSTEMTIME range
[2];
1704 range
[0] = infoPtr
->minSel
;
1705 range
[1] = infoPtr
->maxSel
;
1709 MONTHCAL_GetPrevMonth(&range
[0]);
1710 MONTHCAL_GetPrevMonth(&range
[1]);
1714 MONTHCAL_GetNextMonth(&range
[0]);
1715 MONTHCAL_GetNextMonth(&range
[1]);
1718 MONTHCAL_SetSelRange(infoPtr
, range
);
1721 MONTHCAL_SetCurSel(infoPtr
, &st
);
1723 MONTHCAL_NotifyDayState(infoPtr
);
1725 MONTHCAL_NotifySelectionChange(infoPtr
);
1729 MONTHCAL_RButtonUp(MONTHCAL_INFO
*infoPtr
, LPARAM lParam
)
1731 static const WCHAR todayW
[] = { 'G','o',' ','t','o',' ','T','o','d','a','y',':',0 };
1736 hMenu
= CreatePopupMenu();
1737 if (!LoadStringW(COMCTL32_hModule
, IDM_GOTODAY
, buf
, countof(buf
)))
1739 WARN("Can't load resource\n");
1740 strcpyW(buf
, todayW
);
1742 AppendMenuW(hMenu
, MF_STRING
|MF_ENABLED
, 1, buf
);
1743 menupoint
.x
= (short)LOWORD(lParam
);
1744 menupoint
.y
= (short)HIWORD(lParam
);
1745 ClientToScreen(infoPtr
->hwndSelf
, &menupoint
);
1746 if( TrackPopupMenu(hMenu
, TPM_RIGHTBUTTON
| TPM_NONOTIFY
| TPM_RETURNCMD
,
1747 menupoint
.x
, menupoint
.y
, 0, infoPtr
->hwndSelf
, NULL
))
1749 infoPtr
->curSel
= infoPtr
->todaysDate
;
1750 infoPtr
->minSel
= infoPtr
->todaysDate
;
1751 infoPtr
->maxSel
= infoPtr
->todaysDate
;
1752 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1760 * Subclassed edit control windproc function
1763 * [I] hwnd : the edit window handle
1764 * [I] uMsg : the message that is to be processed
1765 * [I] wParam : first message parameter
1766 * [I] lParam : second message parameter
1769 static LRESULT CALLBACK
EditWndProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1771 MONTHCAL_INFO
*infoPtr
= (MONTHCAL_INFO
*)GetWindowLongPtrW(GetParent(hwnd
), 0);
1773 TRACE("(hwnd=%p, uMsg=%x, wParam=%lx, lParam=%lx)\n",
1774 hwnd
, uMsg
, wParam
, lParam
);
1779 return DLGC_WANTARROWS
| DLGC_WANTALLKEYS
;
1783 WNDPROC editProc
= infoPtr
->EditWndProc
;
1784 infoPtr
->EditWndProc
= NULL
;
1785 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (DWORD_PTR
)editProc
);
1786 return CallWindowProcW(editProc
, hwnd
, uMsg
, wParam
, lParam
);
1793 if ((VK_ESCAPE
== (INT
)wParam
) || (VK_RETURN
== (INT
)wParam
))
1797 return CallWindowProcW(infoPtr
->EditWndProc
, hwnd
, uMsg
, wParam
, lParam
);
1800 SendMessageW(infoPtr
->hWndYearUpDown
, WM_CLOSE
, 0, 0);
1801 SendMessageW(hwnd
, WM_CLOSE
, 0, 0);
1805 /* creates updown control and edit box */
1806 static void MONTHCAL_EditYear(MONTHCAL_INFO
*infoPtr
)
1808 infoPtr
->hWndYearEdit
=
1809 CreateWindowExW(0, WC_EDITW
, 0, WS_VISIBLE
| WS_CHILD
| ES_READONLY
,
1810 infoPtr
->titleyear
.left
+ 3, infoPtr
->titlebtnnext
.top
,
1811 infoPtr
->titleyear
.right
- infoPtr
->titleyear
.left
+ 4,
1812 infoPtr
->textHeight
, infoPtr
->hwndSelf
,
1815 SendMessageW(infoPtr
->hWndYearEdit
, WM_SETFONT
, (WPARAM
)infoPtr
->hBoldFont
, TRUE
);
1817 infoPtr
->hWndYearUpDown
=
1818 CreateWindowExW(0, UPDOWN_CLASSW
, 0,
1819 WS_VISIBLE
| WS_CHILD
| UDS_SETBUDDYINT
| UDS_NOTHOUSANDS
| UDS_ARROWKEYS
,
1820 infoPtr
->titleyear
.right
+ 7, infoPtr
->titlebtnnext
.top
,
1821 18, infoPtr
->textHeight
, infoPtr
->hwndSelf
,
1824 /* attach edit box */
1825 SendMessageW(infoPtr
->hWndYearUpDown
, UDM_SETRANGE
, 0,
1826 MAKELONG(max_allowed_date
.wYear
, min_allowed_date
.wYear
));
1827 SendMessageW(infoPtr
->hWndYearUpDown
, UDM_SETBUDDY
, (WPARAM
)infoPtr
->hWndYearEdit
, 0);
1828 SendMessageW(infoPtr
->hWndYearUpDown
, UDM_SETPOS
, 0, infoPtr
->curSel
.wYear
);
1830 /* subclass edit box */
1831 infoPtr
->EditWndProc
= (WNDPROC
)SetWindowLongPtrW(infoPtr
->hWndYearEdit
,
1832 GWLP_WNDPROC
, (DWORD_PTR
)EditWndProc
);
1834 SetFocus(infoPtr
->hWndYearEdit
);
1838 MONTHCAL_LButtonDown(MONTHCAL_INFO
*infoPtr
, LPARAM lParam
)
1843 /* Actually we don't need input focus for calendar, this is used to kill
1844 year updown and its buddy edit box */
1845 if (IsWindow(infoPtr
->hWndYearUpDown
))
1847 SetFocus(infoPtr
->hwndSelf
);
1851 SetCapture(infoPtr
->hwndSelf
);
1853 ht
.cbSize
= sizeof(MCHITTESTINFO
);
1854 ht
.pt
.x
= (short)LOWORD(lParam
);
1855 ht
.pt
.y
= (short)HIWORD(lParam
);
1857 hit
= MONTHCAL_HitTest(infoPtr
, &ht
);
1859 TRACE("%x at (%d, %d)\n", hit
, ht
.pt
.x
, ht
.pt
.y
);
1863 case MCHT_TITLEBTNNEXT
:
1864 MONTHCAL_GoToPrevNextMonth(infoPtr
, FALSE
);
1865 infoPtr
->status
= MC_NEXTPRESSED
;
1866 SetTimer(infoPtr
->hwndSelf
, MC_PREVNEXTMONTHTIMER
, MC_PREVNEXTMONTHDELAY
, 0);
1867 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1870 case MCHT_TITLEBTNPREV
:
1871 MONTHCAL_GoToPrevNextMonth(infoPtr
, TRUE
);
1872 infoPtr
->status
= MC_PREVPRESSED
;
1873 SetTimer(infoPtr
->hwndSelf
, MC_PREVNEXTMONTHTIMER
, MC_PREVNEXTMONTHDELAY
, 0);
1874 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1877 case MCHT_TITLEMONTH
:
1879 HMENU hMenu
= CreatePopupMenu();
1884 for (i
= 0; i
< 12; i
++)
1886 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SMONTHNAME1
+i
, buf
, countof(buf
));
1887 AppendMenuW(hMenu
, MF_STRING
|MF_ENABLED
, i
+ 1, buf
);
1889 menupoint
.x
= ht
.pt
.x
;
1890 menupoint
.y
= ht
.pt
.y
;
1891 ClientToScreen(infoPtr
->hwndSelf
, &menupoint
);
1892 i
= TrackPopupMenu(hMenu
,TPM_LEFTALIGN
| TPM_NONOTIFY
| TPM_RIGHTBUTTON
| TPM_RETURNCMD
,
1893 menupoint
.x
, menupoint
.y
, 0, infoPtr
->hwndSelf
, NULL
);
1895 if ((i
> 0) && (i
< 13) && infoPtr
->curSel
.wMonth
!= i
)
1897 infoPtr
->curSel
.wMonth
= i
;
1898 MONTHCAL_IsDateInValidRange(infoPtr
, &infoPtr
->curSel
, TRUE
);
1899 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1903 case MCHT_TITLEYEAR
:
1905 MONTHCAL_EditYear(infoPtr
);
1908 case MCHT_TODAYLINK
:
1910 infoPtr
->curSel
= infoPtr
->todaysDate
;
1911 infoPtr
->minSel
= infoPtr
->todaysDate
;
1912 infoPtr
->maxSel
= infoPtr
->todaysDate
;
1913 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1915 MONTHCAL_NotifySelectionChange(infoPtr
);
1916 MONTHCAL_NotifySelect(infoPtr
);
1919 case MCHT_CALENDARDATENEXT
:
1920 case MCHT_CALENDARDATEPREV
:
1921 case MCHT_CALENDARDATE
:
1925 MONTHCAL_CopyDate(&ht
.st
, &infoPtr
->firstSel
);
1927 st
[0] = st
[1] = ht
.st
;
1928 /* clear selection range */
1929 MONTHCAL_SetSelRange(infoPtr
, st
);
1931 infoPtr
->status
= MC_SEL_LBUTDOWN
;
1932 MONTHCAL_SetDayFocus(infoPtr
, &ht
.st
);
1942 MONTHCAL_LButtonUp(MONTHCAL_INFO
*infoPtr
, LPARAM lParam
)
1950 if(infoPtr
->status
& (MC_PREVPRESSED
| MC_NEXTPRESSED
)) {
1953 KillTimer(infoPtr
->hwndSelf
, MC_PREVNEXTMONTHTIMER
);
1954 r
= infoPtr
->status
& MC_PREVPRESSED
? &infoPtr
->titlebtnprev
: &infoPtr
->titlebtnnext
;
1955 infoPtr
->status
&= ~(MC_PREVPRESSED
| MC_NEXTPRESSED
);
1957 InvalidateRect(infoPtr
->hwndSelf
, r
, FALSE
);
1962 /* always send NM_RELEASEDCAPTURE notification */
1963 nmhdr
.hwndFrom
= infoPtr
->hwndSelf
;
1964 nmhdr
.idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1965 nmhdr
.code
= NM_RELEASEDCAPTURE
;
1966 TRACE("Sent notification from %p to %p\n", infoPtr
->hwndSelf
, infoPtr
->hwndNotify
);
1968 SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, nmhdr
.idFrom
, (LPARAM
)&nmhdr
);
1970 if(!(infoPtr
->status
& MC_SEL_LBUTDOWN
)) return 0;
1972 ht
.cbSize
= sizeof(MCHITTESTINFO
);
1973 ht
.pt
.x
= (short)LOWORD(lParam
);
1974 ht
.pt
.y
= (short)HIWORD(lParam
);
1975 hit
= MONTHCAL_HitTest(infoPtr
, &ht
);
1977 infoPtr
->status
= MC_SEL_LBUTUP
;
1978 MONTHCAL_SetDayFocus(infoPtr
, NULL
);
1980 if((hit
& MCHT_CALENDARDATE
) == MCHT_CALENDARDATE
)
1982 SYSTEMTIME sel
= infoPtr
->curSel
;
1984 /* will be invalidated here */
1985 MONTHCAL_SetCurSel(infoPtr
, &ht
.st
);
1987 /* send MCN_SELCHANGE only if new date selected */
1988 if (!MONTHCAL_IsDateEqual(&sel
, &ht
.st
))
1989 MONTHCAL_NotifySelectionChange(infoPtr
);
1991 MONTHCAL_NotifySelect(infoPtr
);
1999 MONTHCAL_Timer(MONTHCAL_INFO
*infoPtr
, WPARAM id
)
2004 case MC_PREVNEXTMONTHTIMER
:
2005 if(infoPtr
->status
& MC_NEXTPRESSED
) MONTHCAL_GoToPrevNextMonth(infoPtr
, FALSE
);
2006 if(infoPtr
->status
& MC_PREVPRESSED
) MONTHCAL_GoToPrevNextMonth(infoPtr
, TRUE
);
2007 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
2009 case MC_TODAYUPDATETIMER
:
2013 if(infoPtr
->todaySet
) return 0;
2016 MONTHCAL_UpdateToday(infoPtr
, &st
);
2018 /* notification sent anyway */
2019 MONTHCAL_NotifySelectionChange(infoPtr
);
2024 ERR("got unknown timer %ld\n", id
);
2033 MONTHCAL_MouseMove(MONTHCAL_INFO
*infoPtr
, LPARAM lParam
)
2036 SYSTEMTIME old_focused
, st_ht
;
2040 if(!(infoPtr
->status
& MC_SEL_LBUTDOWN
)) return 0;
2042 ht
.cbSize
= sizeof(MCHITTESTINFO
);
2043 ht
.pt
.x
= (short)LOWORD(lParam
);
2044 ht
.pt
.y
= (short)HIWORD(lParam
);
2046 hit
= MONTHCAL_HitTest(infoPtr
, &ht
);
2048 /* not on the calendar date numbers? bail out */
2049 TRACE("hit:%x\n",hit
);
2050 if((hit
& MCHT_CALENDARDATE
) != MCHT_CALENDARDATE
)
2052 MONTHCAL_SetDayFocus(infoPtr
, NULL
);
2057 old_focused
= infoPtr
->focusedSel
;
2059 /* if pointer is over focused day still there's nothing to do */
2060 if(!MONTHCAL_SetDayFocus(infoPtr
, &ht
.st
)) return 0;
2062 MONTHCAL_CalcPosFromDay(infoPtr
, &ht
.st
, &r
);
2064 if(infoPtr
->dwStyle
& MCS_MULTISELECT
) {
2067 MONTHCAL_GetSelRange(infoPtr
, st
);
2069 /* If we're still at the first selected date and range is empty, return.
2070 If range isn't empty we should change range to a single firstSel */
2071 if(MONTHCAL_IsDateEqual(&infoPtr
->firstSel
, &st_ht
) &&
2072 MONTHCAL_IsDateEqual(&st
[0], &st
[1])) goto done
;
2074 MONTHCAL_IsSelRangeValid(infoPtr
, &st_ht
, &infoPtr
->firstSel
, &st_ht
);
2076 st
[0] = infoPtr
->firstSel
;
2077 /* we should overwrite timestamp here */
2078 MONTHCAL_CopyDate(&st_ht
, &st
[1]);
2080 /* bounds will be swapped here if needed */
2081 MONTHCAL_SetSelRange(infoPtr
, st
);
2088 /* FIXME: this should specify a rectangle containing only the days that changed
2089 using InvalidateRect */
2090 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
2097 MONTHCAL_Paint(MONTHCAL_INFO
*infoPtr
, HDC hdc_paint
)
2104 GetClientRect(infoPtr
->hwndSelf
, &ps
.rcPaint
);
2108 hdc
= BeginPaint(infoPtr
->hwndSelf
, &ps
);
2110 MONTHCAL_Refresh(infoPtr
, hdc
, &ps
);
2111 if (!hdc_paint
) EndPaint(infoPtr
->hwndSelf
, &ps
);
2116 MONTHCAL_EraseBkgnd(const MONTHCAL_INFO
*infoPtr
, HDC hdc
)
2121 if (!GetClipBox(hdc
, &rc
)) return FALSE
;
2123 /* fill background */
2124 hbr
= CreateSolidBrush (infoPtr
->bk
);
2125 FillRect(hdc
, &rc
, hbr
);
2132 MONTHCAL_PrintClient(MONTHCAL_INFO
*infoPtr
, HDC hdc
, DWORD options
)
2134 FIXME("Partial Stub: (hdc=%p options=0x%08x)\n", hdc
, options
);
2136 if ((options
& PRF_CHECKVISIBLE
) && !IsWindowVisible(infoPtr
->hwndSelf
))
2139 if (options
& PRF_ERASEBKGND
)
2140 MONTHCAL_EraseBkgnd(infoPtr
, hdc
);
2142 if (options
& PRF_CLIENT
)
2143 MONTHCAL_Paint(infoPtr
, hdc
);
2149 MONTHCAL_SetFocus(const MONTHCAL_INFO
*infoPtr
)
2153 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
2158 /* sets the size information */
2159 static void MONTHCAL_UpdateSize(MONTHCAL_INFO
*infoPtr
)
2161 static const WCHAR O0W
[] = { '0','0',0 };
2162 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
2163 RECT
*title
=&infoPtr
->title
;
2164 RECT
*prev
=&infoPtr
->titlebtnprev
;
2165 RECT
*next
=&infoPtr
->titlebtnnext
;
2166 RECT
*titlemonth
=&infoPtr
->titlemonth
;
2167 RECT
*titleyear
=&infoPtr
->titleyear
;
2168 RECT
*wdays
=&infoPtr
->wdays
;
2169 RECT
*weeknumrect
=&infoPtr
->weeknums
;
2170 RECT
*days
=&infoPtr
->days
;
2171 RECT
*todayrect
=&infoPtr
->todayrect
;
2175 INT xdiv
, dx
, dy
, i
;
2179 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
2181 currentFont
= SelectObject(hdc
, infoPtr
->hFont
);
2183 /* get the height and width of each day's text */
2184 GetTextMetricsW(hdc
, &tm
);
2185 infoPtr
->textHeight
= tm
.tmHeight
+ tm
.tmExternalLeading
+ tm
.tmInternalLeading
;
2187 /* find largest abbreviated day name for current locale */
2188 size
.cx
= sz
.cx
= 0;
2189 for (i
= 0; i
< 7; i
++)
2191 if(GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SABBREVDAYNAME1
+ i
,
2192 buff
, countof(buff
)))
2194 GetTextExtentPoint32W(hdc
, buff
, lstrlenW(buff
), &sz
);
2195 if (sz
.cx
> size
.cx
) size
.cx
= sz
.cx
;
2197 else /* locale independent fallback on failure */
2199 static const WCHAR SunW
[] = { 'S','u','n',0 };
2201 GetTextExtentPoint32W(hdc
, SunW
, lstrlenW(SunW
), &size
);
2206 infoPtr
->textWidth
= size
.cx
+ 2;
2208 /* recalculate the height and width increments and offsets */
2209 GetTextExtentPoint32W(hdc
, O0W
, 2, &size
);
2211 xdiv
= (infoPtr
->dwStyle
& MCS_WEEKNUMBERS
) ? 8 : 7;
2213 infoPtr
->width_increment
= size
.cx
* 2 + 4;
2214 infoPtr
->height_increment
= infoPtr
->textHeight
;
2216 /* calculate title area */
2218 title
->bottom
= 3 * infoPtr
->height_increment
/ 2;
2220 title
->right
= infoPtr
->width_increment
* xdiv
;
2222 /* set the dimensions of the next and previous buttons and center */
2223 /* the month text vertically */
2224 prev
->top
= next
->top
= title
->top
+ 4;
2225 prev
->bottom
= next
->bottom
= title
->bottom
- 4;
2226 prev
->left
= title
->left
+ 4;
2227 prev
->right
= prev
->left
+ (title
->bottom
- title
->top
);
2228 next
->right
= title
->right
- 4;
2229 next
->left
= next
->right
- (title
->bottom
- title
->top
);
2231 /* titlemonth->left and right change based upon the current month */
2232 /* and are recalculated in refresh as the current month may change */
2233 /* without the control being resized */
2234 titlemonth
->top
= titleyear
->top
= title
->top
+ (infoPtr
->height_increment
)/2;
2235 titlemonth
->bottom
= titleyear
->bottom
= title
->bottom
- (infoPtr
->height_increment
)/2;
2237 /* setup the dimensions of the rectangle we draw the names of the */
2238 /* days of the week in */
2239 weeknumrect
->left
= 0;
2241 if(infoPtr
->dwStyle
& MCS_WEEKNUMBERS
)
2242 weeknumrect
->right
= prev
->right
;
2244 weeknumrect
->right
= weeknumrect
->left
;
2246 wdays
->left
= days
->left
= weeknumrect
->right
;
2247 wdays
->right
= days
->right
= wdays
->left
+ 7 * infoPtr
->width_increment
;
2248 wdays
->top
= title
->bottom
;
2249 wdays
->bottom
= wdays
->top
+ infoPtr
->height_increment
;
2251 days
->top
= weeknumrect
->top
= wdays
->bottom
;
2252 days
->bottom
= weeknumrect
->bottom
= days
->top
+ 6 * infoPtr
->height_increment
;
2254 todayrect
->left
= 0;
2255 todayrect
->right
= title
->right
;
2256 todayrect
->top
= days
->bottom
;
2257 todayrect
->bottom
= days
->bottom
+ infoPtr
->height_increment
;
2259 /* offset all rectangles to center in client area */
2260 dx
= (rcClient
.right
- title
->right
) / 2;
2261 dy
= (rcClient
.bottom
- todayrect
->bottom
) / 2;
2263 /* if calendar doesn't fit client area show it at left/top bounds */
2264 if (title
->left
+ dx
< 0) dx
= 0;
2265 if (title
->top
+ dy
< 0) dy
= 0;
2267 if (dx
!= 0 || dy
!= 0)
2269 OffsetRect(title
, dx
, dy
);
2270 OffsetRect(prev
, dx
, dy
);
2271 OffsetRect(next
, dx
, dy
);
2272 OffsetRect(titlemonth
, dx
, dy
);
2273 OffsetRect(titleyear
, dx
, dy
);
2274 OffsetRect(wdays
, dx
, dy
);
2275 OffsetRect(weeknumrect
, dx
, dy
);
2276 OffsetRect(days
, dx
, dy
);
2277 OffsetRect(todayrect
, dx
, dy
);
2280 TRACE("dx=%d dy=%d client[%s] title[%s] wdays[%s] days[%s] today[%s]\n",
2281 infoPtr
->width_increment
,infoPtr
->height_increment
,
2282 wine_dbgstr_rect(&rcClient
),
2283 wine_dbgstr_rect(title
),
2284 wine_dbgstr_rect(wdays
),
2285 wine_dbgstr_rect(days
),
2286 wine_dbgstr_rect(todayrect
));
2288 /* restore the originally selected font */
2289 SelectObject(hdc
, currentFont
);
2291 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2294 static LRESULT
MONTHCAL_Size(MONTHCAL_INFO
*infoPtr
, int Width
, int Height
)
2296 TRACE("(width=%d, height=%d)\n", Width
, Height
);
2298 MONTHCAL_UpdateSize(infoPtr
);
2300 /* invalidate client area and erase background */
2301 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
2306 static LRESULT
MONTHCAL_GetFont(const MONTHCAL_INFO
*infoPtr
)
2308 return (LRESULT
)infoPtr
->hFont
;
2311 static LRESULT
MONTHCAL_SetFont(MONTHCAL_INFO
*infoPtr
, HFONT hFont
, BOOL redraw
)
2316 if (!hFont
) return 0;
2318 hOldFont
= infoPtr
->hFont
;
2319 infoPtr
->hFont
= hFont
;
2321 GetObjectW(infoPtr
->hFont
, sizeof(lf
), &lf
);
2322 lf
.lfWeight
= FW_BOLD
;
2323 infoPtr
->hBoldFont
= CreateFontIndirectW(&lf
);
2325 MONTHCAL_UpdateSize(infoPtr
);
2328 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
2330 return (LRESULT
)hOldFont
;
2333 /* update theme after a WM_THEMECHANGED message */
2334 static LRESULT
theme_changed (const MONTHCAL_INFO
* infoPtr
)
2336 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
2337 CloseThemeData (theme
);
2338 OpenThemeData (infoPtr
->hwndSelf
, themeClass
);
2342 static INT
MONTHCAL_StyleChanged(MONTHCAL_INFO
*infoPtr
, WPARAM wStyleType
,
2343 const STYLESTRUCT
*lpss
)
2345 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
2346 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
2348 if (wStyleType
!= GWL_STYLE
) return 0;
2350 infoPtr
->dwStyle
= lpss
->styleNew
;
2352 /* make room for week numbers */
2353 if ((lpss
->styleNew
^ lpss
->styleOld
) & MCS_WEEKNUMBERS
)
2354 MONTHCAL_UpdateSize(infoPtr
);
2359 static INT
MONTHCAL_StyleChanging(MONTHCAL_INFO
*infoPtr
, WPARAM wStyleType
,
2362 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
2363 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
2365 /* block MCS_MULTISELECT change */
2366 if ((lpss
->styleNew
^ lpss
->styleOld
) & MCS_MULTISELECT
)
2368 if (lpss
->styleOld
& MCS_MULTISELECT
)
2369 lpss
->styleNew
|= MCS_MULTISELECT
;
2371 lpss
->styleNew
&= ~MCS_MULTISELECT
;
2377 /* FIXME: check whether dateMin/dateMax need to be adjusted. */
2379 MONTHCAL_Create(HWND hwnd
, LPCREATESTRUCTW lpcs
)
2381 MONTHCAL_INFO
*infoPtr
;
2383 /* allocate memory for info structure */
2384 infoPtr
= Alloc(sizeof(MONTHCAL_INFO
));
2385 SetWindowLongPtrW(hwnd
, 0, (DWORD_PTR
)infoPtr
);
2387 if(infoPtr
== NULL
) {
2388 ERR( "could not allocate info memory!\n");
2392 infoPtr
->hwndSelf
= hwnd
;
2393 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
2394 infoPtr
->dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
2396 MONTHCAL_SetFont(infoPtr
, GetStockObject(DEFAULT_GUI_FONT
), FALSE
);
2398 /* initialize info structure */
2399 /* FIXME: calculate systemtime ->> localtime(substract timezoneinfo) */
2401 GetLocalTime(&infoPtr
->todaysDate
);
2402 MONTHCAL_SetFirstDayOfWeek(infoPtr
, -1);
2404 infoPtr
->maxSelCount
= (infoPtr
->dwStyle
& MCS_MULTISELECT
) ? 7 : 1;
2405 infoPtr
->monthRange
= 3;
2406 infoPtr
->monthdayState
= Alloc(infoPtr
->monthRange
* sizeof(MONTHDAYSTATE
));
2407 infoPtr
->titlebk
= comctl32_color
.clrActiveCaption
;
2408 infoPtr
->titletxt
= comctl32_color
.clrWindow
;
2409 infoPtr
->monthbk
= comctl32_color
.clrWindow
;
2410 infoPtr
->trailingtxt
= comctl32_color
.clrGrayText
;
2411 infoPtr
->bk
= comctl32_color
.clrWindow
;
2412 infoPtr
->txt
= comctl32_color
.clrWindowText
;
2414 infoPtr
->minSel
= infoPtr
->todaysDate
;
2415 infoPtr
->maxSel
= infoPtr
->todaysDate
;
2416 infoPtr
->curSel
= infoPtr
->todaysDate
;
2417 infoPtr
->isUnicode
= TRUE
;
2419 /* call MONTHCAL_UpdateSize to set all of the dimensions */
2420 /* of the control */
2421 MONTHCAL_UpdateSize(infoPtr
);
2423 /* today auto update timer, to be freed only on control destruction */
2424 SetTimer(infoPtr
->hwndSelf
, MC_TODAYUPDATETIMER
, MC_TODAYUPDATEDELAY
, 0);
2426 OpenThemeData (infoPtr
->hwndSelf
, themeClass
);
2433 MONTHCAL_Destroy(MONTHCAL_INFO
*infoPtr
)
2435 /* free month calendar info data */
2436 Free(infoPtr
->monthdayState
);
2437 SetWindowLongPtrW(infoPtr
->hwndSelf
, 0, 0);
2439 CloseThemeData (GetWindowTheme (infoPtr
->hwndSelf
));
2446 * Handler for WM_NOTIFY messages
2449 MONTHCAL_Notify(MONTHCAL_INFO
*infoPtr
, NMHDR
*hdr
)
2451 /* notification from year edit updown */
2452 if (hdr
->code
== UDN_DELTAPOS
)
2454 NMUPDOWN
*nmud
= (NMUPDOWN
*)hdr
;
2456 if (hdr
->hwndFrom
== infoPtr
->hWndYearUpDown
)
2458 /* year value limits are set up explicitly after updown creation */
2459 if ((nmud
->iDelta
+ nmud
->iPos
) != infoPtr
->curSel
.wYear
)
2461 SYSTEMTIME new_date
= infoPtr
->curSel
;
2463 new_date
.wYear
= nmud
->iDelta
+ nmud
->iPos
;
2464 MONTHCAL_SetCurSel(infoPtr
, &new_date
);
2472 MONTHCAL_SetUnicodeFormat(MONTHCAL_INFO
*infoPtr
, BOOL isUnicode
)
2474 BOOL prev
= infoPtr
->isUnicode
;
2475 infoPtr
->isUnicode
= isUnicode
;
2480 MONTHCAL_GetUnicodeFormat(const MONTHCAL_INFO
*infoPtr
)
2482 return infoPtr
->isUnicode
;
2485 static LRESULT WINAPI
2486 MONTHCAL_WindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
2488 MONTHCAL_INFO
*infoPtr
;
2490 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n", hwnd
, uMsg
, wParam
, lParam
);
2492 infoPtr
= MONTHCAL_GetInfoPtr(hwnd
);
2493 if (!infoPtr
&& (uMsg
!= WM_CREATE
))
2494 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
2498 return MONTHCAL_GetCurSel(infoPtr
, (LPSYSTEMTIME
)lParam
);
2501 return MONTHCAL_SetCurSel(infoPtr
, (LPSYSTEMTIME
)lParam
);
2503 case MCM_GETMAXSELCOUNT
:
2504 return MONTHCAL_GetMaxSelCount(infoPtr
);
2506 case MCM_SETMAXSELCOUNT
:
2507 return MONTHCAL_SetMaxSelCount(infoPtr
, wParam
);
2509 case MCM_GETSELRANGE
:
2510 return MONTHCAL_GetSelRange(infoPtr
, (LPSYSTEMTIME
)lParam
);
2512 case MCM_SETSELRANGE
:
2513 return MONTHCAL_SetSelRange(infoPtr
, (LPSYSTEMTIME
)lParam
);
2515 case MCM_GETMONTHRANGE
:
2516 return MONTHCAL_GetMonthRange(infoPtr
, wParam
, (SYSTEMTIME
*)lParam
);
2518 case MCM_SETDAYSTATE
:
2519 return MONTHCAL_SetDayState(infoPtr
, (INT
)wParam
, (LPMONTHDAYSTATE
)lParam
);
2521 case MCM_GETMINREQRECT
:
2522 return MONTHCAL_GetMinReqRect(infoPtr
, (LPRECT
)lParam
);
2525 return MONTHCAL_GetColor(infoPtr
, wParam
);
2528 return MONTHCAL_SetColor(infoPtr
, wParam
, (COLORREF
)lParam
);
2531 return MONTHCAL_GetToday(infoPtr
, (LPSYSTEMTIME
)lParam
);
2534 return MONTHCAL_SetToday(infoPtr
, (LPSYSTEMTIME
)lParam
);
2537 return MONTHCAL_HitTest(infoPtr
, (PMCHITTESTINFO
)lParam
);
2539 case MCM_GETFIRSTDAYOFWEEK
:
2540 return MONTHCAL_GetFirstDayOfWeek(infoPtr
);
2542 case MCM_SETFIRSTDAYOFWEEK
:
2543 return MONTHCAL_SetFirstDayOfWeek(infoPtr
, (INT
)lParam
);
2546 return MONTHCAL_GetRange(infoPtr
, (LPSYSTEMTIME
)lParam
);
2549 return MONTHCAL_SetRange(infoPtr
, (SHORT
)wParam
, (LPSYSTEMTIME
)lParam
);
2551 case MCM_GETMONTHDELTA
:
2552 return MONTHCAL_GetMonthDelta(infoPtr
);
2554 case MCM_SETMONTHDELTA
:
2555 return MONTHCAL_SetMonthDelta(infoPtr
, wParam
);
2557 case MCM_GETMAXTODAYWIDTH
:
2558 return MONTHCAL_GetMaxTodayWidth(infoPtr
);
2560 case MCM_SETUNICODEFORMAT
:
2561 return MONTHCAL_SetUnicodeFormat(infoPtr
, (BOOL
)wParam
);
2563 case MCM_GETUNICODEFORMAT
:
2564 return MONTHCAL_GetUnicodeFormat(infoPtr
);
2567 return DLGC_WANTARROWS
| DLGC_WANTCHARS
;
2570 return MONTHCAL_RButtonUp(infoPtr
, lParam
);
2572 case WM_LBUTTONDOWN
:
2573 return MONTHCAL_LButtonDown(infoPtr
, lParam
);
2576 return MONTHCAL_MouseMove(infoPtr
, lParam
);
2579 return MONTHCAL_LButtonUp(infoPtr
, lParam
);
2582 return MONTHCAL_Paint(infoPtr
, (HDC
)wParam
);
2584 case WM_PRINTCLIENT
:
2585 return MONTHCAL_PrintClient(infoPtr
, (HDC
)wParam
, (DWORD
)lParam
);
2588 return MONTHCAL_EraseBkgnd(infoPtr
, (HDC
)wParam
);
2591 return MONTHCAL_SetFocus(infoPtr
);
2594 return MONTHCAL_Size(infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
2597 return MONTHCAL_Notify(infoPtr
, (NMHDR
*)lParam
);
2600 return MONTHCAL_Create(hwnd
, (LPCREATESTRUCTW
)lParam
);
2603 return MONTHCAL_SetFont(infoPtr
, (HFONT
)wParam
, (BOOL
)lParam
);
2606 return MONTHCAL_GetFont(infoPtr
);
2609 return MONTHCAL_Timer(infoPtr
, wParam
);
2611 case WM_THEMECHANGED
:
2612 return theme_changed (infoPtr
);
2615 return MONTHCAL_Destroy(infoPtr
);
2617 case WM_SYSCOLORCHANGE
:
2618 COMCTL32_RefreshSysColors();
2621 case WM_STYLECHANGED
:
2622 return MONTHCAL_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
2624 case WM_STYLECHANGING
:
2625 return MONTHCAL_StyleChanging(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
2628 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
2629 ERR( "unknown msg %04x wp=%08lx lp=%08lx\n", uMsg
, wParam
, lParam
);
2630 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
2636 MONTHCAL_Register(void)
2640 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
2641 wndClass
.style
= CS_GLOBALCLASS
;
2642 wndClass
.lpfnWndProc
= MONTHCAL_WindowProc
;
2643 wndClass
.cbClsExtra
= 0;
2644 wndClass
.cbWndExtra
= sizeof(MONTHCAL_INFO
*);
2645 wndClass
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
2646 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
2647 wndClass
.lpszClassName
= MONTHCAL_CLASSW
;
2649 RegisterClassW(&wndClass
);
2654 MONTHCAL_Unregister(void)
2656 UnregisterClassW(MONTHCAL_CLASSW
, NULL
);