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 * -- DTS_SHORTDATECENTURYFORMAT
48 #include "wine/debug.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(datetime
);
62 RECT rcClient
; /* rect around the edge of the window */
63 RECT rcDraw
; /* rect inside of the border */
64 RECT checkbox
; /* checkbox allowing the control to be enabled/disabled */
65 RECT calbutton
; /* button that toggles the dropdown of the monthcal control */
66 BOOL bCalDepressed
; /* TRUE = cal button is depressed */
67 BOOL bCalHot
; /* TRUE if calendar button is hovered */
68 BOOL bDropdownEnabled
;
70 WCHAR charsEntered
[4];
73 int nrFieldsAllocated
;
82 } DATETIME_INFO
, *LPDATETIME_INFO
;
84 /* this list of defines is closely related to `allowedformatchars' defined
85 * in datetime.c; the high nibble indicates the `base type' of the format
87 * Do not change without first reading DATETIME_UseFormat.
91 #define DT_END_FORMAT 0
92 #define ONEDIGITDAY 0x01
93 #define TWODIGITDAY 0x02
94 #define THREECHARDAY 0x03
96 #define ONEDIGIT12HOUR 0x11
97 #define TWODIGIT12HOUR 0x12
98 #define ONEDIGIT24HOUR 0x21
99 #define TWODIGIT24HOUR 0x22
100 #define ONEDIGITMINUTE 0x31
101 #define TWODIGITMINUTE 0x32
102 #define ONEDIGITMONTH 0x41
103 #define TWODIGITMONTH 0x42
104 #define THREECHARMONTH 0x43
105 #define FULLMONTH 0x44
106 #define ONEDIGITSECOND 0x51
107 #define TWODIGITSECOND 0x52
108 #define ONELETTERAMPM 0x61
109 #define TWOLETTERAMPM 0x62
110 #define ONEDIGITYEAR 0x71
111 #define TWODIGITYEAR 0x72
112 #define INVALIDFULLYEAR 0x73 /* FIXME - yyy is not valid - we'll treat it as yyyy */
113 #define FULLYEAR 0x74
114 #define FORMATCALLBACK 0x81 /* -> maximum of 0x80 callbacks possible */
115 #define FORMATCALLMASK 0x80
116 #define DT_STRING 0x0100
118 #define DTHT_DATEFIELD 0xff /* for hit-testing */
120 #define DTHT_NONE 0x1000
121 #define DTHT_CHECKBOX 0x2000 /* these should end at '00' , to make */
122 #define DTHT_MCPOPUP 0x3000 /* & DTHT_DATEFIELD 0 when DATETIME_KeyDown */
123 #define DTHT_GOTFOCUS 0x4000 /* tests for date-fields */
124 #define DTHT_NODATEMASK 0xf000 /* to mask check and drop down from others */
126 static BOOL
DATETIME_SendSimpleNotify (const DATETIME_INFO
*infoPtr
, UINT code
);
127 static BOOL
DATETIME_SendDateTimeChangeNotify (const DATETIME_INFO
*infoPtr
);
128 static const WCHAR allowedformatchars
[] = L
"dhHmMstyX";
129 static const int maxrepetition
[] = {4,2,2,2,4,2,2,4,-1};
130 static const WCHAR
*themeClass
= WC_SCROLLBARW
;
132 /* valid date limits */
133 static const SYSTEMTIME max_allowed_date
= { .wYear
= 9999, .wMonth
= 12, .wDayOfWeek
= 0, .wDay
= 31 };
134 static const SYSTEMTIME min_allowed_date
= { .wYear
= 1752, .wMonth
= 9, .wDayOfWeek
= 0, .wDay
= 14 };
137 DATETIME_GetSystemTime (const DATETIME_INFO
*infoPtr
, SYSTEMTIME
*systime
)
139 if (!systime
) return GDT_NONE
;
141 if ((infoPtr
->dwStyle
& DTS_SHOWNONE
) &&
142 (SendMessageW (infoPtr
->hwndCheckbut
, BM_GETCHECK
, 0, 0) == BST_UNCHECKED
))
145 *systime
= infoPtr
->date
;
150 /* Checks value is within configured date range
154 * [I] infoPtr : valid pointer to control data
155 * [I] date : pointer to valid date data to check
159 * TRUE - date within configured range
160 * FALSE - date is outside configured range
162 static BOOL
DATETIME_IsDateInValidRange(const DATETIME_INFO
*infoPtr
, const SYSTEMTIME
*date
)
167 if ((MONTHCAL_CompareSystemTime(date
, &max_allowed_date
) == 1) ||
168 (MONTHCAL_CompareSystemTime(date
, &min_allowed_date
) == -1))
171 limits
= SendMessageW (infoPtr
->hMonthCal
, MCM_GETRANGE
, 0, (LPARAM
)range
);
173 if (limits
& GDTR_MAX
)
175 if (MONTHCAL_CompareSystemTime(date
, &range
[1]) == 1)
179 if (limits
& GDTR_MIN
)
181 if (MONTHCAL_CompareSystemTime(date
, &range
[0]) == -1)
189 DATETIME_SetSystemTime (DATETIME_INFO
*infoPtr
, DWORD flag
, const SYSTEMTIME
*systime
)
191 if (!systime
) return FALSE
;
193 TRACE("%04d/%02d/%02d %02d:%02d:%02d\n",
194 systime
->wYear
, systime
->wMonth
, systime
->wDay
,
195 systime
->wHour
, systime
->wMinute
, systime
->wSecond
);
197 if (flag
== GDT_VALID
) {
198 if (systime
->wYear
== 0 ||
199 systime
->wMonth
< 1 || systime
->wMonth
> 12 ||
201 systime
->wDay
> MONTHCAL_MonthLength(systime
->wMonth
, systime
->wYear
) ||
202 systime
->wHour
> 23 ||
203 systime
->wMinute
> 59 ||
204 systime
->wSecond
> 59 ||
205 systime
->wMilliseconds
> 999
209 /* Windows returns true if the date is valid but outside the limits set */
210 if (!DATETIME_IsDateInValidRange(infoPtr
, systime
))
213 infoPtr
->dateValid
= TRUE
;
214 infoPtr
->date
= *systime
;
215 /* always store a valid day of week */
216 MONTHCAL_CalculateDayOfWeek(&infoPtr
->date
, TRUE
);
218 SendMessageW (infoPtr
->hMonthCal
, MCM_SETCURSEL
, 0, (LPARAM
)(&infoPtr
->date
));
219 SendMessageW (infoPtr
->hwndCheckbut
, BM_SETCHECK
, BST_CHECKED
, 0);
220 } else if ((infoPtr
->dwStyle
& DTS_SHOWNONE
) && (flag
== GDT_NONE
)) {
221 infoPtr
->dateValid
= FALSE
;
222 SendMessageW (infoPtr
->hwndCheckbut
, BM_SETCHECK
, BST_UNCHECKED
, 0);
227 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
233 * Split up a formattxt in actions.
234 * See ms documentation for the meaning of the letter codes/'specifiers'.
237 * *'dddddd' is handled as 'dddd' plus 'dd'.
238 * *unrecognized formats are strings (here given the type DT_STRING;
239 * start of the string is encoded in lower bits of DT_STRING.
240 * Therefore, 'string' ends up as '<show seconds>tring'.
244 DATETIME_UseFormat (DATETIME_INFO
*infoPtr
, LPCWSTR formattxt
)
248 BOOL inside_literal
= FALSE
; /* inside '...' */
249 int *nrFields
= &infoPtr
->nrFields
;
252 infoPtr
->fieldspec
[*nrFields
] = 0;
253 len
= lstrlenW(allowedformatchars
);
256 for (i
= 0; formattxt
[i
]; i
++) {
257 TRACE ("\n%d %c:", i
, formattxt
[i
]);
258 if (!inside_literal
) {
259 for (j
= 0; j
< len
; j
++) {
260 if (allowedformatchars
[j
]==formattxt
[i
]) {
261 TRACE ("%c[%d,%x]", allowedformatchars
[j
], *nrFields
, infoPtr
->fieldspec
[*nrFields
]);
262 if ((*nrFields
==0) && (infoPtr
->fieldspec
[*nrFields
]==0)) {
263 infoPtr
->fieldspec
[*nrFields
] = (j
<<4) + 1;
266 if (infoPtr
->fieldspec
[*nrFields
] >> 4 != j
) {
268 infoPtr
->fieldspec
[*nrFields
] = (j
<<4) + 1;
271 if ((infoPtr
->fieldspec
[*nrFields
] & 0x0f) == maxrepetition
[j
]) {
273 infoPtr
->fieldspec
[*nrFields
] = (j
<<4) + 1;
276 infoPtr
->fieldspec
[*nrFields
]++;
278 } /* if allowedformatchar */
284 if (formattxt
[i
] == '\'')
286 inside_literal
= !inside_literal
;
290 /* char is not a specifier: handle char like a string */
292 if ((*nrFields
==0) && (infoPtr
->fieldspec
[*nrFields
]==0)) {
293 infoPtr
->fieldspec
[*nrFields
] = DT_STRING
+ k
;
294 infoPtr
->buflen
[*nrFields
] = 0;
295 } else if ((infoPtr
->fieldspec
[*nrFields
] & DT_STRING
) != DT_STRING
) {
297 infoPtr
->fieldspec
[*nrFields
] = DT_STRING
+ k
;
298 infoPtr
->buflen
[*nrFields
] = 0;
300 infoPtr
->textbuf
[k
] = formattxt
[i
];
302 infoPtr
->buflen
[*nrFields
]++;
305 if (*nrFields
== infoPtr
->nrFieldsAllocated
) {
306 FIXME ("out of memory; should reallocate. crash ahead.\n");
312 if (infoPtr
->fieldspec
[*nrFields
] != 0) (*nrFields
)++;
317 DATETIME_SetFormatW (DATETIME_INFO
*infoPtr
, LPCWSTR format
)
319 WCHAR format_buf
[80];
324 if ((infoPtr
->dwStyle
& DTS_SHORTDATECENTURYFORMAT
) == DTS_SHORTDATECENTURYFORMAT
)
325 format_item
= LOCALE_SSHORTDATE
;
326 else if ((infoPtr
->dwStyle
& DTS_LONGDATEFORMAT
) == DTS_LONGDATEFORMAT
)
327 format_item
= LOCALE_SLONGDATE
;
328 else if ((infoPtr
->dwStyle
& DTS_TIMEFORMAT
) == DTS_TIMEFORMAT
)
329 format_item
= LOCALE_STIMEFORMAT
;
330 else /* DTS_SHORTDATEFORMAT */
331 format_item
= LOCALE_SSHORTDATE
;
332 GetLocaleInfoW(LOCALE_USER_DEFAULT
, format_item
, format_buf
, ARRAY_SIZE(format_buf
));
336 DATETIME_UseFormat (infoPtr
, format
);
337 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
344 DATETIME_SetFormatA (DATETIME_INFO
*infoPtr
, LPCSTR lpszFormat
)
348 INT len
= MultiByteToWideChar(CP_ACP
, 0, lpszFormat
, -1, NULL
, 0);
349 LPWSTR wstr
= Alloc(len
* sizeof(WCHAR
));
350 if (wstr
) MultiByteToWideChar(CP_ACP
, 0, lpszFormat
, -1, wstr
, len
);
351 retval
= DATETIME_SetFormatW (infoPtr
, wstr
);
356 return DATETIME_SetFormatW (infoPtr
, 0);
362 DATETIME_ReturnTxt (const DATETIME_INFO
*infoPtr
, int count
, LPWSTR result
, int resultSize
)
364 SYSTEMTIME date
= infoPtr
->date
;
369 TRACE ("%d,%d\n", infoPtr
->nrFields
, count
);
370 if (count
>infoPtr
->nrFields
|| count
< 0) {
371 WARN ("buffer overrun, have %d want %d\n", infoPtr
->nrFields
, count
);
375 if (!infoPtr
->fieldspec
) return;
377 spec
= infoPtr
->fieldspec
[count
];
378 if (spec
& DT_STRING
) {
379 int txtlen
= infoPtr
->buflen
[count
];
381 if (txtlen
> resultSize
)
382 txtlen
= resultSize
- 1;
383 memcpy (result
, infoPtr
->textbuf
+ (spec
&~ DT_STRING
), txtlen
* sizeof(WCHAR
));
385 TRACE ("arg%d=%x->[%s]\n", count
, infoPtr
->fieldspec
[count
], debugstr_w(result
));
395 wsprintfW (result
, L
"%d", date
.wDay
);
398 wsprintfW (result
, L
"%.2d", date
.wDay
);
401 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SABBREVDAYNAME1
+(date
.wDayOfWeek
+6)%7, result
, 4);
402 /*wsprintfW (result,"%.3s",days[date.wDayOfWeek]);*/
405 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SDAYNAME1
+(date
.wDayOfWeek
+6)%7, result
, resultSize
);
408 if (date
.wHour
== 0) {
414 wsprintfW (result
, L
"%d", date
.wHour
- (date
.wHour
> 12 ? 12 : 0));
417 if (date
.wHour
== 0) {
423 wsprintfW (result
, L
"%.2d", date
.wHour
- (date
.wHour
> 12 ? 12 : 0));
426 wsprintfW (result
, L
"%d", date
.wHour
);
429 wsprintfW (result
, L
"%.2d", date
.wHour
);
432 wsprintfW (result
, L
"%d", date
.wSecond
);
435 wsprintfW (result
, L
"%.2d", date
.wSecond
);
438 wsprintfW (result
, L
"%d", date
.wMinute
);
441 wsprintfW (result
, L
"%.2d", date
.wMinute
);
444 wsprintfW (result
, L
"%d", date
.wMonth
);
447 wsprintfW (result
, L
"%.2d", date
.wMonth
);
450 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SMONTHNAME1
+date
.wMonth
-1, buffer
, ARRAY_SIZE(buffer
));
451 wsprintfW (result
, L
"%s.3s", buffer
);
454 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SMONTHNAME1
+date
.wMonth
-1,
458 result
[0] = (date
.wHour
< 12 ? 'A' : 'P');
462 result
[0] = (date
.wHour
< 12 ? 'A' : 'P');
467 FIXME ("Not implemented\n");
472 wsprintfW (result
, L
"%d", date
.wYear
% 10);
475 wsprintfW (result
, L
"%.2d", date
.wYear
% 100);
477 case INVALIDFULLYEAR
:
479 wsprintfW (result
, L
"%d", date
.wYear
);
483 TRACE ("arg%d=%x->[%s]\n", count
, infoPtr
->fieldspec
[count
], debugstr_w(result
));
486 static int wrap(int val
, int delta
, int minVal
, int maxVal
)
489 if (delta
== INT_MIN
|| val
< minVal
) return maxVal
;
490 if (delta
== INT_MAX
|| val
> maxVal
) return minVal
;
495 DATETIME_IncreaseField (DATETIME_INFO
*infoPtr
, int number
, int delta
)
497 SYSTEMTIME
*date
= &infoPtr
->date
;
502 TRACE ("%d\n", number
);
503 if ((number
> infoPtr
->nrFields
) || (number
< 0)) return;
505 if ((infoPtr
->fieldspec
[number
] & DTHT_DATEFIELD
) == 0) return;
507 switch (infoPtr
->fieldspec
[number
]) {
511 if (delta
== INT_MIN
)
513 else if (delta
== INT_MAX
)
516 date
->wYear
= max(min(date
->wYear
+ delta
, 9999), 1752);
518 if (date
->wDay
> MONTHCAL_MonthLength(date
->wMonth
, date
->wYear
))
519 /* This can happen when moving away from a leap year. */
520 date
->wDay
= MONTHCAL_MonthLength(date
->wMonth
, date
->wYear
);
521 MONTHCAL_CalculateDayOfWeek(date
, TRUE
);
527 date
->wMonth
= wrap(date
->wMonth
, delta
, 1, 12);
528 MONTHCAL_CalculateDayOfWeek(date
, TRUE
);
535 date
->wDay
= wrap(date
->wDay
, delta
, 1, MONTHCAL_MonthLength(date
->wMonth
, date
->wYear
));
536 MONTHCAL_CalculateDayOfWeek(date
, TRUE
);
546 date
->wHour
= wrap(date
->wHour
, delta
, 0, 23);
550 date
->wMinute
= wrap(date
->wMinute
, delta
, 0, 59);
554 date
->wSecond
= wrap(date
->wSecond
, delta
, 0, 59);
557 FIXME ("Not implemented\n");
561 /* FYI: On 1752/9/14 the calendar changed and England and the
562 * American colonies changed to the Gregorian calendar. This change
563 * involved having September 14th follow September 2nd. So no date
564 * algorithm works before that date.
566 if (10000 * date
->wYear
+ 100 * date
->wMonth
+ date
->wDay
< 17520914) {
575 /* Ensure time is within bounds */
576 limits
= SendMessageW (infoPtr
->hMonthCal
, MCM_GETRANGE
, 0, (LPARAM
)range
);
579 if (limits
& (min
? GDTR_MIN
: GDTR_MAX
))
581 int i
= (min
? 0 : 1);
583 if (MONTHCAL_CompareSystemTime(date
, &range
[i
]) == (min
? -1 : 1))
585 date
->wYear
= range
[i
].wYear
;
586 date
->wMonth
= range
[i
].wMonth
;
587 date
->wDayOfWeek
= range
[i
].wDayOfWeek
;
588 date
->wDay
= range
[i
].wDay
;
589 date
->wHour
= range
[i
].wHour
;
590 date
->wMinute
= range
[i
].wMinute
;
591 date
->wSecond
= range
[i
].wSecond
;
592 date
->wMilliseconds
= range
[i
].wMilliseconds
;
597 static int DATETIME_GetFieldWidth (const DATETIME_INFO
*infoPtr
, HDC hdc
, int count
)
599 /* fields are a fixed width, determined by the largest possible string */
600 /* presumably, these widths should be language dependent */
606 if (!infoPtr
->fieldspec
) return 0;
608 spec
= infoPtr
->fieldspec
[count
];
609 if (spec
& DT_STRING
) {
610 int txtlen
= infoPtr
->buflen
[count
];
614 memcpy (buffer
, infoPtr
->textbuf
+ (spec
&~ DT_STRING
), txtlen
* sizeof(WCHAR
));
627 /* these seem to use a two byte field */
637 case INVALIDFULLYEAR
:
651 /* choose locale data type and fallback string */
655 lctype
= LOCALE_SABBREVDAYNAME1
;
660 lctype
= LOCALE_SDAYNAME1
;
665 lctype
= LOCALE_SABBREVMONTHNAME1
;
668 default: /* FULLMONTH */
670 lctype
= LOCALE_SMONTHNAME1
;
676 for (i
= 0; i
< max_count
; i
++)
678 if(GetLocaleInfoW(LOCALE_USER_DEFAULT
, lctype
+ i
,
679 buffer
, ARRAY_SIZE(buffer
)))
681 GetTextExtentPoint32W(hdc
, buffer
, lstrlenW(buffer
), &size
);
682 if (size
.cx
> cx
) cx
= size
.cx
;
684 else /* locale independent fallback on failure */
686 GetTextExtentPoint32W(hdc
, fall
, lstrlenW(fall
), &size
);
704 GetTextExtentPoint32W (hdc
, bufptr
, lstrlenW(bufptr
), &size
);
709 DATETIME_Refresh (DATETIME_INFO
*infoPtr
, HDC hdc
)
716 if (infoPtr
->dateValid
) {
719 RECT
*rcDraw
= &infoPtr
->rcDraw
;
721 COLORREF oldTextColor
;
722 HFONT oldFont
= SelectObject (hdc
, infoPtr
->hFont
);
723 INT oldBkMode
= SetBkMode (hdc
, TRANSPARENT
);
726 DATETIME_ReturnTxt (infoPtr
, 0, txt
, ARRAY_SIZE(txt
));
727 GetTextExtentPoint32W (hdc
, txt
, lstrlenW(txt
), &size
);
728 rcDraw
->bottom
= size
.cy
+ 2;
730 prevright
= infoPtr
->checkbox
.right
= ((infoPtr
->dwStyle
& DTS_SHOWNONE
) ? 18 : 2);
732 for (i
= 0; i
< infoPtr
->nrFields
; i
++) {
733 DATETIME_ReturnTxt (infoPtr
, i
, txt
, ARRAY_SIZE(txt
));
734 GetTextExtentPoint32W (hdc
, txt
, lstrlenW(txt
), &size
);
735 field
= &infoPtr
->fieldRect
[i
];
736 field
->left
= prevright
;
737 field
->right
= prevright
+ DATETIME_GetFieldWidth (infoPtr
, hdc
, i
);
738 field
->top
= rcDraw
->top
;
739 field
->bottom
= rcDraw
->bottom
;
740 prevright
= field
->right
;
742 if (infoPtr
->dwStyle
& WS_DISABLED
)
743 oldTextColor
= SetTextColor (hdc
, comctl32_color
.clrGrayText
);
744 else if ((infoPtr
->haveFocus
) && (i
== infoPtr
->select
)) {
747 /* fill if focused */
748 HBRUSH hbr
= CreateSolidBrush (comctl32_color
.clrActiveCaption
);
750 if (infoPtr
->nCharsEntered
)
752 memcpy(txt
, infoPtr
->charsEntered
, infoPtr
->nCharsEntered
* sizeof(WCHAR
));
753 txt
[infoPtr
->nCharsEntered
] = 0;
754 GetTextExtentPoint32W (hdc
, txt
, lstrlenW(txt
), &size
);
757 SetRect(&selection
, 0, 0, size
.cx
, size
.cy
);
758 /* center rectangle */
759 OffsetRect(&selection
, (field
->right
+ field
->left
- size
.cx
)/2,
760 (field
->bottom
- size
.cy
)/2);
762 FillRect(hdc
, &selection
, hbr
);
764 oldTextColor
= SetTextColor (hdc
, comctl32_color
.clrWindow
);
767 oldTextColor
= SetTextColor (hdc
, comctl32_color
.clrWindowText
);
769 /* draw the date text using the colour set above */
770 DrawTextW (hdc
, txt
, lstrlenW(txt
), field
, DT_CENTER
| DT_VCENTER
| DT_SINGLELINE
);
771 SetTextColor (hdc
, oldTextColor
);
773 SetBkMode (hdc
, oldBkMode
);
774 SelectObject (hdc
, oldFont
);
777 if (infoPtr
->dwStyle
& DTS_UPDOWN
)
780 theme
= GetWindowTheme(infoPtr
->hwndSelf
);
783 if (infoPtr
->dwStyle
& WS_DISABLED
)
784 state
= ABS_DOWNDISABLED
;
785 else if (infoPtr
->bCalDepressed
)
786 state
= ABS_DOWNPRESSED
;
787 else if (infoPtr
->bCalHot
)
790 state
= ABS_DOWNNORMAL
;
792 DrawThemeBackground(theme
, hdc
, SBP_ARROWBTN
, state
, &infoPtr
->calbutton
, NULL
);
796 DrawFrameControl(hdc
, &infoPtr
->calbutton
, DFC_SCROLL
,
797 DFCS_SCROLLDOWN
| (infoPtr
->bCalDepressed
? DFCS_PUSHED
: 0) |
798 (infoPtr
->dwStyle
& WS_DISABLED
? DFCS_INACTIVE
: 0) );
804 DATETIME_HitTest (const DATETIME_INFO
*infoPtr
, POINT pt
)
808 TRACE ("%s\n", wine_dbgstr_point(&pt
));
810 if (PtInRect (&infoPtr
->calbutton
, pt
)) return DTHT_MCPOPUP
;
811 if (PtInRect (&infoPtr
->checkbox
, pt
)) return DTHT_CHECKBOX
;
813 for (i
= 0; i
< infoPtr
->nrFields
; i
++) {
814 if (PtInRect (&infoPtr
->fieldRect
[i
], pt
)) return i
;
820 /* Returns index of the nearest preceding date field from given,
821 or -1 if none was found */
822 static int DATETIME_GetPrevDateField(const DATETIME_INFO
*infoPtr
, int i
)
824 for(--i
; i
>= 0; i
--)
826 if (infoPtr
->fieldspec
[i
] & DTHT_DATEFIELD
) return i
;
832 DATETIME_ApplySelectedField (DATETIME_INFO
*infoPtr
)
834 int fieldNum
= infoPtr
->select
& DTHT_DATEFIELD
;
836 BOOL clamp_day
= FALSE
;
837 SYSTEMTIME date
= infoPtr
->date
;
840 if (infoPtr
->select
== -1 || infoPtr
->nCharsEntered
== 0)
843 if ((infoPtr
->fieldspec
[fieldNum
] == ONELETTERAMPM
) ||
844 (infoPtr
->fieldspec
[fieldNum
] == TWOLETTERAMPM
))
845 val
= infoPtr
->charsEntered
[0];
847 for (i
=0; i
<infoPtr
->nCharsEntered
; i
++)
848 val
= val
* 10 + infoPtr
->charsEntered
[i
] - '0';
851 infoPtr
->nCharsEntered
= 0;
853 switch (infoPtr
->fieldspec
[fieldNum
]) {
856 oldyear
= date
.wYear
;
857 date
.wYear
= date
.wYear
- (date
.wYear
%100) + val
;
859 if (DATETIME_IsDateInValidRange(infoPtr
, &date
))
862 date
.wYear
= oldyear
;
865 case INVALIDFULLYEAR
:
867 oldyear
= date
.wYear
;
870 if (DATETIME_IsDateInValidRange(infoPtr
, &date
))
873 date
.wYear
= oldyear
;
893 if (date
.wHour
>= 12) /* preserve current AM/PM state */
894 date
.wHour
= (val
== 12 ? 12 : val
+ 12);
896 date
.wHour
= (val
== 12 ? 0 : val
);
913 if (val
== 'a' || val
== 'A') {
914 if (date
.wHour
>= 12)
916 } else if (val
== 'p' || val
== 'P') {
923 if (clamp_day
&& date
.wDay
> MONTHCAL_MonthLength(date
.wMonth
, date
.wYear
))
924 date
.wDay
= MONTHCAL_MonthLength(date
.wMonth
, date
.wYear
);
926 if (DATETIME_SetSystemTime(infoPtr
, GDT_VALID
, &date
))
927 DATETIME_SendDateTimeChangeNotify (infoPtr
);
931 DATETIME_SetSelectedField (DATETIME_INFO
*infoPtr
, int select
)
933 DATETIME_ApplySelectedField(infoPtr
);
935 infoPtr
->select
= select
;
936 infoPtr
->nCharsEntered
= 0;
940 DATETIME_LButtonDown (DATETIME_INFO
*infoPtr
, INT x
, INT y
)
947 new = DATETIME_HitTest (infoPtr
, pt
);
949 SetFocus(infoPtr
->hwndSelf
);
951 if (!(new & DTHT_NODATEMASK
) || (new == DTHT_NONE
))
953 if (new == DTHT_NONE
)
954 new = infoPtr
->nrFields
- 1;
957 /* hitting string part moves selection to next date field to left */
958 if (infoPtr
->fieldspec
[new] & DT_STRING
)
960 new = DATETIME_GetPrevDateField(infoPtr
, new);
961 if (new == -1) return 0;
963 /* never select full day of week */
964 if (infoPtr
->fieldspec
[new] == FULLDAY
) return 0;
968 DATETIME_SetSelectedField(infoPtr
, new);
970 if (infoPtr
->select
== DTHT_MCPOPUP
) {
973 SendMessageW(infoPtr
->hMonthCal
, MCM_GETMINREQRECT
, 0, (LPARAM
)&rcMonthCal
);
975 /* FIXME: button actually is only depressed during dropdown of the */
976 /* calendar control and when the mouse is over the button window */
977 infoPtr
->bCalDepressed
= TRUE
;
979 /* recalculate the position of the monthcal popup */
980 if(infoPtr
->dwStyle
& DTS_RIGHTALIGN
)
981 pos
.x
= infoPtr
->calbutton
.left
- (rcMonthCal
.right
- rcMonthCal
.left
);
983 /* FIXME: this should be after the area reserved for the checkbox */
984 pos
.x
= infoPtr
->rcDraw
.left
;
986 pos
.y
= infoPtr
->rcClient
.bottom
;
987 OffsetRect( &rcMonthCal
, pos
.x
, pos
.y
);
988 MapWindowPoints( infoPtr
->hwndSelf
, 0, (POINT
*)&rcMonthCal
, 2 );
989 SetWindowPos(infoPtr
->hMonthCal
, 0, rcMonthCal
.left
, rcMonthCal
.top
,
990 rcMonthCal
.right
- rcMonthCal
.left
, rcMonthCal
.bottom
- rcMonthCal
.top
, 0);
992 if(IsWindowVisible(infoPtr
->hMonthCal
)) {
993 ShowWindow(infoPtr
->hMonthCal
, SW_HIDE
);
994 infoPtr
->bDropdownEnabled
= FALSE
;
995 DATETIME_SendSimpleNotify (infoPtr
, DTN_CLOSEUP
);
997 const SYSTEMTIME
*lprgSysTimeArray
= &infoPtr
->date
;
998 TRACE("update calendar %04d/%02d/%02d\n",
999 lprgSysTimeArray
->wYear
, lprgSysTimeArray
->wMonth
, lprgSysTimeArray
->wDay
);
1000 SendMessageW(infoPtr
->hMonthCal
, MCM_SETCURSEL
, 0, (LPARAM
)(&infoPtr
->date
));
1002 if (infoPtr
->bDropdownEnabled
) {
1003 ShowWindow(infoPtr
->hMonthCal
, SW_SHOW
);
1004 DATETIME_SendSimpleNotify (infoPtr
, DTN_DROPDOWN
);
1006 infoPtr
->bDropdownEnabled
= TRUE
;
1009 TRACE ("dt:%p mc:%p mc parent:%p, desktop:%p\n",
1010 infoPtr
->hwndSelf
, infoPtr
->hMonthCal
, infoPtr
->hwndNotify
, GetDesktopWindow ());
1013 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1020 DATETIME_LButtonUp (DATETIME_INFO
*infoPtr
)
1022 if(infoPtr
->bCalDepressed
) {
1023 infoPtr
->bCalDepressed
= FALSE
;
1024 InvalidateRect(infoPtr
->hwndSelf
, &(infoPtr
->calbutton
), TRUE
);
1032 DATETIME_Paint (DATETIME_INFO
*infoPtr
, HDC hdc
)
1036 hdc
= BeginPaint (infoPtr
->hwndSelf
, &ps
);
1037 DATETIME_Refresh (infoPtr
, hdc
);
1038 EndPaint (infoPtr
->hwndSelf
, &ps
);
1040 DATETIME_Refresh (infoPtr
, hdc
);
1043 /* Not a click on the dropdown box, enabled it */
1044 infoPtr
->bDropdownEnabled
= TRUE
;
1051 DATETIME_Button_Command (DATETIME_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
1053 if( HIWORD(wParam
) == BN_CLICKED
) {
1054 DWORD state
= SendMessageW((HWND
)lParam
, BM_GETCHECK
, 0, 0);
1055 infoPtr
->dateValid
= (state
== BST_CHECKED
);
1056 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1057 DATETIME_SendDateTimeChangeNotify(infoPtr
);
1065 DATETIME_Command (DATETIME_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
1067 TRACE("hwndbutton = %p\n", infoPtr
->hwndCheckbut
);
1068 if(infoPtr
->hwndCheckbut
== (HWND
)lParam
)
1069 return DATETIME_Button_Command(infoPtr
, wParam
, lParam
);
1075 DATETIME_Enable (DATETIME_INFO
*infoPtr
, BOOL bEnable
)
1077 TRACE("%p %s\n", infoPtr
, bEnable
? "TRUE" : "FALSE");
1079 infoPtr
->dwStyle
&= ~WS_DISABLED
;
1081 infoPtr
->dwStyle
|= WS_DISABLED
;
1083 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1090 DATETIME_EraseBackground (const DATETIME_INFO
*infoPtr
, HDC hdc
)
1092 HBRUSH hBrush
, hSolidBrush
= NULL
;
1095 if (infoPtr
->dwStyle
& WS_DISABLED
)
1096 hBrush
= hSolidBrush
= CreateSolidBrush(comctl32_color
.clrBtnFace
);
1099 hBrush
= (HBRUSH
)SendMessageW(infoPtr
->hwndNotify
, WM_CTLCOLOREDIT
,
1100 (WPARAM
)hdc
, (LPARAM
)infoPtr
->hwndSelf
);
1102 hBrush
= hSolidBrush
= CreateSolidBrush(comctl32_color
.clrWindow
);
1105 GetClientRect (infoPtr
->hwndSelf
, &rc
);
1107 FillRect (hdc
, &rc
, hBrush
);
1110 DeleteObject(hSolidBrush
);
1117 DATETIME_Notify (DATETIME_INFO
*infoPtr
, const NMHDR
*lpnmh
)
1119 TRACE ("Got notification %x from %p\n", lpnmh
->code
, lpnmh
->hwndFrom
);
1120 TRACE ("info: %p %p %p\n", infoPtr
->hwndSelf
, infoPtr
->hMonthCal
, infoPtr
->hUpdown
);
1122 if (lpnmh
->code
== MCN_SELECT
) {
1123 ShowWindow(infoPtr
->hMonthCal
, SW_HIDE
);
1124 infoPtr
->dateValid
= TRUE
;
1125 SendMessageW (infoPtr
->hMonthCal
, MCM_GETCURSEL
, 0, (LPARAM
)&infoPtr
->date
);
1126 TRACE("got from calendar %04d/%02d/%02d day of week %d\n",
1127 infoPtr
->date
.wYear
, infoPtr
->date
.wMonth
, infoPtr
->date
.wDay
, infoPtr
->date
.wDayOfWeek
);
1128 SendMessageW (infoPtr
->hwndCheckbut
, BM_SETCHECK
, BST_CHECKED
, 0);
1129 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1130 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1131 DATETIME_SendSimpleNotify(infoPtr
, DTN_CLOSEUP
);
1133 if ((lpnmh
->hwndFrom
== infoPtr
->hUpdown
) && (lpnmh
->code
== UDN_DELTAPOS
)) {
1134 const NM_UPDOWN
*lpnmud
= (const NM_UPDOWN
*)lpnmh
;
1135 TRACE("Delta pos %d\n", lpnmud
->iDelta
);
1136 infoPtr
->pendingUpdown
= lpnmud
->iDelta
;
1143 DATETIME_KeyDown (DATETIME_INFO
*infoPtr
, DWORD vkCode
)
1145 int fieldNum
= infoPtr
->select
& DTHT_DATEFIELD
;
1149 if (!(infoPtr
->haveFocus
)) return 0;
1150 if ((fieldNum
==0) && (infoPtr
->select
)) return 0;
1152 if (infoPtr
->select
& FORMATCALLMASK
) {
1153 FIXME ("Callbacks not implemented yet\n");
1159 infoPtr
->nCharsEntered
= 0;
1160 DATETIME_IncreaseField (infoPtr
, fieldNum
, 1);
1161 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1165 infoPtr
->nCharsEntered
= 0;
1166 DATETIME_IncreaseField (infoPtr
, fieldNum
, -1);
1167 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1170 infoPtr
->nCharsEntered
= 0;
1171 DATETIME_IncreaseField (infoPtr
, fieldNum
, INT_MIN
);
1172 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1175 infoPtr
->nCharsEntered
= 0;
1176 DATETIME_IncreaseField (infoPtr
, fieldNum
, INT_MAX
);
1177 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1180 new = infoPtr
->select
;
1188 } while ((infoPtr
->fieldspec
[new] & DT_STRING
) && (wrap
<2));
1189 if (new != infoPtr
->select
)
1190 DATETIME_SetSelectedField(infoPtr
, new);
1193 new = infoPtr
->select
;
1196 if (new==infoPtr
->nrFields
) {
1200 } while ((infoPtr
->fieldspec
[new] & DT_STRING
) && (wrap
<2));
1201 if (new != infoPtr
->select
)
1202 DATETIME_SetSelectedField(infoPtr
, new);
1206 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1213 DATETIME_Char (DATETIME_INFO
*infoPtr
, WPARAM vkCode
)
1215 int fieldNum
, fieldSpec
;
1217 fieldNum
= infoPtr
->select
& DTHT_DATEFIELD
;
1218 fieldSpec
= infoPtr
->fieldspec
[fieldNum
];
1220 if (fieldSpec
== ONELETTERAMPM
|| fieldSpec
== TWOLETTERAMPM
) {
1221 infoPtr
->charsEntered
[0] = vkCode
;
1222 infoPtr
->nCharsEntered
= 1;
1224 DATETIME_ApplySelectedField(infoPtr
);
1225 } else if (vkCode
>= '0' && vkCode
<= '9') {
1228 infoPtr
->charsEntered
[infoPtr
->nCharsEntered
++] = vkCode
;
1230 if (fieldSpec
== INVALIDFULLYEAR
|| fieldSpec
== FULLYEAR
)
1235 if ((fieldSpec
== ONEDIGIT12HOUR
||
1236 fieldSpec
== TWODIGIT12HOUR
||
1237 fieldSpec
== ONEDIGIT24HOUR
||
1238 fieldSpec
== TWODIGIT24HOUR
) &&
1239 (infoPtr
->nCharsEntered
== 1))
1245 if (maxChars
== infoPtr
->nCharsEntered
)
1246 DATETIME_ApplySelectedField(infoPtr
);
1254 DATETIME_VScroll (DATETIME_INFO
*infoPtr
, WORD wScroll
)
1256 int fieldNum
= infoPtr
->select
& DTHT_DATEFIELD
;
1258 if ((SHORT
)LOWORD(wScroll
) != SB_THUMBPOSITION
) return 0;
1259 if (!(infoPtr
->haveFocus
)) return 0;
1260 if ((fieldNum
==0) && (infoPtr
->select
)) return 0;
1262 if (infoPtr
->pendingUpdown
>= 0) {
1263 DATETIME_IncreaseField (infoPtr
, fieldNum
, 1);
1264 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1267 DATETIME_IncreaseField (infoPtr
, fieldNum
, -1);
1268 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1271 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1278 DATETIME_KillFocus (DATETIME_INFO
*infoPtr
, HWND lostFocus
)
1280 TRACE("lost focus to %p\n", lostFocus
);
1282 if (infoPtr
->haveFocus
) {
1283 DATETIME_SendSimpleNotify (infoPtr
, NM_KILLFOCUS
);
1284 infoPtr
->haveFocus
= 0;
1285 DATETIME_SetSelectedField (infoPtr
, -1);
1288 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
1295 DATETIME_NCCreate (HWND hwnd
, const CREATESTRUCTW
*lpcs
)
1297 DWORD dwExStyle
= GetWindowLongW(hwnd
, GWL_EXSTYLE
);
1298 /* force control to have client edge */
1299 dwExStyle
|= WS_EX_CLIENTEDGE
;
1300 SetWindowLongW(hwnd
, GWL_EXSTYLE
, dwExStyle
);
1305 static LRESULT
DATETIME_NCPaint (HWND hwnd
, HRGN region
)
1314 theme
= OpenThemeDataForDpi(NULL
, WC_EDITW
, GetDpiForWindow(hwnd
));
1316 return DefWindowProcW(hwnd
, WM_NCPAINT
, (WPARAM
)region
, 0);
1318 exStyle
= GetWindowLongW(hwnd
, GWL_EXSTYLE
);
1319 if (!(exStyle
& WS_EX_CLIENTEDGE
))
1321 CloseThemeData(theme
);
1322 return DefWindowProcW(hwnd
, WM_NCPAINT
, (WPARAM
)region
, 0);
1325 cxEdge
= GetSystemMetrics(SM_CXEDGE
);
1326 cyEdge
= GetSystemMetrics(SM_CYEDGE
);
1327 GetWindowRect(hwnd
, &r
);
1329 /* New clipping region passed to default proc to exclude border */
1330 clipRgn
= CreateRectRgn(r
.left
+ cxEdge
, r
.top
+ cyEdge
, r
.right
- cxEdge
, r
.bottom
- cyEdge
);
1331 if (region
!= (HRGN
)1)
1332 CombineRgn(clipRgn
, clipRgn
, region
, RGN_AND
);
1333 OffsetRect(&r
, -r
.left
, -r
.top
);
1335 dc
= GetDCEx(hwnd
, region
, DCX_WINDOW
| DCX_INTERSECTRGN
);
1336 if (IsThemeBackgroundPartiallyTransparent(theme
, 0, 0))
1337 DrawThemeParentBackground(hwnd
, dc
, &r
);
1338 DrawThemeBackground(theme
, dc
, 0, 0, &r
, 0);
1339 ReleaseDC(hwnd
, dc
);
1340 CloseThemeData(theme
);
1342 /* Call default proc to get the scrollbars etc. also painted */
1343 DefWindowProcW(hwnd
, WM_NCPAINT
, (WPARAM
)clipRgn
, 0);
1344 DeleteObject(clipRgn
);
1348 static LRESULT
DATETIME_MouseMove (DATETIME_INFO
*infoPtr
, LONG x
, LONG y
)
1350 TRACKMOUSEEVENT event
;
1356 hot
= PtInRect(&infoPtr
->calbutton
, point
);
1357 if (hot
!= infoPtr
->bCalHot
)
1359 infoPtr
->bCalHot
= hot
;
1360 RedrawWindow(infoPtr
->hwndSelf
, &infoPtr
->calbutton
, 0, RDW_INVALIDATE
| RDW_UPDATENOW
);
1366 event
.cbSize
= sizeof(TRACKMOUSEEVENT
);
1367 event
.dwFlags
= TME_QUERY
;
1368 if (!TrackMouseEvent(&event
) || event
.hwndTrack
!= infoPtr
->hwndSelf
|| !(event
.dwFlags
& TME_LEAVE
))
1370 event
.hwndTrack
= infoPtr
->hwndSelf
;
1371 event
.dwFlags
= TME_LEAVE
;
1372 TrackMouseEvent(&event
);
1378 static LRESULT
DATETIME_MouseLeave (DATETIME_INFO
*infoPtr
)
1380 infoPtr
->bCalHot
= FALSE
;
1381 RedrawWindow(infoPtr
->hwndSelf
, &infoPtr
->calbutton
, 0, RDW_INVALIDATE
| RDW_UPDATENOW
);
1386 DATETIME_SetFocus (DATETIME_INFO
*infoPtr
, HWND lostFocus
)
1388 TRACE("got focus from %p\n", lostFocus
);
1390 /* if monthcal is open and it loses focus, close monthcal */
1391 if (infoPtr
->hMonthCal
&& (lostFocus
== infoPtr
->hMonthCal
) &&
1392 IsWindowVisible(infoPtr
->hMonthCal
))
1394 ShowWindow(infoPtr
->hMonthCal
, SW_HIDE
);
1395 DATETIME_SendSimpleNotify(infoPtr
, DTN_CLOSEUP
);
1396 /* note: this get triggered even if monthcal loses focus to a dropdown
1397 * box click, which occurs without an intermediate WM_PAINT call
1399 infoPtr
->bDropdownEnabled
= FALSE
;
1403 if (infoPtr
->haveFocus
== 0) {
1404 DATETIME_SendSimpleNotify (infoPtr
, NM_SETFOCUS
);
1405 infoPtr
->haveFocus
= DTHT_GOTFOCUS
;
1408 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1415 DATETIME_SendDateTimeChangeNotify (const DATETIME_INFO
*infoPtr
)
1417 NMDATETIMECHANGE dtdtc
;
1419 dtdtc
.nmhdr
.hwndFrom
= infoPtr
->hwndSelf
;
1420 dtdtc
.nmhdr
.idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1421 dtdtc
.nmhdr
.code
= DTN_DATETIMECHANGE
;
1423 dtdtc
.dwFlags
= infoPtr
->dateValid
? GDT_VALID
: GDT_NONE
;
1425 dtdtc
.st
= infoPtr
->date
;
1426 return (BOOL
) SendMessageW (infoPtr
->hwndNotify
, WM_NOTIFY
,
1427 dtdtc
.nmhdr
.idFrom
, (LPARAM
)&dtdtc
);
1432 DATETIME_SendSimpleNotify (const DATETIME_INFO
*infoPtr
, UINT code
)
1436 TRACE("%x\n", code
);
1437 nmhdr
.hwndFrom
= infoPtr
->hwndSelf
;
1438 nmhdr
.idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1441 return (BOOL
) SendMessageW (infoPtr
->hwndNotify
, WM_NOTIFY
,
1442 nmhdr
.idFrom
, (LPARAM
)&nmhdr
);
1446 DATETIME_Size (DATETIME_INFO
*infoPtr
, INT width
, INT height
)
1449 infoPtr
->rcClient
.bottom
= height
;
1450 infoPtr
->rcClient
.right
= width
;
1452 TRACE("Height %ld, Width %ld\n", infoPtr
->rcClient
.bottom
, infoPtr
->rcClient
.right
);
1454 infoPtr
->rcDraw
= infoPtr
->rcClient
;
1456 if (infoPtr
->dwStyle
& DTS_UPDOWN
) {
1457 SetWindowPos(infoPtr
->hUpdown
, NULL
,
1458 infoPtr
->rcClient
.right
-14, 0,
1459 15, infoPtr
->rcClient
.bottom
- infoPtr
->rcClient
.top
,
1460 SWP_NOACTIVATE
| SWP_NOZORDER
);
1463 /* set the size of the button that drops the calendar down */
1464 /* FIXME: account for style that allows button on left side */
1465 infoPtr
->calbutton
.top
= infoPtr
->rcDraw
.top
;
1466 infoPtr
->calbutton
.bottom
= infoPtr
->rcDraw
.bottom
;
1467 infoPtr
->calbutton
.left
= infoPtr
->rcDraw
.right
-15;
1468 infoPtr
->calbutton
.right
= infoPtr
->rcDraw
.right
;
1471 /* set enable/disable button size for show none style being enabled */
1472 /* FIXME: these dimensions are completely incorrect */
1473 infoPtr
->checkbox
.top
= infoPtr
->rcDraw
.top
;
1474 infoPtr
->checkbox
.bottom
= infoPtr
->rcDraw
.bottom
;
1475 infoPtr
->checkbox
.left
= infoPtr
->rcDraw
.left
;
1476 infoPtr
->checkbox
.right
= infoPtr
->rcDraw
.left
+ 10;
1478 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1484 DATETIME_StyleChanging(DATETIME_INFO
*infoPtr
, WPARAM wStyleType
, STYLESTRUCT
*lpss
)
1486 TRACE("styletype %Ix, styleOld %#lx, styleNew %#lx\n", wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
1488 /* block DTS_SHOWNONE change */
1489 if ((lpss
->styleNew
^ lpss
->styleOld
) & DTS_SHOWNONE
)
1491 if (lpss
->styleOld
& DTS_SHOWNONE
)
1492 lpss
->styleNew
|= DTS_SHOWNONE
;
1494 lpss
->styleNew
&= ~DTS_SHOWNONE
;
1501 DATETIME_StyleChanged(DATETIME_INFO
*infoPtr
, WPARAM wStyleType
, const STYLESTRUCT
*lpss
)
1503 TRACE("styletype %Ix, styleOld %#lx, styleNew %#lx\n", wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
1505 if (wStyleType
!= GWL_STYLE
) return 0;
1507 infoPtr
->dwStyle
= lpss
->styleNew
;
1509 if ( !(lpss
->styleOld
& DTS_SHOWNONE
) && (lpss
->styleNew
& DTS_SHOWNONE
) ) {
1510 infoPtr
->hwndCheckbut
= CreateWindowExW (0, WC_BUTTONW
, 0, WS_CHILD
| WS_VISIBLE
| BS_AUTOCHECKBOX
,
1511 2, 2, 13, 13, infoPtr
->hwndSelf
, 0,
1512 (HINSTANCE
)GetWindowLongPtrW (infoPtr
->hwndSelf
, GWLP_HINSTANCE
), 0);
1513 SendMessageW (infoPtr
->hwndCheckbut
, BM_SETCHECK
, infoPtr
->dateValid
? 1 : 0, 0);
1515 if ( (lpss
->styleOld
& DTS_SHOWNONE
) && !(lpss
->styleNew
& DTS_SHOWNONE
) ) {
1516 DestroyWindow(infoPtr
->hwndCheckbut
);
1517 infoPtr
->hwndCheckbut
= 0;
1519 if ( !(lpss
->styleOld
& DTS_UPDOWN
) && (lpss
->styleNew
& DTS_UPDOWN
) ) {
1520 infoPtr
->hUpdown
= CreateUpDownControl (WS_CHILD
| WS_BORDER
| WS_VISIBLE
, 120, 1, 20, 20,
1521 infoPtr
->hwndSelf
, 1, 0, 0, UD_MAXVAL
, UD_MINVAL
, 0);
1523 if ( (lpss
->styleOld
& DTS_UPDOWN
) && !(lpss
->styleNew
& DTS_UPDOWN
) ) {
1524 DestroyWindow(infoPtr
->hUpdown
);
1525 infoPtr
->hUpdown
= 0;
1530 static LRESULT
DATETIME_ThemeChanged (DATETIME_INFO
*infoPtr
)
1534 theme
= GetWindowTheme(infoPtr
->hwndSelf
);
1535 CloseThemeData(theme
);
1536 OpenThemeData(infoPtr
->hwndSelf
, themeClass
);
1537 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1541 static BOOL
DATETIME_GetIdealSize(DATETIME_INFO
*infoPtr
, SIZE
*size
)
1550 size
->cx
= size
->cy
= 0;
1552 hdc
= GetDC(infoPtr
->hwndSelf
);
1553 oldFont
= SelectObject(hdc
, infoPtr
->hFont
);
1555 /* Get text font height */
1556 DATETIME_ReturnTxt(infoPtr
, 0, txt
, ARRAY_SIZE(txt
));
1557 GetTextExtentPoint32W(hdc
, txt
, lstrlenW(txt
), &field_size
);
1558 size
->cy
= field_size
.cy
;
1560 /* Get text font width */
1561 for (i
= 0; i
< infoPtr
->nrFields
; i
++)
1563 size
->cx
+= DATETIME_GetFieldWidth(infoPtr
, hdc
, i
);
1566 SelectObject(hdc
, oldFont
);
1567 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
1569 if (infoPtr
->dwStyle
& DTS_UPDOWN
)
1571 GetWindowRect(infoPtr
->hUpdown
, &rect
);
1572 size
->cx
+= rect
.right
- rect
.left
;
1576 size
->cx
+= infoPtr
->calbutton
.right
- infoPtr
->calbutton
.left
;
1579 if (infoPtr
->dwStyle
& DTS_SHOWNONE
)
1581 size
->cx
+= infoPtr
->checkbox
.right
- infoPtr
->checkbox
.left
;
1584 /* Add space between controls for them not to get too close */
1588 TRACE("cx %ld, cy %ld\n", size
->cx
, size
->cy
);
1593 DATETIME_SetFont (DATETIME_INFO
*infoPtr
, HFONT font
, BOOL repaint
)
1595 infoPtr
->hFont
= font
;
1596 if (repaint
) InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1602 DATETIME_Create (HWND hwnd
, const CREATESTRUCTW
*lpcs
)
1604 DATETIME_INFO
*infoPtr
= Alloc (sizeof(DATETIME_INFO
));
1605 STYLESTRUCT ss
= { 0, lpcs
->style
};
1607 if (!infoPtr
) return -1;
1609 infoPtr
->hwndSelf
= hwnd
;
1610 infoPtr
->dwStyle
= lpcs
->style
;
1612 infoPtr
->nrFieldsAllocated
= 32;
1613 infoPtr
->fieldspec
= Alloc (infoPtr
->nrFieldsAllocated
* sizeof(int));
1614 infoPtr
->fieldRect
= Alloc (infoPtr
->nrFieldsAllocated
* sizeof(RECT
));
1615 infoPtr
->buflen
= Alloc (infoPtr
->nrFieldsAllocated
* sizeof(int));
1616 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
1617 infoPtr
->select
= -1; /* initially, nothing is selected */
1618 infoPtr
->bDropdownEnabled
= TRUE
;
1619 infoPtr
->bCalHot
= FALSE
;
1621 DATETIME_StyleChanged(infoPtr
, GWL_STYLE
, &ss
);
1622 DATETIME_SetFormatW (infoPtr
, 0);
1624 /* create the monthcal control */
1625 infoPtr
->hMonthCal
= CreateWindowExW (0, MONTHCAL_CLASSW
, 0, WS_BORDER
| WS_POPUP
| WS_CLIPSIBLINGS
,
1626 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, 0, 0);
1628 /* initialize info structure */
1629 GetLocalTime (&infoPtr
->date
);
1630 infoPtr
->dateValid
= TRUE
;
1631 infoPtr
->hFont
= GetStockObject(DEFAULT_GUI_FONT
);
1633 SetWindowLongPtrW (hwnd
, 0, (DWORD_PTR
)infoPtr
);
1634 OpenThemeData(hwnd
, themeClass
);
1642 DATETIME_Destroy (DATETIME_INFO
*infoPtr
)
1646 theme
= GetWindowTheme(infoPtr
->hwndSelf
);
1647 CloseThemeData(theme
);
1649 if (infoPtr
->hwndCheckbut
)
1650 DestroyWindow(infoPtr
->hwndCheckbut
);
1651 if (infoPtr
->hUpdown
)
1652 DestroyWindow(infoPtr
->hUpdown
);
1653 if (infoPtr
->hMonthCal
)
1654 DestroyWindow(infoPtr
->hMonthCal
);
1655 SetWindowLongPtrW( infoPtr
->hwndSelf
, 0, 0 ); /* clear infoPtr */
1656 Free (infoPtr
->buflen
);
1657 Free (infoPtr
->fieldRect
);
1658 Free (infoPtr
->fieldspec
);
1665 DATETIME_GetText (const DATETIME_INFO
*infoPtr
, INT count
, LPWSTR dst
)
1670 if (!dst
|| (count
<= 0)) return 0;
1673 for (i
= 0; i
< infoPtr
->nrFields
; i
++)
1675 DATETIME_ReturnTxt(infoPtr
, i
, buf
, ARRAY_SIZE(buf
));
1676 if ((lstrlenW(dst
) + lstrlenW(buf
)) < count
)
1680 return lstrlenW(dst
);
1683 static int DATETIME_GetTextLength(const DATETIME_INFO
*info
)
1688 TRACE("%p.\n", info
);
1690 for (i
= 0; i
< info
->nrFields
; i
++)
1692 DATETIME_ReturnTxt(info
, i
, buffer
, ARRAY_SIZE(buffer
));
1693 length
+= lstrlenW(buffer
);
1698 static LRESULT WINAPI
1699 DATETIME_WindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1701 DATETIME_INFO
*infoPtr
= ((DATETIME_INFO
*)GetWindowLongPtrW (hwnd
, 0));
1703 TRACE("%x, %Ix, %Ix\n", uMsg
, wParam
, lParam
);
1705 if (!infoPtr
&& (uMsg
!= WM_CREATE
) && (uMsg
!= WM_NCCREATE
))
1706 return DefWindowProcW( hwnd
, uMsg
, wParam
, lParam
);
1710 case DTM_GETSYSTEMTIME
:
1711 return DATETIME_GetSystemTime (infoPtr
, (SYSTEMTIME
*) lParam
);
1713 case DTM_SETSYSTEMTIME
:
1714 return DATETIME_SetSystemTime (infoPtr
, wParam
, (SYSTEMTIME
*) lParam
);
1717 return SendMessageW (infoPtr
->hMonthCal
, MCM_GETRANGE
, wParam
, lParam
);
1720 return SendMessageW (infoPtr
->hMonthCal
, MCM_SETRANGE
, wParam
, lParam
);
1722 case DTM_SETFORMATA
:
1723 return DATETIME_SetFormatA (infoPtr
, (LPCSTR
)lParam
);
1725 case DTM_SETFORMATW
:
1726 return DATETIME_SetFormatW (infoPtr
, (LPCWSTR
)lParam
);
1728 case DTM_GETMONTHCAL
:
1729 return (LRESULT
)infoPtr
->hMonthCal
;
1731 case DTM_SETMCCOLOR
:
1732 return SendMessageW (infoPtr
->hMonthCal
, MCM_SETCOLOR
, wParam
, lParam
);
1734 case DTM_GETMCCOLOR
:
1735 return SendMessageW (infoPtr
->hMonthCal
, MCM_GETCOLOR
, wParam
, 0);
1738 return SendMessageW (infoPtr
->hMonthCal
, WM_SETFONT
, wParam
, lParam
);
1741 return SendMessageW (infoPtr
->hMonthCal
, WM_GETFONT
, wParam
, lParam
);
1743 case DTM_GETIDEALSIZE
:
1744 return DATETIME_GetIdealSize(infoPtr
, (SIZE
*)lParam
);
1747 return DATETIME_Notify (infoPtr
, (LPNMHDR
)lParam
);
1750 return DATETIME_Enable (infoPtr
, (BOOL
)wParam
);
1753 return DATETIME_EraseBackground (infoPtr
, (HDC
)wParam
);
1756 return DLGC_WANTARROWS
| DLGC_WANTCHARS
;
1758 case WM_PRINTCLIENT
:
1760 return DATETIME_Paint (infoPtr
, (HDC
)wParam
);
1763 return DATETIME_KeyDown (infoPtr
, wParam
);
1766 return DATETIME_Char (infoPtr
, wParam
);
1769 return DATETIME_KillFocus (infoPtr
, (HWND
)wParam
);
1772 return DATETIME_NCCreate (hwnd
, (LPCREATESTRUCTW
)lParam
);
1775 return DATETIME_NCPaint(hwnd
, (HRGN
)wParam
);
1778 return DATETIME_MouseMove(infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
1781 return DATETIME_MouseLeave(infoPtr
);
1784 return DATETIME_SetFocus (infoPtr
, (HWND
)wParam
);
1787 return DATETIME_Size (infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
1789 case WM_LBUTTONDOWN
:
1790 return DATETIME_LButtonDown (infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
1793 return DATETIME_LButtonUp (infoPtr
);
1796 return DATETIME_VScroll (infoPtr
, (WORD
)wParam
);
1799 return DATETIME_Create (hwnd
, (LPCREATESTRUCTW
)lParam
);
1802 return DATETIME_Destroy (infoPtr
);
1805 return DATETIME_Command (infoPtr
, wParam
, lParam
);
1807 case WM_STYLECHANGING
:
1808 return DATETIME_StyleChanging(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
1810 case WM_STYLECHANGED
:
1811 return DATETIME_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
1813 case WM_THEMECHANGED
:
1814 return DATETIME_ThemeChanged(infoPtr
);
1817 return DATETIME_SetFont(infoPtr
, (HFONT
)wParam
, (BOOL
)lParam
);
1820 return (LRESULT
) infoPtr
->hFont
;
1823 return (LRESULT
) DATETIME_GetText(infoPtr
, wParam
, (LPWSTR
)lParam
);
1825 case WM_GETTEXTLENGTH
:
1826 return (LRESULT
)DATETIME_GetTextLength(infoPtr
);
1832 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
1833 ERR("unknown msg %04x, wp %Ix, lp %Ix\n", uMsg
, wParam
, lParam
);
1834 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
1840 DATETIME_Register (void)
1844 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
1845 wndClass
.style
= CS_GLOBALCLASS
;
1846 wndClass
.lpfnWndProc
= DATETIME_WindowProc
;
1847 wndClass
.cbClsExtra
= 0;
1848 wndClass
.cbWndExtra
= sizeof(DATETIME_INFO
*);
1849 wndClass
.hCursor
= LoadCursorW (0, (LPCWSTR
)IDC_ARROW
);
1850 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
1851 wndClass
.lpszClassName
= DATETIMEPICK_CLASSW
;
1853 RegisterClassW (&wndClass
);
1858 DATETIME_Unregister (void)
1860 UnregisterClassW (DATETIMEPICK_CLASSW
, NULL
);