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_LONGDATEFORMAT
)
326 format_item
= LOCALE_SLONGDATE
;
327 else if ((infoPtr
->dwStyle
& DTS_TIMEFORMAT
) == DTS_TIMEFORMAT
)
328 format_item
= LOCALE_STIMEFORMAT
;
329 else /* DTS_SHORTDATEFORMAT */
330 format_item
= LOCALE_SSHORTDATE
;
331 GetLocaleInfoW(LOCALE_USER_DEFAULT
, format_item
, format_buf
, sizeof(format_buf
)/sizeof(format_buf
[0]));
335 DATETIME_UseFormat (infoPtr
, format
);
336 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
343 DATETIME_SetFormatA (DATETIME_INFO
*infoPtr
, LPCSTR lpszFormat
)
347 INT len
= MultiByteToWideChar(CP_ACP
, 0, lpszFormat
, -1, NULL
, 0);
348 LPWSTR wstr
= Alloc(len
* sizeof(WCHAR
));
349 if (wstr
) MultiByteToWideChar(CP_ACP
, 0, lpszFormat
, -1, wstr
, len
);
350 retval
= DATETIME_SetFormatW (infoPtr
, wstr
);
355 return DATETIME_SetFormatW (infoPtr
, 0);
361 DATETIME_ReturnTxt (const DATETIME_INFO
*infoPtr
, int count
, LPWSTR result
, int resultSize
)
363 static const WCHAR fmt_dW
[] = { '%', 'd', 0 };
364 static const WCHAR fmt__2dW
[] = { '%', '.', '2', 'd', 0 };
365 static const WCHAR fmt__3sW
[] = { '%', '.', '3', 's', 0 };
366 SYSTEMTIME date
= infoPtr
->date
;
371 TRACE ("%d,%d\n", infoPtr
->nrFields
, count
);
372 if (count
>infoPtr
->nrFields
|| count
< 0) {
373 WARN ("buffer overrun, have %d want %d\n", infoPtr
->nrFields
, count
);
377 if (!infoPtr
->fieldspec
) return;
379 spec
= infoPtr
->fieldspec
[count
];
380 if (spec
& DT_STRING
) {
381 int txtlen
= infoPtr
->buflen
[count
];
383 if (txtlen
> resultSize
)
384 txtlen
= resultSize
- 1;
385 memcpy (result
, infoPtr
->textbuf
+ (spec
&~ DT_STRING
), txtlen
* sizeof(WCHAR
));
387 TRACE ("arg%d=%x->[%s]\n", count
, infoPtr
->fieldspec
[count
], debugstr_w(result
));
397 wsprintfW (result
, fmt_dW
, date
.wDay
);
400 wsprintfW (result
, fmt__2dW
, date
.wDay
);
403 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SABBREVDAYNAME1
+(date
.wDayOfWeek
+6)%7, result
, 4);
404 /*wsprintfW (result,"%.3s",days[date.wDayOfWeek]);*/
407 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SDAYNAME1
+(date
.wDayOfWeek
+6)%7, result
, resultSize
);
410 if (date
.wHour
== 0) {
416 wsprintfW (result
, fmt_dW
, date
.wHour
- (date
.wHour
> 12 ? 12 : 0));
419 if (date
.wHour
== 0) {
425 wsprintfW (result
, fmt__2dW
, date
.wHour
- (date
.wHour
> 12 ? 12 : 0));
428 wsprintfW (result
, fmt_dW
, date
.wHour
);
431 wsprintfW (result
, fmt__2dW
, date
.wHour
);
434 wsprintfW (result
, fmt_dW
, date
.wSecond
);
437 wsprintfW (result
, fmt__2dW
, date
.wSecond
);
440 wsprintfW (result
, fmt_dW
, date
.wMinute
);
443 wsprintfW (result
, fmt__2dW
, date
.wMinute
);
446 wsprintfW (result
, fmt_dW
, date
.wMonth
);
449 wsprintfW (result
, fmt__2dW
, date
.wMonth
);
452 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SMONTHNAME1
+date
.wMonth
-1,
453 buffer
, sizeof(buffer
)/sizeof(buffer
[0]));
454 wsprintfW (result
, fmt__3sW
, buffer
);
457 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SMONTHNAME1
+date
.wMonth
-1,
461 result
[0] = (date
.wHour
< 12 ? 'A' : 'P');
465 result
[0] = (date
.wHour
< 12 ? 'A' : 'P');
470 FIXME ("Not implemented\n");
475 wsprintfW (result
, fmt_dW
, date
.wYear
-10* (int) floor(date
.wYear
/10));
478 wsprintfW (result
, fmt__2dW
, date
.wYear
-100* (int) floor(date
.wYear
/100));
480 case INVALIDFULLYEAR
:
482 wsprintfW (result
, fmt_dW
, date
.wYear
);
486 TRACE ("arg%d=%x->[%s]\n", count
, infoPtr
->fieldspec
[count
], debugstr_w(result
));
489 static int wrap(int val
, int delta
, int minVal
, int maxVal
)
492 if (delta
== INT_MIN
|| val
< minVal
) return maxVal
;
493 if (delta
== INT_MAX
|| val
> maxVal
) return minVal
;
498 DATETIME_IncreaseField (DATETIME_INFO
*infoPtr
, int number
, int delta
)
500 SYSTEMTIME
*date
= &infoPtr
->date
;
505 TRACE ("%d\n", number
);
506 if ((number
> infoPtr
->nrFields
) || (number
< 0)) return;
508 if ((infoPtr
->fieldspec
[number
] & DTHT_DATEFIELD
) == 0) return;
510 switch (infoPtr
->fieldspec
[number
]) {
514 if (delta
== INT_MIN
)
516 else if (delta
== INT_MAX
)
519 date
->wYear
= max(min(date
->wYear
+ delta
, 9999), 1752);
521 if (date
->wDay
> MONTHCAL_MonthLength(date
->wMonth
, date
->wYear
))
522 /* This can happen when moving away from a leap year. */
523 date
->wDay
= MONTHCAL_MonthLength(date
->wMonth
, date
->wYear
);
524 MONTHCAL_CalculateDayOfWeek(date
, TRUE
);
530 date
->wMonth
= wrap(date
->wMonth
, delta
, 1, 12);
531 MONTHCAL_CalculateDayOfWeek(date
, TRUE
);
538 date
->wDay
= wrap(date
->wDay
, delta
, 1, MONTHCAL_MonthLength(date
->wMonth
, date
->wYear
));
539 MONTHCAL_CalculateDayOfWeek(date
, TRUE
);
549 date
->wHour
= wrap(date
->wHour
, delta
, 0, 23);
553 date
->wMinute
= wrap(date
->wMinute
, delta
, 0, 59);
557 date
->wSecond
= wrap(date
->wSecond
, delta
, 0, 59);
560 FIXME ("Not implemented\n");
564 /* FYI: On 1752/9/14 the calendar changed and England and the
565 * American colonies changed to the Gregorian calendar. This change
566 * involved having September 14th follow September 2nd. So no date
567 * algorithm works before that date.
569 if (10000 * date
->wYear
+ 100 * date
->wMonth
+ date
->wDay
< 17520914) {
578 /* Ensure time is within bounds */
579 limits
= SendMessageW (infoPtr
->hMonthCal
, MCM_GETRANGE
, 0, (LPARAM
)range
);
582 if (limits
& (min
? GDTR_MIN
: GDTR_MAX
))
584 int i
= (min
? 0 : 1);
586 if (MONTHCAL_CompareSystemTime(date
, &range
[i
]) == (min
? -1 : 1))
588 date
->wYear
= range
[i
].wYear
;
589 date
->wMonth
= range
[i
].wMonth
;
590 date
->wDayOfWeek
= range
[i
].wDayOfWeek
;
591 date
->wDay
= range
[i
].wDay
;
592 date
->wHour
= range
[i
].wHour
;
593 date
->wMinute
= range
[i
].wMinute
;
594 date
->wSecond
= range
[i
].wSecond
;
595 date
->wMilliseconds
= range
[i
].wMilliseconds
;
601 DATETIME_ReturnFieldWidth (const DATETIME_INFO
*infoPtr
, HDC hdc
, int count
, SHORT
*width
)
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 TRACE ("%d,%d\n", infoPtr
->nrFields
, count
);
616 if (count
>infoPtr
->nrFields
|| count
< 0) {
617 WARN ("buffer overrun, have %d want %d\n", infoPtr
->nrFields
, count
);
621 if (!infoPtr
->fieldspec
) return;
623 spec
= infoPtr
->fieldspec
[count
];
624 if (spec
& DT_STRING
) {
625 int txtlen
= infoPtr
->buflen
[count
];
629 memcpy (buffer
, infoPtr
->textbuf
+ (spec
&~ DT_STRING
), txtlen
* sizeof(WCHAR
));
642 /* these seem to use a two byte field */
652 case INVALIDFULLYEAR
:
661 static const WCHAR fld_day
[] = {'W','e','d','n','e','s','d','a','y',0};
662 static const WCHAR fld_abbrday
[] = {'W','e','d',0};
663 static const WCHAR fld_mon
[] = {'S','e','p','t','e','m','b','e','r',0};
664 static const WCHAR fld_abbrmon
[] = {'D','e','c',0};
671 /* choose locale data type and fallback string */
675 lctype
= LOCALE_SABBREVDAYNAME1
;
680 lctype
= LOCALE_SDAYNAME1
;
685 lctype
= LOCALE_SABBREVMONTHNAME1
;
688 default: /* FULLMONTH */
690 lctype
= LOCALE_SMONTHNAME1
;
696 for (i
= 0; i
< max_count
; i
++)
698 if(GetLocaleInfoW(LOCALE_USER_DEFAULT
, lctype
+ i
,
699 buffer
, lstrlenW(buffer
)))
701 GetTextExtentPoint32W(hdc
, buffer
, lstrlenW(buffer
), &size
);
702 if (size
.cx
> cx
) cx
= size
.cx
;
704 else /* locale independent fallback on failure */
706 GetTextExtentPoint32W(hdc
, fall
, lstrlenW(fall
), &size
);
725 GetTextExtentPoint32W (hdc
, bufptr
, strlenW(bufptr
), &size
);
730 DATETIME_Refresh (DATETIME_INFO
*infoPtr
, HDC hdc
)
734 if (infoPtr
->dateValid
) {
737 RECT
*rcDraw
= &infoPtr
->rcDraw
;
739 COLORREF oldTextColor
;
740 SHORT fieldWidth
= 0;
741 HFONT oldFont
= SelectObject (hdc
, infoPtr
->hFont
);
742 INT oldBkMode
= SetBkMode (hdc
, TRANSPARENT
);
745 DATETIME_ReturnTxt (infoPtr
, 0, txt
, sizeof(txt
)/sizeof(txt
[0]));
746 GetTextExtentPoint32W (hdc
, txt
, strlenW(txt
), &size
);
747 rcDraw
->bottom
= size
.cy
+ 2;
749 prevright
= infoPtr
->checkbox
.right
= ((infoPtr
->dwStyle
& DTS_SHOWNONE
) ? 18 : 2);
751 for (i
= 0; i
< infoPtr
->nrFields
; i
++) {
752 DATETIME_ReturnTxt (infoPtr
, i
, txt
, sizeof(txt
)/sizeof(txt
[0]));
753 GetTextExtentPoint32W (hdc
, txt
, strlenW(txt
), &size
);
754 DATETIME_ReturnFieldWidth (infoPtr
, hdc
, i
, &fieldWidth
);
755 field
= &infoPtr
->fieldRect
[i
];
756 field
->left
= prevright
;
757 field
->right
= prevright
+ fieldWidth
;
758 field
->top
= rcDraw
->top
;
759 field
->bottom
= rcDraw
->bottom
;
760 prevright
= field
->right
;
762 if (infoPtr
->dwStyle
& WS_DISABLED
)
763 oldTextColor
= SetTextColor (hdc
, comctl32_color
.clrGrayText
);
764 else if ((infoPtr
->haveFocus
) && (i
== infoPtr
->select
)) {
767 /* fill if focused */
768 HBRUSH hbr
= CreateSolidBrush (comctl32_color
.clrActiveCaption
);
770 if (infoPtr
->nCharsEntered
)
772 memcpy(txt
, infoPtr
->charsEntered
, infoPtr
->nCharsEntered
* sizeof(WCHAR
));
773 txt
[infoPtr
->nCharsEntered
] = 0;
774 GetTextExtentPoint32W (hdc
, txt
, strlenW(txt
), &size
);
777 SetRect(&selection
, 0, 0, size
.cx
, size
.cy
);
778 /* center rectangle */
779 OffsetRect(&selection
, (field
->right
+ field
->left
- size
.cx
)/2,
780 (field
->bottom
- size
.cy
)/2);
782 FillRect(hdc
, &selection
, hbr
);
784 oldTextColor
= SetTextColor (hdc
, comctl32_color
.clrWindow
);
787 oldTextColor
= SetTextColor (hdc
, comctl32_color
.clrWindowText
);
789 /* draw the date text using the colour set above */
790 DrawTextW (hdc
, txt
, strlenW(txt
), field
, DT_CENTER
| DT_VCENTER
| DT_SINGLELINE
);
791 SetTextColor (hdc
, oldTextColor
);
793 SetBkMode (hdc
, oldBkMode
);
794 SelectObject (hdc
, oldFont
);
797 if (!(infoPtr
->dwStyle
& DTS_UPDOWN
)) {
798 DrawFrameControl(hdc
, &infoPtr
->calbutton
, DFC_SCROLL
,
799 DFCS_SCROLLDOWN
| (infoPtr
->bCalDepressed
? DFCS_PUSHED
: 0) |
800 (infoPtr
->dwStyle
& WS_DISABLED
? DFCS_INACTIVE
: 0) );
806 DATETIME_HitTest (const DATETIME_INFO
*infoPtr
, POINT pt
)
810 TRACE ("%s\n", wine_dbgstr_point(&pt
));
812 if (PtInRect (&infoPtr
->calbutton
, pt
)) return DTHT_MCPOPUP
;
813 if (PtInRect (&infoPtr
->checkbox
, pt
)) return DTHT_CHECKBOX
;
815 for (i
= 0; i
< infoPtr
->nrFields
; i
++) {
816 if (PtInRect (&infoPtr
->fieldRect
[i
], pt
)) return i
;
822 /* Returns index of the nearest preceding date field from given,
823 or -1 if none was found */
824 static int DATETIME_GetPrevDateField(const DATETIME_INFO
*infoPtr
, int i
)
826 for(--i
; i
>= 0; i
--)
828 if (infoPtr
->fieldspec
[i
] & DTHT_DATEFIELD
) return i
;
834 DATETIME_ApplySelectedField (DATETIME_INFO
*infoPtr
)
836 int fieldNum
= infoPtr
->select
& DTHT_DATEFIELD
;
838 BOOL clamp_day
= FALSE
;
839 SYSTEMTIME date
= infoPtr
->date
;
842 if (infoPtr
->select
== -1 || infoPtr
->nCharsEntered
== 0)
845 if ((infoPtr
->fieldspec
[fieldNum
] == ONELETTERAMPM
) ||
846 (infoPtr
->fieldspec
[fieldNum
] == TWOLETTERAMPM
))
847 val
= infoPtr
->charsEntered
[0];
849 for (i
=0; i
<infoPtr
->nCharsEntered
; i
++)
850 val
= val
* 10 + infoPtr
->charsEntered
[i
] - '0';
853 infoPtr
->nCharsEntered
= 0;
855 switch (infoPtr
->fieldspec
[fieldNum
]) {
858 oldyear
= date
.wYear
;
859 date
.wYear
= date
.wYear
- (date
.wYear
%100) + val
;
861 if (DATETIME_IsDateInValidRange(infoPtr
, &date
))
864 date
.wYear
= oldyear
;
867 case INVALIDFULLYEAR
:
869 oldyear
= date
.wYear
;
872 if (DATETIME_IsDateInValidRange(infoPtr
, &date
))
875 date
.wYear
= oldyear
;
895 if (date
.wHour
>= 12) /* preserve current AM/PM state */
896 date
.wHour
= (val
== 12 ? 12 : val
+ 12);
898 date
.wHour
= (val
== 12 ? 0 : val
);
915 if (val
== 'a' || val
== 'A') {
916 if (date
.wHour
>= 12)
918 } else if (val
== 'p' || val
== 'P') {
925 if (clamp_day
&& date
.wDay
> MONTHCAL_MonthLength(date
.wMonth
, date
.wYear
))
926 date
.wDay
= MONTHCAL_MonthLength(date
.wMonth
, date
.wYear
);
928 if (DATETIME_SetSystemTime(infoPtr
, GDT_VALID
, &date
))
929 DATETIME_SendDateTimeChangeNotify (infoPtr
);
933 DATETIME_SetSelectedField (DATETIME_INFO
*infoPtr
, int select
)
935 DATETIME_ApplySelectedField(infoPtr
);
937 infoPtr
->select
= select
;
938 infoPtr
->nCharsEntered
= 0;
942 DATETIME_LButtonDown (DATETIME_INFO
*infoPtr
, INT x
, INT y
)
949 new = DATETIME_HitTest (infoPtr
, pt
);
951 SetFocus(infoPtr
->hwndSelf
);
953 if (!(new & DTHT_NODATEMASK
) || (new == DTHT_NONE
))
955 if (new == DTHT_NONE
)
956 new = infoPtr
->nrFields
- 1;
959 /* hitting string part moves selection to next date field to left */
960 if (infoPtr
->fieldspec
[new] & DT_STRING
)
962 new = DATETIME_GetPrevDateField(infoPtr
, new);
963 if (new == -1) return 0;
965 /* never select full day of week */
966 if (infoPtr
->fieldspec
[new] == FULLDAY
) return 0;
970 DATETIME_SetSelectedField(infoPtr
, new);
972 if (infoPtr
->select
== DTHT_MCPOPUP
) {
975 SendMessageW(infoPtr
->hMonthCal
, MCM_GETMINREQRECT
, 0, (LPARAM
)&rcMonthCal
);
977 /* FIXME: button actually is only depressed during dropdown of the */
978 /* calendar control and when the mouse is over the button window */
979 infoPtr
->bCalDepressed
= TRUE
;
981 /* recalculate the position of the monthcal popup */
982 if(infoPtr
->dwStyle
& DTS_RIGHTALIGN
)
983 pos
.x
= infoPtr
->calbutton
.left
- (rcMonthCal
.right
- rcMonthCal
.left
);
985 /* FIXME: this should be after the area reserved for the checkbox */
986 pos
.x
= infoPtr
->rcDraw
.left
;
988 pos
.y
= infoPtr
->rcClient
.bottom
;
989 OffsetRect( &rcMonthCal
, pos
.x
, pos
.y
);
990 MapWindowPoints( infoPtr
->hwndSelf
, 0, (POINT
*)&rcMonthCal
, 2 );
991 SetWindowPos(infoPtr
->hMonthCal
, 0, rcMonthCal
.left
, rcMonthCal
.top
,
992 rcMonthCal
.right
- rcMonthCal
.left
, rcMonthCal
.bottom
- rcMonthCal
.top
, 0);
994 if(IsWindowVisible(infoPtr
->hMonthCal
)) {
995 ShowWindow(infoPtr
->hMonthCal
, SW_HIDE
);
996 infoPtr
->bDropdownEnabled
= FALSE
;
997 DATETIME_SendSimpleNotify (infoPtr
, DTN_CLOSEUP
);
999 const SYSTEMTIME
*lprgSysTimeArray
= &infoPtr
->date
;
1000 TRACE("update calendar %04d/%02d/%02d\n",
1001 lprgSysTimeArray
->wYear
, lprgSysTimeArray
->wMonth
, lprgSysTimeArray
->wDay
);
1002 SendMessageW(infoPtr
->hMonthCal
, MCM_SETCURSEL
, 0, (LPARAM
)(&infoPtr
->date
));
1004 if (infoPtr
->bDropdownEnabled
) {
1005 ShowWindow(infoPtr
->hMonthCal
, SW_SHOW
);
1006 DATETIME_SendSimpleNotify (infoPtr
, DTN_DROPDOWN
);
1008 infoPtr
->bDropdownEnabled
= TRUE
;
1011 TRACE ("dt:%p mc:%p mc parent:%p, desktop:%p\n",
1012 infoPtr
->hwndSelf
, infoPtr
->hMonthCal
, infoPtr
->hwndNotify
, GetDesktopWindow ());
1015 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1022 DATETIME_LButtonUp (DATETIME_INFO
*infoPtr
)
1024 if(infoPtr
->bCalDepressed
) {
1025 infoPtr
->bCalDepressed
= FALSE
;
1026 InvalidateRect(infoPtr
->hwndSelf
, &(infoPtr
->calbutton
), TRUE
);
1034 DATETIME_Paint (DATETIME_INFO
*infoPtr
, HDC hdc
)
1038 hdc
= BeginPaint (infoPtr
->hwndSelf
, &ps
);
1039 DATETIME_Refresh (infoPtr
, hdc
);
1040 EndPaint (infoPtr
->hwndSelf
, &ps
);
1042 DATETIME_Refresh (infoPtr
, hdc
);
1045 /* Not a click on the dropdown box, enabled it */
1046 infoPtr
->bDropdownEnabled
= TRUE
;
1053 DATETIME_Button_Command (DATETIME_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
1055 if( HIWORD(wParam
) == BN_CLICKED
) {
1056 DWORD state
= SendMessageW((HWND
)lParam
, BM_GETCHECK
, 0, 0);
1057 infoPtr
->dateValid
= (state
== BST_CHECKED
);
1058 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1066 DATETIME_Command (DATETIME_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
1068 TRACE("hwndbutton = %p\n", infoPtr
->hwndCheckbut
);
1069 if(infoPtr
->hwndCheckbut
== (HWND
)lParam
)
1070 return DATETIME_Button_Command(infoPtr
, wParam
, lParam
);
1076 DATETIME_Enable (DATETIME_INFO
*infoPtr
, BOOL bEnable
)
1078 TRACE("%p %s\n", infoPtr
, bEnable
? "TRUE" : "FALSE");
1080 infoPtr
->dwStyle
&= ~WS_DISABLED
;
1082 infoPtr
->dwStyle
|= WS_DISABLED
;
1084 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1091 DATETIME_EraseBackground (const DATETIME_INFO
*infoPtr
, HDC hdc
)
1093 HBRUSH hBrush
, hSolidBrush
= NULL
;
1096 if (infoPtr
->dwStyle
& WS_DISABLED
)
1097 hBrush
= hSolidBrush
= CreateSolidBrush(comctl32_color
.clrBtnFace
);
1100 hBrush
= (HBRUSH
)SendMessageW(infoPtr
->hwndNotify
, WM_CTLCOLOREDIT
,
1101 (WPARAM
)hdc
, (LPARAM
)infoPtr
->hwndSelf
);
1103 hBrush
= hSolidBrush
= CreateSolidBrush(comctl32_color
.clrWindow
);
1106 GetClientRect (infoPtr
->hwndSelf
, &rc
);
1108 FillRect (hdc
, &rc
, hBrush
);
1111 DeleteObject(hSolidBrush
);
1118 DATETIME_Notify (DATETIME_INFO
*infoPtr
, const NMHDR
*lpnmh
)
1120 TRACE ("Got notification %x from %p\n", lpnmh
->code
, lpnmh
->hwndFrom
);
1121 TRACE ("info: %p %p %p\n", infoPtr
->hwndSelf
, infoPtr
->hMonthCal
, infoPtr
->hUpdown
);
1123 if (lpnmh
->code
== MCN_SELECT
) {
1124 ShowWindow(infoPtr
->hMonthCal
, SW_HIDE
);
1125 infoPtr
->dateValid
= TRUE
;
1126 SendMessageW (infoPtr
->hMonthCal
, MCM_GETCURSEL
, 0, (LPARAM
)&infoPtr
->date
);
1127 TRACE("got from calendar %04d/%02d/%02d day of week %d\n",
1128 infoPtr
->date
.wYear
, infoPtr
->date
.wMonth
, infoPtr
->date
.wDay
, infoPtr
->date
.wDayOfWeek
);
1129 SendMessageW (infoPtr
->hwndCheckbut
, BM_SETCHECK
, BST_CHECKED
, 0);
1130 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1131 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1132 DATETIME_SendSimpleNotify(infoPtr
, DTN_CLOSEUP
);
1134 if ((lpnmh
->hwndFrom
== infoPtr
->hUpdown
) && (lpnmh
->code
== UDN_DELTAPOS
)) {
1135 const NM_UPDOWN
*lpnmud
= (const NM_UPDOWN
*)lpnmh
;
1136 TRACE("Delta pos %d\n", lpnmud
->iDelta
);
1137 infoPtr
->pendingUpdown
= lpnmud
->iDelta
;
1144 DATETIME_KeyDown (DATETIME_INFO
*infoPtr
, DWORD vkCode
)
1146 int fieldNum
= infoPtr
->select
& DTHT_DATEFIELD
;
1150 if (!(infoPtr
->haveFocus
)) return 0;
1151 if ((fieldNum
==0) && (infoPtr
->select
)) return 0;
1153 if (infoPtr
->select
& FORMATCALLMASK
) {
1154 FIXME ("Callbacks not implemented yet\n");
1160 infoPtr
->nCharsEntered
= 0;
1161 DATETIME_IncreaseField (infoPtr
, fieldNum
, 1);
1162 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1166 infoPtr
->nCharsEntered
= 0;
1167 DATETIME_IncreaseField (infoPtr
, fieldNum
, -1);
1168 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1171 infoPtr
->nCharsEntered
= 0;
1172 DATETIME_IncreaseField (infoPtr
, fieldNum
, INT_MIN
);
1173 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1176 infoPtr
->nCharsEntered
= 0;
1177 DATETIME_IncreaseField (infoPtr
, fieldNum
, INT_MAX
);
1178 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1181 new = infoPtr
->select
;
1189 } while ((infoPtr
->fieldspec
[new] & DT_STRING
) && (wrap
<2));
1190 if (new != infoPtr
->select
)
1191 DATETIME_SetSelectedField(infoPtr
, new);
1194 new = infoPtr
->select
;
1197 if (new==infoPtr
->nrFields
) {
1201 } while ((infoPtr
->fieldspec
[new] & DT_STRING
) && (wrap
<2));
1202 if (new != infoPtr
->select
)
1203 DATETIME_SetSelectedField(infoPtr
, new);
1207 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1214 DATETIME_Char (DATETIME_INFO
*infoPtr
, WPARAM vkCode
)
1216 int fieldNum
, fieldSpec
;
1218 fieldNum
= infoPtr
->select
& DTHT_DATEFIELD
;
1219 fieldSpec
= infoPtr
->fieldspec
[fieldNum
];
1221 if (fieldSpec
== ONELETTERAMPM
|| fieldSpec
== TWOLETTERAMPM
) {
1222 infoPtr
->charsEntered
[0] = vkCode
;
1223 infoPtr
->nCharsEntered
= 1;
1225 DATETIME_ApplySelectedField(infoPtr
);
1226 } else if (vkCode
>= '0' && vkCode
<= '9') {
1229 infoPtr
->charsEntered
[infoPtr
->nCharsEntered
++] = vkCode
;
1231 if (fieldSpec
== INVALIDFULLYEAR
|| fieldSpec
== FULLYEAR
)
1236 if ((fieldSpec
== ONEDIGIT12HOUR
||
1237 fieldSpec
== TWODIGIT12HOUR
||
1238 fieldSpec
== ONEDIGIT24HOUR
||
1239 fieldSpec
== TWODIGIT24HOUR
) &&
1240 (infoPtr
->nCharsEntered
== 1))
1246 if (maxChars
== infoPtr
->nCharsEntered
)
1247 DATETIME_ApplySelectedField(infoPtr
);
1255 DATETIME_VScroll (DATETIME_INFO
*infoPtr
, WORD wScroll
)
1257 int fieldNum
= infoPtr
->select
& DTHT_DATEFIELD
;
1259 if ((SHORT
)LOWORD(wScroll
) != SB_THUMBPOSITION
) return 0;
1260 if (!(infoPtr
->haveFocus
)) return 0;
1261 if ((fieldNum
==0) && (infoPtr
->select
)) return 0;
1263 if (infoPtr
->pendingUpdown
>= 0) {
1264 DATETIME_IncreaseField (infoPtr
, fieldNum
, 1);
1265 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1268 DATETIME_IncreaseField (infoPtr
, fieldNum
, -1);
1269 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1272 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1279 DATETIME_KillFocus (DATETIME_INFO
*infoPtr
, HWND lostFocus
)
1281 TRACE("lost focus to %p\n", lostFocus
);
1283 if (infoPtr
->haveFocus
) {
1284 DATETIME_SendSimpleNotify (infoPtr
, NM_KILLFOCUS
);
1285 infoPtr
->haveFocus
= 0;
1286 DATETIME_SetSelectedField (infoPtr
, -1);
1289 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
1296 DATETIME_NCCreate (HWND hwnd
, const CREATESTRUCTW
*lpcs
)
1298 DWORD dwExStyle
= GetWindowLongW(hwnd
, GWL_EXSTYLE
);
1299 /* force control to have client edge */
1300 dwExStyle
|= WS_EX_CLIENTEDGE
;
1301 SetWindowLongW(hwnd
, GWL_EXSTYLE
, dwExStyle
);
1303 return DefWindowProcW(hwnd
, WM_NCCREATE
, 0, (LPARAM
)lpcs
);
1308 DATETIME_SetFocus (DATETIME_INFO
*infoPtr
, HWND lostFocus
)
1310 TRACE("got focus from %p\n", lostFocus
);
1312 /* if monthcal is open and it loses focus, close monthcal */
1313 if (infoPtr
->hMonthCal
&& (lostFocus
== infoPtr
->hMonthCal
) &&
1314 IsWindowVisible(infoPtr
->hMonthCal
))
1316 ShowWindow(infoPtr
->hMonthCal
, SW_HIDE
);
1317 DATETIME_SendSimpleNotify(infoPtr
, DTN_CLOSEUP
);
1318 /* note: this get triggered even if monthcal loses focus to a dropdown
1319 * box click, which occurs without an intermediate WM_PAINT call
1321 infoPtr
->bDropdownEnabled
= FALSE
;
1325 if (infoPtr
->haveFocus
== 0) {
1326 DATETIME_SendSimpleNotify (infoPtr
, NM_SETFOCUS
);
1327 infoPtr
->haveFocus
= DTHT_GOTFOCUS
;
1330 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1337 DATETIME_SendDateTimeChangeNotify (const DATETIME_INFO
*infoPtr
)
1339 NMDATETIMECHANGE dtdtc
;
1341 dtdtc
.nmhdr
.hwndFrom
= infoPtr
->hwndSelf
;
1342 dtdtc
.nmhdr
.idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1343 dtdtc
.nmhdr
.code
= DTN_DATETIMECHANGE
;
1345 dtdtc
.dwFlags
= infoPtr
->dateValid
? GDT_VALID
: GDT_NONE
;
1347 dtdtc
.st
= infoPtr
->date
;
1348 return (BOOL
) SendMessageW (infoPtr
->hwndNotify
, WM_NOTIFY
,
1349 dtdtc
.nmhdr
.idFrom
, (LPARAM
)&dtdtc
);
1354 DATETIME_SendSimpleNotify (const DATETIME_INFO
*infoPtr
, UINT code
)
1358 TRACE("%x\n", code
);
1359 nmhdr
.hwndFrom
= infoPtr
->hwndSelf
;
1360 nmhdr
.idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1363 return (BOOL
) SendMessageW (infoPtr
->hwndNotify
, WM_NOTIFY
,
1364 nmhdr
.idFrom
, (LPARAM
)&nmhdr
);
1368 DATETIME_Size (DATETIME_INFO
*infoPtr
, INT width
, INT height
)
1371 infoPtr
->rcClient
.bottom
= height
;
1372 infoPtr
->rcClient
.right
= width
;
1374 TRACE("Height=%d, Width=%d\n", infoPtr
->rcClient
.bottom
, infoPtr
->rcClient
.right
);
1376 infoPtr
->rcDraw
= infoPtr
->rcClient
;
1378 if (infoPtr
->dwStyle
& DTS_UPDOWN
) {
1379 SetWindowPos(infoPtr
->hUpdown
, NULL
,
1380 infoPtr
->rcClient
.right
-14, 0,
1381 15, infoPtr
->rcClient
.bottom
- infoPtr
->rcClient
.top
,
1382 SWP_NOACTIVATE
| SWP_NOZORDER
);
1385 /* set the size of the button that drops the calendar down */
1386 /* FIXME: account for style that allows button on left side */
1387 infoPtr
->calbutton
.top
= infoPtr
->rcDraw
.top
;
1388 infoPtr
->calbutton
.bottom
= infoPtr
->rcDraw
.bottom
;
1389 infoPtr
->calbutton
.left
= infoPtr
->rcDraw
.right
-15;
1390 infoPtr
->calbutton
.right
= infoPtr
->rcDraw
.right
;
1393 /* set enable/disable button size for show none style being enabled */
1394 /* FIXME: these dimensions are completely incorrect */
1395 infoPtr
->checkbox
.top
= infoPtr
->rcDraw
.top
;
1396 infoPtr
->checkbox
.bottom
= infoPtr
->rcDraw
.bottom
;
1397 infoPtr
->checkbox
.left
= infoPtr
->rcDraw
.left
;
1398 infoPtr
->checkbox
.right
= infoPtr
->rcDraw
.left
+ 10;
1400 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1406 DATETIME_StyleChanging(DATETIME_INFO
*infoPtr
, WPARAM wStyleType
, STYLESTRUCT
*lpss
)
1408 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
1409 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
1411 /* block DTS_SHOWNONE change */
1412 if ((lpss
->styleNew
^ lpss
->styleOld
) & DTS_SHOWNONE
)
1414 if (lpss
->styleOld
& DTS_SHOWNONE
)
1415 lpss
->styleNew
|= DTS_SHOWNONE
;
1417 lpss
->styleNew
&= ~DTS_SHOWNONE
;
1424 DATETIME_StyleChanged(DATETIME_INFO
*infoPtr
, WPARAM wStyleType
, const STYLESTRUCT
*lpss
)
1426 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
1427 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
1429 if (wStyleType
!= GWL_STYLE
) return 0;
1431 infoPtr
->dwStyle
= lpss
->styleNew
;
1433 if ( !(lpss
->styleOld
& DTS_SHOWNONE
) && (lpss
->styleNew
& DTS_SHOWNONE
) ) {
1434 infoPtr
->hwndCheckbut
= CreateWindowExW (0, WC_BUTTONW
, 0, WS_CHILD
| WS_VISIBLE
| BS_AUTOCHECKBOX
,
1435 2, 2, 13, 13, infoPtr
->hwndSelf
, 0,
1436 (HINSTANCE
)GetWindowLongPtrW (infoPtr
->hwndSelf
, GWLP_HINSTANCE
), 0);
1437 SendMessageW (infoPtr
->hwndCheckbut
, BM_SETCHECK
, infoPtr
->dateValid
? 1 : 0, 0);
1439 if ( (lpss
->styleOld
& DTS_SHOWNONE
) && !(lpss
->styleNew
& DTS_SHOWNONE
) ) {
1440 DestroyWindow(infoPtr
->hwndCheckbut
);
1441 infoPtr
->hwndCheckbut
= 0;
1443 if ( !(lpss
->styleOld
& DTS_UPDOWN
) && (lpss
->styleNew
& DTS_UPDOWN
) ) {
1444 infoPtr
->hUpdown
= CreateUpDownControl (WS_CHILD
| WS_BORDER
| WS_VISIBLE
, 120, 1, 20, 20,
1445 infoPtr
->hwndSelf
, 1, 0, 0, UD_MAXVAL
, UD_MINVAL
, 0);
1447 if ( (lpss
->styleOld
& DTS_UPDOWN
) && !(lpss
->styleNew
& DTS_UPDOWN
) ) {
1448 DestroyWindow(infoPtr
->hUpdown
);
1449 infoPtr
->hUpdown
= 0;
1452 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1458 DATETIME_SetFont (DATETIME_INFO
*infoPtr
, HFONT font
, BOOL repaint
)
1460 infoPtr
->hFont
= font
;
1461 if (repaint
) InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1467 DATETIME_Create (HWND hwnd
, const CREATESTRUCTW
*lpcs
)
1469 DATETIME_INFO
*infoPtr
= Alloc (sizeof(DATETIME_INFO
));
1470 STYLESTRUCT ss
= { 0, lpcs
->style
};
1472 if (!infoPtr
) return -1;
1474 infoPtr
->hwndSelf
= hwnd
;
1475 infoPtr
->dwStyle
= lpcs
->style
;
1477 infoPtr
->nrFieldsAllocated
= 32;
1478 infoPtr
->fieldspec
= Alloc (infoPtr
->nrFieldsAllocated
* sizeof(int));
1479 infoPtr
->fieldRect
= Alloc (infoPtr
->nrFieldsAllocated
* sizeof(RECT
));
1480 infoPtr
->buflen
= Alloc (infoPtr
->nrFieldsAllocated
* sizeof(int));
1481 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
1482 infoPtr
->select
= -1; /* initially, nothing is selected */
1483 infoPtr
->bDropdownEnabled
= TRUE
;
1485 DATETIME_StyleChanged(infoPtr
, GWL_STYLE
, &ss
);
1486 DATETIME_SetFormatW (infoPtr
, 0);
1488 /* create the monthcal control */
1489 infoPtr
->hMonthCal
= CreateWindowExW (0, MONTHCAL_CLASSW
, 0, WS_BORDER
| WS_POPUP
| WS_CLIPSIBLINGS
,
1490 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, 0, 0);
1492 /* initialize info structure */
1493 GetLocalTime (&infoPtr
->date
);
1494 infoPtr
->dateValid
= TRUE
;
1495 infoPtr
->hFont
= GetStockObject(DEFAULT_GUI_FONT
);
1497 SetWindowLongPtrW (hwnd
, 0, (DWORD_PTR
)infoPtr
);
1505 DATETIME_Destroy (DATETIME_INFO
*infoPtr
)
1507 if (infoPtr
->hwndCheckbut
)
1508 DestroyWindow(infoPtr
->hwndCheckbut
);
1509 if (infoPtr
->hUpdown
)
1510 DestroyWindow(infoPtr
->hUpdown
);
1511 if (infoPtr
->hMonthCal
)
1512 DestroyWindow(infoPtr
->hMonthCal
);
1513 SetWindowLongPtrW( infoPtr
->hwndSelf
, 0, 0 ); /* clear infoPtr */
1514 Free (infoPtr
->buflen
);
1515 Free (infoPtr
->fieldRect
);
1516 Free (infoPtr
->fieldspec
);
1523 DATETIME_GetText (const DATETIME_INFO
*infoPtr
, INT count
, LPWSTR dst
)
1528 if (!dst
|| (count
<= 0)) return 0;
1531 for (i
= 0; i
< infoPtr
->nrFields
; i
++)
1533 DATETIME_ReturnTxt(infoPtr
, i
, buf
, sizeof(buf
)/sizeof(buf
[0]));
1534 if ((strlenW(dst
) + strlenW(buf
)) < count
)
1538 return strlenW(dst
);
1542 static LRESULT WINAPI
1543 DATETIME_WindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1545 DATETIME_INFO
*infoPtr
= ((DATETIME_INFO
*)GetWindowLongPtrW (hwnd
, 0));
1547 TRACE ("%x, %lx, %lx\n", uMsg
, wParam
, lParam
);
1549 if (!infoPtr
&& (uMsg
!= WM_CREATE
) && (uMsg
!= WM_NCCREATE
))
1550 return DefWindowProcW( hwnd
, uMsg
, wParam
, lParam
);
1554 case DTM_GETSYSTEMTIME
:
1555 return DATETIME_GetSystemTime (infoPtr
, (SYSTEMTIME
*) lParam
);
1557 case DTM_SETSYSTEMTIME
:
1558 return DATETIME_SetSystemTime (infoPtr
, wParam
, (SYSTEMTIME
*) lParam
);
1561 return SendMessageW (infoPtr
->hMonthCal
, MCM_GETRANGE
, wParam
, lParam
);
1564 return SendMessageW (infoPtr
->hMonthCal
, MCM_SETRANGE
, wParam
, lParam
);
1566 case DTM_SETFORMATA
:
1567 return DATETIME_SetFormatA (infoPtr
, (LPCSTR
)lParam
);
1569 case DTM_SETFORMATW
:
1570 return DATETIME_SetFormatW (infoPtr
, (LPCWSTR
)lParam
);
1572 case DTM_GETMONTHCAL
:
1573 return (LRESULT
)infoPtr
->hMonthCal
;
1575 case DTM_SETMCCOLOR
:
1576 return SendMessageW (infoPtr
->hMonthCal
, MCM_SETCOLOR
, wParam
, lParam
);
1578 case DTM_GETMCCOLOR
:
1579 return SendMessageW (infoPtr
->hMonthCal
, MCM_GETCOLOR
, wParam
, 0);
1582 return SendMessageW (infoPtr
->hMonthCal
, WM_SETFONT
, wParam
, lParam
);
1585 return SendMessageW (infoPtr
->hMonthCal
, WM_GETFONT
, wParam
, lParam
);
1588 return DATETIME_Notify (infoPtr
, (LPNMHDR
)lParam
);
1591 return DATETIME_Enable (infoPtr
, (BOOL
)wParam
);
1594 return DATETIME_EraseBackground (infoPtr
, (HDC
)wParam
);
1597 return DLGC_WANTARROWS
| DLGC_WANTCHARS
;
1599 case WM_PRINTCLIENT
:
1601 return DATETIME_Paint (infoPtr
, (HDC
)wParam
);
1604 return DATETIME_KeyDown (infoPtr
, wParam
);
1607 return DATETIME_Char (infoPtr
, wParam
);
1610 return DATETIME_KillFocus (infoPtr
, (HWND
)wParam
);
1613 return DATETIME_NCCreate (hwnd
, (LPCREATESTRUCTW
)lParam
);
1616 return DATETIME_SetFocus (infoPtr
, (HWND
)wParam
);
1619 return DATETIME_Size (infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
1621 case WM_LBUTTONDOWN
:
1622 return DATETIME_LButtonDown (infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
1625 return DATETIME_LButtonUp (infoPtr
);
1628 return DATETIME_VScroll (infoPtr
, (WORD
)wParam
);
1631 return DATETIME_Create (hwnd
, (LPCREATESTRUCTW
)lParam
);
1634 return DATETIME_Destroy (infoPtr
);
1637 return DATETIME_Command (infoPtr
, wParam
, lParam
);
1639 case WM_STYLECHANGING
:
1640 return DATETIME_StyleChanging(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
1642 case WM_STYLECHANGED
:
1643 return DATETIME_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
1646 return DATETIME_SetFont(infoPtr
, (HFONT
)wParam
, (BOOL
)lParam
);
1649 return (LRESULT
) infoPtr
->hFont
;
1652 return (LRESULT
) DATETIME_GetText(infoPtr
, wParam
, (LPWSTR
)lParam
);
1658 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
1659 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
1660 uMsg
, wParam
, lParam
);
1661 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
1667 DATETIME_Register (void)
1671 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
1672 wndClass
.style
= CS_GLOBALCLASS
;
1673 wndClass
.lpfnWndProc
= DATETIME_WindowProc
;
1674 wndClass
.cbClsExtra
= 0;
1675 wndClass
.cbWndExtra
= sizeof(DATETIME_INFO
*);
1676 wndClass
.hCursor
= LoadCursorW (0, (LPCWSTR
)IDC_ARROW
);
1677 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
1678 wndClass
.lpszClassName
= DATETIMEPICK_CLASSW
;
1680 RegisterClassW (&wndClass
);
1685 DATETIME_Unregister (void)
1687 UnregisterClassW (DATETIMEPICK_CLASSW
, NULL
);