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 * - All notifications.
40 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(datetime);
52 RECT rcClient; /* rect around the edge of the window */
53 RECT rcDraw; /* rect inside of the border */
54 RECT checkbox; /* checkbox allowing the control to be enabled/disabled */
55 RECT calbutton; /* button that toggles the dropdown of the monthcal control */
56 BOOL bCalDepressed; /* TRUE = cal button is depressed */
59 int nrFieldsAllocated;
67 } DATETIME_INFO, *LPDATETIME_INFO;
70 extern int MONTHCAL_MonthLength(int month, int year);
72 /* this list of defines is closely related to `allowedformatchars' defined
73 * in datetime.c; the high nibble indicates the `base type' of the format
75 * Do not change without first reading DATETIME_UseFormat.
79 #define DT_END_FORMAT 0
80 #define ONEDIGITDAY 0x01
81 #define TWODIGITDAY 0x02
82 #define THREECHARDAY 0x03
84 #define ONEDIGIT12HOUR 0x11
85 #define TWODIGIT12HOUR 0x12
86 #define ONEDIGIT24HOUR 0x21
87 #define TWODIGIT24HOUR 0x22
88 #define ONEDIGITMINUTE 0x31
89 #define TWODIGITMINUTE 0x32
90 #define ONEDIGITMONTH 0x41
91 #define TWODIGITMONTH 0x42
92 #define THREECHARMONTH 0x43
93 #define FULLMONTH 0x44
94 #define ONEDIGITSECOND 0x51
95 #define TWODIGITSECOND 0x52
96 #define ONELETTERAMPM 0x61
97 #define TWOLETTERAMPM 0x62
98 #define ONEDIGITYEAR 0x71
99 #define TWODIGITYEAR 0x72
100 #define INVALIDFULLYEAR 0x73 /* FIXME - yyy is not valid - we'll treat it as yyyy */
101 #define FULLYEAR 0x74
102 #define FORMATCALLBACK 0x81 /* -> maximum of 0x80 callbacks possible */
103 #define FORMATCALLMASK 0x80
104 #define DT_STRING 0x0100
106 #define DTHT_DATEFIELD 0xff /* for hit-testing */
109 #define DTHT_CHECKBOX 0x200 /* these should end at '00' , to make */
110 #define DTHT_MCPOPUP 0x300 /* & DTHT_DATEFIELD 0 when DATETIME_KeyDown */
111 #define DTHT_GOTFOCUS 0x400 /* tests for date-fields */
113 #define DATETIME_GetInfoPtr(hwnd) ((DATETIME_INFO *)GetWindowLongPtrW (hwnd, 0))
115 static BOOL DATETIME_SendSimpleNotify (HWND hwnd, UINT code);
116 static BOOL DATETIME_SendDateTimeChangeNotify (HWND hwnd);
117 extern void MONTHCAL_CopyTime(const SYSTEMTIME *from, SYSTEMTIME *to);
118 static const char *allowedformatchars = {"dhHmMstyX'"};
119 static const int maxrepetition [] = {4,2,2,2,4,2,2,4,-1,-1};
123 DATETIME_GetSystemTime (HWND hwnd, WPARAM wParam, LPARAM lParam )
125 DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr (hwnd);
126 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
127 SYSTEMTIME *lprgSysTimeArray=(SYSTEMTIME *) lParam;
129 TRACE("%04x %08lx\n",wParam,lParam);
130 if (!lParam) return GDT_NONE;
132 if ((dwStyle & DTS_SHOWNONE) &&
133 (SendMessageA (infoPtr->hwndCheckbut, BM_GETCHECK, 0, 0) == BST_UNCHECKED))
136 MONTHCAL_CopyTime (&infoPtr->date, lprgSysTimeArray);
143 DATETIME_SetSystemTime (HWND hwnd, WPARAM wParam, LPARAM lParam )
145 DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr (hwnd);
146 SYSTEMTIME *lprgSysTimeArray=(SYSTEMTIME *) lParam;
148 TRACE("%p %04x %08lx\n",hwnd, wParam, lParam);
149 if (!lParam) return 0;
151 TRACE("%04d/%02d/%02d %02d:%02d:%02d\n",
152 lprgSysTimeArray->wYear, lprgSysTimeArray->wMonth, lprgSysTimeArray->wDay,
153 lprgSysTimeArray->wHour, lprgSysTimeArray->wMinute, lprgSysTimeArray->wSecond);
155 if (wParam==GDT_VALID) {
156 infoPtr->dateValid = TRUE;
157 MONTHCAL_CopyTime (lprgSysTimeArray, &infoPtr->date);
158 SendMessageA(infoPtr->hMonthCal, MCM_SETCURSEL, 0, (LPARAM)(&infoPtr->date));
159 SendMessageA (infoPtr->hwndCheckbut, BM_SETCHECK, BST_CHECKED, 0);
160 } else if (wParam==GDT_NONE) {
161 infoPtr->dateValid = FALSE;
162 SendMessageA (infoPtr->hwndCheckbut, BM_SETCHECK, BST_UNCHECKED, 0);
164 InvalidateRect(hwnd, NULL, TRUE);
170 DATETIME_GetRange (HWND hwnd, LPARAM lParam )
172 DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr (hwnd);
175 TRACE("%08lx\n", lParam);
176 ret = SendMessageA (infoPtr->hMonthCal, MCM_GETRANGE, 0, lParam);
177 if (!ret) ret = 1; /* bug emulation... */
182 DATETIME_SetRange (HWND hwnd, WPARAM wParam, LPARAM lParam )
184 DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr (hwnd);
186 TRACE("%04x %08lx\n",wParam,lParam);
188 return SendMessageA (infoPtr->hMonthCal, MCM_SETRANGE, wParam, lParam);
192 DATETIME_GetMonthCalColor (HWND hwnd, WPARAM wParam)
194 DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr (hwnd);
196 TRACE("%04x\n",wParam);
197 return SendMessageA (infoPtr->hMonthCal, MCM_GETCOLOR, wParam, 0);
202 DATETIME_SetMonthCalColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
204 DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr (hwnd);
206 TRACE("%04x %08lx\n",wParam,lParam);
207 return SendMessageA (infoPtr->hMonthCal, MCM_SETCOLOR, wParam, lParam);
211 /* FIXME: need to get way to force font into monthcal structure */
213 DATETIME_GetMonthCal (HWND hwnd)
215 DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr (hwnd);
218 return (LRESULT)infoPtr->hMonthCal;
223 /* FIXME: need to get way to force font into monthcal structure */
226 DATETIME_GetMonthCalFont (HWND hwnd)
235 DATETIME_SetMonthCalFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
238 TRACE("%04x %08lx\n",wParam,lParam);
244 Split up a formattxt in actions.
245 See ms documentation for the meaning of the letter codes/'specifiers'.
248 *'dddddd' is handled as 'dddd' plus 'dd'.
249 *unrecognized formats are strings (here given the type DT_STRING;
250 start of the string is encoded in lower bits of DT_STRING.
251 Therefore, 'string' ends finally up as '<show seconds>tring'.
257 DATETIME_UseFormat (DATETIME_INFO *infoPtr, const char *formattxt)
261 int *nrFields=& infoPtr->nrFields;
263 TRACE ("%s\n",formattxt);
267 infoPtr->fieldspec[*nrFields]=0;
268 len=strlen(allowedformatchars);
271 for (i=0; formattxt[i]; i++) {
272 TRACE ("\n%d %c:",i, formattxt[i]);
273 for (j=0; j<len; j++) {
274 if (allowedformatchars[j]==formattxt[i]) {
275 TRACE ("%c[%d,%x]",allowedformatchars[j], *nrFields,
276 infoPtr->fieldspec[*nrFields]);
277 if ((*nrFields==0) && (infoPtr->fieldspec[*nrFields]==0)) {
278 infoPtr->fieldspec[*nrFields]=(j<<4) +1;
281 if (infoPtr->fieldspec[*nrFields]>>4!=j) {
283 infoPtr->fieldspec[*nrFields]=(j<<4) +1;
286 if ((infoPtr->fieldspec[*nrFields] & 0x0f)==maxrepetition[j]) {
288 infoPtr->fieldspec[*nrFields]=(j<<4) +1;
291 infoPtr->fieldspec[*nrFields]++;
293 } /* if allowedformatchar */
297 /* char is not a specifier: handle char like a string */
299 if ((*nrFields==0) && (infoPtr->fieldspec[*nrFields]==0)) {
300 infoPtr->fieldspec[*nrFields]=DT_STRING+k;
301 infoPtr->buflen[*nrFields]=0;
303 if ((infoPtr->fieldspec[*nrFields] & DT_STRING)!=DT_STRING) {
305 infoPtr->fieldspec[*nrFields]=DT_STRING+k;
306 infoPtr->buflen[*nrFields]=0;
308 infoPtr->textbuf[k]=formattxt[i];
310 infoPtr->buflen[*nrFields]++;
313 if (*nrFields==infoPtr->nrFieldsAllocated) {
314 FIXME ("out of memory; should reallocate. crash ahead.\n");
321 if (infoPtr->fieldspec[*nrFields]!=0) (*nrFields)++;
326 DATETIME_SetFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
328 DATETIME_INFO *infoPtr= DATETIME_GetInfoPtr (hwnd);
332 TRACE("%04x %08lx\n",wParam,lParam);
334 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
336 if (dwStyle & DTS_LONGDATEFORMAT)
337 format_item=LOCALE_SLONGDATE;
338 else if (dwStyle & DTS_TIMEFORMAT)
339 format_item=LOCALE_STIMEFORMAT;
340 else /* DTS_SHORTDATEFORMAT */
341 format_item=LOCALE_SSHORTDATE;
342 GetLocaleInfoA( GetSystemDefaultLCID(), format_item,format_buf,sizeof(format_buf));
343 DATETIME_UseFormat (infoPtr, format_buf);
346 DATETIME_UseFormat (infoPtr, (char *) lParam);
348 return infoPtr->nrFields;
353 DATETIME_SetFormatW (HWND hwnd, WPARAM wParam, LPARAM lParam)
356 TRACE("%04x %08lx\n",wParam,lParam);
360 int len = WideCharToMultiByte( CP_ACP, 0, (LPWSTR)lParam, -1, NULL, 0, NULL, NULL );
362 buf = (LPSTR) Alloc (len);
363 WideCharToMultiByte( CP_ACP, 0, (LPWSTR)lParam, -1, buf, len, NULL, NULL );
364 retval=DATETIME_SetFormat (hwnd, 0, (LPARAM) buf);
369 return DATETIME_SetFormat (hwnd, 0, 0);
375 DATETIME_ReturnTxt (DATETIME_INFO *infoPtr, int count, char *result, int resultSize)
377 SYSTEMTIME date = infoPtr->date;
382 TRACE ("%d,%d\n", infoPtr->nrFields, count);
383 if ((count>infoPtr->nrFields) || (count<0)) {
384 WARN ("buffer overrun, have %d want %d\n", infoPtr->nrFields, count);
388 if (!infoPtr->fieldspec) return;
390 spec=infoPtr->fieldspec[count];
391 if (spec & DT_STRING) {
392 int txtlen=infoPtr->buflen[count];
394 if (txtlen > resultSize)
395 txtlen = resultSize - 1;
396 memcpy (result, infoPtr->textbuf + (spec &~ DT_STRING), txtlen);
398 TRACE ("arg%d=%x->[%s]\n",count,infoPtr->fieldspec[count],result);
408 sprintf (result,"%d",date.wDay);
411 sprintf (result,"%.2d",date.wDay);
414 GetLocaleInfoA( LOCALE_USER_DEFAULT, LOCALE_SABBREVDAYNAME1+(date.wDayOfWeek+6)%7,
416 /*sprintf (result,"%.3s",days[date.wDayOfWeek]);*/
419 GetLocaleInfoA( LOCALE_USER_DEFAULT,LOCALE_SDAYNAME1+ (date.wDayOfWeek+6)%7,
424 sprintf (result,"%d",date.wHour-12);
426 sprintf (result,"%d",date.wHour);
430 sprintf (result,"%.2d",date.wHour-12);
432 sprintf (result,"%.2d",date.wHour);
435 sprintf (result,"%d",date.wHour);
438 sprintf (result,"%.2d",date.wHour);
441 sprintf (result,"%d",date.wSecond);
444 sprintf (result,"%.2d",date.wSecond);
447 sprintf (result,"%d",date.wMinute);
450 sprintf (result,"%.2d",date.wMinute);
453 sprintf (result,"%d",date.wMonth);
456 sprintf (result,"%.2d",date.wMonth);
459 GetLocaleInfoA( GetSystemDefaultLCID(),LOCALE_SMONTHNAME1+date.wMonth -1,
460 buffer,sizeof(buffer));
461 sprintf (result,"%.3s",buffer);
464 GetLocaleInfoA( GetSystemDefaultLCID(),LOCALE_SMONTHNAME1+date.wMonth -1,
475 strcpy (result,"AM");
477 strcpy (result,"PM");
480 FIXME ("Not implemented\n");
481 strcpy (result,"xxx");
484 sprintf (result,"%d",date.wYear-10* (int) floor(date.wYear/10));
487 sprintf (result,"%.2d",date.wYear-100* (int) floor(date.wYear/100));
489 case INVALIDFULLYEAR:
491 sprintf (result,"%d",date.wYear);
495 TRACE ("arg%d=%x->[%s]\n",count,infoPtr->fieldspec[count],result);
500 DATETIME_IncreaseField (DATETIME_INFO *infoPtr, int number)
502 SYSTEMTIME *date = &infoPtr->date;
505 TRACE ("%d\n",number);
506 if ((number>infoPtr->nrFields) || (number<0)) return;
508 spec=infoPtr->fieldspec[number];
509 if ((spec & DTHT_DATEFIELD)==0) return;
517 if (date->wDay>MONTHCAL_MonthLength(date->wMonth,date->wYear))
525 if (date->wHour>23) date->wHour=0;
530 if (date->wSecond>59) date->wSecond=0;
535 if (date->wMinute>59) date->wMinute=0;
542 if (date->wMonth>12) date->wMonth=1;
543 if (date->wDay>MONTHCAL_MonthLength(date->wMonth,date->wYear))
544 date->wDay=MONTHCAL_MonthLength(date->wMonth,date->wYear);
549 if (date->wHour>23) date->wHour-=24;
552 FIXME ("Not implemented\n");
565 DATETIME_DecreaseField (DATETIME_INFO *infoPtr, int number)
567 SYSTEMTIME *date = & infoPtr->date;
570 TRACE ("%d\n",number);
571 if ((number>infoPtr->nrFields) || (number<0)) return;
573 spec = infoPtr->fieldspec[number];
574 if ((spec & DTHT_DATEFIELD)==0) return;
585 date->wDay=MONTHCAL_MonthLength(date->wMonth,date->wYear);
618 if (date->wDay>MONTHCAL_MonthLength(date->wMonth,date->wYear))
619 date->wDay=MONTHCAL_MonthLength(date->wMonth,date->wYear);
629 FIXME ("Not implemented\n");
642 DATETIME_ResetFieldDown (DATETIME_INFO *infoPtr, int number)
644 SYSTEMTIME *date = &infoPtr->date;
647 TRACE ("%d\n",number);
648 if ((number>infoPtr->nrFields) || (number<0)) return;
650 spec = infoPtr->fieldspec[number];
651 if ((spec & DTHT_DATEFIELD)==0) return;
683 FIXME ("Not implemented\n");
687 /* FYI: On 1752/9/14 the calendar changed and England and the
688 * American colonies changed to the Gregorian calendar. This change
689 * involved having September 14th follow September 2nd. So no date
690 * algorithm works before that date.
696 date->wDay = 14; /* overactive ms-programmers..*/
706 DATETIME_ResetFieldUp (DATETIME_INFO *infoPtr, int number)
708 SYSTEMTIME *date = & infoPtr->date;
711 TRACE("%d \n",number);
712 if ((number>infoPtr->nrFields) || (number<0)) return;
714 spec=infoPtr->fieldspec[number];
715 if ((spec & DTHT_DATEFIELD)==0) return;
722 date->wDay=MONTHCAL_MonthLength(date->wMonth,date->wYear);
746 FIXME ("Not implemented\n");
751 date->wYear=9999; /* Y10K problem? naaah. */
758 static void DATETIME_Refresh (HWND hwnd, HDC hdc)
761 DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr (hwnd);
764 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
765 RECT *rcDraw = &infoPtr->rcDraw;
766 RECT *rcClient = &infoPtr->rcClient;
767 RECT *calbutton = &infoPtr->calbutton;
768 RECT *checkbox = &infoPtr->checkbox;
771 COLORREF oldBk, oldTextColor;
773 /* draw control edge */
775 hbr = CreateSolidBrush(RGB(255, 255, 255));
776 FillRect(hdc, rcClient, hbr);
777 DrawEdge(hdc, rcClient, EDGE_SUNKEN, BF_RECT);
780 if (infoPtr->dateValid) {
783 oldFont = SelectObject (hdc, infoPtr->hFont);
785 DATETIME_ReturnTxt (infoPtr, 0, txt, sizeof(txt));
786 GetTextExtentPoint32A (hdc, txt, strlen (txt), &size);
787 rcDraw->bottom = size.cy+2;
789 if (dwStyle & DTS_SHOWNONE)
790 checkbox->right = 18;
793 prevright = checkbox->right;
795 for (i=0; i<infoPtr->nrFields; i++) {
796 DATETIME_ReturnTxt (infoPtr, i, txt, sizeof(txt));
797 GetTextExtentPoint32A (hdc, txt, strlen (txt), &size);
798 field = & infoPtr->fieldRect[i];
799 field->left = prevright;
800 field->right = prevright+size.cx;
801 field->top = rcDraw->top;
802 field->bottom = rcDraw->bottom;
803 prevright = field->right;
805 if ((infoPtr->haveFocus) && (i==infoPtr->select)) {
806 hbr = CreateSolidBrush (GetSysColor (COLOR_ACTIVECAPTION));
807 FillRect(hdc, field, hbr);
808 oldBk = SetBkColor (hdc, GetSysColor(COLOR_ACTIVECAPTION));
809 oldTextColor = SetTextColor (hdc, GetSysColor(COLOR_WINDOW));
811 DrawTextA ( hdc, txt, strlen(txt), field,
812 DT_RIGHT | DT_VCENTER | DT_SINGLELINE );
813 SetBkColor (hdc, oldBk);
814 SetTextColor (hdc, oldTextColor);
817 DrawTextA ( hdc, txt, strlen(txt), field,
818 DT_RIGHT | DT_VCENTER | DT_SINGLELINE );
821 SelectObject (hdc, oldFont);
824 if (!(dwStyle & DTS_UPDOWN)) {
825 DrawFrameControl(hdc, calbutton, DFC_SCROLL,
826 DFCS_SCROLLDOWN | (infoPtr->bCalDepressed ? DFCS_PUSHED : 0) |
827 (dwStyle & WS_DISABLED ? DFCS_INACTIVE : 0) );
833 DATETIME_HitTest (HWND hwnd, DATETIME_INFO *infoPtr, POINT pt)
837 TRACE ("%ld, %ld\n",pt.x,pt.y);
840 if (PtInRect (&infoPtr->calbutton, pt))
841 {retval = DTHT_MCPOPUP; TRACE("Hit in calbutton(DTHT_MCPOPUP)\n"); goto done; }
842 if (PtInRect (&infoPtr->checkbox, pt))
843 {retval = DTHT_CHECKBOX; TRACE("Hit in checkbox(DTHT_CHECKBOX)\n"); goto done; }
845 for (i=0; i<infoPtr->nrFields; i++) {
846 if (PtInRect (&infoPtr->fieldRect[i], pt)) {
848 TRACE("Hit in date text in field %d\n", i);
859 DATETIME_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
861 DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr (hwnd);
862 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
868 old = infoPtr->select;
869 pt.x = (INT)LOWORD(lParam);
870 pt.y = (INT)HIWORD(lParam);
872 new = DATETIME_HitTest (hwnd, infoPtr, pt);
874 /* FIXME: might be conditions where we don't want to update infoPtr->select */
875 infoPtr->select = new;
877 if (infoPtr->select != old) {
878 infoPtr->haveFocus = DTHT_GOTFOCUS;
881 if (infoPtr->select == DTHT_MCPOPUP) {
882 /* FIXME: button actually is only depressed during dropdown of the */
883 /* calendar control and when the mouse is over the button window */
884 infoPtr->bCalDepressed = TRUE;
886 /* recalculate the position of the monthcal popup */
887 if(dwStyle & DTS_RIGHTALIGN)
888 infoPtr->monthcal_pos.x = infoPtr->rcClient.right - ((infoPtr->calbutton.right -
889 infoPtr->calbutton.left) + 200);
891 infoPtr->monthcal_pos.x = 8;
893 infoPtr->monthcal_pos.y = infoPtr->rcClient.bottom;
894 ClientToScreen (hwnd, &(infoPtr->monthcal_pos));
895 /* FIXME My Windoze has cx=about 200, but it probably depends on font size etc */
896 SetWindowPos(infoPtr->hMonthCal, 0, infoPtr->monthcal_pos.x,
897 infoPtr->monthcal_pos.y, 200, 150, 0);
899 if(IsWindowVisible(infoPtr->hMonthCal))
900 ShowWindow(infoPtr->hMonthCal, SW_HIDE);
902 SYSTEMTIME *lprgSysTimeArray = &infoPtr->date;
903 TRACE("update calendar %04d/%02d/%02d\n",
904 lprgSysTimeArray->wYear, lprgSysTimeArray->wMonth, lprgSysTimeArray->wDay);
905 SendMessageA(infoPtr->hMonthCal, MCM_SETCURSEL, 0, (LPARAM)(&infoPtr->date));
906 ShowWindow(infoPtr->hMonthCal, SW_SHOW);
909 TRACE ("dt:%p mc:%p mc parent:%p, desktop:%p\n",
910 hwnd, infoPtr->hMonthCal, infoPtr->hwndNotify, GetDesktopWindow ());
911 DATETIME_SendSimpleNotify (hwnd, DTN_DROPDOWN);
914 InvalidateRect(hwnd, NULL, FALSE);
921 DATETIME_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
923 DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr (hwnd);
927 if(infoPtr->bCalDepressed == TRUE) {
928 infoPtr->bCalDepressed = FALSE;
929 InvalidateRect(hwnd, &(infoPtr->calbutton), TRUE);
937 DATETIME_Paint (HWND hwnd, WPARAM wParam)
942 hdc = wParam==0 ? BeginPaint (hwnd, &ps) : (HDC)wParam;
943 DATETIME_Refresh (hwnd, hdc);
945 EndPaint (hwnd, &ps);
951 DATETIME_Button_Command (HWND hwnd, WPARAM wParam, LPARAM lParam)
953 DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr(hwnd);
955 switch(HIWORD(wParam)) {
958 DWORD state = SendMessageA((HWND)lParam, BM_GETCHECK, 0, 0);
959 if(state == BST_CHECKED)
960 infoPtr->dateValid = TRUE;
962 infoPtr->dateValid = FALSE;
963 InvalidateRect(hwnd, NULL, TRUE);
974 DATETIME_Command (HWND hwnd, WPARAM wParam, LPARAM lParam)
976 DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr(hwnd);
978 TRACE("%08x %08lx\n", wParam, lParam);
979 TRACE("hwndbutton = %p\n", infoPtr->hwndCheckbut);
980 if(infoPtr->hwndCheckbut == (HWND)lParam)
981 return DATETIME_Button_Command(hwnd, wParam, lParam);
986 DATETIME_ParentNotify (HWND hwnd, WPARAM wParam, LPARAM lParam)
988 DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr (hwnd);
989 LPNMHDR lpnmh = (LPNMHDR) lParam;
991 TRACE ("%x,%lx\n",wParam, lParam);
992 TRACE ("Got notification %x from %p\n", lpnmh->code, lpnmh->hwndFrom);
993 TRACE ("info: %p %p %p\n",hwnd,infoPtr->hMonthCal,infoPtr->hUpdown);
999 DATETIME_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
1002 DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr (hwnd);
1003 LPNMHDR lpnmh = (LPNMHDR) lParam;
1005 TRACE ("%x,%lx\n",wParam, lParam);
1006 TRACE ("Got notification %x from %p\n", lpnmh->code, lpnmh->hwndFrom);
1007 TRACE ("info: %p %p %p\n",hwnd,infoPtr->hMonthCal,infoPtr->hUpdown);
1009 if (lpnmh->code==MCN_SELECT) {
1010 ShowWindow(infoPtr->hMonthCal, SW_HIDE);
1011 infoPtr->dateValid = TRUE;
1012 SendMessageA (infoPtr->hMonthCal, MCM_GETCURSEL, 0, (LPARAM)&infoPtr->date);
1013 TRACE("got from calendar %04d/%02d/%02d\n",
1014 infoPtr->date.wYear, infoPtr->date.wMonth, infoPtr->date.wDay);
1015 SendMessageA (infoPtr->hwndCheckbut, BM_SETCHECK, BST_CHECKED, 0);
1016 InvalidateRect(hwnd, NULL, TRUE);
1017 DATETIME_SendDateTimeChangeNotify (hwnd);
1024 DATETIME_KeyDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
1026 DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr (hwnd);
1027 int FieldNum,wrap=0;
1029 TRACE("%x %lx %x\n",wParam, lParam, infoPtr->select);
1031 FieldNum = infoPtr->select & DTHT_DATEFIELD;
1033 if (!(infoPtr->haveFocus)) return 0;
1034 if ((FieldNum==0) && (infoPtr->select)) return 0;
1036 if (infoPtr->select & FORMATCALLMASK) {
1037 FIXME ("Callbacks not implemented yet\n");
1043 DATETIME_IncreaseField (infoPtr,FieldNum);
1044 DATETIME_SendDateTimeChangeNotify (hwnd);
1048 DATETIME_DecreaseField (infoPtr,FieldNum);
1049 DATETIME_SendDateTimeChangeNotify (hwnd);
1052 DATETIME_ResetFieldDown (infoPtr,FieldNum);
1053 DATETIME_SendDateTimeChangeNotify (hwnd);
1056 DATETIME_ResetFieldUp(infoPtr,FieldNum);
1057 DATETIME_SendDateTimeChangeNotify (hwnd);
1061 if (infoPtr->select==0) {
1062 infoPtr->select = infoPtr->nrFields - 1;
1067 while ((infoPtr->fieldspec[infoPtr->select] & DT_STRING) && (wrap<2));
1072 if (infoPtr->select==infoPtr->nrFields) {
1073 infoPtr->select = 0;
1077 while ((infoPtr->fieldspec[infoPtr->select] & DT_STRING) && (wrap<2));
1081 InvalidateRect(hwnd, NULL, FALSE);
1088 DATETIME_KillFocus (HWND hwnd, WPARAM wParam, LPARAM lParam)
1090 DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr (hwnd);
1094 if (infoPtr->haveFocus) {
1095 DATETIME_SendSimpleNotify (hwnd, NM_KILLFOCUS);
1096 infoPtr->haveFocus = 0;
1099 InvalidateRect (hwnd, NULL, TRUE);
1106 DATETIME_SetFocus (HWND hwnd, WPARAM wParam, LPARAM lParam)
1108 DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr (hwnd);
1112 if (infoPtr->haveFocus==0) {
1113 DATETIME_SendSimpleNotify (hwnd, NM_SETFOCUS);
1114 infoPtr->haveFocus = DTHT_GOTFOCUS;
1117 InvalidateRect(hwnd, NULL, FALSE);
1124 DATETIME_SendDateTimeChangeNotify (HWND hwnd)
1127 DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr (hwnd);
1128 NMDATETIMECHANGE dtdtc;
1131 dtdtc.nmhdr.hwndFrom = hwnd;
1132 dtdtc.nmhdr.idFrom = GetWindowLongPtrW(hwnd, GWLP_ID);
1133 dtdtc.nmhdr.code = DTN_DATETIMECHANGE;
1135 if ((GetWindowLongA (hwnd, GWL_STYLE) & DTS_SHOWNONE))
1136 dtdtc.dwFlags = GDT_NONE;
1138 dtdtc.dwFlags = GDT_VALID;
1140 MONTHCAL_CopyTime (&infoPtr->date, &dtdtc.st);
1141 return (BOOL) SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
1142 (WPARAM)dtdtc.nmhdr.idFrom, (LPARAM)&dtdtc);
1147 DATETIME_SendSimpleNotify (HWND hwnd, UINT code)
1149 DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr (hwnd);
1153 nmhdr.hwndFrom = hwnd;
1154 nmhdr.idFrom = GetWindowLongPtrW(hwnd, GWLP_ID);
1157 return (BOOL) SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
1158 (WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr);
1162 DATETIME_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
1164 DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr(hwnd);
1165 DWORD dwStyle = GetWindowLongA(hwnd, GWL_STYLE);
1168 infoPtr->rcClient.bottom = HIWORD(lParam);
1169 infoPtr->rcClient.right = LOWORD(lParam);
1171 TRACE("Height=%ld, Width=%ld\n", infoPtr->rcClient.bottom, infoPtr->rcClient.right);
1173 /* use DrawEdge to adjust the size of rcEdge to get rcDraw */
1174 memcpy((&infoPtr->rcDraw), (&infoPtr->rcClient), sizeof(infoPtr->rcDraw));
1176 DrawEdge(NULL, &(infoPtr->rcDraw), EDGE_SUNKEN, BF_RECT | BF_ADJUST);
1178 /* set the size of the button that drops the calendar down */
1179 /* FIXME: account for style that allows button on left side */
1180 infoPtr->calbutton.top = infoPtr->rcDraw.top;
1181 infoPtr->calbutton.bottom= infoPtr->rcDraw.bottom;
1182 infoPtr->calbutton.left = infoPtr->rcDraw.right-15;
1183 infoPtr->calbutton.right = infoPtr->rcDraw.right;
1185 /* set enable/disable button size for show none style being enabled */
1186 /* FIXME: these dimensions are completely incorrect */
1187 infoPtr->checkbox.top = infoPtr->rcDraw.top;
1188 infoPtr->checkbox.bottom = infoPtr->rcDraw.bottom;
1189 infoPtr->checkbox.left = infoPtr->rcDraw.left;
1190 infoPtr->checkbox.right = infoPtr->rcDraw.left + 10;
1192 /* update the position of the monthcal control */
1193 if(dwStyle & DTS_RIGHTALIGN)
1194 infoPtr->monthcal_pos.x = infoPtr->rcClient.right - ((infoPtr->calbutton.right -
1195 infoPtr->calbutton.left) + 145);
1197 infoPtr->monthcal_pos.x = 8;
1199 infoPtr->monthcal_pos.y = infoPtr->rcClient.bottom;
1200 ClientToScreen (hwnd, &(infoPtr->monthcal_pos));
1201 SetWindowPos(infoPtr->hMonthCal, 0, infoPtr->monthcal_pos.x,
1202 infoPtr->monthcal_pos.y,
1205 InvalidateRect(hwnd, NULL, FALSE);
1212 DATETIME_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
1214 DATETIME_INFO *infoPtr;
1215 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1217 /* allocate memory for info structure */
1218 TRACE("%04x %08lx\n",wParam,lParam);
1219 infoPtr = (DATETIME_INFO *)Alloc (sizeof(DATETIME_INFO));
1220 if (infoPtr == NULL) {
1221 ERR("could not allocate info memory!\n");
1225 SetWindowLongPtrA (hwnd, 0, (DWORD_PTR)infoPtr);
1227 if (dwStyle & DTS_SHOWNONE) {
1228 infoPtr->hwndCheckbut=CreateWindowExA (0,"button", 0,
1229 WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
1232 0, (HINSTANCE)GetWindowLongPtrW (hwnd, GWLP_HINSTANCE), 0);
1233 SendMessageA (infoPtr->hwndCheckbut, BM_SETCHECK, 1, 0);
1236 if (dwStyle & DTS_UPDOWN) {
1237 infoPtr->hUpdown=CreateUpDownControl (
1238 WS_CHILD | WS_BORDER | WS_VISIBLE,
1241 UD_MAXVAL, UD_MINVAL, 0);
1244 infoPtr->fieldspec = (int *) Alloc (32*sizeof(int));
1245 infoPtr->fieldRect = (RECT *) Alloc (32*sizeof(RECT));
1246 infoPtr->buflen = (int *) Alloc (32*sizeof(int));
1247 infoPtr->nrFieldsAllocated = 32;
1248 infoPtr->hwndNotify = ((LPCREATESTRUCTA)lParam)->hwndParent;
1250 DATETIME_SetFormat (hwnd, 0, 0);
1252 /* create the monthcal control */
1253 infoPtr->hMonthCal = CreateWindowExA (0,"SysMonthCal32", 0,
1254 WS_BORDER | WS_POPUP | WS_CLIPSIBLINGS,
1259 /* initialize info structure */
1260 GetSystemTime (&infoPtr->date);
1261 infoPtr->dateValid = TRUE;
1262 infoPtr->hFont = GetStockObject(DEFAULT_GUI_FONT);
1268 DATETIME_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
1270 DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr (hwnd);
1273 if (infoPtr->hMonthCal) {
1274 /* FIXME I don't completely understand why doesn't it
1275 * happen automatically, WS_POPUP maybe? */
1276 DestroyWindow(infoPtr->hMonthCal);
1277 infoPtr->hMonthCal = NULL;
1280 SetWindowLongPtrA( hwnd, 0, 0 ); /* clear infoPtr */
1285 static LRESULT WINAPI
1286 DATETIME_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1288 if (!DATETIME_GetInfoPtr(hwnd) && (uMsg != WM_CREATE))
1289 return DefWindowProcA( hwnd, uMsg, wParam, lParam );
1294 case DTM_GETSYSTEMTIME:
1295 return DATETIME_GetSystemTime (hwnd, wParam, lParam);
1297 case DTM_SETSYSTEMTIME:
1298 return DATETIME_SetSystemTime (hwnd, wParam, lParam);
1301 return DATETIME_GetRange(hwnd, lParam);
1304 return DATETIME_SetRange(hwnd, wParam, lParam);
1306 case DTM_SETFORMATA:
1307 return DATETIME_SetFormat (hwnd, wParam, lParam);
1309 case DTM_SETFORMATW:
1310 return DATETIME_SetFormatW (hwnd, wParam, lParam);
1312 case DTM_SETMCCOLOR:
1313 return DATETIME_SetMonthCalColor (hwnd, wParam, lParam);
1315 case DTM_GETMCCOLOR:
1316 return DATETIME_GetMonthCalColor (hwnd, wParam);
1318 case DTM_GETMONTHCAL:
1319 return DATETIME_GetMonthCal (hwnd);
1322 return DATETIME_SetMonthCalFont (hwnd, wParam, lParam);
1325 return DATETIME_GetMonthCalFont (hwnd);
1327 case WM_PARENTNOTIFY:
1328 return DATETIME_ParentNotify (hwnd, wParam, lParam);
1331 return DATETIME_Notify (hwnd, wParam, lParam);
1334 return DLGC_WANTARROWS | DLGC_WANTCHARS;
1337 return DATETIME_Paint (hwnd, wParam);
1340 return DATETIME_KeyDown (hwnd, wParam, lParam);
1343 return DATETIME_KillFocus (hwnd, wParam, lParam);
1346 return DATETIME_SetFocus (hwnd, wParam, lParam);
1349 return DATETIME_Size (hwnd, wParam, lParam);
1351 case WM_LBUTTONDOWN:
1352 return DATETIME_LButtonDown (hwnd, wParam, lParam);
1355 return DATETIME_LButtonUp (hwnd, wParam, lParam);
1358 return DATETIME_Create (hwnd, wParam, lParam);
1361 return DATETIME_Destroy (hwnd, wParam, lParam);
1364 return DATETIME_Command (hwnd, wParam, lParam);
1367 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
1368 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
1369 uMsg, wParam, lParam);
1370 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
1377 DATETIME_Register (void)
1382 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
1383 wndClass.style = CS_GLOBALCLASS;
1384 wndClass.lpfnWndProc = (WNDPROC)DATETIME_WindowProc;
1385 wndClass.cbClsExtra = 0;
1386 wndClass.cbWndExtra = sizeof(DATETIME_INFO *);
1387 wndClass.hCursor = LoadCursorA (0, (LPSTR)IDC_ARROW);
1388 wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
1389 wndClass.lpszClassName = DATETIMEPICK_CLASSA;
1391 RegisterClassA (&wndClass);
1396 DATETIME_Unregister (void)
1399 UnregisterClassA (DATETIMEPICK_CLASSA, NULL);