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 */
77 int nrFieldsAllocated
;
86 } DATETIME_INFO
, *LPDATETIME_INFO
;
89 extern int MONTHCAL_MonthLength(int month
, int year
);
90 extern int MONTHCAL_CalculateDayOfWeek(SYSTEMTIME
*date
, BOOL inplace
);
92 /* this list of defines is closely related to `allowedformatchars' defined
93 * in datetime.c; the high nibble indicates the `base type' of the format
95 * Do not change without first reading DATETIME_UseFormat.
99 #define DT_END_FORMAT 0
100 #define ONEDIGITDAY 0x01
101 #define TWODIGITDAY 0x02
102 #define THREECHARDAY 0x03
104 #define ONEDIGIT12HOUR 0x11
105 #define TWODIGIT12HOUR 0x12
106 #define ONEDIGIT24HOUR 0x21
107 #define TWODIGIT24HOUR 0x22
108 #define ONEDIGITMINUTE 0x31
109 #define TWODIGITMINUTE 0x32
110 #define ONEDIGITMONTH 0x41
111 #define TWODIGITMONTH 0x42
112 #define THREECHARMONTH 0x43
113 #define FULLMONTH 0x44
114 #define ONEDIGITSECOND 0x51
115 #define TWODIGITSECOND 0x52
116 #define ONELETTERAMPM 0x61
117 #define TWOLETTERAMPM 0x62
118 #define ONEDIGITYEAR 0x71
119 #define TWODIGITYEAR 0x72
120 #define INVALIDFULLYEAR 0x73 /* FIXME - yyy is not valid - we'll treat it as yyyy */
121 #define FULLYEAR 0x74
122 #define FORMATCALLBACK 0x81 /* -> maximum of 0x80 callbacks possible */
123 #define FORMATCALLMASK 0x80
124 #define DT_STRING 0x0100
126 #define DTHT_DATEFIELD 0xff /* for hit-testing */
128 #define DTHT_NONE 0x1000
129 #define DTHT_CHECKBOX 0x2000 /* these should end at '00' , to make */
130 #define DTHT_MCPOPUP 0x3000 /* & DTHT_DATEFIELD 0 when DATETIME_KeyDown */
131 #define DTHT_GOTFOCUS 0x4000 /* tests for date-fields */
132 #define DTHT_NODATEMASK 0xf000 /* to mask check and drop down from others */
134 static BOOL
DATETIME_SendSimpleNotify (const DATETIME_INFO
*infoPtr
, UINT code
);
135 static BOOL
DATETIME_SendDateTimeChangeNotify (const DATETIME_INFO
*infoPtr
);
136 extern void MONTHCAL_CopyTime(const SYSTEMTIME
*from
, SYSTEMTIME
*to
);
137 static const WCHAR allowedformatchars
[] = {'d', 'h', 'H', 'm', 'M', 's', 't', 'y', 'X', 0};
138 static const int maxrepetition
[] = {4,2,2,2,4,2,2,4,-1};
142 DATETIME_GetSystemTime (const DATETIME_INFO
*infoPtr
, SYSTEMTIME
*systime
)
144 if (!systime
) return GDT_NONE
;
146 if ((infoPtr
->dwStyle
& DTS_SHOWNONE
) &&
147 (SendMessageW (infoPtr
->hwndCheckbut
, BM_GETCHECK
, 0, 0) == BST_UNCHECKED
))
150 *systime
= infoPtr
->date
;
157 DATETIME_SetSystemTime (DATETIME_INFO
*infoPtr
, DWORD flag
, const SYSTEMTIME
*systime
)
159 if (!systime
) return 0;
161 TRACE("%04d/%02d/%02d %02d:%02d:%02d\n",
162 systime
->wYear
, systime
->wMonth
, systime
->wDay
,
163 systime
->wHour
, systime
->wMinute
, systime
->wSecond
);
165 if (flag
== GDT_VALID
) {
166 if (systime
->wYear
< 1601 || systime
->wYear
> 30827 ||
167 systime
->wMonth
< 1 || systime
->wMonth
> 12 ||
168 systime
->wDay
< 1 || systime
->wDay
> 31 ||
169 systime
->wHour
> 23 ||
170 systime
->wMinute
> 59 ||
171 systime
->wSecond
> 59 ||
172 systime
->wMilliseconds
> 999
176 infoPtr
->dateValid
= TRUE
;
177 infoPtr
->date
= *systime
;
178 /* always store a valid day of week */
179 MONTHCAL_CalculateDayOfWeek(&infoPtr
->date
, TRUE
);
181 SendMessageW (infoPtr
->hMonthCal
, MCM_SETCURSEL
, 0, (LPARAM
)(&infoPtr
->date
));
182 SendMessageW (infoPtr
->hwndCheckbut
, BM_SETCHECK
, BST_CHECKED
, 0);
183 } else if ((infoPtr
->dwStyle
& DTS_SHOWNONE
) && (flag
== GDT_NONE
)) {
184 infoPtr
->dateValid
= FALSE
;
185 SendMessageW (infoPtr
->hwndCheckbut
, BM_SETCHECK
, BST_UNCHECKED
, 0);
190 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
196 * Split up a formattxt in actions.
197 * See ms documentation for the meaning of the letter codes/'specifiers'.
200 * *'dddddd' is handled as 'dddd' plus 'dd'.
201 * *unrecognized formats are strings (here given the type DT_STRING;
202 * start of the string is encoded in lower bits of DT_STRING.
203 * Therefore, 'string' ends finally up as '<show seconds>tring'.
207 DATETIME_UseFormat (DATETIME_INFO
*infoPtr
, LPCWSTR formattxt
)
211 BOOL inside_literal
= FALSE
; /* inside '...' */
212 int *nrFields
= &infoPtr
->nrFields
;
215 infoPtr
->fieldspec
[*nrFields
] = 0;
216 len
= strlenW(allowedformatchars
);
219 for (i
= 0; formattxt
[i
]; i
++) {
220 TRACE ("\n%d %c:", i
, formattxt
[i
]);
221 if (!inside_literal
) {
222 for (j
= 0; j
< len
; j
++) {
223 if (allowedformatchars
[j
]==formattxt
[i
]) {
224 TRACE ("%c[%d,%x]", allowedformatchars
[j
], *nrFields
, infoPtr
->fieldspec
[*nrFields
]);
225 if ((*nrFields
==0) && (infoPtr
->fieldspec
[*nrFields
]==0)) {
226 infoPtr
->fieldspec
[*nrFields
] = (j
<<4) + 1;
229 if (infoPtr
->fieldspec
[*nrFields
] >> 4 != j
) {
231 infoPtr
->fieldspec
[*nrFields
] = (j
<<4) + 1;
234 if ((infoPtr
->fieldspec
[*nrFields
] & 0x0f) == maxrepetition
[j
]) {
236 infoPtr
->fieldspec
[*nrFields
] = (j
<<4) + 1;
239 infoPtr
->fieldspec
[*nrFields
]++;
241 } /* if allowedformatchar */
247 if (formattxt
[i
] == '\'')
249 inside_literal
= !inside_literal
;
253 /* char is not a specifier: handle char like a string */
255 if ((*nrFields
==0) && (infoPtr
->fieldspec
[*nrFields
]==0)) {
256 infoPtr
->fieldspec
[*nrFields
] = DT_STRING
+ k
;
257 infoPtr
->buflen
[*nrFields
] = 0;
258 } else if ((infoPtr
->fieldspec
[*nrFields
] & DT_STRING
) != DT_STRING
) {
260 infoPtr
->fieldspec
[*nrFields
] = DT_STRING
+ k
;
261 infoPtr
->buflen
[*nrFields
] = 0;
263 infoPtr
->textbuf
[k
] = formattxt
[i
];
265 infoPtr
->buflen
[*nrFields
]++;
268 if (*nrFields
== infoPtr
->nrFieldsAllocated
) {
269 FIXME ("out of memory; should reallocate. crash ahead.\n");
275 if (infoPtr
->fieldspec
[*nrFields
] != 0) (*nrFields
)++;
280 DATETIME_SetFormatW (DATETIME_INFO
*infoPtr
, LPCWSTR lpszFormat
)
283 WCHAR format_buf
[80];
286 if (infoPtr
->dwStyle
& DTS_LONGDATEFORMAT
)
287 format_item
= LOCALE_SLONGDATE
;
288 else if ((infoPtr
->dwStyle
& DTS_TIMEFORMAT
) == DTS_TIMEFORMAT
)
289 format_item
= LOCALE_STIMEFORMAT
;
290 else /* DTS_SHORTDATEFORMAT */
291 format_item
= LOCALE_SSHORTDATE
;
292 GetLocaleInfoW( GetSystemDefaultLCID(), format_item
, format_buf
, sizeof(format_buf
)/sizeof(format_buf
[0]));
293 lpszFormat
= format_buf
;
296 DATETIME_UseFormat (infoPtr
, lpszFormat
);
297 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
304 DATETIME_SetFormatA (DATETIME_INFO
*infoPtr
, LPCSTR lpszFormat
)
308 INT len
= MultiByteToWideChar(CP_ACP
, 0, lpszFormat
, -1, NULL
, 0);
309 LPWSTR wstr
= Alloc(len
* sizeof(WCHAR
));
310 if (wstr
) MultiByteToWideChar(CP_ACP
, 0, lpszFormat
, -1, wstr
, len
);
311 retval
= DATETIME_SetFormatW (infoPtr
, wstr
);
316 return DATETIME_SetFormatW (infoPtr
, 0);
322 DATETIME_ReturnTxt (const DATETIME_INFO
*infoPtr
, int count
, LPWSTR result
, int resultSize
)
324 static const WCHAR fmt_dW
[] = { '%', 'd', 0 };
325 static const WCHAR fmt__2dW
[] = { '%', '.', '2', 'd', 0 };
326 static const WCHAR fmt__3sW
[] = { '%', '.', '3', 's', 0 };
327 SYSTEMTIME date
= infoPtr
->date
;
332 TRACE ("%d,%d\n", infoPtr
->nrFields
, count
);
333 if (count
>infoPtr
->nrFields
|| count
< 0) {
334 WARN ("buffer overrun, have %d want %d\n", infoPtr
->nrFields
, count
);
338 if (!infoPtr
->fieldspec
) return;
340 spec
= infoPtr
->fieldspec
[count
];
341 if (spec
& DT_STRING
) {
342 int txtlen
= infoPtr
->buflen
[count
];
344 if (txtlen
> resultSize
)
345 txtlen
= resultSize
- 1;
346 memcpy (result
, infoPtr
->textbuf
+ (spec
&~ DT_STRING
), txtlen
* sizeof(WCHAR
));
348 TRACE ("arg%d=%x->[%s]\n", count
, infoPtr
->fieldspec
[count
], debugstr_w(result
));
358 wsprintfW (result
, fmt_dW
, date
.wDay
);
361 wsprintfW (result
, fmt__2dW
, date
.wDay
);
364 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SABBREVDAYNAME1
+(date
.wDayOfWeek
+6)%7, result
, 4);
365 /*wsprintfW (result,"%.3s",days[date.wDayOfWeek]);*/
368 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SDAYNAME1
+(date
.wDayOfWeek
+6)%7, result
, resultSize
);
371 if (date
.wHour
== 0) {
377 wsprintfW (result
, fmt_dW
, date
.wHour
- (date
.wHour
> 12 ? 12 : 0));
380 if (date
.wHour
== 0) {
386 wsprintfW (result
, fmt__2dW
, date
.wHour
- (date
.wHour
> 12 ? 12 : 0));
389 wsprintfW (result
, fmt_dW
, date
.wHour
);
392 wsprintfW (result
, fmt__2dW
, date
.wHour
);
395 wsprintfW (result
, fmt_dW
, date
.wSecond
);
398 wsprintfW (result
, fmt__2dW
, date
.wSecond
);
401 wsprintfW (result
, fmt_dW
, date
.wMinute
);
404 wsprintfW (result
, fmt__2dW
, date
.wMinute
);
407 wsprintfW (result
, fmt_dW
, date
.wMonth
);
410 wsprintfW (result
, fmt__2dW
, date
.wMonth
);
413 GetLocaleInfoW(GetSystemDefaultLCID(), LOCALE_SMONTHNAME1
+date
.wMonth
-1,
414 buffer
, sizeof(buffer
)/sizeof(buffer
[0]));
415 wsprintfW (result
, fmt__3sW
, buffer
);
418 GetLocaleInfoW(GetSystemDefaultLCID(),LOCALE_SMONTHNAME1
+date
.wMonth
-1,
422 result
[0] = (date
.wHour
< 12 ? 'A' : 'P');
426 result
[0] = (date
.wHour
< 12 ? 'A' : 'P');
431 FIXME ("Not implemented\n");
436 wsprintfW (result
, fmt_dW
, date
.wYear
-10* (int) floor(date
.wYear
/10));
439 wsprintfW (result
, fmt__2dW
, date
.wYear
-100* (int) floor(date
.wYear
/100));
441 case INVALIDFULLYEAR
:
443 wsprintfW (result
, fmt_dW
, date
.wYear
);
447 TRACE ("arg%d=%x->[%s]\n", count
, infoPtr
->fieldspec
[count
], debugstr_w(result
));
450 static int wrap(int val
, int delta
, int minVal
, int maxVal
)
453 if (delta
== INT_MIN
|| val
< minVal
) return maxVal
;
454 if (delta
== INT_MAX
|| val
> maxVal
) return minVal
;
459 DATETIME_IncreaseField (DATETIME_INFO
*infoPtr
, int number
, int delta
)
461 SYSTEMTIME
*date
= &infoPtr
->date
;
463 TRACE ("%d\n", number
);
464 if ((number
> infoPtr
->nrFields
) || (number
< 0)) return;
466 if ((infoPtr
->fieldspec
[number
] & DTHT_DATEFIELD
) == 0) return;
468 switch (infoPtr
->fieldspec
[number
]) {
472 date
->wYear
= wrap(date
->wYear
, delta
, 1752, 9999);
473 MONTHCAL_CalculateDayOfWeek(date
, TRUE
);
479 date
->wMonth
= wrap(date
->wMonth
, delta
, 1, 12);
480 MONTHCAL_CalculateDayOfWeek(date
, TRUE
);
487 date
->wDay
= wrap(date
->wDay
, delta
, 1, MONTHCAL_MonthLength(date
->wMonth
, date
->wYear
));
488 MONTHCAL_CalculateDayOfWeek(date
, TRUE
);
498 date
->wHour
= wrap(date
->wHour
, delta
, 0, 23);
502 date
->wMinute
= wrap(date
->wMinute
, delta
, 0, 59);
506 date
->wSecond
= wrap(date
->wSecond
, delta
, 0, 59);
509 FIXME ("Not implemented\n");
513 /* FYI: On 1752/9/14 the calendar changed and England and the
514 * American colonies changed to the Gregorian calendar. This change
515 * involved having September 14th follow September 2nd. So no date
516 * algorithm works before that date.
518 if (10000 * date
->wYear
+ 100 * date
->wMonth
+ date
->wDay
< 17520914) {
530 DATETIME_ReturnFieldWidth (const DATETIME_INFO
*infoPtr
, HDC hdc
, int count
, SHORT
*width
)
532 /* fields are a fixed width, determined by the largest possible string */
533 /* presumably, these widths should be language dependent */
534 static const WCHAR fld_d1W
[] = { '2', 0 };
535 static const WCHAR fld_d2W
[] = { '2', '2', 0 };
536 static const WCHAR fld_d4W
[] = { '2', '2', '2', '2', 0 };
537 static const WCHAR fld_am1
[] = { 'A', 0 };
538 static const WCHAR fld_am2
[] = { 'A', 'M', 0 };
544 TRACE ("%d,%d\n", infoPtr
->nrFields
, count
);
545 if (count
>infoPtr
->nrFields
|| count
< 0) {
546 WARN ("buffer overrun, have %d want %d\n", infoPtr
->nrFields
, count
);
550 if (!infoPtr
->fieldspec
) return;
552 spec
= infoPtr
->fieldspec
[count
];
553 if (spec
& DT_STRING
) {
554 int txtlen
= infoPtr
->buflen
[count
];
558 memcpy (buffer
, infoPtr
->textbuf
+ (spec
&~ DT_STRING
), txtlen
* sizeof(WCHAR
));
571 /* these seem to use a two byte field */
581 case INVALIDFULLYEAR
:
590 static const WCHAR fld_day
[] = {'W','e','d','n','e','s','d','a','y',0};
591 static const WCHAR fld_abbrday
[] = {'W','e','d',0};
592 static const WCHAR fld_mon
[] = {'S','e','p','t','e','m','b','e','r',0};
593 static const WCHAR fld_abbrmon
[] = {'D','e','c',0};
600 /* choose locale data type and fallback string */
604 lctype
= LOCALE_SABBREVDAYNAME1
;
609 lctype
= LOCALE_SDAYNAME1
;
614 lctype
= LOCALE_SABBREVMONTHNAME1
;
619 lctype
= LOCALE_SMONTHNAME1
;
625 for (i
= 0; i
< max_count
; i
++)
627 if(GetLocaleInfoW(LOCALE_USER_DEFAULT
, lctype
+ i
,
628 buffer
, lstrlenW(buffer
)))
630 GetTextExtentPoint32W(hdc
, buffer
, lstrlenW(buffer
), &size
);
631 if (size
.cx
> cx
) cx
= size
.cx
;
633 else /* locale independent fallback on failure */
635 GetTextExtentPoint32W(hdc
, fall
, lstrlenW(fall
), &size
);
654 GetTextExtentPoint32W (hdc
, bufptr
, strlenW(bufptr
), &size
);
659 DATETIME_Refresh (DATETIME_INFO
*infoPtr
, HDC hdc
)
663 if (infoPtr
->dateValid
) {
666 RECT
*rcDraw
= &infoPtr
->rcDraw
;
668 COLORREF oldTextColor
;
669 SHORT fieldWidth
= 0;
670 HFONT oldFont
= SelectObject (hdc
, infoPtr
->hFont
);
671 INT oldBkMode
= SetBkMode (hdc
, TRANSPARENT
);
674 DATETIME_ReturnTxt (infoPtr
, 0, txt
, sizeof(txt
)/sizeof(txt
[0]));
675 GetTextExtentPoint32W (hdc
, txt
, strlenW(txt
), &size
);
676 rcDraw
->bottom
= size
.cy
+ 2;
678 prevright
= infoPtr
->checkbox
.right
= ((infoPtr
->dwStyle
& DTS_SHOWNONE
) ? 18 : 2);
680 for (i
= 0; i
< infoPtr
->nrFields
; i
++) {
681 DATETIME_ReturnTxt (infoPtr
, i
, txt
, sizeof(txt
)/sizeof(txt
[0]));
682 GetTextExtentPoint32W (hdc
, txt
, strlenW(txt
), &size
);
683 DATETIME_ReturnFieldWidth (infoPtr
, hdc
, i
, &fieldWidth
);
684 field
= &infoPtr
->fieldRect
[i
];
685 field
->left
= prevright
;
686 field
->right
= prevright
+ fieldWidth
;
687 field
->top
= rcDraw
->top
;
688 field
->bottom
= rcDraw
->bottom
;
689 prevright
= field
->right
;
691 if (infoPtr
->dwStyle
& WS_DISABLED
)
692 oldTextColor
= SetTextColor (hdc
, comctl32_color
.clrGrayText
);
693 else if ((infoPtr
->haveFocus
) && (i
== infoPtr
->select
)) {
696 /* fill if focused */
697 HBRUSH hbr
= CreateSolidBrush (comctl32_color
.clrActiveCaption
);
701 selection
.right
= size
.cx
;
702 selection
.bottom
= size
.cy
;
703 /* center rectangle */
704 OffsetRect(&selection
, (field
->right
+ field
->left
- size
.cx
)/2,
705 (field
->bottom
- size
.cy
)/2);
707 FillRect(hdc
, &selection
, hbr
);
709 oldTextColor
= SetTextColor (hdc
, comctl32_color
.clrWindow
);
712 oldTextColor
= SetTextColor (hdc
, comctl32_color
.clrWindowText
);
714 /* draw the date text using the colour set above */
715 DrawTextW (hdc
, txt
, strlenW(txt
), field
, DT_CENTER
| DT_VCENTER
| DT_SINGLELINE
);
716 SetTextColor (hdc
, oldTextColor
);
718 SetBkMode (hdc
, oldBkMode
);
719 SelectObject (hdc
, oldFont
);
722 if (!(infoPtr
->dwStyle
& DTS_UPDOWN
)) {
723 DrawFrameControl(hdc
, &infoPtr
->calbutton
, DFC_SCROLL
,
724 DFCS_SCROLLDOWN
| (infoPtr
->bCalDepressed
? DFCS_PUSHED
: 0) |
725 (infoPtr
->dwStyle
& WS_DISABLED
? DFCS_INACTIVE
: 0) );
731 DATETIME_HitTest (const DATETIME_INFO
*infoPtr
, POINT pt
)
735 TRACE ("%d, %d\n", pt
.x
, pt
.y
);
737 if (PtInRect (&infoPtr
->calbutton
, pt
)) return DTHT_MCPOPUP
;
738 if (PtInRect (&infoPtr
->checkbox
, pt
)) return DTHT_CHECKBOX
;
740 for (i
= 0; i
< infoPtr
->nrFields
; i
++) {
741 if (PtInRect (&infoPtr
->fieldRect
[i
], pt
)) return i
;
747 /* Returns index of a closest date field from given counting to left
748 or -1 if there's no such fields at left */
749 static int DATETIME_GetPrevDateField(const DATETIME_INFO
*infoPtr
, int i
)
751 for(--i
; i
>= 0; i
--)
753 if (infoPtr
->fieldspec
[i
] & DTHT_DATEFIELD
) return i
;
759 DATETIME_LButtonDown (DATETIME_INFO
*infoPtr
, INT x
, INT y
)
766 old
= infoPtr
->select
;
767 new = DATETIME_HitTest (infoPtr
, pt
);
769 SetFocus(infoPtr
->hwndSelf
);
771 if (!(new & DTHT_NODATEMASK
) || (new == DTHT_NONE
))
773 if (new == DTHT_NONE
)
774 new = infoPtr
->nrFields
- 1;
777 /* hitting string part moves selection to next date field to left */
778 if (infoPtr
->fieldspec
[new] & DT_STRING
)
780 new = DATETIME_GetPrevDateField(infoPtr
, new);
781 if (new == -1) return 0;
783 /* never select full day of week */
784 if (infoPtr
->fieldspec
[new] == FULLDAY
) return 0;
787 infoPtr
->select
= new;
789 if (infoPtr
->select
== DTHT_MCPOPUP
) {
791 SendMessageW(infoPtr
->hMonthCal
, MCM_GETMINREQRECT
, 0, (LPARAM
)&rcMonthCal
);
793 /* FIXME: button actually is only depressed during dropdown of the */
794 /* calendar control and when the mouse is over the button window */
795 infoPtr
->bCalDepressed
= TRUE
;
797 /* recalculate the position of the monthcal popup */
798 if(infoPtr
->dwStyle
& DTS_RIGHTALIGN
)
799 infoPtr
->monthcal_pos
.x
= infoPtr
->calbutton
.left
-
800 (rcMonthCal
.right
- rcMonthCal
.left
);
802 /* FIXME: this should be after the area reserved for the checkbox */
803 infoPtr
->monthcal_pos
.x
= infoPtr
->rcDraw
.left
;
805 infoPtr
->monthcal_pos
.y
= infoPtr
->rcClient
.bottom
;
806 ClientToScreen (infoPtr
->hwndSelf
, &(infoPtr
->monthcal_pos
));
807 SetWindowPos(infoPtr
->hMonthCal
, 0, infoPtr
->monthcal_pos
.x
,
808 infoPtr
->monthcal_pos
.y
, rcMonthCal
.right
- rcMonthCal
.left
,
809 rcMonthCal
.bottom
- rcMonthCal
.top
, 0);
811 if(IsWindowVisible(infoPtr
->hMonthCal
)) {
812 ShowWindow(infoPtr
->hMonthCal
, SW_HIDE
);
813 infoPtr
->bDropdownEnabled
= FALSE
;
814 DATETIME_SendSimpleNotify (infoPtr
, DTN_CLOSEUP
);
816 const SYSTEMTIME
*lprgSysTimeArray
= &infoPtr
->date
;
817 TRACE("update calendar %04d/%02d/%02d\n",
818 lprgSysTimeArray
->wYear
, lprgSysTimeArray
->wMonth
, lprgSysTimeArray
->wDay
);
819 SendMessageW(infoPtr
->hMonthCal
, MCM_SETCURSEL
, 0, (LPARAM
)(&infoPtr
->date
));
821 if (infoPtr
->bDropdownEnabled
) {
822 ShowWindow(infoPtr
->hMonthCal
, SW_SHOW
);
823 DATETIME_SendSimpleNotify (infoPtr
, DTN_DROPDOWN
);
825 infoPtr
->bDropdownEnabled
= TRUE
;
828 TRACE ("dt:%p mc:%p mc parent:%p, desktop:%p\n",
829 infoPtr
->hwndSelf
, infoPtr
->hMonthCal
, infoPtr
->hwndNotify
, GetDesktopWindow ());
832 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
839 DATETIME_LButtonUp (DATETIME_INFO
*infoPtr
)
841 if(infoPtr
->bCalDepressed
) {
842 infoPtr
->bCalDepressed
= FALSE
;
843 InvalidateRect(infoPtr
->hwndSelf
, &(infoPtr
->calbutton
), TRUE
);
851 DATETIME_Paint (DATETIME_INFO
*infoPtr
, HDC hdc
)
855 hdc
= BeginPaint (infoPtr
->hwndSelf
, &ps
);
856 DATETIME_Refresh (infoPtr
, hdc
);
857 EndPaint (infoPtr
->hwndSelf
, &ps
);
859 DATETIME_Refresh (infoPtr
, hdc
);
862 /* Not a click on the dropdown box, enabled it */
863 infoPtr
->bDropdownEnabled
= TRUE
;
870 DATETIME_Button_Command (DATETIME_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
872 if( HIWORD(wParam
) == BN_CLICKED
) {
873 DWORD state
= SendMessageW((HWND
)lParam
, BM_GETCHECK
, 0, 0);
874 infoPtr
->dateValid
= (state
== BST_CHECKED
);
875 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
883 DATETIME_Command (DATETIME_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
885 TRACE("hwndbutton = %p\n", infoPtr
->hwndCheckbut
);
886 if(infoPtr
->hwndCheckbut
== (HWND
)lParam
)
887 return DATETIME_Button_Command(infoPtr
, wParam
, lParam
);
893 DATETIME_Enable (DATETIME_INFO
*infoPtr
, BOOL bEnable
)
895 TRACE("%p %s\n", infoPtr
, bEnable
? "TRUE" : "FALSE");
897 infoPtr
->dwStyle
&= ~WS_DISABLED
;
899 infoPtr
->dwStyle
|= WS_DISABLED
;
901 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
908 DATETIME_EraseBackground (const DATETIME_INFO
*infoPtr
, HDC hdc
)
910 HBRUSH hBrush
, hSolidBrush
= NULL
;
913 if (infoPtr
->dwStyle
& WS_DISABLED
)
914 hBrush
= hSolidBrush
= CreateSolidBrush(comctl32_color
.clrBtnFace
);
917 hBrush
= (HBRUSH
)SendMessageW(infoPtr
->hwndNotify
, WM_CTLCOLOREDIT
,
918 (WPARAM
)hdc
, (LPARAM
)infoPtr
->hwndSelf
);
920 hBrush
= hSolidBrush
= CreateSolidBrush(comctl32_color
.clrWindow
);
923 GetClientRect (infoPtr
->hwndSelf
, &rc
);
925 FillRect (hdc
, &rc
, hBrush
);
928 DeleteObject(hSolidBrush
);
935 DATETIME_Notify (DATETIME_INFO
*infoPtr
, const NMHDR
*lpnmh
)
937 TRACE ("Got notification %x from %p\n", lpnmh
->code
, lpnmh
->hwndFrom
);
938 TRACE ("info: %p %p %p\n", infoPtr
->hwndSelf
, infoPtr
->hMonthCal
, infoPtr
->hUpdown
);
940 if (lpnmh
->code
== MCN_SELECT
) {
941 ShowWindow(infoPtr
->hMonthCal
, SW_HIDE
);
942 infoPtr
->dateValid
= TRUE
;
943 SendMessageW (infoPtr
->hMonthCal
, MCM_GETCURSEL
, 0, (LPARAM
)&infoPtr
->date
);
944 TRACE("got from calendar %04d/%02d/%02d day of week %d\n",
945 infoPtr
->date
.wYear
, infoPtr
->date
.wMonth
, infoPtr
->date
.wDay
, infoPtr
->date
.wDayOfWeek
);
946 SendMessageW (infoPtr
->hwndCheckbut
, BM_SETCHECK
, BST_CHECKED
, 0);
947 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
948 DATETIME_SendDateTimeChangeNotify (infoPtr
);
949 DATETIME_SendSimpleNotify(infoPtr
, DTN_CLOSEUP
);
951 if ((lpnmh
->hwndFrom
== infoPtr
->hUpdown
) && (lpnmh
->code
== UDN_DELTAPOS
)) {
952 LPNMUPDOWN lpnmud
= (LPNMUPDOWN
)lpnmh
;
953 TRACE("Delta pos %d\n", lpnmud
->iDelta
);
954 infoPtr
->pendingUpdown
= lpnmud
->iDelta
;
961 DATETIME_KeyDown (DATETIME_INFO
*infoPtr
, DWORD vkCode
)
963 int fieldNum
= infoPtr
->select
& DTHT_DATEFIELD
;
966 if (!(infoPtr
->haveFocus
)) return 0;
967 if ((fieldNum
==0) && (infoPtr
->select
)) return 0;
969 if (infoPtr
->select
& FORMATCALLMASK
) {
970 FIXME ("Callbacks not implemented yet\n");
976 DATETIME_IncreaseField (infoPtr
, fieldNum
, 1);
977 DATETIME_SendDateTimeChangeNotify (infoPtr
);
981 DATETIME_IncreaseField (infoPtr
, fieldNum
, -1);
982 DATETIME_SendDateTimeChangeNotify (infoPtr
);
985 DATETIME_IncreaseField (infoPtr
, fieldNum
, INT_MIN
);
986 DATETIME_SendDateTimeChangeNotify (infoPtr
);
989 DATETIME_IncreaseField (infoPtr
, fieldNum
, INT_MAX
);
990 DATETIME_SendDateTimeChangeNotify (infoPtr
);
994 if (infoPtr
->select
== 0) {
995 infoPtr
->select
= infoPtr
->nrFields
- 1;
1000 } while ((infoPtr
->fieldspec
[infoPtr
->select
] & DT_STRING
) && (wrap
<2));
1005 if (infoPtr
->select
==infoPtr
->nrFields
) {
1006 infoPtr
->select
= 0;
1009 } while ((infoPtr
->fieldspec
[infoPtr
->select
] & DT_STRING
) && (wrap
<2));
1013 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1020 DATETIME_Char (DATETIME_INFO
*infoPtr
, WPARAM vkCode
)
1022 int fieldNum
= infoPtr
->select
& DTHT_DATEFIELD
;
1024 if (vkCode
>= '0' && vkCode
<= '9') {
1025 int num
= vkCode
-'0';
1028 /* this is a somewhat simplified version of what Windows does */
1029 SYSTEMTIME
*date
= &infoPtr
->date
;
1030 switch (infoPtr
->fieldspec
[fieldNum
]) {
1033 date
->wYear
= date
->wYear
- (date
->wYear
%100) +
1034 (date
->wYear
%10)*10 + num
;
1035 MONTHCAL_CalculateDayOfWeek(date
, TRUE
);
1036 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1038 case INVALIDFULLYEAR
:
1040 /* reset current year initialy */
1041 date
->wYear
= ((date
->wYear
/1000) ? 0 : 1)*(date
->wYear
%1000)*10 + num
;
1042 MONTHCAL_CalculateDayOfWeek(date
, TRUE
);
1043 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1047 if ((date
->wMonth
%10) > 1 || num
> 2)
1050 date
->wMonth
= (date
->wMonth
%10)*10+num
;
1051 MONTHCAL_CalculateDayOfWeek(date
, TRUE
);
1052 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1056 newDays
= (date
->wDay
%10)*10+num
;
1057 if (newDays
> MONTHCAL_MonthLength(date
->wMonth
, date
->wYear
))
1060 date
->wDay
= newDays
;
1061 MONTHCAL_CalculateDayOfWeek(date
, TRUE
);
1062 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1064 case ONEDIGIT12HOUR
:
1065 case TWODIGIT12HOUR
:
1066 if ((date
->wHour
%10) > 1 || num
> 2)
1069 date
->wHour
= (date
->wHour
%10)*10+num
;
1070 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1072 case ONEDIGIT24HOUR
:
1073 case TWODIGIT24HOUR
:
1074 if ((date
->wHour
%10) > 2)
1076 else if ((date
->wHour
%10) == 2 && num
> 3)
1079 date
->wHour
= (date
->wHour
%10)*10+num
;
1080 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1082 case ONEDIGITMINUTE
:
1083 case TWODIGITMINUTE
:
1084 if ((date
->wMinute
%10) > 5)
1085 date
->wMinute
= num
;
1087 date
->wMinute
= (date
->wMinute
%10)*10+num
;
1088 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1090 case ONEDIGITSECOND
:
1091 case TWODIGITSECOND
:
1092 if ((date
->wSecond
%10) > 5)
1093 date
->wSecond
= num
;
1095 date
->wSecond
= (date
->wSecond
%10)*10+num
;
1096 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1105 DATETIME_VScroll (DATETIME_INFO
*infoPtr
, WORD wScroll
)
1107 int fieldNum
= infoPtr
->select
& DTHT_DATEFIELD
;
1109 if ((SHORT
)LOWORD(wScroll
) != SB_THUMBPOSITION
) return 0;
1110 if (!(infoPtr
->haveFocus
)) return 0;
1111 if ((fieldNum
==0) && (infoPtr
->select
)) return 0;
1113 if (infoPtr
->pendingUpdown
>= 0) {
1114 DATETIME_IncreaseField (infoPtr
, fieldNum
, 1);
1115 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1118 DATETIME_IncreaseField (infoPtr
, fieldNum
, -1);
1119 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1122 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1129 DATETIME_KillFocus (DATETIME_INFO
*infoPtr
, HWND lostFocus
)
1131 TRACE("lost focus to %p\n", lostFocus
);
1133 if (infoPtr
->haveFocus
) {
1134 DATETIME_SendSimpleNotify (infoPtr
, NM_KILLFOCUS
);
1135 infoPtr
->haveFocus
= 0;
1138 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
1145 DATETIME_NCCreate (HWND hwnd
, const CREATESTRUCTW
*lpcs
)
1147 DWORD dwExStyle
= GetWindowLongW(hwnd
, GWL_EXSTYLE
);
1148 /* force control to have client edge */
1149 dwExStyle
|= WS_EX_CLIENTEDGE
;
1150 SetWindowLongW(hwnd
, GWL_EXSTYLE
, dwExStyle
);
1152 return DefWindowProcW(hwnd
, WM_NCCREATE
, 0, (LPARAM
)lpcs
);
1157 DATETIME_SetFocus (DATETIME_INFO
*infoPtr
, HWND lostFocus
)
1159 TRACE("got focus from %p\n", lostFocus
);
1161 /* if monthcal is open and it loses focus, close monthcal */
1162 if (infoPtr
->hMonthCal
&& (lostFocus
== infoPtr
->hMonthCal
) &&
1163 IsWindowVisible(infoPtr
->hMonthCal
))
1165 ShowWindow(infoPtr
->hMonthCal
, SW_HIDE
);
1166 DATETIME_SendSimpleNotify(infoPtr
, DTN_CLOSEUP
);
1167 /* note: this get triggered even if monthcal loses focus to a dropdown
1168 * box click, which occurs without an intermediate WM_PAINT call
1170 infoPtr
->bDropdownEnabled
= FALSE
;
1174 if (infoPtr
->haveFocus
== 0) {
1175 DATETIME_SendSimpleNotify (infoPtr
, NM_SETFOCUS
);
1176 infoPtr
->haveFocus
= DTHT_GOTFOCUS
;
1179 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1186 DATETIME_SendDateTimeChangeNotify (const DATETIME_INFO
*infoPtr
)
1188 NMDATETIMECHANGE dtdtc
;
1190 dtdtc
.nmhdr
.hwndFrom
= infoPtr
->hwndSelf
;
1191 dtdtc
.nmhdr
.idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1192 dtdtc
.nmhdr
.code
= DTN_DATETIMECHANGE
;
1194 dtdtc
.dwFlags
= infoPtr
->dateValid
? GDT_VALID
: GDT_NONE
;
1196 dtdtc
.st
= infoPtr
->date
;
1197 return (BOOL
) SendMessageW (infoPtr
->hwndNotify
, WM_NOTIFY
,
1198 dtdtc
.nmhdr
.idFrom
, (LPARAM
)&dtdtc
);
1203 DATETIME_SendSimpleNotify (const DATETIME_INFO
*infoPtr
, UINT code
)
1207 TRACE("%x\n", code
);
1208 nmhdr
.hwndFrom
= infoPtr
->hwndSelf
;
1209 nmhdr
.idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1212 return (BOOL
) SendMessageW (infoPtr
->hwndNotify
, WM_NOTIFY
,
1213 nmhdr
.idFrom
, (LPARAM
)&nmhdr
);
1217 DATETIME_Size (DATETIME_INFO
*infoPtr
, INT width
, INT height
)
1220 infoPtr
->rcClient
.bottom
= height
;
1221 infoPtr
->rcClient
.right
= width
;
1223 TRACE("Height=%d, Width=%d\n", infoPtr
->rcClient
.bottom
, infoPtr
->rcClient
.right
);
1225 infoPtr
->rcDraw
= infoPtr
->rcClient
;
1227 if (infoPtr
->dwStyle
& DTS_UPDOWN
) {
1228 SetWindowPos(infoPtr
->hUpdown
, NULL
,
1229 infoPtr
->rcClient
.right
-14, 0,
1230 15, infoPtr
->rcClient
.bottom
- infoPtr
->rcClient
.top
,
1231 SWP_NOACTIVATE
| SWP_NOZORDER
);
1234 /* set the size of the button that drops the calendar down */
1235 /* FIXME: account for style that allows button on left side */
1236 infoPtr
->calbutton
.top
= infoPtr
->rcDraw
.top
;
1237 infoPtr
->calbutton
.bottom
= infoPtr
->rcDraw
.bottom
;
1238 infoPtr
->calbutton
.left
= infoPtr
->rcDraw
.right
-15;
1239 infoPtr
->calbutton
.right
= infoPtr
->rcDraw
.right
;
1242 /* set enable/disable button size for show none style being enabled */
1243 /* FIXME: these dimensions are completely incorrect */
1244 infoPtr
->checkbox
.top
= infoPtr
->rcDraw
.top
;
1245 infoPtr
->checkbox
.bottom
= infoPtr
->rcDraw
.bottom
;
1246 infoPtr
->checkbox
.left
= infoPtr
->rcDraw
.left
;
1247 infoPtr
->checkbox
.right
= infoPtr
->rcDraw
.left
+ 10;
1249 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1255 DATETIME_StyleChanging(DATETIME_INFO
*infoPtr
, WPARAM wStyleType
, STYLESTRUCT
*lpss
)
1257 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
1258 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
1260 /* block DTS_SHOWNONE change */
1261 if ((lpss
->styleNew
^ lpss
->styleOld
) & DTS_SHOWNONE
)
1263 if (lpss
->styleOld
& DTS_SHOWNONE
)
1264 lpss
->styleNew
|= DTS_SHOWNONE
;
1266 lpss
->styleNew
&= ~DTS_SHOWNONE
;
1273 DATETIME_StyleChanged(DATETIME_INFO
*infoPtr
, WPARAM wStyleType
, const STYLESTRUCT
*lpss
)
1275 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
1276 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
1278 if (wStyleType
!= GWL_STYLE
) return 0;
1280 infoPtr
->dwStyle
= lpss
->styleNew
;
1282 if ( !(lpss
->styleOld
& DTS_SHOWNONE
) && (lpss
->styleNew
& DTS_SHOWNONE
) ) {
1283 infoPtr
->hwndCheckbut
= CreateWindowExW (0, WC_BUTTONW
, 0, WS_CHILD
| WS_VISIBLE
| BS_AUTOCHECKBOX
,
1284 2, 2, 13, 13, infoPtr
->hwndSelf
, 0,
1285 (HINSTANCE
)GetWindowLongPtrW (infoPtr
->hwndSelf
, GWLP_HINSTANCE
), 0);
1286 SendMessageW (infoPtr
->hwndCheckbut
, BM_SETCHECK
, 1, 0);
1288 if ( (lpss
->styleOld
& DTS_SHOWNONE
) && !(lpss
->styleNew
& DTS_SHOWNONE
) ) {
1289 DestroyWindow(infoPtr
->hwndCheckbut
);
1290 infoPtr
->hwndCheckbut
= 0;
1292 if ( !(lpss
->styleOld
& DTS_UPDOWN
) && (lpss
->styleNew
& DTS_UPDOWN
) ) {
1293 infoPtr
->hUpdown
= CreateUpDownControl (WS_CHILD
| WS_BORDER
| WS_VISIBLE
, 120, 1, 20, 20,
1294 infoPtr
->hwndSelf
, 1, 0, 0, UD_MAXVAL
, UD_MINVAL
, 0);
1296 if ( (lpss
->styleOld
& DTS_UPDOWN
) && !(lpss
->styleNew
& DTS_UPDOWN
) ) {
1297 DestroyWindow(infoPtr
->hUpdown
);
1298 infoPtr
->hUpdown
= 0;
1301 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1307 DATETIME_SetFont (DATETIME_INFO
*infoPtr
, HFONT font
, BOOL repaint
)
1309 infoPtr
->hFont
= font
;
1310 if (repaint
) InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1316 DATETIME_Create (HWND hwnd
, const CREATESTRUCTW
*lpcs
)
1318 DATETIME_INFO
*infoPtr
= Alloc (sizeof(DATETIME_INFO
));
1319 STYLESTRUCT ss
= { 0, lpcs
->style
};
1321 if (!infoPtr
) return -1;
1323 infoPtr
->hwndSelf
= hwnd
;
1324 infoPtr
->dwStyle
= lpcs
->style
;
1326 infoPtr
->nrFieldsAllocated
= 32;
1327 infoPtr
->fieldspec
= Alloc (infoPtr
->nrFieldsAllocated
* sizeof(int));
1328 infoPtr
->fieldRect
= Alloc (infoPtr
->nrFieldsAllocated
* sizeof(RECT
));
1329 infoPtr
->buflen
= Alloc (infoPtr
->nrFieldsAllocated
* sizeof(int));
1330 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
1331 infoPtr
->select
= -1; /* initially, nothing is selected */
1332 infoPtr
->bDropdownEnabled
= TRUE
;
1334 DATETIME_StyleChanged(infoPtr
, GWL_STYLE
, &ss
);
1335 DATETIME_SetFormatW (infoPtr
, 0);
1337 /* create the monthcal control */
1338 infoPtr
->hMonthCal
= CreateWindowExW (0, MONTHCAL_CLASSW
, 0, WS_BORDER
| WS_POPUP
| WS_CLIPSIBLINGS
,
1339 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, 0, 0);
1341 /* initialize info structure */
1342 GetLocalTime (&infoPtr
->date
);
1343 infoPtr
->dateValid
= TRUE
;
1344 infoPtr
->hFont
= GetStockObject(DEFAULT_GUI_FONT
);
1346 SetWindowLongPtrW (hwnd
, 0, (DWORD_PTR
)infoPtr
);
1354 DATETIME_Destroy (DATETIME_INFO
*infoPtr
)
1356 if (infoPtr
->hwndCheckbut
)
1357 DestroyWindow(infoPtr
->hwndCheckbut
);
1358 if (infoPtr
->hUpdown
)
1359 DestroyWindow(infoPtr
->hUpdown
);
1360 if (infoPtr
->hMonthCal
)
1361 DestroyWindow(infoPtr
->hMonthCal
);
1362 SetWindowLongPtrW( infoPtr
->hwndSelf
, 0, 0 ); /* clear infoPtr */
1363 Free (infoPtr
->buflen
);
1364 Free (infoPtr
->fieldRect
);
1365 Free (infoPtr
->fieldspec
);
1372 DATETIME_GetText (DATETIME_INFO
*infoPtr
, INT count
, LPWSTR dst
)
1377 if (!dst
|| (count
<= 0)) return 0;
1380 for (i
= 0; i
< infoPtr
->nrFields
; i
++)
1382 DATETIME_ReturnTxt(infoPtr
, i
, buf
, sizeof(buf
)/sizeof(buf
[0]));
1383 if ((strlenW(dst
) + strlenW(buf
)) < count
)
1387 return strlenW(dst
);
1391 static LRESULT WINAPI
1392 DATETIME_WindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1394 DATETIME_INFO
*infoPtr
= ((DATETIME_INFO
*)GetWindowLongPtrW (hwnd
, 0));
1397 TRACE ("%x, %lx, %lx\n", uMsg
, wParam
, lParam
);
1399 if (!infoPtr
&& (uMsg
!= WM_CREATE
) && (uMsg
!= WM_NCCREATE
))
1400 return DefWindowProcW( hwnd
, uMsg
, wParam
, lParam
);
1404 case DTM_GETSYSTEMTIME
:
1405 return DATETIME_GetSystemTime (infoPtr
, (SYSTEMTIME
*) lParam
);
1407 case DTM_SETSYSTEMTIME
:
1408 return DATETIME_SetSystemTime (infoPtr
, wParam
, (SYSTEMTIME
*) lParam
);
1411 ret
= SendMessageW (infoPtr
->hMonthCal
, MCM_GETRANGE
, wParam
, lParam
);
1412 return ret
? ret
: 1; /* bug emulation */
1415 return SendMessageW (infoPtr
->hMonthCal
, MCM_SETRANGE
, wParam
, lParam
);
1417 case DTM_SETFORMATA
:
1418 return DATETIME_SetFormatA (infoPtr
, (LPCSTR
)lParam
);
1420 case DTM_SETFORMATW
:
1421 return DATETIME_SetFormatW (infoPtr
, (LPCWSTR
)lParam
);
1423 case DTM_GETMONTHCAL
:
1424 return (LRESULT
)infoPtr
->hMonthCal
;
1426 case DTM_SETMCCOLOR
:
1427 return SendMessageW (infoPtr
->hMonthCal
, MCM_SETCOLOR
, wParam
, lParam
);
1429 case DTM_GETMCCOLOR
:
1430 return SendMessageW (infoPtr
->hMonthCal
, MCM_GETCOLOR
, wParam
, 0);
1433 return SendMessageW (infoPtr
->hMonthCal
, WM_SETFONT
, wParam
, lParam
);
1436 return SendMessageW (infoPtr
->hMonthCal
, WM_GETFONT
, wParam
, lParam
);
1439 return DATETIME_Notify (infoPtr
, (LPNMHDR
)lParam
);
1442 return DATETIME_Enable (infoPtr
, (BOOL
)wParam
);
1445 return DATETIME_EraseBackground (infoPtr
, (HDC
)wParam
);
1448 return DLGC_WANTARROWS
| DLGC_WANTCHARS
;
1450 case WM_PRINTCLIENT
:
1452 return DATETIME_Paint (infoPtr
, (HDC
)wParam
);
1455 return DATETIME_KeyDown (infoPtr
, wParam
);
1458 return DATETIME_Char (infoPtr
, wParam
);
1461 return DATETIME_KillFocus (infoPtr
, (HWND
)wParam
);
1464 return DATETIME_NCCreate (hwnd
, (LPCREATESTRUCTW
)lParam
);
1467 return DATETIME_SetFocus (infoPtr
, (HWND
)wParam
);
1470 return DATETIME_Size (infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
1472 case WM_LBUTTONDOWN
:
1473 return DATETIME_LButtonDown (infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
1476 return DATETIME_LButtonUp (infoPtr
);
1479 return DATETIME_VScroll (infoPtr
, (WORD
)wParam
);
1482 return DATETIME_Create (hwnd
, (LPCREATESTRUCTW
)lParam
);
1485 return DATETIME_Destroy (infoPtr
);
1488 return DATETIME_Command (infoPtr
, wParam
, lParam
);
1490 case WM_STYLECHANGING
:
1491 return DATETIME_StyleChanging(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
1493 case WM_STYLECHANGED
:
1494 return DATETIME_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
1497 return DATETIME_SetFont(infoPtr
, (HFONT
)wParam
, (BOOL
)lParam
);
1500 return (LRESULT
) infoPtr
->hFont
;
1503 return (LRESULT
) DATETIME_GetText(infoPtr
, wParam
, (LPWSTR
)lParam
);
1509 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
1510 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
1511 uMsg
, wParam
, lParam
);
1512 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
1518 DATETIME_Register (void)
1522 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
1523 wndClass
.style
= CS_GLOBALCLASS
;
1524 wndClass
.lpfnWndProc
= DATETIME_WindowProc
;
1525 wndClass
.cbClsExtra
= 0;
1526 wndClass
.cbWndExtra
= sizeof(DATETIME_INFO
*);
1527 wndClass
.hCursor
= LoadCursorW (0, (LPCWSTR
)IDC_ARROW
);
1528 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
1529 wndClass
.lpszClassName
= DATETIMEPICK_CLASSW
;
1531 RegisterClassW (&wndClass
);
1536 DATETIME_Unregister (void)
1538 UnregisterClassW (DATETIMEPICK_CLASSW
, NULL
);