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
46 #include "wine/debug.h"
47 #include "wine/unicode.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(datetime
);
61 RECT rcClient
; /* rect around the edge of the window */
62 RECT rcDraw
; /* rect inside of the border */
63 RECT checkbox
; /* checkbox allowing the control to be enabled/disabled */
64 RECT calbutton
; /* button that toggles the dropdown of the monthcal control */
65 BOOL bCalDepressed
; /* TRUE = cal button is depressed */
66 BOOL bDropdownEnabled
;
68 WCHAR charsEntered
[4];
71 int nrFieldsAllocated
;
80 } DATETIME_INFO
, *LPDATETIME_INFO
;
83 extern int MONTHCAL_MonthLength(int month
, int year
);
84 extern int MONTHCAL_CalculateDayOfWeek(SYSTEMTIME
*date
, BOOL inplace
);
86 /* this list of defines is closely related to `allowedformatchars' defined
87 * in datetime.c; the high nibble indicates the `base type' of the format
89 * Do not change without first reading DATETIME_UseFormat.
93 #define DT_END_FORMAT 0
94 #define ONEDIGITDAY 0x01
95 #define TWODIGITDAY 0x02
96 #define THREECHARDAY 0x03
98 #define ONEDIGIT12HOUR 0x11
99 #define TWODIGIT12HOUR 0x12
100 #define ONEDIGIT24HOUR 0x21
101 #define TWODIGIT24HOUR 0x22
102 #define ONEDIGITMINUTE 0x31
103 #define TWODIGITMINUTE 0x32
104 #define ONEDIGITMONTH 0x41
105 #define TWODIGITMONTH 0x42
106 #define THREECHARMONTH 0x43
107 #define FULLMONTH 0x44
108 #define ONEDIGITSECOND 0x51
109 #define TWODIGITSECOND 0x52
110 #define ONELETTERAMPM 0x61
111 #define TWOLETTERAMPM 0x62
112 #define ONEDIGITYEAR 0x71
113 #define TWODIGITYEAR 0x72
114 #define INVALIDFULLYEAR 0x73 /* FIXME - yyy is not valid - we'll treat it as yyyy */
115 #define FULLYEAR 0x74
116 #define FORMATCALLBACK 0x81 /* -> maximum of 0x80 callbacks possible */
117 #define FORMATCALLMASK 0x80
118 #define DT_STRING 0x0100
120 #define DTHT_DATEFIELD 0xff /* for hit-testing */
122 #define DTHT_NONE 0x1000
123 #define DTHT_CHECKBOX 0x2000 /* these should end at '00' , to make */
124 #define DTHT_MCPOPUP 0x3000 /* & DTHT_DATEFIELD 0 when DATETIME_KeyDown */
125 #define DTHT_GOTFOCUS 0x4000 /* tests for date-fields */
126 #define DTHT_NODATEMASK 0xf000 /* to mask check and drop down from others */
128 static BOOL
DATETIME_SendSimpleNotify (const DATETIME_INFO
*infoPtr
, UINT code
);
129 static BOOL
DATETIME_SendDateTimeChangeNotify (const DATETIME_INFO
*infoPtr
);
130 static const WCHAR allowedformatchars
[] = {'d', 'h', 'H', 'm', 'M', 's', 't', 'y', 'X', 0};
131 static const int maxrepetition
[] = {4,2,2,2,4,2,2,4,-1};
133 /* valid date limits */
134 static const SYSTEMTIME max_allowed_date
= { /* wYear */ 9999, /* wMonth */ 12, /* wDayOfWeek */ 0, /* wDay */ 31 };
135 static const SYSTEMTIME min_allowed_date
= { /* wYear */ 1752, /* wMonth */ 9, /* wDayOfWeek */ 0, /* wDay */ 14 };
138 DATETIME_GetSystemTime (const DATETIME_INFO
*infoPtr
, SYSTEMTIME
*systime
)
140 if (!systime
) return GDT_NONE
;
142 if ((infoPtr
->dwStyle
& DTS_SHOWNONE
) &&
143 (SendMessageW (infoPtr
->hwndCheckbut
, BM_GETCHECK
, 0, 0) == BST_UNCHECKED
))
146 *systime
= infoPtr
->date
;
151 /* Checks value is within configured date range
155 * [I] infoPtr : valid pointer to control data
156 * [I] date : pointer to valid date data to check
160 * TRUE - date within configured range
161 * FALSE - date is outside configured range
163 static BOOL
DATETIME_IsDateInValidRange(const DATETIME_INFO
*infoPtr
, const SYSTEMTIME
*date
)
168 if ((MONTHCAL_CompareSystemTime(date
, &max_allowed_date
) == 1) ||
169 (MONTHCAL_CompareSystemTime(date
, &min_allowed_date
) == -1))
172 limits
= SendMessageW (infoPtr
->hMonthCal
, MCM_GETRANGE
, 0, (LPARAM
)range
);
174 if (limits
& GDTR_MAX
)
176 if (MONTHCAL_CompareSystemTime(date
, &range
[1]) == 1)
180 if (limits
& GDTR_MIN
)
182 if (MONTHCAL_CompareSystemTime(date
, &range
[0]) == -1)
190 DATETIME_SetSystemTime (DATETIME_INFO
*infoPtr
, DWORD flag
, const SYSTEMTIME
*systime
)
192 if (!systime
) return FALSE
;
194 TRACE("%04d/%02d/%02d %02d:%02d:%02d\n",
195 systime
->wYear
, systime
->wMonth
, systime
->wDay
,
196 systime
->wHour
, systime
->wMinute
, systime
->wSecond
);
198 if (flag
== GDT_VALID
) {
199 if (systime
->wYear
== 0 ||
200 systime
->wMonth
< 1 || systime
->wMonth
> 12 ||
202 systime
->wDay
> MONTHCAL_MonthLength(systime
->wMonth
, systime
->wYear
) ||
203 systime
->wHour
> 23 ||
204 systime
->wMinute
> 59 ||
205 systime
->wSecond
> 59 ||
206 systime
->wMilliseconds
> 999
210 /* Windows returns true if the date is valid but outside the limits set */
211 if (!DATETIME_IsDateInValidRange(infoPtr
, systime
))
214 infoPtr
->dateValid
= TRUE
;
215 infoPtr
->date
= *systime
;
216 /* always store a valid day of week */
217 MONTHCAL_CalculateDayOfWeek(&infoPtr
->date
, TRUE
);
219 SendMessageW (infoPtr
->hMonthCal
, MCM_SETCURSEL
, 0, (LPARAM
)(&infoPtr
->date
));
220 SendMessageW (infoPtr
->hwndCheckbut
, BM_SETCHECK
, BST_CHECKED
, 0);
221 } else if ((infoPtr
->dwStyle
& DTS_SHOWNONE
) && (flag
== GDT_NONE
)) {
222 infoPtr
->dateValid
= FALSE
;
223 SendMessageW (infoPtr
->hwndCheckbut
, BM_SETCHECK
, BST_UNCHECKED
, 0);
228 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
234 * Split up a formattxt in actions.
235 * See ms documentation for the meaning of the letter codes/'specifiers'.
238 * *'dddddd' is handled as 'dddd' plus 'dd'.
239 * *unrecognized formats are strings (here given the type DT_STRING;
240 * start of the string is encoded in lower bits of DT_STRING.
241 * Therefore, 'string' ends finally up as '<show seconds>tring'.
245 DATETIME_UseFormat (DATETIME_INFO
*infoPtr
, LPCWSTR formattxt
)
249 BOOL inside_literal
= FALSE
; /* inside '...' */
250 int *nrFields
= &infoPtr
->nrFields
;
253 infoPtr
->fieldspec
[*nrFields
] = 0;
254 len
= strlenW(allowedformatchars
);
257 for (i
= 0; formattxt
[i
]; i
++) {
258 TRACE ("\n%d %c:", i
, formattxt
[i
]);
259 if (!inside_literal
) {
260 for (j
= 0; j
< len
; j
++) {
261 if (allowedformatchars
[j
]==formattxt
[i
]) {
262 TRACE ("%c[%d,%x]", allowedformatchars
[j
], *nrFields
, infoPtr
->fieldspec
[*nrFields
]);
263 if ((*nrFields
==0) && (infoPtr
->fieldspec
[*nrFields
]==0)) {
264 infoPtr
->fieldspec
[*nrFields
] = (j
<<4) + 1;
267 if (infoPtr
->fieldspec
[*nrFields
] >> 4 != j
) {
269 infoPtr
->fieldspec
[*nrFields
] = (j
<<4) + 1;
272 if ((infoPtr
->fieldspec
[*nrFields
] & 0x0f) == maxrepetition
[j
]) {
274 infoPtr
->fieldspec
[*nrFields
] = (j
<<4) + 1;
277 infoPtr
->fieldspec
[*nrFields
]++;
279 } /* if allowedformatchar */
285 if (formattxt
[i
] == '\'')
287 inside_literal
= !inside_literal
;
291 /* char is not a specifier: handle char like a string */
293 if ((*nrFields
==0) && (infoPtr
->fieldspec
[*nrFields
]==0)) {
294 infoPtr
->fieldspec
[*nrFields
] = DT_STRING
+ k
;
295 infoPtr
->buflen
[*nrFields
] = 0;
296 } else if ((infoPtr
->fieldspec
[*nrFields
] & DT_STRING
) != DT_STRING
) {
298 infoPtr
->fieldspec
[*nrFields
] = DT_STRING
+ k
;
299 infoPtr
->buflen
[*nrFields
] = 0;
301 infoPtr
->textbuf
[k
] = formattxt
[i
];
303 infoPtr
->buflen
[*nrFields
]++;
306 if (*nrFields
== infoPtr
->nrFieldsAllocated
) {
307 FIXME ("out of memory; should reallocate. crash ahead.\n");
313 if (infoPtr
->fieldspec
[*nrFields
] != 0) (*nrFields
)++;
318 DATETIME_SetFormatW (DATETIME_INFO
*infoPtr
, LPCWSTR format
)
320 WCHAR format_buf
[80];
325 if ((infoPtr
->dwStyle
& DTS_SHORTDATECENTURYFORMAT
) == DTS_SHORTDATECENTURYFORMAT
)
326 format_item
= LOCALE_SSHORTDATE
;
327 else if ((infoPtr
->dwStyle
& DTS_LONGDATEFORMAT
) == DTS_LONGDATEFORMAT
)
328 format_item
= LOCALE_SLONGDATE
;
329 else if ((infoPtr
->dwStyle
& DTS_TIMEFORMAT
) == DTS_TIMEFORMAT
)
330 format_item
= LOCALE_STIMEFORMAT
;
331 else /* DTS_SHORTDATEFORMAT */
332 format_item
= LOCALE_SSHORTDATE
;
333 GetLocaleInfoW(LOCALE_USER_DEFAULT
, format_item
, format_buf
, ARRAY_SIZE(format_buf
));
337 DATETIME_UseFormat (infoPtr
, format
);
338 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
345 DATETIME_SetFormatA (DATETIME_INFO
*infoPtr
, LPCSTR lpszFormat
)
349 INT len
= MultiByteToWideChar(CP_ACP
, 0, lpszFormat
, -1, NULL
, 0);
350 LPWSTR wstr
= Alloc(len
* sizeof(WCHAR
));
351 if (wstr
) MultiByteToWideChar(CP_ACP
, 0, lpszFormat
, -1, wstr
, len
);
352 retval
= DATETIME_SetFormatW (infoPtr
, wstr
);
357 return DATETIME_SetFormatW (infoPtr
, 0);
363 DATETIME_ReturnTxt (const DATETIME_INFO
*infoPtr
, int count
, LPWSTR result
, int resultSize
)
365 static const WCHAR fmt_dW
[] = { '%', 'd', 0 };
366 static const WCHAR fmt__2dW
[] = { '%', '.', '2', 'd', 0 };
367 static const WCHAR fmt__3sW
[] = { '%', '.', '3', 's', 0 };
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
, fmt_dW
, date
.wDay
);
402 wsprintfW (result
, fmt__2dW
, 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
, fmt_dW
, date
.wHour
- (date
.wHour
> 12 ? 12 : 0));
421 if (date
.wHour
== 0) {
427 wsprintfW (result
, fmt__2dW
, date
.wHour
- (date
.wHour
> 12 ? 12 : 0));
430 wsprintfW (result
, fmt_dW
, date
.wHour
);
433 wsprintfW (result
, fmt__2dW
, date
.wHour
);
436 wsprintfW (result
, fmt_dW
, date
.wSecond
);
439 wsprintfW (result
, fmt__2dW
, date
.wSecond
);
442 wsprintfW (result
, fmt_dW
, date
.wMinute
);
445 wsprintfW (result
, fmt__2dW
, date
.wMinute
);
448 wsprintfW (result
, fmt_dW
, date
.wMonth
);
451 wsprintfW (result
, fmt__2dW
, date
.wMonth
);
454 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SMONTHNAME1
+date
.wMonth
-1, buffer
, ARRAY_SIZE(buffer
));
455 wsprintfW (result
, fmt__3sW
, 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
, fmt_dW
, date
.wYear
-10* (int) floor(date
.wYear
/10));
479 wsprintfW (result
, fmt__2dW
, date
.wYear
-100* (int) floor(date
.wYear
/100));
481 case INVALIDFULLYEAR
:
483 wsprintfW (result
, fmt_dW
, 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 */
605 static const WCHAR fld_d1W
[] = { '2', 0 };
606 static const WCHAR fld_d2W
[] = { '2', '2', 0 };
607 static const WCHAR fld_d4W
[] = { '2', '2', '2', '2', 0 };
608 static const WCHAR fld_am1
[] = { 'A', 0 };
609 static const WCHAR fld_am2
[] = { 'A', 'M', 0 };
615 if (!infoPtr
->fieldspec
) return 0;
617 spec
= infoPtr
->fieldspec
[count
];
618 if (spec
& DT_STRING
) {
619 int txtlen
= infoPtr
->buflen
[count
];
623 memcpy (buffer
, infoPtr
->textbuf
+ (spec
&~ DT_STRING
), txtlen
* sizeof(WCHAR
));
636 /* these seem to use a two byte field */
646 case INVALIDFULLYEAR
:
655 static const WCHAR fld_day
[] = {'W','e','d','n','e','s','d','a','y',0};
656 static const WCHAR fld_abbrday
[] = {'W','e','d',0};
657 static const WCHAR fld_mon
[] = {'S','e','p','t','e','m','b','e','r',0};
658 static const WCHAR fld_abbrmon
[] = {'D','e','c',0};
665 /* choose locale data type and fallback string */
669 lctype
= LOCALE_SABBREVDAYNAME1
;
674 lctype
= LOCALE_SDAYNAME1
;
679 lctype
= LOCALE_SABBREVMONTHNAME1
;
682 default: /* FULLMONTH */
684 lctype
= LOCALE_SMONTHNAME1
;
690 for (i
= 0; i
< max_count
; i
++)
692 if(GetLocaleInfoW(LOCALE_USER_DEFAULT
, lctype
+ i
,
693 buffer
, ARRAY_SIZE(buffer
)))
695 GetTextExtentPoint32W(hdc
, buffer
, lstrlenW(buffer
), &size
);
696 if (size
.cx
> cx
) cx
= size
.cx
;
698 else /* locale independent fallback on failure */
700 GetTextExtentPoint32W(hdc
, fall
, lstrlenW(fall
), &size
);
718 GetTextExtentPoint32W (hdc
, bufptr
, strlenW(bufptr
), &size
);
723 DATETIME_Refresh (DATETIME_INFO
*infoPtr
, HDC hdc
)
727 if (infoPtr
->dateValid
) {
730 RECT
*rcDraw
= &infoPtr
->rcDraw
;
732 COLORREF oldTextColor
;
733 HFONT oldFont
= SelectObject (hdc
, infoPtr
->hFont
);
734 INT oldBkMode
= SetBkMode (hdc
, TRANSPARENT
);
737 DATETIME_ReturnTxt (infoPtr
, 0, txt
, ARRAY_SIZE(txt
));
738 GetTextExtentPoint32W (hdc
, txt
, strlenW(txt
), &size
);
739 rcDraw
->bottom
= size
.cy
+ 2;
741 prevright
= infoPtr
->checkbox
.right
= ((infoPtr
->dwStyle
& DTS_SHOWNONE
) ? 18 : 2);
743 for (i
= 0; i
< infoPtr
->nrFields
; i
++) {
744 DATETIME_ReturnTxt (infoPtr
, i
, txt
, ARRAY_SIZE(txt
));
745 GetTextExtentPoint32W (hdc
, txt
, strlenW(txt
), &size
);
746 field
= &infoPtr
->fieldRect
[i
];
747 field
->left
= prevright
;
748 field
->right
= prevright
+ DATETIME_GetFieldWidth (infoPtr
, hdc
, i
);
749 field
->top
= rcDraw
->top
;
750 field
->bottom
= rcDraw
->bottom
;
751 prevright
= field
->right
;
753 if (infoPtr
->dwStyle
& WS_DISABLED
)
754 oldTextColor
= SetTextColor (hdc
, comctl32_color
.clrGrayText
);
755 else if ((infoPtr
->haveFocus
) && (i
== infoPtr
->select
)) {
758 /* fill if focused */
759 HBRUSH hbr
= CreateSolidBrush (comctl32_color
.clrActiveCaption
);
761 if (infoPtr
->nCharsEntered
)
763 memcpy(txt
, infoPtr
->charsEntered
, infoPtr
->nCharsEntered
* sizeof(WCHAR
));
764 txt
[infoPtr
->nCharsEntered
] = 0;
765 GetTextExtentPoint32W (hdc
, txt
, strlenW(txt
), &size
);
768 SetRect(&selection
, 0, 0, size
.cx
, size
.cy
);
769 /* center rectangle */
770 OffsetRect(&selection
, (field
->right
+ field
->left
- size
.cx
)/2,
771 (field
->bottom
- size
.cy
)/2);
773 FillRect(hdc
, &selection
, hbr
);
775 oldTextColor
= SetTextColor (hdc
, comctl32_color
.clrWindow
);
778 oldTextColor
= SetTextColor (hdc
, comctl32_color
.clrWindowText
);
780 /* draw the date text using the colour set above */
781 DrawTextW (hdc
, txt
, strlenW(txt
), field
, DT_CENTER
| DT_VCENTER
| DT_SINGLELINE
);
782 SetTextColor (hdc
, oldTextColor
);
784 SetBkMode (hdc
, oldBkMode
);
785 SelectObject (hdc
, oldFont
);
788 if (!(infoPtr
->dwStyle
& DTS_UPDOWN
)) {
789 DrawFrameControl(hdc
, &infoPtr
->calbutton
, DFC_SCROLL
,
790 DFCS_SCROLLDOWN
| (infoPtr
->bCalDepressed
? DFCS_PUSHED
: 0) |
791 (infoPtr
->dwStyle
& WS_DISABLED
? DFCS_INACTIVE
: 0) );
797 DATETIME_HitTest (const DATETIME_INFO
*infoPtr
, POINT pt
)
801 TRACE ("%s\n", wine_dbgstr_point(&pt
));
803 if (PtInRect (&infoPtr
->calbutton
, pt
)) return DTHT_MCPOPUP
;
804 if (PtInRect (&infoPtr
->checkbox
, pt
)) return DTHT_CHECKBOX
;
806 for (i
= 0; i
< infoPtr
->nrFields
; i
++) {
807 if (PtInRect (&infoPtr
->fieldRect
[i
], pt
)) return i
;
813 /* Returns index of the nearest preceding date field from given,
814 or -1 if none was found */
815 static int DATETIME_GetPrevDateField(const DATETIME_INFO
*infoPtr
, int i
)
817 for(--i
; i
>= 0; i
--)
819 if (infoPtr
->fieldspec
[i
] & DTHT_DATEFIELD
) return i
;
825 DATETIME_ApplySelectedField (DATETIME_INFO
*infoPtr
)
827 int fieldNum
= infoPtr
->select
& DTHT_DATEFIELD
;
829 BOOL clamp_day
= FALSE
;
830 SYSTEMTIME date
= infoPtr
->date
;
833 if (infoPtr
->select
== -1 || infoPtr
->nCharsEntered
== 0)
836 if ((infoPtr
->fieldspec
[fieldNum
] == ONELETTERAMPM
) ||
837 (infoPtr
->fieldspec
[fieldNum
] == TWOLETTERAMPM
))
838 val
= infoPtr
->charsEntered
[0];
840 for (i
=0; i
<infoPtr
->nCharsEntered
; i
++)
841 val
= val
* 10 + infoPtr
->charsEntered
[i
] - '0';
844 infoPtr
->nCharsEntered
= 0;
846 switch (infoPtr
->fieldspec
[fieldNum
]) {
849 oldyear
= date
.wYear
;
850 date
.wYear
= date
.wYear
- (date
.wYear
%100) + val
;
852 if (DATETIME_IsDateInValidRange(infoPtr
, &date
))
855 date
.wYear
= oldyear
;
858 case INVALIDFULLYEAR
:
860 oldyear
= date
.wYear
;
863 if (DATETIME_IsDateInValidRange(infoPtr
, &date
))
866 date
.wYear
= oldyear
;
886 if (date
.wHour
>= 12) /* preserve current AM/PM state */
887 date
.wHour
= (val
== 12 ? 12 : val
+ 12);
889 date
.wHour
= (val
== 12 ? 0 : val
);
906 if (val
== 'a' || val
== 'A') {
907 if (date
.wHour
>= 12)
909 } else if (val
== 'p' || val
== 'P') {
916 if (clamp_day
&& date
.wDay
> MONTHCAL_MonthLength(date
.wMonth
, date
.wYear
))
917 date
.wDay
= MONTHCAL_MonthLength(date
.wMonth
, date
.wYear
);
919 if (DATETIME_SetSystemTime(infoPtr
, GDT_VALID
, &date
))
920 DATETIME_SendDateTimeChangeNotify (infoPtr
);
924 DATETIME_SetSelectedField (DATETIME_INFO
*infoPtr
, int select
)
926 DATETIME_ApplySelectedField(infoPtr
);
928 infoPtr
->select
= select
;
929 infoPtr
->nCharsEntered
= 0;
933 DATETIME_LButtonDown (DATETIME_INFO
*infoPtr
, INT x
, INT y
)
940 new = DATETIME_HitTest (infoPtr
, pt
);
942 SetFocus(infoPtr
->hwndSelf
);
944 if (!(new & DTHT_NODATEMASK
) || (new == DTHT_NONE
))
946 if (new == DTHT_NONE
)
947 new = infoPtr
->nrFields
- 1;
950 /* hitting string part moves selection to next date field to left */
951 if (infoPtr
->fieldspec
[new] & DT_STRING
)
953 new = DATETIME_GetPrevDateField(infoPtr
, new);
954 if (new == -1) return 0;
956 /* never select full day of week */
957 if (infoPtr
->fieldspec
[new] == FULLDAY
) return 0;
961 DATETIME_SetSelectedField(infoPtr
, new);
963 if (infoPtr
->select
== DTHT_MCPOPUP
) {
966 SendMessageW(infoPtr
->hMonthCal
, MCM_GETMINREQRECT
, 0, (LPARAM
)&rcMonthCal
);
968 /* FIXME: button actually is only depressed during dropdown of the */
969 /* calendar control and when the mouse is over the button window */
970 infoPtr
->bCalDepressed
= TRUE
;
972 /* recalculate the position of the monthcal popup */
973 if(infoPtr
->dwStyle
& DTS_RIGHTALIGN
)
974 pos
.x
= infoPtr
->calbutton
.left
- (rcMonthCal
.right
- rcMonthCal
.left
);
976 /* FIXME: this should be after the area reserved for the checkbox */
977 pos
.x
= infoPtr
->rcDraw
.left
;
979 pos
.y
= infoPtr
->rcClient
.bottom
;
980 OffsetRect( &rcMonthCal
, pos
.x
, pos
.y
);
981 MapWindowPoints( infoPtr
->hwndSelf
, 0, (POINT
*)&rcMonthCal
, 2 );
982 SetWindowPos(infoPtr
->hMonthCal
, 0, rcMonthCal
.left
, rcMonthCal
.top
,
983 rcMonthCal
.right
- rcMonthCal
.left
, rcMonthCal
.bottom
- rcMonthCal
.top
, 0);
985 if(IsWindowVisible(infoPtr
->hMonthCal
)) {
986 ShowWindow(infoPtr
->hMonthCal
, SW_HIDE
);
987 infoPtr
->bDropdownEnabled
= FALSE
;
988 DATETIME_SendSimpleNotify (infoPtr
, DTN_CLOSEUP
);
990 const SYSTEMTIME
*lprgSysTimeArray
= &infoPtr
->date
;
991 TRACE("update calendar %04d/%02d/%02d\n",
992 lprgSysTimeArray
->wYear
, lprgSysTimeArray
->wMonth
, lprgSysTimeArray
->wDay
);
993 SendMessageW(infoPtr
->hMonthCal
, MCM_SETCURSEL
, 0, (LPARAM
)(&infoPtr
->date
));
995 if (infoPtr
->bDropdownEnabled
) {
996 ShowWindow(infoPtr
->hMonthCal
, SW_SHOW
);
997 DATETIME_SendSimpleNotify (infoPtr
, DTN_DROPDOWN
);
999 infoPtr
->bDropdownEnabled
= TRUE
;
1002 TRACE ("dt:%p mc:%p mc parent:%p, desktop:%p\n",
1003 infoPtr
->hwndSelf
, infoPtr
->hMonthCal
, infoPtr
->hwndNotify
, GetDesktopWindow ());
1006 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1013 DATETIME_LButtonUp (DATETIME_INFO
*infoPtr
)
1015 if(infoPtr
->bCalDepressed
) {
1016 infoPtr
->bCalDepressed
= FALSE
;
1017 InvalidateRect(infoPtr
->hwndSelf
, &(infoPtr
->calbutton
), TRUE
);
1025 DATETIME_Paint (DATETIME_INFO
*infoPtr
, HDC hdc
)
1029 hdc
= BeginPaint (infoPtr
->hwndSelf
, &ps
);
1030 DATETIME_Refresh (infoPtr
, hdc
);
1031 EndPaint (infoPtr
->hwndSelf
, &ps
);
1033 DATETIME_Refresh (infoPtr
, hdc
);
1036 /* Not a click on the dropdown box, enabled it */
1037 infoPtr
->bDropdownEnabled
= TRUE
;
1044 DATETIME_Button_Command (DATETIME_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
1046 if( HIWORD(wParam
) == BN_CLICKED
) {
1047 DWORD state
= SendMessageW((HWND
)lParam
, BM_GETCHECK
, 0, 0);
1048 infoPtr
->dateValid
= (state
== BST_CHECKED
);
1049 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1057 DATETIME_Command (DATETIME_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
1059 TRACE("hwndbutton = %p\n", infoPtr
->hwndCheckbut
);
1060 if(infoPtr
->hwndCheckbut
== (HWND
)lParam
)
1061 return DATETIME_Button_Command(infoPtr
, wParam
, lParam
);
1067 DATETIME_Enable (DATETIME_INFO
*infoPtr
, BOOL bEnable
)
1069 TRACE("%p %s\n", infoPtr
, bEnable
? "TRUE" : "FALSE");
1071 infoPtr
->dwStyle
&= ~WS_DISABLED
;
1073 infoPtr
->dwStyle
|= WS_DISABLED
;
1075 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1082 DATETIME_EraseBackground (const DATETIME_INFO
*infoPtr
, HDC hdc
)
1084 HBRUSH hBrush
, hSolidBrush
= NULL
;
1087 if (infoPtr
->dwStyle
& WS_DISABLED
)
1088 hBrush
= hSolidBrush
= CreateSolidBrush(comctl32_color
.clrBtnFace
);
1091 hBrush
= (HBRUSH
)SendMessageW(infoPtr
->hwndNotify
, WM_CTLCOLOREDIT
,
1092 (WPARAM
)hdc
, (LPARAM
)infoPtr
->hwndSelf
);
1094 hBrush
= hSolidBrush
= CreateSolidBrush(comctl32_color
.clrWindow
);
1097 GetClientRect (infoPtr
->hwndSelf
, &rc
);
1099 FillRect (hdc
, &rc
, hBrush
);
1102 DeleteObject(hSolidBrush
);
1109 DATETIME_Notify (DATETIME_INFO
*infoPtr
, const NMHDR
*lpnmh
)
1111 TRACE ("Got notification %x from %p\n", lpnmh
->code
, lpnmh
->hwndFrom
);
1112 TRACE ("info: %p %p %p\n", infoPtr
->hwndSelf
, infoPtr
->hMonthCal
, infoPtr
->hUpdown
);
1114 if (lpnmh
->code
== MCN_SELECT
) {
1115 ShowWindow(infoPtr
->hMonthCal
, SW_HIDE
);
1116 infoPtr
->dateValid
= TRUE
;
1117 SendMessageW (infoPtr
->hMonthCal
, MCM_GETCURSEL
, 0, (LPARAM
)&infoPtr
->date
);
1118 TRACE("got from calendar %04d/%02d/%02d day of week %d\n",
1119 infoPtr
->date
.wYear
, infoPtr
->date
.wMonth
, infoPtr
->date
.wDay
, infoPtr
->date
.wDayOfWeek
);
1120 SendMessageW (infoPtr
->hwndCheckbut
, BM_SETCHECK
, BST_CHECKED
, 0);
1121 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1122 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1123 DATETIME_SendSimpleNotify(infoPtr
, DTN_CLOSEUP
);
1125 if ((lpnmh
->hwndFrom
== infoPtr
->hUpdown
) && (lpnmh
->code
== UDN_DELTAPOS
)) {
1126 const NM_UPDOWN
*lpnmud
= (const NM_UPDOWN
*)lpnmh
;
1127 TRACE("Delta pos %d\n", lpnmud
->iDelta
);
1128 infoPtr
->pendingUpdown
= lpnmud
->iDelta
;
1135 DATETIME_KeyDown (DATETIME_INFO
*infoPtr
, DWORD vkCode
)
1137 int fieldNum
= infoPtr
->select
& DTHT_DATEFIELD
;
1141 if (!(infoPtr
->haveFocus
)) return 0;
1142 if ((fieldNum
==0) && (infoPtr
->select
)) return 0;
1144 if (infoPtr
->select
& FORMATCALLMASK
) {
1145 FIXME ("Callbacks not implemented yet\n");
1151 infoPtr
->nCharsEntered
= 0;
1152 DATETIME_IncreaseField (infoPtr
, fieldNum
, 1);
1153 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1157 infoPtr
->nCharsEntered
= 0;
1158 DATETIME_IncreaseField (infoPtr
, fieldNum
, -1);
1159 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1162 infoPtr
->nCharsEntered
= 0;
1163 DATETIME_IncreaseField (infoPtr
, fieldNum
, INT_MIN
);
1164 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1167 infoPtr
->nCharsEntered
= 0;
1168 DATETIME_IncreaseField (infoPtr
, fieldNum
, INT_MAX
);
1169 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1172 new = infoPtr
->select
;
1180 } while ((infoPtr
->fieldspec
[new] & DT_STRING
) && (wrap
<2));
1181 if (new != infoPtr
->select
)
1182 DATETIME_SetSelectedField(infoPtr
, new);
1185 new = infoPtr
->select
;
1188 if (new==infoPtr
->nrFields
) {
1192 } while ((infoPtr
->fieldspec
[new] & DT_STRING
) && (wrap
<2));
1193 if (new != infoPtr
->select
)
1194 DATETIME_SetSelectedField(infoPtr
, new);
1198 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1205 DATETIME_Char (DATETIME_INFO
*infoPtr
, WPARAM vkCode
)
1207 int fieldNum
, fieldSpec
;
1209 fieldNum
= infoPtr
->select
& DTHT_DATEFIELD
;
1210 fieldSpec
= infoPtr
->fieldspec
[fieldNum
];
1212 if (fieldSpec
== ONELETTERAMPM
|| fieldSpec
== TWOLETTERAMPM
) {
1213 infoPtr
->charsEntered
[0] = vkCode
;
1214 infoPtr
->nCharsEntered
= 1;
1216 DATETIME_ApplySelectedField(infoPtr
);
1217 } else if (vkCode
>= '0' && vkCode
<= '9') {
1220 infoPtr
->charsEntered
[infoPtr
->nCharsEntered
++] = vkCode
;
1222 if (fieldSpec
== INVALIDFULLYEAR
|| fieldSpec
== FULLYEAR
)
1227 if ((fieldSpec
== ONEDIGIT12HOUR
||
1228 fieldSpec
== TWODIGIT12HOUR
||
1229 fieldSpec
== ONEDIGIT24HOUR
||
1230 fieldSpec
== TWODIGIT24HOUR
) &&
1231 (infoPtr
->nCharsEntered
== 1))
1237 if (maxChars
== infoPtr
->nCharsEntered
)
1238 DATETIME_ApplySelectedField(infoPtr
);
1246 DATETIME_VScroll (DATETIME_INFO
*infoPtr
, WORD wScroll
)
1248 int fieldNum
= infoPtr
->select
& DTHT_DATEFIELD
;
1250 if ((SHORT
)LOWORD(wScroll
) != SB_THUMBPOSITION
) return 0;
1251 if (!(infoPtr
->haveFocus
)) return 0;
1252 if ((fieldNum
==0) && (infoPtr
->select
)) return 0;
1254 if (infoPtr
->pendingUpdown
>= 0) {
1255 DATETIME_IncreaseField (infoPtr
, fieldNum
, 1);
1256 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1259 DATETIME_IncreaseField (infoPtr
, fieldNum
, -1);
1260 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1263 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1270 DATETIME_KillFocus (DATETIME_INFO
*infoPtr
, HWND lostFocus
)
1272 TRACE("lost focus to %p\n", lostFocus
);
1274 if (infoPtr
->haveFocus
) {
1275 DATETIME_SendSimpleNotify (infoPtr
, NM_KILLFOCUS
);
1276 infoPtr
->haveFocus
= 0;
1277 DATETIME_SetSelectedField (infoPtr
, -1);
1280 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
1287 DATETIME_NCCreate (HWND hwnd
, const CREATESTRUCTW
*lpcs
)
1289 DWORD dwExStyle
= GetWindowLongW(hwnd
, GWL_EXSTYLE
);
1290 /* force control to have client edge */
1291 dwExStyle
|= WS_EX_CLIENTEDGE
;
1292 SetWindowLongW(hwnd
, GWL_EXSTYLE
, dwExStyle
);
1294 return DefWindowProcW(hwnd
, WM_NCCREATE
, 0, (LPARAM
)lpcs
);
1299 DATETIME_SetFocus (DATETIME_INFO
*infoPtr
, HWND lostFocus
)
1301 TRACE("got focus from %p\n", lostFocus
);
1303 /* if monthcal is open and it loses focus, close monthcal */
1304 if (infoPtr
->hMonthCal
&& (lostFocus
== infoPtr
->hMonthCal
) &&
1305 IsWindowVisible(infoPtr
->hMonthCal
))
1307 ShowWindow(infoPtr
->hMonthCal
, SW_HIDE
);
1308 DATETIME_SendSimpleNotify(infoPtr
, DTN_CLOSEUP
);
1309 /* note: this get triggered even if monthcal loses focus to a dropdown
1310 * box click, which occurs without an intermediate WM_PAINT call
1312 infoPtr
->bDropdownEnabled
= FALSE
;
1316 if (infoPtr
->haveFocus
== 0) {
1317 DATETIME_SendSimpleNotify (infoPtr
, NM_SETFOCUS
);
1318 infoPtr
->haveFocus
= DTHT_GOTFOCUS
;
1321 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1328 DATETIME_SendDateTimeChangeNotify (const DATETIME_INFO
*infoPtr
)
1330 NMDATETIMECHANGE dtdtc
;
1332 dtdtc
.nmhdr
.hwndFrom
= infoPtr
->hwndSelf
;
1333 dtdtc
.nmhdr
.idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1334 dtdtc
.nmhdr
.code
= DTN_DATETIMECHANGE
;
1336 dtdtc
.dwFlags
= infoPtr
->dateValid
? GDT_VALID
: GDT_NONE
;
1338 dtdtc
.st
= infoPtr
->date
;
1339 return (BOOL
) SendMessageW (infoPtr
->hwndNotify
, WM_NOTIFY
,
1340 dtdtc
.nmhdr
.idFrom
, (LPARAM
)&dtdtc
);
1345 DATETIME_SendSimpleNotify (const DATETIME_INFO
*infoPtr
, UINT code
)
1349 TRACE("%x\n", code
);
1350 nmhdr
.hwndFrom
= infoPtr
->hwndSelf
;
1351 nmhdr
.idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1354 return (BOOL
) SendMessageW (infoPtr
->hwndNotify
, WM_NOTIFY
,
1355 nmhdr
.idFrom
, (LPARAM
)&nmhdr
);
1359 DATETIME_Size (DATETIME_INFO
*infoPtr
, INT width
, INT height
)
1362 infoPtr
->rcClient
.bottom
= height
;
1363 infoPtr
->rcClient
.right
= width
;
1365 TRACE("Height=%d, Width=%d\n", infoPtr
->rcClient
.bottom
, infoPtr
->rcClient
.right
);
1367 infoPtr
->rcDraw
= infoPtr
->rcClient
;
1369 if (infoPtr
->dwStyle
& DTS_UPDOWN
) {
1370 SetWindowPos(infoPtr
->hUpdown
, NULL
,
1371 infoPtr
->rcClient
.right
-14, 0,
1372 15, infoPtr
->rcClient
.bottom
- infoPtr
->rcClient
.top
,
1373 SWP_NOACTIVATE
| SWP_NOZORDER
);
1376 /* set the size of the button that drops the calendar down */
1377 /* FIXME: account for style that allows button on left side */
1378 infoPtr
->calbutton
.top
= infoPtr
->rcDraw
.top
;
1379 infoPtr
->calbutton
.bottom
= infoPtr
->rcDraw
.bottom
;
1380 infoPtr
->calbutton
.left
= infoPtr
->rcDraw
.right
-15;
1381 infoPtr
->calbutton
.right
= infoPtr
->rcDraw
.right
;
1384 /* set enable/disable button size for show none style being enabled */
1385 /* FIXME: these dimensions are completely incorrect */
1386 infoPtr
->checkbox
.top
= infoPtr
->rcDraw
.top
;
1387 infoPtr
->checkbox
.bottom
= infoPtr
->rcDraw
.bottom
;
1388 infoPtr
->checkbox
.left
= infoPtr
->rcDraw
.left
;
1389 infoPtr
->checkbox
.right
= infoPtr
->rcDraw
.left
+ 10;
1391 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1397 DATETIME_StyleChanging(DATETIME_INFO
*infoPtr
, WPARAM wStyleType
, STYLESTRUCT
*lpss
)
1399 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
1400 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
1402 /* block DTS_SHOWNONE change */
1403 if ((lpss
->styleNew
^ lpss
->styleOld
) & DTS_SHOWNONE
)
1405 if (lpss
->styleOld
& DTS_SHOWNONE
)
1406 lpss
->styleNew
|= DTS_SHOWNONE
;
1408 lpss
->styleNew
&= ~DTS_SHOWNONE
;
1415 DATETIME_StyleChanged(DATETIME_INFO
*infoPtr
, WPARAM wStyleType
, const STYLESTRUCT
*lpss
)
1417 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
1418 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
1420 if (wStyleType
!= GWL_STYLE
) return 0;
1422 infoPtr
->dwStyle
= lpss
->styleNew
;
1424 if ( !(lpss
->styleOld
& DTS_SHOWNONE
) && (lpss
->styleNew
& DTS_SHOWNONE
) ) {
1425 infoPtr
->hwndCheckbut
= CreateWindowExW (0, WC_BUTTONW
, 0, WS_CHILD
| WS_VISIBLE
| BS_AUTOCHECKBOX
,
1426 2, 2, 13, 13, infoPtr
->hwndSelf
, 0,
1427 (HINSTANCE
)GetWindowLongPtrW (infoPtr
->hwndSelf
, GWLP_HINSTANCE
), 0);
1428 SendMessageW (infoPtr
->hwndCheckbut
, BM_SETCHECK
, infoPtr
->dateValid
? 1 : 0, 0);
1430 if ( (lpss
->styleOld
& DTS_SHOWNONE
) && !(lpss
->styleNew
& DTS_SHOWNONE
) ) {
1431 DestroyWindow(infoPtr
->hwndCheckbut
);
1432 infoPtr
->hwndCheckbut
= 0;
1434 if ( !(lpss
->styleOld
& DTS_UPDOWN
) && (lpss
->styleNew
& DTS_UPDOWN
) ) {
1435 infoPtr
->hUpdown
= CreateUpDownControl (WS_CHILD
| WS_BORDER
| WS_VISIBLE
, 120, 1, 20, 20,
1436 infoPtr
->hwndSelf
, 1, 0, 0, UD_MAXVAL
, UD_MINVAL
, 0);
1438 if ( (lpss
->styleOld
& DTS_UPDOWN
) && !(lpss
->styleNew
& DTS_UPDOWN
) ) {
1439 DestroyWindow(infoPtr
->hUpdown
);
1440 infoPtr
->hUpdown
= 0;
1443 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1447 static BOOL
DATETIME_GetIdealSize(DATETIME_INFO
*infoPtr
, SIZE
*size
)
1456 size
->cx
= size
->cy
= 0;
1458 hdc
= GetDC(infoPtr
->hwndSelf
);
1459 oldFont
= SelectObject(hdc
, infoPtr
->hFont
);
1461 /* Get text font height */
1462 DATETIME_ReturnTxt(infoPtr
, 0, txt
, ARRAY_SIZE(txt
));
1463 GetTextExtentPoint32W(hdc
, txt
, strlenW(txt
), &field_size
);
1464 size
->cy
= field_size
.cy
;
1466 /* Get text font width */
1467 for (i
= 0; i
< infoPtr
->nrFields
; i
++)
1469 size
->cx
+= DATETIME_GetFieldWidth(infoPtr
, hdc
, i
);
1472 SelectObject(hdc
, oldFont
);
1473 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
1475 if (infoPtr
->dwStyle
& DTS_UPDOWN
)
1477 GetWindowRect(infoPtr
->hUpdown
, &rect
);
1478 size
->cx
+= rect
.right
- rect
.left
;
1482 size
->cx
+= infoPtr
->calbutton
.right
- infoPtr
->calbutton
.left
;
1485 if (infoPtr
->dwStyle
& DTS_SHOWNONE
)
1487 size
->cx
+= infoPtr
->checkbox
.right
- infoPtr
->checkbox
.left
;
1490 /* Add space between controls for them not to get too close */
1494 TRACE("cx=%d cy=%d\n", size
->cx
, size
->cy
);
1499 DATETIME_SetFont (DATETIME_INFO
*infoPtr
, HFONT font
, BOOL repaint
)
1501 infoPtr
->hFont
= font
;
1502 if (repaint
) InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1508 DATETIME_Create (HWND hwnd
, const CREATESTRUCTW
*lpcs
)
1510 DATETIME_INFO
*infoPtr
= Alloc (sizeof(DATETIME_INFO
));
1511 STYLESTRUCT ss
= { 0, lpcs
->style
};
1513 if (!infoPtr
) return -1;
1515 infoPtr
->hwndSelf
= hwnd
;
1516 infoPtr
->dwStyle
= lpcs
->style
;
1518 infoPtr
->nrFieldsAllocated
= 32;
1519 infoPtr
->fieldspec
= Alloc (infoPtr
->nrFieldsAllocated
* sizeof(int));
1520 infoPtr
->fieldRect
= Alloc (infoPtr
->nrFieldsAllocated
* sizeof(RECT
));
1521 infoPtr
->buflen
= Alloc (infoPtr
->nrFieldsAllocated
* sizeof(int));
1522 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
1523 infoPtr
->select
= -1; /* initially, nothing is selected */
1524 infoPtr
->bDropdownEnabled
= TRUE
;
1526 DATETIME_StyleChanged(infoPtr
, GWL_STYLE
, &ss
);
1527 DATETIME_SetFormatW (infoPtr
, 0);
1529 /* create the monthcal control */
1530 infoPtr
->hMonthCal
= CreateWindowExW (0, MONTHCAL_CLASSW
, 0, WS_BORDER
| WS_POPUP
| WS_CLIPSIBLINGS
,
1531 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, 0, 0);
1533 /* initialize info structure */
1534 GetLocalTime (&infoPtr
->date
);
1535 infoPtr
->dateValid
= TRUE
;
1536 infoPtr
->hFont
= GetStockObject(DEFAULT_GUI_FONT
);
1538 SetWindowLongPtrW (hwnd
, 0, (DWORD_PTR
)infoPtr
);
1546 DATETIME_Destroy (DATETIME_INFO
*infoPtr
)
1548 if (infoPtr
->hwndCheckbut
)
1549 DestroyWindow(infoPtr
->hwndCheckbut
);
1550 if (infoPtr
->hUpdown
)
1551 DestroyWindow(infoPtr
->hUpdown
);
1552 if (infoPtr
->hMonthCal
)
1553 DestroyWindow(infoPtr
->hMonthCal
);
1554 SetWindowLongPtrW( infoPtr
->hwndSelf
, 0, 0 ); /* clear infoPtr */
1555 Free (infoPtr
->buflen
);
1556 Free (infoPtr
->fieldRect
);
1557 Free (infoPtr
->fieldspec
);
1564 DATETIME_GetText (const DATETIME_INFO
*infoPtr
, INT count
, LPWSTR dst
)
1569 if (!dst
|| (count
<= 0)) return 0;
1572 for (i
= 0; i
< infoPtr
->nrFields
; i
++)
1574 DATETIME_ReturnTxt(infoPtr
, i
, buf
, ARRAY_SIZE(buf
));
1575 if ((strlenW(dst
) + strlenW(buf
)) < count
)
1579 return strlenW(dst
);
1583 static LRESULT WINAPI
1584 DATETIME_WindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1586 DATETIME_INFO
*infoPtr
= ((DATETIME_INFO
*)GetWindowLongPtrW (hwnd
, 0));
1588 TRACE ("%x, %lx, %lx\n", uMsg
, wParam
, lParam
);
1590 if (!infoPtr
&& (uMsg
!= WM_CREATE
) && (uMsg
!= WM_NCCREATE
))
1591 return DefWindowProcW( hwnd
, uMsg
, wParam
, lParam
);
1595 case DTM_GETSYSTEMTIME
:
1596 return DATETIME_GetSystemTime (infoPtr
, (SYSTEMTIME
*) lParam
);
1598 case DTM_SETSYSTEMTIME
:
1599 return DATETIME_SetSystemTime (infoPtr
, wParam
, (SYSTEMTIME
*) lParam
);
1602 return SendMessageW (infoPtr
->hMonthCal
, MCM_GETRANGE
, wParam
, lParam
);
1605 return SendMessageW (infoPtr
->hMonthCal
, MCM_SETRANGE
, wParam
, lParam
);
1607 case DTM_SETFORMATA
:
1608 return DATETIME_SetFormatA (infoPtr
, (LPCSTR
)lParam
);
1610 case DTM_SETFORMATW
:
1611 return DATETIME_SetFormatW (infoPtr
, (LPCWSTR
)lParam
);
1613 case DTM_GETMONTHCAL
:
1614 return (LRESULT
)infoPtr
->hMonthCal
;
1616 case DTM_SETMCCOLOR
:
1617 return SendMessageW (infoPtr
->hMonthCal
, MCM_SETCOLOR
, wParam
, lParam
);
1619 case DTM_GETMCCOLOR
:
1620 return SendMessageW (infoPtr
->hMonthCal
, MCM_GETCOLOR
, wParam
, 0);
1623 return SendMessageW (infoPtr
->hMonthCal
, WM_SETFONT
, wParam
, lParam
);
1626 return SendMessageW (infoPtr
->hMonthCal
, WM_GETFONT
, wParam
, lParam
);
1628 case DTM_GETIDEALSIZE
:
1629 return DATETIME_GetIdealSize(infoPtr
, (SIZE
*)lParam
);
1632 return DATETIME_Notify (infoPtr
, (LPNMHDR
)lParam
);
1635 return DATETIME_Enable (infoPtr
, (BOOL
)wParam
);
1638 return DATETIME_EraseBackground (infoPtr
, (HDC
)wParam
);
1641 return DLGC_WANTARROWS
| DLGC_WANTCHARS
;
1643 case WM_PRINTCLIENT
:
1645 return DATETIME_Paint (infoPtr
, (HDC
)wParam
);
1648 return DATETIME_KeyDown (infoPtr
, wParam
);
1651 return DATETIME_Char (infoPtr
, wParam
);
1654 return DATETIME_KillFocus (infoPtr
, (HWND
)wParam
);
1657 return DATETIME_NCCreate (hwnd
, (LPCREATESTRUCTW
)lParam
);
1660 return DATETIME_SetFocus (infoPtr
, (HWND
)wParam
);
1663 return DATETIME_Size (infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
1665 case WM_LBUTTONDOWN
:
1666 return DATETIME_LButtonDown (infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
1669 return DATETIME_LButtonUp (infoPtr
);
1672 return DATETIME_VScroll (infoPtr
, (WORD
)wParam
);
1675 return DATETIME_Create (hwnd
, (LPCREATESTRUCTW
)lParam
);
1678 return DATETIME_Destroy (infoPtr
);
1681 return DATETIME_Command (infoPtr
, wParam
, lParam
);
1683 case WM_STYLECHANGING
:
1684 return DATETIME_StyleChanging(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
1686 case WM_STYLECHANGED
:
1687 return DATETIME_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
1690 return DATETIME_SetFont(infoPtr
, (HFONT
)wParam
, (BOOL
)lParam
);
1693 return (LRESULT
) infoPtr
->hFont
;
1696 return (LRESULT
) DATETIME_GetText(infoPtr
, wParam
, (LPWSTR
)lParam
);
1702 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
1703 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
1704 uMsg
, wParam
, lParam
);
1705 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
1711 DATETIME_Register (void)
1715 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
1716 wndClass
.style
= CS_GLOBALCLASS
;
1717 wndClass
.lpfnWndProc
= DATETIME_WindowProc
;
1718 wndClass
.cbClsExtra
= 0;
1719 wndClass
.cbWndExtra
= sizeof(DATETIME_INFO
*);
1720 wndClass
.hCursor
= LoadCursorW (0, (LPCWSTR
)IDC_ARROW
);
1721 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
1722 wndClass
.lpszClassName
= DATETIMEPICK_CLASSW
;
1724 RegisterClassW (&wndClass
);
1729 DATETIME_Unregister (void)
1731 UnregisterClassW (DATETIMEPICK_CLASSW
, NULL
);