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
);
51 RECT rcClient
; /* rect around the edge of the window */
52 RECT rcDraw
; /* rect inside of the border */
53 RECT checkbox
; /* checkbox allowing the control to be enabled/disabled */
54 RECT calbutton
; /* button that toggles the dropdown of the monthcal control */
55 BOOL bCalDepressed
; /* TRUE = cal button is depressed */
58 int nrFieldsAllocated
;
66 } DATETIME_INFO
, *LPDATETIME_INFO
;
69 extern int MONTHCAL_MonthLength(int month
, int year
);
71 /* this list of defines is closely related to `allowedformatchars' defined
72 * in datetime.c; the high nibble indicates the `base type' of the format
74 * Do not change without first reading DATETIME_UseFormat.
78 #define DT_END_FORMAT 0
79 #define ONEDIGITDAY 0x01
80 #define TWODIGITDAY 0x02
81 #define THREECHARDAY 0x03
83 #define ONEDIGIT12HOUR 0x11
84 #define TWODIGIT12HOUR 0x12
85 #define ONEDIGIT24HOUR 0x21
86 #define TWODIGIT24HOUR 0x22
87 #define ONEDIGITMINUTE 0x31
88 #define TWODIGITMINUTE 0x32
89 #define ONEDIGITMONTH 0x41
90 #define TWODIGITMONTH 0x42
91 #define THREECHARMONTH 0x43
92 #define FULLMONTH 0x44
93 #define ONEDIGITSECOND 0x51
94 #define TWODIGITSECOND 0x52
95 #define ONELETTERAMPM 0x61
96 #define TWOLETTERAMPM 0x62
97 #define ONEDIGITYEAR 0x71
98 #define TWODIGITYEAR 0x72
99 #define INVALIDFULLYEAR 0x73 /* FIXME - yyy is not valid - we'll treat it as yyyy */
100 #define FULLYEAR 0x74
101 #define FORMATCALLBACK 0x81 /* -> maximum of 0x80 callbacks possible */
102 #define FORMATCALLMASK 0x80
103 #define DT_STRING 0x0100
105 #define DTHT_DATEFIELD 0xff /* for hit-testing */
108 #define DTHT_CHECKBOX 0x200 /* these should end at '00' , to make */
109 #define DTHT_MCPOPUP 0x300 /* & DTHT_DATEFIELD 0 when DATETIME_KeyDown */
110 #define DTHT_GOTFOCUS 0x400 /* tests for date-fields */
112 #define DATETIME_GetInfoPtr(hwnd) ((DATETIME_INFO *)GetWindowLongA (hwnd, 0))
114 static BOOL
DATETIME_SendSimpleNotify (HWND hwnd
, UINT code
);
115 static BOOL
DATETIME_SendDateTimeChangeNotify (HWND hwnd
);
116 extern void MONTHCAL_CopyTime(const SYSTEMTIME
*from
, SYSTEMTIME
*to
);
117 static const char *allowedformatchars
= {"dhHmMstyX'"};
118 static const int maxrepetition
[] = {4,2,2,2,4,2,2,4,-1,-1};
122 DATETIME_GetSystemTime (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
124 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
125 DWORD dwStyle
= GetWindowLongA (hwnd
, GWL_STYLE
);
126 SYSTEMTIME
*lprgSysTimeArray
=(SYSTEMTIME
*) lParam
;
128 TRACE("%04x %08lx\n",wParam
,lParam
);
129 if (!lParam
) return GDT_NONE
;
131 if ((dwStyle
& DTS_SHOWNONE
) &&
132 (SendMessageA (infoPtr
->hwndCheckbut
, BM_GETCHECK
, 0, 0) == BST_UNCHECKED
))
135 MONTHCAL_CopyTime (&infoPtr
->date
, lprgSysTimeArray
);
142 DATETIME_SetSystemTime (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
144 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
145 SYSTEMTIME
*lprgSysTimeArray
=(SYSTEMTIME
*) lParam
;
147 TRACE("%p %04x %08lx\n",hwnd
, wParam
, lParam
);
148 if (!lParam
) return 0;
150 TRACE("%04d/%02d/%02d %02d:%02d:%02d)\n",
151 lprgSysTimeArray
->wYear
, lprgSysTimeArray
->wMonth
, lprgSysTimeArray
->wDay
,
152 lprgSysTimeArray
->wHour
, lprgSysTimeArray
->wMinute
, lprgSysTimeArray
->wSecond
);
154 if (wParam
==GDT_VALID
) {
155 infoPtr
->dateValid
= TRUE
;
156 MONTHCAL_CopyTime (lprgSysTimeArray
, &infoPtr
->date
);
157 SendMessageA (infoPtr
->hwndCheckbut
, BM_SETCHECK
, BST_CHECKED
, 0);
158 } else if (wParam
==GDT_NONE
) {
159 infoPtr
->dateValid
= FALSE
;
160 SendMessageA (infoPtr
->hwndCheckbut
, BM_SETCHECK
, BST_UNCHECKED
, 0);
162 InvalidateRect(hwnd
, NULL
, TRUE
);
168 DATETIME_GetRange (HWND hwnd
, LPARAM lParam
)
170 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
173 TRACE("%08lx\n", lParam
);
174 ret
= SendMessageA (infoPtr
->hMonthCal
, MCM_GETRANGE
, 0, lParam
);
175 if (!ret
) ret
= 1; /* bug emulation... */
180 DATETIME_SetRange (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
182 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
184 TRACE("%04x %08lx\n",wParam
,lParam
);
186 return SendMessageA (infoPtr
->hMonthCal
, MCM_SETRANGE
, wParam
, lParam
);
190 DATETIME_GetMonthCalColor (HWND hwnd
, WPARAM wParam
)
192 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
194 TRACE("%04x\n",wParam
);
195 return SendMessageA (infoPtr
->hMonthCal
, MCM_GETCOLOR
, wParam
, 0);
200 DATETIME_SetMonthCalColor (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
202 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
204 TRACE("%04x %08lx\n",wParam
,lParam
);
205 return SendMessageA (infoPtr
->hMonthCal
, MCM_SETCOLOR
, wParam
, lParam
);
209 /* FIXME: need to get way to force font into monthcal structure */
211 DATETIME_GetMonthCal (HWND hwnd
)
213 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
216 return (LRESULT
)infoPtr
->hMonthCal
;
221 /* FIXME: need to get way to force font into monthcal structure */
224 DATETIME_GetMonthCalFont (HWND hwnd
)
233 DATETIME_SetMonthCalFont (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
236 TRACE("%04x %08lx\n",wParam
,lParam
);
242 Split up a formattxt in actions.
243 See ms documentation for the meaning of the letter codes/'specifiers'.
246 *'dddddd' is handled as 'dddd' plus 'dd'.
247 *unrecognized formats are strings (here given the type DT_STRING;
248 start of the string is encoded in lower bits of DT_STRING.
249 Therefore, 'string' ends finally up as '<show seconds>tring'.
255 DATETIME_UseFormat (DATETIME_INFO
*infoPtr
, const char *formattxt
)
258 int *nrFields
=& infoPtr
->nrFields
;
260 TRACE ("%s\n",formattxt
);
264 infoPtr
->fieldspec
[*nrFields
]=0;
265 len
=strlen(allowedformatchars
);
268 for (i
=0; i
<strlen (formattxt
); i
++) {
269 TRACE ("\n%d %c:",i
, formattxt
[i
]);
270 for (j
=0; j
<len
; j
++) {
271 if (allowedformatchars
[j
]==formattxt
[i
]) {
272 TRACE ("%c[%d,%x]",allowedformatchars
[j
], *nrFields
,
273 infoPtr
->fieldspec
[*nrFields
]);
274 if ((*nrFields
==0) && (infoPtr
->fieldspec
[*nrFields
]==0)) {
275 infoPtr
->fieldspec
[*nrFields
]=(j
<<4) +1;
278 if (infoPtr
->fieldspec
[*nrFields
]>>4!=j
) {
280 infoPtr
->fieldspec
[*nrFields
]=(j
<<4) +1;
283 if ((infoPtr
->fieldspec
[*nrFields
] & 0x0f)==maxrepetition
[j
]) {
285 infoPtr
->fieldspec
[*nrFields
]=(j
<<4) +1;
288 infoPtr
->fieldspec
[*nrFields
]++;
290 } /* if allowedformatchar */
294 /* char is not a specifier: handle char like a string */
296 if ((*nrFields
==0) && (infoPtr
->fieldspec
[*nrFields
]==0)) {
297 infoPtr
->fieldspec
[*nrFields
]=DT_STRING
+k
;
298 infoPtr
->buflen
[*nrFields
]=0;
300 if ((infoPtr
->fieldspec
[*nrFields
] & DT_STRING
)!=DT_STRING
) {
302 infoPtr
->fieldspec
[*nrFields
]=DT_STRING
+k
;
303 infoPtr
->buflen
[*nrFields
]=0;
305 infoPtr
->textbuf
[k
]=formattxt
[i
];
307 infoPtr
->buflen
[*nrFields
]++;
310 if (*nrFields
==infoPtr
->nrFieldsAllocated
) {
311 FIXME ("out of memory; should reallocate. crash ahead.\n");
318 if (infoPtr
->fieldspec
[*nrFields
]!=0) (*nrFields
)++;
323 DATETIME_SetFormat (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
325 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
329 TRACE("%04x %08lx\n",wParam
,lParam
);
331 DWORD dwStyle
= GetWindowLongA (hwnd
, GWL_STYLE
);
333 if (dwStyle
& DTS_LONGDATEFORMAT
)
334 format_item
=LOCALE_SLONGDATE
;
335 else if (dwStyle
& DTS_TIMEFORMAT
)
336 format_item
=LOCALE_STIMEFORMAT
;
337 else /* DTS_SHORTDATEFORMAT */
338 format_item
=LOCALE_SSHORTDATE
;
339 GetLocaleInfoA( GetSystemDefaultLCID(), format_item
,format_buf
,sizeof(format_buf
));
340 DATETIME_UseFormat (infoPtr
, format_buf
);
343 DATETIME_UseFormat (infoPtr
, (char *) lParam
);
345 return infoPtr
->nrFields
;
350 DATETIME_SetFormatW (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
353 TRACE("%04x %08lx\n",wParam
,lParam
);
357 int len
= WideCharToMultiByte( CP_ACP
, 0, (LPWSTR
)lParam
, -1, NULL
, 0, NULL
, NULL
);
359 buf
= (LPSTR
) Alloc (len
);
360 WideCharToMultiByte( CP_ACP
, 0, (LPWSTR
)lParam
, -1, buf
, len
, NULL
, NULL
);
361 retval
=DATETIME_SetFormat (hwnd
, 0, (LPARAM
) buf
);
366 return DATETIME_SetFormat (hwnd
, 0, 0);
372 DATETIME_ReturnTxt (DATETIME_INFO
*infoPtr
, int count
, char *result
, int resultSize
)
374 SYSTEMTIME date
= infoPtr
->date
;
379 TRACE ("%d,%d\n", infoPtr
->nrFields
, count
);
380 if ((count
>infoPtr
->nrFields
) || (count
<0)) {
381 WARN ("buffer overrun, have %d want %d\n", infoPtr
->nrFields
, count
);
385 if (!infoPtr
->fieldspec
) return;
387 spec
=infoPtr
->fieldspec
[count
];
388 if (spec
& DT_STRING
) {
389 int txtlen
=infoPtr
->buflen
[count
];
391 if (txtlen
> resultSize
)
392 txtlen
= resultSize
- 1;
393 memcpy (result
, infoPtr
->textbuf
+ (spec
&~ DT_STRING
), txtlen
);
395 TRACE ("arg%d=%x->[%s]\n",count
,infoPtr
->fieldspec
[count
],result
);
405 sprintf (result
,"%d",date
.wDay
);
408 sprintf (result
,"%.2d",date
.wDay
);
411 GetLocaleInfoA( LOCALE_USER_DEFAULT
, LOCALE_SABBREVDAYNAME1
+(date
.wDayOfWeek
+6)%7,
413 /*sprintf (result,"%.3s",days[date.wDayOfWeek]);*/
416 GetLocaleInfoA( LOCALE_USER_DEFAULT
,LOCALE_SDAYNAME1
+ (date
.wDayOfWeek
+6)%7,
421 sprintf (result
,"%d",date
.wHour
-12);
423 sprintf (result
,"%d",date
.wHour
);
427 sprintf (result
,"%.2d",date
.wHour
-12);
429 sprintf (result
,"%.2d",date
.wHour
);
432 sprintf (result
,"%d",date
.wHour
);
435 sprintf (result
,"%.2d",date
.wHour
);
438 sprintf (result
,"%d",date
.wSecond
);
441 sprintf (result
,"%.2d",date
.wSecond
);
444 sprintf (result
,"%d",date
.wMinute
);
447 sprintf (result
,"%.2d",date
.wMinute
);
450 sprintf (result
,"%d",date
.wMonth
);
453 sprintf (result
,"%.2d",date
.wMonth
);
456 GetLocaleInfoA( GetSystemDefaultLCID(),LOCALE_SMONTHNAME1
+date
.wMonth
-1,
457 buffer
,sizeof(buffer
));
458 sprintf (result
,"%.3s",buffer
);
461 GetLocaleInfoA( GetSystemDefaultLCID(),LOCALE_SMONTHNAME1
+date
.wMonth
-1,
472 strcpy (result
,"AM");
474 strcpy (result
,"PM");
477 FIXME ("Not implemented\n");
478 strcpy (result
,"xxx");
481 sprintf (result
,"%d",date
.wYear
-10* (int) floor(date
.wYear
/10));
484 sprintf (result
,"%.2d",date
.wYear
-100* (int) floor(date
.wYear
/100));
486 case INVALIDFULLYEAR
:
488 sprintf (result
,"%d",date
.wYear
);
492 TRACE ("arg%d=%x->[%s]\n",count
,infoPtr
->fieldspec
[count
],result
);
497 DATETIME_IncreaseField (DATETIME_INFO
*infoPtr
, int number
)
499 SYSTEMTIME
*date
= &infoPtr
->date
;
502 TRACE ("%d\n",number
);
503 if ((number
>infoPtr
->nrFields
) || (number
<0)) return;
505 spec
=infoPtr
->fieldspec
[number
];
506 if ((spec
& DTHT_DATEFIELD
)==0) return;
514 if (date
->wDay
>MONTHCAL_MonthLength(date
->wMonth
,date
->wYear
))
522 if (date
->wHour
>23) date
->wHour
=0;
527 if (date
->wSecond
>59) date
->wSecond
=0;
532 if (date
->wMinute
>59) date
->wMinute
=0;
539 if (date
->wMonth
>12) date
->wMonth
=1;
540 if (date
->wDay
>MONTHCAL_MonthLength(date
->wMonth
,date
->wYear
))
541 date
->wDay
=MONTHCAL_MonthLength(date
->wMonth
,date
->wYear
);
546 if (date
->wHour
>23) date
->wHour
-=24;
549 FIXME ("Not implemented\n");
562 DATETIME_DecreaseField (DATETIME_INFO
*infoPtr
, int number
)
564 SYSTEMTIME
*date
= & infoPtr
->date
;
567 TRACE ("%d\n",number
);
568 if ((number
>infoPtr
->nrFields
) || (number
<0)) return;
570 spec
= infoPtr
->fieldspec
[number
];
571 if ((spec
& DTHT_DATEFIELD
)==0) return;
582 date
->wDay
=MONTHCAL_MonthLength(date
->wMonth
,date
->wYear
);
615 if (date
->wDay
>MONTHCAL_MonthLength(date
->wMonth
,date
->wYear
))
616 date
->wDay
=MONTHCAL_MonthLength(date
->wMonth
,date
->wYear
);
626 FIXME ("Not implemented\n");
639 DATETIME_ResetFieldDown (DATETIME_INFO
*infoPtr
, int number
)
641 SYSTEMTIME
*date
= &infoPtr
->date
;
644 TRACE ("%d\n",number
);
645 if ((number
>infoPtr
->nrFields
) || (number
<0)) return;
647 spec
= infoPtr
->fieldspec
[number
];
648 if ((spec
& DTHT_DATEFIELD
)==0) return;
680 FIXME ("Not implemented\n");
684 /* FYI: On 1752/9/14 the calendar changed and England and the
685 * American colonies changed to the Gregorian calendar. This change
686 * involved having September 14th follow September 2nd. So no date
687 * algorithm works before that date.
693 date
->wDay
= 14; /* overactive ms-programmers..*/
703 DATETIME_ResetFieldUp (DATETIME_INFO
*infoPtr
, int number
)
705 SYSTEMTIME
*date
= & infoPtr
->date
;
708 TRACE("%d \n",number
);
709 if ((number
>infoPtr
->nrFields
) || (number
<0)) return;
711 spec
=infoPtr
->fieldspec
[number
];
712 if ((spec
& DTHT_DATEFIELD
)==0) return;
719 date
->wDay
=MONTHCAL_MonthLength(date
->wMonth
,date
->wYear
);
743 FIXME ("Not implemented\n");
748 date
->wYear
=9999; /* Y10K problem? naaah. */
755 static void DATETIME_Refresh (HWND hwnd
, HDC hdc
)
758 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
761 DWORD dwStyle
= GetWindowLongA (hwnd
, GWL_STYLE
);
762 RECT
*rcDraw
= &infoPtr
->rcDraw
;
763 RECT
*rcClient
= &infoPtr
->rcClient
;
764 RECT
*calbutton
= &infoPtr
->calbutton
;
765 RECT
*checkbox
= &infoPtr
->checkbox
;
768 COLORREF oldBk
, oldTextColor
;
770 /* draw control edge */
772 hbr
= CreateSolidBrush(RGB(255, 255, 255));
773 FillRect(hdc
, rcClient
, hbr
);
774 DrawEdge(hdc
, rcClient
, EDGE_SUNKEN
, BF_RECT
);
777 if (infoPtr
->dateValid
) {
780 oldFont
= SelectObject (hdc
, infoPtr
->hFont
);
782 DATETIME_ReturnTxt (infoPtr
, 0, txt
, sizeof(txt
));
783 GetTextExtentPoint32A (hdc
, txt
, strlen (txt
), &size
);
784 rcDraw
->bottom
= size
.cy
+2;
786 if (dwStyle
& DTS_SHOWNONE
) checkbox
->right
= 18;
788 prevright
= checkbox
->right
;
790 for (i
=0; i
<infoPtr
->nrFields
; i
++) {
791 DATETIME_ReturnTxt (infoPtr
, i
, txt
, sizeof(txt
));
792 GetTextExtentPoint32A (hdc
, txt
, strlen (txt
), &size
);
793 field
= & infoPtr
->fieldRect
[i
];
794 field
->left
= prevright
;
795 field
->right
= prevright
+size
.cx
;
796 field
->top
= rcDraw
->top
;
797 field
->bottom
= rcDraw
->bottom
;
798 prevright
= field
->right
;
800 if ((infoPtr
->haveFocus
) && (i
==infoPtr
->select
)) {
801 hbr
= CreateSolidBrush (GetSysColor (COLOR_ACTIVECAPTION
));
802 FillRect(hdc
, field
, hbr
);
803 oldBk
= SetBkColor (hdc
, GetSysColor(COLOR_ACTIVECAPTION
));
804 oldTextColor
= SetTextColor (hdc
, GetSysColor(COLOR_WINDOW
));
806 DrawTextA ( hdc
, txt
, strlen(txt
), field
,
807 DT_RIGHT
| DT_VCENTER
| DT_SINGLELINE
);
808 SetBkColor (hdc
, oldBk
);
809 SetTextColor (hdc
, oldTextColor
);
812 DrawTextA ( hdc
, txt
, strlen(txt
), field
,
813 DT_RIGHT
| DT_VCENTER
| DT_SINGLELINE
);
816 SelectObject (hdc
, oldFont
);
819 if (!(dwStyle
& DTS_UPDOWN
)) {
820 DrawFrameControl(hdc
, calbutton
, DFC_SCROLL
,
821 DFCS_SCROLLDOWN
| (infoPtr
->bCalDepressed
? DFCS_PUSHED
: 0) |
822 (dwStyle
& WS_DISABLED
? DFCS_INACTIVE
: 0) );
828 DATETIME_HitTest (HWND hwnd
, DATETIME_INFO
*infoPtr
, POINT pt
)
832 TRACE ("%ld, %ld\n",pt
.x
,pt
.y
);
835 if (PtInRect (&infoPtr
->calbutton
, pt
))
836 {retval
= DTHT_MCPOPUP
; TRACE("Hit in calbutton(DTHT_MCPOPUP)\n"); goto done
; }
837 if (PtInRect (&infoPtr
->checkbox
, pt
))
838 {retval
= DTHT_CHECKBOX
; TRACE("Hit in checkbox(DTHT_CHECKBOX)\n"); goto done
; }
840 for (i
=0; i
<infoPtr
->nrFields
; i
++) {
841 if (PtInRect (&infoPtr
->fieldRect
[i
], pt
)) {
843 TRACE("Hit in date text in field %d\n", i
);
854 DATETIME_LButtonDown (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
856 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
857 DWORD dwStyle
= GetWindowLongA (hwnd
, GWL_STYLE
);
863 old
= infoPtr
->select
;
864 pt
.x
= (INT
)LOWORD(lParam
);
865 pt
.y
= (INT
)HIWORD(lParam
);
867 new = DATETIME_HitTest (hwnd
, infoPtr
, pt
);
869 /* FIXME: might be conditions where we don't want to update infoPtr->select */
870 infoPtr
->select
= new;
872 if (infoPtr
->select
!= old
) {
873 infoPtr
->haveFocus
= DTHT_GOTFOCUS
;
876 if (infoPtr
->select
== DTHT_MCPOPUP
) {
877 /* FIXME: button actually is only depressed during dropdown of the */
878 /* calendar control and when the mouse is over the button window */
879 infoPtr
->bCalDepressed
= TRUE
;
881 /* recalculate the position of the monthcal popup */
882 if(dwStyle
& DTS_RIGHTALIGN
)
883 infoPtr
->monthcal_pos
.x
= infoPtr
->rcClient
.right
- ((infoPtr
->calbutton
.right
-
884 infoPtr
->calbutton
.left
) + 145);
886 infoPtr
->monthcal_pos
.x
= 8;
888 infoPtr
->monthcal_pos
.y
= infoPtr
->rcClient
.bottom
;
889 ClientToScreen (hwnd
, &(infoPtr
->monthcal_pos
));
890 SetWindowPos(infoPtr
->hMonthCal
, 0, infoPtr
->monthcal_pos
.x
,
891 infoPtr
->monthcal_pos
.y
, 145, 150, 0);
893 if(IsWindowVisible(infoPtr
->hMonthCal
))
894 ShowWindow(infoPtr
->hMonthCal
, SW_HIDE
);
896 ShowWindow(infoPtr
->hMonthCal
, SW_SHOW
);
898 TRACE ("dt:%p mc:%p mc parent:%p, desktop:%p, mcpp:%p\n",
899 hwnd
,infoPtr
->hMonthCal
,
900 GetParent (infoPtr
->hMonthCal
),
902 GetParent (GetParent (infoPtr
->hMonthCal
)));
903 DATETIME_SendSimpleNotify (hwnd
, DTN_DROPDOWN
);
906 InvalidateRect(hwnd
, NULL
, FALSE
);
913 DATETIME_LButtonUp (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
915 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
919 if(infoPtr
->bCalDepressed
== TRUE
) {
920 infoPtr
->bCalDepressed
= FALSE
;
921 InvalidateRect(hwnd
, &(infoPtr
->calbutton
), TRUE
);
929 DATETIME_Paint (HWND hwnd
, WPARAM wParam
)
934 hdc
= wParam
==0 ? BeginPaint (hwnd
, &ps
) : (HDC
)wParam
;
935 DATETIME_Refresh (hwnd
, hdc
);
937 EndPaint (hwnd
, &ps
);
943 DATETIME_Button_Command (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
945 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr(hwnd
);
947 switch(HIWORD(wParam
)) {
950 DWORD state
= SendMessageA((HWND
)lParam
, BM_GETCHECK
, 0, 0);
951 if(state
== BST_CHECKED
)
952 infoPtr
->dateValid
= TRUE
;
954 infoPtr
->dateValid
= FALSE
;
955 InvalidateRect(hwnd
, NULL
, TRUE
);
966 DATETIME_Command (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
968 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr(hwnd
);
970 TRACE("%08x %08lx\n", wParam
, lParam
);
971 TRACE("hwndbutton = %p\n", infoPtr
->hwndCheckbut
);
972 if(infoPtr
->hwndCheckbut
== (HWND
)lParam
)
973 return DATETIME_Button_Command(hwnd
, wParam
, lParam
);
978 DATETIME_ParentNotify (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
980 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
981 LPNMHDR lpnmh
= (LPNMHDR
) lParam
;
983 TRACE ("%x,%lx\n",wParam
, lParam
);
984 TRACE ("Got notification %x from %p\n", lpnmh
->code
, lpnmh
->hwndFrom
);
985 TRACE ("info: %p %p %p\n",hwnd
,infoPtr
->hMonthCal
,infoPtr
->hUpdown
);
991 DATETIME_Notify (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
994 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
995 LPNMHDR lpnmh
= (LPNMHDR
) lParam
;
997 TRACE ("%x,%lx\n",wParam
, lParam
);
998 TRACE ("Got notification %x from %p\n", lpnmh
->code
, lpnmh
->hwndFrom
);
999 TRACE ("info: %p %p %p\n",hwnd
,infoPtr
->hMonthCal
,infoPtr
->hUpdown
);
1005 DATETIME_KeyDown (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1007 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
1008 int FieldNum
,wrap
=0;
1010 TRACE("%x %lx %x\n",wParam
, lParam
, infoPtr
->select
);
1012 FieldNum
= infoPtr
->select
& DTHT_DATEFIELD
;
1014 if (!(infoPtr
->haveFocus
)) return 0;
1015 if ((FieldNum
==0) && (infoPtr
->select
)) return 0;
1017 if (infoPtr
->select
& FORMATCALLMASK
) {
1018 FIXME ("Callbacks not implemented yet\n");
1024 DATETIME_IncreaseField (infoPtr
,FieldNum
);
1025 DATETIME_SendDateTimeChangeNotify (hwnd
);
1029 DATETIME_DecreaseField (infoPtr
,FieldNum
);
1030 DATETIME_SendDateTimeChangeNotify (hwnd
);
1033 DATETIME_ResetFieldDown (infoPtr
,FieldNum
);
1034 DATETIME_SendDateTimeChangeNotify (hwnd
);
1037 DATETIME_ResetFieldUp(infoPtr
,FieldNum
);
1038 DATETIME_SendDateTimeChangeNotify (hwnd
);
1042 if (infoPtr
->select
==0) {
1043 infoPtr
->select
= infoPtr
->nrFields
- 1;
1048 while ((infoPtr
->fieldspec
[infoPtr
->select
] & DT_STRING
) && (wrap
<2));
1053 if (infoPtr
->select
==infoPtr
->nrFields
) {
1054 infoPtr
->select
= 0;
1058 while ((infoPtr
->fieldspec
[infoPtr
->select
] & DT_STRING
) && (wrap
<2));
1062 InvalidateRect(hwnd
, NULL
, FALSE
);
1069 DATETIME_KillFocus (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1071 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
1075 if (infoPtr
->haveFocus
) {
1076 DATETIME_SendSimpleNotify (hwnd
, NM_KILLFOCUS
);
1077 infoPtr
->haveFocus
= 0;
1080 InvalidateRect (hwnd
, NULL
, TRUE
);
1087 DATETIME_SetFocus (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1089 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
1093 if (infoPtr
->haveFocus
==0) {
1094 DATETIME_SendSimpleNotify (hwnd
, NM_SETFOCUS
);
1095 infoPtr
->haveFocus
= DTHT_GOTFOCUS
;
1098 InvalidateRect(hwnd
, NULL
, FALSE
);
1105 DATETIME_SendDateTimeChangeNotify (HWND hwnd
)
1108 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
1109 NMDATETIMECHANGE dtdtc
;
1112 dtdtc
.nmhdr
.hwndFrom
= hwnd
;
1113 dtdtc
.nmhdr
.idFrom
= GetWindowLongA( hwnd
, GWL_ID
);
1114 dtdtc
.nmhdr
.code
= DTN_DATETIMECHANGE
;
1116 if ((GetWindowLongA (hwnd
, GWL_STYLE
) & DTS_SHOWNONE
))
1117 dtdtc
.dwFlags
= GDT_NONE
;
1119 dtdtc
.dwFlags
= GDT_VALID
;
1121 MONTHCAL_CopyTime (&infoPtr
->date
, &dtdtc
.st
);
1122 return (BOOL
) SendMessageA (GetParent (hwnd
), WM_NOTIFY
,
1123 (WPARAM
)dtdtc
.nmhdr
.idFrom
, (LPARAM
)&dtdtc
);
1128 DATETIME_SendSimpleNotify (HWND hwnd
, UINT code
)
1133 nmhdr
.hwndFrom
= hwnd
;
1134 nmhdr
.idFrom
= GetWindowLongA( hwnd
, GWL_ID
);
1137 return (BOOL
) SendMessageA (GetParent (hwnd
), WM_NOTIFY
,
1138 (WPARAM
)nmhdr
.idFrom
, (LPARAM
)&nmhdr
);
1142 DATETIME_Size (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1144 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr(hwnd
);
1145 DWORD dwStyle
= GetWindowLongA(hwnd
, GWL_STYLE
);
1148 infoPtr
->rcClient
.bottom
= HIWORD(lParam
);
1149 infoPtr
->rcClient
.right
= LOWORD(lParam
);
1151 TRACE("Height=%ld, Width=%ld\n", infoPtr
->rcClient
.bottom
, infoPtr
->rcClient
.right
);
1153 /* use DrawEdge to adjust the size of rcEdge to get rcDraw */
1154 memcpy((&infoPtr
->rcDraw
), (&infoPtr
->rcClient
), sizeof(infoPtr
->rcDraw
));
1156 DrawEdge(NULL
, &(infoPtr
->rcDraw
), EDGE_SUNKEN
, BF_RECT
| BF_ADJUST
);
1158 /* set the size of the button that drops the calendar down */
1159 /* FIXME: account for style that allows button on left side */
1160 infoPtr
->calbutton
.top
= infoPtr
->rcDraw
.top
;
1161 infoPtr
->calbutton
.bottom
= infoPtr
->rcDraw
.bottom
;
1162 infoPtr
->calbutton
.left
= infoPtr
->rcDraw
.right
-15;
1163 infoPtr
->calbutton
.right
= infoPtr
->rcDraw
.right
;
1165 /* set enable/disable button size for show none style being enabled */
1166 /* FIXME: these dimensions are completely incorrect */
1167 infoPtr
->checkbox
.top
= infoPtr
->rcDraw
.top
;
1168 infoPtr
->checkbox
.bottom
= infoPtr
->rcDraw
.bottom
;
1169 infoPtr
->checkbox
.left
= infoPtr
->rcDraw
.left
;
1170 infoPtr
->checkbox
.right
= infoPtr
->rcDraw
.left
+ 10;
1172 /* update the position of the monthcal control */
1173 if(dwStyle
& DTS_RIGHTALIGN
)
1174 infoPtr
->monthcal_pos
.x
= infoPtr
->rcClient
.right
- ((infoPtr
->calbutton
.right
-
1175 infoPtr
->calbutton
.left
) + 145);
1177 infoPtr
->monthcal_pos
.x
= 8;
1179 infoPtr
->monthcal_pos
.y
= infoPtr
->rcClient
.bottom
;
1180 ClientToScreen (hwnd
, &(infoPtr
->monthcal_pos
));
1181 SetWindowPos(infoPtr
->hMonthCal
, 0, infoPtr
->monthcal_pos
.x
,
1182 infoPtr
->monthcal_pos
.y
,
1185 InvalidateRect(hwnd
, NULL
, FALSE
);
1192 DATETIME_Create (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1194 DATETIME_INFO
*infoPtr
;
1195 DWORD dwStyle
= GetWindowLongA (hwnd
, GWL_STYLE
);
1197 /* allocate memory for info structure */
1198 TRACE("%04x %08lx\n",wParam
,lParam
);
1199 infoPtr
= (DATETIME_INFO
*)Alloc (sizeof(DATETIME_INFO
));
1200 if (infoPtr
== NULL
) {
1201 ERR("could not allocate info memory!\n");
1205 SetWindowLongA (hwnd
, 0, (DWORD
)infoPtr
);
1207 if (dwStyle
& DTS_SHOWNONE
) {
1208 infoPtr
->hwndCheckbut
=CreateWindowExA (0,"button", 0,
1209 WS_CHILD
| WS_VISIBLE
| BS_AUTOCHECKBOX
,
1212 0, (HINSTANCE
)GetWindowLongA (hwnd
, GWL_HINSTANCE
), 0);
1213 SendMessageA (infoPtr
->hwndCheckbut
, BM_SETCHECK
, 1, 0);
1216 if (dwStyle
& DTS_UPDOWN
) {
1217 infoPtr
->hUpdown
=CreateUpDownControl (
1218 WS_CHILD
| WS_BORDER
| WS_VISIBLE
,
1221 UD_MAXVAL
, UD_MINVAL
, 0);
1224 infoPtr
->fieldspec
= (int *) Alloc (32*sizeof(int));
1225 infoPtr
->fieldRect
= (RECT
*) Alloc (32*sizeof(RECT
));
1226 infoPtr
->buflen
= (int *) Alloc (32*sizeof(int));
1227 infoPtr
->nrFieldsAllocated
= 32;
1229 DATETIME_SetFormat (hwnd
, 0, 0);
1231 /* create the monthcal control */
1232 infoPtr
->hMonthCal
= CreateWindowExA (0,"SysMonthCal32", 0,
1233 WS_BORDER
| WS_POPUP
| WS_CLIPSIBLINGS
,
1238 /* initialize info structure */
1239 GetSystemTime (&infoPtr
->date
);
1240 infoPtr
->dateValid
= TRUE
;
1241 infoPtr
->hFont
= GetStockObject(DEFAULT_GUI_FONT
);
1247 DATETIME_Destroy (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1249 DATETIME_INFO
*infoPtr
= DATETIME_GetInfoPtr (hwnd
);
1253 SetWindowLongA( hwnd
, 0, 0 );
1258 static LRESULT WINAPI
1259 DATETIME_WindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1261 if (!DATETIME_GetInfoPtr(hwnd
) && (uMsg
!= WM_CREATE
))
1262 return DefWindowProcA( hwnd
, uMsg
, wParam
, lParam
);
1267 case DTM_GETSYSTEMTIME
:
1268 return DATETIME_GetSystemTime (hwnd
, wParam
, lParam
);
1270 case DTM_SETSYSTEMTIME
:
1271 return DATETIME_SetSystemTime (hwnd
, wParam
, lParam
);
1274 return DATETIME_GetRange(hwnd
, lParam
);
1277 return DATETIME_SetRange(hwnd
, wParam
, lParam
);
1279 case DTM_SETFORMATA
:
1280 return DATETIME_SetFormat (hwnd
, wParam
, lParam
);
1282 case DTM_SETFORMATW
:
1283 return DATETIME_SetFormatW (hwnd
, wParam
, lParam
);
1285 case DTM_SETMCCOLOR
:
1286 return DATETIME_SetMonthCalColor (hwnd
, wParam
, lParam
);
1288 case DTM_GETMCCOLOR
:
1289 return DATETIME_GetMonthCalColor (hwnd
, wParam
);
1291 case DTM_GETMONTHCAL
:
1292 return DATETIME_GetMonthCal (hwnd
);
1295 return DATETIME_SetMonthCalFont (hwnd
, wParam
, lParam
);
1298 return DATETIME_GetMonthCalFont (hwnd
);
1300 case WM_PARENTNOTIFY
:
1301 return DATETIME_ParentNotify (hwnd
, wParam
, lParam
);
1304 return DATETIME_Notify (hwnd
, wParam
, lParam
);
1307 return DLGC_WANTARROWS
| DLGC_WANTCHARS
;
1310 return DATETIME_Paint (hwnd
, wParam
);
1313 return DATETIME_KeyDown (hwnd
, wParam
, lParam
);
1316 return DATETIME_KillFocus (hwnd
, wParam
, lParam
);
1319 return DATETIME_SetFocus (hwnd
, wParam
, lParam
);
1322 return DATETIME_Size (hwnd
, wParam
, lParam
);
1324 case WM_LBUTTONDOWN
:
1325 return DATETIME_LButtonDown (hwnd
, wParam
, lParam
);
1328 return DATETIME_LButtonUp (hwnd
, wParam
, lParam
);
1331 return DATETIME_Create (hwnd
, wParam
, lParam
);
1334 return DATETIME_Destroy (hwnd
, wParam
, lParam
);
1337 return DATETIME_Command (hwnd
, wParam
, lParam
);
1340 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
))
1341 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
1342 uMsg
, wParam
, lParam
);
1343 return DefWindowProcA (hwnd
, uMsg
, wParam
, lParam
);
1350 DATETIME_Register (void)
1355 ZeroMemory (&wndClass
, sizeof(WNDCLASSA
));
1356 wndClass
.style
= CS_GLOBALCLASS
;
1357 wndClass
.lpfnWndProc
= (WNDPROC
)DATETIME_WindowProc
;
1358 wndClass
.cbClsExtra
= 0;
1359 wndClass
.cbWndExtra
= sizeof(DATETIME_INFO
*);
1360 wndClass
.hCursor
= LoadCursorA (0, (LPSTR
)IDC_ARROW
);
1361 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
1362 wndClass
.lpszClassName
= DATETIMEPICK_CLASSA
;
1364 RegisterClassA (&wndClass
);
1369 DATETIME_Unregister (void)
1372 UnregisterClassA (DATETIMEPICK_CLASSA
, NULL
);