2 * Date and time picker control
4 * Copyright 1998, 1999 Eric Kohl
5 * Copyright 1999, 2000 Alex Priem <alexp@sci.kun.nl>
6 * Copyright 2000 Chris Morgan <cmorgan@wpi.edu>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 * This code was audited for completeness against the documented features
25 * of Comctl32.dll version 6.0 on Oct. 20, 2004, by Dimitrie O. Paun.
27 * Unless otherwise noted, we believe this code to be complete, as per
28 * the specification mentioned above.
29 * If you discover missing features, or bugs, please note them below.
33 * -- DTS_SHORTDATECENTURYFORMAT
55 #include "wine/debug.h"
56 #include "wine/unicode.h"
58 WINE_DEFAULT_DEBUG_CHANNEL(datetime
);
70 RECT rcClient
; /* rect around the edge of the window */
71 RECT rcDraw
; /* rect inside of the border */
72 RECT checkbox
; /* checkbox allowing the control to be enabled/disabled */
73 RECT calbutton
; /* button that toggles the dropdown of the monthcal control */
74 BOOL bCalDepressed
; /* TRUE = cal button is depressed */
78 int nrFieldsAllocated
;
87 } DATETIME_INFO
, *LPDATETIME_INFO
;
90 extern int MONTHCAL_MonthLength(int month
, int year
);
91 extern int MONTHCAL_CalculateDayOfWeek(WORD day
, WORD month
, WORD year
);
93 /* this list of defines is closely related to `allowedformatchars' defined
94 * in datetime.c; the high nibble indicates the `base type' of the format
96 * Do not change without first reading DATETIME_UseFormat.
100 #define DT_END_FORMAT 0
101 #define ONEDIGITDAY 0x01
102 #define TWODIGITDAY 0x02
103 #define THREECHARDAY 0x03
105 #define ONEDIGIT12HOUR 0x11
106 #define TWODIGIT12HOUR 0x12
107 #define ONEDIGIT24HOUR 0x21
108 #define TWODIGIT24HOUR 0x22
109 #define ONEDIGITMINUTE 0x31
110 #define TWODIGITMINUTE 0x32
111 #define ONEDIGITMONTH 0x41
112 #define TWODIGITMONTH 0x42
113 #define THREECHARMONTH 0x43
114 #define FULLMONTH 0x44
115 #define ONEDIGITSECOND 0x51
116 #define TWODIGITSECOND 0x52
117 #define ONELETTERAMPM 0x61
118 #define TWOLETTERAMPM 0x62
119 #define ONEDIGITYEAR 0x71
120 #define TWODIGITYEAR 0x72
121 #define INVALIDFULLYEAR 0x73 /* FIXME - yyy is not valid - we'll treat it as yyyy */
122 #define FULLYEAR 0x74
123 #define FORMATCALLBACK 0x81 /* -> maximum of 0x80 callbacks possible */
124 #define FORMATCALLMASK 0x80
125 #define DT_STRING 0x0100
127 #define DTHT_DATEFIELD 0xff /* for hit-testing */
129 #define DTHT_NONE 0x1000
130 #define DTHT_CHECKBOX 0x2000 /* these should end at '00' , to make */
131 #define DTHT_MCPOPUP 0x3000 /* & DTHT_DATEFIELD 0 when DATETIME_KeyDown */
132 #define DTHT_GOTFOCUS 0x4000 /* tests for date-fields */
133 #define DTHT_NODATEMASK 0xf000 /* to mask check and drop down from others */
135 static BOOL
DATETIME_SendSimpleNotify (const DATETIME_INFO
*infoPtr
, UINT code
);
136 static BOOL
DATETIME_SendDateTimeChangeNotify (const DATETIME_INFO
*infoPtr
);
137 extern void MONTHCAL_CopyTime(const SYSTEMTIME
*from
, SYSTEMTIME
*to
);
138 static const WCHAR allowedformatchars
[] = {'d', 'h', 'H', 'm', 'M', 's', 't', 'y', 'X', 0};
139 static const int maxrepetition
[] = {4,2,2,2,4,2,2,4,-1};
143 DATETIME_GetSystemTime (const DATETIME_INFO
*infoPtr
, SYSTEMTIME
*systime
)
145 if (!systime
) return GDT_NONE
;
147 if ((infoPtr
->dwStyle
& DTS_SHOWNONE
) &&
148 (SendMessageW (infoPtr
->hwndCheckbut
, BM_GETCHECK
, 0, 0) == BST_UNCHECKED
))
151 *systime
= infoPtr
->date
;
158 DATETIME_SetSystemTime (DATETIME_INFO
*infoPtr
, DWORD flag
, const SYSTEMTIME
*systime
)
160 if (!systime
) return 0;
162 TRACE("%04d/%02d/%02d %02d:%02d:%02d\n",
163 systime
->wYear
, systime
->wMonth
, systime
->wDay
,
164 systime
->wHour
, systime
->wMinute
, systime
->wSecond
);
166 if (flag
== GDT_VALID
) {
167 if (systime
->wYear
< 1601 || systime
->wYear
> 30827 ||
168 systime
->wMonth
< 1 || systime
->wMonth
> 12 ||
169 systime
->wDay
< 1 || systime
->wDay
> 31 ||
170 systime
->wHour
> 23 ||
171 systime
->wMinute
> 59 ||
172 systime
->wSecond
> 59 ||
173 systime
->wMilliseconds
> 999
177 infoPtr
->dateValid
= TRUE
;
178 infoPtr
->date
= *systime
;
179 /* always store a valid day of week */
180 infoPtr
->date
.wDayOfWeek
=
181 MONTHCAL_CalculateDayOfWeek(infoPtr
->date
.wDay
, infoPtr
->date
.wMonth
,
182 infoPtr
->date
.wYear
);
184 SendMessageW (infoPtr
->hMonthCal
, MCM_SETCURSEL
, 0, (LPARAM
)(&infoPtr
->date
));
185 SendMessageW (infoPtr
->hwndCheckbut
, BM_SETCHECK
, BST_CHECKED
, 0);
186 } else if ((infoPtr
->dwStyle
& DTS_SHOWNONE
) && (flag
== GDT_NONE
)) {
187 infoPtr
->dateValid
= FALSE
;
188 SendMessageW (infoPtr
->hwndCheckbut
, BM_SETCHECK
, BST_UNCHECKED
, 0);
193 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
199 * Split up a formattxt in actions.
200 * See ms documentation for the meaning of the letter codes/'specifiers'.
203 * *'dddddd' is handled as 'dddd' plus 'dd'.
204 * *unrecognized formats are strings (here given the type DT_STRING;
205 * start of the string is encoded in lower bits of DT_STRING.
206 * Therefore, 'string' ends finally up as '<show seconds>tring'.
210 DATETIME_UseFormat (DATETIME_INFO
*infoPtr
, LPCWSTR formattxt
)
214 BOOL inside_literal
= FALSE
; /* inside '...' */
215 int *nrFields
= &infoPtr
->nrFields
;
218 infoPtr
->fieldspec
[*nrFields
] = 0;
219 len
= strlenW(allowedformatchars
);
222 for (i
= 0; formattxt
[i
]; i
++) {
223 TRACE ("\n%d %c:", i
, formattxt
[i
]);
224 if (!inside_literal
) {
225 for (j
= 0; j
< len
; j
++) {
226 if (allowedformatchars
[j
]==formattxt
[i
]) {
227 TRACE ("%c[%d,%x]", allowedformatchars
[j
], *nrFields
, infoPtr
->fieldspec
[*nrFields
]);
228 if ((*nrFields
==0) && (infoPtr
->fieldspec
[*nrFields
]==0)) {
229 infoPtr
->fieldspec
[*nrFields
] = (j
<<4) + 1;
232 if (infoPtr
->fieldspec
[*nrFields
] >> 4 != j
) {
234 infoPtr
->fieldspec
[*nrFields
] = (j
<<4) + 1;
237 if ((infoPtr
->fieldspec
[*nrFields
] & 0x0f) == maxrepetition
[j
]) {
239 infoPtr
->fieldspec
[*nrFields
] = (j
<<4) + 1;
242 infoPtr
->fieldspec
[*nrFields
]++;
244 } /* if allowedformatchar */
250 if (formattxt
[i
] == '\'')
252 inside_literal
= !inside_literal
;
256 /* char is not a specifier: handle char like a string */
258 if ((*nrFields
==0) && (infoPtr
->fieldspec
[*nrFields
]==0)) {
259 infoPtr
->fieldspec
[*nrFields
] = DT_STRING
+ k
;
260 infoPtr
->buflen
[*nrFields
] = 0;
261 } else if ((infoPtr
->fieldspec
[*nrFields
] & DT_STRING
) != DT_STRING
) {
263 infoPtr
->fieldspec
[*nrFields
] = DT_STRING
+ k
;
264 infoPtr
->buflen
[*nrFields
] = 0;
266 infoPtr
->textbuf
[k
] = formattxt
[i
];
268 infoPtr
->buflen
[*nrFields
]++;
271 if (*nrFields
== infoPtr
->nrFieldsAllocated
) {
272 FIXME ("out of memory; should reallocate. crash ahead.\n");
278 if (infoPtr
->fieldspec
[*nrFields
] != 0) (*nrFields
)++;
283 DATETIME_SetFormatW (DATETIME_INFO
*infoPtr
, LPCWSTR lpszFormat
)
286 WCHAR format_buf
[80];
289 if (infoPtr
->dwStyle
& DTS_LONGDATEFORMAT
)
290 format_item
= LOCALE_SLONGDATE
;
291 else if ((infoPtr
->dwStyle
& DTS_TIMEFORMAT
) == DTS_TIMEFORMAT
)
292 format_item
= LOCALE_STIMEFORMAT
;
293 else /* DTS_SHORTDATEFORMAT */
294 format_item
= LOCALE_SSHORTDATE
;
295 GetLocaleInfoW( GetSystemDefaultLCID(), format_item
, format_buf
, sizeof(format_buf
)/sizeof(format_buf
[0]));
296 lpszFormat
= format_buf
;
299 DATETIME_UseFormat (infoPtr
, lpszFormat
);
300 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
307 DATETIME_SetFormatA (DATETIME_INFO
*infoPtr
, LPCSTR lpszFormat
)
311 INT len
= MultiByteToWideChar(CP_ACP
, 0, lpszFormat
, -1, NULL
, 0);
312 LPWSTR wstr
= Alloc(len
* sizeof(WCHAR
));
313 if (wstr
) MultiByteToWideChar(CP_ACP
, 0, lpszFormat
, -1, wstr
, len
);
314 retval
= DATETIME_SetFormatW (infoPtr
, wstr
);
319 return DATETIME_SetFormatW (infoPtr
, 0);
325 DATETIME_ReturnTxt (const DATETIME_INFO
*infoPtr
, int count
, LPWSTR result
, int resultSize
)
327 static const WCHAR fmt_dW
[] = { '%', 'd', 0 };
328 static const WCHAR fmt__2dW
[] = { '%', '.', '2', 'd', 0 };
329 static const WCHAR fmt__3sW
[] = { '%', '.', '3', 's', 0 };
330 SYSTEMTIME date
= infoPtr
->date
;
335 TRACE ("%d,%d\n", infoPtr
->nrFields
, count
);
336 if (count
>infoPtr
->nrFields
|| count
< 0) {
337 WARN ("buffer overrun, have %d want %d\n", infoPtr
->nrFields
, count
);
341 if (!infoPtr
->fieldspec
) return;
343 spec
= infoPtr
->fieldspec
[count
];
344 if (spec
& DT_STRING
) {
345 int txtlen
= infoPtr
->buflen
[count
];
347 if (txtlen
> resultSize
)
348 txtlen
= resultSize
- 1;
349 memcpy (result
, infoPtr
->textbuf
+ (spec
&~ DT_STRING
), txtlen
* sizeof(WCHAR
));
351 TRACE ("arg%d=%x->[%s]\n", count
, infoPtr
->fieldspec
[count
], debugstr_w(result
));
361 wsprintfW (result
, fmt_dW
, date
.wDay
);
364 wsprintfW (result
, fmt__2dW
, date
.wDay
);
367 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SABBREVDAYNAME1
+(date
.wDayOfWeek
+6)%7, result
, 4);
368 /*wsprintfW (result,"%.3s",days[date.wDayOfWeek]);*/
371 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SDAYNAME1
+(date
.wDayOfWeek
+6)%7, result
, resultSize
);
374 if (date
.wHour
== 0) {
380 wsprintfW (result
, fmt_dW
, date
.wHour
- (date
.wHour
> 12 ? 12 : 0));
383 if (date
.wHour
== 0) {
389 wsprintfW (result
, fmt__2dW
, date
.wHour
- (date
.wHour
> 12 ? 12 : 0));
392 wsprintfW (result
, fmt_dW
, date
.wHour
);
395 wsprintfW (result
, fmt__2dW
, date
.wHour
);
398 wsprintfW (result
, fmt_dW
, date
.wSecond
);
401 wsprintfW (result
, fmt__2dW
, date
.wSecond
);
404 wsprintfW (result
, fmt_dW
, date
.wMinute
);
407 wsprintfW (result
, fmt__2dW
, date
.wMinute
);
410 wsprintfW (result
, fmt_dW
, date
.wMonth
);
413 wsprintfW (result
, fmt__2dW
, date
.wMonth
);
416 GetLocaleInfoW(GetSystemDefaultLCID(), LOCALE_SMONTHNAME1
+date
.wMonth
-1,
417 buffer
, sizeof(buffer
)/sizeof(buffer
[0]));
418 wsprintfW (result
, fmt__3sW
, buffer
);
421 GetLocaleInfoW(GetSystemDefaultLCID(),LOCALE_SMONTHNAME1
+date
.wMonth
-1,
425 result
[0] = (date
.wHour
< 12 ? 'A' : 'P');
429 result
[0] = (date
.wHour
< 12 ? 'A' : 'P');
434 FIXME ("Not implemented\n");
439 wsprintfW (result
, fmt_dW
, date
.wYear
-10* (int) floor(date
.wYear
/10));
442 wsprintfW (result
, fmt__2dW
, date
.wYear
-100* (int) floor(date
.wYear
/100));
444 case INVALIDFULLYEAR
:
446 wsprintfW (result
, fmt_dW
, date
.wYear
);
450 TRACE ("arg%d=%x->[%s]\n", count
, infoPtr
->fieldspec
[count
], debugstr_w(result
));
453 /* Offsets of days in the week to the weekday of january 1 in a leap year. */
454 static const int DayOfWeekTable
[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
456 /* returns the day in the week(0 == sunday, 6 == saturday) */
457 /* day(1 == 1st, 2 == 2nd... etc), year is the year value */
458 static int DATETIME_CalculateDayOfWeek(DWORD day
, DWORD month
, DWORD year
)
462 return((year
+ year
/4 - year
/100 + year
/400 +
463 DayOfWeekTable
[month
-1] + day
) % 7);
466 static int wrap(int val
, int delta
, int minVal
, int maxVal
)
469 if (delta
== INT_MIN
|| val
< minVal
) return maxVal
;
470 if (delta
== INT_MAX
|| val
> maxVal
) return minVal
;
475 DATETIME_IncreaseField (DATETIME_INFO
*infoPtr
, int number
, int delta
)
477 SYSTEMTIME
*date
= &infoPtr
->date
;
479 TRACE ("%d\n", number
);
480 if ((number
> infoPtr
->nrFields
) || (number
< 0)) return;
482 if ((infoPtr
->fieldspec
[number
] & DTHT_DATEFIELD
) == 0) return;
484 switch (infoPtr
->fieldspec
[number
]) {
488 date
->wYear
= wrap(date
->wYear
, delta
, 1752, 9999);
489 date
->wDayOfWeek
= DATETIME_CalculateDayOfWeek(date
->wDay
,date
->wMonth
,date
->wYear
);
495 date
->wMonth
= wrap(date
->wMonth
, delta
, 1, 12);
496 date
->wDayOfWeek
= DATETIME_CalculateDayOfWeek(date
->wDay
,date
->wMonth
,date
->wYear
);
503 date
->wDay
= wrap(date
->wDay
, delta
, 1, MONTHCAL_MonthLength(date
->wMonth
, date
->wYear
));
504 date
->wDayOfWeek
= DATETIME_CalculateDayOfWeek(date
->wDay
,date
->wMonth
,date
->wYear
);
514 date
->wHour
= wrap(date
->wHour
, delta
, 0, 23);
518 date
->wMinute
= wrap(date
->wMinute
, delta
, 0, 59);
522 date
->wSecond
= wrap(date
->wSecond
, delta
, 0, 59);
525 FIXME ("Not implemented\n");
529 /* FYI: On 1752/9/14 the calendar changed and England and the
530 * American colonies changed to the Gregorian calendar. This change
531 * involved having September 14th follow September 2nd. So no date
532 * algorithm works before that date.
534 if (10000 * date
->wYear
+ 100 * date
->wMonth
+ date
->wDay
< 17520914) {
546 DATETIME_ReturnFieldWidth (const DATETIME_INFO
*infoPtr
, HDC hdc
, int count
, SHORT
*width
)
548 /* fields are a fixed width, determined by the largest possible string */
549 /* presumably, these widths should be language dependent */
550 static const WCHAR fld_d1W
[] = { '2', 0 };
551 static const WCHAR fld_d2W
[] = { '2', '2', 0 };
552 static const WCHAR fld_d4W
[] = { '2', '2', '2', '2', 0 };
553 static const WCHAR fld_am1
[] = { 'A', 0 };
554 static const WCHAR fld_am2
[] = { 'A', 'M', 0 };
560 TRACE ("%d,%d\n", infoPtr
->nrFields
, count
);
561 if (count
>infoPtr
->nrFields
|| count
< 0) {
562 WARN ("buffer overrun, have %d want %d\n", infoPtr
->nrFields
, count
);
566 if (!infoPtr
->fieldspec
) return;
568 spec
= infoPtr
->fieldspec
[count
];
569 if (spec
& DT_STRING
) {
570 int txtlen
= infoPtr
->buflen
[count
];
574 memcpy (buffer
, infoPtr
->textbuf
+ (spec
&~ DT_STRING
), txtlen
* sizeof(WCHAR
));
587 /* these seem to use a two byte field */
597 case INVALIDFULLYEAR
:
606 static const WCHAR fld_day
[] = {'W','e','d','n','e','s','d','a','y',0};
607 static const WCHAR fld_abbrday
[] = {'W','e','d',0};
608 static const WCHAR fld_mon
[] = {'S','e','p','t','e','m','b','e','r',0};
609 static const WCHAR fld_abbrmon
[] = {'D','e','c',0};
616 /* choose locale data type and fallback string */
620 lctype
= LOCALE_SABBREVDAYNAME1
;
625 lctype
= LOCALE_SDAYNAME1
;
630 lctype
= LOCALE_SABBREVMONTHNAME1
;
635 lctype
= LOCALE_SMONTHNAME1
;
641 for (i
= 0; i
< max_count
; i
++)
643 if(GetLocaleInfoW(LOCALE_USER_DEFAULT
, lctype
+ i
,
644 buffer
, lstrlenW(buffer
)))
646 GetTextExtentPoint32W(hdc
, buffer
, lstrlenW(buffer
), &size
);
647 if (size
.cx
> cx
) cx
= size
.cx
;
649 else /* locale independent fallback on failure */
651 GetTextExtentPoint32W(hdc
, fall
, lstrlenW(fall
), &size
);
670 GetTextExtentPoint32W (hdc
, bufptr
, strlenW(bufptr
), &size
);
675 DATETIME_Refresh (DATETIME_INFO
*infoPtr
, HDC hdc
)
679 if (infoPtr
->dateValid
) {
682 RECT
*rcDraw
= &infoPtr
->rcDraw
;
684 COLORREF oldTextColor
;
685 SHORT fieldWidth
= 0;
686 HFONT oldFont
= SelectObject (hdc
, infoPtr
->hFont
);
687 INT oldBkMode
= SetBkMode (hdc
, TRANSPARENT
);
690 DATETIME_ReturnTxt (infoPtr
, 0, txt
, sizeof(txt
)/sizeof(txt
[0]));
691 GetTextExtentPoint32W (hdc
, txt
, strlenW(txt
), &size
);
692 rcDraw
->bottom
= size
.cy
+ 2;
694 prevright
= infoPtr
->checkbox
.right
= ((infoPtr
->dwStyle
& DTS_SHOWNONE
) ? 18 : 2);
696 for (i
= 0; i
< infoPtr
->nrFields
; i
++) {
697 DATETIME_ReturnTxt (infoPtr
, i
, txt
, sizeof(txt
)/sizeof(txt
[0]));
698 GetTextExtentPoint32W (hdc
, txt
, strlenW(txt
), &size
);
699 DATETIME_ReturnFieldWidth (infoPtr
, hdc
, i
, &fieldWidth
);
700 field
= &infoPtr
->fieldRect
[i
];
701 field
->left
= prevright
;
702 field
->right
= prevright
+ fieldWidth
;
703 field
->top
= rcDraw
->top
;
704 field
->bottom
= rcDraw
->bottom
;
705 prevright
= field
->right
;
707 if (infoPtr
->dwStyle
& WS_DISABLED
)
708 oldTextColor
= SetTextColor (hdc
, comctl32_color
.clrGrayText
);
709 else if ((infoPtr
->haveFocus
) && (i
== infoPtr
->select
)) {
712 /* fill if focused */
713 HBRUSH hbr
= CreateSolidBrush (comctl32_color
.clrActiveCaption
);
715 selection
.right
= field
->right
;
716 selection
.left
= selection
.right
- size
.cx
;
718 selection
.bottom
= size
.cy
;
719 /* center rectangle */
720 OffsetRect(&selection
, 0, (field
->bottom
- size
.cy
)/2);
722 FillRect(hdc
, &selection
, hbr
);
724 oldTextColor
= SetTextColor (hdc
, comctl32_color
.clrWindow
);
727 oldTextColor
= SetTextColor (hdc
, comctl32_color
.clrWindowText
);
729 /* draw the date text using the colour set above */
730 DrawTextW (hdc
, txt
, strlenW(txt
), field
, DT_RIGHT
| DT_VCENTER
| DT_SINGLELINE
);
731 SetTextColor (hdc
, oldTextColor
);
733 SetBkMode (hdc
, oldBkMode
);
734 SelectObject (hdc
, oldFont
);
737 if (!(infoPtr
->dwStyle
& DTS_UPDOWN
)) {
738 DrawFrameControl(hdc
, &infoPtr
->calbutton
, DFC_SCROLL
,
739 DFCS_SCROLLDOWN
| (infoPtr
->bCalDepressed
? DFCS_PUSHED
: 0) |
740 (infoPtr
->dwStyle
& WS_DISABLED
? DFCS_INACTIVE
: 0) );
746 DATETIME_HitTest (const DATETIME_INFO
*infoPtr
, POINT pt
)
750 TRACE ("%d, %d\n", pt
.x
, pt
.y
);
752 if (PtInRect (&infoPtr
->calbutton
, pt
)) return DTHT_MCPOPUP
;
753 if (PtInRect (&infoPtr
->checkbox
, pt
)) return DTHT_CHECKBOX
;
755 for (i
= 0; i
< infoPtr
->nrFields
; i
++) {
756 if (PtInRect (&infoPtr
->fieldRect
[i
], pt
)) return i
;
762 /* Returns index of a closest date field from given counting to left
763 or -1 if there's no such fields at left */
764 static int DATETIME_GetPrevDateField(const DATETIME_INFO
*infoPtr
, int i
)
766 for(--i
; i
>= 0; i
--)
768 if (infoPtr
->fieldspec
[i
] & DTHT_DATEFIELD
) return i
;
774 DATETIME_LButtonDown (DATETIME_INFO
*infoPtr
, INT x
, INT y
)
781 old
= infoPtr
->select
;
782 new = DATETIME_HitTest (infoPtr
, pt
);
784 SetFocus(infoPtr
->hwndSelf
);
786 if (!(new & DTHT_NODATEMASK
) || (new == DTHT_NONE
))
788 if (new == DTHT_NONE
)
789 new = infoPtr
->nrFields
- 1;
792 /* hitting string part moves selection to next date field to left */
793 if (infoPtr
->fieldspec
[new] & DT_STRING
)
795 new = DATETIME_GetPrevDateField(infoPtr
, new);
796 if (new == -1) return 0;
798 /* never select full day of week */
799 if (infoPtr
->fieldspec
[new] == FULLDAY
) return 0;
802 infoPtr
->select
= new;
804 if (infoPtr
->select
== DTHT_MCPOPUP
) {
806 SendMessageW(infoPtr
->hMonthCal
, MCM_GETMINREQRECT
, 0, (LPARAM
)&rcMonthCal
);
808 /* FIXME: button actually is only depressed during dropdown of the */
809 /* calendar control and when the mouse is over the button window */
810 infoPtr
->bCalDepressed
= TRUE
;
812 /* recalculate the position of the monthcal popup */
813 if(infoPtr
->dwStyle
& DTS_RIGHTALIGN
)
814 infoPtr
->monthcal_pos
.x
= infoPtr
->calbutton
.left
-
815 (rcMonthCal
.right
- rcMonthCal
.left
);
817 /* FIXME: this should be after the area reserved for the checkbox */
818 infoPtr
->monthcal_pos
.x
= infoPtr
->rcDraw
.left
;
820 infoPtr
->monthcal_pos
.y
= infoPtr
->rcClient
.bottom
;
821 ClientToScreen (infoPtr
->hwndSelf
, &(infoPtr
->monthcal_pos
));
822 SetWindowPos(infoPtr
->hMonthCal
, 0, infoPtr
->monthcal_pos
.x
,
823 infoPtr
->monthcal_pos
.y
, rcMonthCal
.right
- rcMonthCal
.left
,
824 rcMonthCal
.bottom
- rcMonthCal
.top
, 0);
826 if(IsWindowVisible(infoPtr
->hMonthCal
)) {
827 ShowWindow(infoPtr
->hMonthCal
, SW_HIDE
);
829 const SYSTEMTIME
*lprgSysTimeArray
= &infoPtr
->date
;
830 TRACE("update calendar %04d/%02d/%02d\n",
831 lprgSysTimeArray
->wYear
, lprgSysTimeArray
->wMonth
, lprgSysTimeArray
->wDay
);
832 SendMessageW(infoPtr
->hMonthCal
, MCM_SETCURSEL
, 0, (LPARAM
)(&infoPtr
->date
));
834 if (infoPtr
->bDropdownEnabled
)
835 ShowWindow(infoPtr
->hMonthCal
, SW_SHOW
);
836 infoPtr
->bDropdownEnabled
= TRUE
;
839 TRACE ("dt:%p mc:%p mc parent:%p, desktop:%p\n",
840 infoPtr
->hwndSelf
, infoPtr
->hMonthCal
, infoPtr
->hwndNotify
, GetDesktopWindow ());
841 DATETIME_SendSimpleNotify (infoPtr
, DTN_DROPDOWN
);
844 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
851 DATETIME_LButtonUp (DATETIME_INFO
*infoPtr
)
853 if(infoPtr
->bCalDepressed
) {
854 infoPtr
->bCalDepressed
= FALSE
;
855 InvalidateRect(infoPtr
->hwndSelf
, &(infoPtr
->calbutton
), TRUE
);
863 DATETIME_Paint (DATETIME_INFO
*infoPtr
, HDC hdc
)
867 hdc
= BeginPaint (infoPtr
->hwndSelf
, &ps
);
868 DATETIME_Refresh (infoPtr
, hdc
);
869 EndPaint (infoPtr
->hwndSelf
, &ps
);
871 DATETIME_Refresh (infoPtr
, hdc
);
874 /* Not a click on the dropdown box, enabled it */
875 infoPtr
->bDropdownEnabled
= TRUE
;
882 DATETIME_Button_Command (DATETIME_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
884 if( HIWORD(wParam
) == BN_CLICKED
) {
885 DWORD state
= SendMessageW((HWND
)lParam
, BM_GETCHECK
, 0, 0);
886 infoPtr
->dateValid
= (state
== BST_CHECKED
);
887 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
895 DATETIME_Command (DATETIME_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
897 TRACE("hwndbutton = %p\n", infoPtr
->hwndCheckbut
);
898 if(infoPtr
->hwndCheckbut
== (HWND
)lParam
)
899 return DATETIME_Button_Command(infoPtr
, wParam
, lParam
);
905 DATETIME_Enable (DATETIME_INFO
*infoPtr
, BOOL bEnable
)
907 TRACE("%p %s\n", infoPtr
, bEnable
? "TRUE" : "FALSE");
909 infoPtr
->dwStyle
&= ~WS_DISABLED
;
911 infoPtr
->dwStyle
|= WS_DISABLED
;
913 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
920 DATETIME_EraseBackground (const DATETIME_INFO
*infoPtr
, HDC hdc
)
922 HBRUSH hBrush
, hSolidBrush
= NULL
;
925 if (infoPtr
->dwStyle
& WS_DISABLED
)
926 hBrush
= hSolidBrush
= CreateSolidBrush(comctl32_color
.clrBtnFace
);
929 hBrush
= (HBRUSH
)SendMessageW(infoPtr
->hwndNotify
, WM_CTLCOLOREDIT
,
930 (WPARAM
)hdc
, (LPARAM
)infoPtr
->hwndSelf
);
932 hBrush
= hSolidBrush
= CreateSolidBrush(comctl32_color
.clrWindow
);
935 GetClientRect (infoPtr
->hwndSelf
, &rc
);
937 FillRect (hdc
, &rc
, hBrush
);
940 DeleteObject(hSolidBrush
);
947 DATETIME_Notify (DATETIME_INFO
*infoPtr
, LPNMHDR lpnmh
)
949 TRACE ("Got notification %x from %p\n", lpnmh
->code
, lpnmh
->hwndFrom
);
950 TRACE ("info: %p %p %p\n", infoPtr
->hwndSelf
, infoPtr
->hMonthCal
, infoPtr
->hUpdown
);
952 if (lpnmh
->code
== MCN_SELECT
) {
953 ShowWindow(infoPtr
->hMonthCal
, SW_HIDE
);
954 infoPtr
->dateValid
= TRUE
;
955 SendMessageW (infoPtr
->hMonthCal
, MCM_GETCURSEL
, 0, (LPARAM
)&infoPtr
->date
);
956 TRACE("got from calendar %04d/%02d/%02d day of week %d\n",
957 infoPtr
->date
.wYear
, infoPtr
->date
.wMonth
, infoPtr
->date
.wDay
, infoPtr
->date
.wDayOfWeek
);
958 SendMessageW (infoPtr
->hwndCheckbut
, BM_SETCHECK
, BST_CHECKED
, 0);
959 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
960 DATETIME_SendDateTimeChangeNotify (infoPtr
);
962 if ((lpnmh
->hwndFrom
== infoPtr
->hUpdown
) && (lpnmh
->code
== UDN_DELTAPOS
)) {
963 LPNMUPDOWN lpnmud
= (LPNMUPDOWN
)lpnmh
;
964 TRACE("Delta pos %d\n", lpnmud
->iDelta
);
965 infoPtr
->pendingUpdown
= lpnmud
->iDelta
;
972 DATETIME_KeyDown (DATETIME_INFO
*infoPtr
, DWORD vkCode
)
974 int fieldNum
= infoPtr
->select
& DTHT_DATEFIELD
;
977 if (!(infoPtr
->haveFocus
)) return 0;
978 if ((fieldNum
==0) && (infoPtr
->select
)) return 0;
980 if (infoPtr
->select
& FORMATCALLMASK
) {
981 FIXME ("Callbacks not implemented yet\n");
987 DATETIME_IncreaseField (infoPtr
, fieldNum
, 1);
988 DATETIME_SendDateTimeChangeNotify (infoPtr
);
992 DATETIME_IncreaseField (infoPtr
, fieldNum
, -1);
993 DATETIME_SendDateTimeChangeNotify (infoPtr
);
996 DATETIME_IncreaseField (infoPtr
, fieldNum
, INT_MIN
);
997 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1000 DATETIME_IncreaseField (infoPtr
, fieldNum
, INT_MAX
);
1001 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1005 if (infoPtr
->select
== 0) {
1006 infoPtr
->select
= infoPtr
->nrFields
- 1;
1011 } while ((infoPtr
->fieldspec
[infoPtr
->select
] & DT_STRING
) && (wrap
<2));
1016 if (infoPtr
->select
==infoPtr
->nrFields
) {
1017 infoPtr
->select
= 0;
1020 } while ((infoPtr
->fieldspec
[infoPtr
->select
] & DT_STRING
) && (wrap
<2));
1024 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1031 DATETIME_Char (DATETIME_INFO
*infoPtr
, WPARAM vkCode
)
1033 int fieldNum
= infoPtr
->select
& DTHT_DATEFIELD
;
1035 if (vkCode
>= '0' && vkCode
<= '9') {
1036 int num
= vkCode
-'0';
1039 /* this is a somewhat simplified version of what Windows does */
1040 SYSTEMTIME
*date
= &infoPtr
->date
;
1041 switch (infoPtr
->fieldspec
[fieldNum
]) {
1044 date
->wYear
= date
->wYear
- (date
->wYear
%100) +
1045 (date
->wYear
%10)*10 + num
;
1046 date
->wDayOfWeek
= DATETIME_CalculateDayOfWeek(
1047 date
->wDay
,date
->wMonth
,date
->wYear
);
1048 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1050 case INVALIDFULLYEAR
:
1052 /* reset current year initialy */
1053 date
->wYear
= ((date
->wYear
/1000) ? 0 : 1)*(date
->wYear
%1000)*10 + num
;
1054 date
->wDayOfWeek
= DATETIME_CalculateDayOfWeek(
1055 date
->wDay
,date
->wMonth
,date
->wYear
);
1056 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1060 if ((date
->wMonth
%10) > 1 || num
> 2)
1063 date
->wMonth
= (date
->wMonth
%10)*10+num
;
1064 date
->wDayOfWeek
= DATETIME_CalculateDayOfWeek(
1065 date
->wDay
,date
->wMonth
,date
->wYear
);
1066 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1070 newDays
= (date
->wDay
%10)*10+num
;
1071 if (newDays
> MONTHCAL_MonthLength(date
->wMonth
, date
->wYear
))
1074 date
->wDay
= newDays
;
1075 date
->wDayOfWeek
= DATETIME_CalculateDayOfWeek(
1076 date
->wDay
,date
->wMonth
,date
->wYear
);
1077 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1079 case ONEDIGIT12HOUR
:
1080 case TWODIGIT12HOUR
:
1081 if ((date
->wHour
%10) > 1 || num
> 2)
1084 date
->wHour
= (date
->wHour
%10)*10+num
;
1085 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1087 case ONEDIGIT24HOUR
:
1088 case TWODIGIT24HOUR
:
1089 if ((date
->wHour
%10) > 2)
1091 else if ((date
->wHour
%10) == 2 && num
> 3)
1094 date
->wHour
= (date
->wHour
%10)*10+num
;
1095 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1097 case ONEDIGITMINUTE
:
1098 case TWODIGITMINUTE
:
1099 if ((date
->wMinute
%10) > 5)
1100 date
->wMinute
= num
;
1102 date
->wMinute
= (date
->wMinute
%10)*10+num
;
1103 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1105 case ONEDIGITSECOND
:
1106 case TWODIGITSECOND
:
1107 if ((date
->wSecond
%10) > 5)
1108 date
->wSecond
= num
;
1110 date
->wSecond
= (date
->wSecond
%10)*10+num
;
1111 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1120 DATETIME_VScroll (DATETIME_INFO
*infoPtr
, WORD wScroll
)
1122 int fieldNum
= infoPtr
->select
& DTHT_DATEFIELD
;
1124 if ((SHORT
)LOWORD(wScroll
) != SB_THUMBPOSITION
) return 0;
1125 if (!(infoPtr
->haveFocus
)) return 0;
1126 if ((fieldNum
==0) && (infoPtr
->select
)) return 0;
1128 if (infoPtr
->pendingUpdown
>= 0) {
1129 DATETIME_IncreaseField (infoPtr
, fieldNum
, 1);
1130 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1133 DATETIME_IncreaseField (infoPtr
, fieldNum
, -1);
1134 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1137 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1144 DATETIME_KillFocus (DATETIME_INFO
*infoPtr
, HWND lostFocus
)
1146 TRACE("lost focus to %p\n", lostFocus
);
1148 if (infoPtr
->haveFocus
) {
1149 DATETIME_SendSimpleNotify (infoPtr
, NM_KILLFOCUS
);
1150 infoPtr
->haveFocus
= 0;
1153 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
1160 DATETIME_NCCreate (HWND hwnd
, const CREATESTRUCTW
*lpcs
)
1162 DWORD dwExStyle
= GetWindowLongW(hwnd
, GWL_EXSTYLE
);
1163 /* force control to have client edge */
1164 dwExStyle
|= WS_EX_CLIENTEDGE
;
1165 SetWindowLongW(hwnd
, GWL_EXSTYLE
, dwExStyle
);
1167 return DefWindowProcW(hwnd
, WM_NCCREATE
, 0, (LPARAM
)lpcs
);
1172 DATETIME_SetFocus (DATETIME_INFO
*infoPtr
, HWND lostFocus
)
1174 TRACE("got focus from %p\n", lostFocus
);
1176 /* if monthcal is open and it loses focus, close monthcal */
1177 if (infoPtr
->hMonthCal
&& (lostFocus
== infoPtr
->hMonthCal
) &&
1178 IsWindowVisible(infoPtr
->hMonthCal
))
1180 ShowWindow(infoPtr
->hMonthCal
, SW_HIDE
);
1181 DATETIME_SendSimpleNotify(infoPtr
, DTN_CLOSEUP
);
1182 /* note: this get triggered even if monthcal loses focus to a dropdown
1183 * box click, which occurs without an intermediate WM_PAINT call
1185 infoPtr
->bDropdownEnabled
= FALSE
;
1189 if (infoPtr
->haveFocus
== 0) {
1190 DATETIME_SendSimpleNotify (infoPtr
, NM_SETFOCUS
);
1191 infoPtr
->haveFocus
= DTHT_GOTFOCUS
;
1194 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1201 DATETIME_SendDateTimeChangeNotify (const DATETIME_INFO
*infoPtr
)
1203 NMDATETIMECHANGE dtdtc
;
1205 dtdtc
.nmhdr
.hwndFrom
= infoPtr
->hwndSelf
;
1206 dtdtc
.nmhdr
.idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1207 dtdtc
.nmhdr
.code
= DTN_DATETIMECHANGE
;
1209 dtdtc
.dwFlags
= (infoPtr
->dwStyle
& DTS_SHOWNONE
) ? GDT_NONE
: GDT_VALID
;
1211 dtdtc
.st
= infoPtr
->date
;
1212 return (BOOL
) SendMessageW (infoPtr
->hwndNotify
, WM_NOTIFY
,
1213 dtdtc
.nmhdr
.idFrom
, (LPARAM
)&dtdtc
);
1218 DATETIME_SendSimpleNotify (const DATETIME_INFO
*infoPtr
, UINT code
)
1222 TRACE("%x\n", code
);
1223 nmhdr
.hwndFrom
= infoPtr
->hwndSelf
;
1224 nmhdr
.idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1227 return (BOOL
) SendMessageW (infoPtr
->hwndNotify
, WM_NOTIFY
,
1228 nmhdr
.idFrom
, (LPARAM
)&nmhdr
);
1232 DATETIME_Size (DATETIME_INFO
*infoPtr
, INT width
, INT height
)
1235 infoPtr
->rcClient
.bottom
= height
;
1236 infoPtr
->rcClient
.right
= width
;
1238 TRACE("Height=%d, Width=%d\n", infoPtr
->rcClient
.bottom
, infoPtr
->rcClient
.right
);
1240 infoPtr
->rcDraw
= infoPtr
->rcClient
;
1242 if (infoPtr
->dwStyle
& DTS_UPDOWN
) {
1243 SetWindowPos(infoPtr
->hUpdown
, NULL
,
1244 infoPtr
->rcClient
.right
-14, 0,
1245 15, infoPtr
->rcClient
.bottom
- infoPtr
->rcClient
.top
,
1246 SWP_NOACTIVATE
| SWP_NOZORDER
);
1249 /* set the size of the button that drops the calendar down */
1250 /* FIXME: account for style that allows button on left side */
1251 infoPtr
->calbutton
.top
= infoPtr
->rcDraw
.top
;
1252 infoPtr
->calbutton
.bottom
= infoPtr
->rcDraw
.bottom
;
1253 infoPtr
->calbutton
.left
= infoPtr
->rcDraw
.right
-15;
1254 infoPtr
->calbutton
.right
= infoPtr
->rcDraw
.right
;
1257 /* set enable/disable button size for show none style being enabled */
1258 /* FIXME: these dimensions are completely incorrect */
1259 infoPtr
->checkbox
.top
= infoPtr
->rcDraw
.top
;
1260 infoPtr
->checkbox
.bottom
= infoPtr
->rcDraw
.bottom
;
1261 infoPtr
->checkbox
.left
= infoPtr
->rcDraw
.left
;
1262 infoPtr
->checkbox
.right
= infoPtr
->rcDraw
.left
+ 10;
1264 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1271 DATETIME_StyleChanged(DATETIME_INFO
*infoPtr
, WPARAM wStyleType
, const STYLESTRUCT
*lpss
)
1273 static const WCHAR buttonW
[] = { 'b', 'u', 't', 't', 'o', 'n', 0 };
1275 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
1276 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
1278 if (wStyleType
!= GWL_STYLE
) return 0;
1280 infoPtr
->dwStyle
= lpss
->styleNew
;
1282 if ( !(lpss
->styleOld
& DTS_SHOWNONE
) && (lpss
->styleNew
& DTS_SHOWNONE
) ) {
1283 infoPtr
->hwndCheckbut
= CreateWindowExW (0, buttonW
, 0, WS_CHILD
| WS_VISIBLE
| BS_AUTOCHECKBOX
,
1284 2, 2, 13, 13, infoPtr
->hwndSelf
, 0,
1285 (HINSTANCE
)GetWindowLongPtrW (infoPtr
->hwndSelf
, GWLP_HINSTANCE
), 0);
1286 SendMessageW (infoPtr
->hwndCheckbut
, BM_SETCHECK
, 1, 0);
1288 if ( (lpss
->styleOld
& DTS_SHOWNONE
) && !(lpss
->styleNew
& DTS_SHOWNONE
) ) {
1289 DestroyWindow(infoPtr
->hwndCheckbut
);
1290 infoPtr
->hwndCheckbut
= 0;
1292 if ( !(lpss
->styleOld
& DTS_UPDOWN
) && (lpss
->styleNew
& DTS_UPDOWN
) ) {
1293 infoPtr
->hUpdown
= CreateUpDownControl (WS_CHILD
| WS_BORDER
| WS_VISIBLE
, 120, 1, 20, 20,
1294 infoPtr
->hwndSelf
, 1, 0, 0, UD_MAXVAL
, UD_MINVAL
, 0);
1296 if ( (lpss
->styleOld
& DTS_UPDOWN
) && !(lpss
->styleNew
& DTS_UPDOWN
) ) {
1297 DestroyWindow(infoPtr
->hUpdown
);
1298 infoPtr
->hUpdown
= 0;
1301 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1307 DATETIME_SetFont (DATETIME_INFO
*infoPtr
, HFONT font
, BOOL repaint
)
1309 infoPtr
->hFont
= font
;
1310 if (repaint
) InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1316 DATETIME_Create (HWND hwnd
, const CREATESTRUCTW
*lpcs
)
1318 DATETIME_INFO
*infoPtr
= Alloc (sizeof(DATETIME_INFO
));
1319 STYLESTRUCT ss
= { 0, lpcs
->style
};
1321 if (!infoPtr
) return -1;
1323 infoPtr
->hwndSelf
= hwnd
;
1324 infoPtr
->dwStyle
= lpcs
->style
;
1326 infoPtr
->nrFieldsAllocated
= 32;
1327 infoPtr
->fieldspec
= Alloc (infoPtr
->nrFieldsAllocated
* sizeof(int));
1328 infoPtr
->fieldRect
= Alloc (infoPtr
->nrFieldsAllocated
* sizeof(RECT
));
1329 infoPtr
->buflen
= Alloc (infoPtr
->nrFieldsAllocated
* sizeof(int));
1330 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
1331 infoPtr
->select
= -1; /* initially, nothing is selected */
1332 infoPtr
->bDropdownEnabled
= TRUE
;
1334 DATETIME_StyleChanged(infoPtr
, GWL_STYLE
, &ss
);
1335 DATETIME_SetFormatW (infoPtr
, 0);
1337 /* create the monthcal control */
1338 infoPtr
->hMonthCal
= CreateWindowExW (0, MONTHCAL_CLASSW
, 0, WS_BORDER
| WS_POPUP
| WS_CLIPSIBLINGS
,
1339 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, 0, 0);
1341 /* initialize info structure */
1342 GetLocalTime (&infoPtr
->date
);
1343 infoPtr
->dateValid
= TRUE
;
1344 infoPtr
->hFont
= GetStockObject(DEFAULT_GUI_FONT
);
1346 SetWindowLongPtrW (hwnd
, 0, (DWORD_PTR
)infoPtr
);
1354 DATETIME_Destroy (DATETIME_INFO
*infoPtr
)
1356 if (infoPtr
->hwndCheckbut
)
1357 DestroyWindow(infoPtr
->hwndCheckbut
);
1358 if (infoPtr
->hUpdown
)
1359 DestroyWindow(infoPtr
->hUpdown
);
1360 if (infoPtr
->hMonthCal
)
1361 DestroyWindow(infoPtr
->hMonthCal
);
1362 SetWindowLongPtrW( infoPtr
->hwndSelf
, 0, 0 ); /* clear infoPtr */
1368 static LRESULT WINAPI
1369 DATETIME_WindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1371 DATETIME_INFO
*infoPtr
= ((DATETIME_INFO
*)GetWindowLongPtrW (hwnd
, 0));
1374 TRACE ("%x, %lx, %lx\n", uMsg
, wParam
, lParam
);
1376 if (!infoPtr
&& (uMsg
!= WM_CREATE
) && (uMsg
!= WM_NCCREATE
))
1377 return DefWindowProcW( hwnd
, uMsg
, wParam
, lParam
);
1381 case DTM_GETSYSTEMTIME
:
1382 return DATETIME_GetSystemTime (infoPtr
, (SYSTEMTIME
*) lParam
);
1384 case DTM_SETSYSTEMTIME
:
1385 return DATETIME_SetSystemTime (infoPtr
, wParam
, (SYSTEMTIME
*) lParam
);
1388 ret
= SendMessageW (infoPtr
->hMonthCal
, MCM_GETRANGE
, wParam
, lParam
);
1389 return ret
? ret
: 1; /* bug emulation */
1392 return SendMessageW (infoPtr
->hMonthCal
, MCM_SETRANGE
, wParam
, lParam
);
1394 case DTM_SETFORMATA
:
1395 return DATETIME_SetFormatA (infoPtr
, (LPCSTR
)lParam
);
1397 case DTM_SETFORMATW
:
1398 return DATETIME_SetFormatW (infoPtr
, (LPCWSTR
)lParam
);
1400 case DTM_GETMONTHCAL
:
1401 return (LRESULT
)infoPtr
->hMonthCal
;
1403 case DTM_SETMCCOLOR
:
1404 return SendMessageW (infoPtr
->hMonthCal
, MCM_SETCOLOR
, wParam
, lParam
);
1406 case DTM_GETMCCOLOR
:
1407 return SendMessageW (infoPtr
->hMonthCal
, MCM_GETCOLOR
, wParam
, 0);
1410 return SendMessageW (infoPtr
->hMonthCal
, WM_SETFONT
, wParam
, lParam
);
1413 return SendMessageW (infoPtr
->hMonthCal
, WM_GETFONT
, wParam
, lParam
);
1416 return DATETIME_Notify (infoPtr
, (LPNMHDR
)lParam
);
1419 return DATETIME_Enable (infoPtr
, (BOOL
)wParam
);
1422 return DATETIME_EraseBackground (infoPtr
, (HDC
)wParam
);
1425 return DLGC_WANTARROWS
| DLGC_WANTCHARS
;
1427 case WM_PRINTCLIENT
:
1429 return DATETIME_Paint (infoPtr
, (HDC
)wParam
);
1432 return DATETIME_KeyDown (infoPtr
, wParam
);
1435 return DATETIME_Char (infoPtr
, wParam
);
1438 return DATETIME_KillFocus (infoPtr
, (HWND
)wParam
);
1441 return DATETIME_NCCreate (hwnd
, (LPCREATESTRUCTW
)lParam
);
1444 return DATETIME_SetFocus (infoPtr
, (HWND
)wParam
);
1447 return DATETIME_Size (infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
1449 case WM_LBUTTONDOWN
:
1450 return DATETIME_LButtonDown (infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
1453 return DATETIME_LButtonUp (infoPtr
);
1456 return DATETIME_VScroll (infoPtr
, (WORD
)wParam
);
1459 return DATETIME_Create (hwnd
, (LPCREATESTRUCTW
)lParam
);
1462 return DATETIME_Destroy (infoPtr
);
1465 return DATETIME_Command (infoPtr
, wParam
, lParam
);
1467 case WM_STYLECHANGED
:
1468 return DATETIME_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
1471 return DATETIME_SetFont(infoPtr
, (HFONT
)wParam
, (BOOL
)lParam
);
1474 return (LRESULT
) infoPtr
->hFont
;
1480 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
1481 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
1482 uMsg
, wParam
, lParam
);
1483 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
1489 DATETIME_Register (void)
1493 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
1494 wndClass
.style
= CS_GLOBALCLASS
;
1495 wndClass
.lpfnWndProc
= DATETIME_WindowProc
;
1496 wndClass
.cbClsExtra
= 0;
1497 wndClass
.cbWndExtra
= sizeof(DATETIME_INFO
*);
1498 wndClass
.hCursor
= LoadCursorW (0, (LPCWSTR
)IDC_ARROW
);
1499 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
1500 wndClass
.lpszClassName
= DATETIMEPICK_CLASSW
;
1502 RegisterClassW (&wndClass
);
1507 DATETIME_Unregister (void)
1509 UnregisterClassW (DATETIMEPICK_CLASSW
, NULL
);