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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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
55 #include "wine/debug.h"
56 #include "wine/unicode.h"
58 WINE_DEFAULT_DEBUG_CHANNEL(datetime
);
70 RECT rcClient
; /* rect around the edge of the window */
71 RECT rcDraw
; /* rect inside of the border */
72 RECT checkbox
; /* checkbox allowing the control to be enabled/disabled */
73 RECT calbutton
; /* button that toggles the dropdown of the monthcal control */
74 BOOL bCalDepressed
; /* TRUE = cal button is depressed */
77 int nrFieldsAllocated
;
85 } DATETIME_INFO
, *LPDATETIME_INFO
;
88 extern int MONTHCAL_MonthLength(int month
, int year
);
90 /* this list of defines is closely related to `allowedformatchars' defined
91 * in datetime.c; the high nibble indicates the `base type' of the format
93 * Do not change without first reading DATETIME_UseFormat.
97 #define DT_END_FORMAT 0
98 #define ONEDIGITDAY 0x01
99 #define TWODIGITDAY 0x02
100 #define THREECHARDAY 0x03
102 #define ONEDIGIT12HOUR 0x11
103 #define TWODIGIT12HOUR 0x12
104 #define ONEDIGIT24HOUR 0x21
105 #define TWODIGIT24HOUR 0x22
106 #define ONEDIGITMINUTE 0x31
107 #define TWODIGITMINUTE 0x32
108 #define ONEDIGITMONTH 0x41
109 #define TWODIGITMONTH 0x42
110 #define THREECHARMONTH 0x43
111 #define FULLMONTH 0x44
112 #define ONEDIGITSECOND 0x51
113 #define TWODIGITSECOND 0x52
114 #define ONELETTERAMPM 0x61
115 #define TWOLETTERAMPM 0x62
116 #define ONEDIGITYEAR 0x71
117 #define TWODIGITYEAR 0x72
118 #define INVALIDFULLYEAR 0x73 /* FIXME - yyy is not valid - we'll treat it as yyyy */
119 #define FULLYEAR 0x74
120 #define FORMATCALLBACK 0x81 /* -> maximum of 0x80 callbacks possible */
121 #define FORMATCALLMASK 0x80
122 #define DT_STRING 0x0100
124 #define DTHT_DATEFIELD 0xff /* for hit-testing */
127 #define DTHT_CHECKBOX 0x200 /* these should end at '00' , to make */
128 #define DTHT_MCPOPUP 0x300 /* & DTHT_DATEFIELD 0 when DATETIME_KeyDown */
129 #define DTHT_GOTFOCUS 0x400 /* tests for date-fields */
131 static BOOL
DATETIME_SendSimpleNotify (DATETIME_INFO
*infoPtr
, UINT code
);
132 static BOOL
DATETIME_SendDateTimeChangeNotify (DATETIME_INFO
*infoPtr
);
133 extern void MONTHCAL_CopyTime(const SYSTEMTIME
*from
, SYSTEMTIME
*to
);
134 static const WCHAR allowedformatchars
[] = {'d', 'h', 'H', 'm', 'M', 's', 't', 'y', 'X', '\'', 0};
135 static const int maxrepetition
[] = {4,2,2,2,4,2,2,4,-1,-1};
139 DATETIME_GetSystemTime (DATETIME_INFO
*infoPtr
, SYSTEMTIME
*lprgSysTimeArray
)
141 if (!lprgSysTimeArray
) return GDT_NONE
;
143 if ((infoPtr
->dwStyle
& DTS_SHOWNONE
) &&
144 (SendMessageW (infoPtr
->hwndCheckbut
, BM_GETCHECK
, 0, 0) == BST_UNCHECKED
))
147 MONTHCAL_CopyTime (&infoPtr
->date
, lprgSysTimeArray
);
154 DATETIME_SetSystemTime (DATETIME_INFO
*infoPtr
, DWORD flag
, SYSTEMTIME
*lprgSysTimeArray
)
156 if (!lprgSysTimeArray
) return 0;
158 TRACE("%04d/%02d/%02d %02d:%02d:%02d\n",
159 lprgSysTimeArray
->wYear
, lprgSysTimeArray
->wMonth
, lprgSysTimeArray
->wDay
,
160 lprgSysTimeArray
->wHour
, lprgSysTimeArray
->wMinute
, lprgSysTimeArray
->wSecond
);
162 if (flag
== GDT_VALID
) {
163 infoPtr
->dateValid
= TRUE
;
164 MONTHCAL_CopyTime (lprgSysTimeArray
, &infoPtr
->date
);
165 SendMessageW (infoPtr
->hMonthCal
, MCM_SETCURSEL
, 0, (LPARAM
)(&infoPtr
->date
));
166 SendMessageW (infoPtr
->hwndCheckbut
, BM_SETCHECK
, BST_CHECKED
, 0);
167 } else if (flag
== GDT_NONE
) {
168 infoPtr
->dateValid
= FALSE
;
169 SendMessageW (infoPtr
->hwndCheckbut
, BM_SETCHECK
, BST_UNCHECKED
, 0);
172 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
178 * Split up a formattxt in actions.
179 * See ms documentation for the meaning of the letter codes/'specifiers'.
182 * *'dddddd' is handled as 'dddd' plus 'dd'.
183 * *unrecognized formats are strings (here given the type DT_STRING;
184 * start of the string is encoded in lower bits of DT_STRING.
185 * Therefore, 'string' ends finally up as '<show seconds>tring'.
189 DATETIME_UseFormat (DATETIME_INFO
*infoPtr
, LPCWSTR formattxt
)
193 int *nrFields
= &infoPtr
->nrFields
;
196 infoPtr
->fieldspec
[*nrFields
] = 0;
197 len
= strlenW(allowedformatchars
);
200 for (i
= 0; formattxt
[i
]; i
++) {
201 TRACE ("\n%d %c:", i
, formattxt
[i
]);
202 for (j
= 0; j
< len
; j
++) {
203 if (allowedformatchars
[j
]==formattxt
[i
]) {
204 TRACE ("%c[%d,%x]", allowedformatchars
[j
], *nrFields
, infoPtr
->fieldspec
[*nrFields
]);
205 if ((*nrFields
==0) && (infoPtr
->fieldspec
[*nrFields
]==0)) {
206 infoPtr
->fieldspec
[*nrFields
] = (j
<<4) + 1;
209 if (infoPtr
->fieldspec
[*nrFields
] >> 4 != j
) {
211 infoPtr
->fieldspec
[*nrFields
] = (j
<<4) + 1;
214 if ((infoPtr
->fieldspec
[*nrFields
] & 0x0f) == maxrepetition
[j
]) {
216 infoPtr
->fieldspec
[*nrFields
] = (j
<<4) + 1;
219 infoPtr
->fieldspec
[*nrFields
]++;
221 } /* if allowedformatchar */
224 /* char is not a specifier: handle char like a string */
226 if ((*nrFields
==0) && (infoPtr
->fieldspec
[*nrFields
]==0)) {
227 infoPtr
->fieldspec
[*nrFields
] = DT_STRING
+ k
;
228 infoPtr
->buflen
[*nrFields
] = 0;
229 } else if ((infoPtr
->fieldspec
[*nrFields
] & DT_STRING
) != DT_STRING
) {
231 infoPtr
->fieldspec
[*nrFields
] = DT_STRING
+ k
;
232 infoPtr
->buflen
[*nrFields
] = 0;
234 infoPtr
->textbuf
[k
] = formattxt
[i
];
236 infoPtr
->buflen
[*nrFields
]++;
239 if (*nrFields
== infoPtr
->nrFieldsAllocated
) {
240 FIXME ("out of memory; should reallocate. crash ahead.\n");
246 if (infoPtr
->fieldspec
[*nrFields
] != 0) (*nrFields
)++;
251 DATETIME_SetFormatW (DATETIME_INFO
*infoPtr
, LPCWSTR lpszFormat
)
254 WCHAR format_buf
[80];
257 if (infoPtr
->dwStyle
& DTS_LONGDATEFORMAT
)
258 format_item
= LOCALE_SLONGDATE
;
259 else if (infoPtr
->dwStyle
& DTS_TIMEFORMAT
)
260 format_item
= LOCALE_STIMEFORMAT
;
261 else /* DTS_SHORTDATEFORMAT */
262 format_item
= LOCALE_SSHORTDATE
;
263 GetLocaleInfoW( GetSystemDefaultLCID(), format_item
, format_buf
, sizeof(format_buf
)/sizeof(format_buf
[0]));
264 lpszFormat
= format_buf
;
267 DATETIME_UseFormat (infoPtr
, lpszFormat
);
269 return infoPtr
->nrFields
;
274 DATETIME_SetFormatA (DATETIME_INFO
*infoPtr
, LPCSTR lpszFormat
)
278 INT len
= MultiByteToWideChar(CP_ACP
, 0, lpszFormat
, -1, NULL
, 0);
279 LPWSTR wstr
= Alloc(len
* sizeof(WCHAR
));
280 if (wstr
) MultiByteToWideChar(CP_ACP
, 0, lpszFormat
, -1, wstr
, len
);
281 retval
= DATETIME_SetFormatW (infoPtr
, wstr
);
286 return DATETIME_SetFormatW (infoPtr
, 0);
292 DATETIME_ReturnTxt (DATETIME_INFO
*infoPtr
, int count
, LPWSTR result
, int resultSize
)
294 static const WCHAR fmt_dW
[] = { '%', 'd', 0 };
295 static const WCHAR fmt__2dW
[] = { '%', '.', '2', 'd', 0 };
296 static const WCHAR fmt__3sW
[] = { '%', '.', '3', 's', 0 };
297 SYSTEMTIME date
= infoPtr
->date
;
302 TRACE ("%d,%d\n", infoPtr
->nrFields
, count
);
303 if (count
>infoPtr
->nrFields
|| count
< 0) {
304 WARN ("buffer overrun, have %d want %d\n", infoPtr
->nrFields
, count
);
308 if (!infoPtr
->fieldspec
) return;
310 spec
= infoPtr
->fieldspec
[count
];
311 if (spec
& DT_STRING
) {
312 int txtlen
= infoPtr
->buflen
[count
];
314 if (txtlen
> resultSize
)
315 txtlen
= resultSize
- 1;
316 memcpy (result
, infoPtr
->textbuf
+ (spec
&~ DT_STRING
), txtlen
* sizeof(WCHAR
));
318 TRACE ("arg%d=%x->[%s]\n", count
, infoPtr
->fieldspec
[count
], debugstr_w(result
));
328 wsprintfW (result
, fmt_dW
, date
.wDay
);
331 wsprintfW (result
, fmt__2dW
, date
.wDay
);
334 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SABBREVDAYNAME1
+(date
.wDayOfWeek
+6)%7, result
, 4);
335 /*wsprintfW (result,"%.3s",days[date.wDayOfWeek]);*/
338 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SDAYNAME1
+(date
.wDayOfWeek
+6)%7, result
, resultSize
);
341 wsprintfW (result
, fmt_dW
, date
.wHour
- (date
.wHour
> 12 ? 12 : 0));
344 wsprintfW (result
, fmt__2dW
, date
.wHour
- (date
.wHour
> 12 ? 12 : 0));
347 wsprintfW (result
, fmt_dW
, date
.wHour
);
350 wsprintfW (result
, fmt__2dW
, date
.wHour
);
353 wsprintfW (result
, fmt_dW
, date
.wSecond
);
356 wsprintfW (result
, fmt__2dW
, date
.wSecond
);
359 wsprintfW (result
, fmt_dW
, date
.wMinute
);
362 wsprintfW (result
, fmt__2dW
, date
.wMinute
);
365 wsprintfW (result
, fmt_dW
, date
.wMonth
);
368 wsprintfW (result
, fmt__2dW
, date
.wMonth
);
371 GetLocaleInfoW(GetSystemDefaultLCID(), LOCALE_SMONTHNAME1
+date
.wMonth
-1,
372 buffer
, sizeof(buffer
)/sizeof(buffer
[0]));
373 wsprintfW (result
, fmt__3sW
, buffer
);
376 GetLocaleInfoW(GetSystemDefaultLCID(),LOCALE_SMONTHNAME1
+date
.wMonth
-1,
380 result
[0] = (date
.wHour
< 12 ? 'A' : 'P');
384 result
[0] = (date
.wHour
< 12 ? 'A' : 'P');
389 FIXME ("Not implemented\n");
394 wsprintfW (result
, fmt_dW
, date
.wYear
-10* (int) floor(date
.wYear
/10));
397 wsprintfW (result
, fmt__2dW
, date
.wYear
-100* (int) floor(date
.wYear
/100));
399 case INVALIDFULLYEAR
:
401 wsprintfW (result
, fmt_dW
, date
.wYear
);
405 TRACE ("arg%d=%x->[%s]\n", count
, infoPtr
->fieldspec
[count
], debugstr_w(result
));
408 static int wrap(int val
, int delta
, int minVal
, int maxVal
)
411 if (delta
== INT_MIN
|| val
< minVal
) return maxVal
;
412 if (delta
== INT_MAX
|| val
> maxVal
) return minVal
;
417 DATETIME_IncreaseField (DATETIME_INFO
*infoPtr
, int number
, int delta
)
419 SYSTEMTIME
*date
= &infoPtr
->date
;
421 TRACE ("%d\n", number
);
422 if ((number
> infoPtr
->nrFields
) || (number
< 0)) return;
424 if ((infoPtr
->fieldspec
[number
] & DTHT_DATEFIELD
) == 0) return;
426 switch (infoPtr
->fieldspec
[number
]) {
430 date
->wYear
= wrap(date
->wYear
, delta
, 1752, 9999);
436 date
->wMonth
= wrap(date
->wMonth
, delta
, 1, 12);
443 date
->wDay
= wrap(date
->wDay
, delta
, 1, MONTHCAL_MonthLength(date
->wMonth
, date
->wYear
));
453 date
->wHour
= wrap(date
->wHour
, delta
, 0, 23);
457 date
->wMinute
= wrap(date
->wMinute
, delta
, 0, 59);
461 date
->wSecond
= wrap(date
->wSecond
, delta
, 0, 59);
464 FIXME ("Not implemented\n");
468 /* FYI: On 1752/9/14 the calendar changed and England and the
469 * American colonies changed to the Gregorian calendar. This change
470 * involved having September 14th follow September 2nd. So no date
471 * algorithm works before that date.
473 if (10000 * date
->wYear
+ 100 * date
->wMonth
+ date
->wDay
< 17520914) {
485 DATETIME_Refresh (DATETIME_INFO
*infoPtr
, HDC hdc
)
489 RECT
*rcDraw
= &infoPtr
->rcDraw
;
490 RECT
*rcClient
= &infoPtr
->rcClient
;
491 RECT
*calbutton
= &infoPtr
->calbutton
;
492 RECT
*checkbox
= &infoPtr
->checkbox
;
495 COLORREF oldBk
, oldTextColor
;
497 /* draw control edge */
499 hbr
= CreateSolidBrush(RGB(255, 255, 255));
500 FillRect(hdc
, rcClient
, hbr
);
501 DrawEdge(hdc
, rcClient
, EDGE_SUNKEN
, BF_RECT
);
504 if (infoPtr
->dateValid
) {
505 HFONT oldFont
= SelectObject (hdc
, infoPtr
->hFont
);
508 DATETIME_ReturnTxt (infoPtr
, 0, txt
, sizeof(txt
)/sizeof(txt
[0]));
509 GetTextExtentPoint32W (hdc
, txt
, strlenW(txt
), &size
);
510 rcDraw
->bottom
= size
.cy
+ 2;
512 prevright
= checkbox
->right
= ((infoPtr
->dwStyle
& DTS_SHOWNONE
) ? 18 : 2);
514 for (i
= 0; i
< infoPtr
->nrFields
; i
++) {
515 DATETIME_ReturnTxt (infoPtr
, i
, txt
, sizeof(txt
)/sizeof(txt
[0]));
516 GetTextExtentPoint32W (hdc
, txt
, strlenW(txt
), &size
);
517 field
= &infoPtr
->fieldRect
[i
];
518 field
->left
= prevright
;
519 field
->right
= prevright
+size
.cx
;
520 field
->top
= rcDraw
->top
;
521 field
->bottom
= rcDraw
->bottom
;
522 prevright
= field
->right
;
524 if ((infoPtr
->haveFocus
) && (i
== infoPtr
->select
)) {
525 hbr
= CreateSolidBrush (GetSysColor (COLOR_ACTIVECAPTION
));
526 FillRect(hdc
, field
, hbr
);
527 oldBk
= SetBkColor (hdc
, GetSysColor(COLOR_ACTIVECAPTION
));
528 oldTextColor
= SetTextColor (hdc
, GetSysColor(COLOR_WINDOW
));
530 DrawTextW (hdc
, txt
, strlenW(txt
), field
, DT_RIGHT
| DT_VCENTER
| DT_SINGLELINE
);
531 SetBkColor (hdc
, oldBk
);
532 SetTextColor (hdc
, oldTextColor
);
534 DrawTextW ( hdc
, txt
, strlenW(txt
), field
, DT_RIGHT
| DT_VCENTER
| DT_SINGLELINE
);
536 SelectObject (hdc
, oldFont
);
539 if (!(infoPtr
->dwStyle
& DTS_UPDOWN
)) {
540 DrawFrameControl(hdc
, calbutton
, DFC_SCROLL
,
541 DFCS_SCROLLDOWN
| (infoPtr
->bCalDepressed
? DFCS_PUSHED
: 0) |
542 (infoPtr
->dwStyle
& WS_DISABLED
? DFCS_INACTIVE
: 0) );
548 DATETIME_HitTest (DATETIME_INFO
*infoPtr
, POINT pt
)
552 TRACE ("%ld, %ld\n", pt
.x
, pt
.y
);
554 if (PtInRect (&infoPtr
->calbutton
, pt
)) return DTHT_MCPOPUP
;
555 if (PtInRect (&infoPtr
->checkbox
, pt
)) return DTHT_CHECKBOX
;
557 for (i
=0; i
< infoPtr
->nrFields
; i
++) {
558 if (PtInRect (&infoPtr
->fieldRect
[i
], pt
)) return i
;
566 DATETIME_LButtonDown (DATETIME_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
573 old
= infoPtr
->select
;
574 new = DATETIME_HitTest (infoPtr
, pt
);
576 /* FIXME: might be conditions where we don't want to update infoPtr->select */
577 infoPtr
->select
= new;
579 if (infoPtr
->select
!= old
)
580 infoPtr
->haveFocus
= DTHT_GOTFOCUS
;
582 if (infoPtr
->select
== DTHT_MCPOPUP
) {
583 /* FIXME: button actually is only depressed during dropdown of the */
584 /* calendar control and when the mouse is over the button window */
585 infoPtr
->bCalDepressed
= TRUE
;
587 /* recalculate the position of the monthcal popup */
588 if(infoPtr
->dwStyle
& DTS_RIGHTALIGN
)
589 infoPtr
->monthcal_pos
.x
= infoPtr
->rcClient
.right
-
590 ((infoPtr
->calbutton
.right
- infoPtr
->calbutton
.left
) + 200);
592 infoPtr
->monthcal_pos
.x
= 8;
594 infoPtr
->monthcal_pos
.y
= infoPtr
->rcClient
.bottom
;
595 ClientToScreen (infoPtr
->hwndSelf
, &(infoPtr
->monthcal_pos
));
596 /* FIXME My Windoze has cx=about 200, but it probably depends on font size etc */
597 SetWindowPos(infoPtr
->hMonthCal
, 0, infoPtr
->monthcal_pos
.x
, infoPtr
->monthcal_pos
.y
, 200, 150, 0);
599 if(IsWindowVisible(infoPtr
->hMonthCal
)) {
600 ShowWindow(infoPtr
->hMonthCal
, SW_HIDE
);
602 SYSTEMTIME
*lprgSysTimeArray
= &infoPtr
->date
;
603 TRACE("update calendar %04d/%02d/%02d\n",
604 lprgSysTimeArray
->wYear
, lprgSysTimeArray
->wMonth
, lprgSysTimeArray
->wDay
);
605 SendMessageW(infoPtr
->hMonthCal
, MCM_SETCURSEL
, 0, (LPARAM
)(&infoPtr
->date
));
606 ShowWindow(infoPtr
->hMonthCal
, SW_SHOW
);
609 TRACE ("dt:%p mc:%p mc parent:%p, desktop:%p\n",
610 infoPtr
->hwndSelf
, infoPtr
->hMonthCal
, infoPtr
->hwndNotify
, GetDesktopWindow ());
611 DATETIME_SendSimpleNotify (infoPtr
, DTN_DROPDOWN
);
614 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
621 DATETIME_LButtonUp (DATETIME_INFO
*infoPtr
, WORD wKey
)
623 if(infoPtr
->bCalDepressed
== TRUE
) {
624 infoPtr
->bCalDepressed
= FALSE
;
625 InvalidateRect(infoPtr
->hwndSelf
, &(infoPtr
->calbutton
), TRUE
);
633 DATETIME_Paint (DATETIME_INFO
*infoPtr
, HDC hdc
)
637 hdc
= BeginPaint (infoPtr
->hwndSelf
, &ps
);
638 DATETIME_Refresh (infoPtr
, hdc
);
639 EndPaint (infoPtr
->hwndSelf
, &ps
);
641 DATETIME_Refresh (infoPtr
, hdc
);
648 DATETIME_Button_Command (DATETIME_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
650 if( HIWORD(wParam
) == BN_CLICKED
) {
651 DWORD state
= SendMessageW((HWND
)lParam
, BM_GETCHECK
, 0, 0);
652 infoPtr
->dateValid
= (state
== BST_CHECKED
);
653 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
661 DATETIME_Command (DATETIME_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
663 TRACE("hwndbutton = %p\n", infoPtr
->hwndCheckbut
);
664 if(infoPtr
->hwndCheckbut
== (HWND
)lParam
)
665 return DATETIME_Button_Command(infoPtr
, wParam
, lParam
);
671 DATETIME_Notify (DATETIME_INFO
*infoPtr
, int idCtrl
, LPNMHDR lpnmh
)
673 TRACE ("Got notification %x from %p\n", lpnmh
->code
, lpnmh
->hwndFrom
);
674 TRACE ("info: %p %p %p\n", infoPtr
->hwndSelf
, infoPtr
->hMonthCal
, infoPtr
->hUpdown
);
676 if (lpnmh
->code
== MCN_SELECT
) {
677 ShowWindow(infoPtr
->hMonthCal
, SW_HIDE
);
678 infoPtr
->dateValid
= TRUE
;
679 SendMessageW (infoPtr
->hMonthCal
, MCM_GETCURSEL
, 0, (LPARAM
)&infoPtr
->date
);
680 TRACE("got from calendar %04d/%02d/%02d\n",
681 infoPtr
->date
.wYear
, infoPtr
->date
.wMonth
, infoPtr
->date
.wDay
);
682 SendMessageW (infoPtr
->hwndCheckbut
, BM_SETCHECK
, BST_CHECKED
, 0);
683 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
684 DATETIME_SendDateTimeChangeNotify (infoPtr
);
691 DATETIME_KeyDown (DATETIME_INFO
*infoPtr
, DWORD vkCode
, LPARAM flags
)
693 int fieldNum
= infoPtr
->select
& DTHT_DATEFIELD
;
696 if (!(infoPtr
->haveFocus
)) return 0;
697 if ((fieldNum
==0) && (infoPtr
->select
)) return 0;
699 if (infoPtr
->select
& FORMATCALLMASK
) {
700 FIXME ("Callbacks not implemented yet\n");
706 DATETIME_IncreaseField (infoPtr
, fieldNum
, 1);
707 DATETIME_SendDateTimeChangeNotify (infoPtr
);
711 DATETIME_IncreaseField (infoPtr
, fieldNum
, -1);
712 DATETIME_SendDateTimeChangeNotify (infoPtr
);
715 DATETIME_IncreaseField (infoPtr
, fieldNum
, INT_MIN
);
716 DATETIME_SendDateTimeChangeNotify (infoPtr
);
719 DATETIME_IncreaseField (infoPtr
, fieldNum
, INT_MAX
);
720 DATETIME_SendDateTimeChangeNotify (infoPtr
);
724 if (infoPtr
->select
== 0) {
725 infoPtr
->select
= infoPtr
->nrFields
- 1;
730 } while ((infoPtr
->fieldspec
[infoPtr
->select
] & DT_STRING
) && (wrap
<2));
735 if (infoPtr
->select
==infoPtr
->nrFields
) {
739 } while ((infoPtr
->fieldspec
[infoPtr
->select
] & DT_STRING
) && (wrap
<2));
743 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
750 DATETIME_KillFocus (DATETIME_INFO
*infoPtr
, HWND lostFocus
)
752 if (infoPtr
->haveFocus
) {
753 DATETIME_SendSimpleNotify (infoPtr
, NM_KILLFOCUS
);
754 infoPtr
->haveFocus
= 0;
757 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
764 DATETIME_SetFocus (DATETIME_INFO
*infoPtr
, HWND lostFocus
)
766 if (infoPtr
->haveFocus
== 0) {
767 DATETIME_SendSimpleNotify (infoPtr
, NM_SETFOCUS
);
768 infoPtr
->haveFocus
= DTHT_GOTFOCUS
;
771 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
778 DATETIME_SendDateTimeChangeNotify (DATETIME_INFO
*infoPtr
)
780 NMDATETIMECHANGE dtdtc
;
782 dtdtc
.nmhdr
.hwndFrom
= infoPtr
->hwndSelf
;
783 dtdtc
.nmhdr
.idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
784 dtdtc
.nmhdr
.code
= DTN_DATETIMECHANGE
;
786 dtdtc
.dwFlags
= (infoPtr
->dwStyle
& DTS_SHOWNONE
) ? GDT_NONE
: GDT_VALID
;
788 MONTHCAL_CopyTime (&infoPtr
->date
, &dtdtc
.st
);
789 return (BOOL
) SendMessageW (infoPtr
->hwndNotify
, WM_NOTIFY
,
790 (WPARAM
)dtdtc
.nmhdr
.idFrom
, (LPARAM
)&dtdtc
);
795 DATETIME_SendSimpleNotify (DATETIME_INFO
*infoPtr
, UINT code
)
800 nmhdr
.hwndFrom
= infoPtr
->hwndSelf
;
801 nmhdr
.idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
804 return (BOOL
) SendMessageW (infoPtr
->hwndNotify
, WM_NOTIFY
,
805 (WPARAM
)nmhdr
.idFrom
, (LPARAM
)&nmhdr
);
809 DATETIME_Size (DATETIME_INFO
*infoPtr
, WORD flags
, INT width
, INT height
)
812 infoPtr
->rcClient
.bottom
= height
;
813 infoPtr
->rcClient
.right
= width
;
815 TRACE("Height=%ld, Width=%ld\n", infoPtr
->rcClient
.bottom
, infoPtr
->rcClient
.right
);
817 memcpy((&infoPtr
->rcDraw
), (&infoPtr
->rcClient
), sizeof(infoPtr
->rcDraw
));
819 /* subract the size of the edge drawn by DrawEdge */
820 InflateRect(&infoPtr
->rcDraw
, -GetSystemMetrics(SM_CXEDGE
),
821 -GetSystemMetrics(SM_CYEDGE
));
823 /* set the size of the button that drops the calendar down */
824 /* FIXME: account for style that allows button on left side */
825 infoPtr
->calbutton
.top
= infoPtr
->rcDraw
.top
;
826 infoPtr
->calbutton
.bottom
= infoPtr
->rcDraw
.bottom
;
827 infoPtr
->calbutton
.left
= infoPtr
->rcDraw
.right
-15;
828 infoPtr
->calbutton
.right
= infoPtr
->rcDraw
.right
;
830 /* set enable/disable button size for show none style being enabled */
831 /* FIXME: these dimensions are completely incorrect */
832 infoPtr
->checkbox
.top
= infoPtr
->rcDraw
.top
;
833 infoPtr
->checkbox
.bottom
= infoPtr
->rcDraw
.bottom
;
834 infoPtr
->checkbox
.left
= infoPtr
->rcDraw
.left
;
835 infoPtr
->checkbox
.right
= infoPtr
->rcDraw
.left
+ 10;
837 /* update the position of the monthcal control */
838 if(infoPtr
->dwStyle
& DTS_RIGHTALIGN
)
839 infoPtr
->monthcal_pos
.x
= infoPtr
->rcClient
.right
- ((infoPtr
->calbutton
.right
-
840 infoPtr
->calbutton
.left
) + 145);
842 infoPtr
->monthcal_pos
.x
= 8;
844 infoPtr
->monthcal_pos
.y
= infoPtr
->rcClient
.bottom
;
845 ClientToScreen (infoPtr
->hwndSelf
, &(infoPtr
->monthcal_pos
));
846 SetWindowPos(infoPtr
->hMonthCal
, 0, infoPtr
->monthcal_pos
.x
, infoPtr
->monthcal_pos
.y
, 145, 150, 0);
848 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
855 DATETIME_StyleChanged(DATETIME_INFO
*infoPtr
, WPARAM wStyleType
, LPSTYLESTRUCT lpss
)
857 static const WCHAR buttonW
[] = { 'b', 'u', 't', 't', 'o', 'n', 0 };
859 TRACE("(styletype=%x, styleOld=0x%08lx, styleNew=0x%08lx)\n",
860 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
862 if (wStyleType
!= GWL_STYLE
) return 0;
864 infoPtr
->dwStyle
= lpss
->styleNew
;
866 if ( !(lpss
->styleOld
& DTS_SHOWNONE
) && (lpss
->styleNew
& DTS_SHOWNONE
) ) {
867 infoPtr
->hwndCheckbut
= CreateWindowExW (0, buttonW
, 0, WS_CHILD
| WS_VISIBLE
| BS_AUTOCHECKBOX
,
868 2, 2, 13, 13, infoPtr
->hwndSelf
, 0,
869 (HINSTANCE
)GetWindowLongPtrW (infoPtr
->hwndSelf
, GWLP_HINSTANCE
), 0);
870 SendMessageW (infoPtr
->hwndCheckbut
, BM_SETCHECK
, 1, 0);
872 if ( (lpss
->styleOld
& DTS_SHOWNONE
) && !(lpss
->styleNew
& DTS_SHOWNONE
) ) {
873 DestroyWindow(infoPtr
->hwndCheckbut
);
874 infoPtr
->hwndCheckbut
= 0;
876 if ( !(lpss
->styleOld
& DTS_UPDOWN
) && (lpss
->styleNew
& DTS_UPDOWN
) ) {
877 infoPtr
->hUpdown
= CreateUpDownControl (WS_CHILD
| WS_BORDER
| WS_VISIBLE
, 120, 1, 20, 20,
878 infoPtr
->hwndSelf
, 1, 0, 0, UD_MAXVAL
, UD_MINVAL
, 0);
880 if ( (lpss
->styleOld
& DTS_UPDOWN
) && !(lpss
->styleNew
& DTS_UPDOWN
) ) {
881 DestroyWindow(infoPtr
->hUpdown
);
882 infoPtr
->hUpdown
= 0;
885 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
891 DATETIME_Create (HWND hwnd
, LPCREATESTRUCTW lpcs
)
893 static const WCHAR SysMonthCal32W
[] = { 'S', 'y', 's', 'M', 'o', 'n', 't', 'h', 'C', 'a', 'l', '3', '2', 0 };
894 DATETIME_INFO
*infoPtr
= (DATETIME_INFO
*)Alloc (sizeof(DATETIME_INFO
));
895 STYLESTRUCT ss
= { 0, lpcs
->style
};
897 if (!infoPtr
) return -1;
899 infoPtr
->hwndSelf
= hwnd
;
900 infoPtr
->dwStyle
= lpcs
->style
;
902 infoPtr
->nrFieldsAllocated
= 32;
903 infoPtr
->fieldspec
= (int *) Alloc (infoPtr
->nrFieldsAllocated
* sizeof(int));
904 infoPtr
->fieldRect
= (RECT
*) Alloc (infoPtr
->nrFieldsAllocated
* sizeof(RECT
));
905 infoPtr
->buflen
= (int *) Alloc (infoPtr
->nrFieldsAllocated
* sizeof(int));
906 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
908 DATETIME_StyleChanged(infoPtr
, GWL_STYLE
, &ss
);
909 DATETIME_SetFormatW (infoPtr
, 0);
911 /* create the monthcal control */
912 infoPtr
->hMonthCal
= CreateWindowExW (0, SysMonthCal32W
, 0, WS_BORDER
| WS_POPUP
| WS_CLIPSIBLINGS
,
913 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, 0, 0);
915 /* initialize info structure */
916 GetSystemTime (&infoPtr
->date
);
917 infoPtr
->dateValid
= TRUE
;
918 infoPtr
->hFont
= GetStockObject(DEFAULT_GUI_FONT
);
920 SetWindowLongPtrW (hwnd
, 0, (DWORD_PTR
)infoPtr
);
928 DATETIME_Destroy (DATETIME_INFO
*infoPtr
)
930 if (infoPtr
->hwndCheckbut
)
931 DestroyWindow(infoPtr
->hwndCheckbut
);
932 if (infoPtr
->hUpdown
)
933 DestroyWindow(infoPtr
->hUpdown
);
934 if (infoPtr
->hMonthCal
)
935 DestroyWindow(infoPtr
->hMonthCal
);
936 SetWindowLongPtrW( infoPtr
->hwndSelf
, 0, 0 ); /* clear infoPtr */
942 static LRESULT WINAPI
943 DATETIME_WindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
945 DATETIME_INFO
*infoPtr
= ((DATETIME_INFO
*)GetWindowLongPtrW (hwnd
, 0));
948 TRACE ("%x, %x, %lx\n", uMsg
, wParam
, lParam
);
950 if (!infoPtr
&& (uMsg
!= WM_CREATE
))
951 return DefWindowProcW( hwnd
, uMsg
, wParam
, lParam
);
955 case DTM_GETSYSTEMTIME
:
956 return DATETIME_GetSystemTime (infoPtr
, (SYSTEMTIME
*) lParam
);
958 case DTM_SETSYSTEMTIME
:
959 return DATETIME_SetSystemTime (infoPtr
, wParam
, (SYSTEMTIME
*) lParam
);
962 ret
= SendMessageW (infoPtr
->hMonthCal
, MCM_GETRANGE
, wParam
, lParam
);
963 return ret
? ret
: 1; /* bug emulation */
966 return SendMessageW (infoPtr
->hMonthCal
, MCM_SETRANGE
, wParam
, lParam
);
969 return DATETIME_SetFormatA (infoPtr
, (LPCSTR
)lParam
);
972 return DATETIME_SetFormatW (infoPtr
, (LPCWSTR
)lParam
);
974 case DTM_GETMONTHCAL
:
975 return (LRESULT
)infoPtr
->hMonthCal
;
978 return SendMessageW (infoPtr
->hMonthCal
, MCM_SETCOLOR
, wParam
, lParam
);
981 return SendMessageW (infoPtr
->hMonthCal
, MCM_GETCOLOR
, wParam
, 0);
984 return SendMessageW (infoPtr
->hMonthCal
, WM_SETFONT
, wParam
, lParam
);
987 return SendMessageW (infoPtr
->hMonthCal
, WM_GETFONT
, wParam
, lParam
);
990 return DATETIME_Notify (infoPtr
, (int)wParam
, (LPNMHDR
)lParam
);
993 return DLGC_WANTARROWS
| DLGC_WANTCHARS
;
996 return DATETIME_Paint (infoPtr
, (HDC
)wParam
);
999 return DATETIME_KeyDown (infoPtr
, wParam
, lParam
);
1002 return DATETIME_KillFocus (infoPtr
, (HWND
)wParam
);
1005 return DATETIME_SetFocus (infoPtr
, (HWND
)wParam
);
1008 return DATETIME_Size (infoPtr
, wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
1010 case WM_LBUTTONDOWN
:
1011 return DATETIME_LButtonDown (infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
1014 return DATETIME_LButtonUp (infoPtr
, (WORD
)wParam
);
1017 return DATETIME_Create (hwnd
, (LPCREATESTRUCTW
)lParam
);
1020 return DATETIME_Destroy (infoPtr
);
1023 return DATETIME_Command (infoPtr
, wParam
, lParam
);
1025 case WM_STYLECHANGED
:
1026 return DATETIME_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
1029 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
))
1030 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
1031 uMsg
, wParam
, lParam
);
1032 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
1039 DATETIME_Register (void)
1043 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
1044 wndClass
.style
= CS_GLOBALCLASS
;
1045 wndClass
.lpfnWndProc
= DATETIME_WindowProc
;
1046 wndClass
.cbClsExtra
= 0;
1047 wndClass
.cbWndExtra
= sizeof(DATETIME_INFO
*);
1048 wndClass
.hCursor
= LoadCursorW (0, (LPCWSTR
)IDC_ARROW
);
1049 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
1050 wndClass
.lpszClassName
= DATETIMEPICK_CLASSW
;
1052 RegisterClassW (&wndClass
);
1057 DATETIME_Unregister (void)
1059 UnregisterClassW (DATETIMEPICK_CLASSW
, NULL
);