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
;
85 extern int MONTHCAL_MonthLength(int month
, int year
);
86 extern int MONTHCAL_CalculateDayOfWeek(SYSTEMTIME
*date
, BOOL inplace
);
88 /* this list of defines is closely related to `allowedformatchars' defined
89 * in datetime.c; the high nibble indicates the `base type' of the format
91 * Do not change without first reading DATETIME_UseFormat.
95 #define DT_END_FORMAT 0
96 #define ONEDIGITDAY 0x01
97 #define TWODIGITDAY 0x02
98 #define THREECHARDAY 0x03
100 #define ONEDIGIT12HOUR 0x11
101 #define TWODIGIT12HOUR 0x12
102 #define ONEDIGIT24HOUR 0x21
103 #define TWODIGIT24HOUR 0x22
104 #define ONEDIGITMINUTE 0x31
105 #define TWODIGITMINUTE 0x32
106 #define ONEDIGITMONTH 0x41
107 #define TWODIGITMONTH 0x42
108 #define THREECHARMONTH 0x43
109 #define FULLMONTH 0x44
110 #define ONEDIGITSECOND 0x51
111 #define TWODIGITSECOND 0x52
112 #define ONELETTERAMPM 0x61
113 #define TWOLETTERAMPM 0x62
114 #define ONEDIGITYEAR 0x71
115 #define TWODIGITYEAR 0x72
116 #define INVALIDFULLYEAR 0x73 /* FIXME - yyy is not valid - we'll treat it as yyyy */
117 #define FULLYEAR 0x74
118 #define FORMATCALLBACK 0x81 /* -> maximum of 0x80 callbacks possible */
119 #define FORMATCALLMASK 0x80
120 #define DT_STRING 0x0100
122 #define DTHT_DATEFIELD 0xff /* for hit-testing */
124 #define DTHT_NONE 0x1000
125 #define DTHT_CHECKBOX 0x2000 /* these should end at '00' , to make */
126 #define DTHT_MCPOPUP 0x3000 /* & DTHT_DATEFIELD 0 when DATETIME_KeyDown */
127 #define DTHT_GOTFOCUS 0x4000 /* tests for date-fields */
128 #define DTHT_NODATEMASK 0xf000 /* to mask check and drop down from others */
130 static BOOL
DATETIME_SendSimpleNotify (const DATETIME_INFO
*infoPtr
, UINT code
);
131 static BOOL
DATETIME_SendDateTimeChangeNotify (const DATETIME_INFO
*infoPtr
);
132 static const WCHAR allowedformatchars
[] = L
"dhHmMstyX";
133 static const int maxrepetition
[] = {4,2,2,2,4,2,2,4,-1};
134 static const WCHAR
*themeClass
= WC_SCROLLBARW
;
136 /* valid date limits */
137 static const SYSTEMTIME max_allowed_date
= { .wYear
= 9999, .wMonth
= 12, .wDayOfWeek
= 0, .wDay
= 31 };
138 static const SYSTEMTIME min_allowed_date
= { .wYear
= 1752, .wMonth
= 9, .wDayOfWeek
= 0, .wDay
= 14 };
141 DATETIME_GetSystemTime (const DATETIME_INFO
*infoPtr
, SYSTEMTIME
*systime
)
143 if (!systime
) return GDT_NONE
;
145 if ((infoPtr
->dwStyle
& DTS_SHOWNONE
) &&
146 (SendMessageW (infoPtr
->hwndCheckbut
, BM_GETCHECK
, 0, 0) == BST_UNCHECKED
))
149 *systime
= infoPtr
->date
;
154 /* Checks value is within configured date range
158 * [I] infoPtr : valid pointer to control data
159 * [I] date : pointer to valid date data to check
163 * TRUE - date within configured range
164 * FALSE - date is outside configured range
166 static BOOL
DATETIME_IsDateInValidRange(const DATETIME_INFO
*infoPtr
, const SYSTEMTIME
*date
)
171 if ((MONTHCAL_CompareSystemTime(date
, &max_allowed_date
) == 1) ||
172 (MONTHCAL_CompareSystemTime(date
, &min_allowed_date
) == -1))
175 limits
= SendMessageW (infoPtr
->hMonthCal
, MCM_GETRANGE
, 0, (LPARAM
)range
);
177 if (limits
& GDTR_MAX
)
179 if (MONTHCAL_CompareSystemTime(date
, &range
[1]) == 1)
183 if (limits
& GDTR_MIN
)
185 if (MONTHCAL_CompareSystemTime(date
, &range
[0]) == -1)
193 DATETIME_SetSystemTime (DATETIME_INFO
*infoPtr
, DWORD flag
, const SYSTEMTIME
*systime
)
195 if (!systime
) return FALSE
;
197 TRACE("%04d/%02d/%02d %02d:%02d:%02d\n",
198 systime
->wYear
, systime
->wMonth
, systime
->wDay
,
199 systime
->wHour
, systime
->wMinute
, systime
->wSecond
);
201 if (flag
== GDT_VALID
) {
202 if (systime
->wYear
== 0 ||
203 systime
->wMonth
< 1 || systime
->wMonth
> 12 ||
205 systime
->wDay
> MONTHCAL_MonthLength(systime
->wMonth
, systime
->wYear
) ||
206 systime
->wHour
> 23 ||
207 systime
->wMinute
> 59 ||
208 systime
->wSecond
> 59 ||
209 systime
->wMilliseconds
> 999
213 /* Windows returns true if the date is valid but outside the limits set */
214 if (!DATETIME_IsDateInValidRange(infoPtr
, systime
))
217 infoPtr
->dateValid
= TRUE
;
218 infoPtr
->date
= *systime
;
219 /* always store a valid day of week */
220 MONTHCAL_CalculateDayOfWeek(&infoPtr
->date
, TRUE
);
222 SendMessageW (infoPtr
->hMonthCal
, MCM_SETCURSEL
, 0, (LPARAM
)(&infoPtr
->date
));
223 SendMessageW (infoPtr
->hwndCheckbut
, BM_SETCHECK
, BST_CHECKED
, 0);
224 } else if ((infoPtr
->dwStyle
& DTS_SHOWNONE
) && (flag
== GDT_NONE
)) {
225 infoPtr
->dateValid
= FALSE
;
226 SendMessageW (infoPtr
->hwndCheckbut
, BM_SETCHECK
, BST_UNCHECKED
, 0);
231 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
237 * Split up a formattxt in actions.
238 * See ms documentation for the meaning of the letter codes/'specifiers'.
241 * *'dddddd' is handled as 'dddd' plus 'dd'.
242 * *unrecognized formats are strings (here given the type DT_STRING;
243 * start of the string is encoded in lower bits of DT_STRING.
244 * Therefore, 'string' ends up as '<show seconds>tring'.
248 DATETIME_UseFormat (DATETIME_INFO
*infoPtr
, LPCWSTR formattxt
)
252 BOOL inside_literal
= FALSE
; /* inside '...' */
253 int *nrFields
= &infoPtr
->nrFields
;
256 infoPtr
->fieldspec
[*nrFields
] = 0;
257 len
= lstrlenW(allowedformatchars
);
260 for (i
= 0; formattxt
[i
]; i
++) {
261 TRACE ("\n%d %c:", i
, formattxt
[i
]);
262 if (!inside_literal
) {
263 for (j
= 0; j
< len
; j
++) {
264 if (allowedformatchars
[j
]==formattxt
[i
]) {
265 TRACE ("%c[%d,%x]", allowedformatchars
[j
], *nrFields
, infoPtr
->fieldspec
[*nrFields
]);
266 if ((*nrFields
==0) && (infoPtr
->fieldspec
[*nrFields
]==0)) {
267 infoPtr
->fieldspec
[*nrFields
] = (j
<<4) + 1;
270 if (infoPtr
->fieldspec
[*nrFields
] >> 4 != j
) {
272 infoPtr
->fieldspec
[*nrFields
] = (j
<<4) + 1;
275 if ((infoPtr
->fieldspec
[*nrFields
] & 0x0f) == maxrepetition
[j
]) {
277 infoPtr
->fieldspec
[*nrFields
] = (j
<<4) + 1;
280 infoPtr
->fieldspec
[*nrFields
]++;
282 } /* if allowedformatchar */
288 if (formattxt
[i
] == '\'')
290 inside_literal
= !inside_literal
;
294 /* char is not a specifier: handle char like a string */
296 if ((*nrFields
==0) && (infoPtr
->fieldspec
[*nrFields
]==0)) {
297 infoPtr
->fieldspec
[*nrFields
] = DT_STRING
+ k
;
298 infoPtr
->buflen
[*nrFields
] = 0;
299 } else if ((infoPtr
->fieldspec
[*nrFields
] & DT_STRING
) != DT_STRING
) {
301 infoPtr
->fieldspec
[*nrFields
] = DT_STRING
+ k
;
302 infoPtr
->buflen
[*nrFields
] = 0;
304 infoPtr
->textbuf
[k
] = formattxt
[i
];
306 infoPtr
->buflen
[*nrFields
]++;
309 if (*nrFields
== infoPtr
->nrFieldsAllocated
) {
310 FIXME ("out of memory; should reallocate. crash ahead.\n");
316 if (infoPtr
->fieldspec
[*nrFields
] != 0) (*nrFields
)++;
321 DATETIME_SetFormatW (DATETIME_INFO
*infoPtr
, LPCWSTR format
)
323 WCHAR format_buf
[80];
328 if ((infoPtr
->dwStyle
& DTS_SHORTDATECENTURYFORMAT
) == DTS_SHORTDATECENTURYFORMAT
)
329 format_item
= LOCALE_SSHORTDATE
;
330 else if ((infoPtr
->dwStyle
& DTS_LONGDATEFORMAT
) == DTS_LONGDATEFORMAT
)
331 format_item
= LOCALE_SLONGDATE
;
332 else if ((infoPtr
->dwStyle
& DTS_TIMEFORMAT
) == DTS_TIMEFORMAT
)
333 format_item
= LOCALE_STIMEFORMAT
;
334 else /* DTS_SHORTDATEFORMAT */
335 format_item
= LOCALE_SSHORTDATE
;
336 GetLocaleInfoW(LOCALE_USER_DEFAULT
, format_item
, format_buf
, ARRAY_SIZE(format_buf
));
340 DATETIME_UseFormat (infoPtr
, format
);
341 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
348 DATETIME_SetFormatA (DATETIME_INFO
*infoPtr
, LPCSTR lpszFormat
)
352 INT len
= MultiByteToWideChar(CP_ACP
, 0, lpszFormat
, -1, NULL
, 0);
353 LPWSTR wstr
= Alloc(len
* sizeof(WCHAR
));
354 if (wstr
) MultiByteToWideChar(CP_ACP
, 0, lpszFormat
, -1, wstr
, len
);
355 retval
= DATETIME_SetFormatW (infoPtr
, wstr
);
360 return DATETIME_SetFormatW (infoPtr
, 0);
366 DATETIME_ReturnTxt (const DATETIME_INFO
*infoPtr
, int count
, LPWSTR result
, int resultSize
)
368 SYSTEMTIME date
= infoPtr
->date
;
373 TRACE ("%d,%d\n", infoPtr
->nrFields
, count
);
374 if (count
>infoPtr
->nrFields
|| count
< 0) {
375 WARN ("buffer overrun, have %d want %d\n", infoPtr
->nrFields
, count
);
379 if (!infoPtr
->fieldspec
) return;
381 spec
= infoPtr
->fieldspec
[count
];
382 if (spec
& DT_STRING
) {
383 int txtlen
= infoPtr
->buflen
[count
];
385 if (txtlen
> resultSize
)
386 txtlen
= resultSize
- 1;
387 memcpy (result
, infoPtr
->textbuf
+ (spec
&~ DT_STRING
), txtlen
* sizeof(WCHAR
));
389 TRACE ("arg%d=%x->[%s]\n", count
, infoPtr
->fieldspec
[count
], debugstr_w(result
));
399 wsprintfW (result
, L
"%d", date
.wDay
);
402 wsprintfW (result
, L
"%.2d", date
.wDay
);
405 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SABBREVDAYNAME1
+(date
.wDayOfWeek
+6)%7, result
, 4);
406 /*wsprintfW (result,"%.3s",days[date.wDayOfWeek]);*/
409 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SDAYNAME1
+(date
.wDayOfWeek
+6)%7, result
, resultSize
);
412 if (date
.wHour
== 0) {
418 wsprintfW (result
, L
"%d", date
.wHour
- (date
.wHour
> 12 ? 12 : 0));
421 if (date
.wHour
== 0) {
427 wsprintfW (result
, L
"%.2d", date
.wHour
- (date
.wHour
> 12 ? 12 : 0));
430 wsprintfW (result
, L
"%d", date
.wHour
);
433 wsprintfW (result
, L
"%.2d", date
.wHour
);
436 wsprintfW (result
, L
"%d", date
.wSecond
);
439 wsprintfW (result
, L
"%.2d", date
.wSecond
);
442 wsprintfW (result
, L
"%d", date
.wMinute
);
445 wsprintfW (result
, L
"%.2d", date
.wMinute
);
448 wsprintfW (result
, L
"%d", date
.wMonth
);
451 wsprintfW (result
, L
"%.2d", date
.wMonth
);
454 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SMONTHNAME1
+date
.wMonth
-1, buffer
, ARRAY_SIZE(buffer
));
455 wsprintfW (result
, L
"%s.3s", buffer
);
458 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SMONTHNAME1
+date
.wMonth
-1,
462 result
[0] = (date
.wHour
< 12 ? 'A' : 'P');
466 result
[0] = (date
.wHour
< 12 ? 'A' : 'P');
471 FIXME ("Not implemented\n");
476 wsprintfW (result
, L
"%d", date
.wYear
% 10);
479 wsprintfW (result
, L
"%.2d", date
.wYear
% 100);
481 case INVALIDFULLYEAR
:
483 wsprintfW (result
, L
"%d", date
.wYear
);
487 TRACE ("arg%d=%x->[%s]\n", count
, infoPtr
->fieldspec
[count
], debugstr_w(result
));
490 static int wrap(int val
, int delta
, int minVal
, int maxVal
)
493 if (delta
== INT_MIN
|| val
< minVal
) return maxVal
;
494 if (delta
== INT_MAX
|| val
> maxVal
) return minVal
;
499 DATETIME_IncreaseField (DATETIME_INFO
*infoPtr
, int number
, int delta
)
501 SYSTEMTIME
*date
= &infoPtr
->date
;
506 TRACE ("%d\n", number
);
507 if ((number
> infoPtr
->nrFields
) || (number
< 0)) return;
509 if ((infoPtr
->fieldspec
[number
] & DTHT_DATEFIELD
) == 0) return;
511 switch (infoPtr
->fieldspec
[number
]) {
515 if (delta
== INT_MIN
)
517 else if (delta
== INT_MAX
)
520 date
->wYear
= max(min(date
->wYear
+ delta
, 9999), 1752);
522 if (date
->wDay
> MONTHCAL_MonthLength(date
->wMonth
, date
->wYear
))
523 /* This can happen when moving away from a leap year. */
524 date
->wDay
= MONTHCAL_MonthLength(date
->wMonth
, date
->wYear
);
525 MONTHCAL_CalculateDayOfWeek(date
, TRUE
);
531 date
->wMonth
= wrap(date
->wMonth
, delta
, 1, 12);
532 MONTHCAL_CalculateDayOfWeek(date
, TRUE
);
539 date
->wDay
= wrap(date
->wDay
, delta
, 1, MONTHCAL_MonthLength(date
->wMonth
, date
->wYear
));
540 MONTHCAL_CalculateDayOfWeek(date
, TRUE
);
550 date
->wHour
= wrap(date
->wHour
, delta
, 0, 23);
554 date
->wMinute
= wrap(date
->wMinute
, delta
, 0, 59);
558 date
->wSecond
= wrap(date
->wSecond
, delta
, 0, 59);
561 FIXME ("Not implemented\n");
565 /* FYI: On 1752/9/14 the calendar changed and England and the
566 * American colonies changed to the Gregorian calendar. This change
567 * involved having September 14th follow September 2nd. So no date
568 * algorithm works before that date.
570 if (10000 * date
->wYear
+ 100 * date
->wMonth
+ date
->wDay
< 17520914) {
579 /* Ensure time is within bounds */
580 limits
= SendMessageW (infoPtr
->hMonthCal
, MCM_GETRANGE
, 0, (LPARAM
)range
);
583 if (limits
& (min
? GDTR_MIN
: GDTR_MAX
))
585 int i
= (min
? 0 : 1);
587 if (MONTHCAL_CompareSystemTime(date
, &range
[i
]) == (min
? -1 : 1))
589 date
->wYear
= range
[i
].wYear
;
590 date
->wMonth
= range
[i
].wMonth
;
591 date
->wDayOfWeek
= range
[i
].wDayOfWeek
;
592 date
->wDay
= range
[i
].wDay
;
593 date
->wHour
= range
[i
].wHour
;
594 date
->wMinute
= range
[i
].wMinute
;
595 date
->wSecond
= range
[i
].wSecond
;
596 date
->wMilliseconds
= range
[i
].wMilliseconds
;
601 static int DATETIME_GetFieldWidth (const DATETIME_INFO
*infoPtr
, HDC hdc
, int count
)
603 /* fields are a fixed width, determined by the largest possible string */
604 /* presumably, these widths should be language dependent */
610 if (!infoPtr
->fieldspec
) return 0;
612 spec
= infoPtr
->fieldspec
[count
];
613 if (spec
& DT_STRING
) {
614 int txtlen
= infoPtr
->buflen
[count
];
618 memcpy (buffer
, infoPtr
->textbuf
+ (spec
&~ DT_STRING
), txtlen
* sizeof(WCHAR
));
631 /* these seem to use a two byte field */
641 case INVALIDFULLYEAR
:
655 /* choose locale data type and fallback string */
659 lctype
= LOCALE_SABBREVDAYNAME1
;
664 lctype
= LOCALE_SDAYNAME1
;
669 lctype
= LOCALE_SABBREVMONTHNAME1
;
672 default: /* FULLMONTH */
674 lctype
= LOCALE_SMONTHNAME1
;
680 for (i
= 0; i
< max_count
; i
++)
682 if(GetLocaleInfoW(LOCALE_USER_DEFAULT
, lctype
+ i
,
683 buffer
, ARRAY_SIZE(buffer
)))
685 GetTextExtentPoint32W(hdc
, buffer
, lstrlenW(buffer
), &size
);
686 if (size
.cx
> cx
) cx
= size
.cx
;
688 else /* locale independent fallback on failure */
690 GetTextExtentPoint32W(hdc
, fall
, lstrlenW(fall
), &size
);
708 GetTextExtentPoint32W (hdc
, bufptr
, lstrlenW(bufptr
), &size
);
713 DATETIME_Refresh (DATETIME_INFO
*infoPtr
, HDC hdc
)
720 if (infoPtr
->dateValid
) {
723 RECT
*rcDraw
= &infoPtr
->rcDraw
;
725 COLORREF oldTextColor
;
726 HFONT oldFont
= SelectObject (hdc
, infoPtr
->hFont
);
727 INT oldBkMode
= SetBkMode (hdc
, TRANSPARENT
);
730 DATETIME_ReturnTxt (infoPtr
, 0, txt
, ARRAY_SIZE(txt
));
731 GetTextExtentPoint32W (hdc
, txt
, lstrlenW(txt
), &size
);
732 rcDraw
->bottom
= size
.cy
+ 2;
734 prevright
= infoPtr
->checkbox
.right
= ((infoPtr
->dwStyle
& DTS_SHOWNONE
) ? 18 : 2);
736 for (i
= 0; i
< infoPtr
->nrFields
; i
++) {
737 DATETIME_ReturnTxt (infoPtr
, i
, txt
, ARRAY_SIZE(txt
));
738 GetTextExtentPoint32W (hdc
, txt
, lstrlenW(txt
), &size
);
739 field
= &infoPtr
->fieldRect
[i
];
740 field
->left
= prevright
;
741 field
->right
= prevright
+ DATETIME_GetFieldWidth (infoPtr
, hdc
, i
);
742 field
->top
= rcDraw
->top
;
743 field
->bottom
= rcDraw
->bottom
;
744 prevright
= field
->right
;
746 if (infoPtr
->dwStyle
& WS_DISABLED
)
747 oldTextColor
= SetTextColor (hdc
, comctl32_color
.clrGrayText
);
748 else if ((infoPtr
->haveFocus
) && (i
== infoPtr
->select
)) {
751 /* fill if focused */
752 HBRUSH hbr
= CreateSolidBrush (comctl32_color
.clrActiveCaption
);
754 if (infoPtr
->nCharsEntered
)
756 memcpy(txt
, infoPtr
->charsEntered
, infoPtr
->nCharsEntered
* sizeof(WCHAR
));
757 txt
[infoPtr
->nCharsEntered
] = 0;
758 GetTextExtentPoint32W (hdc
, txt
, lstrlenW(txt
), &size
);
761 SetRect(&selection
, 0, 0, size
.cx
, size
.cy
);
762 /* center rectangle */
763 OffsetRect(&selection
, (field
->right
+ field
->left
- size
.cx
)/2,
764 (field
->bottom
- size
.cy
)/2);
766 FillRect(hdc
, &selection
, hbr
);
768 oldTextColor
= SetTextColor (hdc
, comctl32_color
.clrWindow
);
771 oldTextColor
= SetTextColor (hdc
, comctl32_color
.clrWindowText
);
773 /* draw the date text using the colour set above */
774 DrawTextW (hdc
, txt
, lstrlenW(txt
), field
, DT_CENTER
| DT_VCENTER
| DT_SINGLELINE
);
775 SetTextColor (hdc
, oldTextColor
);
777 SetBkMode (hdc
, oldBkMode
);
778 SelectObject (hdc
, oldFont
);
781 if (infoPtr
->dwStyle
& DTS_UPDOWN
)
784 theme
= GetWindowTheme(infoPtr
->hwndSelf
);
787 if (infoPtr
->dwStyle
& WS_DISABLED
)
788 state
= ABS_DOWNDISABLED
;
789 else if (infoPtr
->bCalDepressed
)
790 state
= ABS_DOWNPRESSED
;
791 else if (infoPtr
->bCalHot
)
794 state
= ABS_DOWNNORMAL
;
796 DrawThemeBackground(theme
, hdc
, SBP_ARROWBTN
, state
, &infoPtr
->calbutton
, NULL
);
800 DrawFrameControl(hdc
, &infoPtr
->calbutton
, DFC_SCROLL
,
801 DFCS_SCROLLDOWN
| (infoPtr
->bCalDepressed
? DFCS_PUSHED
: 0) |
802 (infoPtr
->dwStyle
& WS_DISABLED
? DFCS_INACTIVE
: 0) );
808 DATETIME_HitTest (const DATETIME_INFO
*infoPtr
, POINT pt
)
812 TRACE ("%s\n", wine_dbgstr_point(&pt
));
814 if (PtInRect (&infoPtr
->calbutton
, pt
)) return DTHT_MCPOPUP
;
815 if (PtInRect (&infoPtr
->checkbox
, pt
)) return DTHT_CHECKBOX
;
817 for (i
= 0; i
< infoPtr
->nrFields
; i
++) {
818 if (PtInRect (&infoPtr
->fieldRect
[i
], pt
)) return i
;
824 /* Returns index of the nearest preceding date field from given,
825 or -1 if none was found */
826 static int DATETIME_GetPrevDateField(const DATETIME_INFO
*infoPtr
, int i
)
828 for(--i
; i
>= 0; i
--)
830 if (infoPtr
->fieldspec
[i
] & DTHT_DATEFIELD
) return i
;
836 DATETIME_ApplySelectedField (DATETIME_INFO
*infoPtr
)
838 int fieldNum
= infoPtr
->select
& DTHT_DATEFIELD
;
840 BOOL clamp_day
= FALSE
;
841 SYSTEMTIME date
= infoPtr
->date
;
844 if (infoPtr
->select
== -1 || infoPtr
->nCharsEntered
== 0)
847 if ((infoPtr
->fieldspec
[fieldNum
] == ONELETTERAMPM
) ||
848 (infoPtr
->fieldspec
[fieldNum
] == TWOLETTERAMPM
))
849 val
= infoPtr
->charsEntered
[0];
851 for (i
=0; i
<infoPtr
->nCharsEntered
; i
++)
852 val
= val
* 10 + infoPtr
->charsEntered
[i
] - '0';
855 infoPtr
->nCharsEntered
= 0;
857 switch (infoPtr
->fieldspec
[fieldNum
]) {
860 oldyear
= date
.wYear
;
861 date
.wYear
= date
.wYear
- (date
.wYear
%100) + val
;
863 if (DATETIME_IsDateInValidRange(infoPtr
, &date
))
866 date
.wYear
= oldyear
;
869 case INVALIDFULLYEAR
:
871 oldyear
= date
.wYear
;
874 if (DATETIME_IsDateInValidRange(infoPtr
, &date
))
877 date
.wYear
= oldyear
;
897 if (date
.wHour
>= 12) /* preserve current AM/PM state */
898 date
.wHour
= (val
== 12 ? 12 : val
+ 12);
900 date
.wHour
= (val
== 12 ? 0 : val
);
917 if (val
== 'a' || val
== 'A') {
918 if (date
.wHour
>= 12)
920 } else if (val
== 'p' || val
== 'P') {
927 if (clamp_day
&& date
.wDay
> MONTHCAL_MonthLength(date
.wMonth
, date
.wYear
))
928 date
.wDay
= MONTHCAL_MonthLength(date
.wMonth
, date
.wYear
);
930 if (DATETIME_SetSystemTime(infoPtr
, GDT_VALID
, &date
))
931 DATETIME_SendDateTimeChangeNotify (infoPtr
);
935 DATETIME_SetSelectedField (DATETIME_INFO
*infoPtr
, int select
)
937 DATETIME_ApplySelectedField(infoPtr
);
939 infoPtr
->select
= select
;
940 infoPtr
->nCharsEntered
= 0;
944 DATETIME_LButtonDown (DATETIME_INFO
*infoPtr
, INT x
, INT y
)
951 new = DATETIME_HitTest (infoPtr
, pt
);
953 SetFocus(infoPtr
->hwndSelf
);
955 if (!(new & DTHT_NODATEMASK
) || (new == DTHT_NONE
))
957 if (new == DTHT_NONE
)
958 new = infoPtr
->nrFields
- 1;
961 /* hitting string part moves selection to next date field to left */
962 if (infoPtr
->fieldspec
[new] & DT_STRING
)
964 new = DATETIME_GetPrevDateField(infoPtr
, new);
965 if (new == -1) return 0;
967 /* never select full day of week */
968 if (infoPtr
->fieldspec
[new] == FULLDAY
) return 0;
972 DATETIME_SetSelectedField(infoPtr
, new);
974 if (infoPtr
->select
== DTHT_MCPOPUP
) {
977 SendMessageW(infoPtr
->hMonthCal
, MCM_GETMINREQRECT
, 0, (LPARAM
)&rcMonthCal
);
979 /* FIXME: button actually is only depressed during dropdown of the */
980 /* calendar control and when the mouse is over the button window */
981 infoPtr
->bCalDepressed
= TRUE
;
983 /* recalculate the position of the monthcal popup */
984 if(infoPtr
->dwStyle
& DTS_RIGHTALIGN
)
985 pos
.x
= infoPtr
->calbutton
.left
- (rcMonthCal
.right
- rcMonthCal
.left
);
987 /* FIXME: this should be after the area reserved for the checkbox */
988 pos
.x
= infoPtr
->rcDraw
.left
;
990 pos
.y
= infoPtr
->rcClient
.bottom
;
991 OffsetRect( &rcMonthCal
, pos
.x
, pos
.y
);
992 MapWindowPoints( infoPtr
->hwndSelf
, 0, (POINT
*)&rcMonthCal
, 2 );
993 SetWindowPos(infoPtr
->hMonthCal
, 0, rcMonthCal
.left
, rcMonthCal
.top
,
994 rcMonthCal
.right
- rcMonthCal
.left
, rcMonthCal
.bottom
- rcMonthCal
.top
, 0);
996 if(IsWindowVisible(infoPtr
->hMonthCal
)) {
997 ShowWindow(infoPtr
->hMonthCal
, SW_HIDE
);
998 infoPtr
->bDropdownEnabled
= FALSE
;
999 DATETIME_SendSimpleNotify (infoPtr
, DTN_CLOSEUP
);
1001 const SYSTEMTIME
*lprgSysTimeArray
= &infoPtr
->date
;
1002 TRACE("update calendar %04d/%02d/%02d\n",
1003 lprgSysTimeArray
->wYear
, lprgSysTimeArray
->wMonth
, lprgSysTimeArray
->wDay
);
1004 SendMessageW(infoPtr
->hMonthCal
, MCM_SETCURSEL
, 0, (LPARAM
)(&infoPtr
->date
));
1006 if (infoPtr
->bDropdownEnabled
) {
1007 ShowWindow(infoPtr
->hMonthCal
, SW_SHOW
);
1008 DATETIME_SendSimpleNotify (infoPtr
, DTN_DROPDOWN
);
1010 infoPtr
->bDropdownEnabled
= TRUE
;
1013 TRACE ("dt:%p mc:%p mc parent:%p, desktop:%p\n",
1014 infoPtr
->hwndSelf
, infoPtr
->hMonthCal
, infoPtr
->hwndNotify
, GetDesktopWindow ());
1017 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1024 DATETIME_LButtonUp (DATETIME_INFO
*infoPtr
)
1026 if(infoPtr
->bCalDepressed
) {
1027 infoPtr
->bCalDepressed
= FALSE
;
1028 InvalidateRect(infoPtr
->hwndSelf
, &(infoPtr
->calbutton
), TRUE
);
1036 DATETIME_Paint (DATETIME_INFO
*infoPtr
, HDC hdc
)
1040 hdc
= BeginPaint (infoPtr
->hwndSelf
, &ps
);
1041 DATETIME_Refresh (infoPtr
, hdc
);
1042 EndPaint (infoPtr
->hwndSelf
, &ps
);
1044 DATETIME_Refresh (infoPtr
, hdc
);
1047 /* Not a click on the dropdown box, enabled it */
1048 infoPtr
->bDropdownEnabled
= TRUE
;
1055 DATETIME_Button_Command (DATETIME_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
1057 if( HIWORD(wParam
) == BN_CLICKED
) {
1058 DWORD state
= SendMessageW((HWND
)lParam
, BM_GETCHECK
, 0, 0);
1059 infoPtr
->dateValid
= (state
== BST_CHECKED
);
1060 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1061 DATETIME_SendDateTimeChangeNotify(infoPtr
);
1069 DATETIME_Command (DATETIME_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
1071 TRACE("hwndbutton = %p\n", infoPtr
->hwndCheckbut
);
1072 if(infoPtr
->hwndCheckbut
== (HWND
)lParam
)
1073 return DATETIME_Button_Command(infoPtr
, wParam
, lParam
);
1079 DATETIME_Enable (DATETIME_INFO
*infoPtr
, BOOL bEnable
)
1081 TRACE("%p %s\n", infoPtr
, bEnable
? "TRUE" : "FALSE");
1083 infoPtr
->dwStyle
&= ~WS_DISABLED
;
1085 infoPtr
->dwStyle
|= WS_DISABLED
;
1087 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1094 DATETIME_EraseBackground (const DATETIME_INFO
*infoPtr
, HDC hdc
)
1096 HBRUSH hBrush
, hSolidBrush
= NULL
;
1099 if (infoPtr
->dwStyle
& WS_DISABLED
)
1100 hBrush
= hSolidBrush
= CreateSolidBrush(comctl32_color
.clrBtnFace
);
1103 hBrush
= (HBRUSH
)SendMessageW(infoPtr
->hwndNotify
, WM_CTLCOLOREDIT
,
1104 (WPARAM
)hdc
, (LPARAM
)infoPtr
->hwndSelf
);
1106 hBrush
= hSolidBrush
= CreateSolidBrush(comctl32_color
.clrWindow
);
1109 GetClientRect (infoPtr
->hwndSelf
, &rc
);
1111 FillRect (hdc
, &rc
, hBrush
);
1114 DeleteObject(hSolidBrush
);
1121 DATETIME_Notify (DATETIME_INFO
*infoPtr
, const NMHDR
*lpnmh
)
1123 TRACE ("Got notification %x from %p\n", lpnmh
->code
, lpnmh
->hwndFrom
);
1124 TRACE ("info: %p %p %p\n", infoPtr
->hwndSelf
, infoPtr
->hMonthCal
, infoPtr
->hUpdown
);
1126 if (lpnmh
->code
== MCN_SELECT
) {
1127 ShowWindow(infoPtr
->hMonthCal
, SW_HIDE
);
1128 infoPtr
->dateValid
= TRUE
;
1129 SendMessageW (infoPtr
->hMonthCal
, MCM_GETCURSEL
, 0, (LPARAM
)&infoPtr
->date
);
1130 TRACE("got from calendar %04d/%02d/%02d day of week %d\n",
1131 infoPtr
->date
.wYear
, infoPtr
->date
.wMonth
, infoPtr
->date
.wDay
, infoPtr
->date
.wDayOfWeek
);
1132 SendMessageW (infoPtr
->hwndCheckbut
, BM_SETCHECK
, BST_CHECKED
, 0);
1133 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1134 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1135 DATETIME_SendSimpleNotify(infoPtr
, DTN_CLOSEUP
);
1137 if ((lpnmh
->hwndFrom
== infoPtr
->hUpdown
) && (lpnmh
->code
== UDN_DELTAPOS
)) {
1138 const NM_UPDOWN
*lpnmud
= (const NM_UPDOWN
*)lpnmh
;
1139 TRACE("Delta pos %d\n", lpnmud
->iDelta
);
1140 infoPtr
->pendingUpdown
= lpnmud
->iDelta
;
1147 DATETIME_KeyDown (DATETIME_INFO
*infoPtr
, DWORD vkCode
)
1149 int fieldNum
= infoPtr
->select
& DTHT_DATEFIELD
;
1153 if (!(infoPtr
->haveFocus
)) return 0;
1154 if ((fieldNum
==0) && (infoPtr
->select
)) return 0;
1156 if (infoPtr
->select
& FORMATCALLMASK
) {
1157 FIXME ("Callbacks not implemented yet\n");
1163 infoPtr
->nCharsEntered
= 0;
1164 DATETIME_IncreaseField (infoPtr
, fieldNum
, 1);
1165 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1169 infoPtr
->nCharsEntered
= 0;
1170 DATETIME_IncreaseField (infoPtr
, fieldNum
, -1);
1171 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1174 infoPtr
->nCharsEntered
= 0;
1175 DATETIME_IncreaseField (infoPtr
, fieldNum
, INT_MIN
);
1176 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1179 infoPtr
->nCharsEntered
= 0;
1180 DATETIME_IncreaseField (infoPtr
, fieldNum
, INT_MAX
);
1181 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1184 new = infoPtr
->select
;
1192 } while ((infoPtr
->fieldspec
[new] & DT_STRING
) && (wrap
<2));
1193 if (new != infoPtr
->select
)
1194 DATETIME_SetSelectedField(infoPtr
, new);
1197 new = infoPtr
->select
;
1200 if (new==infoPtr
->nrFields
) {
1204 } while ((infoPtr
->fieldspec
[new] & DT_STRING
) && (wrap
<2));
1205 if (new != infoPtr
->select
)
1206 DATETIME_SetSelectedField(infoPtr
, new);
1210 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1217 DATETIME_Char (DATETIME_INFO
*infoPtr
, WPARAM vkCode
)
1219 int fieldNum
, fieldSpec
;
1221 fieldNum
= infoPtr
->select
& DTHT_DATEFIELD
;
1222 fieldSpec
= infoPtr
->fieldspec
[fieldNum
];
1224 if (fieldSpec
== ONELETTERAMPM
|| fieldSpec
== TWOLETTERAMPM
) {
1225 infoPtr
->charsEntered
[0] = vkCode
;
1226 infoPtr
->nCharsEntered
= 1;
1228 DATETIME_ApplySelectedField(infoPtr
);
1229 } else if (vkCode
>= '0' && vkCode
<= '9') {
1232 infoPtr
->charsEntered
[infoPtr
->nCharsEntered
++] = vkCode
;
1234 if (fieldSpec
== INVALIDFULLYEAR
|| fieldSpec
== FULLYEAR
)
1239 if ((fieldSpec
== ONEDIGIT12HOUR
||
1240 fieldSpec
== TWODIGIT12HOUR
||
1241 fieldSpec
== ONEDIGIT24HOUR
||
1242 fieldSpec
== TWODIGIT24HOUR
) &&
1243 (infoPtr
->nCharsEntered
== 1))
1249 if (maxChars
== infoPtr
->nCharsEntered
)
1250 DATETIME_ApplySelectedField(infoPtr
);
1258 DATETIME_VScroll (DATETIME_INFO
*infoPtr
, WORD wScroll
)
1260 int fieldNum
= infoPtr
->select
& DTHT_DATEFIELD
;
1262 if ((SHORT
)LOWORD(wScroll
) != SB_THUMBPOSITION
) return 0;
1263 if (!(infoPtr
->haveFocus
)) return 0;
1264 if ((fieldNum
==0) && (infoPtr
->select
)) return 0;
1266 if (infoPtr
->pendingUpdown
>= 0) {
1267 DATETIME_IncreaseField (infoPtr
, fieldNum
, 1);
1268 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1271 DATETIME_IncreaseField (infoPtr
, fieldNum
, -1);
1272 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1275 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1282 DATETIME_KillFocus (DATETIME_INFO
*infoPtr
, HWND lostFocus
)
1284 TRACE("lost focus to %p\n", lostFocus
);
1286 if (infoPtr
->haveFocus
) {
1287 DATETIME_SendSimpleNotify (infoPtr
, NM_KILLFOCUS
);
1288 infoPtr
->haveFocus
= 0;
1289 DATETIME_SetSelectedField (infoPtr
, -1);
1292 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
1299 DATETIME_NCCreate (HWND hwnd
, const CREATESTRUCTW
*lpcs
)
1301 DWORD dwExStyle
= GetWindowLongW(hwnd
, GWL_EXSTYLE
);
1302 /* force control to have client edge */
1303 dwExStyle
|= WS_EX_CLIENTEDGE
;
1304 SetWindowLongW(hwnd
, GWL_EXSTYLE
, dwExStyle
);
1309 static LRESULT
DATETIME_NCPaint (HWND hwnd
, HRGN region
)
1318 theme
= OpenThemeDataForDpi(NULL
, WC_EDITW
, GetDpiForWindow(hwnd
));
1320 return DefWindowProcW(hwnd
, WM_NCPAINT
, (WPARAM
)region
, 0);
1322 exStyle
= GetWindowLongW(hwnd
, GWL_EXSTYLE
);
1323 if (!(exStyle
& WS_EX_CLIENTEDGE
))
1325 CloseThemeData(theme
);
1326 return DefWindowProcW(hwnd
, WM_NCPAINT
, (WPARAM
)region
, 0);
1329 cxEdge
= GetSystemMetrics(SM_CXEDGE
);
1330 cyEdge
= GetSystemMetrics(SM_CYEDGE
);
1331 GetWindowRect(hwnd
, &r
);
1333 /* New clipping region passed to default proc to exclude border */
1334 clipRgn
= CreateRectRgn(r
.left
+ cxEdge
, r
.top
+ cyEdge
, r
.right
- cxEdge
, r
.bottom
- cyEdge
);
1335 if (region
!= (HRGN
)1)
1336 CombineRgn(clipRgn
, clipRgn
, region
, RGN_AND
);
1337 OffsetRect(&r
, -r
.left
, -r
.top
);
1339 dc
= GetDCEx(hwnd
, region
, DCX_WINDOW
| DCX_INTERSECTRGN
);
1340 if (IsThemeBackgroundPartiallyTransparent(theme
, 0, 0))
1341 DrawThemeParentBackground(hwnd
, dc
, &r
);
1342 DrawThemeBackground(theme
, dc
, 0, 0, &r
, 0);
1343 ReleaseDC(hwnd
, dc
);
1344 CloseThemeData(theme
);
1346 /* Call default proc to get the scrollbars etc. also painted */
1347 DefWindowProcW(hwnd
, WM_NCPAINT
, (WPARAM
)clipRgn
, 0);
1348 DeleteObject(clipRgn
);
1352 static LRESULT
DATETIME_MouseMove (DATETIME_INFO
*infoPtr
, LONG x
, LONG y
)
1354 TRACKMOUSEEVENT event
;
1360 hot
= PtInRect(&infoPtr
->calbutton
, point
);
1361 if (hot
!= infoPtr
->bCalHot
)
1363 infoPtr
->bCalHot
= hot
;
1364 RedrawWindow(infoPtr
->hwndSelf
, &infoPtr
->calbutton
, 0, RDW_INVALIDATE
| RDW_UPDATENOW
);
1370 event
.cbSize
= sizeof(TRACKMOUSEEVENT
);
1371 event
.dwFlags
= TME_QUERY
;
1372 if (!TrackMouseEvent(&event
) || event
.hwndTrack
!= infoPtr
->hwndSelf
|| !(event
.dwFlags
& TME_LEAVE
))
1374 event
.hwndTrack
= infoPtr
->hwndSelf
;
1375 event
.dwFlags
= TME_LEAVE
;
1376 TrackMouseEvent(&event
);
1382 static LRESULT
DATETIME_MouseLeave (DATETIME_INFO
*infoPtr
)
1384 infoPtr
->bCalHot
= FALSE
;
1385 RedrawWindow(infoPtr
->hwndSelf
, &infoPtr
->calbutton
, 0, RDW_INVALIDATE
| RDW_UPDATENOW
);
1390 DATETIME_SetFocus (DATETIME_INFO
*infoPtr
, HWND lostFocus
)
1392 TRACE("got focus from %p\n", lostFocus
);
1394 /* if monthcal is open and it loses focus, close monthcal */
1395 if (infoPtr
->hMonthCal
&& (lostFocus
== infoPtr
->hMonthCal
) &&
1396 IsWindowVisible(infoPtr
->hMonthCal
))
1398 ShowWindow(infoPtr
->hMonthCal
, SW_HIDE
);
1399 DATETIME_SendSimpleNotify(infoPtr
, DTN_CLOSEUP
);
1400 /* note: this get triggered even if monthcal loses focus to a dropdown
1401 * box click, which occurs without an intermediate WM_PAINT call
1403 infoPtr
->bDropdownEnabled
= FALSE
;
1407 if (infoPtr
->haveFocus
== 0) {
1408 DATETIME_SendSimpleNotify (infoPtr
, NM_SETFOCUS
);
1409 infoPtr
->haveFocus
= DTHT_GOTFOCUS
;
1412 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1419 DATETIME_SendDateTimeChangeNotify (const DATETIME_INFO
*infoPtr
)
1421 NMDATETIMECHANGE dtdtc
;
1423 dtdtc
.nmhdr
.hwndFrom
= infoPtr
->hwndSelf
;
1424 dtdtc
.nmhdr
.idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1425 dtdtc
.nmhdr
.code
= DTN_DATETIMECHANGE
;
1427 dtdtc
.dwFlags
= infoPtr
->dateValid
? GDT_VALID
: GDT_NONE
;
1429 dtdtc
.st
= infoPtr
->date
;
1430 return (BOOL
) SendMessageW (infoPtr
->hwndNotify
, WM_NOTIFY
,
1431 dtdtc
.nmhdr
.idFrom
, (LPARAM
)&dtdtc
);
1436 DATETIME_SendSimpleNotify (const DATETIME_INFO
*infoPtr
, UINT code
)
1440 TRACE("%x\n", code
);
1441 nmhdr
.hwndFrom
= infoPtr
->hwndSelf
;
1442 nmhdr
.idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1445 return (BOOL
) SendMessageW (infoPtr
->hwndNotify
, WM_NOTIFY
,
1446 nmhdr
.idFrom
, (LPARAM
)&nmhdr
);
1450 DATETIME_Size (DATETIME_INFO
*infoPtr
, INT width
, INT height
)
1453 infoPtr
->rcClient
.bottom
= height
;
1454 infoPtr
->rcClient
.right
= width
;
1456 TRACE("Height %ld, Width %ld\n", infoPtr
->rcClient
.bottom
, infoPtr
->rcClient
.right
);
1458 infoPtr
->rcDraw
= infoPtr
->rcClient
;
1460 if (infoPtr
->dwStyle
& DTS_UPDOWN
) {
1461 SetWindowPos(infoPtr
->hUpdown
, NULL
,
1462 infoPtr
->rcClient
.right
-14, 0,
1463 15, infoPtr
->rcClient
.bottom
- infoPtr
->rcClient
.top
,
1464 SWP_NOACTIVATE
| SWP_NOZORDER
);
1467 /* set the size of the button that drops the calendar down */
1468 /* FIXME: account for style that allows button on left side */
1469 infoPtr
->calbutton
.top
= infoPtr
->rcDraw
.top
;
1470 infoPtr
->calbutton
.bottom
= infoPtr
->rcDraw
.bottom
;
1471 infoPtr
->calbutton
.left
= infoPtr
->rcDraw
.right
-15;
1472 infoPtr
->calbutton
.right
= infoPtr
->rcDraw
.right
;
1475 /* set enable/disable button size for show none style being enabled */
1476 /* FIXME: these dimensions are completely incorrect */
1477 infoPtr
->checkbox
.top
= infoPtr
->rcDraw
.top
;
1478 infoPtr
->checkbox
.bottom
= infoPtr
->rcDraw
.bottom
;
1479 infoPtr
->checkbox
.left
= infoPtr
->rcDraw
.left
;
1480 infoPtr
->checkbox
.right
= infoPtr
->rcDraw
.left
+ 10;
1482 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1488 DATETIME_StyleChanging(DATETIME_INFO
*infoPtr
, WPARAM wStyleType
, STYLESTRUCT
*lpss
)
1490 TRACE("styletype %Ix, styleOld %#lx, styleNew %#lx\n", wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
1492 /* block DTS_SHOWNONE change */
1493 if ((lpss
->styleNew
^ lpss
->styleOld
) & DTS_SHOWNONE
)
1495 if (lpss
->styleOld
& DTS_SHOWNONE
)
1496 lpss
->styleNew
|= DTS_SHOWNONE
;
1498 lpss
->styleNew
&= ~DTS_SHOWNONE
;
1505 DATETIME_StyleChanged(DATETIME_INFO
*infoPtr
, WPARAM wStyleType
, const STYLESTRUCT
*lpss
)
1507 TRACE("styletype %Ix, styleOld %#lx, styleNew %#lx\n", wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
1509 if (wStyleType
!= GWL_STYLE
) return 0;
1511 infoPtr
->dwStyle
= lpss
->styleNew
;
1513 if ( !(lpss
->styleOld
& DTS_SHOWNONE
) && (lpss
->styleNew
& DTS_SHOWNONE
) ) {
1514 infoPtr
->hwndCheckbut
= CreateWindowExW (0, WC_BUTTONW
, 0, WS_CHILD
| WS_VISIBLE
| BS_AUTOCHECKBOX
,
1515 2, 2, 13, 13, infoPtr
->hwndSelf
, 0,
1516 (HINSTANCE
)GetWindowLongPtrW (infoPtr
->hwndSelf
, GWLP_HINSTANCE
), 0);
1517 SendMessageW (infoPtr
->hwndCheckbut
, BM_SETCHECK
, infoPtr
->dateValid
? 1 : 0, 0);
1519 if ( (lpss
->styleOld
& DTS_SHOWNONE
) && !(lpss
->styleNew
& DTS_SHOWNONE
) ) {
1520 DestroyWindow(infoPtr
->hwndCheckbut
);
1521 infoPtr
->hwndCheckbut
= 0;
1523 if ( !(lpss
->styleOld
& DTS_UPDOWN
) && (lpss
->styleNew
& DTS_UPDOWN
) ) {
1524 infoPtr
->hUpdown
= CreateUpDownControl (WS_CHILD
| WS_BORDER
| WS_VISIBLE
, 120, 1, 20, 20,
1525 infoPtr
->hwndSelf
, 1, 0, 0, UD_MAXVAL
, UD_MINVAL
, 0);
1527 if ( (lpss
->styleOld
& DTS_UPDOWN
) && !(lpss
->styleNew
& DTS_UPDOWN
) ) {
1528 DestroyWindow(infoPtr
->hUpdown
);
1529 infoPtr
->hUpdown
= 0;
1534 static LRESULT
DATETIME_ThemeChanged (DATETIME_INFO
*infoPtr
)
1538 theme
= GetWindowTheme(infoPtr
->hwndSelf
);
1539 CloseThemeData(theme
);
1540 OpenThemeData(infoPtr
->hwndSelf
, themeClass
);
1541 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1545 static BOOL
DATETIME_GetIdealSize(DATETIME_INFO
*infoPtr
, SIZE
*size
)
1554 size
->cx
= size
->cy
= 0;
1556 hdc
= GetDC(infoPtr
->hwndSelf
);
1557 oldFont
= SelectObject(hdc
, infoPtr
->hFont
);
1559 /* Get text font height */
1560 DATETIME_ReturnTxt(infoPtr
, 0, txt
, ARRAY_SIZE(txt
));
1561 GetTextExtentPoint32W(hdc
, txt
, lstrlenW(txt
), &field_size
);
1562 size
->cy
= field_size
.cy
;
1564 /* Get text font width */
1565 for (i
= 0; i
< infoPtr
->nrFields
; i
++)
1567 size
->cx
+= DATETIME_GetFieldWidth(infoPtr
, hdc
, i
);
1570 SelectObject(hdc
, oldFont
);
1571 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
1573 if (infoPtr
->dwStyle
& DTS_UPDOWN
)
1575 GetWindowRect(infoPtr
->hUpdown
, &rect
);
1576 size
->cx
+= rect
.right
- rect
.left
;
1580 size
->cx
+= infoPtr
->calbutton
.right
- infoPtr
->calbutton
.left
;
1583 if (infoPtr
->dwStyle
& DTS_SHOWNONE
)
1585 size
->cx
+= infoPtr
->checkbox
.right
- infoPtr
->checkbox
.left
;
1588 /* Add space between controls for them not to get too close */
1592 TRACE("cx %ld, cy %ld\n", size
->cx
, size
->cy
);
1597 DATETIME_SetFont (DATETIME_INFO
*infoPtr
, HFONT font
, BOOL repaint
)
1599 infoPtr
->hFont
= font
;
1600 if (repaint
) InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1606 DATETIME_Create (HWND hwnd
, const CREATESTRUCTW
*lpcs
)
1608 DATETIME_INFO
*infoPtr
= Alloc (sizeof(DATETIME_INFO
));
1609 STYLESTRUCT ss
= { 0, lpcs
->style
};
1611 if (!infoPtr
) return -1;
1613 infoPtr
->hwndSelf
= hwnd
;
1614 infoPtr
->dwStyle
= lpcs
->style
;
1616 infoPtr
->nrFieldsAllocated
= 32;
1617 infoPtr
->fieldspec
= Alloc (infoPtr
->nrFieldsAllocated
* sizeof(int));
1618 infoPtr
->fieldRect
= Alloc (infoPtr
->nrFieldsAllocated
* sizeof(RECT
));
1619 infoPtr
->buflen
= Alloc (infoPtr
->nrFieldsAllocated
* sizeof(int));
1620 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
1621 infoPtr
->select
= -1; /* initially, nothing is selected */
1622 infoPtr
->bDropdownEnabled
= TRUE
;
1623 infoPtr
->bCalHot
= FALSE
;
1625 DATETIME_StyleChanged(infoPtr
, GWL_STYLE
, &ss
);
1626 DATETIME_SetFormatW (infoPtr
, 0);
1628 /* create the monthcal control */
1629 infoPtr
->hMonthCal
= CreateWindowExW (0, MONTHCAL_CLASSW
, 0, WS_BORDER
| WS_POPUP
| WS_CLIPSIBLINGS
,
1630 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, 0, 0);
1632 /* initialize info structure */
1633 GetLocalTime (&infoPtr
->date
);
1634 infoPtr
->dateValid
= TRUE
;
1635 infoPtr
->hFont
= GetStockObject(DEFAULT_GUI_FONT
);
1637 SetWindowLongPtrW (hwnd
, 0, (DWORD_PTR
)infoPtr
);
1638 OpenThemeData(hwnd
, themeClass
);
1646 DATETIME_Destroy (DATETIME_INFO
*infoPtr
)
1650 theme
= GetWindowTheme(infoPtr
->hwndSelf
);
1651 CloseThemeData(theme
);
1653 if (infoPtr
->hwndCheckbut
)
1654 DestroyWindow(infoPtr
->hwndCheckbut
);
1655 if (infoPtr
->hUpdown
)
1656 DestroyWindow(infoPtr
->hUpdown
);
1657 if (infoPtr
->hMonthCal
)
1658 DestroyWindow(infoPtr
->hMonthCal
);
1659 SetWindowLongPtrW( infoPtr
->hwndSelf
, 0, 0 ); /* clear infoPtr */
1660 Free (infoPtr
->buflen
);
1661 Free (infoPtr
->fieldRect
);
1662 Free (infoPtr
->fieldspec
);
1669 DATETIME_GetText (const DATETIME_INFO
*infoPtr
, INT count
, LPWSTR dst
)
1674 if (!dst
|| (count
<= 0)) return 0;
1677 for (i
= 0; i
< infoPtr
->nrFields
; i
++)
1679 DATETIME_ReturnTxt(infoPtr
, i
, buf
, ARRAY_SIZE(buf
));
1680 if ((lstrlenW(dst
) + lstrlenW(buf
)) < count
)
1684 return lstrlenW(dst
);
1687 static int DATETIME_GetTextLength(const DATETIME_INFO
*info
)
1692 TRACE("%p.\n", info
);
1694 for (i
= 0; i
< info
->nrFields
; i
++)
1696 DATETIME_ReturnTxt(info
, i
, buffer
, ARRAY_SIZE(buffer
));
1697 length
+= lstrlenW(buffer
);
1702 static LRESULT WINAPI
1703 DATETIME_WindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1705 DATETIME_INFO
*infoPtr
= ((DATETIME_INFO
*)GetWindowLongPtrW (hwnd
, 0));
1707 TRACE("%x, %Ix, %Ix\n", uMsg
, wParam
, lParam
);
1709 if (!infoPtr
&& (uMsg
!= WM_CREATE
) && (uMsg
!= WM_NCCREATE
))
1710 return DefWindowProcW( hwnd
, uMsg
, wParam
, lParam
);
1714 case DTM_GETSYSTEMTIME
:
1715 return DATETIME_GetSystemTime (infoPtr
, (SYSTEMTIME
*) lParam
);
1717 case DTM_SETSYSTEMTIME
:
1718 return DATETIME_SetSystemTime (infoPtr
, wParam
, (SYSTEMTIME
*) lParam
);
1721 return SendMessageW (infoPtr
->hMonthCal
, MCM_GETRANGE
, wParam
, lParam
);
1724 return SendMessageW (infoPtr
->hMonthCal
, MCM_SETRANGE
, wParam
, lParam
);
1726 case DTM_SETFORMATA
:
1727 return DATETIME_SetFormatA (infoPtr
, (LPCSTR
)lParam
);
1729 case DTM_SETFORMATW
:
1730 return DATETIME_SetFormatW (infoPtr
, (LPCWSTR
)lParam
);
1732 case DTM_GETMONTHCAL
:
1733 return (LRESULT
)infoPtr
->hMonthCal
;
1735 case DTM_SETMCCOLOR
:
1736 return SendMessageW (infoPtr
->hMonthCal
, MCM_SETCOLOR
, wParam
, lParam
);
1738 case DTM_GETMCCOLOR
:
1739 return SendMessageW (infoPtr
->hMonthCal
, MCM_GETCOLOR
, wParam
, 0);
1742 return SendMessageW (infoPtr
->hMonthCal
, WM_SETFONT
, wParam
, lParam
);
1745 return SendMessageW (infoPtr
->hMonthCal
, WM_GETFONT
, wParam
, lParam
);
1747 case DTM_GETIDEALSIZE
:
1748 return DATETIME_GetIdealSize(infoPtr
, (SIZE
*)lParam
);
1751 return DATETIME_Notify (infoPtr
, (LPNMHDR
)lParam
);
1754 return DATETIME_Enable (infoPtr
, (BOOL
)wParam
);
1757 return DATETIME_EraseBackground (infoPtr
, (HDC
)wParam
);
1760 return DLGC_WANTARROWS
| DLGC_WANTCHARS
;
1762 case WM_PRINTCLIENT
:
1764 return DATETIME_Paint (infoPtr
, (HDC
)wParam
);
1767 return DATETIME_KeyDown (infoPtr
, wParam
);
1770 return DATETIME_Char (infoPtr
, wParam
);
1773 return DATETIME_KillFocus (infoPtr
, (HWND
)wParam
);
1776 return DATETIME_NCCreate (hwnd
, (LPCREATESTRUCTW
)lParam
);
1779 return DATETIME_NCPaint(hwnd
, (HRGN
)wParam
);
1782 return DATETIME_MouseMove(infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
1785 return DATETIME_MouseLeave(infoPtr
);
1788 return DATETIME_SetFocus (infoPtr
, (HWND
)wParam
);
1791 return DATETIME_Size (infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
1793 case WM_LBUTTONDOWN
:
1794 return DATETIME_LButtonDown (infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
1797 return DATETIME_LButtonUp (infoPtr
);
1800 return DATETIME_VScroll (infoPtr
, (WORD
)wParam
);
1803 return DATETIME_Create (hwnd
, (LPCREATESTRUCTW
)lParam
);
1806 return DATETIME_Destroy (infoPtr
);
1809 return DATETIME_Command (infoPtr
, wParam
, lParam
);
1811 case WM_STYLECHANGING
:
1812 return DATETIME_StyleChanging(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
1814 case WM_STYLECHANGED
:
1815 return DATETIME_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
1817 case WM_THEMECHANGED
:
1818 return DATETIME_ThemeChanged(infoPtr
);
1821 return DATETIME_SetFont(infoPtr
, (HFONT
)wParam
, (BOOL
)lParam
);
1824 return (LRESULT
) infoPtr
->hFont
;
1827 return (LRESULT
) DATETIME_GetText(infoPtr
, wParam
, (LPWSTR
)lParam
);
1829 case WM_GETTEXTLENGTH
:
1830 return (LRESULT
)DATETIME_GetTextLength(infoPtr
);
1836 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
1837 ERR("unknown msg %04x, wp %Ix, lp %Ix\n", uMsg
, wParam
, lParam
);
1838 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
1844 DATETIME_Register (void)
1848 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
1849 wndClass
.style
= CS_GLOBALCLASS
;
1850 wndClass
.lpfnWndProc
= DATETIME_WindowProc
;
1851 wndClass
.cbClsExtra
= 0;
1852 wndClass
.cbWndExtra
= sizeof(DATETIME_INFO
*);
1853 wndClass
.hCursor
= LoadCursorW (0, (LPCWSTR
)IDC_ARROW
);
1854 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
1855 wndClass
.lpszClassName
= DATETIMEPICK_CLASSW
;
1857 RegisterClassW (&wndClass
);
1862 DATETIME_Unregister (void)
1864 UnregisterClassW (DATETIMEPICK_CLASSW
, NULL
);