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 0;
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
) == FALSE
)
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
);
788 selection
.right
= size
.cx
;
789 selection
.bottom
= size
.cy
;
790 /* center rectangle */
791 OffsetRect(&selection
, (field
->right
+ field
->left
- size
.cx
)/2,
792 (field
->bottom
- size
.cy
)/2);
794 FillRect(hdc
, &selection
, hbr
);
796 oldTextColor
= SetTextColor (hdc
, comctl32_color
.clrWindow
);
799 oldTextColor
= SetTextColor (hdc
, comctl32_color
.clrWindowText
);
801 /* draw the date text using the colour set above */
802 DrawTextW (hdc
, txt
, strlenW(txt
), field
, DT_CENTER
| DT_VCENTER
| DT_SINGLELINE
);
803 SetTextColor (hdc
, oldTextColor
);
805 SetBkMode (hdc
, oldBkMode
);
806 SelectObject (hdc
, oldFont
);
809 if (!(infoPtr
->dwStyle
& DTS_UPDOWN
)) {
810 DrawFrameControl(hdc
, &infoPtr
->calbutton
, DFC_SCROLL
,
811 DFCS_SCROLLDOWN
| (infoPtr
->bCalDepressed
? DFCS_PUSHED
: 0) |
812 (infoPtr
->dwStyle
& WS_DISABLED
? DFCS_INACTIVE
: 0) );
818 DATETIME_HitTest (const DATETIME_INFO
*infoPtr
, POINT pt
)
822 TRACE ("%d, %d\n", pt
.x
, pt
.y
);
824 if (PtInRect (&infoPtr
->calbutton
, pt
)) return DTHT_MCPOPUP
;
825 if (PtInRect (&infoPtr
->checkbox
, pt
)) return DTHT_CHECKBOX
;
827 for (i
= 0; i
< infoPtr
->nrFields
; i
++) {
828 if (PtInRect (&infoPtr
->fieldRect
[i
], pt
)) return i
;
834 /* Returns index of a closest date field from given counting to left
835 or -1 if there's no such field at left */
836 static int DATETIME_GetPrevDateField(const DATETIME_INFO
*infoPtr
, int i
)
838 for(--i
; i
>= 0; i
--)
840 if (infoPtr
->fieldspec
[i
] & DTHT_DATEFIELD
) return i
;
846 DATETIME_ApplySelectedField (DATETIME_INFO
*infoPtr
)
848 int fieldNum
= infoPtr
->select
& DTHT_DATEFIELD
;
849 int i
, val
=0, clamp_day
=0;
850 SYSTEMTIME date
= infoPtr
->date
;
853 if (infoPtr
->select
== -1 || infoPtr
->nCharsEntered
== 0)
856 if ((infoPtr
->fieldspec
[fieldNum
] == ONELETTERAMPM
) ||
857 (infoPtr
->fieldspec
[fieldNum
] == TWOLETTERAMPM
))
858 val
= infoPtr
->charsEntered
[0];
860 for (i
=0; i
<infoPtr
->nCharsEntered
; i
++)
861 val
= val
* 10 + infoPtr
->charsEntered
[i
] - '0';
864 infoPtr
->nCharsEntered
= 0;
866 switch (infoPtr
->fieldspec
[fieldNum
]) {
869 oldyear
= date
.wYear
;
870 date
.wYear
= date
.wYear
- (date
.wYear
%100) + val
;
872 if (DATETIME_IsDateInValidRange(infoPtr
, &date
))
875 date
.wYear
= oldyear
;
878 case INVALIDFULLYEAR
:
880 oldyear
= date
.wYear
;
883 if (DATETIME_IsDateInValidRange(infoPtr
, &date
))
886 date
.wYear
= oldyear
;
906 if (date
.wHour
>= 12) /* preserve current AM/PM state */
907 date
.wHour
= (val
== 12 ? 12 : val
+ 12);
909 date
.wHour
= (val
== 12 ? 0 : val
);
926 if (val
== 'a' || val
== 'A') {
927 if (date
.wHour
>= 12)
929 } else if (val
== 'p' || val
== 'P') {
936 if (clamp_day
&& date
.wDay
> MONTHCAL_MonthLength(date
.wMonth
, date
.wYear
))
937 date
.wDay
= MONTHCAL_MonthLength(date
.wMonth
, date
.wYear
);
939 if (DATETIME_SetSystemTime(infoPtr
, GDT_VALID
, &date
))
940 DATETIME_SendDateTimeChangeNotify (infoPtr
);
944 DATETIME_SetSelectedField (DATETIME_INFO
*infoPtr
, int select
)
946 DATETIME_ApplySelectedField(infoPtr
);
948 infoPtr
->select
= select
;
949 infoPtr
->nCharsEntered
= 0;
953 DATETIME_LButtonDown (DATETIME_INFO
*infoPtr
, INT x
, INT y
)
960 new = DATETIME_HitTest (infoPtr
, pt
);
962 SetFocus(infoPtr
->hwndSelf
);
964 if (!(new & DTHT_NODATEMASK
) || (new == DTHT_NONE
))
966 if (new == DTHT_NONE
)
967 new = infoPtr
->nrFields
- 1;
970 /* hitting string part moves selection to next date field to left */
971 if (infoPtr
->fieldspec
[new] & DT_STRING
)
973 new = DATETIME_GetPrevDateField(infoPtr
, new);
974 if (new == -1) return 0;
976 /* never select full day of week */
977 if (infoPtr
->fieldspec
[new] == FULLDAY
) return 0;
981 DATETIME_SetSelectedField(infoPtr
, new);
983 if (infoPtr
->select
== DTHT_MCPOPUP
) {
986 SendMessageW(infoPtr
->hMonthCal
, MCM_GETMINREQRECT
, 0, (LPARAM
)&rcMonthCal
);
988 /* FIXME: button actually is only depressed during dropdown of the */
989 /* calendar control and when the mouse is over the button window */
990 infoPtr
->bCalDepressed
= TRUE
;
992 /* recalculate the position of the monthcal popup */
993 if(infoPtr
->dwStyle
& DTS_RIGHTALIGN
)
994 pos
.x
= infoPtr
->calbutton
.left
- (rcMonthCal
.right
- rcMonthCal
.left
);
996 /* FIXME: this should be after the area reserved for the checkbox */
997 pos
.x
= infoPtr
->rcDraw
.left
;
999 pos
.y
= infoPtr
->rcClient
.bottom
;
1000 OffsetRect( &rcMonthCal
, pos
.x
, pos
.y
);
1001 MapWindowPoints( infoPtr
->hwndSelf
, 0, (POINT
*)&rcMonthCal
, 2 );
1002 SetWindowPos(infoPtr
->hMonthCal
, 0, rcMonthCal
.left
, rcMonthCal
.top
,
1003 rcMonthCal
.right
- rcMonthCal
.left
, rcMonthCal
.bottom
- rcMonthCal
.top
, 0);
1005 if(IsWindowVisible(infoPtr
->hMonthCal
)) {
1006 ShowWindow(infoPtr
->hMonthCal
, SW_HIDE
);
1007 infoPtr
->bDropdownEnabled
= FALSE
;
1008 DATETIME_SendSimpleNotify (infoPtr
, DTN_CLOSEUP
);
1010 const SYSTEMTIME
*lprgSysTimeArray
= &infoPtr
->date
;
1011 TRACE("update calendar %04d/%02d/%02d\n",
1012 lprgSysTimeArray
->wYear
, lprgSysTimeArray
->wMonth
, lprgSysTimeArray
->wDay
);
1013 SendMessageW(infoPtr
->hMonthCal
, MCM_SETCURSEL
, 0, (LPARAM
)(&infoPtr
->date
));
1015 if (infoPtr
->bDropdownEnabled
) {
1016 ShowWindow(infoPtr
->hMonthCal
, SW_SHOW
);
1017 DATETIME_SendSimpleNotify (infoPtr
, DTN_DROPDOWN
);
1019 infoPtr
->bDropdownEnabled
= TRUE
;
1022 TRACE ("dt:%p mc:%p mc parent:%p, desktop:%p\n",
1023 infoPtr
->hwndSelf
, infoPtr
->hMonthCal
, infoPtr
->hwndNotify
, GetDesktopWindow ());
1026 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1033 DATETIME_LButtonUp (DATETIME_INFO
*infoPtr
)
1035 if(infoPtr
->bCalDepressed
) {
1036 infoPtr
->bCalDepressed
= FALSE
;
1037 InvalidateRect(infoPtr
->hwndSelf
, &(infoPtr
->calbutton
), TRUE
);
1045 DATETIME_Paint (DATETIME_INFO
*infoPtr
, HDC hdc
)
1049 hdc
= BeginPaint (infoPtr
->hwndSelf
, &ps
);
1050 DATETIME_Refresh (infoPtr
, hdc
);
1051 EndPaint (infoPtr
->hwndSelf
, &ps
);
1053 DATETIME_Refresh (infoPtr
, hdc
);
1056 /* Not a click on the dropdown box, enabled it */
1057 infoPtr
->bDropdownEnabled
= TRUE
;
1064 DATETIME_Button_Command (DATETIME_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
1066 if( HIWORD(wParam
) == BN_CLICKED
) {
1067 DWORD state
= SendMessageW((HWND
)lParam
, BM_GETCHECK
, 0, 0);
1068 infoPtr
->dateValid
= (state
== BST_CHECKED
);
1069 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1077 DATETIME_Command (DATETIME_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
1079 TRACE("hwndbutton = %p\n", infoPtr
->hwndCheckbut
);
1080 if(infoPtr
->hwndCheckbut
== (HWND
)lParam
)
1081 return DATETIME_Button_Command(infoPtr
, wParam
, lParam
);
1087 DATETIME_Enable (DATETIME_INFO
*infoPtr
, BOOL bEnable
)
1089 TRACE("%p %s\n", infoPtr
, bEnable
? "TRUE" : "FALSE");
1091 infoPtr
->dwStyle
&= ~WS_DISABLED
;
1093 infoPtr
->dwStyle
|= WS_DISABLED
;
1095 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1102 DATETIME_EraseBackground (const DATETIME_INFO
*infoPtr
, HDC hdc
)
1104 HBRUSH hBrush
, hSolidBrush
= NULL
;
1107 if (infoPtr
->dwStyle
& WS_DISABLED
)
1108 hBrush
= hSolidBrush
= CreateSolidBrush(comctl32_color
.clrBtnFace
);
1111 hBrush
= (HBRUSH
)SendMessageW(infoPtr
->hwndNotify
, WM_CTLCOLOREDIT
,
1112 (WPARAM
)hdc
, (LPARAM
)infoPtr
->hwndSelf
);
1114 hBrush
= hSolidBrush
= CreateSolidBrush(comctl32_color
.clrWindow
);
1117 GetClientRect (infoPtr
->hwndSelf
, &rc
);
1119 FillRect (hdc
, &rc
, hBrush
);
1122 DeleteObject(hSolidBrush
);
1129 DATETIME_Notify (DATETIME_INFO
*infoPtr
, const NMHDR
*lpnmh
)
1131 TRACE ("Got notification %x from %p\n", lpnmh
->code
, lpnmh
->hwndFrom
);
1132 TRACE ("info: %p %p %p\n", infoPtr
->hwndSelf
, infoPtr
->hMonthCal
, infoPtr
->hUpdown
);
1134 if (lpnmh
->code
== MCN_SELECT
) {
1135 ShowWindow(infoPtr
->hMonthCal
, SW_HIDE
);
1136 infoPtr
->dateValid
= TRUE
;
1137 SendMessageW (infoPtr
->hMonthCal
, MCM_GETCURSEL
, 0, (LPARAM
)&infoPtr
->date
);
1138 TRACE("got from calendar %04d/%02d/%02d day of week %d\n",
1139 infoPtr
->date
.wYear
, infoPtr
->date
.wMonth
, infoPtr
->date
.wDay
, infoPtr
->date
.wDayOfWeek
);
1140 SendMessageW (infoPtr
->hwndCheckbut
, BM_SETCHECK
, BST_CHECKED
, 0);
1141 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1142 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1143 DATETIME_SendSimpleNotify(infoPtr
, DTN_CLOSEUP
);
1145 if ((lpnmh
->hwndFrom
== infoPtr
->hUpdown
) && (lpnmh
->code
== UDN_DELTAPOS
)) {
1146 const NM_UPDOWN
*lpnmud
= (const NM_UPDOWN
*)lpnmh
;
1147 TRACE("Delta pos %d\n", lpnmud
->iDelta
);
1148 infoPtr
->pendingUpdown
= lpnmud
->iDelta
;
1155 DATETIME_KeyDown (DATETIME_INFO
*infoPtr
, DWORD vkCode
)
1157 int fieldNum
= infoPtr
->select
& DTHT_DATEFIELD
;
1161 if (!(infoPtr
->haveFocus
)) return 0;
1162 if ((fieldNum
==0) && (infoPtr
->select
)) return 0;
1164 if (infoPtr
->select
& FORMATCALLMASK
) {
1165 FIXME ("Callbacks not implemented yet\n");
1171 infoPtr
->nCharsEntered
= 0;
1172 DATETIME_IncreaseField (infoPtr
, fieldNum
, 1);
1173 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1177 infoPtr
->nCharsEntered
= 0;
1178 DATETIME_IncreaseField (infoPtr
, fieldNum
, -1);
1179 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1182 infoPtr
->nCharsEntered
= 0;
1183 DATETIME_IncreaseField (infoPtr
, fieldNum
, INT_MIN
);
1184 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1187 infoPtr
->nCharsEntered
= 0;
1188 DATETIME_IncreaseField (infoPtr
, fieldNum
, INT_MAX
);
1189 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1192 new = infoPtr
->select
;
1200 } while ((infoPtr
->fieldspec
[new] & DT_STRING
) && (wrap
<2));
1201 if (new != infoPtr
->select
)
1202 DATETIME_SetSelectedField(infoPtr
, new);
1205 new = infoPtr
->select
;
1208 if (new==infoPtr
->nrFields
) {
1212 } while ((infoPtr
->fieldspec
[new] & DT_STRING
) && (wrap
<2));
1213 if (new != infoPtr
->select
)
1214 DATETIME_SetSelectedField(infoPtr
, new);
1218 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1225 DATETIME_Char (DATETIME_INFO
*infoPtr
, WPARAM vkCode
)
1227 int fieldNum
, fieldSpec
;
1229 fieldNum
= infoPtr
->select
& DTHT_DATEFIELD
;
1230 fieldSpec
= infoPtr
->fieldspec
[fieldNum
];
1232 if (fieldSpec
== ONELETTERAMPM
|| fieldSpec
== TWOLETTERAMPM
) {
1233 infoPtr
->charsEntered
[0] = vkCode
;
1234 infoPtr
->nCharsEntered
= 1;
1236 DATETIME_ApplySelectedField(infoPtr
);
1237 } else if (vkCode
>= '0' && vkCode
<= '9') {
1240 infoPtr
->charsEntered
[infoPtr
->nCharsEntered
++] = vkCode
;
1242 if (fieldSpec
== INVALIDFULLYEAR
|| fieldSpec
== FULLYEAR
)
1247 if ((fieldSpec
== ONEDIGIT12HOUR
||
1248 fieldSpec
== TWODIGIT12HOUR
||
1249 fieldSpec
== ONEDIGIT24HOUR
||
1250 fieldSpec
== TWODIGIT24HOUR
) &&
1251 (infoPtr
->nCharsEntered
== 1))
1257 if (maxChars
== infoPtr
->nCharsEntered
)
1258 DATETIME_ApplySelectedField(infoPtr
);
1266 DATETIME_VScroll (DATETIME_INFO
*infoPtr
, WORD wScroll
)
1268 int fieldNum
= infoPtr
->select
& DTHT_DATEFIELD
;
1270 if ((SHORT
)LOWORD(wScroll
) != SB_THUMBPOSITION
) return 0;
1271 if (!(infoPtr
->haveFocus
)) return 0;
1272 if ((fieldNum
==0) && (infoPtr
->select
)) return 0;
1274 if (infoPtr
->pendingUpdown
>= 0) {
1275 DATETIME_IncreaseField (infoPtr
, fieldNum
, 1);
1276 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1279 DATETIME_IncreaseField (infoPtr
, fieldNum
, -1);
1280 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1283 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1290 DATETIME_KillFocus (DATETIME_INFO
*infoPtr
, HWND lostFocus
)
1292 TRACE("lost focus to %p\n", lostFocus
);
1294 if (infoPtr
->haveFocus
) {
1295 DATETIME_SendSimpleNotify (infoPtr
, NM_KILLFOCUS
);
1296 infoPtr
->haveFocus
= 0;
1297 DATETIME_SetSelectedField (infoPtr
, -1);
1300 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
1307 DATETIME_NCCreate (HWND hwnd
, const CREATESTRUCTW
*lpcs
)
1309 DWORD dwExStyle
= GetWindowLongW(hwnd
, GWL_EXSTYLE
);
1310 /* force control to have client edge */
1311 dwExStyle
|= WS_EX_CLIENTEDGE
;
1312 SetWindowLongW(hwnd
, GWL_EXSTYLE
, dwExStyle
);
1314 return DefWindowProcW(hwnd
, WM_NCCREATE
, 0, (LPARAM
)lpcs
);
1319 DATETIME_SetFocus (DATETIME_INFO
*infoPtr
, HWND lostFocus
)
1321 TRACE("got focus from %p\n", lostFocus
);
1323 /* if monthcal is open and it loses focus, close monthcal */
1324 if (infoPtr
->hMonthCal
&& (lostFocus
== infoPtr
->hMonthCal
) &&
1325 IsWindowVisible(infoPtr
->hMonthCal
))
1327 ShowWindow(infoPtr
->hMonthCal
, SW_HIDE
);
1328 DATETIME_SendSimpleNotify(infoPtr
, DTN_CLOSEUP
);
1329 /* note: this get triggered even if monthcal loses focus to a dropdown
1330 * box click, which occurs without an intermediate WM_PAINT call
1332 infoPtr
->bDropdownEnabled
= FALSE
;
1336 if (infoPtr
->haveFocus
== 0) {
1337 DATETIME_SendSimpleNotify (infoPtr
, NM_SETFOCUS
);
1338 infoPtr
->haveFocus
= DTHT_GOTFOCUS
;
1341 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1348 DATETIME_SendDateTimeChangeNotify (const DATETIME_INFO
*infoPtr
)
1350 NMDATETIMECHANGE dtdtc
;
1352 dtdtc
.nmhdr
.hwndFrom
= infoPtr
->hwndSelf
;
1353 dtdtc
.nmhdr
.idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1354 dtdtc
.nmhdr
.code
= DTN_DATETIMECHANGE
;
1356 dtdtc
.dwFlags
= infoPtr
->dateValid
? GDT_VALID
: GDT_NONE
;
1358 dtdtc
.st
= infoPtr
->date
;
1359 return (BOOL
) SendMessageW (infoPtr
->hwndNotify
, WM_NOTIFY
,
1360 dtdtc
.nmhdr
.idFrom
, (LPARAM
)&dtdtc
);
1365 DATETIME_SendSimpleNotify (const DATETIME_INFO
*infoPtr
, UINT code
)
1369 TRACE("%x\n", code
);
1370 nmhdr
.hwndFrom
= infoPtr
->hwndSelf
;
1371 nmhdr
.idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1374 return (BOOL
) SendMessageW (infoPtr
->hwndNotify
, WM_NOTIFY
,
1375 nmhdr
.idFrom
, (LPARAM
)&nmhdr
);
1379 DATETIME_Size (DATETIME_INFO
*infoPtr
, INT width
, INT height
)
1382 infoPtr
->rcClient
.bottom
= height
;
1383 infoPtr
->rcClient
.right
= width
;
1385 TRACE("Height=%d, Width=%d\n", infoPtr
->rcClient
.bottom
, infoPtr
->rcClient
.right
);
1387 infoPtr
->rcDraw
= infoPtr
->rcClient
;
1389 if (infoPtr
->dwStyle
& DTS_UPDOWN
) {
1390 SetWindowPos(infoPtr
->hUpdown
, NULL
,
1391 infoPtr
->rcClient
.right
-14, 0,
1392 15, infoPtr
->rcClient
.bottom
- infoPtr
->rcClient
.top
,
1393 SWP_NOACTIVATE
| SWP_NOZORDER
);
1396 /* set the size of the button that drops the calendar down */
1397 /* FIXME: account for style that allows button on left side */
1398 infoPtr
->calbutton
.top
= infoPtr
->rcDraw
.top
;
1399 infoPtr
->calbutton
.bottom
= infoPtr
->rcDraw
.bottom
;
1400 infoPtr
->calbutton
.left
= infoPtr
->rcDraw
.right
-15;
1401 infoPtr
->calbutton
.right
= infoPtr
->rcDraw
.right
;
1404 /* set enable/disable button size for show none style being enabled */
1405 /* FIXME: these dimensions are completely incorrect */
1406 infoPtr
->checkbox
.top
= infoPtr
->rcDraw
.top
;
1407 infoPtr
->checkbox
.bottom
= infoPtr
->rcDraw
.bottom
;
1408 infoPtr
->checkbox
.left
= infoPtr
->rcDraw
.left
;
1409 infoPtr
->checkbox
.right
= infoPtr
->rcDraw
.left
+ 10;
1411 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1417 DATETIME_StyleChanging(DATETIME_INFO
*infoPtr
, WPARAM wStyleType
, STYLESTRUCT
*lpss
)
1419 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
1420 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
1422 /* block DTS_SHOWNONE change */
1423 if ((lpss
->styleNew
^ lpss
->styleOld
) & DTS_SHOWNONE
)
1425 if (lpss
->styleOld
& DTS_SHOWNONE
)
1426 lpss
->styleNew
|= DTS_SHOWNONE
;
1428 lpss
->styleNew
&= ~DTS_SHOWNONE
;
1435 DATETIME_StyleChanged(DATETIME_INFO
*infoPtr
, WPARAM wStyleType
, const STYLESTRUCT
*lpss
)
1437 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
1438 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
1440 if (wStyleType
!= GWL_STYLE
) return 0;
1442 infoPtr
->dwStyle
= lpss
->styleNew
;
1444 if ( !(lpss
->styleOld
& DTS_SHOWNONE
) && (lpss
->styleNew
& DTS_SHOWNONE
) ) {
1445 infoPtr
->hwndCheckbut
= CreateWindowExW (0, WC_BUTTONW
, 0, WS_CHILD
| WS_VISIBLE
| BS_AUTOCHECKBOX
,
1446 2, 2, 13, 13, infoPtr
->hwndSelf
, 0,
1447 (HINSTANCE
)GetWindowLongPtrW (infoPtr
->hwndSelf
, GWLP_HINSTANCE
), 0);
1448 SendMessageW (infoPtr
->hwndCheckbut
, BM_SETCHECK
, infoPtr
->dateValid
? 1 : 0, 0);
1450 if ( (lpss
->styleOld
& DTS_SHOWNONE
) && !(lpss
->styleNew
& DTS_SHOWNONE
) ) {
1451 DestroyWindow(infoPtr
->hwndCheckbut
);
1452 infoPtr
->hwndCheckbut
= 0;
1454 if ( !(lpss
->styleOld
& DTS_UPDOWN
) && (lpss
->styleNew
& DTS_UPDOWN
) ) {
1455 infoPtr
->hUpdown
= CreateUpDownControl (WS_CHILD
| WS_BORDER
| WS_VISIBLE
, 120, 1, 20, 20,
1456 infoPtr
->hwndSelf
, 1, 0, 0, UD_MAXVAL
, UD_MINVAL
, 0);
1458 if ( (lpss
->styleOld
& DTS_UPDOWN
) && !(lpss
->styleNew
& DTS_UPDOWN
) ) {
1459 DestroyWindow(infoPtr
->hUpdown
);
1460 infoPtr
->hUpdown
= 0;
1463 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1469 DATETIME_SetFont (DATETIME_INFO
*infoPtr
, HFONT font
, BOOL repaint
)
1471 infoPtr
->hFont
= font
;
1472 if (repaint
) InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1478 DATETIME_Create (HWND hwnd
, const CREATESTRUCTW
*lpcs
)
1480 DATETIME_INFO
*infoPtr
= Alloc (sizeof(DATETIME_INFO
));
1481 STYLESTRUCT ss
= { 0, lpcs
->style
};
1483 if (!infoPtr
) return -1;
1485 infoPtr
->hwndSelf
= hwnd
;
1486 infoPtr
->dwStyle
= lpcs
->style
;
1488 infoPtr
->nrFieldsAllocated
= 32;
1489 infoPtr
->fieldspec
= Alloc (infoPtr
->nrFieldsAllocated
* sizeof(int));
1490 infoPtr
->fieldRect
= Alloc (infoPtr
->nrFieldsAllocated
* sizeof(RECT
));
1491 infoPtr
->buflen
= Alloc (infoPtr
->nrFieldsAllocated
* sizeof(int));
1492 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
1493 infoPtr
->select
= -1; /* initially, nothing is selected */
1494 infoPtr
->bDropdownEnabled
= TRUE
;
1496 DATETIME_StyleChanged(infoPtr
, GWL_STYLE
, &ss
);
1497 DATETIME_SetFormatW (infoPtr
, 0);
1499 /* create the monthcal control */
1500 infoPtr
->hMonthCal
= CreateWindowExW (0, MONTHCAL_CLASSW
, 0, WS_BORDER
| WS_POPUP
| WS_CLIPSIBLINGS
,
1501 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, 0, 0);
1503 /* initialize info structure */
1504 GetLocalTime (&infoPtr
->date
);
1505 infoPtr
->dateValid
= TRUE
;
1506 infoPtr
->hFont
= GetStockObject(DEFAULT_GUI_FONT
);
1508 SetWindowLongPtrW (hwnd
, 0, (DWORD_PTR
)infoPtr
);
1516 DATETIME_Destroy (DATETIME_INFO
*infoPtr
)
1518 if (infoPtr
->hwndCheckbut
)
1519 DestroyWindow(infoPtr
->hwndCheckbut
);
1520 if (infoPtr
->hUpdown
)
1521 DestroyWindow(infoPtr
->hUpdown
);
1522 if (infoPtr
->hMonthCal
)
1523 DestroyWindow(infoPtr
->hMonthCal
);
1524 SetWindowLongPtrW( infoPtr
->hwndSelf
, 0, 0 ); /* clear infoPtr */
1525 Free (infoPtr
->buflen
);
1526 Free (infoPtr
->fieldRect
);
1527 Free (infoPtr
->fieldspec
);
1534 DATETIME_GetText (const DATETIME_INFO
*infoPtr
, INT count
, LPWSTR dst
)
1539 if (!dst
|| (count
<= 0)) return 0;
1542 for (i
= 0; i
< infoPtr
->nrFields
; i
++)
1544 DATETIME_ReturnTxt(infoPtr
, i
, buf
, sizeof(buf
)/sizeof(buf
[0]));
1545 if ((strlenW(dst
) + strlenW(buf
)) < count
)
1549 return strlenW(dst
);
1553 static LRESULT WINAPI
1554 DATETIME_WindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1556 DATETIME_INFO
*infoPtr
= ((DATETIME_INFO
*)GetWindowLongPtrW (hwnd
, 0));
1559 TRACE ("%x, %lx, %lx\n", uMsg
, wParam
, lParam
);
1561 if (!infoPtr
&& (uMsg
!= WM_CREATE
) && (uMsg
!= WM_NCCREATE
))
1562 return DefWindowProcW( hwnd
, uMsg
, wParam
, lParam
);
1566 case DTM_GETSYSTEMTIME
:
1567 return DATETIME_GetSystemTime (infoPtr
, (SYSTEMTIME
*) lParam
);
1569 case DTM_SETSYSTEMTIME
:
1570 return DATETIME_SetSystemTime (infoPtr
, wParam
, (SYSTEMTIME
*) lParam
);
1573 ret
= SendMessageW (infoPtr
->hMonthCal
, MCM_GETRANGE
, wParam
, lParam
);
1574 return ret
? ret
: 1; /* bug emulation */
1577 return SendMessageW (infoPtr
->hMonthCal
, MCM_SETRANGE
, wParam
, lParam
);
1579 case DTM_SETFORMATA
:
1580 return DATETIME_SetFormatA (infoPtr
, (LPCSTR
)lParam
);
1582 case DTM_SETFORMATW
:
1583 return DATETIME_SetFormatW (infoPtr
, (LPCWSTR
)lParam
);
1585 case DTM_GETMONTHCAL
:
1586 return (LRESULT
)infoPtr
->hMonthCal
;
1588 case DTM_SETMCCOLOR
:
1589 return SendMessageW (infoPtr
->hMonthCal
, MCM_SETCOLOR
, wParam
, lParam
);
1591 case DTM_GETMCCOLOR
:
1592 return SendMessageW (infoPtr
->hMonthCal
, MCM_GETCOLOR
, wParam
, 0);
1595 return SendMessageW (infoPtr
->hMonthCal
, WM_SETFONT
, wParam
, lParam
);
1598 return SendMessageW (infoPtr
->hMonthCal
, WM_GETFONT
, wParam
, lParam
);
1601 return DATETIME_Notify (infoPtr
, (LPNMHDR
)lParam
);
1604 return DATETIME_Enable (infoPtr
, (BOOL
)wParam
);
1607 return DATETIME_EraseBackground (infoPtr
, (HDC
)wParam
);
1610 return DLGC_WANTARROWS
| DLGC_WANTCHARS
;
1612 case WM_PRINTCLIENT
:
1614 return DATETIME_Paint (infoPtr
, (HDC
)wParam
);
1617 return DATETIME_KeyDown (infoPtr
, wParam
);
1620 return DATETIME_Char (infoPtr
, wParam
);
1623 return DATETIME_KillFocus (infoPtr
, (HWND
)wParam
);
1626 return DATETIME_NCCreate (hwnd
, (LPCREATESTRUCTW
)lParam
);
1629 return DATETIME_SetFocus (infoPtr
, (HWND
)wParam
);
1632 return DATETIME_Size (infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
1634 case WM_LBUTTONDOWN
:
1635 return DATETIME_LButtonDown (infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
1638 return DATETIME_LButtonUp (infoPtr
);
1641 return DATETIME_VScroll (infoPtr
, (WORD
)wParam
);
1644 return DATETIME_Create (hwnd
, (LPCREATESTRUCTW
)lParam
);
1647 return DATETIME_Destroy (infoPtr
);
1650 return DATETIME_Command (infoPtr
, wParam
, lParam
);
1652 case WM_STYLECHANGING
:
1653 return DATETIME_StyleChanging(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
1655 case WM_STYLECHANGED
:
1656 return DATETIME_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
1659 return DATETIME_SetFont(infoPtr
, (HFONT
)wParam
, (BOOL
)lParam
);
1662 return (LRESULT
) infoPtr
->hFont
;
1665 return (LRESULT
) DATETIME_GetText(infoPtr
, wParam
, (LPWSTR
)lParam
);
1671 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
1672 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
1673 uMsg
, wParam
, lParam
);
1674 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
1680 DATETIME_Register (void)
1684 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
1685 wndClass
.style
= CS_GLOBALCLASS
;
1686 wndClass
.lpfnWndProc
= DATETIME_WindowProc
;
1687 wndClass
.cbClsExtra
= 0;
1688 wndClass
.cbWndExtra
= sizeof(DATETIME_INFO
*);
1689 wndClass
.hCursor
= LoadCursorW (0, (LPCWSTR
)IDC_ARROW
);
1690 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
1691 wndClass
.lpszClassName
= DATETIMEPICK_CLASSW
;
1693 RegisterClassW (&wndClass
);
1698 DATETIME_Unregister (void)
1700 UnregisterClassW (DATETIMEPICK_CLASSW
, NULL
);