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>
7 * Copyright 2012 Owen Rudge for CodeWeavers
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 * This code was audited for completeness against the documented features
26 * of Comctl32.dll version 6.0 on Oct. 20, 2004, by Dimitrie O. Paun.
28 * Unless otherwise noted, we believe this code to be complete, as per
29 * the specification mentioned above.
30 * If you discover missing features, or bugs, please note them below.
34 * -- 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 */
75 BOOL bDropdownEnabled
;
77 WCHAR charsEntered
[4];
80 int nrFieldsAllocated
;
89 } DATETIME_INFO
, *LPDATETIME_INFO
;
92 extern int MONTHCAL_MonthLength(int month
, int year
);
93 extern int MONTHCAL_CalculateDayOfWeek(SYSTEMTIME
*date
, BOOL inplace
);
95 /* this list of defines is closely related to `allowedformatchars' defined
96 * in datetime.c; the high nibble indicates the `base type' of the format
98 * Do not change without first reading DATETIME_UseFormat.
102 #define DT_END_FORMAT 0
103 #define ONEDIGITDAY 0x01
104 #define TWODIGITDAY 0x02
105 #define THREECHARDAY 0x03
107 #define ONEDIGIT12HOUR 0x11
108 #define TWODIGIT12HOUR 0x12
109 #define ONEDIGIT24HOUR 0x21
110 #define TWODIGIT24HOUR 0x22
111 #define ONEDIGITMINUTE 0x31
112 #define TWODIGITMINUTE 0x32
113 #define ONEDIGITMONTH 0x41
114 #define TWODIGITMONTH 0x42
115 #define THREECHARMONTH 0x43
116 #define FULLMONTH 0x44
117 #define ONEDIGITSECOND 0x51
118 #define TWODIGITSECOND 0x52
119 #define ONELETTERAMPM 0x61
120 #define TWOLETTERAMPM 0x62
121 #define ONEDIGITYEAR 0x71
122 #define TWODIGITYEAR 0x72
123 #define INVALIDFULLYEAR 0x73 /* FIXME - yyy is not valid - we'll treat it as yyyy */
124 #define FULLYEAR 0x74
125 #define FORMATCALLBACK 0x81 /* -> maximum of 0x80 callbacks possible */
126 #define FORMATCALLMASK 0x80
127 #define DT_STRING 0x0100
129 #define DTHT_DATEFIELD 0xff /* for hit-testing */
131 #define DTHT_NONE 0x1000
132 #define DTHT_CHECKBOX 0x2000 /* these should end at '00' , to make */
133 #define DTHT_MCPOPUP 0x3000 /* & DTHT_DATEFIELD 0 when DATETIME_KeyDown */
134 #define DTHT_GOTFOCUS 0x4000 /* tests for date-fields */
135 #define DTHT_NODATEMASK 0xf000 /* to mask check and drop down from others */
137 static BOOL
DATETIME_SendSimpleNotify (const DATETIME_INFO
*infoPtr
, UINT code
);
138 static BOOL
DATETIME_SendDateTimeChangeNotify (const DATETIME_INFO
*infoPtr
);
139 static const WCHAR allowedformatchars
[] = {'d', 'h', 'H', 'm', 'M', 's', 't', 'y', 'X', 0};
140 static const int maxrepetition
[] = {4,2,2,2,4,2,2,4,-1};
142 /* valid date limits */
143 static const SYSTEMTIME max_allowed_date
= { /* wYear */ 9999, /* wMonth */ 12, /* wDayOfWeek */ 0, /* wDay */ 31 };
144 static const SYSTEMTIME min_allowed_date
= { /* wYear */ 1752, /* wMonth */ 9, /* wDayOfWeek */ 0, /* wDay */ 14 };
147 DATETIME_GetSystemTime (const DATETIME_INFO
*infoPtr
, SYSTEMTIME
*systime
)
149 if (!systime
) return GDT_NONE
;
151 if ((infoPtr
->dwStyle
& DTS_SHOWNONE
) &&
152 (SendMessageW (infoPtr
->hwndCheckbut
, BM_GETCHECK
, 0, 0) == BST_UNCHECKED
))
155 *systime
= infoPtr
->date
;
160 /* Checks value is within configured date range
164 * [I] infoPtr : valid pointer to control data
165 * [I] date : pointer to valid date data to check
169 * TRUE - date within configured range
170 * FALSE - date is outside configured range
172 static BOOL
DATETIME_IsDateInValidRange(const DATETIME_INFO
*infoPtr
, const SYSTEMTIME
*date
)
177 if ((MONTHCAL_CompareSystemTime(date
, &max_allowed_date
) == 1) ||
178 (MONTHCAL_CompareSystemTime(date
, &min_allowed_date
) == -1))
181 limits
= SendMessageW (infoPtr
->hMonthCal
, MCM_GETRANGE
, 0, (LPARAM
)range
);
183 if (limits
& GDTR_MAX
)
185 if (MONTHCAL_CompareSystemTime(date
, &range
[1]) == 1)
189 if (limits
& GDTR_MIN
)
191 if (MONTHCAL_CompareSystemTime(date
, &range
[0]) == -1)
199 DATETIME_SetSystemTime (DATETIME_INFO
*infoPtr
, DWORD flag
, const SYSTEMTIME
*systime
)
201 if (!systime
) return FALSE
;
203 TRACE("%04d/%02d/%02d %02d:%02d:%02d\n",
204 systime
->wYear
, systime
->wMonth
, systime
->wDay
,
205 systime
->wHour
, systime
->wMinute
, systime
->wSecond
);
207 if (flag
== GDT_VALID
) {
208 if (systime
->wYear
== 0 ||
209 systime
->wMonth
< 1 || systime
->wMonth
> 12 ||
211 systime
->wDay
> MONTHCAL_MonthLength(systime
->wMonth
, systime
->wYear
) ||
212 systime
->wHour
> 23 ||
213 systime
->wMinute
> 59 ||
214 systime
->wSecond
> 59 ||
215 systime
->wMilliseconds
> 999
219 /* Windows returns true if the date is valid but outside the limits set */
220 if (!DATETIME_IsDateInValidRange(infoPtr
, systime
))
223 infoPtr
->dateValid
= TRUE
;
224 infoPtr
->date
= *systime
;
225 /* always store a valid day of week */
226 MONTHCAL_CalculateDayOfWeek(&infoPtr
->date
, TRUE
);
228 SendMessageW (infoPtr
->hMonthCal
, MCM_SETCURSEL
, 0, (LPARAM
)(&infoPtr
->date
));
229 SendMessageW (infoPtr
->hwndCheckbut
, BM_SETCHECK
, BST_CHECKED
, 0);
230 } else if ((infoPtr
->dwStyle
& DTS_SHOWNONE
) && (flag
== GDT_NONE
)) {
231 infoPtr
->dateValid
= FALSE
;
232 SendMessageW (infoPtr
->hwndCheckbut
, BM_SETCHECK
, BST_UNCHECKED
, 0);
237 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
243 * Split up a formattxt in actions.
244 * See ms documentation for the meaning of the letter codes/'specifiers'.
247 * *'dddddd' is handled as 'dddd' plus 'dd'.
248 * *unrecognized formats are strings (here given the type DT_STRING;
249 * start of the string is encoded in lower bits of DT_STRING.
250 * Therefore, 'string' ends finally up as '<show seconds>tring'.
254 DATETIME_UseFormat (DATETIME_INFO
*infoPtr
, LPCWSTR formattxt
)
258 BOOL inside_literal
= FALSE
; /* inside '...' */
259 int *nrFields
= &infoPtr
->nrFields
;
262 infoPtr
->fieldspec
[*nrFields
] = 0;
263 len
= strlenW(allowedformatchars
);
266 for (i
= 0; formattxt
[i
]; i
++) {
267 TRACE ("\n%d %c:", i
, formattxt
[i
]);
268 if (!inside_literal
) {
269 for (j
= 0; j
< len
; j
++) {
270 if (allowedformatchars
[j
]==formattxt
[i
]) {
271 TRACE ("%c[%d,%x]", allowedformatchars
[j
], *nrFields
, infoPtr
->fieldspec
[*nrFields
]);
272 if ((*nrFields
==0) && (infoPtr
->fieldspec
[*nrFields
]==0)) {
273 infoPtr
->fieldspec
[*nrFields
] = (j
<<4) + 1;
276 if (infoPtr
->fieldspec
[*nrFields
] >> 4 != j
) {
278 infoPtr
->fieldspec
[*nrFields
] = (j
<<4) + 1;
281 if ((infoPtr
->fieldspec
[*nrFields
] & 0x0f) == maxrepetition
[j
]) {
283 infoPtr
->fieldspec
[*nrFields
] = (j
<<4) + 1;
286 infoPtr
->fieldspec
[*nrFields
]++;
288 } /* if allowedformatchar */
294 if (formattxt
[i
] == '\'')
296 inside_literal
= !inside_literal
;
300 /* char is not a specifier: handle char like a string */
302 if ((*nrFields
==0) && (infoPtr
->fieldspec
[*nrFields
]==0)) {
303 infoPtr
->fieldspec
[*nrFields
] = DT_STRING
+ k
;
304 infoPtr
->buflen
[*nrFields
] = 0;
305 } else if ((infoPtr
->fieldspec
[*nrFields
] & DT_STRING
) != DT_STRING
) {
307 infoPtr
->fieldspec
[*nrFields
] = DT_STRING
+ k
;
308 infoPtr
->buflen
[*nrFields
] = 0;
310 infoPtr
->textbuf
[k
] = formattxt
[i
];
312 infoPtr
->buflen
[*nrFields
]++;
315 if (*nrFields
== infoPtr
->nrFieldsAllocated
) {
316 FIXME ("out of memory; should reallocate. crash ahead.\n");
322 if (infoPtr
->fieldspec
[*nrFields
] != 0) (*nrFields
)++;
327 DATETIME_SetFormatW (DATETIME_INFO
*infoPtr
, LPCWSTR format
)
329 WCHAR format_buf
[80];
334 if (infoPtr
->dwStyle
& DTS_LONGDATEFORMAT
)
335 format_item
= LOCALE_SLONGDATE
;
336 else if ((infoPtr
->dwStyle
& DTS_TIMEFORMAT
) == DTS_TIMEFORMAT
)
337 format_item
= LOCALE_STIMEFORMAT
;
338 else /* DTS_SHORTDATEFORMAT */
339 format_item
= LOCALE_SSHORTDATE
;
340 GetLocaleInfoW(LOCALE_USER_DEFAULT
, format_item
, format_buf
, sizeof(format_buf
)/sizeof(format_buf
[0]));
344 DATETIME_UseFormat (infoPtr
, format
);
345 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
352 DATETIME_SetFormatA (DATETIME_INFO
*infoPtr
, LPCSTR lpszFormat
)
356 INT len
= MultiByteToWideChar(CP_ACP
, 0, lpszFormat
, -1, NULL
, 0);
357 LPWSTR wstr
= Alloc(len
* sizeof(WCHAR
));
358 if (wstr
) MultiByteToWideChar(CP_ACP
, 0, lpszFormat
, -1, wstr
, len
);
359 retval
= DATETIME_SetFormatW (infoPtr
, wstr
);
364 return DATETIME_SetFormatW (infoPtr
, 0);
370 DATETIME_ReturnTxt (const DATETIME_INFO
*infoPtr
, int count
, LPWSTR result
, int resultSize
)
372 static const WCHAR fmt_dW
[] = { '%', 'd', 0 };
373 static const WCHAR fmt__2dW
[] = { '%', '.', '2', 'd', 0 };
374 static const WCHAR fmt__3sW
[] = { '%', '.', '3', 's', 0 };
375 SYSTEMTIME date
= infoPtr
->date
;
380 TRACE ("%d,%d\n", infoPtr
->nrFields
, count
);
381 if (count
>infoPtr
->nrFields
|| count
< 0) {
382 WARN ("buffer overrun, have %d want %d\n", infoPtr
->nrFields
, count
);
386 if (!infoPtr
->fieldspec
) return;
388 spec
= infoPtr
->fieldspec
[count
];
389 if (spec
& DT_STRING
) {
390 int txtlen
= infoPtr
->buflen
[count
];
392 if (txtlen
> resultSize
)
393 txtlen
= resultSize
- 1;
394 memcpy (result
, infoPtr
->textbuf
+ (spec
&~ DT_STRING
), txtlen
* sizeof(WCHAR
));
396 TRACE ("arg%d=%x->[%s]\n", count
, infoPtr
->fieldspec
[count
], debugstr_w(result
));
406 wsprintfW (result
, fmt_dW
, date
.wDay
);
409 wsprintfW (result
, fmt__2dW
, date
.wDay
);
412 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SABBREVDAYNAME1
+(date
.wDayOfWeek
+6)%7, result
, 4);
413 /*wsprintfW (result,"%.3s",days[date.wDayOfWeek]);*/
416 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SDAYNAME1
+(date
.wDayOfWeek
+6)%7, result
, resultSize
);
419 if (date
.wHour
== 0) {
425 wsprintfW (result
, fmt_dW
, date
.wHour
- (date
.wHour
> 12 ? 12 : 0));
428 if (date
.wHour
== 0) {
434 wsprintfW (result
, fmt__2dW
, date
.wHour
- (date
.wHour
> 12 ? 12 : 0));
437 wsprintfW (result
, fmt_dW
, date
.wHour
);
440 wsprintfW (result
, fmt__2dW
, date
.wHour
);
443 wsprintfW (result
, fmt_dW
, date
.wSecond
);
446 wsprintfW (result
, fmt__2dW
, date
.wSecond
);
449 wsprintfW (result
, fmt_dW
, date
.wMinute
);
452 wsprintfW (result
, fmt__2dW
, date
.wMinute
);
455 wsprintfW (result
, fmt_dW
, date
.wMonth
);
458 wsprintfW (result
, fmt__2dW
, date
.wMonth
);
461 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SMONTHNAME1
+date
.wMonth
-1,
462 buffer
, sizeof(buffer
)/sizeof(buffer
[0]));
463 wsprintfW (result
, fmt__3sW
, buffer
);
466 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SMONTHNAME1
+date
.wMonth
-1,
470 result
[0] = (date
.wHour
< 12 ? 'A' : 'P');
474 result
[0] = (date
.wHour
< 12 ? 'A' : 'P');
479 FIXME ("Not implemented\n");
484 wsprintfW (result
, fmt_dW
, date
.wYear
-10* (int) floor(date
.wYear
/10));
487 wsprintfW (result
, fmt__2dW
, date
.wYear
-100* (int) floor(date
.wYear
/100));
489 case INVALIDFULLYEAR
:
491 wsprintfW (result
, fmt_dW
, date
.wYear
);
495 TRACE ("arg%d=%x->[%s]\n", count
, infoPtr
->fieldspec
[count
], debugstr_w(result
));
498 static int wrap(int val
, int delta
, int minVal
, int maxVal
)
501 if (delta
== INT_MIN
|| val
< minVal
) return maxVal
;
502 if (delta
== INT_MAX
|| val
> maxVal
) return minVal
;
507 DATETIME_IncreaseField (DATETIME_INFO
*infoPtr
, int number
, int delta
)
509 SYSTEMTIME
*date
= &infoPtr
->date
;
514 TRACE ("%d\n", number
);
515 if ((number
> infoPtr
->nrFields
) || (number
< 0)) return;
517 if ((infoPtr
->fieldspec
[number
] & DTHT_DATEFIELD
) == 0) return;
519 switch (infoPtr
->fieldspec
[number
]) {
523 if (delta
== INT_MIN
)
525 else if (delta
== INT_MAX
)
528 date
->wYear
= max(min(date
->wYear
+ delta
, 9999), 1752);
530 if (date
->wDay
> MONTHCAL_MonthLength(date
->wMonth
, date
->wYear
))
531 /* This can happen when moving away from a leap year. */
532 date
->wDay
= MONTHCAL_MonthLength(date
->wMonth
, date
->wYear
);
533 MONTHCAL_CalculateDayOfWeek(date
, TRUE
);
539 date
->wMonth
= wrap(date
->wMonth
, delta
, 1, 12);
540 MONTHCAL_CalculateDayOfWeek(date
, TRUE
);
547 date
->wDay
= wrap(date
->wDay
, delta
, 1, MONTHCAL_MonthLength(date
->wMonth
, date
->wYear
));
548 MONTHCAL_CalculateDayOfWeek(date
, TRUE
);
558 date
->wHour
= wrap(date
->wHour
, delta
, 0, 23);
562 date
->wMinute
= wrap(date
->wMinute
, delta
, 0, 59);
566 date
->wSecond
= wrap(date
->wSecond
, delta
, 0, 59);
569 FIXME ("Not implemented\n");
573 /* FYI: On 1752/9/14 the calendar changed and England and the
574 * American colonies changed to the Gregorian calendar. This change
575 * involved having September 14th follow September 2nd. So no date
576 * algorithm works before that date.
578 if (10000 * date
->wYear
+ 100 * date
->wMonth
+ date
->wDay
< 17520914) {
587 /* Ensure time is within bounds */
588 limits
= SendMessageW (infoPtr
->hMonthCal
, MCM_GETRANGE
, 0, (LPARAM
)range
);
591 if (limits
& (min
? GDTR_MIN
: GDTR_MAX
))
593 int i
= (min
? 0 : 1);
595 if (MONTHCAL_CompareSystemTime(date
, &range
[i
]) == (min
? -1 : 1))
597 date
->wYear
= range
[i
].wYear
;
598 date
->wMonth
= range
[i
].wMonth
;
599 date
->wDayOfWeek
= range
[i
].wDayOfWeek
;
600 date
->wDay
= range
[i
].wDay
;
601 date
->wHour
= range
[i
].wHour
;
602 date
->wMinute
= range
[i
].wMinute
;
603 date
->wSecond
= range
[i
].wSecond
;
604 date
->wMilliseconds
= range
[i
].wMilliseconds
;
610 DATETIME_ReturnFieldWidth (const DATETIME_INFO
*infoPtr
, HDC hdc
, int count
, SHORT
*width
)
612 /* fields are a fixed width, determined by the largest possible string */
613 /* presumably, these widths should be language dependent */
614 static const WCHAR fld_d1W
[] = { '2', 0 };
615 static const WCHAR fld_d2W
[] = { '2', '2', 0 };
616 static const WCHAR fld_d4W
[] = { '2', '2', '2', '2', 0 };
617 static const WCHAR fld_am1
[] = { 'A', 0 };
618 static const WCHAR fld_am2
[] = { 'A', 'M', 0 };
624 TRACE ("%d,%d\n", infoPtr
->nrFields
, count
);
625 if (count
>infoPtr
->nrFields
|| count
< 0) {
626 WARN ("buffer overrun, have %d want %d\n", infoPtr
->nrFields
, count
);
630 if (!infoPtr
->fieldspec
) return;
632 spec
= infoPtr
->fieldspec
[count
];
633 if (spec
& DT_STRING
) {
634 int txtlen
= infoPtr
->buflen
[count
];
638 memcpy (buffer
, infoPtr
->textbuf
+ (spec
&~ DT_STRING
), txtlen
* sizeof(WCHAR
));
651 /* these seem to use a two byte field */
661 case INVALIDFULLYEAR
:
670 static const WCHAR fld_day
[] = {'W','e','d','n','e','s','d','a','y',0};
671 static const WCHAR fld_abbrday
[] = {'W','e','d',0};
672 static const WCHAR fld_mon
[] = {'S','e','p','t','e','m','b','e','r',0};
673 static const WCHAR fld_abbrmon
[] = {'D','e','c',0};
680 /* choose locale data type and fallback string */
684 lctype
= LOCALE_SABBREVDAYNAME1
;
689 lctype
= LOCALE_SDAYNAME1
;
694 lctype
= LOCALE_SABBREVMONTHNAME1
;
697 default: /* FULLMONTH */
699 lctype
= LOCALE_SMONTHNAME1
;
705 for (i
= 0; i
< max_count
; i
++)
707 if(GetLocaleInfoW(LOCALE_USER_DEFAULT
, lctype
+ i
,
708 buffer
, lstrlenW(buffer
)))
710 GetTextExtentPoint32W(hdc
, buffer
, lstrlenW(buffer
), &size
);
711 if (size
.cx
> cx
) cx
= size
.cx
;
713 else /* locale independent fallback on failure */
715 GetTextExtentPoint32W(hdc
, fall
, lstrlenW(fall
), &size
);
734 GetTextExtentPoint32W (hdc
, bufptr
, strlenW(bufptr
), &size
);
739 DATETIME_Refresh (DATETIME_INFO
*infoPtr
, HDC hdc
)
743 if (infoPtr
->dateValid
) {
746 RECT
*rcDraw
= &infoPtr
->rcDraw
;
748 COLORREF oldTextColor
;
749 SHORT fieldWidth
= 0;
750 HFONT oldFont
= SelectObject (hdc
, infoPtr
->hFont
);
751 INT oldBkMode
= SetBkMode (hdc
, TRANSPARENT
);
754 DATETIME_ReturnTxt (infoPtr
, 0, txt
, sizeof(txt
)/sizeof(txt
[0]));
755 GetTextExtentPoint32W (hdc
, txt
, strlenW(txt
), &size
);
756 rcDraw
->bottom
= size
.cy
+ 2;
758 prevright
= infoPtr
->checkbox
.right
= ((infoPtr
->dwStyle
& DTS_SHOWNONE
) ? 18 : 2);
760 for (i
= 0; i
< infoPtr
->nrFields
; i
++) {
761 DATETIME_ReturnTxt (infoPtr
, i
, txt
, sizeof(txt
)/sizeof(txt
[0]));
762 GetTextExtentPoint32W (hdc
, txt
, strlenW(txt
), &size
);
763 DATETIME_ReturnFieldWidth (infoPtr
, hdc
, i
, &fieldWidth
);
764 field
= &infoPtr
->fieldRect
[i
];
765 field
->left
= prevright
;
766 field
->right
= prevright
+ fieldWidth
;
767 field
->top
= rcDraw
->top
;
768 field
->bottom
= rcDraw
->bottom
;
769 prevright
= field
->right
;
771 if (infoPtr
->dwStyle
& WS_DISABLED
)
772 oldTextColor
= SetTextColor (hdc
, comctl32_color
.clrGrayText
);
773 else if ((infoPtr
->haveFocus
) && (i
== infoPtr
->select
)) {
776 /* fill if focused */
777 HBRUSH hbr
= CreateSolidBrush (comctl32_color
.clrActiveCaption
);
779 if (infoPtr
->nCharsEntered
)
781 memcpy(txt
, infoPtr
->charsEntered
, infoPtr
->nCharsEntered
* sizeof(WCHAR
));
782 txt
[infoPtr
->nCharsEntered
] = 0;
783 GetTextExtentPoint32W (hdc
, txt
, strlenW(txt
), &size
);
786 SetRect(&selection
, 0, 0, size
.cx
, size
.cy
);
787 /* center rectangle */
788 OffsetRect(&selection
, (field
->right
+ field
->left
- size
.cx
)/2,
789 (field
->bottom
- size
.cy
)/2);
791 FillRect(hdc
, &selection
, hbr
);
793 oldTextColor
= SetTextColor (hdc
, comctl32_color
.clrWindow
);
796 oldTextColor
= SetTextColor (hdc
, comctl32_color
.clrWindowText
);
798 /* draw the date text using the colour set above */
799 DrawTextW (hdc
, txt
, strlenW(txt
), field
, DT_CENTER
| DT_VCENTER
| DT_SINGLELINE
);
800 SetTextColor (hdc
, oldTextColor
);
802 SetBkMode (hdc
, oldBkMode
);
803 SelectObject (hdc
, oldFont
);
806 if (!(infoPtr
->dwStyle
& DTS_UPDOWN
)) {
807 DrawFrameControl(hdc
, &infoPtr
->calbutton
, DFC_SCROLL
,
808 DFCS_SCROLLDOWN
| (infoPtr
->bCalDepressed
? DFCS_PUSHED
: 0) |
809 (infoPtr
->dwStyle
& WS_DISABLED
? DFCS_INACTIVE
: 0) );
815 DATETIME_HitTest (const DATETIME_INFO
*infoPtr
, POINT pt
)
819 TRACE ("%s\n", wine_dbgstr_point(&pt
));
821 if (PtInRect (&infoPtr
->calbutton
, pt
)) return DTHT_MCPOPUP
;
822 if (PtInRect (&infoPtr
->checkbox
, pt
)) return DTHT_CHECKBOX
;
824 for (i
= 0; i
< infoPtr
->nrFields
; i
++) {
825 if (PtInRect (&infoPtr
->fieldRect
[i
], pt
)) return i
;
831 /* Returns index of the nearest preceding date field from given,
832 or -1 if none was found */
833 static int DATETIME_GetPrevDateField(const DATETIME_INFO
*infoPtr
, int i
)
835 for(--i
; i
>= 0; i
--)
837 if (infoPtr
->fieldspec
[i
] & DTHT_DATEFIELD
) return i
;
843 DATETIME_ApplySelectedField (DATETIME_INFO
*infoPtr
)
845 int fieldNum
= infoPtr
->select
& DTHT_DATEFIELD
;
847 BOOL clamp_day
= FALSE
;
848 SYSTEMTIME date
= infoPtr
->date
;
851 if (infoPtr
->select
== -1 || infoPtr
->nCharsEntered
== 0)
854 if ((infoPtr
->fieldspec
[fieldNum
] == ONELETTERAMPM
) ||
855 (infoPtr
->fieldspec
[fieldNum
] == TWOLETTERAMPM
))
856 val
= infoPtr
->charsEntered
[0];
858 for (i
=0; i
<infoPtr
->nCharsEntered
; i
++)
859 val
= val
* 10 + infoPtr
->charsEntered
[i
] - '0';
862 infoPtr
->nCharsEntered
= 0;
864 switch (infoPtr
->fieldspec
[fieldNum
]) {
867 oldyear
= date
.wYear
;
868 date
.wYear
= date
.wYear
- (date
.wYear
%100) + val
;
870 if (DATETIME_IsDateInValidRange(infoPtr
, &date
))
873 date
.wYear
= oldyear
;
876 case INVALIDFULLYEAR
:
878 oldyear
= date
.wYear
;
881 if (DATETIME_IsDateInValidRange(infoPtr
, &date
))
884 date
.wYear
= oldyear
;
904 if (date
.wHour
>= 12) /* preserve current AM/PM state */
905 date
.wHour
= (val
== 12 ? 12 : val
+ 12);
907 date
.wHour
= (val
== 12 ? 0 : val
);
924 if (val
== 'a' || val
== 'A') {
925 if (date
.wHour
>= 12)
927 } else if (val
== 'p' || val
== 'P') {
934 if (clamp_day
&& date
.wDay
> MONTHCAL_MonthLength(date
.wMonth
, date
.wYear
))
935 date
.wDay
= MONTHCAL_MonthLength(date
.wMonth
, date
.wYear
);
937 if (DATETIME_SetSystemTime(infoPtr
, GDT_VALID
, &date
))
938 DATETIME_SendDateTimeChangeNotify (infoPtr
);
942 DATETIME_SetSelectedField (DATETIME_INFO
*infoPtr
, int select
)
944 DATETIME_ApplySelectedField(infoPtr
);
946 infoPtr
->select
= select
;
947 infoPtr
->nCharsEntered
= 0;
951 DATETIME_LButtonDown (DATETIME_INFO
*infoPtr
, INT x
, INT y
)
958 new = DATETIME_HitTest (infoPtr
, pt
);
960 SetFocus(infoPtr
->hwndSelf
);
962 if (!(new & DTHT_NODATEMASK
) || (new == DTHT_NONE
))
964 if (new == DTHT_NONE
)
965 new = infoPtr
->nrFields
- 1;
968 /* hitting string part moves selection to next date field to left */
969 if (infoPtr
->fieldspec
[new] & DT_STRING
)
971 new = DATETIME_GetPrevDateField(infoPtr
, new);
972 if (new == -1) return 0;
974 /* never select full day of week */
975 if (infoPtr
->fieldspec
[new] == FULLDAY
) return 0;
979 DATETIME_SetSelectedField(infoPtr
, new);
981 if (infoPtr
->select
== DTHT_MCPOPUP
) {
984 SendMessageW(infoPtr
->hMonthCal
, MCM_GETMINREQRECT
, 0, (LPARAM
)&rcMonthCal
);
986 /* FIXME: button actually is only depressed during dropdown of the */
987 /* calendar control and when the mouse is over the button window */
988 infoPtr
->bCalDepressed
= TRUE
;
990 /* recalculate the position of the monthcal popup */
991 if(infoPtr
->dwStyle
& DTS_RIGHTALIGN
)
992 pos
.x
= infoPtr
->calbutton
.left
- (rcMonthCal
.right
- rcMonthCal
.left
);
994 /* FIXME: this should be after the area reserved for the checkbox */
995 pos
.x
= infoPtr
->rcDraw
.left
;
997 pos
.y
= infoPtr
->rcClient
.bottom
;
998 OffsetRect( &rcMonthCal
, pos
.x
, pos
.y
);
999 MapWindowPoints( infoPtr
->hwndSelf
, 0, (POINT
*)&rcMonthCal
, 2 );
1000 SetWindowPos(infoPtr
->hMonthCal
, 0, rcMonthCal
.left
, rcMonthCal
.top
,
1001 rcMonthCal
.right
- rcMonthCal
.left
, rcMonthCal
.bottom
- rcMonthCal
.top
, 0);
1003 if(IsWindowVisible(infoPtr
->hMonthCal
)) {
1004 ShowWindow(infoPtr
->hMonthCal
, SW_HIDE
);
1005 infoPtr
->bDropdownEnabled
= FALSE
;
1006 DATETIME_SendSimpleNotify (infoPtr
, DTN_CLOSEUP
);
1008 const SYSTEMTIME
*lprgSysTimeArray
= &infoPtr
->date
;
1009 TRACE("update calendar %04d/%02d/%02d\n",
1010 lprgSysTimeArray
->wYear
, lprgSysTimeArray
->wMonth
, lprgSysTimeArray
->wDay
);
1011 SendMessageW(infoPtr
->hMonthCal
, MCM_SETCURSEL
, 0, (LPARAM
)(&infoPtr
->date
));
1013 if (infoPtr
->bDropdownEnabled
) {
1014 ShowWindow(infoPtr
->hMonthCal
, SW_SHOW
);
1015 DATETIME_SendSimpleNotify (infoPtr
, DTN_DROPDOWN
);
1017 infoPtr
->bDropdownEnabled
= TRUE
;
1020 TRACE ("dt:%p mc:%p mc parent:%p, desktop:%p\n",
1021 infoPtr
->hwndSelf
, infoPtr
->hMonthCal
, infoPtr
->hwndNotify
, GetDesktopWindow ());
1024 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1031 DATETIME_LButtonUp (DATETIME_INFO
*infoPtr
)
1033 if(infoPtr
->bCalDepressed
) {
1034 infoPtr
->bCalDepressed
= FALSE
;
1035 InvalidateRect(infoPtr
->hwndSelf
, &(infoPtr
->calbutton
), TRUE
);
1043 DATETIME_Paint (DATETIME_INFO
*infoPtr
, HDC hdc
)
1047 hdc
= BeginPaint (infoPtr
->hwndSelf
, &ps
);
1048 DATETIME_Refresh (infoPtr
, hdc
);
1049 EndPaint (infoPtr
->hwndSelf
, &ps
);
1051 DATETIME_Refresh (infoPtr
, hdc
);
1054 /* Not a click on the dropdown box, enabled it */
1055 infoPtr
->bDropdownEnabled
= TRUE
;
1062 DATETIME_Button_Command (DATETIME_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
1064 if( HIWORD(wParam
) == BN_CLICKED
) {
1065 DWORD state
= SendMessageW((HWND
)lParam
, BM_GETCHECK
, 0, 0);
1066 infoPtr
->dateValid
= (state
== BST_CHECKED
);
1067 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1075 DATETIME_Command (DATETIME_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
1077 TRACE("hwndbutton = %p\n", infoPtr
->hwndCheckbut
);
1078 if(infoPtr
->hwndCheckbut
== (HWND
)lParam
)
1079 return DATETIME_Button_Command(infoPtr
, wParam
, lParam
);
1085 DATETIME_Enable (DATETIME_INFO
*infoPtr
, BOOL bEnable
)
1087 TRACE("%p %s\n", infoPtr
, bEnable
? "TRUE" : "FALSE");
1089 infoPtr
->dwStyle
&= ~WS_DISABLED
;
1091 infoPtr
->dwStyle
|= WS_DISABLED
;
1093 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1100 DATETIME_EraseBackground (const DATETIME_INFO
*infoPtr
, HDC hdc
)
1102 HBRUSH hBrush
, hSolidBrush
= NULL
;
1105 if (infoPtr
->dwStyle
& WS_DISABLED
)
1106 hBrush
= hSolidBrush
= CreateSolidBrush(comctl32_color
.clrBtnFace
);
1109 hBrush
= (HBRUSH
)SendMessageW(infoPtr
->hwndNotify
, WM_CTLCOLOREDIT
,
1110 (WPARAM
)hdc
, (LPARAM
)infoPtr
->hwndSelf
);
1112 hBrush
= hSolidBrush
= CreateSolidBrush(comctl32_color
.clrWindow
);
1115 GetClientRect (infoPtr
->hwndSelf
, &rc
);
1117 FillRect (hdc
, &rc
, hBrush
);
1120 DeleteObject(hSolidBrush
);
1127 DATETIME_Notify (DATETIME_INFO
*infoPtr
, const NMHDR
*lpnmh
)
1129 TRACE ("Got notification %x from %p\n", lpnmh
->code
, lpnmh
->hwndFrom
);
1130 TRACE ("info: %p %p %p\n", infoPtr
->hwndSelf
, infoPtr
->hMonthCal
, infoPtr
->hUpdown
);
1132 if (lpnmh
->code
== MCN_SELECT
) {
1133 ShowWindow(infoPtr
->hMonthCal
, SW_HIDE
);
1134 infoPtr
->dateValid
= TRUE
;
1135 SendMessageW (infoPtr
->hMonthCal
, MCM_GETCURSEL
, 0, (LPARAM
)&infoPtr
->date
);
1136 TRACE("got from calendar %04d/%02d/%02d day of week %d\n",
1137 infoPtr
->date
.wYear
, infoPtr
->date
.wMonth
, infoPtr
->date
.wDay
, infoPtr
->date
.wDayOfWeek
);
1138 SendMessageW (infoPtr
->hwndCheckbut
, BM_SETCHECK
, BST_CHECKED
, 0);
1139 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1140 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1141 DATETIME_SendSimpleNotify(infoPtr
, DTN_CLOSEUP
);
1143 if ((lpnmh
->hwndFrom
== infoPtr
->hUpdown
) && (lpnmh
->code
== UDN_DELTAPOS
)) {
1144 const NM_UPDOWN
*lpnmud
= (const NM_UPDOWN
*)lpnmh
;
1145 TRACE("Delta pos %d\n", lpnmud
->iDelta
);
1146 infoPtr
->pendingUpdown
= lpnmud
->iDelta
;
1153 DATETIME_KeyDown (DATETIME_INFO
*infoPtr
, DWORD vkCode
)
1155 int fieldNum
= infoPtr
->select
& DTHT_DATEFIELD
;
1159 if (!(infoPtr
->haveFocus
)) return 0;
1160 if ((fieldNum
==0) && (infoPtr
->select
)) return 0;
1162 if (infoPtr
->select
& FORMATCALLMASK
) {
1163 FIXME ("Callbacks not implemented yet\n");
1169 infoPtr
->nCharsEntered
= 0;
1170 DATETIME_IncreaseField (infoPtr
, fieldNum
, 1);
1171 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1175 infoPtr
->nCharsEntered
= 0;
1176 DATETIME_IncreaseField (infoPtr
, fieldNum
, -1);
1177 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1180 infoPtr
->nCharsEntered
= 0;
1181 DATETIME_IncreaseField (infoPtr
, fieldNum
, INT_MIN
);
1182 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1185 infoPtr
->nCharsEntered
= 0;
1186 DATETIME_IncreaseField (infoPtr
, fieldNum
, INT_MAX
);
1187 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1190 new = infoPtr
->select
;
1198 } while ((infoPtr
->fieldspec
[new] & DT_STRING
) && (wrap
<2));
1199 if (new != infoPtr
->select
)
1200 DATETIME_SetSelectedField(infoPtr
, new);
1203 new = infoPtr
->select
;
1206 if (new==infoPtr
->nrFields
) {
1210 } while ((infoPtr
->fieldspec
[new] & DT_STRING
) && (wrap
<2));
1211 if (new != infoPtr
->select
)
1212 DATETIME_SetSelectedField(infoPtr
, new);
1216 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1223 DATETIME_Char (DATETIME_INFO
*infoPtr
, WPARAM vkCode
)
1225 int fieldNum
, fieldSpec
;
1227 fieldNum
= infoPtr
->select
& DTHT_DATEFIELD
;
1228 fieldSpec
= infoPtr
->fieldspec
[fieldNum
];
1230 if (fieldSpec
== ONELETTERAMPM
|| fieldSpec
== TWOLETTERAMPM
) {
1231 infoPtr
->charsEntered
[0] = vkCode
;
1232 infoPtr
->nCharsEntered
= 1;
1234 DATETIME_ApplySelectedField(infoPtr
);
1235 } else if (vkCode
>= '0' && vkCode
<= '9') {
1238 infoPtr
->charsEntered
[infoPtr
->nCharsEntered
++] = vkCode
;
1240 if (fieldSpec
== INVALIDFULLYEAR
|| fieldSpec
== FULLYEAR
)
1245 if ((fieldSpec
== ONEDIGIT12HOUR
||
1246 fieldSpec
== TWODIGIT12HOUR
||
1247 fieldSpec
== ONEDIGIT24HOUR
||
1248 fieldSpec
== TWODIGIT24HOUR
) &&
1249 (infoPtr
->nCharsEntered
== 1))
1255 if (maxChars
== infoPtr
->nCharsEntered
)
1256 DATETIME_ApplySelectedField(infoPtr
);
1264 DATETIME_VScroll (DATETIME_INFO
*infoPtr
, WORD wScroll
)
1266 int fieldNum
= infoPtr
->select
& DTHT_DATEFIELD
;
1268 if ((SHORT
)LOWORD(wScroll
) != SB_THUMBPOSITION
) return 0;
1269 if (!(infoPtr
->haveFocus
)) return 0;
1270 if ((fieldNum
==0) && (infoPtr
->select
)) return 0;
1272 if (infoPtr
->pendingUpdown
>= 0) {
1273 DATETIME_IncreaseField (infoPtr
, fieldNum
, 1);
1274 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1277 DATETIME_IncreaseField (infoPtr
, fieldNum
, -1);
1278 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1281 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1288 DATETIME_KillFocus (DATETIME_INFO
*infoPtr
, HWND lostFocus
)
1290 TRACE("lost focus to %p\n", lostFocus
);
1292 if (infoPtr
->haveFocus
) {
1293 DATETIME_SendSimpleNotify (infoPtr
, NM_KILLFOCUS
);
1294 infoPtr
->haveFocus
= 0;
1295 DATETIME_SetSelectedField (infoPtr
, -1);
1298 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
1305 DATETIME_NCCreate (HWND hwnd
, const CREATESTRUCTW
*lpcs
)
1307 DWORD dwExStyle
= GetWindowLongW(hwnd
, GWL_EXSTYLE
);
1308 /* force control to have client edge */
1309 dwExStyle
|= WS_EX_CLIENTEDGE
;
1310 SetWindowLongW(hwnd
, GWL_EXSTYLE
, dwExStyle
);
1312 return DefWindowProcW(hwnd
, WM_NCCREATE
, 0, (LPARAM
)lpcs
);
1317 DATETIME_SetFocus (DATETIME_INFO
*infoPtr
, HWND lostFocus
)
1319 TRACE("got focus from %p\n", lostFocus
);
1321 /* if monthcal is open and it loses focus, close monthcal */
1322 if (infoPtr
->hMonthCal
&& (lostFocus
== infoPtr
->hMonthCal
) &&
1323 IsWindowVisible(infoPtr
->hMonthCal
))
1325 ShowWindow(infoPtr
->hMonthCal
, SW_HIDE
);
1326 DATETIME_SendSimpleNotify(infoPtr
, DTN_CLOSEUP
);
1327 /* note: this get triggered even if monthcal loses focus to a dropdown
1328 * box click, which occurs without an intermediate WM_PAINT call
1330 infoPtr
->bDropdownEnabled
= FALSE
;
1334 if (infoPtr
->haveFocus
== 0) {
1335 DATETIME_SendSimpleNotify (infoPtr
, NM_SETFOCUS
);
1336 infoPtr
->haveFocus
= DTHT_GOTFOCUS
;
1339 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1346 DATETIME_SendDateTimeChangeNotify (const DATETIME_INFO
*infoPtr
)
1348 NMDATETIMECHANGE dtdtc
;
1350 dtdtc
.nmhdr
.hwndFrom
= infoPtr
->hwndSelf
;
1351 dtdtc
.nmhdr
.idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1352 dtdtc
.nmhdr
.code
= DTN_DATETIMECHANGE
;
1354 dtdtc
.dwFlags
= infoPtr
->dateValid
? GDT_VALID
: GDT_NONE
;
1356 dtdtc
.st
= infoPtr
->date
;
1357 return (BOOL
) SendMessageW (infoPtr
->hwndNotify
, WM_NOTIFY
,
1358 dtdtc
.nmhdr
.idFrom
, (LPARAM
)&dtdtc
);
1363 DATETIME_SendSimpleNotify (const DATETIME_INFO
*infoPtr
, UINT code
)
1367 TRACE("%x\n", code
);
1368 nmhdr
.hwndFrom
= infoPtr
->hwndSelf
;
1369 nmhdr
.idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1372 return (BOOL
) SendMessageW (infoPtr
->hwndNotify
, WM_NOTIFY
,
1373 nmhdr
.idFrom
, (LPARAM
)&nmhdr
);
1377 DATETIME_Size (DATETIME_INFO
*infoPtr
, INT width
, INT height
)
1380 infoPtr
->rcClient
.bottom
= height
;
1381 infoPtr
->rcClient
.right
= width
;
1383 TRACE("Height=%d, Width=%d\n", infoPtr
->rcClient
.bottom
, infoPtr
->rcClient
.right
);
1385 infoPtr
->rcDraw
= infoPtr
->rcClient
;
1387 if (infoPtr
->dwStyle
& DTS_UPDOWN
) {
1388 SetWindowPos(infoPtr
->hUpdown
, NULL
,
1389 infoPtr
->rcClient
.right
-14, 0,
1390 15, infoPtr
->rcClient
.bottom
- infoPtr
->rcClient
.top
,
1391 SWP_NOACTIVATE
| SWP_NOZORDER
);
1394 /* set the size of the button that drops the calendar down */
1395 /* FIXME: account for style that allows button on left side */
1396 infoPtr
->calbutton
.top
= infoPtr
->rcDraw
.top
;
1397 infoPtr
->calbutton
.bottom
= infoPtr
->rcDraw
.bottom
;
1398 infoPtr
->calbutton
.left
= infoPtr
->rcDraw
.right
-15;
1399 infoPtr
->calbutton
.right
= infoPtr
->rcDraw
.right
;
1402 /* set enable/disable button size for show none style being enabled */
1403 /* FIXME: these dimensions are completely incorrect */
1404 infoPtr
->checkbox
.top
= infoPtr
->rcDraw
.top
;
1405 infoPtr
->checkbox
.bottom
= infoPtr
->rcDraw
.bottom
;
1406 infoPtr
->checkbox
.left
= infoPtr
->rcDraw
.left
;
1407 infoPtr
->checkbox
.right
= infoPtr
->rcDraw
.left
+ 10;
1409 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1415 DATETIME_StyleChanging(DATETIME_INFO
*infoPtr
, WPARAM wStyleType
, STYLESTRUCT
*lpss
)
1417 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
1418 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
1420 /* block DTS_SHOWNONE change */
1421 if ((lpss
->styleNew
^ lpss
->styleOld
) & DTS_SHOWNONE
)
1423 if (lpss
->styleOld
& DTS_SHOWNONE
)
1424 lpss
->styleNew
|= DTS_SHOWNONE
;
1426 lpss
->styleNew
&= ~DTS_SHOWNONE
;
1433 DATETIME_StyleChanged(DATETIME_INFO
*infoPtr
, WPARAM wStyleType
, const STYLESTRUCT
*lpss
)
1435 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
1436 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
1438 if (wStyleType
!= GWL_STYLE
) return 0;
1440 infoPtr
->dwStyle
= lpss
->styleNew
;
1442 if ( !(lpss
->styleOld
& DTS_SHOWNONE
) && (lpss
->styleNew
& DTS_SHOWNONE
) ) {
1443 infoPtr
->hwndCheckbut
= CreateWindowExW (0, WC_BUTTONW
, 0, WS_CHILD
| WS_VISIBLE
| BS_AUTOCHECKBOX
,
1444 2, 2, 13, 13, infoPtr
->hwndSelf
, 0,
1445 (HINSTANCE
)GetWindowLongPtrW (infoPtr
->hwndSelf
, GWLP_HINSTANCE
), 0);
1446 SendMessageW (infoPtr
->hwndCheckbut
, BM_SETCHECK
, infoPtr
->dateValid
? 1 : 0, 0);
1448 if ( (lpss
->styleOld
& DTS_SHOWNONE
) && !(lpss
->styleNew
& DTS_SHOWNONE
) ) {
1449 DestroyWindow(infoPtr
->hwndCheckbut
);
1450 infoPtr
->hwndCheckbut
= 0;
1452 if ( !(lpss
->styleOld
& DTS_UPDOWN
) && (lpss
->styleNew
& DTS_UPDOWN
) ) {
1453 infoPtr
->hUpdown
= CreateUpDownControl (WS_CHILD
| WS_BORDER
| WS_VISIBLE
, 120, 1, 20, 20,
1454 infoPtr
->hwndSelf
, 1, 0, 0, UD_MAXVAL
, UD_MINVAL
, 0);
1456 if ( (lpss
->styleOld
& DTS_UPDOWN
) && !(lpss
->styleNew
& DTS_UPDOWN
) ) {
1457 DestroyWindow(infoPtr
->hUpdown
);
1458 infoPtr
->hUpdown
= 0;
1461 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1467 DATETIME_SetFont (DATETIME_INFO
*infoPtr
, HFONT font
, BOOL repaint
)
1469 infoPtr
->hFont
= font
;
1470 if (repaint
) InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1476 DATETIME_Create (HWND hwnd
, const CREATESTRUCTW
*lpcs
)
1478 DATETIME_INFO
*infoPtr
= Alloc (sizeof(DATETIME_INFO
));
1479 STYLESTRUCT ss
= { 0, lpcs
->style
};
1481 if (!infoPtr
) return -1;
1483 infoPtr
->hwndSelf
= hwnd
;
1484 infoPtr
->dwStyle
= lpcs
->style
;
1486 infoPtr
->nrFieldsAllocated
= 32;
1487 infoPtr
->fieldspec
= Alloc (infoPtr
->nrFieldsAllocated
* sizeof(int));
1488 infoPtr
->fieldRect
= Alloc (infoPtr
->nrFieldsAllocated
* sizeof(RECT
));
1489 infoPtr
->buflen
= Alloc (infoPtr
->nrFieldsAllocated
* sizeof(int));
1490 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
1491 infoPtr
->select
= -1; /* initially, nothing is selected */
1492 infoPtr
->bDropdownEnabled
= TRUE
;
1494 DATETIME_StyleChanged(infoPtr
, GWL_STYLE
, &ss
);
1495 DATETIME_SetFormatW (infoPtr
, 0);
1497 /* create the monthcal control */
1498 infoPtr
->hMonthCal
= CreateWindowExW (0, MONTHCAL_CLASSW
, 0, WS_BORDER
| WS_POPUP
| WS_CLIPSIBLINGS
,
1499 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, 0, 0);
1501 /* initialize info structure */
1502 GetLocalTime (&infoPtr
->date
);
1503 infoPtr
->dateValid
= TRUE
;
1504 infoPtr
->hFont
= GetStockObject(DEFAULT_GUI_FONT
);
1506 SetWindowLongPtrW (hwnd
, 0, (DWORD_PTR
)infoPtr
);
1514 DATETIME_Destroy (DATETIME_INFO
*infoPtr
)
1516 if (infoPtr
->hwndCheckbut
)
1517 DestroyWindow(infoPtr
->hwndCheckbut
);
1518 if (infoPtr
->hUpdown
)
1519 DestroyWindow(infoPtr
->hUpdown
);
1520 if (infoPtr
->hMonthCal
)
1521 DestroyWindow(infoPtr
->hMonthCal
);
1522 SetWindowLongPtrW( infoPtr
->hwndSelf
, 0, 0 ); /* clear infoPtr */
1523 Free (infoPtr
->buflen
);
1524 Free (infoPtr
->fieldRect
);
1525 Free (infoPtr
->fieldspec
);
1532 DATETIME_GetText (const DATETIME_INFO
*infoPtr
, INT count
, LPWSTR dst
)
1537 if (!dst
|| (count
<= 0)) return 0;
1540 for (i
= 0; i
< infoPtr
->nrFields
; i
++)
1542 DATETIME_ReturnTxt(infoPtr
, i
, buf
, sizeof(buf
)/sizeof(buf
[0]));
1543 if ((strlenW(dst
) + strlenW(buf
)) < count
)
1547 return strlenW(dst
);
1551 static LRESULT WINAPI
1552 DATETIME_WindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1554 DATETIME_INFO
*infoPtr
= ((DATETIME_INFO
*)GetWindowLongPtrW (hwnd
, 0));
1556 TRACE ("%x, %lx, %lx\n", uMsg
, wParam
, lParam
);
1558 if (!infoPtr
&& (uMsg
!= WM_CREATE
) && (uMsg
!= WM_NCCREATE
))
1559 return DefWindowProcW( hwnd
, uMsg
, wParam
, lParam
);
1563 case DTM_GETSYSTEMTIME
:
1564 return DATETIME_GetSystemTime (infoPtr
, (SYSTEMTIME
*) lParam
);
1566 case DTM_SETSYSTEMTIME
:
1567 return DATETIME_SetSystemTime (infoPtr
, wParam
, (SYSTEMTIME
*) lParam
);
1570 return SendMessageW (infoPtr
->hMonthCal
, MCM_GETRANGE
, wParam
, lParam
);
1573 return SendMessageW (infoPtr
->hMonthCal
, MCM_SETRANGE
, wParam
, lParam
);
1575 case DTM_SETFORMATA
:
1576 return DATETIME_SetFormatA (infoPtr
, (LPCSTR
)lParam
);
1578 case DTM_SETFORMATW
:
1579 return DATETIME_SetFormatW (infoPtr
, (LPCWSTR
)lParam
);
1581 case DTM_GETMONTHCAL
:
1582 return (LRESULT
)infoPtr
->hMonthCal
;
1584 case DTM_SETMCCOLOR
:
1585 return SendMessageW (infoPtr
->hMonthCal
, MCM_SETCOLOR
, wParam
, lParam
);
1587 case DTM_GETMCCOLOR
:
1588 return SendMessageW (infoPtr
->hMonthCal
, MCM_GETCOLOR
, wParam
, 0);
1591 return SendMessageW (infoPtr
->hMonthCal
, WM_SETFONT
, wParam
, lParam
);
1594 return SendMessageW (infoPtr
->hMonthCal
, WM_GETFONT
, wParam
, lParam
);
1597 return DATETIME_Notify (infoPtr
, (LPNMHDR
)lParam
);
1600 return DATETIME_Enable (infoPtr
, (BOOL
)wParam
);
1603 return DATETIME_EraseBackground (infoPtr
, (HDC
)wParam
);
1606 return DLGC_WANTARROWS
| DLGC_WANTCHARS
;
1608 case WM_PRINTCLIENT
:
1610 return DATETIME_Paint (infoPtr
, (HDC
)wParam
);
1613 return DATETIME_KeyDown (infoPtr
, wParam
);
1616 return DATETIME_Char (infoPtr
, wParam
);
1619 return DATETIME_KillFocus (infoPtr
, (HWND
)wParam
);
1622 return DATETIME_NCCreate (hwnd
, (LPCREATESTRUCTW
)lParam
);
1625 return DATETIME_SetFocus (infoPtr
, (HWND
)wParam
);
1628 return DATETIME_Size (infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
1630 case WM_LBUTTONDOWN
:
1631 return DATETIME_LButtonDown (infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
1634 return DATETIME_LButtonUp (infoPtr
);
1637 return DATETIME_VScroll (infoPtr
, (WORD
)wParam
);
1640 return DATETIME_Create (hwnd
, (LPCREATESTRUCTW
)lParam
);
1643 return DATETIME_Destroy (infoPtr
);
1646 return DATETIME_Command (infoPtr
, wParam
, lParam
);
1648 case WM_STYLECHANGING
:
1649 return DATETIME_StyleChanging(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
1651 case WM_STYLECHANGED
:
1652 return DATETIME_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
1655 return DATETIME_SetFont(infoPtr
, (HFONT
)wParam
, (BOOL
)lParam
);
1658 return (LRESULT
) infoPtr
->hFont
;
1661 return (LRESULT
) DATETIME_GetText(infoPtr
, wParam
, (LPWSTR
)lParam
);
1667 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
1668 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
1669 uMsg
, wParam
, lParam
);
1670 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
1676 DATETIME_Register (void)
1680 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
1681 wndClass
.style
= CS_GLOBALCLASS
;
1682 wndClass
.lpfnWndProc
= DATETIME_WindowProc
;
1683 wndClass
.cbClsExtra
= 0;
1684 wndClass
.cbWndExtra
= sizeof(DATETIME_INFO
*);
1685 wndClass
.hCursor
= LoadCursorW (0, (LPCWSTR
)IDC_ARROW
);
1686 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
1687 wndClass
.lpszClassName
= DATETIMEPICK_CLASSW
;
1689 RegisterClassW (&wndClass
);
1694 DATETIME_Unregister (void)
1696 UnregisterClassW (DATETIMEPICK_CLASSW
, NULL
);