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>
11 * - All notifications.
22 #include "debugtools.h"
24 DEFAULT_DEBUG_CHANNEL(datetime
);
33 RECT rcClient
; /* rect around the edge of the window */
34 RECT rcDraw
; /* rect inside of the border */
35 RECT checkbox
; /* checkbox allowing the control to be enabled/disabled */
36 RECT calbutton
; /* button that toggles the dropdown of the monthcal control */
37 BOOL bCalDepressed
; /* TRUE = cal button is depressed */
40 int nrFieldsAllocated
;
48 } DATETIME_INFO
, *LPDATETIME_INFO
;
51 extern int MONTHCAL_MonthLength(int month
, int year
);
53 /* this list of defines is closely related to `allowedformatchars' defined
54 * in datetime.c; the high nibble indicates the `base type' of the format
56 * Do not change without first reading DATETIME_UseFormat.
60 #define DT_END_FORMAT 0
61 #define ONEDIGITDAY 0x01
62 #define TWODIGITDAY 0x02
63 #define THREECHARDAY 0x03
65 #define ONEDIGIT12HOUR 0x11
66 #define TWODIGIT12HOUR 0x12
67 #define ONEDIGIT24HOUR 0x21
68 #define TWODIGIT24HOUR 0x22
69 #define ONEDIGITMINUTE 0x31
70 #define TWODIGITMINUTE 0x32
71 #define ONEDIGITMONTH 0x41
72 #define TWODIGITMONTH 0x42
73 #define THREECHARMONTH 0x43
74 #define FULLMONTH 0x44
75 #define ONEDIGITSECOND 0x51
76 #define TWODIGITSECOND 0x52
77 #define ONELETTERAMPM 0x61
78 #define TWOLETTERAMPM 0x62
79 #define ONEDIGITYEAR 0x71
80 #define TWODIGITYEAR 0x72
82 #define FORMATCALLBACK 0x81 /* -> maximum of 0x80 callbacks possible */
83 #define FORMATCALLMASK 0x80
84 #define DT_STRING 0x0100
86 #define DTHT_DATEFIELD 0xff /* for hit-testing */
89 #define DTHT_CHECKBOX 0x200 /* these should end at '00' , to make */
90 #define DTHT_MCPOPUP 0x300 /* & DTHT_DATEFIELD 0 when DATETIME_KeyDown */
91 #define DTHT_GOTFOCUS 0x400 /* tests for date-fields */
93 #define DATETIME_GetInfoPtr(hwnd) ((DATETIME_INFO *)GetWindowLongA (hwnd, 0))
95 static BOOL
DATETIME_SendSimpleNotify (HWND hwnd
, UINT code
);
96 static BOOL
DATETIME_SendDateTimeChangeNotify (HWND hwnd
);
97 extern void MONTHCAL_CopyTime(const SYSTEMTIME
*from
, SYSTEMTIME
*to
);
98 static const char *allowedformatchars
= {"dhHmMstyX'"};
99 static const int maxrepetition
[] = {4,2,2,2,4,2,2,3,-1,-1};
103 DATETIME_GetSystemTime (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
105 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
106 DWORD dwStyle
= GetWindowLongA (hwnd
, GWL_STYLE
);
107 SYSTEMTIME
*lprgSysTimeArray
=(SYSTEMTIME
*) lParam
;
109 TRACE("%04x %08lx\n",wParam
,lParam
);
110 if (!lParam
) return GDT_NONE
;
112 if ((dwStyle
& DTS_SHOWNONE
) &&
113 (SendMessageA (infoPtr
->hwndCheckbut
, BM_GETCHECK
, 0, 0)))
116 MONTHCAL_CopyTime (&infoPtr
->date
, lprgSysTimeArray
);
123 DATETIME_SetSystemTime (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
125 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
126 SYSTEMTIME
*lprgSysTimeArray
=(SYSTEMTIME
*) lParam
;
128 TRACE("%04x %08lx\n",wParam
,lParam
);
129 if (!lParam
) return 0;
131 if (lParam
==GDT_VALID
)
132 MONTHCAL_CopyTime (lprgSysTimeArray
, &infoPtr
->date
);
133 if (lParam
==GDT_NONE
) {
134 infoPtr
->dateValid
=FALSE
;
135 SendMessageA (infoPtr
->hwndCheckbut
, BM_SETCHECK
, 0, 0);
142 DATETIME_GetRange (HWND hwnd
, LPARAM lParam
)
144 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
147 TRACE("%08lx\n", lParam
);
148 ret
= SendMessageA (infoPtr
->hMonthCal
, MCM_GETRANGE
, 0, lParam
);
149 if (!ret
) ret
= 1; /* bug emulation... */
154 DATETIME_SetRange (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
156 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
158 TRACE("%04x %08lx\n",wParam
,lParam
);
160 return SendMessageA (infoPtr
->hMonthCal
, MCM_SETRANGE
, wParam
, lParam
);
164 DATETIME_GetMonthCalColor (HWND hwnd
, WPARAM wParam
)
166 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
168 TRACE("%04x\n",wParam
);
169 return SendMessageA (infoPtr
->hMonthCal
, MCM_GETCOLOR
, wParam
, 0);
174 DATETIME_SetMonthCalColor (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
176 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
178 TRACE("%04x %08lx\n",wParam
,lParam
);
179 return SendMessageA (infoPtr
->hMonthCal
, MCM_SETCOLOR
, wParam
, lParam
);
183 /* FIXME: need to get way to force font into monthcal structure */
185 DATETIME_GetMonthCal (HWND hwnd
)
187 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
190 return infoPtr
->hMonthCal
;
195 /* FIXME: need to get way to force font into monthcal structure */
198 DATETIME_GetMonthCalFont (HWND hwnd
)
207 DATETIME_SetMonthCalFont (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
210 TRACE("%04x %08lx\n",wParam
,lParam
);
216 Split up a formattxt in actions.
217 See ms documentation for the meaning of the letter codes/'specifiers'.
220 *'dddddd' is handled as 'dddd' plus 'dd'.
221 *unrecognized formats are strings (here given the type DT_STRING;
222 start of the string is encoded in lower bits of DT_STRING.
223 Therefore, 'string' ends finally up as '<show seconds>tring'.
229 DATETIME_UseFormat (DATETIME_INFO
*infoPtr
, const char *formattxt
)
232 int *nrFields
=& infoPtr
->nrFields
;
234 TRACE ("%s\n",formattxt
);
238 infoPtr
->fieldspec
[*nrFields
]=0;
239 len
=strlen(allowedformatchars
);
242 for (i
=0; i
<strlen (formattxt
); i
++) {
243 TRACE ("\n%d %c:",i
, formattxt
[i
]);
244 for (j
=0; j
<len
; j
++) {
245 if (allowedformatchars
[j
]==formattxt
[i
]) {
246 TRACE ("%c[%d,%x]",allowedformatchars
[j
], *nrFields
,
247 infoPtr
->fieldspec
[*nrFields
]);
248 if ((*nrFields
==0) && (infoPtr
->fieldspec
[*nrFields
]==0)) {
249 infoPtr
->fieldspec
[*nrFields
]=(j
<<4) +1;
252 if (infoPtr
->fieldspec
[*nrFields
]>>4!=j
) {
254 infoPtr
->fieldspec
[*nrFields
]=(j
<<4) +1;
257 if ((infoPtr
->fieldspec
[*nrFields
] & 0x0f)==maxrepetition
[j
]) {
259 infoPtr
->fieldspec
[*nrFields
]=(j
<<4) +1;
262 infoPtr
->fieldspec
[*nrFields
]++;
264 } /* if allowedformatchar */
268 /* char is not a specifier: handle char like a string */
270 if ((*nrFields
==0) && (infoPtr
->fieldspec
[*nrFields
]==0)) {
271 infoPtr
->fieldspec
[*nrFields
]=DT_STRING
+k
;
272 infoPtr
->buflen
[*nrFields
]=0;
274 if ((infoPtr
->fieldspec
[*nrFields
] & DT_STRING
)!=DT_STRING
) {
276 infoPtr
->fieldspec
[*nrFields
]=DT_STRING
+k
;
277 infoPtr
->buflen
[*nrFields
]=0;
279 infoPtr
->textbuf
[k
]=formattxt
[i
];
281 infoPtr
->buflen
[*nrFields
]++;
284 if (*nrFields
==infoPtr
->nrFieldsAllocated
) {
285 FIXME ("out of memory; should reallocate. crash ahead.\n");
292 if (infoPtr
->fieldspec
[*nrFields
]!=0) (*nrFields
)++;
297 DATETIME_SetFormat (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
299 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
303 TRACE("%04x %08lx\n",wParam
,lParam
);
305 DWORD dwStyle
= GetWindowLongA (hwnd
, GWL_STYLE
);
307 if (dwStyle
& DTS_LONGDATEFORMAT
)
308 format_item
=LOCALE_SLONGDATE
;
309 else if (dwStyle
& DTS_TIMEFORMAT
)
310 format_item
=LOCALE_STIMEFORMAT
;
311 else /* DTS_SHORTDATEFORMAT */
312 format_item
=LOCALE_SSHORTDATE
;
313 GetLocaleInfoA( GetSystemDefaultLCID(), format_item
,format_buf
,sizeof(format_buf
));
314 DATETIME_UseFormat (infoPtr
, format_buf
);
317 DATETIME_UseFormat (infoPtr
, (char *) lParam
);
319 return infoPtr
->nrFields
;
324 DATETIME_SetFormatW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
327 TRACE("%04x %08lx\n",wParam
,lParam
);
331 int len
= WideCharToMultiByte( CP_ACP
, 0, (LPWSTR
)lParam
, -1, NULL
, 0, NULL
, NULL
);
333 buf
= (LPSTR
) COMCTL32_Alloc (len
);
334 WideCharToMultiByte( CP_ACP
, 0, (LPWSTR
)lParam
, -1, buf
, len
, NULL
, NULL
);
335 retval
=DATETIME_SetFormat (hwnd
, 0, (LPARAM
) buf
);
340 return DATETIME_SetFormat (hwnd
, 0, 0);
346 DATETIME_ReturnTxt (DATETIME_INFO
*infoPtr
, int count
, char *result
)
348 SYSTEMTIME date
= infoPtr
->date
;
353 TRACE ("%d,%d\n", infoPtr
->nrFields
, count
);
354 if ((count
>infoPtr
->nrFields
) || (count
<0)) {
355 WARN ("buffer overrun, have %d want %d\n", infoPtr
->nrFields
, count
);
359 if (!infoPtr
->fieldspec
) return;
361 spec
=infoPtr
->fieldspec
[count
];
362 if (spec
& DT_STRING
) {
363 int txtlen
=infoPtr
->buflen
[count
];
365 strncpy (result
, infoPtr
->textbuf
+ (spec
&~ DT_STRING
), txtlen
);
367 TRACE ("arg%d=%x->[%s]\n",count
,infoPtr
->fieldspec
[count
],result
);
377 sprintf (result
,"%d",date
.wDay
);
380 sprintf (result
,"%.2d",date
.wDay
);
383 GetLocaleInfoA( LOCALE_USER_DEFAULT
, LOCALE_SABBREVDAYNAME1
+(date
.wDayOfWeek
+6)%7,
385 /*sprintf (result,"%.3s",days[date.wDayOfWeek]);*/
388 GetLocaleInfoA( LOCALE_USER_DEFAULT
,LOCALE_SDAYNAME1
+ (date
.wDayOfWeek
+6)%7,
389 buffer
,sizeof(buffer
));
390 strcpy (result
,buffer
);
394 sprintf (result
,"%d",date
.wHour
-12);
396 sprintf (result
,"%d",date
.wHour
);
400 sprintf (result
,"%.2d",date
.wHour
-12);
402 sprintf (result
,"%.2d",date
.wHour
);
405 sprintf (result
,"%d",date
.wHour
);
408 sprintf (result
,"%.2d",date
.wHour
);
411 sprintf (result
,"%d",date
.wSecond
);
414 sprintf (result
,"%.2d",date
.wSecond
);
417 sprintf (result
,"%d",date
.wMinute
);
420 sprintf (result
,"%.2d",date
.wMinute
);
423 sprintf (result
,"%d",date
.wMonth
);
426 sprintf (result
,"%.2d",date
.wMonth
);
429 GetLocaleInfoA( GetSystemDefaultLCID(),LOCALE_SMONTHNAME1
+date
.wMonth
-1,
430 buffer
,sizeof(buffer
));
431 sprintf (result
,"%.3s",buffer
);
434 GetLocaleInfoA( GetSystemDefaultLCID(),LOCALE_SMONTHNAME1
+date
.wMonth
-1,
435 result
,sizeof(result
));
445 strcpy (result
,"AM");
447 strcpy (result
,"PM");
450 FIXME ("Not implemented\n");
451 strcpy (result
,"xxx");
454 sprintf (result
,"%d",date
.wYear
-10* (int) floor(date
.wYear
/10));
457 sprintf (result
,"%.2d",date
.wYear
-100* (int) floor(date
.wYear
/100));
460 sprintf (result
,"%d",date
.wYear
);
464 TRACE ("arg%d=%x->[%s]\n",count
,infoPtr
->fieldspec
[count
],result
);
469 DATETIME_IncreaseField (DATETIME_INFO
*infoPtr
, int number
)
471 SYSTEMTIME
*date
= &infoPtr
->date
;
474 TRACE ("%d\n",number
);
475 if ((number
>infoPtr
->nrFields
) || (number
<0)) return;
477 spec
=infoPtr
->fieldspec
[number
];
478 if ((spec
& DTHT_DATEFIELD
)==0) return;
486 if (date
->wDay
>MONTHCAL_MonthLength(date
->wMonth
,date
->wYear
))
494 if (date
->wHour
>23) date
->wHour
=0;
499 if (date
->wSecond
>59) date
->wSecond
=0;
504 if (date
->wMinute
>59) date
->wMinute
=0;
511 if (date
->wMonth
>12) date
->wMonth
=1;
512 if (date
->wDay
>MONTHCAL_MonthLength(date
->wMonth
,date
->wYear
))
513 date
->wDay
=MONTHCAL_MonthLength(date
->wMonth
,date
->wYear
);
518 if (date
->wHour
>23) date
->wHour
-=24;
521 FIXME ("Not implemented\n");
534 DATETIME_DecreaseField (DATETIME_INFO
*infoPtr
, int number
)
536 SYSTEMTIME
*date
= & infoPtr
->date
;
539 TRACE ("%d\n",number
);
540 if ((number
>infoPtr
->nrFields
) || (number
<0)) return;
542 spec
= infoPtr
->fieldspec
[number
];
543 if ((spec
& DTHT_DATEFIELD
)==0) return;
554 date
->wDay
=MONTHCAL_MonthLength(date
->wMonth
,date
->wYear
);
587 if (date
->wDay
>MONTHCAL_MonthLength(date
->wMonth
,date
->wYear
))
588 date
->wDay
=MONTHCAL_MonthLength(date
->wMonth
,date
->wYear
);
598 FIXME ("Not implemented\n");
611 DATETIME_ResetFieldDown (DATETIME_INFO
*infoPtr
, int number
)
613 SYSTEMTIME
*date
= &infoPtr
->date
;
616 TRACE ("%d\n",number
);
617 if ((number
>infoPtr
->nrFields
) || (number
<0)) return;
619 spec
= infoPtr
->fieldspec
[number
];
620 if ((spec
& DTHT_DATEFIELD
)==0) return;
652 FIXME ("Not implemented\n");
656 /* FYI: On 9/14/1752 the calender changed and England and the American */
657 /* colonies changed to the Gregorian calender. This change involved */
658 /* having September 14th following September 2nd. So no date algorithms */
659 /* work before that date. */
664 date
->wDay
= 14; /* overactive ms-programmers..*/
674 DATETIME_ResetFieldUp (DATETIME_INFO
*infoPtr
, int number
)
676 SYSTEMTIME
*date
= & infoPtr
->date
;
679 TRACE("%d \n",number
);
680 if ((number
>infoPtr
->nrFields
) || (number
<0)) return;
682 spec
=infoPtr
->fieldspec
[number
];
683 if ((spec
& DTHT_DATEFIELD
)==0) return;
690 date
->wDay
=MONTHCAL_MonthLength(date
->wMonth
,date
->wYear
);
714 FIXME ("Not implemented\n");
719 date
->wYear
=9999; /* Y10K problem? naaah. */
726 static void DATETIME_Refresh (HWND hwnd
, HDC hdc
)
729 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
732 DWORD dwStyle
= GetWindowLongA (hwnd
, GWL_STYLE
);
733 RECT
*rcDraw
= &infoPtr
->rcDraw
;
734 RECT
*rcClient
= &infoPtr
->rcClient
;
735 RECT
*calbutton
= &infoPtr
->calbutton
;
736 RECT
*checkbox
= &infoPtr
->checkbox
;
739 COLORREF oldBk
, oldTextColor
;
741 /* draw control edge */
743 hbr
= CreateSolidBrush(RGB(255, 255, 255));
744 FillRect(hdc
, rcClient
, hbr
);
745 DrawEdge(hdc
, rcClient
, EDGE_SUNKEN
, BF_RECT
);
748 if (infoPtr
->dateValid
) {
751 oldFont
= SelectObject (hdc
, infoPtr
->hFont
);
753 DATETIME_ReturnTxt (infoPtr
, 0, txt
);
754 GetTextExtentPoint32A (hdc
, txt
, strlen (txt
), &size
);
755 rcDraw
->bottom
= size
.cy
+2;
757 if (dwStyle
& DTS_SHOWNONE
) checkbox
->right
= 18;
759 prevright
= checkbox
->right
;
761 for (i
=0; i
<infoPtr
->nrFields
; i
++) {
762 DATETIME_ReturnTxt (infoPtr
, i
, txt
);
763 GetTextExtentPoint32A (hdc
, txt
, strlen (txt
), &size
);
764 field
= & infoPtr
->fieldRect
[i
];
765 field
->left
= prevright
;
766 field
->right
= prevright
+size
.cx
;
767 field
->top
= rcDraw
->top
;
768 field
->bottom
= rcDraw
->bottom
;
769 prevright
= field
->right
;
771 if ((infoPtr
->haveFocus
) && (i
==infoPtr
->select
)) {
772 hbr
= CreateSolidBrush (GetSysColor (COLOR_ACTIVECAPTION
));
773 FillRect(hdc
, field
, hbr
);
774 oldBk
= SetBkColor (hdc
, GetSysColor(COLOR_ACTIVECAPTION
));
775 oldTextColor
= SetTextColor (hdc
, GetSysColor(COLOR_WINDOW
));
777 DrawTextA ( hdc
, txt
, strlen(txt
), field
,
778 DT_RIGHT
| DT_VCENTER
| DT_SINGLELINE
);
779 SetBkColor (hdc
, oldBk
);
780 SetTextColor (hdc
, oldTextColor
);
783 DrawTextA ( hdc
, txt
, strlen(txt
), field
,
784 DT_RIGHT
| DT_VCENTER
| DT_SINGLELINE
);
787 SelectObject (hdc
, oldFont
);
790 if (!(dwStyle
& DTS_UPDOWN
)) {
791 DrawFrameControl(hdc
, calbutton
, DFC_SCROLL
,
792 DFCS_SCROLLDOWN
| (infoPtr
->bCalDepressed
? DFCS_PUSHED
: 0) |
793 (dwStyle
& WS_DISABLED
? DFCS_INACTIVE
: 0) );
799 DATETIME_HitTest (HWND hwnd
, DATETIME_INFO
*infoPtr
, POINT pt
)
803 TRACE ("%ld, %ld\n",pt
.x
,pt
.y
);
806 if (PtInRect (&infoPtr
->calbutton
, pt
))
807 {retval
= DTHT_MCPOPUP
; TRACE("Hit in calbutton(DTHT_MCPOPUP)\n"); goto done
; }
808 if (PtInRect (&infoPtr
->checkbox
, pt
))
809 {retval
= DTHT_CHECKBOX
; TRACE("Hit in checkbox(DTHT_CHECKBOX)\n"); goto done
; }
811 for (i
=0; i
<infoPtr
->nrFields
; i
++) {
812 if (PtInRect (&infoPtr
->fieldRect
[i
], pt
)) {
814 TRACE("Hit in date text in field %d\n", i
);
825 DATETIME_LButtonDown (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
827 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
828 DWORD dwStyle
= GetWindowLongA (hwnd
, GWL_STYLE
);
834 old
= infoPtr
->select
;
835 pt
.x
= (INT
)LOWORD(lParam
);
836 pt
.y
= (INT
)HIWORD(lParam
);
838 new = DATETIME_HitTest (hwnd
, infoPtr
, pt
);
840 /* FIXME: might be conditions where we don't want to update infoPtr->select */
841 infoPtr
->select
= new;
843 if (infoPtr
->select
!= old
) {
844 infoPtr
->haveFocus
= DTHT_GOTFOCUS
;
847 if (infoPtr
->select
== DTHT_MCPOPUP
) {
848 /* FIXME: button actually is only depressed during dropdown of the */
849 /* calender control and when the mouse is over the button window */
850 infoPtr
->bCalDepressed
= TRUE
;
852 /* recalculate the position of the monthcal popup */
853 if(dwStyle
& DTS_RIGHTALIGN
)
854 infoPtr
->monthcal_pos
.x
= infoPtr
->rcClient
.right
- ((infoPtr
->calbutton
.right
-
855 infoPtr
->calbutton
.left
) + 145);
857 infoPtr
->monthcal_pos
.x
= 8;
859 infoPtr
->monthcal_pos
.y
= infoPtr
->rcClient
.bottom
;
860 ClientToScreen (hwnd
, &(infoPtr
->monthcal_pos
));
861 SetWindowPos(infoPtr
->hMonthCal
, 0, infoPtr
->monthcal_pos
.x
,
862 infoPtr
->monthcal_pos
.y
, 145, 150, 0);
864 if(IsWindowVisible(infoPtr
->hMonthCal
))
865 ShowWindow(infoPtr
->hMonthCal
, SW_HIDE
);
867 ShowWindow(infoPtr
->hMonthCal
, SW_SHOW
);
869 TRACE ("dt:%x mc:%x mc parent:%x, desktop:%x, mcpp:%x\n",
870 hwnd
,infoPtr
->hMonthCal
,
871 GetParent (infoPtr
->hMonthCal
),
873 GetParent (GetParent (infoPtr
->hMonthCal
)));
874 DATETIME_SendSimpleNotify (hwnd
, DTN_DROPDOWN
);
877 InvalidateRect(hwnd
, NULL
, FALSE
);
884 DATETIME_LButtonUp (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
886 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
890 if(infoPtr
->bCalDepressed
== TRUE
) {
891 infoPtr
->bCalDepressed
= FALSE
;
892 InvalidateRect(hwnd
, &(infoPtr
->calbutton
), TRUE
);
900 DATETIME_Paint (HWND hwnd
, WPARAM wParam
)
905 hdc
= wParam
==0 ? BeginPaint (hwnd
, &ps
) : (HDC
)wParam
;
906 DATETIME_Refresh (hwnd
, hdc
);
908 EndPaint (hwnd
, &ps
);
914 DATETIME_ParentNotify (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
916 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
917 LPNMHDR lpnmh
= (LPNMHDR
) lParam
;
919 TRACE ("%x,%lx\n",wParam
, lParam
);
920 TRACE ("Got notification %x from %x\n", lpnmh
->code
, lpnmh
->hwndFrom
);
921 TRACE ("info: %x %x %x\n",hwnd
,infoPtr
->hMonthCal
,infoPtr
->hUpdown
);
927 DATETIME_Notify (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
930 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
931 LPNMHDR lpnmh
= (LPNMHDR
) lParam
;
933 TRACE ("%x,%lx\n",wParam
, lParam
);
934 TRACE ("Got notification %x from %x\n", lpnmh
->code
, lpnmh
->hwndFrom
);
935 TRACE ("info: %x %x %x\n",hwnd
,infoPtr
->hMonthCal
,infoPtr
->hUpdown
);
941 DATETIME_KeyDown (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
943 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
946 TRACE("%x %lx %x\n",wParam
, lParam
, infoPtr
->select
);
948 FieldNum
= infoPtr
->select
& DTHT_DATEFIELD
;
950 if (!(infoPtr
->haveFocus
)) return 0;
951 if ((FieldNum
==0) && (infoPtr
->select
)) return 0;
953 if (infoPtr
->select
& FORMATCALLMASK
) {
954 FIXME ("Callbacks not implemented yet\n");
960 DATETIME_IncreaseField (infoPtr
,FieldNum
);
961 DATETIME_SendDateTimeChangeNotify (hwnd
);
965 DATETIME_DecreaseField (infoPtr
,FieldNum
);
966 DATETIME_SendDateTimeChangeNotify (hwnd
);
969 DATETIME_ResetFieldDown (infoPtr
,FieldNum
);
970 DATETIME_SendDateTimeChangeNotify (hwnd
);
973 DATETIME_ResetFieldUp(infoPtr
,FieldNum
);
974 DATETIME_SendDateTimeChangeNotify (hwnd
);
978 if (infoPtr
->select
==0) {
979 infoPtr
->select
= infoPtr
->nrFields
- 1;
984 while ((infoPtr
->fieldspec
[infoPtr
->select
] & DT_STRING
) && (wrap
<2));
989 if (infoPtr
->select
==infoPtr
->nrFields
) {
994 while ((infoPtr
->fieldspec
[infoPtr
->select
] & DT_STRING
) && (wrap
<2));
998 InvalidateRect(hwnd
, NULL
, FALSE
);
1005 DATETIME_KillFocus (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1007 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
1011 if (infoPtr
->haveFocus
) {
1012 DATETIME_SendSimpleNotify (hwnd
, NM_KILLFOCUS
);
1013 infoPtr
->haveFocus
= 0;
1016 InvalidateRect (hwnd
, NULL
, TRUE
);
1023 DATETIME_SetFocus (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1025 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
1029 if (infoPtr
->haveFocus
==0) {
1030 DATETIME_SendSimpleNotify (hwnd
, NM_SETFOCUS
);
1031 infoPtr
->haveFocus
= DTHT_GOTFOCUS
;
1034 InvalidateRect(hwnd
, NULL
, FALSE
);
1041 DATETIME_SendDateTimeChangeNotify (HWND hwnd
)
1044 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
1045 NMDATETIMECHANGE dtdtc
;
1048 dtdtc
.nmhdr
.hwndFrom
= hwnd
;
1049 dtdtc
.nmhdr
.idFrom
= GetWindowLongA( hwnd
, GWL_ID
);
1050 dtdtc
.nmhdr
.code
= DTN_DATETIMECHANGE
;
1052 if ((GetWindowLongA (hwnd
, GWL_STYLE
) & DTS_SHOWNONE
))
1053 dtdtc
.dwFlags
= GDT_NONE
;
1055 dtdtc
.dwFlags
= GDT_VALID
;
1057 MONTHCAL_CopyTime (&infoPtr
->date
, &dtdtc
.st
);
1058 return (BOOL
) SendMessageA (GetParent (hwnd
), WM_NOTIFY
,
1059 (WPARAM
)dtdtc
.nmhdr
.idFrom
, (LPARAM
)&dtdtc
);
1064 DATETIME_SendSimpleNotify (HWND hwnd
, UINT code
)
1069 nmhdr
.hwndFrom
= hwnd
;
1070 nmhdr
.idFrom
= GetWindowLongA( hwnd
, GWL_ID
);
1073 return (BOOL
) SendMessageA (GetParent (hwnd
), WM_NOTIFY
,
1074 (WPARAM
)nmhdr
.idFrom
, (LPARAM
)&nmhdr
);
1078 DATETIME_Size (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1080 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr(hwnd
);
1081 DWORD dwStyle
= GetWindowLongA(hwnd
, GWL_STYLE
);
1084 infoPtr
->rcClient
.bottom
= HIWORD(lParam
);
1085 infoPtr
->rcClient
.right
= LOWORD(lParam
);
1087 TRACE("Height=%d, Width=%d\n", infoPtr
->rcClient
.bottom
, infoPtr
->rcClient
.right
);
1089 /* use DrawEdge to adjust the size of rcEdge to get rcDraw */
1090 memcpy((&infoPtr
->rcDraw
), (&infoPtr
->rcClient
), sizeof(infoPtr
->rcDraw
));
1092 DrawEdge((HDC
)NULL
, &(infoPtr
->rcDraw
), EDGE_SUNKEN
, BF_RECT
| BF_ADJUST
);
1094 /* set the size of the button that drops the calender down */
1095 /* FIXME: account for style that allows button on left side */
1096 infoPtr
->calbutton
.top
= infoPtr
->rcDraw
.top
;
1097 infoPtr
->calbutton
.bottom
= infoPtr
->rcDraw
.bottom
;
1098 infoPtr
->calbutton
.left
= infoPtr
->rcDraw
.right
-15;
1099 infoPtr
->calbutton
.right
= infoPtr
->rcDraw
.right
;
1101 /* set enable/disable button size for show none style being enabled */
1102 /* FIXME: these dimensions are completely incorrect */
1103 infoPtr
->checkbox
.top
= infoPtr
->rcDraw
.top
;
1104 infoPtr
->checkbox
.bottom
= infoPtr
->rcDraw
.bottom
;
1105 infoPtr
->checkbox
.left
= infoPtr
->rcDraw
.left
;
1106 infoPtr
->checkbox
.right
= infoPtr
->rcDraw
.left
+ 10;
1108 /* update the position of the monthcal control */
1109 if(dwStyle
& DTS_RIGHTALIGN
)
1110 infoPtr
->monthcal_pos
.x
= infoPtr
->rcClient
.right
- ((infoPtr
->calbutton
.right
-
1111 infoPtr
->calbutton
.left
) + 145);
1113 infoPtr
->monthcal_pos
.x
= 8;
1115 infoPtr
->monthcal_pos
.y
= infoPtr
->rcClient
.bottom
;
1116 ClientToScreen (hwnd
, &(infoPtr
->monthcal_pos
));
1117 SetWindowPos(infoPtr
->hMonthCal
, 0, infoPtr
->monthcal_pos
.x
,
1118 infoPtr
->monthcal_pos
.y
,
1121 InvalidateRect(hwnd
, NULL
, FALSE
);
1128 DATETIME_Create (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1130 DATETIME_INFO
*infoPtr
;
1131 DWORD dwStyle
= GetWindowLongA (hwnd
, GWL_STYLE
);
1133 /* allocate memory for info structure */
1134 TRACE("%04x %08lx\n",wParam
,lParam
);
1135 infoPtr
= (DATETIME_INFO
*)COMCTL32_Alloc (sizeof(DATETIME_INFO
));
1136 if (infoPtr
== NULL
) {
1137 ERR("could not allocate info memory!\n");
1141 SetWindowLongA (hwnd
, 0, (DWORD
)infoPtr
);
1143 if (dwStyle
& DTS_SHOWNONE
) {
1144 infoPtr
->hwndCheckbut
=CreateWindowExA (0,"button", 0,
1145 WS_CHILD
| WS_VISIBLE
| BS_AUTOCHECKBOX
,
1148 0, GetWindowLongA (hwnd
, GWL_HINSTANCE
), 0);
1149 SendMessageA (infoPtr
->hwndCheckbut
, BM_SETCHECK
, 1, 0);
1152 if (dwStyle
& DTS_UPDOWN
) {
1153 infoPtr
->hUpdown
=CreateUpDownControl (
1154 WS_CHILD
| WS_BORDER
| WS_VISIBLE
,
1157 UD_MAXVAL
, UD_MINVAL
, 0);
1160 infoPtr
->fieldspec
= (int *) COMCTL32_Alloc (32*sizeof(int));
1161 infoPtr
->fieldRect
= (RECT
*) COMCTL32_Alloc (32*sizeof(RECT
));
1162 infoPtr
->buflen
= (int *) COMCTL32_Alloc (32*sizeof(int));
1163 infoPtr
->nrFieldsAllocated
= 32;
1165 DATETIME_SetFormat (hwnd
, 0, 0);
1167 /* create the monthcal control */
1168 infoPtr
->hMonthCal
= CreateWindowExA (0,"SysMonthCal32", 0,
1169 WS_BORDER
| WS_POPUP
| WS_CLIPSIBLINGS
,
1174 /* initialize info structure */
1175 GetSystemTime (&infoPtr
->date
);
1176 infoPtr
->dateValid
= TRUE
;
1177 infoPtr
->hFont
= GetStockObject(DEFAULT_GUI_FONT
);
1183 DATETIME_Destroy (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1185 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
1188 COMCTL32_Free (infoPtr
);
1189 SetWindowLongA( hwnd
, 0, 0 );
1194 static LRESULT WINAPI
1195 DATETIME_WindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1197 if (!DATETIME_GetInfoPtr(hwnd
) && (uMsg
!= WM_CREATE
))
1198 return DefWindowProcA( hwnd
, uMsg
, wParam
, lParam
);
1203 case DTM_GETSYSTEMTIME
:
1204 return DATETIME_GetSystemTime (hwnd
, wParam
, lParam
);
1206 case DTM_SETSYSTEMTIME
:
1207 return DATETIME_SetSystemTime (hwnd
, wParam
, lParam
);
1210 return DATETIME_GetRange(hwnd
, lParam
);
1213 return DATETIME_SetRange(hwnd
, wParam
, lParam
);
1215 case DTM_SETFORMATA
:
1216 return DATETIME_SetFormat (hwnd
, wParam
, lParam
);
1218 case DTM_SETFORMATW
:
1219 return DATETIME_SetFormatW (hwnd
, wParam
, lParam
);
1221 case DTM_SETMCCOLOR
:
1222 return DATETIME_SetMonthCalColor (hwnd
, wParam
, lParam
);
1224 case DTM_GETMCCOLOR
:
1225 return DATETIME_GetMonthCalColor (hwnd
, wParam
);
1227 case DTM_GETMONTHCAL
:
1228 return DATETIME_GetMonthCal (hwnd
);
1231 return DATETIME_SetMonthCalFont (hwnd
, wParam
, lParam
);
1234 return DATETIME_GetMonthCalFont (hwnd
);
1236 case WM_PARENTNOTIFY
:
1237 return DATETIME_ParentNotify (hwnd
, wParam
, lParam
);
1240 return DATETIME_Notify (hwnd
, wParam
, lParam
);
1243 return DLGC_WANTARROWS
| DLGC_WANTCHARS
;
1246 return DATETIME_Paint (hwnd
, wParam
);
1249 return DATETIME_KeyDown (hwnd
, wParam
, lParam
);
1252 return DATETIME_KillFocus (hwnd
, wParam
, lParam
);
1255 return DATETIME_SetFocus (hwnd
, wParam
, lParam
);
1258 return DATETIME_Size (hwnd
, wParam
, lParam
);
1260 case WM_LBUTTONDOWN
:
1261 return DATETIME_LButtonDown (hwnd
, wParam
, lParam
);
1264 return DATETIME_LButtonUp (hwnd
, wParam
, lParam
);
1267 return DATETIME_Create (hwnd
, wParam
, lParam
);
1270 return DATETIME_Destroy (hwnd
, wParam
, lParam
);
1273 if (uMsg
>= WM_USER
)
1274 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
1275 uMsg
, wParam
, lParam
);
1276 return DefWindowProcA (hwnd
, uMsg
, wParam
, lParam
);
1283 DATETIME_Register (void)
1288 ZeroMemory (&wndClass
, sizeof(WNDCLASSA
));
1289 wndClass
.style
= CS_GLOBALCLASS
;
1290 wndClass
.lpfnWndProc
= (WNDPROC
)DATETIME_WindowProc
;
1291 wndClass
.cbClsExtra
= 0;
1292 wndClass
.cbWndExtra
= sizeof(DATETIME_INFO
*);
1293 wndClass
.hCursor
= LoadCursorA (0, IDC_ARROWA
);
1294 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
1295 wndClass
.lpszClassName
= DATETIMEPICK_CLASSA
;
1297 RegisterClassA (&wndClass
);
1302 DATETIME_Unregister (void)
1305 UnregisterClassA (DATETIMEPICK_CLASSA
, (HINSTANCE
)NULL
);