| 1 | /* | 
|---|
| 2 | * Date and time picker control | 
|---|
| 3 | * | 
|---|
| 4 | * Copyright 1998, 1999 Eric Kohl | 
|---|
| 5 | * Copyright 1999, 2000 Alex Priem <alexp@sci.kun.nl> | 
|---|
| 6 | * Copyright 2000 Chris Morgan <cmorgan@wpi.edu> | 
|---|
| 7 | * | 
|---|
| 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. | 
|---|
| 12 | * | 
|---|
| 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. | 
|---|
| 17 | * | 
|---|
| 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 | 
|---|
| 21 | * | 
|---|
| 22 | * TODO: | 
|---|
| 23 | *   - All messages. | 
|---|
| 24 | *   - All notifications. | 
|---|
| 25 | * | 
|---|
| 26 | */ | 
|---|
| 27 |  | 
|---|
| 28 | #include <math.h> | 
|---|
| 29 | #include <string.h> | 
|---|
| 30 | #include <stdio.h> | 
|---|
| 31 |  | 
|---|
| 32 | #include "winbase.h" | 
|---|
| 33 | #include "wingdi.h" | 
|---|
| 34 | #include "commctrl.h" | 
|---|
| 35 | #include "wine/debug.h" | 
|---|
| 36 |  | 
|---|
| 37 | WINE_DEFAULT_DEBUG_CHANNEL(datetime); | 
|---|
| 38 |  | 
|---|
| 39 | typedef struct | 
|---|
| 40 | { | 
|---|
| 41 | HWND hMonthCal; | 
|---|
| 42 | HWND hUpdown; | 
|---|
| 43 | SYSTEMTIME date; | 
|---|
| 44 | BOOL dateValid; | 
|---|
| 45 | HWND hwndCheckbut; | 
|---|
| 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 */ | 
|---|
| 51 | int  select; | 
|---|
| 52 | HFONT hFont; | 
|---|
| 53 | int nrFieldsAllocated; | 
|---|
| 54 | int nrFields; | 
|---|
| 55 | int haveFocus; | 
|---|
| 56 | int *fieldspec; | 
|---|
| 57 | RECT *fieldRect; | 
|---|
| 58 | int  *buflen; | 
|---|
| 59 | char textbuf[256]; | 
|---|
| 60 | POINT monthcal_pos; | 
|---|
| 61 | } DATETIME_INFO, *LPDATETIME_INFO; | 
|---|
| 62 |  | 
|---|
| 63 | /* in monthcal.c */ | 
|---|
| 64 | extern int MONTHCAL_MonthLength(int month, int year); | 
|---|
| 65 |  | 
|---|
| 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 | 
|---|
| 68 | * specifier. | 
|---|
| 69 | * Do not change without first reading DATETIME_UseFormat. | 
|---|
| 70 | * | 
|---|
| 71 | */ | 
|---|
| 72 |  | 
|---|
| 73 | #define DT_END_FORMAT      0 | 
|---|
| 74 | #define ONEDIGITDAY     0x01 | 
|---|
| 75 | #define TWODIGITDAY     0x02 | 
|---|
| 76 | #define THREECHARDAY    0x03 | 
|---|
| 77 | #define FULLDAY         0x04 | 
|---|
| 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 | 
|---|
| 94 | #define INVALIDFULLYEAR 0x73      /* FIXME - yyy is not valid - we'll treat it as yyyy */ | 
|---|
| 95 | #define FULLYEAR        0x74 | 
|---|
| 96 | #define FORMATCALLBACK  0x81      /* -> maximum of 0x80 callbacks possible */ | 
|---|
| 97 | #define FORMATCALLMASK  0x80 | 
|---|
| 98 | #define DT_STRING       0x0100 | 
|---|
| 99 |  | 
|---|
| 100 | #define DTHT_DATEFIELD  0xff      /* for hit-testing */ | 
|---|
| 101 |  | 
|---|
| 102 | #define DTHT_NONE     0 | 
|---|
| 103 | #define DTHT_CHECKBOX 0x200     /* these should end at '00' , to make */ | 
|---|
| 104 | #define DTHT_MCPOPUP  0x300     /* & DTHT_DATEFIELD 0 when DATETIME_KeyDown */ | 
|---|
| 105 | #define DTHT_GOTFOCUS 0x400     /* tests for date-fields */ | 
|---|
| 106 |  | 
|---|
| 107 | #define DATETIME_GetInfoPtr(hwnd) ((DATETIME_INFO *)GetWindowLongA (hwnd, 0)) | 
|---|
| 108 |  | 
|---|
| 109 | static BOOL DATETIME_SendSimpleNotify (HWND hwnd, UINT code); | 
|---|
| 110 | static BOOL DATETIME_SendDateTimeChangeNotify (HWND hwnd); | 
|---|
| 111 | extern void MONTHCAL_CopyTime(const SYSTEMTIME *from, SYSTEMTIME *to); | 
|---|
| 112 | static const char *allowedformatchars = {"dhHmMstyX'"}; | 
|---|
| 113 | static const int maxrepetition [] = {4,2,2,2,4,2,2,4,-1,-1}; | 
|---|
| 114 |  | 
|---|
| 115 |  | 
|---|
| 116 | static LRESULT | 
|---|
| 117 | DATETIME_GetSystemTime (HWND hwnd, WPARAM wParam, LPARAM lParam ) | 
|---|
| 118 | { | 
|---|
| 119 | DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr (hwnd); | 
|---|
| 120 | DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE); | 
|---|
| 121 | SYSTEMTIME *lprgSysTimeArray=(SYSTEMTIME *) lParam; | 
|---|
| 122 |  | 
|---|
| 123 | TRACE("%04x %08lx\n",wParam,lParam); | 
|---|
| 124 | if (!lParam) return GDT_NONE; | 
|---|
| 125 |  | 
|---|
| 126 | if ((dwStyle & DTS_SHOWNONE) && | 
|---|
| 127 | (SendMessageA (infoPtr->hwndCheckbut, BM_GETCHECK, 0, 0) == BST_UNCHECKED)) | 
|---|
| 128 | return GDT_NONE; | 
|---|
| 129 |  | 
|---|
| 130 | MONTHCAL_CopyTime (&infoPtr->date, lprgSysTimeArray); | 
|---|
| 131 |  | 
|---|
| 132 | return GDT_VALID; | 
|---|
| 133 | } | 
|---|
| 134 |  | 
|---|
| 135 |  | 
|---|
| 136 | static LRESULT | 
|---|
| 137 | DATETIME_SetSystemTime (HWND hwnd, WPARAM wParam, LPARAM lParam ) | 
|---|
| 138 | { | 
|---|
| 139 | DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr (hwnd); | 
|---|
| 140 | SYSTEMTIME *lprgSysTimeArray=(SYSTEMTIME *) lParam; | 
|---|
| 141 |  | 
|---|
| 142 | TRACE("%p %04x %08lx\n",hwnd, wParam, lParam); | 
|---|
| 143 | if (!lParam) return 0; | 
|---|
| 144 |  | 
|---|
| 145 | TRACE("%04d/%02d/%02d %02d:%02d:%02d)\n", | 
|---|
| 146 | lprgSysTimeArray->wYear, lprgSysTimeArray->wMonth, lprgSysTimeArray->wDay, | 
|---|
| 147 | lprgSysTimeArray->wHour, lprgSysTimeArray->wMinute, lprgSysTimeArray->wSecond); | 
|---|
| 148 |  | 
|---|
| 149 | if (wParam==GDT_VALID) { | 
|---|
| 150 | infoPtr->dateValid = TRUE; | 
|---|
| 151 | MONTHCAL_CopyTime (lprgSysTimeArray, &infoPtr->date); | 
|---|
| 152 | SendMessageA (infoPtr->hwndCheckbut, BM_SETCHECK, BST_CHECKED, 0); | 
|---|
| 153 | } else if (wParam==GDT_NONE) { | 
|---|
| 154 | infoPtr->dateValid = FALSE; | 
|---|
| 155 | SendMessageA (infoPtr->hwndCheckbut, BM_SETCHECK, BST_UNCHECKED, 0); | 
|---|
| 156 | } | 
|---|
| 157 | InvalidateRect(hwnd, NULL, TRUE); | 
|---|
| 158 | return 1; | 
|---|
| 159 | } | 
|---|
| 160 |  | 
|---|
| 161 |  | 
|---|
| 162 | static LRESULT | 
|---|
| 163 | DATETIME_GetRange (HWND hwnd, LPARAM lParam ) | 
|---|
| 164 | { | 
|---|
| 165 | DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr (hwnd); | 
|---|
| 166 | LRESULT ret; | 
|---|
| 167 |  | 
|---|
| 168 | TRACE("%08lx\n", lParam); | 
|---|
| 169 | ret =  SendMessageA (infoPtr->hMonthCal, MCM_GETRANGE, 0, lParam); | 
|---|
| 170 | if (!ret) ret = 1; /* bug emulation... */ | 
|---|
| 171 | return ret; | 
|---|
| 172 | } | 
|---|
| 173 |  | 
|---|
| 174 | static LRESULT | 
|---|
| 175 | DATETIME_SetRange (HWND hwnd, WPARAM wParam, LPARAM lParam ) | 
|---|
| 176 | { | 
|---|
| 177 | DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr (hwnd); | 
|---|
| 178 |  | 
|---|
| 179 | TRACE("%04x %08lx\n",wParam,lParam); | 
|---|
| 180 |  | 
|---|
| 181 | return SendMessageA (infoPtr->hMonthCal, MCM_SETRANGE, wParam, lParam); | 
|---|
| 182 | } | 
|---|
| 183 |  | 
|---|
| 184 | static LRESULT | 
|---|
| 185 | DATETIME_GetMonthCalColor (HWND hwnd, WPARAM wParam) | 
|---|
| 186 | { | 
|---|
| 187 | DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr (hwnd); | 
|---|
| 188 |  | 
|---|
| 189 | TRACE("%04x\n",wParam); | 
|---|
| 190 | return SendMessageA (infoPtr->hMonthCal, MCM_GETCOLOR, wParam, 0); | 
|---|
| 191 | } | 
|---|
| 192 |  | 
|---|
| 193 |  | 
|---|
| 194 | static LRESULT | 
|---|
| 195 | DATETIME_SetMonthCalColor (HWND hwnd, WPARAM wParam, LPARAM lParam) | 
|---|
| 196 | { | 
|---|
| 197 | DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr (hwnd); | 
|---|
| 198 |  | 
|---|
| 199 | TRACE("%04x %08lx\n",wParam,lParam); | 
|---|
| 200 | return SendMessageA (infoPtr->hMonthCal, MCM_SETCOLOR, wParam, lParam); | 
|---|
| 201 | } | 
|---|
| 202 |  | 
|---|
| 203 |  | 
|---|
| 204 | /* FIXME: need to get way to force font into monthcal structure */ | 
|---|
| 205 | static LRESULT | 
|---|
| 206 | DATETIME_GetMonthCal (HWND hwnd) | 
|---|
| 207 | { | 
|---|
| 208 | DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr (hwnd); | 
|---|
| 209 |  | 
|---|
| 210 | TRACE("\n"); | 
|---|
| 211 | return (LRESULT)infoPtr->hMonthCal; | 
|---|
| 212 | } | 
|---|
| 213 |  | 
|---|
| 214 |  | 
|---|
| 215 |  | 
|---|
| 216 | /* FIXME: need to get way to force font into monthcal structure */ | 
|---|
| 217 |  | 
|---|
| 218 | static LRESULT | 
|---|
| 219 | DATETIME_GetMonthCalFont (HWND hwnd) | 
|---|
| 220 | { | 
|---|
| 221 |  | 
|---|
| 222 | TRACE("\n"); | 
|---|
| 223 | return 0; | 
|---|
| 224 | } | 
|---|
| 225 |  | 
|---|
| 226 |  | 
|---|
| 227 | static LRESULT | 
|---|
| 228 | DATETIME_SetMonthCalFont (HWND hwnd, WPARAM wParam, LPARAM lParam) | 
|---|
| 229 | { | 
|---|
| 230 |  | 
|---|
| 231 | TRACE("%04x %08lx\n",wParam,lParam); | 
|---|
| 232 | return 0; | 
|---|
| 233 | } | 
|---|
| 234 |  | 
|---|
| 235 |  | 
|---|
| 236 | /* | 
|---|
| 237 | Split up a formattxt in actions. | 
|---|
| 238 | See ms documentation for the meaning of the letter codes/'specifiers'. | 
|---|
| 239 |  | 
|---|
| 240 | Notes: | 
|---|
| 241 | *'dddddd' is handled as 'dddd' plus 'dd'. | 
|---|
| 242 | *unrecognized formats are strings (here given the type DT_STRING; | 
|---|
| 243 | start of the string is encoded in lower bits of DT_STRING. | 
|---|
| 244 | Therefore, 'string' ends finally up as '<show seconds>tring'. | 
|---|
| 245 |  | 
|---|
| 246 | */ | 
|---|
| 247 |  | 
|---|
| 248 |  | 
|---|
| 249 | static void | 
|---|
| 250 | DATETIME_UseFormat (DATETIME_INFO *infoPtr, const char *formattxt) | 
|---|
| 251 | { | 
|---|
| 252 | int i,j,k,len; | 
|---|
| 253 | int *nrFields=& infoPtr->nrFields; | 
|---|
| 254 |  | 
|---|
| 255 | TRACE ("%s\n",formattxt); | 
|---|
| 256 |  | 
|---|
| 257 |  | 
|---|
| 258 | *nrFields=0; | 
|---|
| 259 | infoPtr->fieldspec[*nrFields]=0; | 
|---|
| 260 | len=strlen(allowedformatchars); | 
|---|
| 261 | k=0; | 
|---|
| 262 |  | 
|---|
| 263 | for (i=0; i<strlen (formattxt); i++)  { | 
|---|
| 264 | TRACE ("\n%d %c:",i, formattxt[i]); | 
|---|
| 265 | for (j=0; j<len; j++) { | 
|---|
| 266 | if (allowedformatchars[j]==formattxt[i]) { | 
|---|
| 267 | TRACE ("%c[%d,%x]",allowedformatchars[j], *nrFields, | 
|---|
| 268 | infoPtr->fieldspec[*nrFields]); | 
|---|
| 269 | if ((*nrFields==0) && (infoPtr->fieldspec[*nrFields]==0)) { | 
|---|
| 270 | infoPtr->fieldspec[*nrFields]=(j<<4) +1; | 
|---|
| 271 | break; | 
|---|
| 272 | } | 
|---|
| 273 | if (infoPtr->fieldspec[*nrFields]>>4!=j) { | 
|---|
| 274 | (*nrFields)++; | 
|---|
| 275 | infoPtr->fieldspec[*nrFields]=(j<<4) +1; | 
|---|
| 276 | break; | 
|---|
| 277 | } | 
|---|
| 278 | if ((infoPtr->fieldspec[*nrFields] & 0x0f)==maxrepetition[j]) { | 
|---|
| 279 | (*nrFields)++; | 
|---|
| 280 | infoPtr->fieldspec[*nrFields]=(j<<4) +1; | 
|---|
| 281 | break; | 
|---|
| 282 | } | 
|---|
| 283 | infoPtr->fieldspec[*nrFields]++; | 
|---|
| 284 | break; | 
|---|
| 285 | }   /* if allowedformatchar */ | 
|---|
| 286 | } /* for j */ | 
|---|
| 287 |  | 
|---|
| 288 |  | 
|---|
| 289 | /* char is not a specifier: handle char like a string */ | 
|---|
| 290 | if (j==len) { | 
|---|
| 291 | if ((*nrFields==0) && (infoPtr->fieldspec[*nrFields]==0)) { | 
|---|
| 292 | infoPtr->fieldspec[*nrFields]=DT_STRING+k; | 
|---|
| 293 | infoPtr->buflen[*nrFields]=0; | 
|---|
| 294 | } else | 
|---|
| 295 | if ((infoPtr->fieldspec[*nrFields] & DT_STRING)!=DT_STRING)  { | 
|---|
| 296 | (*nrFields)++; | 
|---|
| 297 | infoPtr->fieldspec[*nrFields]=DT_STRING+k; | 
|---|
| 298 | infoPtr->buflen[*nrFields]=0; | 
|---|
| 299 | } | 
|---|
| 300 | infoPtr->textbuf[k]=formattxt[i]; | 
|---|
| 301 | k++; | 
|---|
| 302 | infoPtr->buflen[*nrFields]++; | 
|---|
| 303 | }   /* if j=len */ | 
|---|
| 304 |  | 
|---|
| 305 | if (*nrFields==infoPtr->nrFieldsAllocated) { | 
|---|
| 306 | FIXME ("out of memory; should reallocate. crash ahead.\n"); | 
|---|
| 307 | } | 
|---|
| 308 |  | 
|---|
| 309 | } /* for i */ | 
|---|
| 310 |  | 
|---|
| 311 | TRACE("\n"); | 
|---|
| 312 |  | 
|---|
| 313 | if (infoPtr->fieldspec[*nrFields]!=0) (*nrFields)++; | 
|---|
| 314 | } | 
|---|
| 315 |  | 
|---|
| 316 |  | 
|---|
| 317 | static LRESULT | 
|---|
| 318 | DATETIME_SetFormat (HWND hwnd, WPARAM wParam, LPARAM lParam) | 
|---|
| 319 | { | 
|---|
| 320 | DATETIME_INFO *infoPtr= DATETIME_GetInfoPtr (hwnd); | 
|---|
| 321 | char format_buf[80]; | 
|---|
| 322 | DWORD format_item; | 
|---|
| 323 |  | 
|---|
| 324 | TRACE("%04x %08lx\n",wParam,lParam); | 
|---|
| 325 | if (!lParam) { | 
|---|
| 326 | DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE); | 
|---|
| 327 |  | 
|---|
| 328 | if (dwStyle & DTS_LONGDATEFORMAT) | 
|---|
| 329 | format_item=LOCALE_SLONGDATE; | 
|---|
| 330 | else if (dwStyle & DTS_TIMEFORMAT) | 
|---|
| 331 | format_item=LOCALE_STIMEFORMAT; | 
|---|
| 332 | else /* DTS_SHORTDATEFORMAT */ | 
|---|
| 333 | format_item=LOCALE_SSHORTDATE; | 
|---|
| 334 | GetLocaleInfoA( GetSystemDefaultLCID(), format_item,format_buf,sizeof(format_buf)); | 
|---|
| 335 | DATETIME_UseFormat (infoPtr, format_buf); | 
|---|
| 336 | } | 
|---|
| 337 | else | 
|---|
| 338 | DATETIME_UseFormat (infoPtr, (char *) lParam); | 
|---|
| 339 |  | 
|---|
| 340 | return infoPtr->nrFields; | 
|---|
| 341 | } | 
|---|
| 342 |  | 
|---|
| 343 |  | 
|---|
| 344 | static LRESULT | 
|---|
| 345 | DATETIME_SetFormatW (HWND hwnd, WPARAM wParam, LPARAM lParam) | 
|---|
| 346 |  | 
|---|
| 347 | { | 
|---|
| 348 | TRACE("%04x %08lx\n",wParam,lParam); | 
|---|
| 349 | if (lParam) { | 
|---|
| 350 | LPSTR buf; | 
|---|
| 351 | int retval; | 
|---|
| 352 | int len = WideCharToMultiByte( CP_ACP, 0, (LPWSTR)lParam, -1, NULL, 0, NULL, NULL ); | 
|---|
| 353 |  | 
|---|
| 354 | buf = (LPSTR) COMCTL32_Alloc (len); | 
|---|
| 355 | WideCharToMultiByte( CP_ACP, 0, (LPWSTR)lParam, -1, buf, len, NULL, NULL ); | 
|---|
| 356 | retval=DATETIME_SetFormat (hwnd, 0, (LPARAM) buf); | 
|---|
| 357 | COMCTL32_Free (buf); | 
|---|
| 358 | return retval; | 
|---|
| 359 | } | 
|---|
| 360 | else | 
|---|
| 361 | return DATETIME_SetFormat (hwnd, 0, 0); | 
|---|
| 362 |  | 
|---|
| 363 | } | 
|---|
| 364 |  | 
|---|
| 365 |  | 
|---|
| 366 | static void | 
|---|
| 367 | DATETIME_ReturnTxt (DATETIME_INFO *infoPtr, int count, char *result, int resultSize) | 
|---|
| 368 | { | 
|---|
| 369 | SYSTEMTIME date = infoPtr->date; | 
|---|
| 370 | int spec; | 
|---|
| 371 | char buffer[80]; | 
|---|
| 372 |  | 
|---|
| 373 | *result=0; | 
|---|
| 374 | TRACE ("%d,%d\n", infoPtr->nrFields, count); | 
|---|
| 375 | if ((count>infoPtr->nrFields) || (count<0)) { | 
|---|
| 376 | WARN ("buffer overrun, have %d want %d\n", infoPtr->nrFields, count); | 
|---|
| 377 | return; | 
|---|
| 378 | } | 
|---|
| 379 |  | 
|---|
| 380 | if (!infoPtr->fieldspec) return; | 
|---|
| 381 |  | 
|---|
| 382 | spec=infoPtr->fieldspec[count]; | 
|---|
| 383 | if (spec & DT_STRING) { | 
|---|
| 384 | int txtlen=infoPtr->buflen[count]; | 
|---|
| 385 |  | 
|---|
| 386 | if (txtlen > resultSize) | 
|---|
| 387 | txtlen = resultSize - 1; | 
|---|
| 388 | memcpy (result, infoPtr->textbuf + (spec &~ DT_STRING), txtlen); | 
|---|
| 389 | result[txtlen]=0; | 
|---|
| 390 | TRACE ("arg%d=%x->[%s]\n",count,infoPtr->fieldspec[count],result); | 
|---|
| 391 | return; | 
|---|
| 392 | } | 
|---|
| 393 |  | 
|---|
| 394 |  | 
|---|
| 395 | switch (spec) { | 
|---|
| 396 | case DT_END_FORMAT: | 
|---|
| 397 | *result=0; | 
|---|
| 398 | break; | 
|---|
| 399 | case ONEDIGITDAY: | 
|---|
| 400 | sprintf (result,"%d",date.wDay); | 
|---|
| 401 | break; | 
|---|
| 402 | case TWODIGITDAY: | 
|---|
| 403 | sprintf (result,"%.2d",date.wDay); | 
|---|
| 404 | break; | 
|---|
| 405 | case THREECHARDAY: | 
|---|
| 406 | GetLocaleInfoA( LOCALE_USER_DEFAULT, LOCALE_SABBREVDAYNAME1+(date.wDayOfWeek+6)%7, | 
|---|
| 407 | result,4); | 
|---|
| 408 | /*sprintf (result,"%.3s",days[date.wDayOfWeek]);*/ | 
|---|
| 409 | break; | 
|---|
| 410 | case FULLDAY: | 
|---|
| 411 | GetLocaleInfoA( LOCALE_USER_DEFAULT,LOCALE_SDAYNAME1+ (date.wDayOfWeek+6)%7, | 
|---|
| 412 | result, resultSize); | 
|---|
| 413 | break; | 
|---|
| 414 | case ONEDIGIT12HOUR: | 
|---|
| 415 | if (date.wHour>12) | 
|---|
| 416 | sprintf (result,"%d",date.wHour-12); | 
|---|
| 417 | else | 
|---|
| 418 | sprintf (result,"%d",date.wHour); | 
|---|
| 419 | break; | 
|---|
| 420 | case TWODIGIT12HOUR: | 
|---|
| 421 | if (date.wHour>12) | 
|---|
| 422 | sprintf (result,"%.2d",date.wHour-12); | 
|---|
| 423 | else | 
|---|
| 424 | sprintf (result,"%.2d",date.wHour); | 
|---|
| 425 | break; | 
|---|
| 426 | case ONEDIGIT24HOUR: | 
|---|
| 427 | sprintf (result,"%d",date.wHour); | 
|---|
| 428 | break; | 
|---|
| 429 | case TWODIGIT24HOUR: | 
|---|
| 430 | sprintf (result,"%.2d",date.wHour); | 
|---|
| 431 | break; | 
|---|
| 432 | case ONEDIGITSECOND: | 
|---|
| 433 | sprintf (result,"%d",date.wSecond); | 
|---|
| 434 | break; | 
|---|
| 435 | case TWODIGITSECOND: | 
|---|
| 436 | sprintf (result,"%.2d",date.wSecond); | 
|---|
| 437 | break; | 
|---|
| 438 | case ONEDIGITMINUTE: | 
|---|
| 439 | sprintf (result,"%d",date.wMinute); | 
|---|
| 440 | break; | 
|---|
| 441 | case TWODIGITMINUTE: | 
|---|
| 442 | sprintf (result,"%.2d",date.wMinute); | 
|---|
| 443 | break; | 
|---|
| 444 | case ONEDIGITMONTH: | 
|---|
| 445 | sprintf (result,"%d",date.wMonth); | 
|---|
| 446 | break; | 
|---|
| 447 | case TWODIGITMONTH: | 
|---|
| 448 | sprintf (result,"%.2d",date.wMonth); | 
|---|
| 449 | break; | 
|---|
| 450 | case THREECHARMONTH: | 
|---|
| 451 | GetLocaleInfoA( GetSystemDefaultLCID(),LOCALE_SMONTHNAME1+date.wMonth -1, | 
|---|
| 452 | buffer,sizeof(buffer)); | 
|---|
| 453 | sprintf (result,"%.3s",buffer); | 
|---|
| 454 | break; | 
|---|
| 455 | case FULLMONTH: | 
|---|
| 456 | GetLocaleInfoA( GetSystemDefaultLCID(),LOCALE_SMONTHNAME1+date.wMonth -1, | 
|---|
| 457 | #ifdef __WIN32OS2__ | 
|---|
| 458 | buffer,sizeof(buffer)); | 
|---|
| 459 | strcpy  (result,buffer); | 
|---|
| 460 | #else | 
|---|
| 461 | result, resultSize); | 
|---|
| 462 | #endif | 
|---|
| 463 | break; | 
|---|
| 464 | case ONELETTERAMPM: | 
|---|
| 465 | if (date.wHour<12) | 
|---|
| 466 | strcpy (result,"A"); | 
|---|
| 467 | else | 
|---|
| 468 | strcpy (result,"P"); | 
|---|
| 469 | break; | 
|---|
| 470 | case TWOLETTERAMPM: | 
|---|
| 471 | if (date.wHour<12) | 
|---|
| 472 | strcpy (result,"AM"); | 
|---|
| 473 | else | 
|---|
| 474 | strcpy (result,"PM"); | 
|---|
| 475 | break; | 
|---|
| 476 | case FORMATCALLBACK: | 
|---|
| 477 | FIXME ("Not implemented\n"); | 
|---|
| 478 | strcpy (result,"xxx"); | 
|---|
| 479 | break; | 
|---|
| 480 | case ONEDIGITYEAR: | 
|---|
| 481 | sprintf (result,"%d",date.wYear-10* (int) floor(date.wYear/10)); | 
|---|
| 482 | break; | 
|---|
| 483 | case TWODIGITYEAR: | 
|---|
| 484 | sprintf (result,"%.2d",date.wYear-100* (int) floor(date.wYear/100)); | 
|---|
| 485 | break; | 
|---|
| 486 | case INVALIDFULLYEAR: | 
|---|
| 487 | case FULLYEAR: | 
|---|
| 488 | sprintf (result,"%d",date.wYear); | 
|---|
| 489 | break; | 
|---|
| 490 | } | 
|---|
| 491 |  | 
|---|
| 492 | TRACE ("arg%d=%x->[%s]\n",count,infoPtr->fieldspec[count],result); | 
|---|
| 493 | } | 
|---|
| 494 |  | 
|---|
| 495 |  | 
|---|
| 496 | static void | 
|---|
| 497 | DATETIME_IncreaseField (DATETIME_INFO *infoPtr, int number) | 
|---|
| 498 | { | 
|---|
| 499 | SYSTEMTIME *date = &infoPtr->date; | 
|---|
| 500 | int spec; | 
|---|
| 501 |  | 
|---|
| 502 | TRACE ("%d\n",number); | 
|---|
| 503 | if ((number>infoPtr->nrFields) || (number<0)) return; | 
|---|
| 504 |  | 
|---|
| 505 | spec=infoPtr->fieldspec[number]; | 
|---|
| 506 | if ((spec & DTHT_DATEFIELD)==0) return; | 
|---|
| 507 |  | 
|---|
| 508 | switch (spec) { | 
|---|
| 509 | case ONEDIGITDAY: | 
|---|
| 510 | case TWODIGITDAY: | 
|---|
| 511 | case THREECHARDAY: | 
|---|
| 512 | case FULLDAY: | 
|---|
| 513 | date->wDay++; | 
|---|
| 514 | if (date->wDay>MONTHCAL_MonthLength(date->wMonth,date->wYear)) | 
|---|
| 515 | date->wDay=1; | 
|---|
| 516 | break; | 
|---|
| 517 | case ONEDIGIT12HOUR: | 
|---|
| 518 | case TWODIGIT12HOUR: | 
|---|
| 519 | case ONEDIGIT24HOUR: | 
|---|
| 520 | case TWODIGIT24HOUR: | 
|---|
| 521 | date->wHour++; | 
|---|
| 522 | if (date->wHour>23) date->wHour=0; | 
|---|
| 523 | break; | 
|---|
| 524 | case ONEDIGITSECOND: | 
|---|
| 525 | case TWODIGITSECOND: | 
|---|
| 526 | date->wSecond++; | 
|---|
| 527 | if (date->wSecond>59) date->wSecond=0; | 
|---|
| 528 | break; | 
|---|
| 529 | case ONEDIGITMINUTE: | 
|---|
| 530 | case TWODIGITMINUTE: | 
|---|
| 531 | date->wMinute++; | 
|---|
| 532 | if (date->wMinute>59) date->wMinute=0; | 
|---|
| 533 | break; | 
|---|
| 534 | case ONEDIGITMONTH: | 
|---|
| 535 | case TWODIGITMONTH: | 
|---|
| 536 | case THREECHARMONTH: | 
|---|
| 537 | case FULLMONTH: | 
|---|
| 538 | date->wMonth++; | 
|---|
| 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); | 
|---|
| 542 | break; | 
|---|
| 543 | case ONELETTERAMPM: | 
|---|
| 544 | case TWOLETTERAMPM: | 
|---|
| 545 | date->wHour+=12; | 
|---|
| 546 | if (date->wHour>23) date->wHour-=24; | 
|---|
| 547 | break; | 
|---|
| 548 | case FORMATCALLBACK: | 
|---|
| 549 | FIXME ("Not implemented\n"); | 
|---|
| 550 | break; | 
|---|
| 551 | case ONEDIGITYEAR: | 
|---|
| 552 | case TWODIGITYEAR: | 
|---|
| 553 | case FULLYEAR: | 
|---|
| 554 | date->wYear++; | 
|---|
| 555 | break; | 
|---|
| 556 | } | 
|---|
| 557 |  | 
|---|
| 558 | } | 
|---|
| 559 |  | 
|---|
| 560 |  | 
|---|
| 561 | static void | 
|---|
| 562 | DATETIME_DecreaseField (DATETIME_INFO *infoPtr, int number) | 
|---|
| 563 | { | 
|---|
| 564 | SYSTEMTIME *date = & infoPtr->date; | 
|---|
| 565 | int spec; | 
|---|
| 566 |  | 
|---|
| 567 | TRACE ("%d\n",number); | 
|---|
| 568 | if ((number>infoPtr->nrFields) || (number<0)) return; | 
|---|
| 569 |  | 
|---|
| 570 | spec = infoPtr->fieldspec[number]; | 
|---|
| 571 | if ((spec & DTHT_DATEFIELD)==0) return; | 
|---|
| 572 |  | 
|---|
| 573 | TRACE ("%x\n",spec); | 
|---|
| 574 |  | 
|---|
| 575 | switch (spec) { | 
|---|
| 576 | case ONEDIGITDAY: | 
|---|
| 577 | case TWODIGITDAY: | 
|---|
| 578 | case THREECHARDAY: | 
|---|
| 579 | case FULLDAY: | 
|---|
| 580 | date->wDay--; | 
|---|
| 581 | if (date->wDay<1) | 
|---|
| 582 | date->wDay=MONTHCAL_MonthLength(date->wMonth,date->wYear); | 
|---|
| 583 | break; | 
|---|
| 584 | case ONEDIGIT12HOUR: | 
|---|
| 585 | case TWODIGIT12HOUR: | 
|---|
| 586 | case ONEDIGIT24HOUR: | 
|---|
| 587 | case TWODIGIT24HOUR: | 
|---|
| 588 | if (date->wHour) | 
|---|
| 589 | date->wHour--; | 
|---|
| 590 | else | 
|---|
| 591 | date->wHour=23; | 
|---|
| 592 | break; | 
|---|
| 593 | case ONEDIGITSECOND: | 
|---|
| 594 | case TWODIGITSECOND: | 
|---|
| 595 | if (date->wHour) | 
|---|
| 596 | date->wSecond--; | 
|---|
| 597 | else | 
|---|
| 598 | date->wHour=59; | 
|---|
| 599 | break; | 
|---|
| 600 | case ONEDIGITMINUTE: | 
|---|
| 601 | case TWODIGITMINUTE: | 
|---|
| 602 | if (date->wMinute) | 
|---|
| 603 | date->wMinute--; | 
|---|
| 604 | else | 
|---|
| 605 | date->wMinute=59; | 
|---|
| 606 | break; | 
|---|
| 607 | case ONEDIGITMONTH: | 
|---|
| 608 | case TWODIGITMONTH: | 
|---|
| 609 | case THREECHARMONTH: | 
|---|
| 610 | case FULLMONTH: | 
|---|
| 611 | if (date->wMonth>1) | 
|---|
| 612 | date->wMonth--; | 
|---|
| 613 | else | 
|---|
| 614 | date->wMonth=12; | 
|---|
| 615 | if (date->wDay>MONTHCAL_MonthLength(date->wMonth,date->wYear)) | 
|---|
| 616 | date->wDay=MONTHCAL_MonthLength(date->wMonth,date->wYear); | 
|---|
| 617 | break; | 
|---|
| 618 | case ONELETTERAMPM: | 
|---|
| 619 | case TWOLETTERAMPM: | 
|---|
| 620 | if (date->wHour<12) | 
|---|
| 621 | date->wHour+=12; | 
|---|
| 622 | else | 
|---|
| 623 | date->wHour-=12; | 
|---|
| 624 | break; | 
|---|
| 625 | case FORMATCALLBACK: | 
|---|
| 626 | FIXME ("Not implemented\n"); | 
|---|
| 627 | break; | 
|---|
| 628 | case ONEDIGITYEAR: | 
|---|
| 629 | case TWODIGITYEAR: | 
|---|
| 630 | case FULLYEAR: | 
|---|
| 631 | date->wYear--; | 
|---|
| 632 | break; | 
|---|
| 633 | } | 
|---|
| 634 |  | 
|---|
| 635 | } | 
|---|
| 636 |  | 
|---|
| 637 |  | 
|---|
| 638 | static void | 
|---|
| 639 | DATETIME_ResetFieldDown (DATETIME_INFO *infoPtr, int number) | 
|---|
| 640 | { | 
|---|
| 641 | SYSTEMTIME *date = &infoPtr->date; | 
|---|
| 642 | int spec; | 
|---|
| 643 |  | 
|---|
| 644 | TRACE ("%d\n",number); | 
|---|
| 645 | if ((number>infoPtr->nrFields) || (number<0)) return; | 
|---|
| 646 |  | 
|---|
| 647 | spec = infoPtr->fieldspec[number]; | 
|---|
| 648 | if ((spec & DTHT_DATEFIELD)==0) return; | 
|---|
| 649 |  | 
|---|
| 650 |  | 
|---|
| 651 | switch (spec) { | 
|---|
| 652 | case ONEDIGITDAY: | 
|---|
| 653 | case TWODIGITDAY: | 
|---|
| 654 | case THREECHARDAY: | 
|---|
| 655 | case FULLDAY: | 
|---|
| 656 | date->wDay = 1; | 
|---|
| 657 | break; | 
|---|
| 658 | case ONEDIGIT12HOUR: | 
|---|
| 659 | case TWODIGIT12HOUR: | 
|---|
| 660 | case ONEDIGIT24HOUR: | 
|---|
| 661 | case TWODIGIT24HOUR: | 
|---|
| 662 | case ONELETTERAMPM: | 
|---|
| 663 | case TWOLETTERAMPM: | 
|---|
| 664 | date->wHour = 0; | 
|---|
| 665 | break; | 
|---|
| 666 | case ONEDIGITSECOND: | 
|---|
| 667 | case TWODIGITSECOND: | 
|---|
| 668 | date->wSecond = 0; | 
|---|
| 669 | break; | 
|---|
| 670 | case ONEDIGITMINUTE: | 
|---|
| 671 | case TWODIGITMINUTE: | 
|---|
| 672 | date->wMinute = 0; | 
|---|
| 673 | break; | 
|---|
| 674 | case ONEDIGITMONTH: | 
|---|
| 675 | case TWODIGITMONTH: | 
|---|
| 676 | case THREECHARMONTH: | 
|---|
| 677 | case FULLMONTH: | 
|---|
| 678 | date->wMonth = 1; | 
|---|
| 679 | case FORMATCALLBACK: | 
|---|
| 680 | FIXME ("Not implemented\n"); | 
|---|
| 681 | break; | 
|---|
| 682 | case ONEDIGITYEAR: | 
|---|
| 683 | case TWODIGITYEAR: | 
|---|
| 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. | 
|---|
| 688 | */ | 
|---|
| 689 | case FULLYEAR: | 
|---|
| 690 | date->wSecond = 0; | 
|---|
| 691 | date->wMinute = 0; | 
|---|
| 692 | date->wHour = 0; | 
|---|
| 693 | date->wDay = 14;                /* overactive ms-programmers..*/ | 
|---|
| 694 | date->wMonth = 9; | 
|---|
| 695 | date->wYear = 1752; | 
|---|
| 696 | break; | 
|---|
| 697 | } | 
|---|
| 698 |  | 
|---|
| 699 | } | 
|---|
| 700 |  | 
|---|
| 701 |  | 
|---|
| 702 | static void | 
|---|
| 703 | DATETIME_ResetFieldUp (DATETIME_INFO *infoPtr, int number) | 
|---|
| 704 | { | 
|---|
| 705 | SYSTEMTIME *date = & infoPtr->date; | 
|---|
| 706 | int spec; | 
|---|
| 707 |  | 
|---|
| 708 | TRACE("%d \n",number); | 
|---|
| 709 | if ((number>infoPtr->nrFields) || (number<0)) return; | 
|---|
| 710 |  | 
|---|
| 711 | spec=infoPtr->fieldspec[number]; | 
|---|
| 712 | if ((spec & DTHT_DATEFIELD)==0) return; | 
|---|
| 713 |  | 
|---|
| 714 | switch (spec) { | 
|---|
| 715 | case ONEDIGITDAY: | 
|---|
| 716 | case TWODIGITDAY: | 
|---|
| 717 | case THREECHARDAY: | 
|---|
| 718 | case FULLDAY: | 
|---|
| 719 | date->wDay=MONTHCAL_MonthLength(date->wMonth,date->wYear); | 
|---|
| 720 | break; | 
|---|
| 721 | case ONEDIGIT12HOUR: | 
|---|
| 722 | case TWODIGIT12HOUR: | 
|---|
| 723 | case ONEDIGIT24HOUR: | 
|---|
| 724 | case TWODIGIT24HOUR: | 
|---|
| 725 | case ONELETTERAMPM: | 
|---|
| 726 | case TWOLETTERAMPM: | 
|---|
| 727 | date->wHour=23; | 
|---|
| 728 | break; | 
|---|
| 729 | case ONEDIGITSECOND: | 
|---|
| 730 | case TWODIGITSECOND: | 
|---|
| 731 | date->wSecond=59; | 
|---|
| 732 | break; | 
|---|
| 733 | case ONEDIGITMINUTE: | 
|---|
| 734 | case TWODIGITMINUTE: | 
|---|
| 735 | date->wMinute=59; | 
|---|
| 736 | break; | 
|---|
| 737 | case ONEDIGITMONTH: | 
|---|
| 738 | case TWODIGITMONTH: | 
|---|
| 739 | case THREECHARMONTH: | 
|---|
| 740 | case FULLMONTH: | 
|---|
| 741 | date->wMonth=12; | 
|---|
| 742 | case FORMATCALLBACK: | 
|---|
| 743 | FIXME ("Not implemented\n"); | 
|---|
| 744 | break; | 
|---|
| 745 | case ONEDIGITYEAR: | 
|---|
| 746 | case TWODIGITYEAR: | 
|---|
| 747 | case FULLYEAR: | 
|---|
| 748 | date->wYear=9999;    /* Y10K problem? naaah. */ | 
|---|
| 749 | break; | 
|---|
| 750 | } | 
|---|
| 751 |  | 
|---|
| 752 | } | 
|---|
| 753 |  | 
|---|
| 754 |  | 
|---|
| 755 | static void DATETIME_Refresh (HWND hwnd, HDC hdc) | 
|---|
| 756 |  | 
|---|
| 757 | { | 
|---|
| 758 | DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr (hwnd); | 
|---|
| 759 | int i,prevright; | 
|---|
| 760 | RECT *field; | 
|---|
| 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; | 
|---|
| 766 | HBRUSH hbr; | 
|---|
| 767 | SIZE size; | 
|---|
| 768 | COLORREF oldBk, oldTextColor; | 
|---|
| 769 |  | 
|---|
| 770 | /* draw control edge */ | 
|---|
| 771 | TRACE("\n"); | 
|---|
| 772 | hbr = CreateSolidBrush(RGB(255, 255, 255)); | 
|---|
| 773 | FillRect(hdc, rcClient, hbr); | 
|---|
| 774 | DrawEdge(hdc, rcClient, EDGE_SUNKEN, BF_RECT); | 
|---|
| 775 | DeleteObject(hbr); | 
|---|
| 776 |  | 
|---|
| 777 | if (infoPtr->dateValid) { | 
|---|
| 778 | char txt[80]; | 
|---|
| 779 | HFONT oldFont; | 
|---|
| 780 | oldFont = SelectObject (hdc, infoPtr->hFont); | 
|---|
| 781 |  | 
|---|
| 782 | DATETIME_ReturnTxt (infoPtr, 0, txt, sizeof(txt)); | 
|---|
| 783 | GetTextExtentPoint32A (hdc, txt, strlen (txt), &size); | 
|---|
| 784 | rcDraw->bottom = size.cy+2; | 
|---|
| 785 |  | 
|---|
| 786 | if (dwStyle & DTS_SHOWNONE) checkbox->right = 18; | 
|---|
| 787 |  | 
|---|
| 788 | prevright = checkbox->right; | 
|---|
| 789 |  | 
|---|
| 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; | 
|---|
| 799 |  | 
|---|
| 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)); | 
|---|
| 805 | DeleteObject (hbr); | 
|---|
| 806 | DrawTextA ( hdc, txt, strlen(txt), field, | 
|---|
| 807 | DT_RIGHT | DT_VCENTER | DT_SINGLELINE ); | 
|---|
| 808 | SetBkColor (hdc, oldBk); | 
|---|
| 809 | SetTextColor (hdc, oldTextColor); | 
|---|
| 810 | } | 
|---|
| 811 | else | 
|---|
| 812 | DrawTextA ( hdc, txt, strlen(txt), field, | 
|---|
| 813 | DT_RIGHT | DT_VCENTER | DT_SINGLELINE ); | 
|---|
| 814 | } | 
|---|
| 815 |  | 
|---|
| 816 | SelectObject (hdc, oldFont); | 
|---|
| 817 | } | 
|---|
| 818 |  | 
|---|
| 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) ); | 
|---|
| 823 | } | 
|---|
| 824 | } | 
|---|
| 825 |  | 
|---|
| 826 |  | 
|---|
| 827 | static LRESULT | 
|---|
| 828 | DATETIME_HitTest (HWND hwnd, DATETIME_INFO *infoPtr, POINT pt) | 
|---|
| 829 | { | 
|---|
| 830 | int i, retval; | 
|---|
| 831 |  | 
|---|
| 832 | TRACE ("%ld, %ld\n",pt.x,pt.y); | 
|---|
| 833 |  | 
|---|
| 834 | retval = DTHT_NONE; | 
|---|
| 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; } | 
|---|
| 839 |  | 
|---|
| 840 | for (i=0; i<infoPtr->nrFields; i++) { | 
|---|
| 841 | if (PtInRect (&infoPtr->fieldRect[i], pt)) { | 
|---|
| 842 | retval = i; | 
|---|
| 843 | TRACE("Hit in date text in field %d\n", i); | 
|---|
| 844 | break; | 
|---|
| 845 | } | 
|---|
| 846 | } | 
|---|
| 847 |  | 
|---|
| 848 | done: | 
|---|
| 849 | return retval; | 
|---|
| 850 | } | 
|---|
| 851 |  | 
|---|
| 852 |  | 
|---|
| 853 | static LRESULT | 
|---|
| 854 | DATETIME_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam) | 
|---|
| 855 | { | 
|---|
| 856 | DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr (hwnd); | 
|---|
| 857 | DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE); | 
|---|
| 858 | int old, new; | 
|---|
| 859 | POINT pt; | 
|---|
| 860 |  | 
|---|
| 861 | TRACE ("\n"); | 
|---|
| 862 |  | 
|---|
| 863 | old = infoPtr->select; | 
|---|
| 864 | pt.x = (INT)LOWORD(lParam); | 
|---|
| 865 | pt.y = (INT)HIWORD(lParam); | 
|---|
| 866 |  | 
|---|
| 867 | new = DATETIME_HitTest (hwnd, infoPtr, pt); | 
|---|
| 868 |  | 
|---|
| 869 | /* FIXME: might be conditions where we don't want to update infoPtr->select */ | 
|---|
| 870 | infoPtr->select = new; | 
|---|
| 871 |  | 
|---|
| 872 | if (infoPtr->select != old) { | 
|---|
| 873 | infoPtr->haveFocus = DTHT_GOTFOCUS; | 
|---|
| 874 | } | 
|---|
| 875 |  | 
|---|
| 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; | 
|---|
| 880 |  | 
|---|
| 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); | 
|---|
| 885 | else | 
|---|
| 886 | infoPtr->monthcal_pos.x = 8; | 
|---|
| 887 |  | 
|---|
| 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); | 
|---|
| 892 |  | 
|---|
| 893 | if(IsWindowVisible(infoPtr->hMonthCal)) | 
|---|
| 894 | ShowWindow(infoPtr->hMonthCal, SW_HIDE); | 
|---|
| 895 | else | 
|---|
| 896 | ShowWindow(infoPtr->hMonthCal, SW_SHOW); | 
|---|
| 897 |  | 
|---|
| 898 | TRACE ("dt:%p mc:%p mc parent:%p, desktop:%p, mcpp:%p\n", | 
|---|
| 899 | hwnd,infoPtr->hMonthCal, | 
|---|
| 900 | GetParent (infoPtr->hMonthCal), | 
|---|
| 901 | GetDesktopWindow (), | 
|---|
| 902 | GetParent (GetParent (infoPtr->hMonthCal))); | 
|---|
| 903 | DATETIME_SendSimpleNotify (hwnd, DTN_DROPDOWN); | 
|---|
| 904 | } | 
|---|
| 905 |  | 
|---|
| 906 | InvalidateRect(hwnd, NULL, FALSE); | 
|---|
| 907 |  | 
|---|
| 908 | return 0; | 
|---|
| 909 | } | 
|---|
| 910 |  | 
|---|
| 911 |  | 
|---|
| 912 | static LRESULT | 
|---|
| 913 | DATETIME_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam) | 
|---|
| 914 | { | 
|---|
| 915 | DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr (hwnd); | 
|---|
| 916 |  | 
|---|
| 917 | TRACE("\n"); | 
|---|
| 918 |  | 
|---|
| 919 | if(infoPtr->bCalDepressed == TRUE) { | 
|---|
| 920 | infoPtr->bCalDepressed = FALSE; | 
|---|
| 921 | InvalidateRect(hwnd, &(infoPtr->calbutton), TRUE); | 
|---|
| 922 | } | 
|---|
| 923 |  | 
|---|
| 924 | return 0; | 
|---|
| 925 | } | 
|---|
| 926 |  | 
|---|
| 927 |  | 
|---|
| 928 | static LRESULT | 
|---|
| 929 | DATETIME_Paint (HWND hwnd, WPARAM wParam) | 
|---|
| 930 | { | 
|---|
| 931 | HDC hdc; | 
|---|
| 932 | PAINTSTRUCT ps; | 
|---|
| 933 |  | 
|---|
| 934 | hdc = wParam==0 ? BeginPaint (hwnd, &ps) : (HDC)wParam; | 
|---|
| 935 | DATETIME_Refresh (hwnd, hdc); | 
|---|
| 936 | if(!wParam) | 
|---|
| 937 | EndPaint (hwnd, &ps); | 
|---|
| 938 | return 0; | 
|---|
| 939 | } | 
|---|
| 940 |  | 
|---|
| 941 |  | 
|---|
| 942 | static LRESULT | 
|---|
| 943 | DATETIME_Button_Command (HWND hwnd, WPARAM wParam, LPARAM lParam) | 
|---|
| 944 | { | 
|---|
| 945 | DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr(hwnd); | 
|---|
| 946 |  | 
|---|
| 947 | switch(HIWORD(wParam)) { | 
|---|
| 948 | case BN_CLICKED: | 
|---|
| 949 | { | 
|---|
| 950 | DWORD state = SendMessageA((HWND)lParam, BM_GETCHECK, 0, 0); | 
|---|
| 951 | if(state == BST_CHECKED) | 
|---|
| 952 | infoPtr->dateValid = TRUE; | 
|---|
| 953 | else | 
|---|
| 954 | infoPtr->dateValid = FALSE; | 
|---|
| 955 | InvalidateRect(hwnd, NULL, TRUE); | 
|---|
| 956 | return 0; | 
|---|
| 957 | } | 
|---|
| 958 | default: | 
|---|
| 959 | return 0; | 
|---|
| 960 | } | 
|---|
| 961 | } | 
|---|
| 962 |  | 
|---|
| 963 |  | 
|---|
| 964 |  | 
|---|
| 965 | static LRESULT | 
|---|
| 966 | DATETIME_Command (HWND hwnd, WPARAM wParam, LPARAM lParam) | 
|---|
| 967 | { | 
|---|
| 968 | DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr(hwnd); | 
|---|
| 969 |  | 
|---|
| 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); | 
|---|
| 974 | return 0; | 
|---|
| 975 | } | 
|---|
| 976 |  | 
|---|
| 977 | static LRESULT | 
|---|
| 978 | DATETIME_ParentNotify (HWND hwnd, WPARAM wParam, LPARAM lParam) | 
|---|
| 979 | { | 
|---|
| 980 | DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr (hwnd); | 
|---|
| 981 | LPNMHDR lpnmh = (LPNMHDR) lParam; | 
|---|
| 982 |  | 
|---|
| 983 | #ifdef __WIN32OS2__ | 
|---|
| 984 | //DT: if lParam a pointer or a handle | 
|---|
| 985 | //    if the index forgotten or is it zero | 
|---|
| 986 | TRACE ("DATETIME_ParentNotify %x,%lx\n",wParam, lParam); | 
|---|
| 987 | #else | 
|---|
| 988 | TRACE ("%x,%lx\n",wParam, lParam); | 
|---|
| 989 | TRACE ("Got notification %x from %p\n", lpnmh->code, lpnmh->hwndFrom); | 
|---|
| 990 | #endif | 
|---|
| 991 | TRACE ("info: %p %p %p\n",hwnd,infoPtr->hMonthCal,infoPtr->hUpdown); | 
|---|
| 992 | return 0; | 
|---|
| 993 | } | 
|---|
| 994 |  | 
|---|
| 995 |  | 
|---|
| 996 | static LRESULT | 
|---|
| 997 | DATETIME_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam) | 
|---|
| 998 |  | 
|---|
| 999 | { | 
|---|
| 1000 | DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr (hwnd); | 
|---|
| 1001 | LPNMHDR lpnmh = (LPNMHDR) lParam; | 
|---|
| 1002 |  | 
|---|
| 1003 | TRACE ("%x,%lx\n",wParam, lParam); | 
|---|
| 1004 | TRACE ("Got notification %x from %p\n", lpnmh->code, lpnmh->hwndFrom); | 
|---|
| 1005 | TRACE ("info: %p %p %p\n",hwnd,infoPtr->hMonthCal,infoPtr->hUpdown); | 
|---|
| 1006 | return 0; | 
|---|
| 1007 | } | 
|---|
| 1008 |  | 
|---|
| 1009 |  | 
|---|
| 1010 | static LRESULT | 
|---|
| 1011 | DATETIME_KeyDown (HWND hwnd, WPARAM wParam, LPARAM lParam) | 
|---|
| 1012 | { | 
|---|
| 1013 | DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr (hwnd); | 
|---|
| 1014 | int FieldNum,wrap=0; | 
|---|
| 1015 |  | 
|---|
| 1016 | TRACE("%x %lx %x\n",wParam, lParam, infoPtr->select); | 
|---|
| 1017 |  | 
|---|
| 1018 | FieldNum = infoPtr->select & DTHT_DATEFIELD; | 
|---|
| 1019 |  | 
|---|
| 1020 | if (!(infoPtr->haveFocus)) return 0; | 
|---|
| 1021 | if ((FieldNum==0) && (infoPtr->select)) return 0; | 
|---|
| 1022 |  | 
|---|
| 1023 | if (infoPtr->select & FORMATCALLMASK) { | 
|---|
| 1024 | FIXME ("Callbacks not implemented yet\n"); | 
|---|
| 1025 | } | 
|---|
| 1026 |  | 
|---|
| 1027 | switch (wParam) { | 
|---|
| 1028 | case VK_ADD: | 
|---|
| 1029 | case VK_UP: | 
|---|
| 1030 | DATETIME_IncreaseField (infoPtr,FieldNum); | 
|---|
| 1031 | DATETIME_SendDateTimeChangeNotify (hwnd); | 
|---|
| 1032 | break; | 
|---|
| 1033 | case VK_SUBTRACT: | 
|---|
| 1034 | case VK_DOWN: | 
|---|
| 1035 | DATETIME_DecreaseField (infoPtr,FieldNum); | 
|---|
| 1036 | DATETIME_SendDateTimeChangeNotify (hwnd); | 
|---|
| 1037 | break; | 
|---|
| 1038 | case VK_HOME: | 
|---|
| 1039 | DATETIME_ResetFieldDown (infoPtr,FieldNum); | 
|---|
| 1040 | DATETIME_SendDateTimeChangeNotify (hwnd); | 
|---|
| 1041 | break; | 
|---|
| 1042 | case VK_END: | 
|---|
| 1043 | DATETIME_ResetFieldUp(infoPtr,FieldNum); | 
|---|
| 1044 | DATETIME_SendDateTimeChangeNotify (hwnd); | 
|---|
| 1045 | break; | 
|---|
| 1046 | case VK_LEFT: | 
|---|
| 1047 | do { | 
|---|
| 1048 | if (infoPtr->select==0) { | 
|---|
| 1049 | infoPtr->select = infoPtr->nrFields - 1; | 
|---|
| 1050 | wrap++; | 
|---|
| 1051 | } else | 
|---|
| 1052 | infoPtr->select--; | 
|---|
| 1053 | } | 
|---|
| 1054 | while ((infoPtr->fieldspec[infoPtr->select] & DT_STRING) && (wrap<2)); | 
|---|
| 1055 | break; | 
|---|
| 1056 | case VK_RIGHT: | 
|---|
| 1057 | do { | 
|---|
| 1058 | infoPtr->select++; | 
|---|
| 1059 | if (infoPtr->select==infoPtr->nrFields) { | 
|---|
| 1060 | infoPtr->select = 0; | 
|---|
| 1061 | wrap++; | 
|---|
| 1062 | } | 
|---|
| 1063 | } | 
|---|
| 1064 | while ((infoPtr->fieldspec[infoPtr->select] & DT_STRING) && (wrap<2)); | 
|---|
| 1065 | break; | 
|---|
| 1066 | } | 
|---|
| 1067 |  | 
|---|
| 1068 | InvalidateRect(hwnd, NULL, FALSE); | 
|---|
| 1069 |  | 
|---|
| 1070 | return 0; | 
|---|
| 1071 | } | 
|---|
| 1072 |  | 
|---|
| 1073 |  | 
|---|
| 1074 | static LRESULT | 
|---|
| 1075 | DATETIME_KillFocus (HWND hwnd, WPARAM wParam, LPARAM lParam) | 
|---|
| 1076 | { | 
|---|
| 1077 | DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr (hwnd); | 
|---|
| 1078 |  | 
|---|
| 1079 | TRACE ("\n"); | 
|---|
| 1080 |  | 
|---|
| 1081 | if (infoPtr->haveFocus) { | 
|---|
| 1082 | DATETIME_SendSimpleNotify (hwnd, NM_KILLFOCUS); | 
|---|
| 1083 | infoPtr->haveFocus = 0; | 
|---|
| 1084 | } | 
|---|
| 1085 |  | 
|---|
| 1086 | InvalidateRect (hwnd, NULL, TRUE); | 
|---|
| 1087 |  | 
|---|
| 1088 | return 0; | 
|---|
| 1089 | } | 
|---|
| 1090 |  | 
|---|
| 1091 |  | 
|---|
| 1092 | static LRESULT | 
|---|
| 1093 | DATETIME_SetFocus (HWND hwnd, WPARAM wParam, LPARAM lParam) | 
|---|
| 1094 | { | 
|---|
| 1095 | DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr (hwnd); | 
|---|
| 1096 |  | 
|---|
| 1097 | TRACE ("\n"); | 
|---|
| 1098 |  | 
|---|
| 1099 | if (infoPtr->haveFocus==0) { | 
|---|
| 1100 | DATETIME_SendSimpleNotify (hwnd, NM_SETFOCUS); | 
|---|
| 1101 | infoPtr->haveFocus = DTHT_GOTFOCUS; | 
|---|
| 1102 | } | 
|---|
| 1103 |  | 
|---|
| 1104 | InvalidateRect(hwnd, NULL, FALSE); | 
|---|
| 1105 |  | 
|---|
| 1106 | return 0; | 
|---|
| 1107 | } | 
|---|
| 1108 |  | 
|---|
| 1109 |  | 
|---|
| 1110 | static BOOL | 
|---|
| 1111 | DATETIME_SendDateTimeChangeNotify (HWND hwnd) | 
|---|
| 1112 |  | 
|---|
| 1113 | { | 
|---|
| 1114 | DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr (hwnd); | 
|---|
| 1115 | NMDATETIMECHANGE dtdtc; | 
|---|
| 1116 |  | 
|---|
| 1117 | TRACE ("\n"); | 
|---|
| 1118 | dtdtc.nmhdr.hwndFrom = hwnd; | 
|---|
| 1119 | dtdtc.nmhdr.idFrom   = GetWindowLongA( hwnd, GWL_ID); | 
|---|
| 1120 | dtdtc.nmhdr.code     = DTN_DATETIMECHANGE; | 
|---|
| 1121 |  | 
|---|
| 1122 | if ((GetWindowLongA (hwnd, GWL_STYLE) & DTS_SHOWNONE)) | 
|---|
| 1123 | dtdtc.dwFlags = GDT_NONE; | 
|---|
| 1124 | else | 
|---|
| 1125 | dtdtc.dwFlags = GDT_VALID; | 
|---|
| 1126 |  | 
|---|
| 1127 | MONTHCAL_CopyTime (&infoPtr->date, &dtdtc.st); | 
|---|
| 1128 | return (BOOL) SendMessageA (GetParent (hwnd), WM_NOTIFY, | 
|---|
| 1129 | (WPARAM)dtdtc.nmhdr.idFrom, (LPARAM)&dtdtc); | 
|---|
| 1130 | } | 
|---|
| 1131 |  | 
|---|
| 1132 |  | 
|---|
| 1133 | static BOOL | 
|---|
| 1134 | DATETIME_SendSimpleNotify (HWND hwnd, UINT code) | 
|---|
| 1135 | { | 
|---|
| 1136 | NMHDR nmhdr; | 
|---|
| 1137 |  | 
|---|
| 1138 | TRACE("%x\n",code); | 
|---|
| 1139 | nmhdr.hwndFrom = hwnd; | 
|---|
| 1140 | nmhdr.idFrom   = GetWindowLongA( hwnd, GWL_ID); | 
|---|
| 1141 | nmhdr.code     = code; | 
|---|
| 1142 |  | 
|---|
| 1143 | return (BOOL) SendMessageA (GetParent (hwnd), WM_NOTIFY, | 
|---|
| 1144 | (WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr); | 
|---|
| 1145 | } | 
|---|
| 1146 |  | 
|---|
| 1147 | static LRESULT | 
|---|
| 1148 | DATETIME_Size (HWND hwnd, WPARAM wParam, LPARAM lParam) | 
|---|
| 1149 | { | 
|---|
| 1150 | DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr(hwnd); | 
|---|
| 1151 | DWORD dwStyle = GetWindowLongA(hwnd, GWL_STYLE); | 
|---|
| 1152 |  | 
|---|
| 1153 | /* set size */ | 
|---|
| 1154 | infoPtr->rcClient.bottom = HIWORD(lParam); | 
|---|
| 1155 | infoPtr->rcClient.right = LOWORD(lParam); | 
|---|
| 1156 |  | 
|---|
| 1157 | TRACE("Height=%ld, Width=%ld\n", infoPtr->rcClient.bottom, infoPtr->rcClient.right); | 
|---|
| 1158 |  | 
|---|
| 1159 | /* use DrawEdge to adjust the size of rcEdge to get rcDraw */ | 
|---|
| 1160 | memcpy((&infoPtr->rcDraw), (&infoPtr->rcClient), sizeof(infoPtr->rcDraw)); | 
|---|
| 1161 |  | 
|---|
| 1162 | DrawEdge(NULL, &(infoPtr->rcDraw), EDGE_SUNKEN, BF_RECT | BF_ADJUST); | 
|---|
| 1163 |  | 
|---|
| 1164 | /* set the size of the button that drops the calendar down */ | 
|---|
| 1165 | /* FIXME: account for style that allows button on left side */ | 
|---|
| 1166 | infoPtr->calbutton.top   = infoPtr->rcDraw.top; | 
|---|
| 1167 | infoPtr->calbutton.bottom= infoPtr->rcDraw.bottom; | 
|---|
| 1168 | infoPtr->calbutton.left  = infoPtr->rcDraw.right-15; | 
|---|
| 1169 | infoPtr->calbutton.right = infoPtr->rcDraw.right; | 
|---|
| 1170 |  | 
|---|
| 1171 | /* set enable/disable button size for show none style being enabled */ | 
|---|
| 1172 | /* FIXME: these dimensions are completely incorrect */ | 
|---|
| 1173 | infoPtr->checkbox.top = infoPtr->rcDraw.top; | 
|---|
| 1174 | infoPtr->checkbox.bottom = infoPtr->rcDraw.bottom; | 
|---|
| 1175 | infoPtr->checkbox.left = infoPtr->rcDraw.left; | 
|---|
| 1176 | infoPtr->checkbox.right = infoPtr->rcDraw.left + 10; | 
|---|
| 1177 |  | 
|---|
| 1178 | /* update the position of the monthcal control */ | 
|---|
| 1179 | if(dwStyle & DTS_RIGHTALIGN) | 
|---|
| 1180 | infoPtr->monthcal_pos.x = infoPtr->rcClient.right - ((infoPtr->calbutton.right - | 
|---|
| 1181 | infoPtr->calbutton.left) + 145); | 
|---|
| 1182 | else | 
|---|
| 1183 | infoPtr->monthcal_pos.x = 8; | 
|---|
| 1184 |  | 
|---|
| 1185 | infoPtr->monthcal_pos.y = infoPtr->rcClient.bottom; | 
|---|
| 1186 | ClientToScreen (hwnd, &(infoPtr->monthcal_pos)); | 
|---|
| 1187 | SetWindowPos(infoPtr->hMonthCal, 0, infoPtr->monthcal_pos.x, | 
|---|
| 1188 | infoPtr->monthcal_pos.y, | 
|---|
| 1189 | 145, 150, 0); | 
|---|
| 1190 |  | 
|---|
| 1191 | InvalidateRect(hwnd, NULL, FALSE); | 
|---|
| 1192 |  | 
|---|
| 1193 | return 0; | 
|---|
| 1194 | } | 
|---|
| 1195 |  | 
|---|
| 1196 |  | 
|---|
| 1197 | static LRESULT | 
|---|
| 1198 | DATETIME_Create (HWND hwnd, WPARAM wParam, LPARAM lParam) | 
|---|
| 1199 | { | 
|---|
| 1200 | DATETIME_INFO *infoPtr; | 
|---|
| 1201 | DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE); | 
|---|
| 1202 |  | 
|---|
| 1203 | /* allocate memory for info structure */ | 
|---|
| 1204 | TRACE("%04x %08lx\n",wParam,lParam); | 
|---|
| 1205 | infoPtr = (DATETIME_INFO *)COMCTL32_Alloc (sizeof(DATETIME_INFO)); | 
|---|
| 1206 | if (infoPtr == NULL) { | 
|---|
| 1207 | ERR("could not allocate info memory!\n"); | 
|---|
| 1208 | return 0; | 
|---|
| 1209 | } | 
|---|
| 1210 |  | 
|---|
| 1211 | SetWindowLongA (hwnd, 0, (DWORD)infoPtr); | 
|---|
| 1212 |  | 
|---|
| 1213 | if (dwStyle & DTS_SHOWNONE) { | 
|---|
| 1214 | infoPtr->hwndCheckbut=CreateWindowExA (0,"button", 0, | 
|---|
| 1215 | WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX, | 
|---|
| 1216 | 2,2,13,13, | 
|---|
| 1217 | hwnd, | 
|---|
| 1218 | 0, (HINSTANCE)GetWindowLongA  (hwnd, GWL_HINSTANCE), 0); | 
|---|
| 1219 | SendMessageA (infoPtr->hwndCheckbut, BM_SETCHECK, 1, 0); | 
|---|
| 1220 | } | 
|---|
| 1221 |  | 
|---|
| 1222 | if (dwStyle & DTS_UPDOWN) { | 
|---|
| 1223 | infoPtr->hUpdown=CreateUpDownControl ( | 
|---|
| 1224 | WS_CHILD | WS_BORDER | WS_VISIBLE, | 
|---|
| 1225 | 120,1,20,20, | 
|---|
| 1226 | hwnd,1,0,0, | 
|---|
| 1227 | UD_MAXVAL, UD_MINVAL, 0); | 
|---|
| 1228 | } | 
|---|
| 1229 |  | 
|---|
| 1230 | infoPtr->fieldspec = (int *) COMCTL32_Alloc (32*sizeof(int)); | 
|---|
| 1231 | infoPtr->fieldRect = (RECT *) COMCTL32_Alloc (32*sizeof(RECT)); | 
|---|
| 1232 | infoPtr->buflen = (int *) COMCTL32_Alloc (32*sizeof(int)); | 
|---|
| 1233 | infoPtr->nrFieldsAllocated = 32; | 
|---|
| 1234 |  | 
|---|
| 1235 | DATETIME_SetFormat (hwnd, 0, 0); | 
|---|
| 1236 |  | 
|---|
| 1237 | /* create the monthcal control */ | 
|---|
| 1238 | infoPtr->hMonthCal = CreateWindowExA (0,"SysMonthCal32", 0, | 
|---|
| 1239 | WS_BORDER | WS_POPUP | WS_CLIPSIBLINGS, | 
|---|
| 1240 | 0, 0, 0, 0, | 
|---|
| 1241 | GetParent(hwnd), | 
|---|
| 1242 | 0, 0, 0); | 
|---|
| 1243 |  | 
|---|
| 1244 | /* initialize info structure */ | 
|---|
| 1245 | GetSystemTime (&infoPtr->date); | 
|---|
| 1246 | infoPtr->dateValid = TRUE; | 
|---|
| 1247 | infoPtr->hFont = GetStockObject(DEFAULT_GUI_FONT); | 
|---|
| 1248 | return 0; | 
|---|
| 1249 | } | 
|---|
| 1250 |  | 
|---|
| 1251 |  | 
|---|
| 1252 | static LRESULT | 
|---|
| 1253 | DATETIME_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam) | 
|---|
| 1254 | { | 
|---|
| 1255 | DATETIME_INFO *infoPtr = DATETIME_GetInfoPtr (hwnd); | 
|---|
| 1256 |  | 
|---|
| 1257 | TRACE("\n"); | 
|---|
| 1258 | COMCTL32_Free (infoPtr); | 
|---|
| 1259 | SetWindowLongA( hwnd, 0, 0 ); | 
|---|
| 1260 | return 0; | 
|---|
| 1261 | } | 
|---|
| 1262 |  | 
|---|
| 1263 |  | 
|---|
| 1264 | static LRESULT WINAPI | 
|---|
| 1265 | DATETIME_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) | 
|---|
| 1266 | { | 
|---|
| 1267 | if (!DATETIME_GetInfoPtr(hwnd) && (uMsg != WM_CREATE)) | 
|---|
| 1268 | return DefWindowProcA( hwnd, uMsg, wParam, lParam ); | 
|---|
| 1269 |  | 
|---|
| 1270 | switch (uMsg) | 
|---|
| 1271 | { | 
|---|
| 1272 |  | 
|---|
| 1273 | case DTM_GETSYSTEMTIME: | 
|---|
| 1274 | return DATETIME_GetSystemTime (hwnd, wParam, lParam); | 
|---|
| 1275 |  | 
|---|
| 1276 | case DTM_SETSYSTEMTIME: | 
|---|
| 1277 | return DATETIME_SetSystemTime (hwnd, wParam, lParam); | 
|---|
| 1278 |  | 
|---|
| 1279 | case DTM_GETRANGE: | 
|---|
| 1280 | return DATETIME_GetRange(hwnd, lParam); | 
|---|
| 1281 |  | 
|---|
| 1282 | case DTM_SETRANGE: | 
|---|
| 1283 | return DATETIME_SetRange(hwnd, wParam, lParam); | 
|---|
| 1284 |  | 
|---|
| 1285 | case DTM_SETFORMATA: | 
|---|
| 1286 | return DATETIME_SetFormat (hwnd, wParam, lParam); | 
|---|
| 1287 |  | 
|---|
| 1288 | case DTM_SETFORMATW: | 
|---|
| 1289 | return DATETIME_SetFormatW (hwnd, wParam, lParam); | 
|---|
| 1290 |  | 
|---|
| 1291 | case DTM_SETMCCOLOR: | 
|---|
| 1292 | return DATETIME_SetMonthCalColor (hwnd, wParam, lParam); | 
|---|
| 1293 |  | 
|---|
| 1294 | case DTM_GETMCCOLOR: | 
|---|
| 1295 | return DATETIME_GetMonthCalColor (hwnd, wParam); | 
|---|
| 1296 |  | 
|---|
| 1297 | case DTM_GETMONTHCAL: | 
|---|
| 1298 | return DATETIME_GetMonthCal (hwnd); | 
|---|
| 1299 |  | 
|---|
| 1300 | case DTM_SETMCFONT: | 
|---|
| 1301 | return DATETIME_SetMonthCalFont (hwnd, wParam, lParam); | 
|---|
| 1302 |  | 
|---|
| 1303 | case DTM_GETMCFONT: | 
|---|
| 1304 | return DATETIME_GetMonthCalFont (hwnd); | 
|---|
| 1305 |  | 
|---|
| 1306 | case WM_PARENTNOTIFY: | 
|---|
| 1307 | return DATETIME_ParentNotify (hwnd, wParam, lParam); | 
|---|
| 1308 |  | 
|---|
| 1309 | case WM_NOTIFY: | 
|---|
| 1310 | return DATETIME_Notify (hwnd, wParam, lParam); | 
|---|
| 1311 |  | 
|---|
| 1312 | case WM_GETDLGCODE: | 
|---|
| 1313 | return DLGC_WANTARROWS | DLGC_WANTCHARS; | 
|---|
| 1314 |  | 
|---|
| 1315 | case WM_PAINT: | 
|---|
| 1316 | return DATETIME_Paint (hwnd, wParam); | 
|---|
| 1317 |  | 
|---|
| 1318 | case WM_KEYDOWN: | 
|---|
| 1319 | return DATETIME_KeyDown (hwnd, wParam, lParam); | 
|---|
| 1320 |  | 
|---|
| 1321 | case WM_KILLFOCUS: | 
|---|
| 1322 | return DATETIME_KillFocus (hwnd, wParam, lParam); | 
|---|
| 1323 |  | 
|---|
| 1324 | case WM_SETFOCUS: | 
|---|
| 1325 | return DATETIME_SetFocus (hwnd, wParam, lParam); | 
|---|
| 1326 |  | 
|---|
| 1327 | case WM_SIZE: | 
|---|
| 1328 | return DATETIME_Size (hwnd, wParam, lParam); | 
|---|
| 1329 |  | 
|---|
| 1330 | case WM_LBUTTONDOWN: | 
|---|
| 1331 | return DATETIME_LButtonDown (hwnd, wParam, lParam); | 
|---|
| 1332 |  | 
|---|
| 1333 | case WM_LBUTTONUP: | 
|---|
| 1334 | return DATETIME_LButtonUp (hwnd, wParam, lParam); | 
|---|
| 1335 |  | 
|---|
| 1336 | case WM_CREATE: | 
|---|
| 1337 | return DATETIME_Create (hwnd, wParam, lParam); | 
|---|
| 1338 |  | 
|---|
| 1339 | case WM_DESTROY: | 
|---|
| 1340 | return DATETIME_Destroy (hwnd, wParam, lParam); | 
|---|
| 1341 |  | 
|---|
| 1342 | case WM_COMMAND: | 
|---|
| 1343 | return DATETIME_Command (hwnd, wParam, lParam); | 
|---|
| 1344 |  | 
|---|
| 1345 | default: | 
|---|
| 1346 | if ((uMsg >= WM_USER) && (uMsg < WM_APP)) | 
|---|
| 1347 | ERR("unknown msg %04x wp=%08x lp=%08lx\n", | 
|---|
| 1348 | uMsg, wParam, lParam); | 
|---|
| 1349 | return DefWindowProcA (hwnd, uMsg, wParam, lParam); | 
|---|
| 1350 | } | 
|---|
| 1351 | return 0; | 
|---|
| 1352 | } | 
|---|
| 1353 |  | 
|---|
| 1354 |  | 
|---|
| 1355 | VOID | 
|---|
| 1356 | DATETIME_Register (void) | 
|---|
| 1357 | { | 
|---|
| 1358 | WNDCLASSA wndClass; | 
|---|
| 1359 |  | 
|---|
| 1360 | TRACE("\n"); | 
|---|
| 1361 | ZeroMemory (&wndClass, sizeof(WNDCLASSA)); | 
|---|
| 1362 | wndClass.style         = CS_GLOBALCLASS; | 
|---|
| 1363 | wndClass.lpfnWndProc   = (WNDPROC)DATETIME_WindowProc; | 
|---|
| 1364 | wndClass.cbClsExtra    = 0; | 
|---|
| 1365 | wndClass.cbWndExtra    = sizeof(DATETIME_INFO *); | 
|---|
| 1366 | wndClass.hCursor       = LoadCursorA (0, IDC_ARROWA); | 
|---|
| 1367 | wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); | 
|---|
| 1368 | wndClass.lpszClassName = DATETIMEPICK_CLASSA; | 
|---|
| 1369 |  | 
|---|
| 1370 | RegisterClassA (&wndClass); | 
|---|
| 1371 | } | 
|---|
| 1372 |  | 
|---|
| 1373 |  | 
|---|
| 1374 | VOID | 
|---|
| 1375 | DATETIME_Unregister (void) | 
|---|
| 1376 | { | 
|---|
| 1377 | TRACE("\n"); | 
|---|
| 1378 | UnregisterClassA (DATETIMEPICK_CLASSA, NULL); | 
|---|
| 1379 | } | 
|---|