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 time is valid */
164 static BOOL
MONTHCAL_ValidateTime(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
))
175 /* Note:Depending on DST, this may be offset by a day.
176 Need to find out if we're on a DST place & adjust the clock accordingly.
177 Above function assumes we have a valid data.
178 Valid for year>1752; 1 <= d <= 31, 1 <= m <= 12.
182 /* returns the day in the week(0 == sunday, 6 == saturday) */
183 /* day(1 == 1st, 2 == 2nd... etc), year is the year value */
184 static int MONTHCAL_CalculateDayOfWeek(DWORD day
, DWORD month
, DWORD year
)
188 return((year
+ year
/4 - year
/100 + year
/400 +
189 DayOfWeekTable
[month
-1] + day
) % 7);
192 /* From a given point, calculate the row (weekpos), column(daypos)
193 and day in the calendar. day== 0 mean the last day of tha last month
195 static int MONTHCAL_CalcDayFromPos(const MONTHCAL_INFO
*infoPtr
, int x
, int y
,
196 int *daypos
,int *weekpos
)
198 int retval
, firstDay
;
201 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
203 /* if the point is outside the x bounds of the window put
204 it at the boundary */
205 if (x
> rcClient
.right
)
209 *daypos
= (x
- infoPtr
->days
.left
) / infoPtr
->width_increment
;
210 *weekpos
= (y
- infoPtr
->days
.top
) / infoPtr
->height_increment
;
212 firstDay
= (MONTHCAL_CalculateDayOfWeek(1, infoPtr
->curSel
.wMonth
, infoPtr
->curSel
.wYear
)+6 - infoPtr
->firstDay
)%7;
213 retval
= *daypos
+ (7 * *weekpos
) - firstDay
;
217 /* day is the day of the month, 1 == 1st day of the month */
218 /* sets x and y to be the position of the day */
219 /* x == day, y == week where(0,0) == firstDay, 1st week */
220 static void MONTHCAL_CalcDayXY(const MONTHCAL_INFO
*infoPtr
, int day
, int month
,
223 int firstDay
, prevMonth
;
225 firstDay
= (MONTHCAL_CalculateDayOfWeek(1, infoPtr
->curSel
.wMonth
, infoPtr
->curSel
.wYear
) +6 - infoPtr
->firstDay
)%7;
227 if(month
==infoPtr
->curSel
.wMonth
) {
228 *x
= (day
+ firstDay
) % 7;
229 *y
= (day
+ firstDay
- *x
) / 7;
232 if(month
< infoPtr
->curSel
.wMonth
) {
233 prevMonth
= month
- 1;
237 *x
= (MONTHCAL_MonthLength(prevMonth
, infoPtr
->curSel
.wYear
) - firstDay
) % 7;
242 *y
= MONTHCAL_MonthLength(month
, infoPtr
->curSel
.wYear
- 1) / 7;
243 *x
= (day
+ firstDay
+ MONTHCAL_MonthLength(month
,
244 infoPtr
->curSel
.wYear
)) % 7;
248 /* x: column(day), y: row(week) */
249 static void MONTHCAL_CalcDayRect(const MONTHCAL_INFO
*infoPtr
, RECT
*r
, int x
, int y
)
251 r
->left
= infoPtr
->days
.left
+ x
* infoPtr
->width_increment
;
252 r
->right
= r
->left
+ infoPtr
->width_increment
;
253 r
->top
= infoPtr
->days
.top
+ y
* infoPtr
->height_increment
;
254 r
->bottom
= r
->top
+ infoPtr
->textHeight
;
258 /* sets the RECT struct r to the rectangle around the day and month */
259 /* day is the day value of the month(1 == 1st), month is the month */
260 /* value(january == 1, december == 12) */
261 static inline void MONTHCAL_CalcPosFromDay(const MONTHCAL_INFO
*infoPtr
,
262 int day
, int month
, RECT
*r
)
266 MONTHCAL_CalcDayXY(infoPtr
, day
, month
, &x
, &y
);
267 MONTHCAL_CalcDayRect(infoPtr
, r
, x
, y
);
271 /* day is the day in the month(1 == 1st of the month) */
272 /* month is the month value(1 == january, 12 == december) */
273 static void MONTHCAL_CircleDay(const MONTHCAL_INFO
*infoPtr
, HDC hdc
, int day
, int month
)
275 HPEN hRedPen
= CreatePen(PS_SOLID
, 1, RGB(255, 0, 0));
276 HPEN hOldPen2
= SelectObject(hdc
, hRedPen
);
280 MONTHCAL_CalcPosFromDay(infoPtr
, day
, month
, &day_rect
);
282 hOldBrush
= SelectObject(hdc
, GetStockObject(NULL_BRUSH
));
283 Rectangle(hdc
, day_rect
.left
, day_rect
.top
, day_rect
.right
, day_rect
.bottom
);
285 SelectObject(hdc
, hOldBrush
);
286 DeleteObject(hRedPen
);
287 SelectObject(hdc
, hOldPen2
);
290 static void MONTHCAL_DrawDay(const MONTHCAL_INFO
*infoPtr
, HDC hdc
, int day
, int month
,
291 int x
, int y
, int bold
)
293 static const WCHAR fmtW
[] = { '%','d',0 };
296 static BOOL haveBoldFont
, haveSelectedDay
= FALSE
;
301 wsprintfW(buf
, fmtW
, day
);
303 /* No need to check styles: when selection is not valid, it is set to zero.
304 * 1<day<31, so everything is OK.
307 MONTHCAL_CalcDayRect(infoPtr
, &r
, x
, y
);
309 if((day
>=infoPtr
->minSel
.wDay
) && (day
<=infoPtr
->maxSel
.wDay
)
310 && (month
== infoPtr
->curSel
.wMonth
)) {
313 TRACE("%d %d %d\n",day
, infoPtr
->minSel
.wDay
, infoPtr
->maxSel
.wDay
);
314 TRACE("%s\n", wine_dbgstr_rect(&r
));
315 oldCol
= SetTextColor(hdc
, infoPtr
->monthbk
);
316 oldBk
= SetBkColor(hdc
, infoPtr
->trailingtxt
);
317 hbr
= GetSysColorBrush(COLOR_HIGHLIGHT
);
318 FillRect(hdc
, &r
, hbr
);
320 /* FIXME: this may need to be changed now b/c of the other
321 drawing changes 11/3/99 CMM */
322 r2
.left
= r
.left
- 0.25 * infoPtr
->textWidth
;
324 r2
.right
= r
.left
+ 0.5 * infoPtr
->textWidth
;
325 r2
.bottom
= r
.bottom
;
326 if(haveSelectedDay
) FillRect(hdc
, &r2
, hbr
);
327 haveSelectedDay
= TRUE
;
329 haveSelectedDay
= FALSE
;
332 /* need to add some code for multiple selections */
334 if((bold
) &&(!haveBoldFont
)) {
335 SelectObject(hdc
, infoPtr
->hBoldFont
);
338 if((!bold
) &&(haveBoldFont
)) {
339 SelectObject(hdc
, infoPtr
->hFont
);
340 haveBoldFont
= FALSE
;
343 SetBkMode(hdc
,TRANSPARENT
);
344 DrawTextW(hdc
, buf
, -1, &r
, DT_CENTER
| DT_VCENTER
| DT_SINGLELINE
);
346 if(haveSelectedDay
) {
347 SetTextColor(hdc
, oldCol
);
348 SetBkColor(hdc
, oldBk
);
351 /* draw a rectangle around the currently selected days text */
352 if((day
== infoPtr
->curSel
.wDay
) && (month
== infoPtr
->curSel
.wMonth
))
353 DrawFocusRect(hdc
, &r
);
357 static void paint_button (const MONTHCAL_INFO
*infoPtr
, HDC hdc
, BOOL btnNext
,
358 BOOL pressed
, RECT
* r
)
360 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
364 static const int states
[] = {
366 ABS_LEFTNORMAL
, ABS_LEFTPRESSED
, ABS_LEFTDISABLED
,
368 ABS_RIGHTNORMAL
, ABS_RIGHTPRESSED
, ABS_RIGHTDISABLED
370 int stateNum
= btnNext
? 3 : 0;
375 if (infoPtr
->dwStyle
& WS_DISABLED
) stateNum
+= 2;
377 DrawThemeBackground (theme
, hdc
, SBP_ARROWBTN
, states
[stateNum
], r
, NULL
);
381 int style
= btnNext
? DFCS_SCROLLRIGHT
: DFCS_SCROLLLEFT
;
383 style
|= DFCS_PUSHED
;
386 if (infoPtr
->dwStyle
& WS_DISABLED
) style
|= DFCS_INACTIVE
;
389 DrawFrameControl(hdc
, r
, DFC_SCROLL
, style
);
394 static void MONTHCAL_Refresh(MONTHCAL_INFO
*infoPtr
, HDC hdc
, const PAINTSTRUCT
*ps
)
396 static const WCHAR todayW
[] = { 'T','o','d','a','y',':',0 };
397 static const WCHAR fmt1W
[] = { '%','s',' ','%','l','d',0 };
398 static const WCHAR fmt2W
[] = { '%','s',' ','%','s',0 };
399 static const WCHAR fmt3W
[] = { '%','d',0 };
400 RECT
*title
=&infoPtr
->title
;
401 RECT
*prev
=&infoPtr
->titlebtnprev
;
402 RECT
*next
=&infoPtr
->titlebtnnext
;
403 RECT
*titlemonth
=&infoPtr
->titlemonth
;
404 RECT
*titleyear
=&infoPtr
->titleyear
;
408 int i
, j
, m
, mask
, day
, firstDay
, weeknum
, weeknum1
,prevMonth
;
409 int textHeight
= infoPtr
->textHeight
;
416 COLORREF oldTextColor
, oldBkColor
;
418 RECT rcDay
; /* used in MONTHCAL_CalcDayRect() */
419 SYSTEMTIME localtime
;
422 oldTextColor
= SetTextColor(hdc
, comctl32_color
.clrWindowText
);
424 /* fill background */
425 hbr
= CreateSolidBrush (infoPtr
->bk
);
426 FillRect(hdc
, &ps
->rcPaint
, hbr
);
430 if(IntersectRect(&rcTemp
, &(ps
->rcPaint
), title
))
432 hbr
= CreateSolidBrush(infoPtr
->titlebk
);
433 FillRect(hdc
, title
, hbr
);
437 /* if the previous button is pressed draw it depressed */
438 if(IntersectRect(&rcTemp
, &(ps
->rcPaint
), prev
))
439 paint_button (infoPtr
, hdc
, FALSE
, infoPtr
->status
& MC_PREVPRESSED
, prev
);
441 /* if next button is depressed draw it depressed */
442 if(IntersectRect(&rcTemp
, &(ps
->rcPaint
), next
))
443 paint_button (infoPtr
, hdc
, TRUE
, infoPtr
->status
& MC_NEXTPRESSED
, next
);
445 oldBkColor
= SetBkColor(hdc
, infoPtr
->titlebk
);
446 SetTextColor(hdc
, infoPtr
->titletxt
);
447 currentFont
= SelectObject(hdc
, infoPtr
->hBoldFont
);
449 GetLocaleInfoW( LOCALE_USER_DEFAULT
,LOCALE_SMONTHNAME1
+infoPtr
->curSel
.wMonth
-1,
451 wsprintfW(buf
, fmt1W
, buf1
, infoPtr
->curSel
.wYear
);
453 if(IntersectRect(&rcTemp
, &(ps
->rcPaint
), title
))
455 DrawTextW(hdc
, buf
, strlenW(buf
), title
,
456 DT_CENTER
| DT_VCENTER
| DT_SINGLELINE
);
459 /* titlemonth left/right contained rect for whole titletxt('June 1999')
460 * MCM_HitTestInfo wants month & year rects, so prepare these now.
461 *(no, we can't draw them separately; the whole text is centered)
463 GetTextExtentPoint32W(hdc
, buf
, strlenW(buf
), &size
);
464 titlemonth
->left
= title
->right
/ 2 + title
->left
/ 2 - size
.cx
/ 2;
465 titleyear
->right
= title
->right
/ 2 + title
->left
/ 2 + size
.cx
/ 2;
466 GetTextExtentPoint32W(hdc
, buf1
, strlenW(buf1
), &size
);
467 titlemonth
->right
= titlemonth
->left
+ size
.cx
;
468 titleyear
->left
= titlemonth
->right
;
470 /* draw month area */
471 rcTemp
.top
=infoPtr
->wdays
.top
;
472 rcTemp
.left
=infoPtr
->wdays
.left
;
473 rcTemp
.bottom
=infoPtr
->todayrect
.bottom
;
474 rcTemp
.right
=infoPtr
->todayrect
.right
;
475 if(IntersectRect(&rcTemp
, &(ps
->rcPaint
), &rcTemp
))
477 hbr
= CreateSolidBrush(infoPtr
->monthbk
);
478 FillRect(hdc
, &rcTemp
, hbr
);
482 /* draw line under day abbreviations */
484 MoveToEx(hdc
, infoPtr
->days
.left
+ 3, title
->bottom
+ textHeight
+ 1, NULL
);
485 LineTo(hdc
, infoPtr
->days
.right
- 3, title
->bottom
+ textHeight
+ 1);
487 prevMonth
= infoPtr
->curSel
.wMonth
- 1;
488 if(prevMonth
== 0) /* if curSel.wMonth is january(1) prevMonth is */
489 prevMonth
= 12; /* december(12) of the previous year */
491 infoPtr
->wdays
.left
= infoPtr
->days
.left
= infoPtr
->weeknums
.right
;
492 /* draw day abbreviations */
494 SelectObject(hdc
, infoPtr
->hFont
);
495 SetBkColor(hdc
, infoPtr
->monthbk
);
496 SetTextColor(hdc
, infoPtr
->trailingtxt
);
498 /* copy this rect so we can change the values without changing */
499 /* the original version */
500 days
->left
= infoPtr
->wdays
.left
;
501 days
->right
= days
->left
+ infoPtr
->width_increment
;
502 days
->top
= infoPtr
->wdays
.top
;
503 days
->bottom
= infoPtr
->wdays
.bottom
;
505 i
= infoPtr
->firstDay
;
508 GetLocaleInfoW( LOCALE_USER_DEFAULT
,LOCALE_SABBREVDAYNAME1
+ (i
+j
+6)%7, buf
, countof(buf
));
509 DrawTextW(hdc
, buf
, strlenW(buf
), days
, DT_CENTER
| DT_VCENTER
| DT_SINGLELINE
);
510 days
->left
+=infoPtr
->width_increment
;
511 days
->right
+=infoPtr
->width_increment
;
514 /* draw day numbers; first, the previous month */
516 firstDay
= MONTHCAL_CalculateDayOfWeek(1, infoPtr
->curSel
.wMonth
, infoPtr
->curSel
.wYear
);
518 day
= MONTHCAL_MonthLength(prevMonth
, infoPtr
->curSel
.wYear
) +
519 (infoPtr
->firstDay
+ 7 - firstDay
)%7 + 1;
520 if (day
> MONTHCAL_MonthLength(prevMonth
, infoPtr
->curSel
.wYear
))
522 startofprescal
= day
;
527 while(day
<= MONTHCAL_MonthLength(prevMonth
, infoPtr
->curSel
.wYear
)) {
528 MONTHCAL_CalcDayRect(infoPtr
, &rcDay
, i
, 0);
529 if(IntersectRect(&rcTemp
, &(ps
->rcPaint
), &rcDay
))
531 MONTHCAL_DrawDay(infoPtr
, hdc
, day
, prevMonth
, i
, 0,
532 infoPtr
->monthdayState
[m
] & mask
);
540 /* draw `current' month */
542 day
= 1; /* start at the beginning of the current month */
544 infoPtr
->firstDayplace
= i
;
545 SetTextColor(hdc
, infoPtr
->txt
);
549 /* draw the first week of the current month */
551 MONTHCAL_CalcDayRect(infoPtr
, &rcDay
, i
, 0);
552 if(IntersectRect(&rcTemp
, &(ps
->rcPaint
), &rcDay
))
555 MONTHCAL_DrawDay(infoPtr
, hdc
, day
, infoPtr
->curSel
.wMonth
, i
, 0,
556 infoPtr
->monthdayState
[m
] & mask
);
558 if((infoPtr
->curSel
.wMonth
== infoPtr
->todaysDate
.wMonth
) &&
559 (day
==infoPtr
->todaysDate
.wDay
) &&
560 (infoPtr
->curSel
.wYear
== infoPtr
->todaysDate
.wYear
)) {
561 if(!(infoPtr
->dwStyle
& MCS_NOTODAYCIRCLE
))
562 MONTHCAL_CircleDay(infoPtr
, hdc
, day
, infoPtr
->curSel
.wMonth
);
571 j
= 1; /* move to the 2nd week of the current month */
572 i
= 0; /* move back to sunday */
573 while(day
<= MONTHCAL_MonthLength(infoPtr
->curSel
.wMonth
, infoPtr
->curSel
.wYear
)) {
574 MONTHCAL_CalcDayRect(infoPtr
, &rcDay
, i
, j
);
575 if(IntersectRect(&rcTemp
, &(ps
->rcPaint
), &rcDay
))
577 MONTHCAL_DrawDay(infoPtr
, hdc
, day
, infoPtr
->curSel
.wMonth
, i
, j
,
578 infoPtr
->monthdayState
[m
] & mask
);
580 if((infoPtr
->curSel
.wMonth
== infoPtr
->todaysDate
.wMonth
) &&
581 (day
==infoPtr
->todaysDate
.wDay
) &&
582 (infoPtr
->curSel
.wYear
== infoPtr
->todaysDate
.wYear
))
583 if(!(infoPtr
->dwStyle
& MCS_NOTODAYCIRCLE
))
584 MONTHCAL_CircleDay(infoPtr
, hdc
, day
, infoPtr
->curSel
.wMonth
);
589 if(i
>6) { /* past saturday, goto the next weeks sunday */
595 /* draw `next' month */
597 day
= 1; /* start at the first day of the next month */
601 SetTextColor(hdc
, infoPtr
->trailingtxt
);
602 while((i
<7) &&(j
<6)) {
603 MONTHCAL_CalcDayRect(infoPtr
, &rcDay
, i
, j
);
604 if(IntersectRect(&rcTemp
, &(ps
->rcPaint
), &rcDay
))
606 MONTHCAL_DrawDay(infoPtr
, hdc
, day
, infoPtr
->curSel
.wMonth
+ 1, i
, j
,
607 infoPtr
->monthdayState
[m
] & mask
);
613 if(i
==7) { /* past saturday, go to next week's sunday */
618 SetTextColor(hdc
, infoPtr
->txt
);
621 /* draw `today' date if style allows it, and draw a circle before today's
622 * date if necessary */
624 if(!(infoPtr
->dwStyle
& MCS_NOTODAY
)) {
625 if(!(infoPtr
->dwStyle
& MCS_NOTODAYCIRCLE
)) {
626 /*day is the number of days from nextmonth we put on the calendar */
627 MONTHCAL_CircleDay(infoPtr
, hdc
,
628 day
+MONTHCAL_MonthLength(infoPtr
->curSel
.wMonth
, infoPtr
->curSel
.wYear
),
629 infoPtr
->curSel
.wMonth
);
631 if (!LoadStringW(COMCTL32_hModule
,IDM_TODAY
,buf1
,countof(buf1
)))
633 WARN("Can't load resource\n");
634 strcpyW(buf1
, todayW
);
636 MONTHCAL_CalcDayRect(infoPtr
, &rtoday
, 1, 6);
637 localtime
= infoPtr
->todaysDate
;
638 GetDateFormatW(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
,&localtime
,NULL
,buf2
,countof(buf2
));
639 wsprintfW(buf
, fmt2W
, buf1
, buf2
);
640 SelectObject(hdc
, infoPtr
->hBoldFont
);
642 DrawTextW(hdc
, buf
, -1, &rtoday
, DT_CALCRECT
| DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
);
643 if(IntersectRect(&rcTemp
, &(ps
->rcPaint
), &rtoday
))
645 DrawTextW(hdc
, buf
, -1, &rtoday
, DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
);
647 SelectObject(hdc
, infoPtr
->hFont
);
650 /*eventually draw week numbers*/
651 if(infoPtr
->dwStyle
& MCS_WEEKNUMBERS
) {
652 /* display weeknumbers*/
655 /* Rules what week to call the first week of a new year:
656 LOCALE_IFIRSTWEEKOFYEAR == 0 (e.g US?):
657 The week containing Jan 1 is the first week of year
658 LOCALE_IFIRSTWEEKOFYEAR == 2 (e.g. Germany):
659 First week of year must contain 4 days of the new year
660 LOCALE_IFIRSTWEEKOFYEAR == 1 (what contries?)
661 The first week of the year must contain only days of the new year
663 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_IFIRSTWEEKOFYEAR
, buf
, countof(buf
));
664 weeknum
= atoiW(buf
);
675 if (infoPtr
->curSel
.wMonth
< 2)
677 /* calculate all those exceptions for january */
678 weeknum1
=MONTHCAL_CalculateDayOfWeek(1, 1, infoPtr
->curSel
.wYear
);
679 if ((infoPtr
->firstDay
+7 - weeknum1
)%7 > mindays
)
685 weeknum
+=MONTHCAL_MonthLength(i
+1, infoPtr
->curSel
.wYear
- 1);
686 weeknum
+=startofprescal
+ 7;
688 weeknum1
=MONTHCAL_CalculateDayOfWeek(1, 1, infoPtr
->curSel
.wYear
- 1);
689 if ((infoPtr
->firstDay
+ 7 - weeknum1
)%7 > mindays
)
696 for(i
=0; i
<prevMonth
-1; i
++)
697 weeknum
+=MONTHCAL_MonthLength(i
+1, infoPtr
->curSel
.wYear
);
698 weeknum
+=startofprescal
+ 7;
700 weeknum1
=MONTHCAL_CalculateDayOfWeek(1,1,infoPtr
->curSel
.wYear
);
701 if ((infoPtr
->firstDay
+ 7 - weeknum1
)%7 > mindays
)
704 days
->left
= infoPtr
->weeknums
.left
;
705 days
->right
= infoPtr
->weeknums
.right
;
706 days
->top
= infoPtr
->weeknums
.top
;
707 days
->bottom
= days
->top
+infoPtr
->height_increment
;
709 if((i
==0)&&(weeknum
>50))
711 wsprintfW(buf
, fmt3W
, weeknum
);
714 else if((i
==5)&&(weeknum
>47))
716 wsprintfW(buf
, fmt3W
, 1);
719 wsprintfW(buf
, fmt3W
, weeknum
+ i
);
720 DrawTextW(hdc
, buf
, -1, days
, DT_CENTER
| DT_VCENTER
| DT_SINGLELINE
);
721 days
->top
+=infoPtr
->height_increment
;
722 days
->bottom
+=infoPtr
->height_increment
;
725 MoveToEx(hdc
, infoPtr
->weeknums
.right
, infoPtr
->weeknums
.top
+ 3 , NULL
);
726 LineTo(hdc
, infoPtr
->weeknums
.right
, infoPtr
->weeknums
.bottom
);
729 /* currentFont was font at entering Refresh */
731 SetBkColor(hdc
, oldBkColor
);
732 SelectObject(hdc
, currentFont
);
733 SetTextColor(hdc
, oldTextColor
);
738 MONTHCAL_GetMinReqRect(const MONTHCAL_INFO
*infoPtr
, LPRECT lpRect
)
740 TRACE("rect %p\n", lpRect
);
742 if(!lpRect
) return FALSE
;
744 lpRect
->left
= infoPtr
->title
.left
;
745 lpRect
->top
= infoPtr
->title
.top
;
746 lpRect
->right
= infoPtr
->title
.right
;
747 lpRect
->bottom
= infoPtr
->todayrect
.bottom
;
748 AdjustWindowRect(lpRect
, infoPtr
->dwStyle
, FALSE
);
750 TRACE("%s\n", wine_dbgstr_rect(lpRect
));
757 MONTHCAL_GetColor(const MONTHCAL_INFO
*infoPtr
, INT index
)
762 case MCSC_BACKGROUND
:
767 return infoPtr
->titlebk
;
769 return infoPtr
->titletxt
;
771 return infoPtr
->monthbk
;
772 case MCSC_TRAILINGTEXT
:
773 return infoPtr
->trailingtxt
;
781 MONTHCAL_SetColor(MONTHCAL_INFO
*infoPtr
, INT index
, COLORREF color
)
785 TRACE("%d: color %08x\n", index
, color
);
788 case MCSC_BACKGROUND
:
794 infoPtr
->txt
= color
;
797 prev
= infoPtr
->titlebk
;
798 infoPtr
->titlebk
= color
;
801 prev
=infoPtr
->titletxt
;
802 infoPtr
->titletxt
= color
;
805 prev
= infoPtr
->monthbk
;
806 infoPtr
->monthbk
= color
;
808 case MCSC_TRAILINGTEXT
:
809 prev
= infoPtr
->trailingtxt
;
810 infoPtr
->trailingtxt
= color
;
814 InvalidateRect(infoPtr
->hwndSelf
, NULL
, index
== MCSC_BACKGROUND
? TRUE
: FALSE
);
820 MONTHCAL_GetMonthDelta(const MONTHCAL_INFO
*infoPtr
)
825 return infoPtr
->delta
;
827 return infoPtr
->visible
;
832 MONTHCAL_SetMonthDelta(MONTHCAL_INFO
*infoPtr
, INT delta
)
834 INT prev
= infoPtr
->delta
;
836 TRACE("delta %d\n", delta
);
838 infoPtr
->delta
= delta
;
844 MONTHCAL_GetFirstDayOfWeek(const MONTHCAL_INFO
*infoPtr
)
846 return MAKELONG(infoPtr
->firstDay
, infoPtr
->firstDayHighWord
);
850 /* sets the first day of the week that will appear in the control */
851 /* 0 == Sunday, 6 == Saturday */
852 /* FIXME: this needs to be implemented properly in MONTHCAL_Refresh() */
853 /* FIXME: we need more error checking here */
855 MONTHCAL_SetFirstDayOfWeek(MONTHCAL_INFO
*infoPtr
, INT day
)
857 int prev
= MAKELONG(infoPtr
->firstDay
, infoPtr
->firstDayHighWord
);
861 TRACE("day %d\n", day
);
863 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_IFIRSTDAYOFWEEK
, buf
, countof(buf
));
864 TRACE("%s %d\n", debugstr_w(buf
), strlenW(buf
));
866 localFirstDay
= atoiW(buf
);
870 infoPtr
->firstDay
= localFirstDay
;
871 infoPtr
->firstDayHighWord
= FALSE
;
875 infoPtr
->firstDay
= 6; /* max first day allowed */
876 infoPtr
->firstDayHighWord
= TRUE
;
880 infoPtr
->firstDay
= day
;
881 infoPtr
->firstDayHighWord
= TRUE
;
889 MONTHCAL_GetMonthRange(const MONTHCAL_INFO
*infoPtr
)
893 return infoPtr
->monthRange
;
898 MONTHCAL_GetMaxTodayWidth(const MONTHCAL_INFO
*infoPtr
)
900 return(infoPtr
->todayrect
.right
- infoPtr
->todayrect
.left
);
905 MONTHCAL_SetRange(MONTHCAL_INFO
*infoPtr
, SHORT limits
, SYSTEMTIME
*range
)
907 FILETIME ft_min
, ft_max
;
909 TRACE("%x %p\n", limits
, range
);
911 if ((limits
& GDTR_MIN
&& !MONTHCAL_ValidateTime(range
[0])) ||
912 (limits
& GDTR_MAX
&& !MONTHCAL_ValidateTime(range
[1])))
915 if (limits
& GDTR_MIN
)
917 infoPtr
->minDate
= range
[0];
918 infoPtr
->rangeValid
|= GDTR_MIN
;
920 if (limits
& GDTR_MAX
)
922 infoPtr
->maxDate
= range
[1];
923 infoPtr
->rangeValid
|= GDTR_MAX
;
926 /* Only one limit set - we are done */
927 if ((infoPtr
->rangeValid
& (GDTR_MIN
| GDTR_MAX
)) != (GDTR_MIN
| GDTR_MAX
))
930 SystemTimeToFileTime(&infoPtr
->maxDate
, &ft_max
);
931 SystemTimeToFileTime(&infoPtr
->minDate
, &ft_min
);
933 if (CompareFileTime(&ft_min
, &ft_max
) >= 0)
935 if ((limits
& (GDTR_MIN
| GDTR_MAX
)) == (GDTR_MIN
| GDTR_MAX
))
937 /* Native swaps limits only when both limits are being set. */
938 SYSTEMTIME st_tmp
= infoPtr
->minDate
;
939 infoPtr
->minDate
= infoPtr
->maxDate
;
940 infoPtr
->maxDate
= st_tmp
;
944 static const SYSTEMTIME zero
;
946 /* reset the other limit */
947 if (limits
& GDTR_MIN
) infoPtr
->maxDate
= zero
;
948 if (limits
& GDTR_MAX
) infoPtr
->minDate
= zero
;
949 infoPtr
->rangeValid
&= limits
& GDTR_MIN
? ~GDTR_MAX
: ~GDTR_MIN
;
958 MONTHCAL_GetRange(const MONTHCAL_INFO
*infoPtr
, SYSTEMTIME
*range
)
960 TRACE("%p\n", range
);
962 if(!range
) return FALSE
;
964 range
[1] = infoPtr
->maxDate
;
965 range
[0] = infoPtr
->minDate
;
967 return infoPtr
->rangeValid
;
972 MONTHCAL_SetDayState(const MONTHCAL_INFO
*infoPtr
, INT months
, MONTHDAYSTATE
*states
)
976 TRACE("%d %p\n", months
, states
);
977 if(months
!= infoPtr
->monthRange
) return 0;
979 for(i
= 0; i
< months
; i
++)
980 infoPtr
->monthdayState
[i
] = states
[i
];
986 MONTHCAL_GetCurSel(const MONTHCAL_INFO
*infoPtr
, SYSTEMTIME
*curSel
)
988 TRACE("%p\n", curSel
);
989 if(!curSel
) return FALSE
;
990 if(infoPtr
->dwStyle
& MCS_MULTISELECT
) return FALSE
;
992 *curSel
= infoPtr
->minSel
;
993 TRACE("%d/%d/%d\n", curSel
->wYear
, curSel
->wMonth
, curSel
->wDay
);
997 /* FIXME: if the specified date is not visible, make it visible */
1000 MONTHCAL_SetCurSel(MONTHCAL_INFO
*infoPtr
, SYSTEMTIME
*curSel
)
1002 TRACE("%p\n", curSel
);
1003 if(!curSel
) return FALSE
;
1004 if(infoPtr
->dwStyle
& MCS_MULTISELECT
) return FALSE
;
1006 if(!MONTHCAL_ValidateTime(*curSel
)) return FALSE
;
1008 infoPtr
->minSel
= *curSel
;
1009 infoPtr
->maxSel
= *curSel
;
1011 /* exit earlier if selection equals current */
1012 if (MONTHCAL_IsDateEqual(&infoPtr
->curSel
, curSel
)) return TRUE
;
1014 infoPtr
->curSel
= *curSel
;
1016 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1023 MONTHCAL_GetMaxSelCount(const MONTHCAL_INFO
*infoPtr
)
1025 return infoPtr
->maxSelCount
;
1030 MONTHCAL_SetMaxSelCount(MONTHCAL_INFO
*infoPtr
, INT max
)
1034 if(infoPtr
->dwStyle
& MCS_MULTISELECT
) {
1035 infoPtr
->maxSelCount
= max
;
1043 MONTHCAL_GetSelRange(const MONTHCAL_INFO
*infoPtr
, SYSTEMTIME
*range
)
1045 TRACE("%p\n", range
);
1047 if(!range
) return FALSE
;
1049 if(infoPtr
->dwStyle
& MCS_MULTISELECT
)
1051 range
[1] = infoPtr
->maxSel
;
1052 range
[0] = infoPtr
->minSel
;
1053 TRACE("[min,max]=[%d %d]\n", infoPtr
->minSel
.wDay
, infoPtr
->maxSel
.wDay
);
1062 MONTHCAL_SetSelRange(MONTHCAL_INFO
*infoPtr
, SYSTEMTIME
*range
)
1064 TRACE("%p\n", range
);
1066 if(!range
) return FALSE
;
1068 if(infoPtr
->dwStyle
& MCS_MULTISELECT
)
1070 infoPtr
->maxSel
= range
[1];
1071 infoPtr
->minSel
= range
[0];
1072 TRACE("[min,max]=[%d %d]\n", infoPtr
->minSel
.wDay
, infoPtr
->maxSel
.wDay
);
1081 MONTHCAL_GetToday(const MONTHCAL_INFO
*infoPtr
, SYSTEMTIME
*today
)
1083 TRACE("%p\n", today
);
1085 if(!today
) return FALSE
;
1086 *today
= infoPtr
->todaysDate
;
1092 MONTHCAL_SetToday(MONTHCAL_INFO
*infoPtr
, SYSTEMTIME
*today
)
1094 TRACE("%p\n", today
);
1096 if(!today
) return FALSE
;
1098 if(MONTHCAL_IsDateEqual(today
, &infoPtr
->todaysDate
)) return TRUE
;
1100 infoPtr
->todaysDate
= *today
;
1101 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1107 MONTHCAL_HitTest(const MONTHCAL_INFO
*infoPtr
, MCHITTESTINFO
*lpht
)
1117 ZeroMemory(&lpht
->st
, sizeof(lpht
->st
));
1119 /* Comment in for debugging...
1120 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,
1121 infoPtr->wdays.left, infoPtr->wdays.right,
1122 infoPtr->wdays.top, infoPtr->wdays.bottom,
1123 infoPtr->days.left, infoPtr->days.right,
1124 infoPtr->days.top, infoPtr->days.bottom,
1125 infoPtr->todayrect.left, infoPtr->todayrect.right,
1126 infoPtr->todayrect.top, infoPtr->todayrect.bottom,
1127 infoPtr->weeknums.left, infoPtr->weeknums.right,
1128 infoPtr->weeknums.top, infoPtr->weeknums.bottom);
1131 /* are we in the header? */
1133 if(PtInRect(&infoPtr
->title
, lpht
->pt
)) {
1134 if(PtInRect(&infoPtr
->titlebtnprev
, lpht
->pt
)) {
1135 retval
= MCHT_TITLEBTNPREV
;
1138 if(PtInRect(&infoPtr
->titlebtnnext
, lpht
->pt
)) {
1139 retval
= MCHT_TITLEBTNNEXT
;
1142 if(PtInRect(&infoPtr
->titlemonth
, lpht
->pt
)) {
1143 retval
= MCHT_TITLEMONTH
;
1146 if(PtInRect(&infoPtr
->titleyear
, lpht
->pt
)) {
1147 retval
= MCHT_TITLEYEAR
;
1151 retval
= MCHT_TITLE
;
1155 day
= MONTHCAL_CalcDayFromPos(infoPtr
,x
,y
,&wday
,&wnum
);
1156 if(PtInRect(&infoPtr
->wdays
, lpht
->pt
)) {
1157 retval
= MCHT_CALENDARDAY
;
1158 lpht
->st
.wYear
= infoPtr
->curSel
.wYear
;
1159 lpht
->st
.wMonth
= (day
< 1)? infoPtr
->curSel
.wMonth
-1 : infoPtr
->curSel
.wMonth
;
1160 lpht
->st
.wDay
= (day
< 1)?
1161 MONTHCAL_MonthLength(infoPtr
->curSel
.wMonth
-1, infoPtr
->curSel
.wYear
) -day
: day
;
1164 if(PtInRect(&infoPtr
->weeknums
, lpht
->pt
)) {
1165 retval
= MCHT_CALENDARWEEKNUM
;
1166 lpht
->st
.wYear
= infoPtr
->curSel
.wYear
;
1167 lpht
->st
.wMonth
= (day
< 1) ? infoPtr
->curSel
.wMonth
-1 :
1168 (day
> MONTHCAL_MonthLength(infoPtr
->curSel
.wMonth
,infoPtr
->curSel
.wYear
)) ?
1169 infoPtr
->curSel
.wMonth
+1 :infoPtr
->curSel
.wMonth
;
1170 lpht
->st
.wDay
= (day
< 1 ) ?
1171 MONTHCAL_MonthLength(infoPtr
->curSel
.wMonth
-1,infoPtr
->curSel
.wYear
) -day
:
1172 (day
> MONTHCAL_MonthLength(infoPtr
->curSel
.wMonth
,infoPtr
->curSel
.wYear
)) ?
1173 day
- MONTHCAL_MonthLength(infoPtr
->curSel
.wMonth
,infoPtr
->curSel
.wYear
) : day
;
1176 if(PtInRect(&infoPtr
->days
, lpht
->pt
))
1178 lpht
->st
.wYear
= infoPtr
->curSel
.wYear
;
1181 retval
= MCHT_CALENDARDATEPREV
;
1182 lpht
->st
.wMonth
= infoPtr
->curSel
.wMonth
- 1;
1183 if (lpht
->st
.wMonth
<1)
1185 lpht
->st
.wMonth
= 12;
1188 lpht
->st
.wDay
= MONTHCAL_MonthLength(lpht
->st
.wMonth
,lpht
->st
.wYear
) -day
;
1190 else if (day
> MONTHCAL_MonthLength(infoPtr
->curSel
.wMonth
,infoPtr
->curSel
.wYear
))
1192 retval
= MCHT_CALENDARDATENEXT
;
1193 lpht
->st
.wMonth
= infoPtr
->curSel
.wMonth
+ 1;
1194 if (lpht
->st
.wMonth
<12)
1196 lpht
->st
.wMonth
= 1;
1199 lpht
->st
.wDay
= day
- MONTHCAL_MonthLength(infoPtr
->curSel
.wMonth
,infoPtr
->curSel
.wYear
) ;
1202 retval
= MCHT_CALENDARDATE
;
1203 lpht
->st
.wMonth
= infoPtr
->curSel
.wMonth
;
1204 lpht
->st
.wDay
= day
;
1205 lpht
->st
.wDayOfWeek
= MONTHCAL_CalculateDayOfWeek(day
,lpht
->st
.wMonth
,lpht
->st
.wYear
);
1209 if(PtInRect(&infoPtr
->todayrect
, lpht
->pt
)) {
1210 retval
= MCHT_TODAYLINK
;
1215 /* Hit nothing special? What's left must be background :-) */
1217 retval
= MCHT_CALENDARBK
;
1219 lpht
->uHit
= retval
;
1224 static void MONTHCAL_GoToNextMonth(MONTHCAL_INFO
*infoPtr
)
1226 TRACE("MONTHCAL_GoToNextMonth\n");
1228 infoPtr
->curSel
.wMonth
++;
1229 if(infoPtr
->curSel
.wMonth
> 12) {
1230 infoPtr
->curSel
.wYear
++;
1231 infoPtr
->curSel
.wMonth
= 1;
1234 if(infoPtr
->dwStyle
& MCS_DAYSTATE
) {
1238 nmds
.nmhdr
.hwndFrom
= infoPtr
->hwndSelf
;
1239 nmds
.nmhdr
.idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1240 nmds
.nmhdr
.code
= MCN_GETDAYSTATE
;
1241 nmds
.cDayState
= infoPtr
->monthRange
;
1242 nmds
.prgDayState
= Alloc(infoPtr
->monthRange
* sizeof(MONTHDAYSTATE
));
1244 nmds
.stStart
= infoPtr
->todaysDate
;
1245 nmds
.stStart
.wYear
= infoPtr
->curSel
.wYear
;
1246 nmds
.stStart
.wMonth
= infoPtr
->curSel
.wMonth
;
1247 nmds
.stStart
.wDay
= 1;
1249 SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, nmds
.nmhdr
.idFrom
, (LPARAM
)&nmds
);
1250 for(i
=0; i
<infoPtr
->monthRange
; i
++)
1251 infoPtr
->monthdayState
[i
] = nmds
.prgDayState
[i
];
1256 static void MONTHCAL_GoToPrevMonth(MONTHCAL_INFO
*infoPtr
)
1260 infoPtr
->curSel
.wMonth
--;
1261 if(infoPtr
->curSel
.wMonth
< 1) {
1262 infoPtr
->curSel
.wYear
--;
1263 infoPtr
->curSel
.wMonth
= 12;
1266 if(infoPtr
->dwStyle
& MCS_DAYSTATE
) {
1270 nmds
.nmhdr
.hwndFrom
= infoPtr
->hwndSelf
;
1271 nmds
.nmhdr
.idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1272 nmds
.nmhdr
.code
= MCN_GETDAYSTATE
;
1273 nmds
.cDayState
= infoPtr
->monthRange
;
1274 nmds
.prgDayState
= Alloc
1275 (infoPtr
->monthRange
* sizeof(MONTHDAYSTATE
));
1277 nmds
.stStart
= infoPtr
->todaysDate
;
1278 nmds
.stStart
.wYear
= infoPtr
->curSel
.wYear
;
1279 nmds
.stStart
.wMonth
= infoPtr
->curSel
.wMonth
;
1280 nmds
.stStart
.wDay
= 1;
1282 SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, nmds
.nmhdr
.idFrom
, (LPARAM
)&nmds
);
1283 for(i
=0; i
<infoPtr
->monthRange
; i
++)
1284 infoPtr
->monthdayState
[i
] = nmds
.prgDayState
[i
];
1289 MONTHCAL_RButtonDown(MONTHCAL_INFO
*infoPtr
, LPARAM lParam
)
1291 static const WCHAR todayW
[] = { 'G','o',' ','t','o',' ','T','o','d','a','y',':',0 };
1296 hMenu
= CreatePopupMenu();
1297 if (!LoadStringW(COMCTL32_hModule
, IDM_GOTODAY
, buf
, countof(buf
)))
1299 WARN("Can't load resource\n");
1300 strcpyW(buf
, todayW
);
1302 AppendMenuW(hMenu
, MF_STRING
|MF_ENABLED
, 1, buf
);
1303 menupoint
.x
= (short)LOWORD(lParam
);
1304 menupoint
.y
= (short)HIWORD(lParam
);
1305 ClientToScreen(infoPtr
->hwndSelf
, &menupoint
);
1306 if( TrackPopupMenu(hMenu
, TPM_RIGHTBUTTON
| TPM_NONOTIFY
| TPM_RETURNCMD
,
1307 menupoint
.x
, menupoint
.y
, 0, infoPtr
->hwndSelf
, NULL
))
1309 infoPtr
->curSel
= infoPtr
->todaysDate
;
1310 infoPtr
->minSel
= infoPtr
->todaysDate
;
1311 infoPtr
->maxSel
= infoPtr
->todaysDate
;
1312 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1318 /* creates updown control and edit box */
1319 static void MONTHCAL_EditYear(MONTHCAL_INFO
*infoPtr
)
1321 static const WCHAR EditW
[] = { 'E','D','I','T',0 };
1323 infoPtr
->hWndYearEdit
=
1324 CreateWindowExW(0, EditW
, 0, WS_VISIBLE
| WS_CHILD
| ES_READONLY
,
1325 infoPtr
->titleyear
.left
+ 3, infoPtr
->titlebtnnext
.top
,
1326 infoPtr
->titleyear
.right
- infoPtr
->titleyear
.left
+ 4,
1327 infoPtr
->textHeight
, infoPtr
->hwndSelf
,
1330 SendMessageW(infoPtr
->hWndYearEdit
, WM_SETFONT
, (WPARAM
)infoPtr
->hBoldFont
, TRUE
);
1332 infoPtr
->hWndYearUpDown
=
1333 CreateWindowExW(0, UPDOWN_CLASSW
, 0,
1334 WS_VISIBLE
| WS_CHILD
| UDS_SETBUDDYINT
| UDS_NOTHOUSANDS
| UDS_ARROWKEYS
,
1335 infoPtr
->titleyear
.right
+ 7, infoPtr
->titlebtnnext
.top
,
1336 18, infoPtr
->textHeight
, infoPtr
->hwndSelf
,
1339 /* attach edit box */
1340 SendMessageW(infoPtr
->hWndYearUpDown
, UDM_SETRANGE
, 0, MAKELONG(9999, 1753));
1341 SendMessageW(infoPtr
->hWndYearUpDown
, UDM_SETBUDDY
, (WPARAM
)infoPtr
->hWndYearEdit
, 0);
1342 SendMessageW(infoPtr
->hWndYearUpDown
, UDM_SETPOS
, 0, infoPtr
->curSel
.wYear
);
1346 MONTHCAL_LButtonDown(MONTHCAL_INFO
*infoPtr
, LPARAM lParam
)
1351 if (infoPtr
->hWndYearUpDown
)
1353 infoPtr
->curSel
.wYear
= SendMessageW(infoPtr
->hWndYearUpDown
, UDM_SETPOS
, 0, 0);
1354 if(!DestroyWindow(infoPtr
->hWndYearUpDown
))
1356 FIXME("Can't destroy Updown Control\n");
1359 infoPtr
->hWndYearUpDown
= 0;
1361 if(!DestroyWindow(infoPtr
->hWndYearEdit
))
1363 FIXME("Can't destroy Updown Control\n");
1366 infoPtr
->hWndYearEdit
= 0;
1368 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1371 ht
.pt
.x
= (short)LOWORD(lParam
);
1372 ht
.pt
.y
= (short)HIWORD(lParam
);
1373 TRACE("(%d, %d)\n", ht
.pt
.x
, ht
.pt
.y
);
1375 hit
= MONTHCAL_HitTest(infoPtr
, &ht
);
1379 case MCHT_TITLEBTNNEXT
:
1380 MONTHCAL_GoToNextMonth(infoPtr
);
1381 infoPtr
->status
= MC_NEXTPRESSED
;
1382 SetTimer(infoPtr
->hwndSelf
, MC_NEXTMONTHTIMER
, MC_NEXTMONTHDELAY
, 0);
1383 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1386 case MCHT_TITLEBTNPREV
:
1387 MONTHCAL_GoToPrevMonth(infoPtr
);
1388 infoPtr
->status
= MC_PREVPRESSED
;
1389 SetTimer(infoPtr
->hwndSelf
, MC_PREVMONTHTIMER
, MC_NEXTMONTHDELAY
, 0);
1390 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1393 case MCHT_TITLEMONTH
:
1395 HMENU hMenu
= CreatePopupMenu();
1400 for (i
= 0; i
< 12; i
++)
1402 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SMONTHNAME1
+i
, buf
, countof(buf
));
1403 AppendMenuW(hMenu
, MF_STRING
|MF_ENABLED
, i
+ 1, buf
);
1405 menupoint
.x
= infoPtr
->titlemonth
.right
;
1406 menupoint
.y
= infoPtr
->titlemonth
.bottom
;
1407 ClientToScreen(infoPtr
->hwndSelf
, &menupoint
);
1408 i
= TrackPopupMenu(hMenu
,TPM_LEFTALIGN
| TPM_NONOTIFY
| TPM_RIGHTBUTTON
| TPM_RETURNCMD
,
1409 menupoint
.x
, menupoint
.y
, 0, infoPtr
->hwndSelf
, NULL
);
1411 if ((i
> 0) && (i
< 13))
1413 infoPtr
->curSel
.wMonth
= i
;
1414 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1417 case MCHT_TITLEYEAR
:
1419 MONTHCAL_EditYear(infoPtr
);
1422 case MCHT_TODAYLINK
:
1426 infoPtr
->firstSelDay
= infoPtr
->todaysDate
.wDay
;
1427 infoPtr
->curSel
= infoPtr
->todaysDate
;
1428 infoPtr
->minSel
= infoPtr
->todaysDate
;
1429 infoPtr
->maxSel
= infoPtr
->todaysDate
;
1430 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1432 nmsc
.nmhdr
.hwndFrom
= infoPtr
->hwndSelf
;
1433 nmsc
.nmhdr
.idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1434 nmsc
.nmhdr
.code
= MCN_SELCHANGE
;
1435 nmsc
.stSelStart
= infoPtr
->minSel
;
1436 nmsc
.stSelEnd
= infoPtr
->maxSel
;
1437 SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, nmsc
.nmhdr
.idFrom
, (LPARAM
)&nmsc
);
1439 nmsc
.nmhdr
.code
= MCN_SELECT
;
1440 SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, nmsc
.nmhdr
.idFrom
, (LPARAM
)&nmsc
);
1443 case MCHT_CALENDARDATE
:
1445 RECT rcDay
; /* used in determining area to invalidate */
1446 SYSTEMTIME selArray
[2];
1449 selArray
[0] = ht
.st
;
1450 selArray
[1] = ht
.st
;
1451 MONTHCAL_SetSelRange(infoPtr
, selArray
);
1452 MONTHCAL_SetCurSel(infoPtr
, &selArray
[0]);
1453 TRACE("MCHT_CALENDARDATE\n");
1454 nmsc
.nmhdr
.hwndFrom
= infoPtr
->hwndSelf
;
1455 nmsc
.nmhdr
.idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1456 nmsc
.nmhdr
.code
= MCN_SELCHANGE
;
1457 nmsc
.stSelStart
= infoPtr
->minSel
;
1458 nmsc
.stSelEnd
= infoPtr
->maxSel
;
1460 SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, nmsc
.nmhdr
.idFrom
, (LPARAM
)&nmsc
);
1462 /* redraw both old and new days if the selected day changed */
1463 if(infoPtr
->curSel
.wDay
!= ht
.st
.wDay
) {
1464 MONTHCAL_CalcPosFromDay(infoPtr
, ht
.st
.wDay
, ht
.st
.wMonth
, &rcDay
);
1465 InvalidateRect(infoPtr
->hwndSelf
, &rcDay
, TRUE
);
1467 MONTHCAL_CalcPosFromDay(infoPtr
, infoPtr
->curSel
.wDay
, infoPtr
->curSel
.wMonth
, &rcDay
);
1468 InvalidateRect(infoPtr
->hwndSelf
, &rcDay
, TRUE
);
1471 infoPtr
->firstSelDay
= ht
.st
.wDay
;
1472 infoPtr
->curSel
.wDay
= ht
.st
.wDay
;
1473 infoPtr
->status
= MC_SEL_LBUTDOWN
;
1483 MONTHCAL_LButtonUp(MONTHCAL_INFO
*infoPtr
, LPARAM lParam
)
1487 BOOL redraw
= FALSE
;
1493 if(infoPtr
->status
& MC_NEXTPRESSED
) {
1494 KillTimer(infoPtr
->hwndSelf
, MC_NEXTMONTHTIMER
);
1495 infoPtr
->status
&= ~MC_NEXTPRESSED
;
1498 if(infoPtr
->status
& MC_PREVPRESSED
) {
1499 KillTimer(infoPtr
->hwndSelf
, MC_PREVMONTHTIMER
);
1500 infoPtr
->status
&= ~MC_PREVPRESSED
;
1504 ht
.pt
.x
= (short)LOWORD(lParam
);
1505 ht
.pt
.y
= (short)HIWORD(lParam
);
1506 hit
= MONTHCAL_HitTest(infoPtr
, &ht
);
1508 infoPtr
->status
= MC_SEL_LBUTUP
;
1510 if(hit
==MCHT_CALENDARDATENEXT
) {
1511 MONTHCAL_GoToNextMonth(infoPtr
);
1512 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1515 if(hit
== MCHT_CALENDARDATEPREV
){
1516 MONTHCAL_GoToPrevMonth(infoPtr
);
1517 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1520 nmhdr
.hwndFrom
= infoPtr
->hwndSelf
;
1521 nmhdr
.idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1522 nmhdr
.code
= NM_RELEASEDCAPTURE
;
1523 TRACE("Sent notification from %p to %p\n", infoPtr
->hwndSelf
, infoPtr
->hwndNotify
);
1525 SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, nmhdr
.idFrom
, (LPARAM
)&nmhdr
);
1526 /* redraw if necessary */
1528 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1529 /* only send MCN_SELECT if currently displayed month's day was selected */
1530 if(hit
== MCHT_CALENDARDATE
) {
1531 nmsc
.nmhdr
.hwndFrom
= infoPtr
->hwndSelf
;
1532 nmsc
.nmhdr
.idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1533 nmsc
.nmhdr
.code
= MCN_SELECT
;
1534 nmsc
.stSelStart
= infoPtr
->minSel
;
1535 nmsc
.stSelEnd
= infoPtr
->maxSel
;
1537 SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, nmsc
.nmhdr
.idFrom
, (LPARAM
)&nmsc
);
1545 MONTHCAL_Timer(MONTHCAL_INFO
*infoPtr
, WPARAM wParam
)
1547 BOOL redraw
= FALSE
;
1549 TRACE("%ld\n", wParam
);
1552 case MC_NEXTMONTHTIMER
:
1554 MONTHCAL_GoToNextMonth(infoPtr
);
1556 case MC_PREVMONTHTIMER
:
1558 MONTHCAL_GoToPrevMonth(infoPtr
);
1561 ERR("got unknown timer\n");
1565 /* redraw only if necessary */
1567 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1574 MONTHCAL_MouseMove(MONTHCAL_INFO
*infoPtr
, LPARAM lParam
)
1577 int oldselday
, selday
, hit
;
1580 if(!(infoPtr
->status
& MC_SEL_LBUTDOWN
)) return 0;
1582 ht
.pt
.x
= (short)LOWORD(lParam
);
1583 ht
.pt
.y
= (short)HIWORD(lParam
);
1585 hit
= MONTHCAL_HitTest(infoPtr
, &ht
);
1587 /* not on the calendar date numbers? bail out */
1588 TRACE("hit:%x\n",hit
);
1589 if((hit
& MCHT_CALENDARDATE
) != MCHT_CALENDARDATE
) return 0;
1591 selday
= ht
.st
.wDay
;
1592 oldselday
= infoPtr
->curSel
.wDay
;
1593 infoPtr
->curSel
.wDay
= selday
;
1594 MONTHCAL_CalcPosFromDay(infoPtr
, selday
, ht
.st
. wMonth
, &r
);
1596 if(infoPtr
->dwStyle
& MCS_MULTISELECT
) {
1597 SYSTEMTIME selArray
[2];
1600 MONTHCAL_GetSelRange(infoPtr
, selArray
);
1602 if(infoPtr
->firstSelDay
==selArray
[0].wDay
) i
=1;
1603 TRACE("oldRange:%d %d %d %d\n", infoPtr
->firstSelDay
, selArray
[0].wDay
, selArray
[1].wDay
, i
);
1604 if(infoPtr
->firstSelDay
==selArray
[1].wDay
) {
1605 /* 1st time we get here: selArray[0]=selArray[1]) */
1606 /* if we're still at the first selected date, return */
1607 if(infoPtr
->firstSelDay
==selday
) goto done
;
1608 if(selday
<infoPtr
->firstSelDay
) i
= 0;
1611 if(abs(infoPtr
->firstSelDay
- selday
) >= infoPtr
->maxSelCount
) {
1612 if(selday
>infoPtr
->firstSelDay
)
1613 selday
= infoPtr
->firstSelDay
+ infoPtr
->maxSelCount
;
1615 selday
= infoPtr
->firstSelDay
- infoPtr
->maxSelCount
;
1618 if(selArray
[i
].wDay
!=selday
) {
1619 TRACE("newRange:%d %d %d %d\n", infoPtr
->firstSelDay
, selArray
[0].wDay
, selArray
[1].wDay
, i
);
1621 selArray
[i
].wDay
= selday
;
1623 if(selArray
[0].wDay
>selArray
[1].wDay
) {
1625 tempday
= selArray
[1].wDay
;
1626 selArray
[1].wDay
= selArray
[0].wDay
;
1627 selArray
[0].wDay
= tempday
;
1630 MONTHCAL_SetSelRange(infoPtr
, selArray
);
1636 /* only redraw if the currently selected day changed */
1637 /* FIXME: this should specify a rectangle containing only the days that changed */
1638 /* using InvalidateRect */
1639 if(oldselday
!= infoPtr
->curSel
.wDay
)
1640 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1647 MONTHCAL_Paint(MONTHCAL_INFO
*infoPtr
, HDC hdc_paint
)
1654 GetClientRect(infoPtr
->hwndSelf
, &ps
.rcPaint
);
1658 hdc
= BeginPaint(infoPtr
->hwndSelf
, &ps
);
1660 MONTHCAL_Refresh(infoPtr
, hdc
, &ps
);
1661 if (!hdc_paint
) EndPaint(infoPtr
->hwndSelf
, &ps
);
1667 MONTHCAL_KillFocus(const MONTHCAL_INFO
*infoPtr
, HWND hFocusWnd
)
1671 if (infoPtr
->hwndNotify
!= hFocusWnd
)
1672 ShowWindow(infoPtr
->hwndSelf
, SW_HIDE
);
1674 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1681 MONTHCAL_SetFocus(const MONTHCAL_INFO
*infoPtr
)
1685 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1690 /* sets the size information */
1691 static void MONTHCAL_UpdateSize(MONTHCAL_INFO
*infoPtr
)
1693 static const WCHAR SunW
[] = { 'S','u','n',0 };
1694 static const WCHAR O0W
[] = { '0','0',0 };
1695 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
1696 RECT
*title
=&infoPtr
->title
;
1697 RECT
*prev
=&infoPtr
->titlebtnprev
;
1698 RECT
*next
=&infoPtr
->titlebtnnext
;
1699 RECT
*titlemonth
=&infoPtr
->titlemonth
;
1700 RECT
*titleyear
=&infoPtr
->titleyear
;
1701 RECT
*wdays
=&infoPtr
->wdays
;
1702 RECT
*weeknumrect
=&infoPtr
->weeknums
;
1703 RECT
*days
=&infoPtr
->days
;
1704 RECT
*todayrect
=&infoPtr
->todayrect
;
1708 int xdiv
, left_offset
;
1711 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
1713 currentFont
= SelectObject(hdc
, infoPtr
->hFont
);
1715 /* get the height and width of each day's text */
1716 GetTextMetricsW(hdc
, &tm
);
1717 infoPtr
->textHeight
= tm
.tmHeight
+ tm
.tmExternalLeading
+ tm
.tmInternalLeading
;
1718 GetTextExtentPoint32W(hdc
, SunW
, 3, &size
);
1719 infoPtr
->textWidth
= size
.cx
+ 2;
1721 /* recalculate the height and width increments and offsets */
1722 GetTextExtentPoint32W(hdc
, O0W
, 2, &size
);
1724 xdiv
= (infoPtr
->dwStyle
& MCS_WEEKNUMBERS
) ? 8 : 7;
1726 infoPtr
->width_increment
= size
.cx
* 2 + 4;
1727 infoPtr
->height_increment
= infoPtr
->textHeight
;
1728 left_offset
= (rcClient
.right
- rcClient
.left
) - (infoPtr
->width_increment
* xdiv
);
1730 /* calculate title area */
1731 title
->top
= rcClient
.top
;
1732 title
->bottom
= title
->top
+ 3 * infoPtr
->height_increment
/ 2;
1733 title
->left
= left_offset
;
1734 title
->right
= rcClient
.right
;
1736 /* set the dimensions of the next and previous buttons and center */
1737 /* the month text vertically */
1738 prev
->top
= next
->top
= title
->top
+ 4;
1739 prev
->bottom
= next
->bottom
= title
->bottom
- 4;
1740 prev
->left
= title
->left
+ 4;
1741 prev
->right
= prev
->left
+ (title
->bottom
- title
->top
) ;
1742 next
->right
= title
->right
- 4;
1743 next
->left
= next
->right
- (title
->bottom
- title
->top
);
1745 /* titlemonth->left and right change based upon the current month */
1746 /* and are recalculated in refresh as the current month may change */
1747 /* without the control being resized */
1748 titlemonth
->top
= titleyear
->top
= title
->top
+ (infoPtr
->height_increment
)/2;
1749 titlemonth
->bottom
= titleyear
->bottom
= title
->bottom
- (infoPtr
->height_increment
)/2;
1751 /* setup the dimensions of the rectangle we draw the names of the */
1752 /* days of the week in */
1753 weeknumrect
->left
= left_offset
;
1754 if(infoPtr
->dwStyle
& MCS_WEEKNUMBERS
)
1755 weeknumrect
->right
=prev
->right
;
1757 weeknumrect
->right
=weeknumrect
->left
;
1758 wdays
->left
= days
->left
= weeknumrect
->right
;
1759 wdays
->right
= days
->right
= wdays
->left
+ 7 * infoPtr
->width_increment
;
1760 wdays
->top
= title
->bottom
;
1761 wdays
->bottom
= wdays
->top
+ infoPtr
->height_increment
;
1763 days
->top
= weeknumrect
->top
= wdays
->bottom
;
1764 days
->bottom
= weeknumrect
->bottom
= days
->top
+ 6 * infoPtr
->height_increment
;
1766 todayrect
->left
= rcClient
.left
;
1767 todayrect
->right
= rcClient
.right
;
1768 todayrect
->top
= days
->bottom
;
1769 todayrect
->bottom
= days
->bottom
+ infoPtr
->height_increment
;
1771 TRACE("dx=%d dy=%d client[%s] title[%s] wdays[%s] days[%s] today[%s]\n",
1772 infoPtr
->width_increment
,infoPtr
->height_increment
,
1773 wine_dbgstr_rect(&rcClient
),
1774 wine_dbgstr_rect(title
),
1775 wine_dbgstr_rect(wdays
),
1776 wine_dbgstr_rect(days
),
1777 wine_dbgstr_rect(todayrect
));
1779 /* restore the originally selected font */
1780 SelectObject(hdc
, currentFont
);
1782 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
1785 static LRESULT
MONTHCAL_Size(MONTHCAL_INFO
*infoPtr
, int Width
, int Height
)
1787 TRACE("(width=%d, height=%d)\n", Width
, Height
);
1789 MONTHCAL_UpdateSize(infoPtr
);
1791 /* invalidate client area and erase background */
1792 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1797 static LRESULT
MONTHCAL_GetFont(const MONTHCAL_INFO
*infoPtr
)
1799 return (LRESULT
)infoPtr
->hFont
;
1802 static LRESULT
MONTHCAL_SetFont(MONTHCAL_INFO
*infoPtr
, HFONT hFont
, BOOL redraw
)
1807 if (!hFont
) return 0;
1809 hOldFont
= infoPtr
->hFont
;
1810 infoPtr
->hFont
= hFont
;
1812 GetObjectW(infoPtr
->hFont
, sizeof(lf
), &lf
);
1813 lf
.lfWeight
= FW_BOLD
;
1814 infoPtr
->hBoldFont
= CreateFontIndirectW(&lf
);
1816 MONTHCAL_UpdateSize(infoPtr
);
1819 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1821 return (LRESULT
)hOldFont
;
1824 /* update theme after a WM_THEMECHANGED message */
1825 static LRESULT
theme_changed (const MONTHCAL_INFO
* infoPtr
)
1827 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
1828 CloseThemeData (theme
);
1829 OpenThemeData (infoPtr
->hwndSelf
, themeClass
);
1833 static INT
MONTHCAL_StyleChanged(MONTHCAL_INFO
*infoPtr
, WPARAM wStyleType
,
1834 const STYLESTRUCT
*lpss
)
1836 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
1837 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
1839 if (wStyleType
!= GWL_STYLE
) return 0;
1841 infoPtr
->dwStyle
= lpss
->styleNew
;
1846 /* FIXME: check whether dateMin/dateMax need to be adjusted. */
1848 MONTHCAL_Create(HWND hwnd
, LPCREATESTRUCTW lpcs
)
1850 MONTHCAL_INFO
*infoPtr
;
1852 /* allocate memory for info structure */
1853 infoPtr
= Alloc(sizeof(MONTHCAL_INFO
));
1854 SetWindowLongPtrW(hwnd
, 0, (DWORD_PTR
)infoPtr
);
1856 if(infoPtr
== NULL
) {
1857 ERR( "could not allocate info memory!\n");
1861 infoPtr
->hwndSelf
= hwnd
;
1862 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
1863 infoPtr
->dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
1865 MONTHCAL_SetFont(infoPtr
, GetStockObject(DEFAULT_GUI_FONT
), FALSE
);
1867 /* initialize info structure */
1868 /* FIXME: calculate systemtime ->> localtime(substract timezoneinfo) */
1870 GetLocalTime(&infoPtr
->todaysDate
);
1871 infoPtr
->firstDayHighWord
= FALSE
;
1872 MONTHCAL_SetFirstDayOfWeek(infoPtr
, -1);
1873 infoPtr
->curSel
.wMonth
= infoPtr
->todaysDate
.wMonth
;
1874 infoPtr
->curSel
.wYear
= infoPtr
->todaysDate
.wYear
;
1875 infoPtr
->maxSelCount
= 7;
1876 infoPtr
->monthRange
= 3;
1877 infoPtr
->monthdayState
= Alloc(infoPtr
->monthRange
* sizeof(MONTHDAYSTATE
));
1878 infoPtr
->titlebk
= comctl32_color
.clrActiveCaption
;
1879 infoPtr
->titletxt
= comctl32_color
.clrWindow
;
1880 infoPtr
->monthbk
= comctl32_color
.clrWindow
;
1881 infoPtr
->trailingtxt
= comctl32_color
.clrGrayText
;
1882 infoPtr
->bk
= comctl32_color
.clrWindow
;
1883 infoPtr
->txt
= comctl32_color
.clrWindowText
;
1885 infoPtr
->minSel
= infoPtr
->todaysDate
;
1886 infoPtr
->maxSel
= infoPtr
->todaysDate
;
1888 /* call MONTHCAL_UpdateSize to set all of the dimensions */
1889 /* of the control */
1890 MONTHCAL_UpdateSize(infoPtr
);
1892 OpenThemeData (infoPtr
->hwndSelf
, themeClass
);
1899 MONTHCAL_Destroy(MONTHCAL_INFO
*infoPtr
)
1901 /* free month calendar info data */
1902 Free(infoPtr
->monthdayState
);
1903 SetWindowLongPtrW(infoPtr
->hwndSelf
, 0, 0);
1905 CloseThemeData (GetWindowTheme (infoPtr
->hwndSelf
));
1912 static LRESULT WINAPI
1913 MONTHCAL_WindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1915 MONTHCAL_INFO
*infoPtr
;
1917 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n", hwnd
, uMsg
, wParam
, lParam
);
1919 infoPtr
= MONTHCAL_GetInfoPtr(hwnd
);
1920 if (!infoPtr
&& (uMsg
!= WM_CREATE
))
1921 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
1925 return MONTHCAL_GetCurSel(infoPtr
, (LPSYSTEMTIME
)lParam
);
1928 return MONTHCAL_SetCurSel(infoPtr
, (LPSYSTEMTIME
)lParam
);
1930 case MCM_GETMAXSELCOUNT
:
1931 return MONTHCAL_GetMaxSelCount(infoPtr
);
1933 case MCM_SETMAXSELCOUNT
:
1934 return MONTHCAL_SetMaxSelCount(infoPtr
, wParam
);
1936 case MCM_GETSELRANGE
:
1937 return MONTHCAL_GetSelRange(infoPtr
, (LPSYSTEMTIME
)lParam
);
1939 case MCM_SETSELRANGE
:
1940 return MONTHCAL_SetSelRange(infoPtr
, (LPSYSTEMTIME
)lParam
);
1942 case MCM_GETMONTHRANGE
:
1943 return MONTHCAL_GetMonthRange(infoPtr
);
1945 case MCM_SETDAYSTATE
:
1946 return MONTHCAL_SetDayState(infoPtr
, (INT
)wParam
, (LPMONTHDAYSTATE
)lParam
);
1948 case MCM_GETMINREQRECT
:
1949 return MONTHCAL_GetMinReqRect(infoPtr
, (LPRECT
)lParam
);
1952 return MONTHCAL_GetColor(infoPtr
, wParam
);
1955 return MONTHCAL_SetColor(infoPtr
, wParam
, (COLORREF
)lParam
);
1958 return MONTHCAL_GetToday(infoPtr
, (LPSYSTEMTIME
)lParam
);
1961 return MONTHCAL_SetToday(infoPtr
, (LPSYSTEMTIME
)lParam
);
1964 return MONTHCAL_HitTest(infoPtr
, (PMCHITTESTINFO
)lParam
);
1966 case MCM_GETFIRSTDAYOFWEEK
:
1967 return MONTHCAL_GetFirstDayOfWeek(infoPtr
);
1969 case MCM_SETFIRSTDAYOFWEEK
:
1970 return MONTHCAL_SetFirstDayOfWeek(infoPtr
, (INT
)lParam
);
1973 return MONTHCAL_GetRange(infoPtr
, (LPSYSTEMTIME
)lParam
);
1976 return MONTHCAL_SetRange(infoPtr
, (SHORT
)wParam
, (LPSYSTEMTIME
)lParam
);
1978 case MCM_GETMONTHDELTA
:
1979 return MONTHCAL_GetMonthDelta(infoPtr
);
1981 case MCM_SETMONTHDELTA
:
1982 return MONTHCAL_SetMonthDelta(infoPtr
, wParam
);
1984 case MCM_GETMAXTODAYWIDTH
:
1985 return MONTHCAL_GetMaxTodayWidth(infoPtr
);
1988 return DLGC_WANTARROWS
| DLGC_WANTCHARS
;
1991 return MONTHCAL_KillFocus(infoPtr
, (HWND
)wParam
);
1993 case WM_RBUTTONDOWN
:
1994 return MONTHCAL_RButtonDown(infoPtr
, lParam
);
1996 case WM_LBUTTONDOWN
:
1997 return MONTHCAL_LButtonDown(infoPtr
, lParam
);
2000 return MONTHCAL_MouseMove(infoPtr
, lParam
);
2003 return MONTHCAL_LButtonUp(infoPtr
, lParam
);
2005 case WM_PRINTCLIENT
:
2007 return MONTHCAL_Paint(infoPtr
, (HDC
)wParam
);
2010 return MONTHCAL_SetFocus(infoPtr
);
2013 return MONTHCAL_Size(infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
2016 return MONTHCAL_Create(hwnd
, (LPCREATESTRUCTW
)lParam
);
2019 return MONTHCAL_SetFont(infoPtr
, (HFONT
)wParam
, (BOOL
)lParam
);
2022 return MONTHCAL_GetFont(infoPtr
);
2025 return MONTHCAL_Timer(infoPtr
, wParam
);
2027 case WM_THEMECHANGED
:
2028 return theme_changed (infoPtr
);
2031 return MONTHCAL_Destroy(infoPtr
);
2033 case WM_SYSCOLORCHANGE
:
2034 COMCTL32_RefreshSysColors();
2037 case WM_STYLECHANGED
:
2038 return MONTHCAL_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
2041 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
2042 ERR( "unknown msg %04x wp=%08lx lp=%08lx\n", uMsg
, wParam
, lParam
);
2043 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
2049 MONTHCAL_Register(void)
2053 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
2054 wndClass
.style
= CS_GLOBALCLASS
;
2055 wndClass
.lpfnWndProc
= MONTHCAL_WindowProc
;
2056 wndClass
.cbClsExtra
= 0;
2057 wndClass
.cbWndExtra
= sizeof(MONTHCAL_INFO
*);
2058 wndClass
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
2059 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
2060 wndClass
.lpszClassName
= MONTHCAL_CLASSW
;
2062 RegisterClassW(&wndClass
);
2067 MONTHCAL_Unregister(void)
2069 UnregisterClassW(MONTHCAL_CLASSW
, NULL
);