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(LOCALE_USER_DEFAULT
, 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(LOCALE_USER_DEFAULT
, LOCALE_SMONTHNAME1
+date
.wMonth
-1,
414 buffer
, sizeof(buffer
)/sizeof(buffer
[0]));
415 wsprintfW (result
, fmt__3sW
, buffer
);
418 GetLocaleInfoW(LOCALE_USER_DEFAULT
, 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
;
617 default: /* FULLMONTH */
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 new = DATETIME_HitTest (infoPtr
, pt
);
768 SetFocus(infoPtr
->hwndSelf
);
770 if (!(new & DTHT_NODATEMASK
) || (new == DTHT_NONE
))
772 if (new == DTHT_NONE
)
773 new = infoPtr
->nrFields
- 1;
776 /* hitting string part moves selection to next date field to left */
777 if (infoPtr
->fieldspec
[new] & DT_STRING
)
779 new = DATETIME_GetPrevDateField(infoPtr
, new);
780 if (new == -1) return 0;
782 /* never select full day of week */
783 if (infoPtr
->fieldspec
[new] == FULLDAY
) return 0;
786 infoPtr
->select
= new;
788 if (infoPtr
->select
== DTHT_MCPOPUP
) {
790 SendMessageW(infoPtr
->hMonthCal
, MCM_GETMINREQRECT
, 0, (LPARAM
)&rcMonthCal
);
792 /* FIXME: button actually is only depressed during dropdown of the */
793 /* calendar control and when the mouse is over the button window */
794 infoPtr
->bCalDepressed
= TRUE
;
796 /* recalculate the position of the monthcal popup */
797 if(infoPtr
->dwStyle
& DTS_RIGHTALIGN
)
798 infoPtr
->monthcal_pos
.x
= infoPtr
->calbutton
.left
-
799 (rcMonthCal
.right
- rcMonthCal
.left
);
801 /* FIXME: this should be after the area reserved for the checkbox */
802 infoPtr
->monthcal_pos
.x
= infoPtr
->rcDraw
.left
;
804 infoPtr
->monthcal_pos
.y
= infoPtr
->rcClient
.bottom
;
805 ClientToScreen (infoPtr
->hwndSelf
, &(infoPtr
->monthcal_pos
));
806 SetWindowPos(infoPtr
->hMonthCal
, 0, infoPtr
->monthcal_pos
.x
,
807 infoPtr
->monthcal_pos
.y
, rcMonthCal
.right
- rcMonthCal
.left
,
808 rcMonthCal
.bottom
- rcMonthCal
.top
, 0);
810 if(IsWindowVisible(infoPtr
->hMonthCal
)) {
811 ShowWindow(infoPtr
->hMonthCal
, SW_HIDE
);
812 infoPtr
->bDropdownEnabled
= FALSE
;
813 DATETIME_SendSimpleNotify (infoPtr
, DTN_CLOSEUP
);
815 const SYSTEMTIME
*lprgSysTimeArray
= &infoPtr
->date
;
816 TRACE("update calendar %04d/%02d/%02d\n",
817 lprgSysTimeArray
->wYear
, lprgSysTimeArray
->wMonth
, lprgSysTimeArray
->wDay
);
818 SendMessageW(infoPtr
->hMonthCal
, MCM_SETCURSEL
, 0, (LPARAM
)(&infoPtr
->date
));
820 if (infoPtr
->bDropdownEnabled
) {
821 ShowWindow(infoPtr
->hMonthCal
, SW_SHOW
);
822 DATETIME_SendSimpleNotify (infoPtr
, DTN_DROPDOWN
);
824 infoPtr
->bDropdownEnabled
= TRUE
;
827 TRACE ("dt:%p mc:%p mc parent:%p, desktop:%p\n",
828 infoPtr
->hwndSelf
, infoPtr
->hMonthCal
, infoPtr
->hwndNotify
, GetDesktopWindow ());
831 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
838 DATETIME_LButtonUp (DATETIME_INFO
*infoPtr
)
840 if(infoPtr
->bCalDepressed
) {
841 infoPtr
->bCalDepressed
= FALSE
;
842 InvalidateRect(infoPtr
->hwndSelf
, &(infoPtr
->calbutton
), TRUE
);
850 DATETIME_Paint (DATETIME_INFO
*infoPtr
, HDC hdc
)
854 hdc
= BeginPaint (infoPtr
->hwndSelf
, &ps
);
855 DATETIME_Refresh (infoPtr
, hdc
);
856 EndPaint (infoPtr
->hwndSelf
, &ps
);
858 DATETIME_Refresh (infoPtr
, hdc
);
861 /* Not a click on the dropdown box, enabled it */
862 infoPtr
->bDropdownEnabled
= TRUE
;
869 DATETIME_Button_Command (DATETIME_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
871 if( HIWORD(wParam
) == BN_CLICKED
) {
872 DWORD state
= SendMessageW((HWND
)lParam
, BM_GETCHECK
, 0, 0);
873 infoPtr
->dateValid
= (state
== BST_CHECKED
);
874 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
882 DATETIME_Command (DATETIME_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
884 TRACE("hwndbutton = %p\n", infoPtr
->hwndCheckbut
);
885 if(infoPtr
->hwndCheckbut
== (HWND
)lParam
)
886 return DATETIME_Button_Command(infoPtr
, wParam
, lParam
);
892 DATETIME_Enable (DATETIME_INFO
*infoPtr
, BOOL bEnable
)
894 TRACE("%p %s\n", infoPtr
, bEnable
? "TRUE" : "FALSE");
896 infoPtr
->dwStyle
&= ~WS_DISABLED
;
898 infoPtr
->dwStyle
|= WS_DISABLED
;
900 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
907 DATETIME_EraseBackground (const DATETIME_INFO
*infoPtr
, HDC hdc
)
909 HBRUSH hBrush
, hSolidBrush
= NULL
;
912 if (infoPtr
->dwStyle
& WS_DISABLED
)
913 hBrush
= hSolidBrush
= CreateSolidBrush(comctl32_color
.clrBtnFace
);
916 hBrush
= (HBRUSH
)SendMessageW(infoPtr
->hwndNotify
, WM_CTLCOLOREDIT
,
917 (WPARAM
)hdc
, (LPARAM
)infoPtr
->hwndSelf
);
919 hBrush
= hSolidBrush
= CreateSolidBrush(comctl32_color
.clrWindow
);
922 GetClientRect (infoPtr
->hwndSelf
, &rc
);
924 FillRect (hdc
, &rc
, hBrush
);
927 DeleteObject(hSolidBrush
);
934 DATETIME_Notify (DATETIME_INFO
*infoPtr
, const NMHDR
*lpnmh
)
936 TRACE ("Got notification %x from %p\n", lpnmh
->code
, lpnmh
->hwndFrom
);
937 TRACE ("info: %p %p %p\n", infoPtr
->hwndSelf
, infoPtr
->hMonthCal
, infoPtr
->hUpdown
);
939 if (lpnmh
->code
== MCN_SELECT
) {
940 ShowWindow(infoPtr
->hMonthCal
, SW_HIDE
);
941 infoPtr
->dateValid
= TRUE
;
942 SendMessageW (infoPtr
->hMonthCal
, MCM_GETCURSEL
, 0, (LPARAM
)&infoPtr
->date
);
943 TRACE("got from calendar %04d/%02d/%02d day of week %d\n",
944 infoPtr
->date
.wYear
, infoPtr
->date
.wMonth
, infoPtr
->date
.wDay
, infoPtr
->date
.wDayOfWeek
);
945 SendMessageW (infoPtr
->hwndCheckbut
, BM_SETCHECK
, BST_CHECKED
, 0);
946 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
947 DATETIME_SendDateTimeChangeNotify (infoPtr
);
948 DATETIME_SendSimpleNotify(infoPtr
, DTN_CLOSEUP
);
950 if ((lpnmh
->hwndFrom
== infoPtr
->hUpdown
) && (lpnmh
->code
== UDN_DELTAPOS
)) {
951 const NM_UPDOWN
*lpnmud
= (const NM_UPDOWN
*)lpnmh
;
952 TRACE("Delta pos %d\n", lpnmud
->iDelta
);
953 infoPtr
->pendingUpdown
= lpnmud
->iDelta
;
960 DATETIME_KeyDown (DATETIME_INFO
*infoPtr
, DWORD vkCode
)
962 int fieldNum
= infoPtr
->select
& DTHT_DATEFIELD
;
965 if (!(infoPtr
->haveFocus
)) return 0;
966 if ((fieldNum
==0) && (infoPtr
->select
)) return 0;
968 if (infoPtr
->select
& FORMATCALLMASK
) {
969 FIXME ("Callbacks not implemented yet\n");
975 DATETIME_IncreaseField (infoPtr
, fieldNum
, 1);
976 DATETIME_SendDateTimeChangeNotify (infoPtr
);
980 DATETIME_IncreaseField (infoPtr
, fieldNum
, -1);
981 DATETIME_SendDateTimeChangeNotify (infoPtr
);
984 DATETIME_IncreaseField (infoPtr
, fieldNum
, INT_MIN
);
985 DATETIME_SendDateTimeChangeNotify (infoPtr
);
988 DATETIME_IncreaseField (infoPtr
, fieldNum
, INT_MAX
);
989 DATETIME_SendDateTimeChangeNotify (infoPtr
);
993 if (infoPtr
->select
== 0) {
994 infoPtr
->select
= infoPtr
->nrFields
- 1;
999 } while ((infoPtr
->fieldspec
[infoPtr
->select
] & DT_STRING
) && (wrap
<2));
1004 if (infoPtr
->select
==infoPtr
->nrFields
) {
1005 infoPtr
->select
= 0;
1008 } while ((infoPtr
->fieldspec
[infoPtr
->select
] & DT_STRING
) && (wrap
<2));
1012 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1019 DATETIME_Char (DATETIME_INFO
*infoPtr
, WPARAM vkCode
)
1021 int fieldNum
= infoPtr
->select
& DTHT_DATEFIELD
;
1023 if (vkCode
>= '0' && vkCode
<= '9') {
1024 int num
= vkCode
-'0';
1027 /* this is a somewhat simplified version of what Windows does */
1028 SYSTEMTIME
*date
= &infoPtr
->date
;
1029 switch (infoPtr
->fieldspec
[fieldNum
]) {
1032 date
->wYear
= date
->wYear
- (date
->wYear
%100) +
1033 (date
->wYear
%10)*10 + num
;
1034 MONTHCAL_CalculateDayOfWeek(date
, TRUE
);
1035 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1037 case INVALIDFULLYEAR
:
1039 /* reset current year initialy */
1040 date
->wYear
= ((date
->wYear
/1000) ? 0 : 1)*(date
->wYear
%1000)*10 + num
;
1041 MONTHCAL_CalculateDayOfWeek(date
, TRUE
);
1042 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1046 if ((date
->wMonth
%10) > 1 || num
> 2)
1049 date
->wMonth
= (date
->wMonth
%10)*10+num
;
1050 MONTHCAL_CalculateDayOfWeek(date
, TRUE
);
1051 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1055 newDays
= (date
->wDay
%10)*10+num
;
1056 if (newDays
> MONTHCAL_MonthLength(date
->wMonth
, date
->wYear
))
1059 date
->wDay
= newDays
;
1060 MONTHCAL_CalculateDayOfWeek(date
, TRUE
);
1061 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1063 case ONEDIGIT12HOUR
:
1064 case TWODIGIT12HOUR
:
1065 if ((date
->wHour
%10) > 1 || num
> 2)
1068 date
->wHour
= (date
->wHour
%10)*10+num
;
1069 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1071 case ONEDIGIT24HOUR
:
1072 case TWODIGIT24HOUR
:
1073 if ((date
->wHour
%10) > 2)
1075 else if ((date
->wHour
%10) == 2 && num
> 3)
1078 date
->wHour
= (date
->wHour
%10)*10+num
;
1079 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1081 case ONEDIGITMINUTE
:
1082 case TWODIGITMINUTE
:
1083 if ((date
->wMinute
%10) > 5)
1084 date
->wMinute
= num
;
1086 date
->wMinute
= (date
->wMinute
%10)*10+num
;
1087 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1089 case ONEDIGITSECOND
:
1090 case TWODIGITSECOND
:
1091 if ((date
->wSecond
%10) > 5)
1092 date
->wSecond
= num
;
1094 date
->wSecond
= (date
->wSecond
%10)*10+num
;
1095 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1104 DATETIME_VScroll (DATETIME_INFO
*infoPtr
, WORD wScroll
)
1106 int fieldNum
= infoPtr
->select
& DTHT_DATEFIELD
;
1108 if ((SHORT
)LOWORD(wScroll
) != SB_THUMBPOSITION
) return 0;
1109 if (!(infoPtr
->haveFocus
)) return 0;
1110 if ((fieldNum
==0) && (infoPtr
->select
)) return 0;
1112 if (infoPtr
->pendingUpdown
>= 0) {
1113 DATETIME_IncreaseField (infoPtr
, fieldNum
, 1);
1114 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1117 DATETIME_IncreaseField (infoPtr
, fieldNum
, -1);
1118 DATETIME_SendDateTimeChangeNotify (infoPtr
);
1121 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1128 DATETIME_KillFocus (DATETIME_INFO
*infoPtr
, HWND lostFocus
)
1130 TRACE("lost focus to %p\n", lostFocus
);
1132 if (infoPtr
->haveFocus
) {
1133 DATETIME_SendSimpleNotify (infoPtr
, NM_KILLFOCUS
);
1134 infoPtr
->haveFocus
= 0;
1137 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
1144 DATETIME_NCCreate (HWND hwnd
, const CREATESTRUCTW
*lpcs
)
1146 DWORD dwExStyle
= GetWindowLongW(hwnd
, GWL_EXSTYLE
);
1147 /* force control to have client edge */
1148 dwExStyle
|= WS_EX_CLIENTEDGE
;
1149 SetWindowLongW(hwnd
, GWL_EXSTYLE
, dwExStyle
);
1151 return DefWindowProcW(hwnd
, WM_NCCREATE
, 0, (LPARAM
)lpcs
);
1156 DATETIME_SetFocus (DATETIME_INFO
*infoPtr
, HWND lostFocus
)
1158 TRACE("got focus from %p\n", lostFocus
);
1160 /* if monthcal is open and it loses focus, close monthcal */
1161 if (infoPtr
->hMonthCal
&& (lostFocus
== infoPtr
->hMonthCal
) &&
1162 IsWindowVisible(infoPtr
->hMonthCal
))
1164 ShowWindow(infoPtr
->hMonthCal
, SW_HIDE
);
1165 DATETIME_SendSimpleNotify(infoPtr
, DTN_CLOSEUP
);
1166 /* note: this get triggered even if monthcal loses focus to a dropdown
1167 * box click, which occurs without an intermediate WM_PAINT call
1169 infoPtr
->bDropdownEnabled
= FALSE
;
1173 if (infoPtr
->haveFocus
== 0) {
1174 DATETIME_SendSimpleNotify (infoPtr
, NM_SETFOCUS
);
1175 infoPtr
->haveFocus
= DTHT_GOTFOCUS
;
1178 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1185 DATETIME_SendDateTimeChangeNotify (const DATETIME_INFO
*infoPtr
)
1187 NMDATETIMECHANGE dtdtc
;
1189 dtdtc
.nmhdr
.hwndFrom
= infoPtr
->hwndSelf
;
1190 dtdtc
.nmhdr
.idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1191 dtdtc
.nmhdr
.code
= DTN_DATETIMECHANGE
;
1193 dtdtc
.dwFlags
= infoPtr
->dateValid
? GDT_VALID
: GDT_NONE
;
1195 dtdtc
.st
= infoPtr
->date
;
1196 return (BOOL
) SendMessageW (infoPtr
->hwndNotify
, WM_NOTIFY
,
1197 dtdtc
.nmhdr
.idFrom
, (LPARAM
)&dtdtc
);
1202 DATETIME_SendSimpleNotify (const DATETIME_INFO
*infoPtr
, UINT code
)
1206 TRACE("%x\n", code
);
1207 nmhdr
.hwndFrom
= infoPtr
->hwndSelf
;
1208 nmhdr
.idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1211 return (BOOL
) SendMessageW (infoPtr
->hwndNotify
, WM_NOTIFY
,
1212 nmhdr
.idFrom
, (LPARAM
)&nmhdr
);
1216 DATETIME_Size (DATETIME_INFO
*infoPtr
, INT width
, INT height
)
1219 infoPtr
->rcClient
.bottom
= height
;
1220 infoPtr
->rcClient
.right
= width
;
1222 TRACE("Height=%d, Width=%d\n", infoPtr
->rcClient
.bottom
, infoPtr
->rcClient
.right
);
1224 infoPtr
->rcDraw
= infoPtr
->rcClient
;
1226 if (infoPtr
->dwStyle
& DTS_UPDOWN
) {
1227 SetWindowPos(infoPtr
->hUpdown
, NULL
,
1228 infoPtr
->rcClient
.right
-14, 0,
1229 15, infoPtr
->rcClient
.bottom
- infoPtr
->rcClient
.top
,
1230 SWP_NOACTIVATE
| SWP_NOZORDER
);
1233 /* set the size of the button that drops the calendar down */
1234 /* FIXME: account for style that allows button on left side */
1235 infoPtr
->calbutton
.top
= infoPtr
->rcDraw
.top
;
1236 infoPtr
->calbutton
.bottom
= infoPtr
->rcDraw
.bottom
;
1237 infoPtr
->calbutton
.left
= infoPtr
->rcDraw
.right
-15;
1238 infoPtr
->calbutton
.right
= infoPtr
->rcDraw
.right
;
1241 /* set enable/disable button size for show none style being enabled */
1242 /* FIXME: these dimensions are completely incorrect */
1243 infoPtr
->checkbox
.top
= infoPtr
->rcDraw
.top
;
1244 infoPtr
->checkbox
.bottom
= infoPtr
->rcDraw
.bottom
;
1245 infoPtr
->checkbox
.left
= infoPtr
->rcDraw
.left
;
1246 infoPtr
->checkbox
.right
= infoPtr
->rcDraw
.left
+ 10;
1248 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1254 DATETIME_StyleChanging(DATETIME_INFO
*infoPtr
, WPARAM wStyleType
, STYLESTRUCT
*lpss
)
1256 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
1257 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
1259 /* block DTS_SHOWNONE change */
1260 if ((lpss
->styleNew
^ lpss
->styleOld
) & DTS_SHOWNONE
)
1262 if (lpss
->styleOld
& DTS_SHOWNONE
)
1263 lpss
->styleNew
|= DTS_SHOWNONE
;
1265 lpss
->styleNew
&= ~DTS_SHOWNONE
;
1272 DATETIME_StyleChanged(DATETIME_INFO
*infoPtr
, WPARAM wStyleType
, const STYLESTRUCT
*lpss
)
1274 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
1275 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
1277 if (wStyleType
!= GWL_STYLE
) return 0;
1279 infoPtr
->dwStyle
= lpss
->styleNew
;
1281 if ( !(lpss
->styleOld
& DTS_SHOWNONE
) && (lpss
->styleNew
& DTS_SHOWNONE
) ) {
1282 infoPtr
->hwndCheckbut
= CreateWindowExW (0, WC_BUTTONW
, 0, WS_CHILD
| WS_VISIBLE
| BS_AUTOCHECKBOX
,
1283 2, 2, 13, 13, infoPtr
->hwndSelf
, 0,
1284 (HINSTANCE
)GetWindowLongPtrW (infoPtr
->hwndSelf
, GWLP_HINSTANCE
), 0);
1285 SendMessageW (infoPtr
->hwndCheckbut
, BM_SETCHECK
, 1, 0);
1287 if ( (lpss
->styleOld
& DTS_SHOWNONE
) && !(lpss
->styleNew
& DTS_SHOWNONE
) ) {
1288 DestroyWindow(infoPtr
->hwndCheckbut
);
1289 infoPtr
->hwndCheckbut
= 0;
1291 if ( !(lpss
->styleOld
& DTS_UPDOWN
) && (lpss
->styleNew
& DTS_UPDOWN
) ) {
1292 infoPtr
->hUpdown
= CreateUpDownControl (WS_CHILD
| WS_BORDER
| WS_VISIBLE
, 120, 1, 20, 20,
1293 infoPtr
->hwndSelf
, 1, 0, 0, UD_MAXVAL
, UD_MINVAL
, 0);
1295 if ( (lpss
->styleOld
& DTS_UPDOWN
) && !(lpss
->styleNew
& DTS_UPDOWN
) ) {
1296 DestroyWindow(infoPtr
->hUpdown
);
1297 infoPtr
->hUpdown
= 0;
1300 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1306 DATETIME_SetFont (DATETIME_INFO
*infoPtr
, HFONT font
, BOOL repaint
)
1308 infoPtr
->hFont
= font
;
1309 if (repaint
) InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1315 DATETIME_Create (HWND hwnd
, const CREATESTRUCTW
*lpcs
)
1317 DATETIME_INFO
*infoPtr
= Alloc (sizeof(DATETIME_INFO
));
1318 STYLESTRUCT ss
= { 0, lpcs
->style
};
1320 if (!infoPtr
) return -1;
1322 infoPtr
->hwndSelf
= hwnd
;
1323 infoPtr
->dwStyle
= lpcs
->style
;
1325 infoPtr
->nrFieldsAllocated
= 32;
1326 infoPtr
->fieldspec
= Alloc (infoPtr
->nrFieldsAllocated
* sizeof(int));
1327 infoPtr
->fieldRect
= Alloc (infoPtr
->nrFieldsAllocated
* sizeof(RECT
));
1328 infoPtr
->buflen
= Alloc (infoPtr
->nrFieldsAllocated
* sizeof(int));
1329 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
1330 infoPtr
->select
= -1; /* initially, nothing is selected */
1331 infoPtr
->bDropdownEnabled
= TRUE
;
1333 DATETIME_StyleChanged(infoPtr
, GWL_STYLE
, &ss
);
1334 DATETIME_SetFormatW (infoPtr
, 0);
1336 /* create the monthcal control */
1337 infoPtr
->hMonthCal
= CreateWindowExW (0, MONTHCAL_CLASSW
, 0, WS_BORDER
| WS_POPUP
| WS_CLIPSIBLINGS
,
1338 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, 0, 0);
1340 /* initialize info structure */
1341 GetLocalTime (&infoPtr
->date
);
1342 infoPtr
->dateValid
= TRUE
;
1343 infoPtr
->hFont
= GetStockObject(DEFAULT_GUI_FONT
);
1345 SetWindowLongPtrW (hwnd
, 0, (DWORD_PTR
)infoPtr
);
1353 DATETIME_Destroy (DATETIME_INFO
*infoPtr
)
1355 if (infoPtr
->hwndCheckbut
)
1356 DestroyWindow(infoPtr
->hwndCheckbut
);
1357 if (infoPtr
->hUpdown
)
1358 DestroyWindow(infoPtr
->hUpdown
);
1359 if (infoPtr
->hMonthCal
)
1360 DestroyWindow(infoPtr
->hMonthCal
);
1361 SetWindowLongPtrW( infoPtr
->hwndSelf
, 0, 0 ); /* clear infoPtr */
1362 Free (infoPtr
->buflen
);
1363 Free (infoPtr
->fieldRect
);
1364 Free (infoPtr
->fieldspec
);
1371 DATETIME_GetText (DATETIME_INFO
*infoPtr
, INT count
, LPWSTR dst
)
1376 if (!dst
|| (count
<= 0)) return 0;
1379 for (i
= 0; i
< infoPtr
->nrFields
; i
++)
1381 DATETIME_ReturnTxt(infoPtr
, i
, buf
, sizeof(buf
)/sizeof(buf
[0]));
1382 if ((strlenW(dst
) + strlenW(buf
)) < count
)
1386 return strlenW(dst
);
1390 static LRESULT WINAPI
1391 DATETIME_WindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1393 DATETIME_INFO
*infoPtr
= ((DATETIME_INFO
*)GetWindowLongPtrW (hwnd
, 0));
1396 TRACE ("%x, %lx, %lx\n", uMsg
, wParam
, lParam
);
1398 if (!infoPtr
&& (uMsg
!= WM_CREATE
) && (uMsg
!= WM_NCCREATE
))
1399 return DefWindowProcW( hwnd
, uMsg
, wParam
, lParam
);
1403 case DTM_GETSYSTEMTIME
:
1404 return DATETIME_GetSystemTime (infoPtr
, (SYSTEMTIME
*) lParam
);
1406 case DTM_SETSYSTEMTIME
:
1407 return DATETIME_SetSystemTime (infoPtr
, wParam
, (SYSTEMTIME
*) lParam
);
1410 ret
= SendMessageW (infoPtr
->hMonthCal
, MCM_GETRANGE
, wParam
, lParam
);
1411 return ret
? ret
: 1; /* bug emulation */
1414 return SendMessageW (infoPtr
->hMonthCal
, MCM_SETRANGE
, wParam
, lParam
);
1416 case DTM_SETFORMATA
:
1417 return DATETIME_SetFormatA (infoPtr
, (LPCSTR
)lParam
);
1419 case DTM_SETFORMATW
:
1420 return DATETIME_SetFormatW (infoPtr
, (LPCWSTR
)lParam
);
1422 case DTM_GETMONTHCAL
:
1423 return (LRESULT
)infoPtr
->hMonthCal
;
1425 case DTM_SETMCCOLOR
:
1426 return SendMessageW (infoPtr
->hMonthCal
, MCM_SETCOLOR
, wParam
, lParam
);
1428 case DTM_GETMCCOLOR
:
1429 return SendMessageW (infoPtr
->hMonthCal
, MCM_GETCOLOR
, wParam
, 0);
1432 return SendMessageW (infoPtr
->hMonthCal
, WM_SETFONT
, wParam
, lParam
);
1435 return SendMessageW (infoPtr
->hMonthCal
, WM_GETFONT
, wParam
, lParam
);
1438 return DATETIME_Notify (infoPtr
, (LPNMHDR
)lParam
);
1441 return DATETIME_Enable (infoPtr
, (BOOL
)wParam
);
1444 return DATETIME_EraseBackground (infoPtr
, (HDC
)wParam
);
1447 return DLGC_WANTARROWS
| DLGC_WANTCHARS
;
1449 case WM_PRINTCLIENT
:
1451 return DATETIME_Paint (infoPtr
, (HDC
)wParam
);
1454 return DATETIME_KeyDown (infoPtr
, wParam
);
1457 return DATETIME_Char (infoPtr
, wParam
);
1460 return DATETIME_KillFocus (infoPtr
, (HWND
)wParam
);
1463 return DATETIME_NCCreate (hwnd
, (LPCREATESTRUCTW
)lParam
);
1466 return DATETIME_SetFocus (infoPtr
, (HWND
)wParam
);
1469 return DATETIME_Size (infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
1471 case WM_LBUTTONDOWN
:
1472 return DATETIME_LButtonDown (infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
1475 return DATETIME_LButtonUp (infoPtr
);
1478 return DATETIME_VScroll (infoPtr
, (WORD
)wParam
);
1481 return DATETIME_Create (hwnd
, (LPCREATESTRUCTW
)lParam
);
1484 return DATETIME_Destroy (infoPtr
);
1487 return DATETIME_Command (infoPtr
, wParam
, lParam
);
1489 case WM_STYLECHANGING
:
1490 return DATETIME_StyleChanging(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
1492 case WM_STYLECHANGED
:
1493 return DATETIME_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
1496 return DATETIME_SetFont(infoPtr
, (HFONT
)wParam
, (BOOL
)lParam
);
1499 return (LRESULT
) infoPtr
->hFont
;
1502 return (LRESULT
) DATETIME_GetText(infoPtr
, wParam
, (LPWSTR
)lParam
);
1508 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
1509 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
1510 uMsg
, wParam
, lParam
);
1511 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
1517 DATETIME_Register (void)
1521 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
1522 wndClass
.style
= CS_GLOBALCLASS
;
1523 wndClass
.lpfnWndProc
= DATETIME_WindowProc
;
1524 wndClass
.cbClsExtra
= 0;
1525 wndClass
.cbWndExtra
= sizeof(DATETIME_INFO
*);
1526 wndClass
.hCursor
= LoadCursorW (0, (LPCWSTR
)IDC_ARROW
);
1527 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
1528 wndClass
.lpszClassName
= DATETIMEPICK_CLASSW
;
1530 RegisterClassW (&wndClass
);
1535 DATETIME_Unregister (void)
1537 UnregisterClassW (DATETIMEPICK_CLASSW
, NULL
);