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>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 * This code was audited for completeness against the documented features
25 * of Comctl32.dll version 6.0 on Oct. 20, 2004, by Dimitrie O. Paun.
27 * Unless otherwise noted, we believe this code to be complete, as per
28 * the specification mentioned above.
29 * If you discover missing features, or bugs, please note them below.
33 * -- DTS_SHORTDATECENTURYFORMAT
54 #include "wine/debug.h"
55 #include "wine/unicode.h"
57 WINE_DEFAULT_DEBUG_CHANNEL(datetime
);
69 RECT rcClient
; /* rect around the edge of the window */
70 RECT rcDraw
; /* rect inside of the border */
71 RECT checkbox
; /* checkbox allowing the control to be enabled/disabled */
72 RECT calbutton
; /* button that toggles the dropdown of the monthcal control */
73 BOOL bCalDepressed
; /* TRUE = cal button is depressed */
76 WCHAR charsEntered
[4];
79 int nrFieldsAllocated
;
88 } DATETIME_INFO
, *LPDATETIME_INFO
;
91 extern int MONTHCAL_MonthLength(int month
, int year
);
92 extern int MONTHCAL_CalculateDayOfWeek(SYSTEMTIME
*date
, BOOL inplace
);
94 /* this list of defines is closely related to `allowedformatchars' defined
95 * in datetime.c; the high nibble indicates the `base type' of the format
97 * Do not change without first reading DATETIME_UseFormat.
101 #define DT_END_FORMAT 0
102 #define ONEDIGITDAY 0x01
103 #define TWODIGITDAY 0x02
104 #define THREECHARDAY 0x03
106 #define ONEDIGIT12HOUR 0x11
107 #define TWODIGIT12HOUR 0x12
108 #define ONEDIGIT24HOUR 0x21
109 #define TWODIGIT24HOUR 0x22
110 #define ONEDIGITMINUTE 0x31
111 #define TWODIGITMINUTE 0x32
112 #define ONEDIGITMONTH 0x41
113 #define TWODIGITMONTH 0x42
114 #define THREECHARMONTH 0x43
115 #define FULLMONTH 0x44
116 #define ONEDIGITSECOND 0x51
117 #define TWODIGITSECOND 0x52
118 #define ONELETTERAMPM 0x61
119 #define TWOLETTERAMPM 0x62
120 #define ONEDIGITYEAR 0x71
121 #define TWODIGITYEAR 0x72
122 #define INVALIDFULLYEAR 0x73 /* FIXME - yyy is not valid - we'll treat it as yyyy */
123 #define FULLYEAR 0x74
124 #define FORMATCALLBACK 0x81 /* -> maximum of 0x80 callbacks possible */
125 #define FORMATCALLMASK 0x80
126 #define DT_STRING 0x0100
128 #define DTHT_DATEFIELD 0xff /* for hit-testing */
130 #define DTHT_NONE 0x1000
131 #define DTHT_CHECKBOX 0x2000 /* these should end at '00' , to make */
132 #define DTHT_MCPOPUP 0x3000 /* & DTHT_DATEFIELD 0 when DATETIME_KeyDown */
133 #define DTHT_GOTFOCUS 0x4000 /* tests for date-fields */
134 #define DTHT_NODATEMASK 0xf000 /* to mask check and drop down from others */
136 static BOOL
DATETIME_SendSimpleNotify (const DATETIME_INFO
*infoPtr
, UINT code
);
137 static BOOL
DATETIME_SendDateTimeChangeNotify (const DATETIME_INFO
*infoPtr
);
138 static const WCHAR allowedformatchars
[] = {'d', 'h', 'H', 'm', 'M', 's', 't', 'y', 'X', 0};
139 static const int maxrepetition
[] = {4,2,2,2,4,2,2,4,-1};
141 /* valid date limits */
142 static const SYSTEMTIME max_allowed_date
= { /* wYear */ 9999, /* wMonth */ 12, /* wDayOfWeek */ 0, /* wDay */ 31 };
143 static const SYSTEMTIME min_allowed_date
= { /* wYear */ 1752, /* wMonth */ 9, /* wDayOfWeek */ 0, /* wDay */ 14 };
146 DATETIME_GetSystemTime (const DATETIME_INFO
*infoPtr
, SYSTEMTIME
*systime
)
148 if (!systime
) return GDT_NONE
;
150 if ((infoPtr
->dwStyle
& DTS_SHOWNONE
) &&
151 (SendMessageW (infoPtr
->hwndCheckbut
, BM_GETCHECK
, 0, 0) == BST_UNCHECKED
))
154 *systime
= infoPtr
->date
;
159 /* Checks value is within configured date range
163 * [I] infoPtr : valid pointer to control data
164 * [I] date : pointer to valid date data to check
168 * TRUE - date within configured range
169 * FALSE - date is outside configured range
171 static BOOL
DATETIME_IsDateInValidRange(const DATETIME_INFO
*infoPtr
, const SYSTEMTIME
*date
)
176 if ((MONTHCAL_CompareSystemTime(date
, &max_allowed_date
) == 1) ||
177 (MONTHCAL_CompareSystemTime(date
, &min_allowed_date
) == -1))
180 limits
= SendMessageW (infoPtr
->hMonthCal
, MCM_GETRANGE
, 0, (LPARAM
) &range
);
182 if (limits
& GDTR_MAX
)
184 if (MONTHCAL_CompareSystemTime(date
, &range
[1]) == 1)
188 if (limits
& GDTR_MIN
)
190 if (MONTHCAL_CompareSystemTime(date
, &range
[0]) == -1)
198 DATETIME_SetSystemTime (DATETIME_INFO
*infoPtr
, DWORD flag
, const SYSTEMTIME
*systime
)
200 if (!systime
) return 0;
202 TRACE("%04d/%02d/%02d %02d:%02d:%02d\n",
203 systime
->wYear
, systime
->wMonth
, systime
->wDay
,
204 systime
->wHour
, systime
->wMinute
, systime
->wSecond
);
206 if (flag
== GDT_VALID
) {
207 if (systime
->wYear
== 0 ||
208 systime
->wMonth
< 1 || systime
->wMonth
> 12 ||
210 systime
->wDay
> MONTHCAL_MonthLength(systime
->wMonth
, systime
->wYear
) ||
211 systime
->wHour
> 23 ||
212 systime
->wMinute
> 59 ||
213 systime
->wSecond
> 59 ||
214 systime
->wMilliseconds
> 999
218 /* Windows returns true if the date is valid but outside the limits set */
219 if (DATETIME_IsDateInValidRange(infoPtr
, systime
) == FALSE
)
222 infoPtr
->dateValid
= TRUE
;
223 infoPtr
->date
= *systime
;
224 /* always store a valid day of week */
225 MONTHCAL_CalculateDayOfWeek(&infoPtr
->date
, TRUE
);
227 SendMessageW (infoPtr
->hMonthCal
, MCM_SETCURSEL
, 0, (LPARAM
)(&infoPtr
->date
));
228 SendMessageW (infoPtr
->hwndCheckbut
, BM_SETCHECK
, BST_CHECKED
, 0);
229 } else if ((infoPtr
->dwStyle
& DTS_SHOWNONE
) && (flag
== GDT_NONE
)) {
230 infoPtr
->dateValid
= FALSE
;
231 SendMessageW (infoPtr
->hwndCheckbut
, BM_SETCHECK
, BST_UNCHECKED
, 0);
236 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
242 * Split up a formattxt in actions.
243 * See ms documentation for the meaning of the letter codes/'specifiers'.
246 * *'dddddd' is handled as 'dddd' plus 'dd'.
247 * *unrecognized formats are strings (here given the type DT_STRING;
248 * start of the string is encoded in lower bits of DT_STRING.
249 * Therefore, 'string' ends finally up as '<show seconds>tring'.
253 DATETIME_UseFormat (DATETIME_INFO
*infoPtr
, LPCWSTR formattxt
)
257 BOOL inside_literal
= FALSE
; /* inside '...' */
258 int *nrFields
= &infoPtr
->nrFields
;
261 infoPtr
->fieldspec
[*nrFields
] = 0;
262 len
= strlenW(allowedformatchars
);
265 for (i
= 0; formattxt
[i
]; i
++) {
266 TRACE ("\n%d %c:", i
, formattxt
[i
]);
267 if (!inside_literal
) {
268 for (j
= 0; j
< len
; j
++) {
269 if (allowedformatchars
[j
]==formattxt
[i
]) {
270 TRACE ("%c[%d,%x]", allowedformatchars
[j
], *nrFields
, infoPtr
->fieldspec
[*nrFields
]);
271 if ((*nrFields
==0) && (infoPtr
->fieldspec
[*nrFields
]==0)) {
272 infoPtr
->fieldspec
[*nrFields
] = (j
<<4) + 1;
275 if (infoPtr
->fieldspec
[*nrFields
] >> 4 != j
) {
277 infoPtr
->fieldspec
[*nrFields
] = (j
<<4) + 1;
280 if ((infoPtr
->fieldspec
[*nrFields
] & 0x0f) == maxrepetition
[j
]) {
282 infoPtr
->fieldspec
[*nrFields
] = (j
<<4) + 1;
285 infoPtr
->fieldspec
[*nrFields
]++;
287 } /* if allowedformatchar */
293 if (formattxt
[i
] == '\'')
295 inside_literal
= !inside_literal
;
299 /* char is not a specifier: handle char like a string */
301 if ((*nrFields
==0) && (infoPtr
->fieldspec
[*nrFields
]==0)) {
302 infoPtr
->fieldspec
[*nrFields
] = DT_STRING
+ k
;
303 infoPtr
->buflen
[*nrFields
] = 0;
304 } else if ((infoPtr
->fieldspec
[*nrFields
] & DT_STRING
) != DT_STRING
) {
306 infoPtr
->fieldspec
[*nrFields
] = DT_STRING
+ k
;
307 infoPtr
->buflen
[*nrFields
] = 0;
309 infoPtr
->textbuf
[k
] = formattxt
[i
];
311 infoPtr
->buflen
[*nrFields
]++;
314 if (*nrFields
== infoPtr
->nrFieldsAllocated
) {
315 FIXME ("out of memory; should reallocate. crash ahead.\n");
321 if (infoPtr
->fieldspec
[*nrFields
] != 0) (*nrFields
)++;
326 DATETIME_SetFormatW (DATETIME_INFO
*infoPtr
, LPCWSTR format
)
328 WCHAR format_buf
[80];
333 if (infoPtr
->dwStyle
& DTS_LONGDATEFORMAT
)
334 format_item
= LOCALE_SLONGDATE
;
335 else if ((infoPtr
->dwStyle
& DTS_TIMEFORMAT
) == DTS_TIMEFORMAT
)
336 format_item
= LOCALE_STIMEFORMAT
;
337 else /* DTS_SHORTDATEFORMAT */
338 format_item
= LOCALE_SSHORTDATE
;
339 GetLocaleInfoW(LOCALE_USER_DEFAULT
, format_item
, format_buf
, sizeof(format_buf
)/sizeof(format_buf
[0]));
343 DATETIME_UseFormat (infoPtr
, format
);
344 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
351 DATETIME_SetFormatA (DATETIME_INFO
*infoPtr
, LPCSTR lpszFormat
)
355 INT len
= MultiByteToWideChar(CP_ACP
, 0, lpszFormat
, -1, NULL
, 0);
356 LPWSTR wstr
= Alloc(len
* sizeof(WCHAR
));
357 if (wstr
) MultiByteToWideChar(CP_ACP
, 0, lpszFormat
, -1, wstr
, len
);
358 retval
= DATETIME_SetFormatW (infoPtr
, wstr
);
363 return DATETIME_SetFormatW (infoPtr
, 0);
369 DATETIME_ReturnTxt (const DATETIME_INFO
*infoPtr
, int count
, LPWSTR result
, int resultSize
)
371 static const WCHAR fmt_dW
[] = { '%', 'd', 0 };
372 static const WCHAR fmt__2dW
[] = { '%', '.', '2', 'd', 0 };
373 static const WCHAR fmt__3sW
[] = { '%', '.', '3', 's', 0 };
374 SYSTEMTIME date
= infoPtr
->date
;
379 TRACE ("%d,%d\n", infoPtr
->nrFields
, count
);
380 if (count
>infoPtr
->nrFields
|| count
< 0) {
381 WARN ("buffer overrun, have %d want %d\n", infoPtr
->nrFields
, count
);
385 if (!infoPtr
->fieldspec
) return;
387 spec
= infoPtr
->fieldspec
[count
];
388 if (spec
& DT_STRING
) {
389 int txtlen
= infoPtr
->buflen
[count
];
391 if (txtlen
> resultSize
)
392 txtlen
= resultSize
- 1;
393 memcpy (result
, infoPtr
->textbuf
+ (spec
&~ DT_STRING
), txtlen
* sizeof(WCHAR
));
395 TRACE ("arg%d=%x->[%s]\n", count
, infoPtr
->fieldspec
[count
], debugstr_w(result
));
405 wsprintfW (result
, fmt_dW
, date
.wDay
);
408 wsprintfW (result
, fmt__2dW
, date
.wDay
);
411 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SABBREVDAYNAME1
+(date
.wDayOfWeek
+6)%7, result
, 4);
412 /*wsprintfW (result,"%.3s",days[date.wDayOfWeek]);*/
415 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SDAYNAME1
+(date
.wDayOfWeek
+6)%7, result
, resultSize
);
418 if (date
.wHour
== 0) {
424 wsprintfW (result
, fmt_dW
, date
.wHour
- (date
.wHour
> 12 ? 12 : 0));
427 if (date
.wHour
== 0) {
433 wsprintfW (result
, fmt__2dW
, date
.wHour
- (date
.wHour
> 12 ? 12 : 0));
436 wsprintfW (result
, fmt_dW
, date
.wHour
);
439 wsprintfW (result
, fmt__2dW
, date
.wHour
);
442 wsprintfW (result
, fmt_dW
, date
.wSecond
);
445 wsprintfW (result
, fmt__2dW
, date
.wSecond
);
448 wsprintfW (result
, fmt_dW
, date
.wMinute
);
451 wsprintfW (result
, fmt__2dW
, date
.wMinute
);
454 wsprintfW (result
, fmt_dW
, date
.wMonth
);
457 wsprintfW (result
, fmt__2dW
, date
.wMonth
);
460 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SMONTHNAME1
+date
.wMonth
-1,
461 buffer
, sizeof(buffer
)/sizeof(buffer
[0]));
462 wsprintfW (result
, fmt__3sW
, buffer
);
465 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SMONTHNAME1
+date
.wMonth
-1,
469 result
[0] = (date
.wHour
< 12 ? 'A' : 'P');
473 result
[0] = (date
.wHour
< 12 ? 'A' : 'P');
478 FIXME ("Not implemented\n");
483 wsprintfW (result
, fmt_dW
, date
.wYear
-10* (int) floor(date
.wYear
/10));
486 wsprintfW (result
, fmt__2dW
, date
.wYear
-100* (int) floor(date
.wYear
/100));
488 case INVALIDFULLYEAR
:
490 wsprintfW (result
, fmt_dW
, date
.wYear
);
494 TRACE ("arg%d=%x->[%s]\n", count
, infoPtr
->fieldspec
[count
], debugstr_w(result
));
497 static int wrap(int val
, int delta
, int minVal
, int maxVal
)
500 if (delta
== INT_MIN
|| val
< minVal
) return maxVal
;
501 if (delta
== INT_MAX
|| val
> maxVal
) return minVal
;
506 DATETIME_IncreaseField (DATETIME_INFO
*infoPtr
, int number
, int delta
)
508 SYSTEMTIME
*date
= &infoPtr
->date
;
513 TRACE ("%d\n", number
);
514 if ((number
> infoPtr
->nrFields
) || (number
< 0)) return;
516 if ((infoPtr
->fieldspec
[number
] & DTHT_DATEFIELD
) == 0) return;
518 switch (infoPtr
->fieldspec
[number
]) {
522 if (delta
== INT_MIN
)
524 else if (delta
== INT_MAX
)
527 date
->wYear
= max(min(date
->wYear
+ delta
, 9999), 1752);
529 if (date
->wDay
> MONTHCAL_MonthLength(date
->wMonth
, date
->wYear
))
530 /* This can happen when moving away from a leap year. */
531 date
->wDay
= MONTHCAL_MonthLength(date
->wMonth
, date
->wYear
);
532 MONTHCAL_CalculateDayOfWeek(date
, TRUE
);
538 date
->wMonth
= wrap(date
->wMonth
, delta
, 1, 12);
539 MONTHCAL_CalculateDayOfWeek(date
, TRUE
);
546 date
->wDay
= wrap(date
->wDay
, delta
, 1, MONTHCAL_MonthLength(date
->wMonth
, date
->wYear
));
547 MONTHCAL_CalculateDayOfWeek(date
, TRUE
);
557 date
->wHour
= wrap(date
->wHour
, delta
, 0, 23);
561 date
->wMinute
= wrap(date
->wMinute
, delta
, 0, 59);
565 date
->wSecond
= wrap(date
->wSecond
, delta
, 0, 59);
568 FIXME ("Not implemented\n");
572 /* FYI: On 1752/9/14 the calendar changed and England and the
573 * American colonies changed to the Gregorian calendar. This change
574 * involved having September 14th follow September 2nd. So no date
575 * algorithm works before that date.
577 if (10000 * date
->wYear
+ 100 * date
->wMonth
+ date
->wDay
< 17520914) {
586 /* Ensure time is within bounds */
587 limits
= SendMessageW (infoPtr
->hMonthCal
, MCM_GETRANGE
, 0, (LPARAM
) &range
);
588 min
= ((delta
< 0) ? TRUE
: FALSE
);
590 if (limits
& (min
? GDTR_MIN
: GDTR_MAX
))
592 int i
= (min
? 0 : 1);
594 if (MONTHCAL_CompareSystemTime(date
, &range
[i
]) == (min
? -1 : 1))
596 date
->wYear
= range
[i
].wYear
;
597 date
->wMonth
= range
[i
].wMonth
;
598 date
->wDayOfWeek
= range
[i
].wDayOfWeek
;
599 date
->wDay
= range
[i
].wDay
;
600 date
->wHour
= range
[i
].wHour
;
601 date
->wMinute
= range
[i
].wMinute
;
602 date
->wSecond
= range
[i
].wSecond
;
603 date
->wMilliseconds
= range
[i
].wMilliseconds
;
609 DATETIME_ReturnFieldWidth (const DATETIME_INFO
*infoPtr
, HDC hdc
, int count
, SHORT
*width
)
611 /* fields are a fixed width, determined by the largest possible string */
612 /* presumably, these widths should be language dependent */
613 static const WCHAR fld_d1W
[] = { '2', 0 };
614 static const WCHAR fld_d2W
[] = { '2', '2', 0 };
615 static const WCHAR fld_d4W
[] = { '2', '2', '2', '2', 0 };
616 static const WCHAR fld_am1
[] = { 'A', 0 };
617 static const WCHAR fld_am2
[] = { 'A', 'M', 0 };
623 TRACE ("%d,%d\n", infoPtr
->nrFields
, count
);
624 if (count
>infoPtr
->nrFields
|| count
< 0) {
625 WARN ("buffer overrun, have %d want %d\n", infoPtr
->nrFields
, count
);
629 if (!infoPtr
->fieldspec
) return;
631 spec
= infoPtr
->fieldspec
[count
];
632 if (spec
& DT_STRING
) {
633 int txtlen
= infoPtr
->buflen
[count
];
637 memcpy (buffer
, infoPtr
->textbuf
+ (spec
&~ DT_STRING
), txtlen
* sizeof(WCHAR
));
650 /* these seem to use a two byte field */
660 case INVALIDFULLYEAR
:
669 static const WCHAR fld_day
[] = {'W','e','d','n','e','s','d','a','y',0};
670 static const WCHAR fld_abbrday
[] = {'W','e','d',0};
671 static const WCHAR fld_mon
[] = {'S','e','p','t','e','m','b','e','r',0};
672 static const WCHAR fld_abbrmon
[] = {'D','e','c',0};
679 /* choose locale data type and fallback string */
683 lctype
= LOCALE_SABBREVDAYNAME1
;
688 lctype
= LOCALE_SDAYNAME1
;
693 lctype
= LOCALE_SABBREVMONTHNAME1
;
696 default: /* FULLMONTH */
698 lctype
= LOCALE_SMONTHNAME1
;
704 for (i
= 0; i
< max_count
; i
++)
706 if(GetLocaleInfoW(LOCALE_USER_DEFAULT
, lctype
+ i
,
707 buffer
, lstrlenW(buffer
)))
709 GetTextExtentPoint32W(hdc
, buffer
, lstrlenW(buffer
), &size
);
710 if (size
.cx
> cx
) cx
= size
.cx
;
712 else /* locale independent fallback on failure */
714 GetTextExtentPoint32W(hdc
, fall
, lstrlenW(fall
), &size
);
733 GetTextExtentPoint32W (hdc
, bufptr
, strlenW(bufptr
), &size
);
738 DATETIME_Refresh (DATETIME_INFO
*infoPtr
, HDC hdc
)
742 if (infoPtr
->dateValid
) {
745 RECT
*rcDraw
= &infoPtr
->rcDraw
;
747 COLORREF oldTextColor
;
748 SHORT fieldWidth
= 0;
749 HFONT oldFont
= SelectObject (hdc
, infoPtr
->hFont
);
750 INT oldBkMode
= SetBkMode (hdc
, TRANSPARENT
);
753 DATETIME_ReturnTxt (infoPtr
, 0, txt
, sizeof(txt
)/sizeof(txt
[0]));
754 GetTextExtentPoint32W (hdc
, txt
, strlenW(txt
), &size
);
755 rcDraw
->bottom
= size
.cy
+ 2;
757 prevright
= infoPtr
->checkbox
.right
= ((infoPtr
->dwStyle
& DTS_SHOWNONE
) ? 18 : 2);
759 for (i
= 0; i
< infoPtr
->nrFields
; i
++) {
760 DATETIME_ReturnTxt (infoPtr
, i
, txt
, sizeof(txt
)/sizeof(txt
[0]));
761 GetTextExtentPoint32W (hdc
, txt
, strlenW(txt
), &size
);
762 DATETIME_ReturnFieldWidth (infoPtr
, hdc
, i
, &fieldWidth
);
763 field
= &infoPtr
->fieldRect
[i
];
764 field
->left
= prevright
;
765 field
->right
= prevright
+ fieldWidth
;
766 field
->top
= rcDraw
->top
;
767 field
->bottom
= rcDraw
->bottom
;
768 prevright
= field
->right
;
770 if (infoPtr
->dwStyle
& WS_DISABLED
)
771 oldTextColor
= SetTextColor (hdc
, comctl32_color
.clrGrayText
);
772 else if ((infoPtr
->haveFocus
) && (i
== infoPtr
->select
)) {
775 /* fill if focused */
776 HBRUSH hbr
= CreateSolidBrush (comctl32_color
.clrActiveCaption
);
778 if (infoPtr
->nCharsEntered
)
780 memcpy(txt
, infoPtr
->charsEntered
, infoPtr
->nCharsEntered
* sizeof(WCHAR
));
781 txt
[infoPtr
->nCharsEntered
] = 0;
782 GetTextExtentPoint32W (hdc
, txt
, strlenW(txt
), &size
);
787 selection
.right
= size
.cx
;
788 selection
.bottom
= size
.cy
;
789 /* center rectangle */
790 OffsetRect(&selection
, (field
->right
+ field
->left
- size
.cx
)/2,
791 (field
->bottom
- size
.cy
)/2);
793 FillRect(hdc
, &selection
, hbr
);
795 oldTextColor
= SetTextColor (hdc
, comctl32_color
.clrWindow
);
798 oldTextColor
= SetTextColor (hdc
, comctl32_color
.clrWindowText
);
800 /* draw the date text using the colour set above */
801 DrawTextW (hdc
, txt
, strlenW(txt
), field
, DT_CENTER
| DT_VCENTER
| DT_SINGLELINE
);
802 SetTextColor (hdc
, oldTextColor
);
804 SetBkMode (hdc
, oldBkMode
);
805 SelectObject (hdc
, oldFont
);
808 if (!(infoPtr
->dwStyle
& DTS_UPDOWN
)) {
809 DrawFrameControl(hdc
, &infoPtr
->calbutton
, DFC_SCROLL
,
810 DFCS_SCROLLDOWN
| (infoPtr
->bCalDepressed
? DFCS_PUSHED
: 0) |
811 (infoPtr
->dwStyle
& WS_DISABLED
? DFCS_INACTIVE
: 0) );
817 DATETIME_HitTest (const DATETIME_INFO
*infoPtr
, POINT pt
)
821 TRACE ("%d, %d\n", pt
.x
, pt
.y
);
823 if (PtInRect (&infoPtr
->calbutton
, pt
)) return DTHT_MCPOPUP
;
824 if (PtInRect (&infoPtr
->checkbox
, pt
)) return DTHT_CHECKBOX
;
826 for (i
= 0; i
< infoPtr
->nrFields
; i
++) {
827 if (PtInRect (&infoPtr
->fieldRect
[i
], pt
)) return i
;
833 /* Returns index of a closest date field from given counting to left
834 or -1 if there's no such fields at left */
835 static int DATETIME_GetPrevDateField(const DATETIME_INFO
*infoPtr
, int i
)
837 for(--i
; i
>= 0; i
--)
839 if (infoPtr
->fieldspec
[i
] & DTHT_DATEFIELD
) return i
;
845 DATETIME_ApplySelectedField (DATETIME_INFO
*infoPtr
)
847 int fieldNum
= infoPtr
->select
& DTHT_DATEFIELD
;
848 int i
, val
=0, clamp_day
=0;
849 SYSTEMTIME date
= infoPtr
->date
;
851 if (infoPtr
->select
== -1 || infoPtr
->nCharsEntered
== 0)
854 for (i
=0; i
<infoPtr
->nCharsEntered
; i
++)
855 val
= val
* 10 + infoPtr
->charsEntered
[i
] - '0';
857 infoPtr
->nCharsEntered
= 0;
859 switch (infoPtr
->fieldspec
[fieldNum
]) {
862 date
.wYear
= date
.wYear
- (date
.wYear
%100) + val
;
865 case INVALIDFULLYEAR
:
883 /* FIXME: Preserve AM/PM for 12HOUR? */
896 if (clamp_day
&& date
.wDay
> MONTHCAL_MonthLength(date
.wMonth
, date
.wYear
))
897 date
.wDay
= MONTHCAL_MonthLength(date
.wMonth
, date
.wYear
);
899 if (DATETIME_SetSystemTime(infoPtr
, GDT_VALID
, &date
))
900 DATETIME_SendDateTimeChangeNotify (infoPtr
);
904 DATETIME_SetSelectedField (DATETIME_INFO
*infoPtr
, int select
)
906 DATETIME_ApplySelectedField(infoPtr
);
908 infoPtr
->select
= select
;
909 infoPtr
->nCharsEntered
= 0;
913 DATETIME_LButtonDown (DATETIME_INFO
*infoPtr
, INT x
, INT y
)
920 new = DATETIME_HitTest (infoPtr
, pt
);
922 SetFocus(infoPtr
->hwndSelf
);
924 if (!(new & DTHT_NODATEMASK
) || (new == DTHT_NONE
))
926 if (new == DTHT_NONE
)
927 new = infoPtr
->nrFields
- 1;
930 /* hitting string part moves selection to next date field to left */
931 if (infoPtr
->fieldspec
[new] & DT_STRING
)
933 new = DATETIME_GetPrevDateField(infoPtr
, new);
934 if (new == -1) return 0;
936 /* never select full day of week */
937 if (infoPtr
->fieldspec
[new] == FULLDAY
) return 0;
941 DATETIME_SetSelectedField(infoPtr
, new);
943 if (infoPtr
->select
== DTHT_MCPOPUP
) {
946 SendMessageW(infoPtr
->hMonthCal
, MCM_GETMINREQRECT
, 0, (LPARAM
)&rcMonthCal
);
948 /* FIXME: button actually is only depressed during dropdown of the */
949 /* calendar control and when the mouse is over the button window */
950 infoPtr
->bCalDepressed
= TRUE
;
952 /* recalculate the position of the monthcal popup */
953 if(infoPtr
->dwStyle
& DTS_RIGHTALIGN
)
954 pos
.x
= infoPtr
->calbutton
.left
- (rcMonthCal
.right
- rcMonthCal
.left
);
956 /* FIXME: this should be after the area reserved for the checkbox */
957 pos
.x
= infoPtr
->rcDraw
.left
;
959 pos
.y
= infoPtr
->rcClient
.bottom
;
960 OffsetRect( &rcMonthCal
, pos
.x
, pos
.y
);
961 MapWindowPoints( infoPtr
->hwndSelf
, 0, (POINT
*)&rcMonthCal
, 2 );
962 SetWindowPos(infoPtr
->hMonthCal
, 0, rcMonthCal
.left
, rcMonthCal
.top
,
963 rcMonthCal
.right
- rcMonthCal
.left
, rcMonthCal
.bottom
- rcMonthCal
.top
, 0);
965 if(IsWindowVisible(infoPtr
->hMonthCal
)) {
966 ShowWindow(infoPtr
->hMonthCal
, SW_HIDE
);
967 infoPtr
->bDropdownEnabled
= FALSE
;
968 DATETIME_SendSimpleNotify (infoPtr
, DTN_CLOSEUP
);
970 const SYSTEMTIME
*lprgSysTimeArray
= &infoPtr
->date
;
971 TRACE("update calendar %04d/%02d/%02d\n",
972 lprgSysTimeArray
->wYear
, lprgSysTimeArray
->wMonth
, lprgSysTimeArray
->wDay
);
973 SendMessageW(infoPtr
->hMonthCal
, MCM_SETCURSEL
, 0, (LPARAM
)(&infoPtr
->date
));
975 if (infoPtr
->bDropdownEnabled
) {
976 ShowWindow(infoPtr
->hMonthCal
, SW_SHOW
);
977 DATETIME_SendSimpleNotify (infoPtr
, DTN_DROPDOWN
);
979 infoPtr
->bDropdownEnabled
= TRUE
;
982 TRACE ("dt:%p mc:%p mc parent:%p, desktop:%p\n",
983 infoPtr
->hwndSelf
, infoPtr
->hMonthCal
, infoPtr
->hwndNotify
, GetDesktopWindow ());
986 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
993 DATETIME_LButtonUp (DATETIME_INFO
*infoPtr
)
995 if(infoPtr
->bCalDepressed
) {
996 infoPtr
->bCalDepressed
= FALSE
;
997 InvalidateRect(infoPtr
->hwndSelf
, &(infoPtr
->calbutton
), TRUE
);
1005 DATETIME_Paint (DATETIME_INFO
*infoPtr
, HDC hdc
)
1009 hdc
= BeginPaint (infoPtr
->hwndSelf
, &ps
);
1010 DATETIME_Refresh (infoPtr
, hdc
);
1011 EndPaint (infoPtr
->hwndSelf
, &ps
);
1013 DATETIME_Refresh (infoPtr
, hdc
);
1016 /* Not a click on the dropdown box, enabled it */
1017 infoPtr
->bDropdownEnabled
= TRUE
;
1024 DATETIME_Button_Command (DATETIME_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
1026 if( HIWORD(wParam
) == BN_CLICKED
) {
1027 DWORD state
= SendMessageW((HWND
)lParam
, BM_GETCHECK
, 0, 0);
1028 infoPtr
->dateValid
= (state
== BST_CHECKED
);
1029 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1037 DATETIME_Command (DATETIME_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
1039 TRACE("hwndbutton = %p\n", infoPtr
->hwndCheckbut
);
1040 if(infoPtr
->hwndCheckbut
== (HWND
)lParam
)
1041 return DATETIME_Button_Command(infoPtr
, wParam
, lParam
);
1047 DATETIME_Enable (DATETIME_INFO
*infoPtr
, BOOL bEnable
)
1049 TRACE("%p %s\n", infoPtr
, bEnable
? "TRUE" : "FALSE");
1051 infoPtr
->dwStyle
&= ~WS_DISABLED
;
1053 infoPtr
->dwStyle
|= WS_DISABLED
;
1055 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1062 DATETIME_EraseBackground (const DATETIME_INFO
*infoPtr
, HDC hdc
)
1064 HBRUSH hBrush
, hSolidBrush
= NULL
;
1067 if (infoPtr
->dwStyle
& WS_DISABLED
)
1068 hBrush
= hSolidBrush
= CreateSolidBrush(comctl32_color
.clrBtnFace
);
1071 hBrush
= (HBRUSH
)SendMessageW(infoPtr
->hwndNotify
, WM_CTLCOLOREDIT
,
1072 (WPARAM
)hdc
, (LPARAM
)infoPtr
->hwndSelf
);
1074 hBrush
= hSolidBrush
= CreateSolidBrush(comctl32_color
.clrWindow
);
1077 GetClientRect (infoPtr
->hwndSelf
, &rc
);
1079 FillRect (hdc
, &rc
, hBrush
);
1082 DeleteObject(hSolidBrush
);
1089 DATETIME_Notify (DATETIME_INFO
*infoPtr
, const NMHDR
*lpnmh
)
1091 TRACE ("Got notification %x from %p\n", lpnmh
->code
, lpnmh
->hwndFrom
);
1092 TRACE ("info: %p %p %p\n", infoPtr
->hwndSelf
, infoPtr
->hMonthCal
, infoPtr
->hUpdown
);
1094 if (lpnmh
->code
== MCN_SELECT
) {
1095 ShowWindow(infoPtr
->hMonthCal
, SW_HIDE
);
1096 infoPtr
->dateValid
= TRUE
;
1097 SendMessageW (infoPtr
->hMonthCal
, MCM_GETCURSEL
, 0, (LPARAM
)&infoPtr
->date
);
1098 TRACE("got from calendar %04d/%02d/%02d day of week %d\n",
1099 infoPtr
->date
.wYear
, infoPtr
->date
.wMonth
, infoPtr
->date
.wDay
, infoPtr
->date
.wDayOfWeek
);
1100 SendMessageW (infoPtr
->hwndCheckbut
, BM_SETCHECK
, BST_CHECKED
, 0);
1101 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1102 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1103 DATETIME_SendSimpleNotify(infoPtr
, DTN_CLOSEUP
);
1105 if ((lpnmh
->hwndFrom
== infoPtr
->hUpdown
) && (lpnmh
->code
== UDN_DELTAPOS
)) {
1106 const NM_UPDOWN
*lpnmud
= (const NM_UPDOWN
*)lpnmh
;
1107 TRACE("Delta pos %d\n", lpnmud
->iDelta
);
1108 infoPtr
->pendingUpdown
= lpnmud
->iDelta
;
1115 DATETIME_KeyDown (DATETIME_INFO
*infoPtr
, DWORD vkCode
)
1117 int fieldNum
= infoPtr
->select
& DTHT_DATEFIELD
;
1121 if (!(infoPtr
->haveFocus
)) return 0;
1122 if ((fieldNum
==0) && (infoPtr
->select
)) return 0;
1124 if (infoPtr
->select
& FORMATCALLMASK
) {
1125 FIXME ("Callbacks not implemented yet\n");
1131 infoPtr
->nCharsEntered
= 0;
1132 DATETIME_IncreaseField (infoPtr
, fieldNum
, 1);
1133 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1137 infoPtr
->nCharsEntered
= 0;
1138 DATETIME_IncreaseField (infoPtr
, fieldNum
, -1);
1139 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1142 infoPtr
->nCharsEntered
= 0;
1143 DATETIME_IncreaseField (infoPtr
, fieldNum
, INT_MIN
);
1144 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1147 infoPtr
->nCharsEntered
= 0;
1148 DATETIME_IncreaseField (infoPtr
, fieldNum
, INT_MAX
);
1149 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1152 new = infoPtr
->select
;
1160 } while ((infoPtr
->fieldspec
[new] & DT_STRING
) && (wrap
<2));
1161 if (new != infoPtr
->select
)
1162 DATETIME_SetSelectedField(infoPtr
, new);
1165 new = infoPtr
->select
;
1168 if (new==infoPtr
->nrFields
) {
1172 } while ((infoPtr
->fieldspec
[new] & DT_STRING
) && (wrap
<2));
1173 if (new != infoPtr
->select
)
1174 DATETIME_SetSelectedField(infoPtr
, new);
1178 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1185 DATETIME_Char (DATETIME_INFO
*infoPtr
, WPARAM vkCode
)
1187 int fieldNum
= infoPtr
->select
& DTHT_DATEFIELD
;
1189 if (vkCode
>= '0' && vkCode
<= '9') {
1193 infoPtr
->charsEntered
[infoPtr
->nCharsEntered
++] = vkCode
;
1195 fieldSpec
= infoPtr
->fieldspec
[fieldNum
];
1197 if (fieldSpec
== INVALIDFULLYEAR
|| fieldSpec
== FULLYEAR
)
1202 if (maxChars
== infoPtr
->nCharsEntered
)
1203 DATETIME_ApplySelectedField(infoPtr
);
1210 DATETIME_VScroll (DATETIME_INFO
*infoPtr
, WORD wScroll
)
1212 int fieldNum
= infoPtr
->select
& DTHT_DATEFIELD
;
1214 if ((SHORT
)LOWORD(wScroll
) != SB_THUMBPOSITION
) return 0;
1215 if (!(infoPtr
->haveFocus
)) return 0;
1216 if ((fieldNum
==0) && (infoPtr
->select
)) return 0;
1218 if (infoPtr
->pendingUpdown
>= 0) {
1219 DATETIME_IncreaseField (infoPtr
, fieldNum
, 1);
1220 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1223 DATETIME_IncreaseField (infoPtr
, fieldNum
, -1);
1224 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1227 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1234 DATETIME_KillFocus (DATETIME_INFO
*infoPtr
, HWND lostFocus
)
1236 TRACE("lost focus to %p\n", lostFocus
);
1238 if (infoPtr
->haveFocus
) {
1239 DATETIME_SendSimpleNotify (infoPtr
, NM_KILLFOCUS
);
1240 infoPtr
->haveFocus
= 0;
1241 DATETIME_SetSelectedField (infoPtr
, -1);
1244 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
1251 DATETIME_NCCreate (HWND hwnd
, const CREATESTRUCTW
*lpcs
)
1253 DWORD dwExStyle
= GetWindowLongW(hwnd
, GWL_EXSTYLE
);
1254 /* force control to have client edge */
1255 dwExStyle
|= WS_EX_CLIENTEDGE
;
1256 SetWindowLongW(hwnd
, GWL_EXSTYLE
, dwExStyle
);
1258 return DefWindowProcW(hwnd
, WM_NCCREATE
, 0, (LPARAM
)lpcs
);
1263 DATETIME_SetFocus (DATETIME_INFO
*infoPtr
, HWND lostFocus
)
1265 TRACE("got focus from %p\n", lostFocus
);
1267 /* if monthcal is open and it loses focus, close monthcal */
1268 if (infoPtr
->hMonthCal
&& (lostFocus
== infoPtr
->hMonthCal
) &&
1269 IsWindowVisible(infoPtr
->hMonthCal
))
1271 ShowWindow(infoPtr
->hMonthCal
, SW_HIDE
);
1272 DATETIME_SendSimpleNotify(infoPtr
, DTN_CLOSEUP
);
1273 /* note: this get triggered even if monthcal loses focus to a dropdown
1274 * box click, which occurs without an intermediate WM_PAINT call
1276 infoPtr
->bDropdownEnabled
= FALSE
;
1280 if (infoPtr
->haveFocus
== 0) {
1281 DATETIME_SendSimpleNotify (infoPtr
, NM_SETFOCUS
);
1282 infoPtr
->haveFocus
= DTHT_GOTFOCUS
;
1285 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1292 DATETIME_SendDateTimeChangeNotify (const DATETIME_INFO
*infoPtr
)
1294 NMDATETIMECHANGE dtdtc
;
1296 dtdtc
.nmhdr
.hwndFrom
= infoPtr
->hwndSelf
;
1297 dtdtc
.nmhdr
.idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1298 dtdtc
.nmhdr
.code
= DTN_DATETIMECHANGE
;
1300 dtdtc
.dwFlags
= infoPtr
->dateValid
? GDT_VALID
: GDT_NONE
;
1302 dtdtc
.st
= infoPtr
->date
;
1303 return (BOOL
) SendMessageW (infoPtr
->hwndNotify
, WM_NOTIFY
,
1304 dtdtc
.nmhdr
.idFrom
, (LPARAM
)&dtdtc
);
1309 DATETIME_SendSimpleNotify (const DATETIME_INFO
*infoPtr
, UINT code
)
1313 TRACE("%x\n", code
);
1314 nmhdr
.hwndFrom
= infoPtr
->hwndSelf
;
1315 nmhdr
.idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1318 return (BOOL
) SendMessageW (infoPtr
->hwndNotify
, WM_NOTIFY
,
1319 nmhdr
.idFrom
, (LPARAM
)&nmhdr
);
1323 DATETIME_Size (DATETIME_INFO
*infoPtr
, INT width
, INT height
)
1326 infoPtr
->rcClient
.bottom
= height
;
1327 infoPtr
->rcClient
.right
= width
;
1329 TRACE("Height=%d, Width=%d\n", infoPtr
->rcClient
.bottom
, infoPtr
->rcClient
.right
);
1331 infoPtr
->rcDraw
= infoPtr
->rcClient
;
1333 if (infoPtr
->dwStyle
& DTS_UPDOWN
) {
1334 SetWindowPos(infoPtr
->hUpdown
, NULL
,
1335 infoPtr
->rcClient
.right
-14, 0,
1336 15, infoPtr
->rcClient
.bottom
- infoPtr
->rcClient
.top
,
1337 SWP_NOACTIVATE
| SWP_NOZORDER
);
1340 /* set the size of the button that drops the calendar down */
1341 /* FIXME: account for style that allows button on left side */
1342 infoPtr
->calbutton
.top
= infoPtr
->rcDraw
.top
;
1343 infoPtr
->calbutton
.bottom
= infoPtr
->rcDraw
.bottom
;
1344 infoPtr
->calbutton
.left
= infoPtr
->rcDraw
.right
-15;
1345 infoPtr
->calbutton
.right
= infoPtr
->rcDraw
.right
;
1348 /* set enable/disable button size for show none style being enabled */
1349 /* FIXME: these dimensions are completely incorrect */
1350 infoPtr
->checkbox
.top
= infoPtr
->rcDraw
.top
;
1351 infoPtr
->checkbox
.bottom
= infoPtr
->rcDraw
.bottom
;
1352 infoPtr
->checkbox
.left
= infoPtr
->rcDraw
.left
;
1353 infoPtr
->checkbox
.right
= infoPtr
->rcDraw
.left
+ 10;
1355 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1361 DATETIME_StyleChanging(DATETIME_INFO
*infoPtr
, WPARAM wStyleType
, STYLESTRUCT
*lpss
)
1363 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
1364 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
1366 /* block DTS_SHOWNONE change */
1367 if ((lpss
->styleNew
^ lpss
->styleOld
) & DTS_SHOWNONE
)
1369 if (lpss
->styleOld
& DTS_SHOWNONE
)
1370 lpss
->styleNew
|= DTS_SHOWNONE
;
1372 lpss
->styleNew
&= ~DTS_SHOWNONE
;
1379 DATETIME_StyleChanged(DATETIME_INFO
*infoPtr
, WPARAM wStyleType
, const STYLESTRUCT
*lpss
)
1381 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
1382 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
1384 if (wStyleType
!= GWL_STYLE
) return 0;
1386 infoPtr
->dwStyle
= lpss
->styleNew
;
1388 if ( !(lpss
->styleOld
& DTS_SHOWNONE
) && (lpss
->styleNew
& DTS_SHOWNONE
) ) {
1389 infoPtr
->hwndCheckbut
= CreateWindowExW (0, WC_BUTTONW
, 0, WS_CHILD
| WS_VISIBLE
| BS_AUTOCHECKBOX
,
1390 2, 2, 13, 13, infoPtr
->hwndSelf
, 0,
1391 (HINSTANCE
)GetWindowLongPtrW (infoPtr
->hwndSelf
, GWLP_HINSTANCE
), 0);
1392 SendMessageW (infoPtr
->hwndCheckbut
, BM_SETCHECK
, 1, 0);
1394 if ( (lpss
->styleOld
& DTS_SHOWNONE
) && !(lpss
->styleNew
& DTS_SHOWNONE
) ) {
1395 DestroyWindow(infoPtr
->hwndCheckbut
);
1396 infoPtr
->hwndCheckbut
= 0;
1398 if ( !(lpss
->styleOld
& DTS_UPDOWN
) && (lpss
->styleNew
& DTS_UPDOWN
) ) {
1399 infoPtr
->hUpdown
= CreateUpDownControl (WS_CHILD
| WS_BORDER
| WS_VISIBLE
, 120, 1, 20, 20,
1400 infoPtr
->hwndSelf
, 1, 0, 0, UD_MAXVAL
, UD_MINVAL
, 0);
1402 if ( (lpss
->styleOld
& DTS_UPDOWN
) && !(lpss
->styleNew
& DTS_UPDOWN
) ) {
1403 DestroyWindow(infoPtr
->hUpdown
);
1404 infoPtr
->hUpdown
= 0;
1407 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1413 DATETIME_SetFont (DATETIME_INFO
*infoPtr
, HFONT font
, BOOL repaint
)
1415 infoPtr
->hFont
= font
;
1416 if (repaint
) InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1422 DATETIME_Create (HWND hwnd
, const CREATESTRUCTW
*lpcs
)
1424 DATETIME_INFO
*infoPtr
= Alloc (sizeof(DATETIME_INFO
));
1425 STYLESTRUCT ss
= { 0, lpcs
->style
};
1427 if (!infoPtr
) return -1;
1429 infoPtr
->hwndSelf
= hwnd
;
1430 infoPtr
->dwStyle
= lpcs
->style
;
1432 infoPtr
->nrFieldsAllocated
= 32;
1433 infoPtr
->fieldspec
= Alloc (infoPtr
->nrFieldsAllocated
* sizeof(int));
1434 infoPtr
->fieldRect
= Alloc (infoPtr
->nrFieldsAllocated
* sizeof(RECT
));
1435 infoPtr
->buflen
= Alloc (infoPtr
->nrFieldsAllocated
* sizeof(int));
1436 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
1437 infoPtr
->select
= -1; /* initially, nothing is selected */
1438 infoPtr
->bDropdownEnabled
= TRUE
;
1440 DATETIME_StyleChanged(infoPtr
, GWL_STYLE
, &ss
);
1441 DATETIME_SetFormatW (infoPtr
, 0);
1443 /* create the monthcal control */
1444 infoPtr
->hMonthCal
= CreateWindowExW (0, MONTHCAL_CLASSW
, 0, WS_BORDER
| WS_POPUP
| WS_CLIPSIBLINGS
,
1445 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, 0, 0);
1447 /* initialize info structure */
1448 GetLocalTime (&infoPtr
->date
);
1449 infoPtr
->dateValid
= TRUE
;
1450 infoPtr
->hFont
= GetStockObject(DEFAULT_GUI_FONT
);
1452 SetWindowLongPtrW (hwnd
, 0, (DWORD_PTR
)infoPtr
);
1460 DATETIME_Destroy (DATETIME_INFO
*infoPtr
)
1462 if (infoPtr
->hwndCheckbut
)
1463 DestroyWindow(infoPtr
->hwndCheckbut
);
1464 if (infoPtr
->hUpdown
)
1465 DestroyWindow(infoPtr
->hUpdown
);
1466 if (infoPtr
->hMonthCal
)
1467 DestroyWindow(infoPtr
->hMonthCal
);
1468 SetWindowLongPtrW( infoPtr
->hwndSelf
, 0, 0 ); /* clear infoPtr */
1469 Free (infoPtr
->buflen
);
1470 Free (infoPtr
->fieldRect
);
1471 Free (infoPtr
->fieldspec
);
1478 DATETIME_GetText (const DATETIME_INFO
*infoPtr
, INT count
, LPWSTR dst
)
1483 if (!dst
|| (count
<= 0)) return 0;
1486 for (i
= 0; i
< infoPtr
->nrFields
; i
++)
1488 DATETIME_ReturnTxt(infoPtr
, i
, buf
, sizeof(buf
)/sizeof(buf
[0]));
1489 if ((strlenW(dst
) + strlenW(buf
)) < count
)
1493 return strlenW(dst
);
1497 static LRESULT WINAPI
1498 DATETIME_WindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1500 DATETIME_INFO
*infoPtr
= ((DATETIME_INFO
*)GetWindowLongPtrW (hwnd
, 0));
1503 TRACE ("%x, %lx, %lx\n", uMsg
, wParam
, lParam
);
1505 if (!infoPtr
&& (uMsg
!= WM_CREATE
) && (uMsg
!= WM_NCCREATE
))
1506 return DefWindowProcW( hwnd
, uMsg
, wParam
, lParam
);
1510 case DTM_GETSYSTEMTIME
:
1511 return DATETIME_GetSystemTime (infoPtr
, (SYSTEMTIME
*) lParam
);
1513 case DTM_SETSYSTEMTIME
:
1514 return DATETIME_SetSystemTime (infoPtr
, wParam
, (SYSTEMTIME
*) lParam
);
1517 ret
= SendMessageW (infoPtr
->hMonthCal
, MCM_GETRANGE
, wParam
, lParam
);
1518 return ret
? ret
: 1; /* bug emulation */
1521 return SendMessageW (infoPtr
->hMonthCal
, MCM_SETRANGE
, wParam
, lParam
);
1523 case DTM_SETFORMATA
:
1524 return DATETIME_SetFormatA (infoPtr
, (LPCSTR
)lParam
);
1526 case DTM_SETFORMATW
:
1527 return DATETIME_SetFormatW (infoPtr
, (LPCWSTR
)lParam
);
1529 case DTM_GETMONTHCAL
:
1530 return (LRESULT
)infoPtr
->hMonthCal
;
1532 case DTM_SETMCCOLOR
:
1533 return SendMessageW (infoPtr
->hMonthCal
, MCM_SETCOLOR
, wParam
, lParam
);
1535 case DTM_GETMCCOLOR
:
1536 return SendMessageW (infoPtr
->hMonthCal
, MCM_GETCOLOR
, wParam
, 0);
1539 return SendMessageW (infoPtr
->hMonthCal
, WM_SETFONT
, wParam
, lParam
);
1542 return SendMessageW (infoPtr
->hMonthCal
, WM_GETFONT
, wParam
, lParam
);
1545 return DATETIME_Notify (infoPtr
, (LPNMHDR
)lParam
);
1548 return DATETIME_Enable (infoPtr
, (BOOL
)wParam
);
1551 return DATETIME_EraseBackground (infoPtr
, (HDC
)wParam
);
1554 return DLGC_WANTARROWS
| DLGC_WANTCHARS
;
1556 case WM_PRINTCLIENT
:
1558 return DATETIME_Paint (infoPtr
, (HDC
)wParam
);
1561 return DATETIME_KeyDown (infoPtr
, wParam
);
1564 return DATETIME_Char (infoPtr
, wParam
);
1567 return DATETIME_KillFocus (infoPtr
, (HWND
)wParam
);
1570 return DATETIME_NCCreate (hwnd
, (LPCREATESTRUCTW
)lParam
);
1573 return DATETIME_SetFocus (infoPtr
, (HWND
)wParam
);
1576 return DATETIME_Size (infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
1578 case WM_LBUTTONDOWN
:
1579 return DATETIME_LButtonDown (infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
1582 return DATETIME_LButtonUp (infoPtr
);
1585 return DATETIME_VScroll (infoPtr
, (WORD
)wParam
);
1588 return DATETIME_Create (hwnd
, (LPCREATESTRUCTW
)lParam
);
1591 return DATETIME_Destroy (infoPtr
);
1594 return DATETIME_Command (infoPtr
, wParam
, lParam
);
1596 case WM_STYLECHANGING
:
1597 return DATETIME_StyleChanging(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
1599 case WM_STYLECHANGED
:
1600 return DATETIME_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
1603 return DATETIME_SetFont(infoPtr
, (HFONT
)wParam
, (BOOL
)lParam
);
1606 return (LRESULT
) infoPtr
->hFont
;
1609 return (LRESULT
) DATETIME_GetText(infoPtr
, wParam
, (LPWSTR
)lParam
);
1615 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
1616 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
1617 uMsg
, wParam
, lParam
);
1618 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
1624 DATETIME_Register (void)
1628 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
1629 wndClass
.style
= CS_GLOBALCLASS
;
1630 wndClass
.lpfnWndProc
= DATETIME_WindowProc
;
1631 wndClass
.cbClsExtra
= 0;
1632 wndClass
.cbWndExtra
= sizeof(DATETIME_INFO
*);
1633 wndClass
.hCursor
= LoadCursorW (0, (LPCWSTR
)IDC_ARROW
);
1634 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
1635 wndClass
.lpszClassName
= DATETIMEPICK_CLASSW
;
1637 RegisterClassW (&wndClass
);
1642 DATETIME_Unregister (void)
1644 UnregisterClassW (DATETIMEPICK_CLASSW
, NULL
);