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.
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(datetime
);
46 RECT rcClient
; /* rect around the edge of the window */
47 RECT rcDraw
; /* rect inside of the border */
48 RECT checkbox
; /* checkbox allowing the control to be enabled/disabled */
49 RECT calbutton
; /* button that toggles the dropdown of the monthcal control */
50 BOOL bCalDepressed
; /* TRUE = cal button is depressed */
53 int nrFieldsAllocated
;
61 } DATETIME_INFO
, *LPDATETIME_INFO
;
64 extern int MONTHCAL_MonthLength(int month
, int year
);
66 /* this list of defines is closely related to `allowedformatchars' defined
67 * in datetime.c; the high nibble indicates the `base type' of the format
69 * Do not change without first reading DATETIME_UseFormat.
73 #define DT_END_FORMAT 0
74 #define ONEDIGITDAY 0x01
75 #define TWODIGITDAY 0x02
76 #define THREECHARDAY 0x03
78 #define ONEDIGIT12HOUR 0x11
79 #define TWODIGIT12HOUR 0x12
80 #define ONEDIGIT24HOUR 0x21
81 #define TWODIGIT24HOUR 0x22
82 #define ONEDIGITMINUTE 0x31
83 #define TWODIGITMINUTE 0x32
84 #define ONEDIGITMONTH 0x41
85 #define TWODIGITMONTH 0x42
86 #define THREECHARMONTH 0x43
87 #define FULLMONTH 0x44
88 #define ONEDIGITSECOND 0x51
89 #define TWODIGITSECOND 0x52
90 #define ONELETTERAMPM 0x61
91 #define TWOLETTERAMPM 0x62
92 #define ONEDIGITYEAR 0x71
93 #define TWODIGITYEAR 0x72
95 #define FORMATCALLBACK 0x81 /* -> maximum of 0x80 callbacks possible */
96 #define FORMATCALLMASK 0x80
97 #define DT_STRING 0x0100
99 #define DTHT_DATEFIELD 0xff /* for hit-testing */
102 #define DTHT_CHECKBOX 0x200 /* these should end at '00' , to make */
103 #define DTHT_MCPOPUP 0x300 /* & DTHT_DATEFIELD 0 when DATETIME_KeyDown */
104 #define DTHT_GOTFOCUS 0x400 /* tests for date-fields */
106 #define DATETIME_GetInfoPtr(hwnd) ((DATETIME_INFO *)GetWindowLongA (hwnd, 0))
108 static BOOL
DATETIME_SendSimpleNotify (HWND hwnd
, UINT code
);
109 static BOOL
DATETIME_SendDateTimeChangeNotify (HWND hwnd
);
110 extern void MONTHCAL_CopyTime(const SYSTEMTIME
*from
, SYSTEMTIME
*to
);
111 static const char *allowedformatchars
= {"dhHmMstyX'"};
112 static const int maxrepetition
[] = {4,2,2,2,4,2,2,3,-1,-1};
116 DATETIME_GetSystemTime (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
118 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
119 DWORD dwStyle
= GetWindowLongA (hwnd
, GWL_STYLE
);
120 SYSTEMTIME
*lprgSysTimeArray
=(SYSTEMTIME
*) lParam
;
122 TRACE("%04x %08lx\n",wParam
,lParam
);
123 if (!lParam
) return GDT_NONE
;
125 if ((dwStyle
& DTS_SHOWNONE
) &&
126 (SendMessageA (infoPtr
->hwndCheckbut
, BM_GETCHECK
, 0, 0)))
129 MONTHCAL_CopyTime (&infoPtr
->date
, lprgSysTimeArray
);
136 DATETIME_SetSystemTime (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
138 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
139 SYSTEMTIME
*lprgSysTimeArray
=(SYSTEMTIME
*) lParam
;
141 TRACE("%04x %08lx\n",wParam
,lParam
);
142 if (!lParam
) return 0;
144 if (lParam
==GDT_VALID
)
145 MONTHCAL_CopyTime (lprgSysTimeArray
, &infoPtr
->date
);
146 if (lParam
==GDT_NONE
) {
147 infoPtr
->dateValid
=FALSE
;
148 SendMessageA (infoPtr
->hwndCheckbut
, BM_SETCHECK
, 0, 0);
155 DATETIME_GetRange (HWND hwnd
, LPARAM lParam
)
157 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
160 TRACE("%08lx\n", lParam
);
161 ret
= SendMessageA (infoPtr
->hMonthCal
, MCM_GETRANGE
, 0, lParam
);
162 if (!ret
) ret
= 1; /* bug emulation... */
167 DATETIME_SetRange (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
169 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
171 TRACE("%04x %08lx\n",wParam
,lParam
);
173 return SendMessageA (infoPtr
->hMonthCal
, MCM_SETRANGE
, wParam
, lParam
);
177 DATETIME_GetMonthCalColor (HWND hwnd
, WPARAM wParam
)
179 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
181 TRACE("%04x\n",wParam
);
182 return SendMessageA (infoPtr
->hMonthCal
, MCM_GETCOLOR
, wParam
, 0);
187 DATETIME_SetMonthCalColor (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
189 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
191 TRACE("%04x %08lx\n",wParam
,lParam
);
192 return SendMessageA (infoPtr
->hMonthCal
, MCM_SETCOLOR
, wParam
, lParam
);
196 /* FIXME: need to get way to force font into monthcal structure */
198 DATETIME_GetMonthCal (HWND hwnd
)
200 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
203 return infoPtr
->hMonthCal
;
208 /* FIXME: need to get way to force font into monthcal structure */
211 DATETIME_GetMonthCalFont (HWND hwnd
)
220 DATETIME_SetMonthCalFont (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
223 TRACE("%04x %08lx\n",wParam
,lParam
);
229 Split up a formattxt in actions.
230 See ms documentation for the meaning of the letter codes/'specifiers'.
233 *'dddddd' is handled as 'dddd' plus 'dd'.
234 *unrecognized formats are strings (here given the type DT_STRING;
235 start of the string is encoded in lower bits of DT_STRING.
236 Therefore, 'string' ends finally up as '<show seconds>tring'.
242 DATETIME_UseFormat (DATETIME_INFO
*infoPtr
, const char *formattxt
)
245 int *nrFields
=& infoPtr
->nrFields
;
247 TRACE ("%s\n",formattxt
);
251 infoPtr
->fieldspec
[*nrFields
]=0;
252 len
=strlen(allowedformatchars
);
255 for (i
=0; i
<strlen (formattxt
); i
++) {
256 TRACE ("\n%d %c:",i
, formattxt
[i
]);
257 for (j
=0; j
<len
; j
++) {
258 if (allowedformatchars
[j
]==formattxt
[i
]) {
259 TRACE ("%c[%d,%x]",allowedformatchars
[j
], *nrFields
,
260 infoPtr
->fieldspec
[*nrFields
]);
261 if ((*nrFields
==0) && (infoPtr
->fieldspec
[*nrFields
]==0)) {
262 infoPtr
->fieldspec
[*nrFields
]=(j
<<4) +1;
265 if (infoPtr
->fieldspec
[*nrFields
]>>4!=j
) {
267 infoPtr
->fieldspec
[*nrFields
]=(j
<<4) +1;
270 if ((infoPtr
->fieldspec
[*nrFields
] & 0x0f)==maxrepetition
[j
]) {
272 infoPtr
->fieldspec
[*nrFields
]=(j
<<4) +1;
275 infoPtr
->fieldspec
[*nrFields
]++;
277 } /* if allowedformatchar */
281 /* char is not a specifier: handle char like a string */
283 if ((*nrFields
==0) && (infoPtr
->fieldspec
[*nrFields
]==0)) {
284 infoPtr
->fieldspec
[*nrFields
]=DT_STRING
+k
;
285 infoPtr
->buflen
[*nrFields
]=0;
287 if ((infoPtr
->fieldspec
[*nrFields
] & DT_STRING
)!=DT_STRING
) {
289 infoPtr
->fieldspec
[*nrFields
]=DT_STRING
+k
;
290 infoPtr
->buflen
[*nrFields
]=0;
292 infoPtr
->textbuf
[k
]=formattxt
[i
];
294 infoPtr
->buflen
[*nrFields
]++;
297 if (*nrFields
==infoPtr
->nrFieldsAllocated
) {
298 FIXME ("out of memory; should reallocate. crash ahead.\n");
305 if (infoPtr
->fieldspec
[*nrFields
]!=0) (*nrFields
)++;
310 DATETIME_SetFormat (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
312 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
316 TRACE("%04x %08lx\n",wParam
,lParam
);
318 DWORD dwStyle
= GetWindowLongA (hwnd
, GWL_STYLE
);
320 if (dwStyle
& DTS_LONGDATEFORMAT
)
321 format_item
=LOCALE_SLONGDATE
;
322 else if (dwStyle
& DTS_TIMEFORMAT
)
323 format_item
=LOCALE_STIMEFORMAT
;
324 else /* DTS_SHORTDATEFORMAT */
325 format_item
=LOCALE_SSHORTDATE
;
326 GetLocaleInfoA( GetSystemDefaultLCID(), format_item
,format_buf
,sizeof(format_buf
));
327 DATETIME_UseFormat (infoPtr
, format_buf
);
330 DATETIME_UseFormat (infoPtr
, (char *) lParam
);
332 return infoPtr
->nrFields
;
337 DATETIME_SetFormatW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
340 TRACE("%04x %08lx\n",wParam
,lParam
);
344 int len
= WideCharToMultiByte( CP_ACP
, 0, (LPWSTR
)lParam
, -1, NULL
, 0, NULL
, NULL
);
346 buf
= (LPSTR
) COMCTL32_Alloc (len
);
347 WideCharToMultiByte( CP_ACP
, 0, (LPWSTR
)lParam
, -1, buf
, len
, NULL
, NULL
);
348 retval
=DATETIME_SetFormat (hwnd
, 0, (LPARAM
) buf
);
353 return DATETIME_SetFormat (hwnd
, 0, 0);
359 DATETIME_ReturnTxt (DATETIME_INFO
*infoPtr
, int count
, char *result
)
361 SYSTEMTIME date
= infoPtr
->date
;
366 TRACE ("%d,%d\n", infoPtr
->nrFields
, count
);
367 if ((count
>infoPtr
->nrFields
) || (count
<0)) {
368 WARN ("buffer overrun, have %d want %d\n", infoPtr
->nrFields
, count
);
372 if (!infoPtr
->fieldspec
) return;
374 spec
=infoPtr
->fieldspec
[count
];
375 if (spec
& DT_STRING
) {
376 int txtlen
=infoPtr
->buflen
[count
];
378 strncpy (result
, infoPtr
->textbuf
+ (spec
&~ DT_STRING
), txtlen
);
380 TRACE ("arg%d=%x->[%s]\n",count
,infoPtr
->fieldspec
[count
],result
);
390 sprintf (result
,"%d",date
.wDay
);
393 sprintf (result
,"%.2d",date
.wDay
);
396 GetLocaleInfoA( LOCALE_USER_DEFAULT
, LOCALE_SABBREVDAYNAME1
+(date
.wDayOfWeek
+6)%7,
398 /*sprintf (result,"%.3s",days[date.wDayOfWeek]);*/
401 GetLocaleInfoA( LOCALE_USER_DEFAULT
,LOCALE_SDAYNAME1
+ (date
.wDayOfWeek
+6)%7,
402 buffer
,sizeof(buffer
));
403 strcpy (result
,buffer
);
407 sprintf (result
,"%d",date
.wHour
-12);
409 sprintf (result
,"%d",date
.wHour
);
413 sprintf (result
,"%.2d",date
.wHour
-12);
415 sprintf (result
,"%.2d",date
.wHour
);
418 sprintf (result
,"%d",date
.wHour
);
421 sprintf (result
,"%.2d",date
.wHour
);
424 sprintf (result
,"%d",date
.wSecond
);
427 sprintf (result
,"%.2d",date
.wSecond
);
430 sprintf (result
,"%d",date
.wMinute
);
433 sprintf (result
,"%.2d",date
.wMinute
);
436 sprintf (result
,"%d",date
.wMonth
);
439 sprintf (result
,"%.2d",date
.wMonth
);
442 GetLocaleInfoA( GetSystemDefaultLCID(),LOCALE_SMONTHNAME1
+date
.wMonth
-1,
443 buffer
,sizeof(buffer
));
444 sprintf (result
,"%.3s",buffer
);
447 GetLocaleInfoA( GetSystemDefaultLCID(),LOCALE_SMONTHNAME1
+date
.wMonth
-1,
448 result
,sizeof(result
));
458 strcpy (result
,"AM");
460 strcpy (result
,"PM");
463 FIXME ("Not implemented\n");
464 strcpy (result
,"xxx");
467 sprintf (result
,"%d",date
.wYear
-10* (int) floor(date
.wYear
/10));
470 sprintf (result
,"%.2d",date
.wYear
-100* (int) floor(date
.wYear
/100));
473 sprintf (result
,"%d",date
.wYear
);
477 TRACE ("arg%d=%x->[%s]\n",count
,infoPtr
->fieldspec
[count
],result
);
482 DATETIME_IncreaseField (DATETIME_INFO
*infoPtr
, int number
)
484 SYSTEMTIME
*date
= &infoPtr
->date
;
487 TRACE ("%d\n",number
);
488 if ((number
>infoPtr
->nrFields
) || (number
<0)) return;
490 spec
=infoPtr
->fieldspec
[number
];
491 if ((spec
& DTHT_DATEFIELD
)==0) return;
499 if (date
->wDay
>MONTHCAL_MonthLength(date
->wMonth
,date
->wYear
))
507 if (date
->wHour
>23) date
->wHour
=0;
512 if (date
->wSecond
>59) date
->wSecond
=0;
517 if (date
->wMinute
>59) date
->wMinute
=0;
524 if (date
->wMonth
>12) date
->wMonth
=1;
525 if (date
->wDay
>MONTHCAL_MonthLength(date
->wMonth
,date
->wYear
))
526 date
->wDay
=MONTHCAL_MonthLength(date
->wMonth
,date
->wYear
);
531 if (date
->wHour
>23) date
->wHour
-=24;
534 FIXME ("Not implemented\n");
547 DATETIME_DecreaseField (DATETIME_INFO
*infoPtr
, int number
)
549 SYSTEMTIME
*date
= & infoPtr
->date
;
552 TRACE ("%d\n",number
);
553 if ((number
>infoPtr
->nrFields
) || (number
<0)) return;
555 spec
= infoPtr
->fieldspec
[number
];
556 if ((spec
& DTHT_DATEFIELD
)==0) return;
567 date
->wDay
=MONTHCAL_MonthLength(date
->wMonth
,date
->wYear
);
600 if (date
->wDay
>MONTHCAL_MonthLength(date
->wMonth
,date
->wYear
))
601 date
->wDay
=MONTHCAL_MonthLength(date
->wMonth
,date
->wYear
);
611 FIXME ("Not implemented\n");
624 DATETIME_ResetFieldDown (DATETIME_INFO
*infoPtr
, int number
)
626 SYSTEMTIME
*date
= &infoPtr
->date
;
629 TRACE ("%d\n",number
);
630 if ((number
>infoPtr
->nrFields
) || (number
<0)) return;
632 spec
= infoPtr
->fieldspec
[number
];
633 if ((spec
& DTHT_DATEFIELD
)==0) return;
665 FIXME ("Not implemented\n");
669 /* FYI: On 1752/9/14 the calendar changed and England and the
670 * American colonies changed to the Gregorian calendar. This change
671 * involved having September 14th follow September 2nd. So no date
672 * algorithm works before that date.
678 date
->wDay
= 14; /* overactive ms-programmers..*/
688 DATETIME_ResetFieldUp (DATETIME_INFO
*infoPtr
, int number
)
690 SYSTEMTIME
*date
= & infoPtr
->date
;
693 TRACE("%d \n",number
);
694 if ((number
>infoPtr
->nrFields
) || (number
<0)) return;
696 spec
=infoPtr
->fieldspec
[number
];
697 if ((spec
& DTHT_DATEFIELD
)==0) return;
704 date
->wDay
=MONTHCAL_MonthLength(date
->wMonth
,date
->wYear
);
728 FIXME ("Not implemented\n");
733 date
->wYear
=9999; /* Y10K problem? naaah. */
740 static void DATETIME_Refresh (HWND hwnd
, HDC hdc
)
743 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
746 DWORD dwStyle
= GetWindowLongA (hwnd
, GWL_STYLE
);
747 RECT
*rcDraw
= &infoPtr
->rcDraw
;
748 RECT
*rcClient
= &infoPtr
->rcClient
;
749 RECT
*calbutton
= &infoPtr
->calbutton
;
750 RECT
*checkbox
= &infoPtr
->checkbox
;
753 COLORREF oldBk
, oldTextColor
;
755 /* draw control edge */
757 hbr
= CreateSolidBrush(RGB(255, 255, 255));
758 FillRect(hdc
, rcClient
, hbr
);
759 DrawEdge(hdc
, rcClient
, EDGE_SUNKEN
, BF_RECT
);
762 if (infoPtr
->dateValid
) {
765 oldFont
= SelectObject (hdc
, infoPtr
->hFont
);
767 DATETIME_ReturnTxt (infoPtr
, 0, txt
);
768 GetTextExtentPoint32A (hdc
, txt
, strlen (txt
), &size
);
769 rcDraw
->bottom
= size
.cy
+2;
771 if (dwStyle
& DTS_SHOWNONE
) checkbox
->right
= 18;
773 prevright
= checkbox
->right
;
775 for (i
=0; i
<infoPtr
->nrFields
; i
++) {
776 DATETIME_ReturnTxt (infoPtr
, i
, txt
);
777 GetTextExtentPoint32A (hdc
, txt
, strlen (txt
), &size
);
778 field
= & infoPtr
->fieldRect
[i
];
779 field
->left
= prevright
;
780 field
->right
= prevright
+size
.cx
;
781 field
->top
= rcDraw
->top
;
782 field
->bottom
= rcDraw
->bottom
;
783 prevright
= field
->right
;
785 if ((infoPtr
->haveFocus
) && (i
==infoPtr
->select
)) {
786 hbr
= CreateSolidBrush (GetSysColor (COLOR_ACTIVECAPTION
));
787 FillRect(hdc
, field
, hbr
);
788 oldBk
= SetBkColor (hdc
, GetSysColor(COLOR_ACTIVECAPTION
));
789 oldTextColor
= SetTextColor (hdc
, GetSysColor(COLOR_WINDOW
));
791 DrawTextA ( hdc
, txt
, strlen(txt
), field
,
792 DT_RIGHT
| DT_VCENTER
| DT_SINGLELINE
);
793 SetBkColor (hdc
, oldBk
);
794 SetTextColor (hdc
, oldTextColor
);
797 DrawTextA ( hdc
, txt
, strlen(txt
), field
,
798 DT_RIGHT
| DT_VCENTER
| DT_SINGLELINE
);
801 SelectObject (hdc
, oldFont
);
804 if (!(dwStyle
& DTS_UPDOWN
)) {
805 DrawFrameControl(hdc
, calbutton
, DFC_SCROLL
,
806 DFCS_SCROLLDOWN
| (infoPtr
->bCalDepressed
? DFCS_PUSHED
: 0) |
807 (dwStyle
& WS_DISABLED
? DFCS_INACTIVE
: 0) );
813 DATETIME_HitTest (HWND hwnd
, DATETIME_INFO
*infoPtr
, POINT pt
)
817 TRACE ("%ld, %ld\n",pt
.x
,pt
.y
);
820 if (PtInRect (&infoPtr
->calbutton
, pt
))
821 {retval
= DTHT_MCPOPUP
; TRACE("Hit in calbutton(DTHT_MCPOPUP)\n"); goto done
; }
822 if (PtInRect (&infoPtr
->checkbox
, pt
))
823 {retval
= DTHT_CHECKBOX
; TRACE("Hit in checkbox(DTHT_CHECKBOX)\n"); goto done
; }
825 for (i
=0; i
<infoPtr
->nrFields
; i
++) {
826 if (PtInRect (&infoPtr
->fieldRect
[i
], pt
)) {
828 TRACE("Hit in date text in field %d\n", i
);
839 DATETIME_LButtonDown (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
841 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
842 DWORD dwStyle
= GetWindowLongA (hwnd
, GWL_STYLE
);
848 old
= infoPtr
->select
;
849 pt
.x
= (INT
)LOWORD(lParam
);
850 pt
.y
= (INT
)HIWORD(lParam
);
852 new = DATETIME_HitTest (hwnd
, infoPtr
, pt
);
854 /* FIXME: might be conditions where we don't want to update infoPtr->select */
855 infoPtr
->select
= new;
857 if (infoPtr
->select
!= old
) {
858 infoPtr
->haveFocus
= DTHT_GOTFOCUS
;
861 if (infoPtr
->select
== DTHT_MCPOPUP
) {
862 /* FIXME: button actually is only depressed during dropdown of the */
863 /* calendar control and when the mouse is over the button window */
864 infoPtr
->bCalDepressed
= TRUE
;
866 /* recalculate the position of the monthcal popup */
867 if(dwStyle
& DTS_RIGHTALIGN
)
868 infoPtr
->monthcal_pos
.x
= infoPtr
->rcClient
.right
- ((infoPtr
->calbutton
.right
-
869 infoPtr
->calbutton
.left
) + 145);
871 infoPtr
->monthcal_pos
.x
= 8;
873 infoPtr
->monthcal_pos
.y
= infoPtr
->rcClient
.bottom
;
874 ClientToScreen (hwnd
, &(infoPtr
->monthcal_pos
));
875 SetWindowPos(infoPtr
->hMonthCal
, 0, infoPtr
->monthcal_pos
.x
,
876 infoPtr
->monthcal_pos
.y
, 145, 150, 0);
878 if(IsWindowVisible(infoPtr
->hMonthCal
))
879 ShowWindow(infoPtr
->hMonthCal
, SW_HIDE
);
881 ShowWindow(infoPtr
->hMonthCal
, SW_SHOW
);
883 TRACE ("dt:%x mc:%x mc parent:%x, desktop:%x, mcpp:%x\n",
884 hwnd
,infoPtr
->hMonthCal
,
885 GetParent (infoPtr
->hMonthCal
),
887 GetParent (GetParent (infoPtr
->hMonthCal
)));
888 DATETIME_SendSimpleNotify (hwnd
, DTN_DROPDOWN
);
891 InvalidateRect(hwnd
, NULL
, FALSE
);
898 DATETIME_LButtonUp (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
900 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
904 if(infoPtr
->bCalDepressed
== TRUE
) {
905 infoPtr
->bCalDepressed
= FALSE
;
906 InvalidateRect(hwnd
, &(infoPtr
->calbutton
), TRUE
);
914 DATETIME_Paint (HWND hwnd
, WPARAM wParam
)
919 hdc
= wParam
==0 ? BeginPaint (hwnd
, &ps
) : (HDC
)wParam
;
920 DATETIME_Refresh (hwnd
, hdc
);
922 EndPaint (hwnd
, &ps
);
928 DATETIME_ParentNotify (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_Notify (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
944 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
945 LPNMHDR lpnmh
= (LPNMHDR
) lParam
;
947 TRACE ("%x,%lx\n",wParam
, lParam
);
948 TRACE ("Got notification %x from %x\n", lpnmh
->code
, lpnmh
->hwndFrom
);
949 TRACE ("info: %x %x %x\n",hwnd
,infoPtr
->hMonthCal
,infoPtr
->hUpdown
);
955 DATETIME_KeyDown (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
957 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
960 TRACE("%x %lx %x\n",wParam
, lParam
, infoPtr
->select
);
962 FieldNum
= infoPtr
->select
& DTHT_DATEFIELD
;
964 if (!(infoPtr
->haveFocus
)) return 0;
965 if ((FieldNum
==0) && (infoPtr
->select
)) return 0;
967 if (infoPtr
->select
& FORMATCALLMASK
) {
968 FIXME ("Callbacks not implemented yet\n");
974 DATETIME_IncreaseField (infoPtr
,FieldNum
);
975 DATETIME_SendDateTimeChangeNotify (hwnd
);
979 DATETIME_DecreaseField (infoPtr
,FieldNum
);
980 DATETIME_SendDateTimeChangeNotify (hwnd
);
983 DATETIME_ResetFieldDown (infoPtr
,FieldNum
);
984 DATETIME_SendDateTimeChangeNotify (hwnd
);
987 DATETIME_ResetFieldUp(infoPtr
,FieldNum
);
988 DATETIME_SendDateTimeChangeNotify (hwnd
);
992 if (infoPtr
->select
==0) {
993 infoPtr
->select
= infoPtr
->nrFields
- 1;
998 while ((infoPtr
->fieldspec
[infoPtr
->select
] & DT_STRING
) && (wrap
<2));
1003 if (infoPtr
->select
==infoPtr
->nrFields
) {
1004 infoPtr
->select
= 0;
1008 while ((infoPtr
->fieldspec
[infoPtr
->select
] & DT_STRING
) && (wrap
<2));
1012 InvalidateRect(hwnd
, NULL
, FALSE
);
1019 DATETIME_KillFocus (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1021 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
1025 if (infoPtr
->haveFocus
) {
1026 DATETIME_SendSimpleNotify (hwnd
, NM_KILLFOCUS
);
1027 infoPtr
->haveFocus
= 0;
1030 InvalidateRect (hwnd
, NULL
, TRUE
);
1037 DATETIME_SetFocus (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1039 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
1043 if (infoPtr
->haveFocus
==0) {
1044 DATETIME_SendSimpleNotify (hwnd
, NM_SETFOCUS
);
1045 infoPtr
->haveFocus
= DTHT_GOTFOCUS
;
1048 InvalidateRect(hwnd
, NULL
, FALSE
);
1055 DATETIME_SendDateTimeChangeNotify (HWND hwnd
)
1058 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
1059 NMDATETIMECHANGE dtdtc
;
1062 dtdtc
.nmhdr
.hwndFrom
= hwnd
;
1063 dtdtc
.nmhdr
.idFrom
= GetWindowLongA( hwnd
, GWL_ID
);
1064 dtdtc
.nmhdr
.code
= DTN_DATETIMECHANGE
;
1066 if ((GetWindowLongA (hwnd
, GWL_STYLE
) & DTS_SHOWNONE
))
1067 dtdtc
.dwFlags
= GDT_NONE
;
1069 dtdtc
.dwFlags
= GDT_VALID
;
1071 MONTHCAL_CopyTime (&infoPtr
->date
, &dtdtc
.st
);
1072 return (BOOL
) SendMessageA (GetParent (hwnd
), WM_NOTIFY
,
1073 (WPARAM
)dtdtc
.nmhdr
.idFrom
, (LPARAM
)&dtdtc
);
1078 DATETIME_SendSimpleNotify (HWND hwnd
, UINT code
)
1083 nmhdr
.hwndFrom
= hwnd
;
1084 nmhdr
.idFrom
= GetWindowLongA( hwnd
, GWL_ID
);
1087 return (BOOL
) SendMessageA (GetParent (hwnd
), WM_NOTIFY
,
1088 (WPARAM
)nmhdr
.idFrom
, (LPARAM
)&nmhdr
);
1092 DATETIME_Size (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1094 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr(hwnd
);
1095 DWORD dwStyle
= GetWindowLongA(hwnd
, GWL_STYLE
);
1098 infoPtr
->rcClient
.bottom
= HIWORD(lParam
);
1099 infoPtr
->rcClient
.right
= LOWORD(lParam
);
1101 TRACE("Height=%d, Width=%d\n", infoPtr
->rcClient
.bottom
, infoPtr
->rcClient
.right
);
1103 /* use DrawEdge to adjust the size of rcEdge to get rcDraw */
1104 memcpy((&infoPtr
->rcDraw
), (&infoPtr
->rcClient
), sizeof(infoPtr
->rcDraw
));
1106 DrawEdge((HDC
)NULL
, &(infoPtr
->rcDraw
), EDGE_SUNKEN
, BF_RECT
| BF_ADJUST
);
1108 /* set the size of the button that drops the calendar down */
1109 /* FIXME: account for style that allows button on left side */
1110 infoPtr
->calbutton
.top
= infoPtr
->rcDraw
.top
;
1111 infoPtr
->calbutton
.bottom
= infoPtr
->rcDraw
.bottom
;
1112 infoPtr
->calbutton
.left
= infoPtr
->rcDraw
.right
-15;
1113 infoPtr
->calbutton
.right
= infoPtr
->rcDraw
.right
;
1115 /* set enable/disable button size for show none style being enabled */
1116 /* FIXME: these dimensions are completely incorrect */
1117 infoPtr
->checkbox
.top
= infoPtr
->rcDraw
.top
;
1118 infoPtr
->checkbox
.bottom
= infoPtr
->rcDraw
.bottom
;
1119 infoPtr
->checkbox
.left
= infoPtr
->rcDraw
.left
;
1120 infoPtr
->checkbox
.right
= infoPtr
->rcDraw
.left
+ 10;
1122 /* update the position of the monthcal control */
1123 if(dwStyle
& DTS_RIGHTALIGN
)
1124 infoPtr
->monthcal_pos
.x
= infoPtr
->rcClient
.right
- ((infoPtr
->calbutton
.right
-
1125 infoPtr
->calbutton
.left
) + 145);
1127 infoPtr
->monthcal_pos
.x
= 8;
1129 infoPtr
->monthcal_pos
.y
= infoPtr
->rcClient
.bottom
;
1130 ClientToScreen (hwnd
, &(infoPtr
->monthcal_pos
));
1131 SetWindowPos(infoPtr
->hMonthCal
, 0, infoPtr
->monthcal_pos
.x
,
1132 infoPtr
->monthcal_pos
.y
,
1135 InvalidateRect(hwnd
, NULL
, FALSE
);
1142 DATETIME_Create (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1144 DATETIME_INFO
*infoPtr
;
1145 DWORD dwStyle
= GetWindowLongA (hwnd
, GWL_STYLE
);
1147 /* allocate memory for info structure */
1148 TRACE("%04x %08lx\n",wParam
,lParam
);
1149 infoPtr
= (DATETIME_INFO
*)COMCTL32_Alloc (sizeof(DATETIME_INFO
));
1150 if (infoPtr
== NULL
) {
1151 ERR("could not allocate info memory!\n");
1155 SetWindowLongA (hwnd
, 0, (DWORD
)infoPtr
);
1157 if (dwStyle
& DTS_SHOWNONE
) {
1158 infoPtr
->hwndCheckbut
=CreateWindowExA (0,"button", 0,
1159 WS_CHILD
| WS_VISIBLE
| BS_AUTOCHECKBOX
,
1162 0, GetWindowLongA (hwnd
, GWL_HINSTANCE
), 0);
1163 SendMessageA (infoPtr
->hwndCheckbut
, BM_SETCHECK
, 1, 0);
1166 if (dwStyle
& DTS_UPDOWN
) {
1167 infoPtr
->hUpdown
=CreateUpDownControl (
1168 WS_CHILD
| WS_BORDER
| WS_VISIBLE
,
1171 UD_MAXVAL
, UD_MINVAL
, 0);
1174 infoPtr
->fieldspec
= (int *) COMCTL32_Alloc (32*sizeof(int));
1175 infoPtr
->fieldRect
= (RECT
*) COMCTL32_Alloc (32*sizeof(RECT
));
1176 infoPtr
->buflen
= (int *) COMCTL32_Alloc (32*sizeof(int));
1177 infoPtr
->nrFieldsAllocated
= 32;
1179 DATETIME_SetFormat (hwnd
, 0, 0);
1181 /* create the monthcal control */
1182 infoPtr
->hMonthCal
= CreateWindowExA (0,"SysMonthCal32", 0,
1183 WS_BORDER
| WS_POPUP
| WS_CLIPSIBLINGS
,
1188 /* initialize info structure */
1189 GetSystemTime (&infoPtr
->date
);
1190 infoPtr
->dateValid
= TRUE
;
1191 infoPtr
->hFont
= GetStockObject(DEFAULT_GUI_FONT
);
1197 DATETIME_Destroy (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1199 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
1202 COMCTL32_Free (infoPtr
);
1203 SetWindowLongA( hwnd
, 0, 0 );
1208 static LRESULT WINAPI
1209 DATETIME_WindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1211 if (!DATETIME_GetInfoPtr(hwnd
) && (uMsg
!= WM_CREATE
))
1212 return DefWindowProcA( hwnd
, uMsg
, wParam
, lParam
);
1217 case DTM_GETSYSTEMTIME
:
1218 return DATETIME_GetSystemTime (hwnd
, wParam
, lParam
);
1220 case DTM_SETSYSTEMTIME
:
1221 return DATETIME_SetSystemTime (hwnd
, wParam
, lParam
);
1224 return DATETIME_GetRange(hwnd
, lParam
);
1227 return DATETIME_SetRange(hwnd
, wParam
, lParam
);
1229 case DTM_SETFORMATA
:
1230 return DATETIME_SetFormat (hwnd
, wParam
, lParam
);
1232 case DTM_SETFORMATW
:
1233 return DATETIME_SetFormatW (hwnd
, wParam
, lParam
);
1235 case DTM_SETMCCOLOR
:
1236 return DATETIME_SetMonthCalColor (hwnd
, wParam
, lParam
);
1238 case DTM_GETMCCOLOR
:
1239 return DATETIME_GetMonthCalColor (hwnd
, wParam
);
1241 case DTM_GETMONTHCAL
:
1242 return DATETIME_GetMonthCal (hwnd
);
1245 return DATETIME_SetMonthCalFont (hwnd
, wParam
, lParam
);
1248 return DATETIME_GetMonthCalFont (hwnd
);
1250 case WM_PARENTNOTIFY
:
1251 return DATETIME_ParentNotify (hwnd
, wParam
, lParam
);
1254 return DATETIME_Notify (hwnd
, wParam
, lParam
);
1257 return DLGC_WANTARROWS
| DLGC_WANTCHARS
;
1260 return DATETIME_Paint (hwnd
, wParam
);
1263 return DATETIME_KeyDown (hwnd
, wParam
, lParam
);
1266 return DATETIME_KillFocus (hwnd
, wParam
, lParam
);
1269 return DATETIME_SetFocus (hwnd
, wParam
, lParam
);
1272 return DATETIME_Size (hwnd
, wParam
, lParam
);
1274 case WM_LBUTTONDOWN
:
1275 return DATETIME_LButtonDown (hwnd
, wParam
, lParam
);
1278 return DATETIME_LButtonUp (hwnd
, wParam
, lParam
);
1281 return DATETIME_Create (hwnd
, wParam
, lParam
);
1284 return DATETIME_Destroy (hwnd
, wParam
, lParam
);
1287 if (uMsg
>= WM_USER
)
1288 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
1289 uMsg
, wParam
, lParam
);
1290 return DefWindowProcA (hwnd
, uMsg
, wParam
, lParam
);
1297 DATETIME_Register (void)
1302 ZeroMemory (&wndClass
, sizeof(WNDCLASSA
));
1303 wndClass
.style
= CS_GLOBALCLASS
;
1304 wndClass
.lpfnWndProc
= (WNDPROC
)DATETIME_WindowProc
;
1305 wndClass
.cbClsExtra
= 0;
1306 wndClass
.cbWndExtra
= sizeof(DATETIME_INFO
*);
1307 wndClass
.hCursor
= LoadCursorA (0, IDC_ARROWA
);
1308 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
1309 wndClass
.lpszClassName
= DATETIMEPICK_CLASSA
;
1311 RegisterClassA (&wndClass
);
1316 DATETIME_Unregister (void)
1319 UnregisterClassA (DATETIMEPICK_CLASSA
, (HINSTANCE
)NULL
);