datetime.c 49.1 KB
Newer Older
1 2 3
/*
 * 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>
7
 * Copyright 2012 Owen Rudge for CodeWeavers
8
 *
9 10 11 12 13 14 15 16 17 18 19 20
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
21
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22
 *
23 24 25 26 27 28 29 30 31
 * NOTE
 * 
 * This code was audited for completeness against the documented features
 * of Comctl32.dll version 6.0 on Oct. 20, 2004, by Dimitrie O. Paun.
 * 
 * Unless otherwise noted, we believe this code to be complete, as per
 * the specification mentioned above.
 * If you discover missing features, or bugs, please note them below.
 * 
32
 * TODO:
33 34 35 36 37 38 39
 *    -- DTS_APPCANPARSE
 *    -- DTS_SHORTDATECENTURYFORMAT
 *    -- DTN_FORMAT
 *    -- DTN_FORMATQUERY
 *    -- DTN_USERSTRING
 *    -- DTN_WMKEYDOWN
 *    -- FORMATCALLBACK
40 41
 */

42 43
#include <math.h>
#include <string.h>
44
#include <stdarg.h>
45
#include <stdio.h>
46
#include <limits.h>
47

48
#include "windef.h"
49
#include "winbase.h"
50
#include "wingdi.h"
51 52
#include "winuser.h"
#include "winnls.h"
53
#include "commctrl.h"
54
#include "comctl32.h"
55
#include "wine/debug.h"
56
#include "wine/unicode.h"
57

58
WINE_DEFAULT_DEBUG_CHANNEL(datetime);
59

60 61
typedef struct
{
62 63 64 65
    HWND hwndSelf;
    HWND hMonthCal;
    HWND hwndNotify;
    HWND hUpdown;
66
    DWORD dwStyle;
67 68 69 70 71 72 73 74
    SYSTEMTIME date;
    BOOL dateValid;
    HWND hwndCheckbut;
    RECT rcClient; /* rect around the edge of the window */
    RECT rcDraw; /* rect inside of the border */
    RECT checkbox;  /* checkbox allowing the control to be enabled/disabled */
    RECT calbutton; /* button that toggles the dropdown of the monthcal control */
    BOOL bCalDepressed; /* TRUE = cal button is depressed */
75
    BOOL bDropdownEnabled;
76
    int  select;
77 78
    WCHAR charsEntered[4];
    int nCharsEntered;
79 80 81 82 83 84 85 86 87
    HFONT hFont;
    int nrFieldsAllocated;
    int nrFields;
    int haveFocus;
    int *fieldspec;
    RECT *fieldRect;
    int  *buflen;
    WCHAR textbuf[256];
    POINT monthcal_pos;
Duane Clark's avatar
Duane Clark committed
88
    int pendingUpdown;
89 90 91
} DATETIME_INFO, *LPDATETIME_INFO;

/* in monthcal.c */
92
extern int MONTHCAL_MonthLength(int month, int year);
93
extern int MONTHCAL_CalculateDayOfWeek(SYSTEMTIME *date, BOOL inplace);
94 95 96

/* this list of defines is closely related to `allowedformatchars' defined
 * in datetime.c; the high nibble indicates the `base type' of the format
97
 * specifier.
98
 * Do not change without first reading DATETIME_UseFormat.
99
 *
100 101
 */

102
#define DT_END_FORMAT      0
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
#define ONEDIGITDAY   	0x01
#define TWODIGITDAY   	0x02
#define THREECHARDAY  	0x03
#define FULLDAY         0x04
#define ONEDIGIT12HOUR  0x11
#define TWODIGIT12HOUR  0x12
#define ONEDIGIT24HOUR  0x21
#define TWODIGIT24HOUR  0x22
#define ONEDIGITMINUTE  0x31
#define TWODIGITMINUTE  0x32
#define ONEDIGITMONTH   0x41
#define TWODIGITMONTH   0x42
#define THREECHARMONTH  0x43
#define FULLMONTH       0x44
#define ONEDIGITSECOND  0x51
#define TWODIGITSECOND  0x52
#define ONELETTERAMPM   0x61
#define TWOLETTERAMPM   0x62
#define ONEDIGITYEAR    0x71
#define TWODIGITYEAR    0x72
Huw Davies's avatar
Huw Davies committed
123 124
#define INVALIDFULLYEAR 0x73      /* FIXME - yyy is not valid - we'll treat it as yyyy */
#define FULLYEAR        0x74
125 126 127 128 129 130
#define FORMATCALLBACK  0x81      /* -> maximum of 0x80 callbacks possible */
#define FORMATCALLMASK  0x80
#define DT_STRING 	0x0100

#define DTHT_DATEFIELD  0xff      /* for hit-testing */

131 132 133 134 135
#define DTHT_NONE       0x1000
#define DTHT_CHECKBOX   0x2000  /* these should end at '00' , to make */
#define DTHT_MCPOPUP    0x3000  /* & DTHT_DATEFIELD 0 when DATETIME_KeyDown */
#define DTHT_GOTFOCUS   0x4000  /* tests for date-fields */
#define DTHT_NODATEMASK 0xf000  /* to mask check and drop down from others */
136

137 138
static BOOL DATETIME_SendSimpleNotify (const DATETIME_INFO *infoPtr, UINT code);
static BOOL DATETIME_SendDateTimeChangeNotify (const DATETIME_INFO *infoPtr);
139 140
static const WCHAR allowedformatchars[] = {'d', 'h', 'H', 'm', 'M', 's', 't', 'y', 'X', 0};
static const int maxrepetition [] = {4,2,2,2,4,2,2,4,-1};
141

142 143 144
/* valid date limits */
static const SYSTEMTIME max_allowed_date = { /* wYear */ 9999, /* wMonth */ 12, /* wDayOfWeek */ 0, /* wDay */ 31 };
static const SYSTEMTIME min_allowed_date = { /* wYear */ 1752, /* wMonth */ 9,  /* wDayOfWeek */ 0, /* wDay */ 14 };
145

146
static DWORD
147
DATETIME_GetSystemTime (const DATETIME_INFO *infoPtr, SYSTEMTIME *systime)
148
{
149
    if (!systime) return GDT_NONE;
150

151 152
    if ((infoPtr->dwStyle & DTS_SHOWNONE) &&
        (SendMessageW (infoPtr->hwndCheckbut, BM_GETCHECK, 0, 0) == BST_UNCHECKED))
153 154
        return GDT_NONE;

155
    *systime = infoPtr->date;
156

157
    return GDT_VALID;
158 159
}

160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
/* Checks value is within configured date range
 *
 * PARAMETERS
 *
 *  [I] infoPtr : valid pointer to control data
 *  [I] date    : pointer to valid date data to check
 *
 * RETURN VALUE
 *
 *  TRUE  - date within configured range
 *  FALSE - date is outside configured range
 */
static BOOL DATETIME_IsDateInValidRange(const DATETIME_INFO *infoPtr, const SYSTEMTIME *date)
{
    SYSTEMTIME range[2];
    DWORD limits;

    if ((MONTHCAL_CompareSystemTime(date, &max_allowed_date) == 1) ||
        (MONTHCAL_CompareSystemTime(date, &min_allowed_date) == -1))
        return FALSE;

181
    limits = SendMessageW (infoPtr->hMonthCal, MCM_GETRANGE, 0, (LPARAM)range);
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196

    if (limits & GDTR_MAX)
    {
        if (MONTHCAL_CompareSystemTime(date, &range[1]) == 1)
           return FALSE;
    }

    if (limits & GDTR_MIN)
    {
        if (MONTHCAL_CompareSystemTime(date, &range[0]) == -1)
           return FALSE;
    }

    return TRUE;
}
197

198
static BOOL
199
DATETIME_SetSystemTime (DATETIME_INFO *infoPtr, DWORD flag, const SYSTEMTIME *systime)
200
{
201
    if (!systime) return FALSE;
202

203
    TRACE("%04d/%02d/%02d %02d:%02d:%02d\n",
204 205
          systime->wYear, systime->wMonth, systime->wDay,
          systime->wHour, systime->wMinute, systime->wSecond);
206 207

    if (flag == GDT_VALID) {
208 209 210 211 212 213 214 215 216 217
        if (systime->wYear == 0 ||
            systime->wMonth < 1 || systime->wMonth > 12 ||
            systime->wDay < 1 ||
            systime->wDay > MONTHCAL_MonthLength(systime->wMonth, systime->wYear) ||
            systime->wHour > 23 ||
            systime->wMinute > 59 ||
            systime->wSecond > 59 ||
            systime->wMilliseconds > 999
           )
            return FALSE;
218

219
        /* Windows returns true if the date is valid but outside the limits set */
220
        if (!DATETIME_IsDateInValidRange(infoPtr, systime))
221 222
            return TRUE;

223
        infoPtr->dateValid = TRUE;
224
        infoPtr->date = *systime;
225
        /* always store a valid day of week */
226
        MONTHCAL_CalculateDayOfWeek(&infoPtr->date, TRUE);
227

228 229
        SendMessageW (infoPtr->hMonthCal, MCM_SETCURSEL, 0, (LPARAM)(&infoPtr->date));
        SendMessageW (infoPtr->hwndCheckbut, BM_SETCHECK, BST_CHECKED, 0);
230
    } else if ((infoPtr->dwStyle & DTS_SHOWNONE) && (flag == GDT_NONE)) {
231 232 233
        infoPtr->dateValid = FALSE;
        SendMessageW (infoPtr->hwndCheckbut, BM_SETCHECK, BST_UNCHECKED, 0);
    }
234
    else
235
        return FALSE;
236

237 238
    InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
    return TRUE;
239 240
}

241

242 243 244 245 246 247 248 249 250 251
/***
 * Split up a formattxt in actions.
 * See ms documentation for the meaning of the letter codes/'specifiers'.
 *
 * Notes:
 * *'dddddd' is handled as 'dddd' plus 'dd'.
 * *unrecognized formats are strings (here given the type DT_STRING;
 * start of the string is encoded in lower bits of DT_STRING.
 * Therefore, 'string' ends finally up as '<show seconds>tring'.
 *
252
 */
253
static void
254
DATETIME_UseFormat (DATETIME_INFO *infoPtr, LPCWSTR formattxt)
255
{
256 257
    unsigned int i;
    int j, k, len;
258
    BOOL inside_literal = FALSE; /* inside '...' */
259 260 261 262 263 264 265 266 267
    int *nrFields = &infoPtr->nrFields;

    *nrFields = 0;
    infoPtr->fieldspec[*nrFields] = 0;
    len = strlenW(allowedformatchars);
    k = 0;

    for (i = 0; formattxt[i]; i++)  {
	TRACE ("\n%d %c:", i, formattxt[i]);
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298
	if (!inside_literal) {
	    for (j = 0; j < len; j++) {
	        if (allowedformatchars[j]==formattxt[i]) {
                    TRACE ("%c[%d,%x]", allowedformatchars[j], *nrFields, infoPtr->fieldspec[*nrFields]);
                    if ((*nrFields==0) && (infoPtr->fieldspec[*nrFields]==0)) {
                        infoPtr->fieldspec[*nrFields] = (j<<4) + 1;
                        break;
                    }
                    if (infoPtr->fieldspec[*nrFields] >> 4 != j) {
                        (*nrFields)++;
                        infoPtr->fieldspec[*nrFields] = (j<<4) + 1;
                        break;
                    }
                    if ((infoPtr->fieldspec[*nrFields] & 0x0f) == maxrepetition[j]) {
                        (*nrFields)++;
                        infoPtr->fieldspec[*nrFields] = (j<<4) + 1;
                        break;
		    }
                    infoPtr->fieldspec[*nrFields]++;
                    break;
                }   /* if allowedformatchar */
            } /* for j */
        }
        else
            j = len;

        if (formattxt[i] == '\'')
        {
            inside_literal = !inside_literal;
            continue;
        }
299 300 301 302 303 304 305 306 307 308 309 310 311 312

	/* char is not a specifier: handle char like a string */
	if (j == len) {
	    if ((*nrFields==0) && (infoPtr->fieldspec[*nrFields]==0)) {
		infoPtr->fieldspec[*nrFields] = DT_STRING + k;
		infoPtr->buflen[*nrFields] = 0;
            } else if ((infoPtr->fieldspec[*nrFields] & DT_STRING) != DT_STRING)  {
		(*nrFields)++;
		infoPtr->fieldspec[*nrFields] = DT_STRING + k;
		infoPtr->buflen[*nrFields] = 0;
	    }
	    infoPtr->textbuf[k] = formattxt[i];
	    k++;
	    infoPtr->buflen[*nrFields]++;
313 314
	}   /* if j=len */

315 316
	if (*nrFields == infoPtr->nrFieldsAllocated) {
	    FIXME ("out of memory; should reallocate. crash ahead.\n");
317
	}
318
    } /* for i */
319

320
    TRACE("\n");
321

322
    if (infoPtr->fieldspec[*nrFields] != 0) (*nrFields)++;
323 324
}

325

326
static BOOL
327
DATETIME_SetFormatW (DATETIME_INFO *infoPtr, LPCWSTR format)
328
{
329 330 331
    WCHAR format_buf[80];

    if (!format) {
332
	DWORD format_item;
333

334
	if (infoPtr->dwStyle & DTS_LONGDATEFORMAT)
335
	    format_item = LOCALE_SLONGDATE;
Duane Clark's avatar
Duane Clark committed
336
	else if ((infoPtr->dwStyle & DTS_TIMEFORMAT) == DTS_TIMEFORMAT)
337
	    format_item = LOCALE_STIMEFORMAT;
338
        else /* DTS_SHORTDATEFORMAT */
339
	    format_item = LOCALE_SSHORTDATE;
340
	GetLocaleInfoW(LOCALE_USER_DEFAULT, format_item, format_buf, sizeof(format_buf)/sizeof(format_buf[0]));
341
	format = format_buf;
342
    }
343

344
    DATETIME_UseFormat (infoPtr, format);
345
    InvalidateRect (infoPtr->hwndSelf, NULL, TRUE);
346

347
    return TRUE;
348
}
349

350

351 352
static BOOL
DATETIME_SetFormatA (DATETIME_INFO *infoPtr, LPCSTR lpszFormat)
353
{
354 355 356 357 358 359 360
    if (lpszFormat) {
	BOOL retval;
	INT len = MultiByteToWideChar(CP_ACP, 0, lpszFormat, -1, NULL, 0);
	LPWSTR wstr = Alloc(len * sizeof(WCHAR));
	if (wstr) MultiByteToWideChar(CP_ACP, 0, lpszFormat, -1, wstr, len);
	retval = DATETIME_SetFormatW (infoPtr, wstr);
	Free (wstr);
361
	return retval;
362 363 364
    }
    else
	return DATETIME_SetFormatW (infoPtr, 0);
365 366 367

}

368

369
static void
370
DATETIME_ReturnTxt (const DATETIME_INFO *infoPtr, int count, LPWSTR result, int resultSize)
371
{
372 373 374 375 376 377 378 379 380 381
    static const WCHAR fmt_dW[] = { '%', 'd', 0 };
    static const WCHAR fmt__2dW[] = { '%', '.', '2', 'd', 0 };
    static const WCHAR fmt__3sW[] = { '%', '.', '3', 's', 0 };
    SYSTEMTIME date = infoPtr->date;
    int spec;
    WCHAR buffer[80];

    *result=0;
    TRACE ("%d,%d\n", infoPtr->nrFields, count);
    if (count>infoPtr->nrFields || count < 0) {
382 383
	WARN ("buffer overrun, have %d want %d\n", infoPtr->nrFields, count);
	return;
384
    }
385

386
    if (!infoPtr->fieldspec) return;
387

388 389 390
    spec = infoPtr->fieldspec[count];
    if (spec & DT_STRING) {
	int txtlen = infoPtr->buflen[count];
391

392 393
        if (txtlen > resultSize)
            txtlen = resultSize - 1;
394 395 396
	memcpy (result, infoPtr->textbuf + (spec &~ DT_STRING), txtlen * sizeof(WCHAR));
	result[txtlen] = 0;
	TRACE ("arg%d=%x->[%s]\n", count, infoPtr->fieldspec[count], debugstr_w(result));
397
	return;
398
    }
399

400

401
    switch (spec) {
402
	case DT_END_FORMAT:
403 404
	    *result = 0;
	    break;
405
	case ONEDIGITDAY:
406 407
	    wsprintfW (result, fmt_dW, date.wDay);
	    break;
408
	case TWODIGITDAY:
409 410
	    wsprintfW (result, fmt__2dW, date.wDay);
	    break;
411
	case THREECHARDAY:
412 413 414
	    GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SABBREVDAYNAME1+(date.wDayOfWeek+6)%7, result, 4);
	    /*wsprintfW (result,"%.3s",days[date.wDayOfWeek]);*/
	    break;
415
	case FULLDAY:
416 417
	    GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SDAYNAME1+(date.wDayOfWeek+6)%7, result, resultSize);
	    break;
418
	case ONEDIGIT12HOUR:
419 420 421 422 423 424 425
	    if (date.wHour == 0) {
	        result[0] = '1';
	        result[1] = '2';
	        result[2] = 0;
	    }
	    else
	        wsprintfW (result, fmt_dW, date.wHour - (date.wHour > 12 ? 12 : 0));
426
	    break;
427
	case TWODIGIT12HOUR:
428 429 430 431 432 433 434
	    if (date.wHour == 0) {
	        result[0] = '1';
	        result[1] = '2';
	        result[2] = 0;
	    }
	    else
	        wsprintfW (result, fmt__2dW, date.wHour - (date.wHour > 12 ? 12 : 0));
435
	    break;
436
	case ONEDIGIT24HOUR:
437 438
	    wsprintfW (result, fmt_dW, date.wHour);
	    break;
439
	case TWODIGIT24HOUR:
440 441
	    wsprintfW (result, fmt__2dW, date.wHour);
	    break;
442
	case ONEDIGITSECOND:
443 444
	    wsprintfW (result, fmt_dW, date.wSecond);
	    break;
445
	case TWODIGITSECOND:
446 447
	    wsprintfW (result, fmt__2dW, date.wSecond);
	    break;
448
	case ONEDIGITMINUTE:
449 450
	    wsprintfW (result, fmt_dW, date.wMinute);
	    break;
451
	case TWODIGITMINUTE:
452 453
	    wsprintfW (result, fmt__2dW, date.wMinute);
	    break;
454
	case ONEDIGITMONTH:
455 456
	    wsprintfW (result, fmt_dW, date.wMonth);
	    break;
457
	case TWODIGITMONTH:
458 459
	    wsprintfW (result, fmt__2dW, date.wMonth);
	    break;
460
	case THREECHARMONTH:
461
	    GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SMONTHNAME1+date.wMonth -1,
462 463 464
			   buffer, sizeof(buffer)/sizeof(buffer[0]));
	    wsprintfW (result, fmt__3sW, buffer);
	    break;
465
	case FULLMONTH:
466
	    GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SMONTHNAME1+date.wMonth -1,
467 468
                           result, resultSize);
	    break;
469
	case ONELETTERAMPM:
470 471 472
	    result[0] = (date.wHour < 12 ? 'A' : 'P');
	    result[1] = 0;
	    break;
473
	case TWOLETTERAMPM:
474 475 476 477
	    result[0] = (date.wHour < 12 ? 'A' : 'P');
	    result[1] = 'M';
	    result[2] = 0;
	    break;
478
	case FORMATCALLBACK:
479 480 481 482
	    FIXME ("Not implemented\n");
	    result[0] = 'x';
	    result[1] = 0;
	    break;
483
	case ONEDIGITYEAR:
484 485
	    wsprintfW (result, fmt_dW, date.wYear-10* (int) floor(date.wYear/10));
	    break;
486
	case TWODIGITYEAR:
487 488
	    wsprintfW (result, fmt__2dW, date.wYear-100* (int) floor(date.wYear/100));
	    break;
Huw Davies's avatar
Huw Davies committed
489
        case INVALIDFULLYEAR:
490
	case FULLYEAR:
491 492
	    wsprintfW (result, fmt_dW, date.wYear);
	    break;
493
    }
494

495
    TRACE ("arg%d=%x->[%s]\n", count, infoPtr->fieldspec[count], debugstr_w(result));
496 497
}

498
static int wrap(int val, int delta, int minVal, int maxVal)
499
{
500 501 502 503
    val += delta;
    if (delta == INT_MIN || val < minVal) return maxVal;
    if (delta == INT_MAX || val > maxVal) return minVal;
    return val;
504 505
}

506
static void
507
DATETIME_IncreaseField (DATETIME_INFO *infoPtr, int number, int delta)
508
{
509
    SYSTEMTIME *date = &infoPtr->date;
510 511 512
    SYSTEMTIME range[2];
    DWORD limits;
    BOOL min;
513

514 515
    TRACE ("%d\n", number);
    if ((number > infoPtr->nrFields) || (number < 0)) return;
516

517
    if ((infoPtr->fieldspec[number] & DTHT_DATEFIELD) == 0) return;
518

519
    switch (infoPtr->fieldspec[number]) {
520 521 522
	case ONEDIGITYEAR:
	case TWODIGITYEAR:
	case FULLYEAR:
523 524 525 526 527 528 529
            if (delta == INT_MIN)
                date->wYear = 1752;
            else if (delta == INT_MAX)
                date->wYear = 9999;
            else
                date->wYear = max(min(date->wYear + delta, 9999), 1752);

530 531 532
	    if (date->wDay > MONTHCAL_MonthLength(date->wMonth, date->wYear))
	        /* This can happen when moving away from a leap year. */
	        date->wDay = MONTHCAL_MonthLength(date->wMonth, date->wYear);
533
	    MONTHCAL_CalculateDayOfWeek(date, TRUE);
534
	    break;
535 536 537 538
	case ONEDIGITMONTH:
	case TWODIGITMONTH:
	case THREECHARMONTH:
	case FULLMONTH:
539
	    date->wMonth = wrap(date->wMonth, delta, 1, 12);
540
	    MONTHCAL_CalculateDayOfWeek(date, TRUE);
541 542
	    delta = 0;
	    /* fall through */
543 544 545
	case ONEDIGITDAY:
	case TWODIGITDAY:
	case THREECHARDAY:
546
	case FULLDAY:
547
	    date->wDay = wrap(date->wDay, delta, 1, MONTHCAL_MonthLength(date->wMonth, date->wYear));
548
	    MONTHCAL_CalculateDayOfWeek(date, TRUE);
549 550 551 552 553
	    break;
	case ONELETTERAMPM:
	case TWOLETTERAMPM:
	    delta *= 12;
	    /* fall through */
554 555 556 557
	case ONEDIGIT12HOUR:
	case TWODIGIT12HOUR:
	case ONEDIGIT24HOUR:
	case TWODIGIT24HOUR:
558 559
	    date->wHour = wrap(date->wHour, delta, 0, 23);
	    break;
560 561
	case ONEDIGITMINUTE:
	case TWODIGITMINUTE:
562 563 564 565 566 567
	    date->wMinute = wrap(date->wMinute, delta, 0, 59);
	    break;
	case ONEDIGITSECOND:
	case TWODIGITSECOND:
	    date->wSecond = wrap(date->wSecond, delta, 0, 59);
	    break;
568
	case FORMATCALLBACK:
569 570 571
	    FIXME ("Not implemented\n");
	    break;
    }
572

573 574 575 576 577 578 579 580 581 582 583 584 585
    /* FYI: On 1752/9/14 the calendar changed and England and the
     * American colonies changed to the Gregorian calendar. This change
     * involved having September 14th follow September 2nd. So no date
     * algorithm works before that date.
     */
    if (10000 * date->wYear + 100 * date->wMonth + date->wDay < 17520914) {
	date->wYear = 1752;
    	date->wMonth = 9;
	date->wDay = 14;
	date->wSecond = 0;
	date->wMinute = 0;
	date->wHour = 0;
    }
586

587
    /* Ensure time is within bounds */
588
    limits = SendMessageW (infoPtr->hMonthCal, MCM_GETRANGE, 0, (LPARAM)range);
589
    min = delta < 0;
590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607

    if (limits & (min ? GDTR_MIN : GDTR_MAX))
    {
        int i = (min ? 0 : 1);

        if (MONTHCAL_CompareSystemTime(date, &range[i]) == (min ? -1 : 1))
        {
            date->wYear = range[i].wYear;
            date->wMonth = range[i].wMonth;
            date->wDayOfWeek = range[i].wDayOfWeek;
            date->wDay = range[i].wDay;
            date->wHour = range[i].wHour;
            date->wMinute = range[i].wMinute;
            date->wSecond = range[i].wSecond;
            date->wMilliseconds = range[i].wMilliseconds;
        }
    }
}
608

Duane Clark's avatar
Duane Clark committed
609
static void
610
DATETIME_ReturnFieldWidth (const DATETIME_INFO *infoPtr, HDC hdc, int count, SHORT *width)
Duane Clark's avatar
Duane Clark committed
611 612 613 614 615 616 617 618 619
{
    /* fields are a fixed width, determined by the largest possible string */
    /* presumably, these widths should be language dependent */
    static const WCHAR fld_d1W[] = { '2', 0 };
    static const WCHAR fld_d2W[] = { '2', '2', 0 };
    static const WCHAR fld_d4W[] = { '2', '2', '2', '2', 0 };
    static const WCHAR fld_am1[] = { 'A', 0 };
    static const WCHAR fld_am2[] = { 'A', 'M', 0 };
    int spec;
620 621
    WCHAR buffer[80];
    LPCWSTR bufptr;
Duane Clark's avatar
Duane Clark committed
622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658
    SIZE size;

    TRACE ("%d,%d\n", infoPtr->nrFields, count);
    if (count>infoPtr->nrFields || count < 0) {
	WARN ("buffer overrun, have %d want %d\n", infoPtr->nrFields, count);
	return;
    }

    if (!infoPtr->fieldspec) return;

    spec = infoPtr->fieldspec[count];
    if (spec & DT_STRING) {
	int txtlen = infoPtr->buflen[count];

        if (txtlen > 79)
            txtlen = 79;
	memcpy (buffer, infoPtr->textbuf + (spec &~ DT_STRING), txtlen * sizeof(WCHAR));
	buffer[txtlen] = 0;
	bufptr = buffer;
    }
    else {
        switch (spec) {
	    case ONEDIGITDAY:
	    case ONEDIGIT12HOUR:
	    case ONEDIGIT24HOUR:
	    case ONEDIGITSECOND:
	    case ONEDIGITMINUTE:
	    case ONEDIGITMONTH:
	    case ONEDIGITYEAR:
	        /* these seem to use a two byte field */
	    case TWODIGITDAY:
	    case TWODIGIT12HOUR:
	    case TWODIGIT24HOUR:
	    case TWODIGITSECOND:
	    case TWODIGITMINUTE:
	    case TWODIGITMONTH:
	    case TWODIGITYEAR:
659
	        bufptr = fld_d2W;
Duane Clark's avatar
Duane Clark committed
660 661 662
	        break;
            case INVALIDFULLYEAR:
	    case FULLYEAR:
663
	        bufptr = fld_d4W;
Duane Clark's avatar
Duane Clark committed
664 665 666
	        break;
	    case THREECHARMONTH:
	    case FULLMONTH:
667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696
	    case THREECHARDAY:
	    case FULLDAY:
	    {
		static const WCHAR fld_day[] = {'W','e','d','n','e','s','d','a','y',0};
		static const WCHAR fld_abbrday[] = {'W','e','d',0};
		static const WCHAR fld_mon[] = {'S','e','p','t','e','m','b','e','r',0};
		static const WCHAR fld_abbrmon[] = {'D','e','c',0};

		const WCHAR *fall;
		LCTYPE lctype;
		INT i, max_count;
		LONG cx;

		/* choose locale data type and fallback string */
		switch (spec) {
		case THREECHARDAY:
		    fall   = fld_abbrday;
		    lctype = LOCALE_SABBREVDAYNAME1;
		    max_count = 7;
		    break;
		case FULLDAY:
		    fall   = fld_day;
		    lctype = LOCALE_SDAYNAME1;
		    max_count = 7;
		    break;
		case THREECHARMONTH:
		    fall   = fld_abbrmon;
		    lctype = LOCALE_SABBREVMONTHNAME1;
		    max_count = 12;
		    break;
697
		default: /* FULLMONTH */
698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722
		    fall   = fld_mon;
		    lctype = LOCALE_SMONTHNAME1;
		    max_count = 12;
		    break;
		}

		cx = 0;
		for (i = 0; i < max_count; i++)
		{
		    if(GetLocaleInfoW(LOCALE_USER_DEFAULT, lctype + i,
			buffer, lstrlenW(buffer)))
		    {
			GetTextExtentPoint32W(hdc, buffer, lstrlenW(buffer), &size);
			if (size.cx > cx) cx = size.cx;
		    }
		    else /* locale independent fallback on failure */
		    {
		        GetTextExtentPoint32W(hdc, fall, lstrlenW(fall), &size);
			cx = size.cx;
		        break;
		    }
		}
		*width = cx;
		return;
	    }
Duane Clark's avatar
Duane Clark committed
723
	    case ONELETTERAMPM:
724
	        bufptr = fld_am1;
Duane Clark's avatar
Duane Clark committed
725 726
	        break;
	    case TWOLETTERAMPM:
727
	        bufptr = fld_am2;
Duane Clark's avatar
Duane Clark committed
728 729
	        break;
	    default:
730
	        bufptr = fld_d1W;
Duane Clark's avatar
Duane Clark committed
731 732 733 734
	        break;
        }
    }
    GetTextExtentPoint32W (hdc, bufptr, strlenW(bufptr), &size);
735
    *width = size.cx;
Duane Clark's avatar
Duane Clark committed
736 737
}

738 739
static void 
DATETIME_Refresh (DATETIME_INFO *infoPtr, HDC hdc)
740
{
741 742 743
    TRACE("\n");

    if (infoPtr->dateValid) {
744 745 746 747 748 749
        int i, prevright;
        RECT *field;
        RECT *rcDraw = &infoPtr->rcDraw;
        SIZE size;
        COLORREF oldTextColor;
        SHORT fieldWidth = 0;
750
        HFONT oldFont = SelectObject (hdc, infoPtr->hFont);
751
        INT oldBkMode = SetBkMode (hdc, TRANSPARENT);
752 753 754 755 756 757
        WCHAR txt[80];

        DATETIME_ReturnTxt (infoPtr, 0, txt, sizeof(txt)/sizeof(txt[0]));
        GetTextExtentPoint32W (hdc, txt, strlenW(txt), &size);
        rcDraw->bottom = size.cy + 2;

758
        prevright = infoPtr->checkbox.right = ((infoPtr->dwStyle & DTS_SHOWNONE) ? 18 : 2);
759 760 761 762

        for (i = 0; i < infoPtr->nrFields; i++) {
            DATETIME_ReturnTxt (infoPtr, i, txt, sizeof(txt)/sizeof(txt[0]));
            GetTextExtentPoint32W (hdc, txt, strlenW(txt), &size);
Duane Clark's avatar
Duane Clark committed
763
            DATETIME_ReturnFieldWidth (infoPtr, hdc, i, &fieldWidth);
764
            field = &infoPtr->fieldRect[i];
765 766 767
            field->left   = prevright;
            field->right  = prevright + fieldWidth;
            field->top    = rcDraw->top;
768 769 770
            field->bottom = rcDraw->bottom;
            prevright = field->right;

771 772 773
            if (infoPtr->dwStyle & WS_DISABLED)
                oldTextColor = SetTextColor (hdc, comctl32_color.clrGrayText);
            else if ((infoPtr->haveFocus) && (i == infoPtr->select)) {
774 775
                RECT selection;

776
                /* fill if focused */
777
                HBRUSH hbr = CreateSolidBrush (comctl32_color.clrActiveCaption);
778

779 780 781 782 783 784 785
                if (infoPtr->nCharsEntered)
                {
                    memcpy(txt, infoPtr->charsEntered, infoPtr->nCharsEntered * sizeof(WCHAR));
                    txt[infoPtr->nCharsEntered] = 0;
                    GetTextExtentPoint32W (hdc, txt, strlenW(txt), &size);
                }

786
                SetRect(&selection, 0, 0, size.cx, size.cy);
787
                /* center rectangle */
788 789
                OffsetRect(&selection, (field->right  + field->left - size.cx)/2,
                                       (field->bottom - size.cy)/2);
790 791

                FillRect(hdc, &selection, hbr);
792
                DeleteObject (hbr);
793 794 795 796 797 798
                oldTextColor = SetTextColor (hdc, comctl32_color.clrWindow);
            }
            else
                oldTextColor = SetTextColor (hdc, comctl32_color.clrWindowText);

            /* draw the date text using the colour set above */
799
            DrawTextW (hdc, txt, strlenW(txt), field, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
800
            SetTextColor (hdc, oldTextColor);
801
        }
802
        SetBkMode (hdc, oldBkMode);
803
        SelectObject (hdc, oldFont);
804
    }
805

806
    if (!(infoPtr->dwStyle & DTS_UPDOWN)) {
807
        DrawFrameControl(hdc, &infoPtr->calbutton, DFC_SCROLL,
808 809 810
                         DFCS_SCROLLDOWN | (infoPtr->bCalDepressed ? DFCS_PUSHED : 0) |
                         (infoPtr->dwStyle & WS_DISABLED ? DFCS_INACTIVE : 0) );
    }
811 812
}

813

814
static INT
815
DATETIME_HitTest (const DATETIME_INFO *infoPtr, POINT pt)
816
{
817
    int i;
818

819
    TRACE ("%s\n", wine_dbgstr_point(&pt));
820

821 822
    if (PtInRect (&infoPtr->calbutton, pt)) return DTHT_MCPOPUP;
    if (PtInRect (&infoPtr->checkbox, pt)) return DTHT_CHECKBOX;
823

824
    for (i = 0; i < infoPtr->nrFields; i++) {
825
        if (PtInRect (&infoPtr->fieldRect[i], pt)) return i;
826
    }
827

828
    return DTHT_NONE;
829 830
}

831 832
/* Returns index of the nearest preceding date field from given,
   or -1 if none was found */
833 834 835 836 837 838 839 840
static int DATETIME_GetPrevDateField(const DATETIME_INFO *infoPtr, int i)
{
    for(--i; i >= 0; i--)
    {
        if (infoPtr->fieldspec[i] & DTHT_DATEFIELD) return i;
    }
    return -1;
}
841

842 843 844 845
static void
DATETIME_ApplySelectedField (DATETIME_INFO *infoPtr)
{
    int fieldNum = infoPtr->select & DTHT_DATEFIELD;
846 847
    int i, val = 0;
    BOOL clamp_day = FALSE;
848
    SYSTEMTIME date = infoPtr->date;
849
    int oldyear;
850 851 852 853

    if (infoPtr->select == -1 || infoPtr->nCharsEntered == 0)
        return;

854 855 856 857 858 859 860
    if ((infoPtr->fieldspec[fieldNum] == ONELETTERAMPM) ||
        (infoPtr->fieldspec[fieldNum] == TWOLETTERAMPM))
        val = infoPtr->charsEntered[0];
    else {
        for (i=0; i<infoPtr->nCharsEntered; i++)
            val = val * 10 + infoPtr->charsEntered[i] - '0';
    }
861 862 863 864 865 866

    infoPtr->nCharsEntered = 0;

    switch (infoPtr->fieldspec[fieldNum]) {
        case ONEDIGITYEAR:
        case TWODIGITYEAR:
867
            oldyear = date.wYear;
868
            date.wYear = date.wYear - (date.wYear%100) + val;
869 870

            if (DATETIME_IsDateInValidRange(infoPtr, &date))
871
                clamp_day = TRUE;
872 873 874
            else
                date.wYear = oldyear;

875 876 877
            break;
        case INVALIDFULLYEAR:
        case FULLYEAR:
878
            oldyear = date.wYear;
879
            date.wYear = val;
880 881

            if (DATETIME_IsDateInValidRange(infoPtr, &date))
882
                clamp_day = TRUE;
883 884 885
            else
                date.wYear = oldyear;

886 887 888 889
            break;
        case ONEDIGITMONTH:
        case TWODIGITMONTH:
            date.wMonth = val;
890
            clamp_day = TRUE;
891 892 893 894 895 896 897
            break;
        case ONEDIGITDAY:
        case TWODIGITDAY:
            date.wDay = val;
            break;
        case ONEDIGIT12HOUR:
        case TWODIGIT12HOUR:
898 899 900 901 902 903 904 905 906 907 908 909
            if (val >= 24)
                val -= 20;

            if (val >= 13)
                date.wHour = val;
            else if (val != 0) {
                if (date.wHour >= 12) /* preserve current AM/PM state */
                    date.wHour = (val == 12 ? 12 : val + 12);
                else
                    date.wHour = (val == 12 ? 0 : val);
            }
            break;
910 911 912 913 914 915 916 917 918 919 920 921
        case ONEDIGIT24HOUR:
        case TWODIGIT24HOUR:
            date.wHour = val;
            break;
        case ONEDIGITMINUTE:
        case TWODIGITMINUTE:
            date.wMinute = val;
            break;
        case ONEDIGITSECOND:
        case TWODIGITSECOND:
            date.wSecond = val;
            break;
922 923 924 925 926 927 928 929 930 931
        case ONELETTERAMPM:
        case TWOLETTERAMPM:
            if (val == 'a' || val == 'A') {
                if (date.wHour >= 12)
                    date.wHour -= 12;
            } else if (val == 'p' || val == 'P') {
                if (date.wHour < 12)
                    date.wHour += 12;
            }
            break;
932 933
    }

934 935 936
    if (clamp_day && date.wDay > MONTHCAL_MonthLength(date.wMonth, date.wYear))
        date.wDay = MONTHCAL_MonthLength(date.wMonth, date.wYear);

937 938 939 940 941 942 943 944 945 946 947 948 949
    if (DATETIME_SetSystemTime(infoPtr, GDT_VALID, &date))
        DATETIME_SendDateTimeChangeNotify (infoPtr);
}

static void
DATETIME_SetSelectedField (DATETIME_INFO *infoPtr, int select)
{
    DATETIME_ApplySelectedField(infoPtr);

    infoPtr->select = select;
    infoPtr->nCharsEntered = 0;
}

950
static LRESULT
951
DATETIME_LButtonDown (DATETIME_INFO *infoPtr, INT x, INT y)
952
{
953
    POINT pt;
954
    int new;
955 956 957 958

    pt.x = x;
    pt.y = y;
    new = DATETIME_HitTest (infoPtr, pt);
959

960
    SetFocus(infoPtr->hwndSelf);
961

962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977
    if (!(new & DTHT_NODATEMASK) || (new == DTHT_NONE))
    {
        if (new == DTHT_NONE)
            new = infoPtr->nrFields - 1;
        else
        {
            /* hitting string part moves selection to next date field to left */
            if (infoPtr->fieldspec[new] & DT_STRING)
            {
                new = DATETIME_GetPrevDateField(infoPtr, new);
                if (new == -1) return 0;
            }
            /* never select full day of week */
            if (infoPtr->fieldspec[new] == FULLDAY) return 0;
        }
    }
978 979

    DATETIME_SetSelectedField(infoPtr, new);
980

981
    if (infoPtr->select == DTHT_MCPOPUP) {
982
        RECT rcMonthCal;
983
        POINT pos;
984 985
        SendMessageW(infoPtr->hMonthCal, MCM_GETMINREQRECT, 0, (LPARAM)&rcMonthCal);

986 987 988 989 990 991
        /* FIXME: button actually is only depressed during dropdown of the */
        /* calendar control and when the mouse is over the button window */
        infoPtr->bCalDepressed = TRUE;

        /* recalculate the position of the monthcal popup */
        if(infoPtr->dwStyle & DTS_RIGHTALIGN)
992
            pos.x = infoPtr->calbutton.left - (rcMonthCal.right - rcMonthCal.left);
993
        else
994
            /* FIXME: this should be after the area reserved for the checkbox */
995
            pos.x = infoPtr->rcDraw.left;
996

997 998 999 1000 1001
        pos.y = infoPtr->rcClient.bottom;
        OffsetRect( &rcMonthCal, pos.x, pos.y );
        MapWindowPoints( infoPtr->hwndSelf, 0, (POINT *)&rcMonthCal, 2 );
        SetWindowPos(infoPtr->hMonthCal, 0, rcMonthCal.left, rcMonthCal.top,
                     rcMonthCal.right - rcMonthCal.left, rcMonthCal.bottom - rcMonthCal.top, 0);
1002 1003 1004

        if(IsWindowVisible(infoPtr->hMonthCal)) {
            ShowWindow(infoPtr->hMonthCal, SW_HIDE);
1005 1006
            infoPtr->bDropdownEnabled = FALSE;
            DATETIME_SendSimpleNotify (infoPtr, DTN_CLOSEUP);
1007
        } else {
1008
            const SYSTEMTIME *lprgSysTimeArray = &infoPtr->date;
1009 1010 1011
            TRACE("update calendar %04d/%02d/%02d\n", 
            lprgSysTimeArray->wYear, lprgSysTimeArray->wMonth, lprgSysTimeArray->wDay);
            SendMessageW(infoPtr->hMonthCal, MCM_SETCURSEL, 0, (LPARAM)(&infoPtr->date));
1012

1013
            if (infoPtr->bDropdownEnabled) {
1014
                ShowWindow(infoPtr->hMonthCal, SW_SHOW);
1015 1016
                DATETIME_SendSimpleNotify (infoPtr, DTN_DROPDOWN);
            }
1017
            infoPtr->bDropdownEnabled = TRUE;
1018 1019 1020 1021
        }

        TRACE ("dt:%p mc:%p mc parent:%p, desktop:%p\n",
               infoPtr->hwndSelf, infoPtr->hMonthCal, infoPtr->hwndNotify, GetDesktopWindow ());
1022
    }
1023

1024
    InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
1025

1026
    return 0;
1027 1028 1029 1030
}


static LRESULT
1031
DATETIME_LButtonUp (DATETIME_INFO *infoPtr)
1032
{
1033
    if(infoPtr->bCalDepressed) {
1034 1035 1036
        infoPtr->bCalDepressed = FALSE;
        InvalidateRect(infoPtr->hwndSelf, &(infoPtr->calbutton), TRUE);
    }
1037

1038
    return 0;
1039 1040 1041 1042
}


static LRESULT
1043
DATETIME_Paint (DATETIME_INFO *infoPtr, HDC hdc)
1044
{
1045 1046 1047 1048 1049 1050 1051 1052
    if (!hdc) {
	PAINTSTRUCT ps;
        hdc = BeginPaint (infoPtr->hwndSelf, &ps);
        DATETIME_Refresh (infoPtr, hdc);
        EndPaint (infoPtr->hwndSelf, &ps);
    } else {
        DATETIME_Refresh (infoPtr, hdc);
    }
1053 1054 1055 1056

    /* Not a click on the dropdown box, enabled it */
    infoPtr->bDropdownEnabled = TRUE;

1057 1058 1059
    return 0;
}

1060

Huw Davies's avatar
Huw Davies committed
1061
static LRESULT
1062
DATETIME_Button_Command (DATETIME_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
Huw Davies's avatar
Huw Davies committed
1063
{
1064 1065 1066 1067
    if( HIWORD(wParam) == BN_CLICKED) {
        DWORD state = SendMessageW((HWND)lParam, BM_GETCHECK, 0, 0);
        infoPtr->dateValid = (state == BST_CHECKED);
        InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
Huw Davies's avatar
Huw Davies committed
1068
    }
1069
    return 0;
Huw Davies's avatar
Huw Davies committed
1070 1071 1072 1073 1074
}
          
        
        
static LRESULT
1075
DATETIME_Command (DATETIME_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
Huw Davies's avatar
Huw Davies committed
1076 1077 1078
{
    TRACE("hwndbutton = %p\n", infoPtr->hwndCheckbut);
    if(infoPtr->hwndCheckbut == (HWND)lParam)
1079
        return DATETIME_Button_Command(infoPtr, wParam, lParam);
Huw Davies's avatar
Huw Davies committed
1080 1081 1082
    return 0;
}

1083

1084 1085 1086 1087 1088 1089 1090 1091
static LRESULT
DATETIME_Enable (DATETIME_INFO *infoPtr, BOOL bEnable)
{
    TRACE("%p %s\n", infoPtr, bEnable ? "TRUE" : "FALSE");
    if (bEnable)
        infoPtr->dwStyle &= ~WS_DISABLED;
    else
        infoPtr->dwStyle |= WS_DISABLED;
1092 1093 1094

    InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);

1095 1096 1097 1098 1099
    return 0;
}


static LRESULT
1100
DATETIME_EraseBackground (const DATETIME_INFO *infoPtr, HDC hdc)
1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125
{
    HBRUSH hBrush, hSolidBrush = NULL;
    RECT   rc;

    if (infoPtr->dwStyle & WS_DISABLED)
        hBrush = hSolidBrush = CreateSolidBrush(comctl32_color.clrBtnFace);
    else
    {
        hBrush = (HBRUSH)SendMessageW(infoPtr->hwndNotify, WM_CTLCOLOREDIT,
                                      (WPARAM)hdc, (LPARAM)infoPtr->hwndSelf);
        if (!hBrush)
            hBrush = hSolidBrush = CreateSolidBrush(comctl32_color.clrWindow);
    }

    GetClientRect (infoPtr->hwndSelf, &rc);

    FillRect (hdc, &rc, hBrush);

    if (hSolidBrush)
        DeleteObject(hSolidBrush);

    return -1;
}


1126
static LRESULT
1127
DATETIME_Notify (DATETIME_INFO *infoPtr, const NMHDR *lpnmh)
1128
{
1129 1130 1131 1132 1133 1134 1135
    TRACE ("Got notification %x from %p\n", lpnmh->code, lpnmh->hwndFrom);
    TRACE ("info: %p %p %p\n", infoPtr->hwndSelf, infoPtr->hMonthCal, infoPtr->hUpdown);

    if (lpnmh->code == MCN_SELECT) {
        ShowWindow(infoPtr->hMonthCal, SW_HIDE);
        infoPtr->dateValid = TRUE;
        SendMessageW (infoPtr->hMonthCal, MCM_GETCURSEL, 0, (LPARAM)&infoPtr->date);
Duane Clark's avatar
Duane Clark committed
1136 1137
        TRACE("got from calendar %04d/%02d/%02d day of week %d\n", 
        infoPtr->date.wYear, infoPtr->date.wMonth, infoPtr->date.wDay, infoPtr->date.wDayOfWeek);
1138 1139 1140
        SendMessageW (infoPtr->hwndCheckbut, BM_SETCHECK, BST_CHECKED, 0);
        InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
        DATETIME_SendDateTimeChangeNotify (infoPtr);
1141
        DATETIME_SendSimpleNotify(infoPtr, DTN_CLOSEUP);
1142
    }
Duane Clark's avatar
Duane Clark committed
1143
    if ((lpnmh->hwndFrom == infoPtr->hUpdown) && (lpnmh->code == UDN_DELTAPOS)) {
1144
        const NM_UPDOWN *lpnmud = (const NM_UPDOWN*)lpnmh;
Duane Clark's avatar
Duane Clark committed
1145 1146 1147
        TRACE("Delta pos %d\n", lpnmud->iDelta);
        infoPtr->pendingUpdown = lpnmud->iDelta;
    }
1148
    return 0;
1149 1150
}

1151

1152
static LRESULT
1153
DATETIME_KeyDown (DATETIME_INFO *infoPtr, DWORD vkCode)
1154
{
1155 1156
    int fieldNum = infoPtr->select & DTHT_DATEFIELD;
    int wrap = 0;
1157
    int new;
1158

1159 1160
    if (!(infoPtr->haveFocus)) return 0;
    if ((fieldNum==0) && (infoPtr->select)) return 0;
1161

1162
    if (infoPtr->select & FORMATCALLMASK) {
1163
	FIXME ("Callbacks not implemented yet\n");
1164
    }
1165

1166
    switch (vkCode) {
1167
	case VK_ADD:
1168
    	case VK_UP:
1169
	    infoPtr->nCharsEntered = 0;
1170 1171 1172
	    DATETIME_IncreaseField (infoPtr, fieldNum, 1);
	    DATETIME_SendDateTimeChangeNotify (infoPtr);
	    break;
1173 1174
	case VK_SUBTRACT:
	case VK_DOWN:
1175
	    infoPtr->nCharsEntered = 0;
1176 1177 1178
	    DATETIME_IncreaseField (infoPtr, fieldNum, -1);
	    DATETIME_SendDateTimeChangeNotify (infoPtr);
	    break;
1179
	case VK_HOME:
1180
	    infoPtr->nCharsEntered = 0;
1181 1182 1183
	    DATETIME_IncreaseField (infoPtr, fieldNum, INT_MIN);
	    DATETIME_SendDateTimeChangeNotify (infoPtr);
	    break;
1184
	case VK_END:
1185
	    infoPtr->nCharsEntered = 0;
1186 1187 1188
	    DATETIME_IncreaseField (infoPtr, fieldNum, INT_MAX);
	    DATETIME_SendDateTimeChangeNotify (infoPtr);
	    break;
1189
	case VK_LEFT:
1190
	    new = infoPtr->select;
1191
	    do {
1192 1193
		if (new == 0) {
		    new = new - 1;
1194 1195
		    wrap++;
		} else {
1196
		    new--;
1197
		}
1198 1199 1200
	    } while ((infoPtr->fieldspec[new] & DT_STRING) && (wrap<2));
	    if (new != infoPtr->select)
	        DATETIME_SetSelectedField(infoPtr, new);
1201
	    break;
1202
	case VK_RIGHT:
1203
	    new = infoPtr->select;
1204
	    do {
1205 1206 1207
		new++;
		if (new==infoPtr->nrFields) {
		    new = 0;
1208 1209
		    wrap++;
		}
1210 1211 1212
	    } while ((infoPtr->fieldspec[new] & DT_STRING) && (wrap<2));
	    if (new != infoPtr->select)
	        DATETIME_SetSelectedField(infoPtr, new);
1213 1214
	    break;
    }
1215

1216
    InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
1217

1218
    return 0;
1219 1220 1221
}


1222
static LRESULT
1223
DATETIME_Char (DATETIME_INFO *infoPtr, WPARAM vkCode)
1224
{
1225
    int fieldNum, fieldSpec;
1226

1227 1228 1229 1230 1231 1232 1233 1234 1235
    fieldNum = infoPtr->select & DTHT_DATEFIELD;
    fieldSpec = infoPtr->fieldspec[fieldNum];

    if (fieldSpec == ONELETTERAMPM || fieldSpec == TWOLETTERAMPM) {
        infoPtr->charsEntered[0] = vkCode;
        infoPtr->nCharsEntered = 1;

        DATETIME_ApplySelectedField(infoPtr);
    } else if (vkCode >= '0' && vkCode <= '9') {
1236 1237 1238 1239 1240 1241 1242 1243 1244
        int maxChars;

        infoPtr->charsEntered[infoPtr->nCharsEntered++] = vkCode;

        if (fieldSpec == INVALIDFULLYEAR || fieldSpec == FULLYEAR)
            maxChars = 4;
        else
            maxChars = 2;

1245 1246 1247 1248 1249 1250 1251 1252 1253 1254
        if ((fieldSpec == ONEDIGIT12HOUR ||
             fieldSpec == TWODIGIT12HOUR ||
             fieldSpec == ONEDIGIT24HOUR ||
             fieldSpec == TWODIGIT24HOUR) &&
            (infoPtr->nCharsEntered == 1))
        {
            if (vkCode >= '3')
                 maxChars = 1;
        }

1255 1256
        if (maxChars == infoPtr->nCharsEntered)
            DATETIME_ApplySelectedField(infoPtr);
1257
    }
1258

1259 1260 1261 1262
    return 0;
}


Duane Clark's avatar
Duane Clark committed
1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280
static LRESULT
DATETIME_VScroll (DATETIME_INFO *infoPtr, WORD wScroll)
{
    int fieldNum = infoPtr->select & DTHT_DATEFIELD;

    if ((SHORT)LOWORD(wScroll) != SB_THUMBPOSITION) return 0;
    if (!(infoPtr->haveFocus)) return 0;
    if ((fieldNum==0) && (infoPtr->select)) return 0;

    if (infoPtr->pendingUpdown >= 0) {
	DATETIME_IncreaseField (infoPtr, fieldNum, 1);
	DATETIME_SendDateTimeChangeNotify (infoPtr);
    }
    else {
	DATETIME_IncreaseField (infoPtr, fieldNum, -1);
	DATETIME_SendDateTimeChangeNotify (infoPtr);
    }

1281
    InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
Duane Clark's avatar
Duane Clark committed
1282 1283 1284 1285 1286

    return 0;
}


1287
static LRESULT
1288
DATETIME_KillFocus (DATETIME_INFO *infoPtr, HWND lostFocus)
1289
{
1290 1291
    TRACE("lost focus to %p\n", lostFocus);

1292
    if (infoPtr->haveFocus) {
1293
	DATETIME_SendSimpleNotify (infoPtr, NM_KILLFOCUS);
1294
	infoPtr->haveFocus = 0;
1295
        DATETIME_SetSelectedField (infoPtr, -1);
1296
    }
1297

1298
    InvalidateRect (infoPtr->hwndSelf, NULL, TRUE);
1299 1300 1301 1302 1303

    return 0;
}


1304
static LRESULT
1305
DATETIME_NCCreate (HWND hwnd, const CREATESTRUCTW *lpcs)
1306 1307 1308 1309 1310 1311 1312 1313 1314 1315
{
    DWORD dwExStyle = GetWindowLongW(hwnd, GWL_EXSTYLE);
    /* force control to have client edge */
    dwExStyle |= WS_EX_CLIENTEDGE;
    SetWindowLongW(hwnd, GWL_EXSTYLE, dwExStyle);

    return DefWindowProcW(hwnd, WM_NCCREATE, 0, (LPARAM)lpcs);
}


1316
static LRESULT
1317
DATETIME_SetFocus (DATETIME_INFO *infoPtr, HWND lostFocus)
1318
{
1319 1320
    TRACE("got focus from %p\n", lostFocus);

1321
    /* if monthcal is open and it loses focus, close monthcal */
1322
    if (infoPtr->hMonthCal && (lostFocus == infoPtr->hMonthCal) &&
1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333
        IsWindowVisible(infoPtr->hMonthCal))
    {
        ShowWindow(infoPtr->hMonthCal, SW_HIDE);
        DATETIME_SendSimpleNotify(infoPtr, DTN_CLOSEUP);
        /* note: this get triggered even if monthcal loses focus to a dropdown
         * box click, which occurs without an intermediate WM_PAINT call
         */
        infoPtr->bDropdownEnabled = FALSE;
        return 0;
    }

1334 1335
    if (infoPtr->haveFocus == 0) {
	DATETIME_SendSimpleNotify (infoPtr, NM_SETFOCUS);
1336
	infoPtr->haveFocus = DTHT_GOTFOCUS;
1337
    }
1338

1339
    InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1340 1341 1342 1343 1344

    return 0;
}


1345
static BOOL
1346
DATETIME_SendDateTimeChangeNotify (const DATETIME_INFO *infoPtr)
1347
{
1348 1349 1350 1351 1352 1353
    NMDATETIMECHANGE dtdtc;

    dtdtc.nmhdr.hwndFrom = infoPtr->hwndSelf;
    dtdtc.nmhdr.idFrom   = GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_ID);
    dtdtc.nmhdr.code     = DTN_DATETIMECHANGE;

1354
    dtdtc.dwFlags = infoPtr->dateValid ? GDT_VALID : GDT_NONE;
1355

1356
    dtdtc.st = infoPtr->date;
1357
    return (BOOL) SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
1358
                                dtdtc.nmhdr.idFrom, (LPARAM)&dtdtc);
1359 1360 1361
}


1362
static BOOL
1363
DATETIME_SendSimpleNotify (const DATETIME_INFO *infoPtr, UINT code)
1364 1365 1366
{
    NMHDR nmhdr;

1367 1368 1369
    TRACE("%x\n", code);
    nmhdr.hwndFrom = infoPtr->hwndSelf;
    nmhdr.idFrom   = GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_ID);
1370 1371
    nmhdr.code     = code;

1372
    return (BOOL) SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
1373
                                nmhdr.idFrom, (LPARAM)&nmhdr);
1374
}
1375

1376
static LRESULT
1377
DATETIME_Size (DATETIME_INFO *infoPtr, INT width, INT height)
1378
{
1379 1380 1381 1382
    /* set size */
    infoPtr->rcClient.bottom = height;
    infoPtr->rcClient.right = width;

1383
    TRACE("Height=%d, Width=%d\n", infoPtr->rcClient.bottom, infoPtr->rcClient.right);
1384

1385
    infoPtr->rcDraw = infoPtr->rcClient;
Duane Clark's avatar
Duane Clark committed
1386 1387
    
    if (infoPtr->dwStyle & DTS_UPDOWN) {
1388 1389 1390 1391
        SetWindowPos(infoPtr->hUpdown, NULL,
            infoPtr->rcClient.right-14, 0,
            15, infoPtr->rcClient.bottom - infoPtr->rcClient.top,
            SWP_NOACTIVATE | SWP_NOZORDER);
Duane Clark's avatar
Duane Clark committed
1392 1393 1394 1395 1396 1397 1398 1399 1400
    }
    else {
        /* set the size of the button that drops the calendar down */
        /* FIXME: account for style that allows button on left side */
        infoPtr->calbutton.top   = infoPtr->rcDraw.top;
        infoPtr->calbutton.bottom= infoPtr->rcDraw.bottom;
        infoPtr->calbutton.left  = infoPtr->rcDraw.right-15;
        infoPtr->calbutton.right = infoPtr->rcDraw.right;
    }
1401 1402 1403 1404 1405 1406 1407 1408 1409

    /* set enable/disable button size for show none style being enabled */
    /* FIXME: these dimensions are completely incorrect */
    infoPtr->checkbox.top = infoPtr->rcDraw.top;
    infoPtr->checkbox.bottom = infoPtr->rcDraw.bottom;
    infoPtr->checkbox.left = infoPtr->rcDraw.left;
    infoPtr->checkbox.right = infoPtr->rcDraw.left + 10;

    InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1410

1411 1412
    return 0;
}
1413

1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430
static LRESULT
DATETIME_StyleChanging(DATETIME_INFO *infoPtr, WPARAM wStyleType, STYLESTRUCT *lpss)
{
    TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
          wStyleType, lpss->styleOld, lpss->styleNew);

    /* block DTS_SHOWNONE change */
    if ((lpss->styleNew ^ lpss->styleOld) & DTS_SHOWNONE)
    {
        if (lpss->styleOld & DTS_SHOWNONE)
            lpss->styleNew |= DTS_SHOWNONE;
        else
            lpss->styleNew &= ~DTS_SHOWNONE;
    }

    return 0;
}
1431

1432
static LRESULT 
1433
DATETIME_StyleChanged(DATETIME_INFO *infoPtr, WPARAM wStyleType, const STYLESTRUCT *lpss)
1434
{
1435
    TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
1436
          wStyleType, lpss->styleOld, lpss->styleNew);
1437

1438 1439 1440
    if (wStyleType != GWL_STYLE) return 0;
  
    infoPtr->dwStyle = lpss->styleNew;
1441

1442
    if ( !(lpss->styleOld & DTS_SHOWNONE) && (lpss->styleNew & DTS_SHOWNONE) ) {
1443
        infoPtr->hwndCheckbut = CreateWindowExW (0, WC_BUTTONW, 0, WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
1444 1445
         					 2, 2, 13, 13, infoPtr->hwndSelf, 0, 
						(HINSTANCE)GetWindowLongPtrW (infoPtr->hwndSelf, GWLP_HINSTANCE), 0);
1446
        SendMessageW (infoPtr->hwndCheckbut, BM_SETCHECK, infoPtr->dateValid ? 1 : 0, 0);
1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459
    }
    if ( (lpss->styleOld & DTS_SHOWNONE) && !(lpss->styleNew & DTS_SHOWNONE) ) {
        DestroyWindow(infoPtr->hwndCheckbut);
        infoPtr->hwndCheckbut = 0;
    }
    if ( !(lpss->styleOld & DTS_UPDOWN) && (lpss->styleNew & DTS_UPDOWN) ) {
	infoPtr->hUpdown = CreateUpDownControl (WS_CHILD | WS_BORDER | WS_VISIBLE, 120, 1, 20, 20, 
						infoPtr->hwndSelf, 1, 0, 0, UD_MAXVAL, UD_MINVAL, 0);
    }
    if ( (lpss->styleOld & DTS_UPDOWN) && !(lpss->styleNew & DTS_UPDOWN) ) {
	DestroyWindow(infoPtr->hUpdown);
	infoPtr->hUpdown = 0;
    }
1460

1461 1462
    InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
    return 0;
1463
}
1464

1465

1466 1467 1468 1469 1470 1471 1472 1473 1474
static LRESULT
DATETIME_SetFont (DATETIME_INFO *infoPtr, HFONT font, BOOL repaint)
{
    infoPtr->hFont = font;
    if (repaint) InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
    return 0;
}


1475
static LRESULT
1476
DATETIME_Create (HWND hwnd, const CREATESTRUCTW *lpcs)
1477
{
1478
    DATETIME_INFO *infoPtr = Alloc (sizeof(DATETIME_INFO));
1479 1480 1481 1482 1483 1484 1485 1486
    STYLESTRUCT ss = { 0, lpcs->style };

    if (!infoPtr) return -1;

    infoPtr->hwndSelf = hwnd;
    infoPtr->dwStyle = lpcs->style;

    infoPtr->nrFieldsAllocated = 32;
1487 1488 1489
    infoPtr->fieldspec = Alloc (infoPtr->nrFieldsAllocated * sizeof(int));
    infoPtr->fieldRect = Alloc (infoPtr->nrFieldsAllocated * sizeof(RECT));
    infoPtr->buflen = Alloc (infoPtr->nrFieldsAllocated * sizeof(int));
1490
    infoPtr->hwndNotify = lpcs->hwndParent;
1491
    infoPtr->select = -1; /* initially, nothing is selected */
1492
    infoPtr->bDropdownEnabled = TRUE;
1493 1494 1495 1496 1497

    DATETIME_StyleChanged(infoPtr, GWL_STYLE, &ss);
    DATETIME_SetFormatW (infoPtr, 0);

    /* create the monthcal control */
1498
    infoPtr->hMonthCal = CreateWindowExW (0, MONTHCAL_CLASSW, 0, WS_BORDER | WS_POPUP | WS_CLIPSIBLINGS,
1499 1500 1501
					  0, 0, 0, 0, infoPtr->hwndSelf, 0, 0, 0);

    /* initialize info structure */
1502
    GetLocalTime (&infoPtr->date);
1503 1504 1505 1506 1507 1508
    infoPtr->dateValid = TRUE;
    infoPtr->hFont = GetStockObject(DEFAULT_GUI_FONT);

    SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);

    return 0;
1509 1510 1511
}


1512

1513
static LRESULT
1514
DATETIME_Destroy (DATETIME_INFO *infoPtr)
1515
{
1516 1517 1518 1519
    if (infoPtr->hwndCheckbut)
	DestroyWindow(infoPtr->hwndCheckbut);
    if (infoPtr->hUpdown)
	DestroyWindow(infoPtr->hUpdown);
1520
    if (infoPtr->hMonthCal) 
1521
        DestroyWindow(infoPtr->hMonthCal);
1522
    SetWindowLongPtrW( infoPtr->hwndSelf, 0, 0 ); /* clear infoPtr */
1523 1524 1525
    Free (infoPtr->buflen);
    Free (infoPtr->fieldRect);
    Free (infoPtr->fieldspec);
1526
    Free (infoPtr);
1527 1528 1529 1530
    return 0;
}


1531
static INT
1532
DATETIME_GetText (const DATETIME_INFO *infoPtr, INT count, LPWSTR dst)
1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550
{
    WCHAR buf[80];
    int i;

    if (!dst || (count <= 0)) return 0;

    dst[0] = 0;
    for (i = 0; i < infoPtr->nrFields; i++)
    {
        DATETIME_ReturnTxt(infoPtr, i, buf, sizeof(buf)/sizeof(buf[0]));
        if ((strlenW(dst) + strlenW(buf)) < count)
            strcatW(dst, buf);
        else break;
    }
    return strlenW(dst);
}


1551
static LRESULT WINAPI
1552
DATETIME_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1553
{
1554 1555
    DATETIME_INFO *infoPtr = ((DATETIME_INFO *)GetWindowLongPtrW (hwnd, 0));

1556
    TRACE ("%x, %lx, %lx\n", uMsg, wParam, lParam);
1557

1558
    if (!infoPtr && (uMsg != WM_CREATE) && (uMsg != WM_NCCREATE))
1559
	return DefWindowProcW( hwnd, uMsg, wParam, lParam );
1560

1561
    switch (uMsg) {
1562

1563
    case DTM_GETSYSTEMTIME:
1564
        return DATETIME_GetSystemTime (infoPtr, (SYSTEMTIME *) lParam);
1565 1566

    case DTM_SETSYSTEMTIME:
1567
	return DATETIME_SetSystemTime (infoPtr, wParam, (SYSTEMTIME *) lParam);
1568 1569

    case DTM_GETRANGE:
1570
	return SendMessageW (infoPtr->hMonthCal, MCM_GETRANGE, wParam, lParam);
1571 1572

    case DTM_SETRANGE:
1573
	return SendMessageW (infoPtr->hMonthCal, MCM_SETRANGE, wParam, lParam);
1574

1575
    case DTM_SETFORMATA:
1576
        return DATETIME_SetFormatA (infoPtr, (LPCSTR)lParam);
1577

1578
    case DTM_SETFORMATW:
1579
        return DATETIME_SetFormatW (infoPtr, (LPCWSTR)lParam);
1580

1581 1582 1583
    case DTM_GETMONTHCAL:
	return (LRESULT)infoPtr->hMonthCal;

1584
    case DTM_SETMCCOLOR:
1585
	return SendMessageW (infoPtr->hMonthCal, MCM_SETCOLOR, wParam, lParam);
1586 1587

    case DTM_GETMCCOLOR:
1588
        return SendMessageW (infoPtr->hMonthCal, MCM_GETCOLOR, wParam, 0);
1589 1590

    case DTM_SETMCFONT:
1591
	return SendMessageW (infoPtr->hMonthCal, WM_SETFONT, wParam, lParam);
1592 1593

    case DTM_GETMCFONT:
1594
	return SendMessageW (infoPtr->hMonthCal, WM_GETFONT, wParam, lParam);
1595 1596

    case WM_NOTIFY:
1597
	return DATETIME_Notify (infoPtr, (LPNMHDR)lParam);
1598

1599 1600 1601 1602 1603 1604
    case WM_ENABLE:
        return DATETIME_Enable (infoPtr, (BOOL)wParam);

    case WM_ERASEBKGND:
        return DATETIME_EraseBackground (infoPtr, (HDC)wParam);

1605 1606
    case WM_GETDLGCODE:
        return DLGC_WANTARROWS | DLGC_WANTCHARS;
1607

1608
    case WM_PRINTCLIENT:
1609
    case WM_PAINT:
1610
        return DATETIME_Paint (infoPtr, (HDC)wParam);
1611

1612
    case WM_KEYDOWN:
1613
        return DATETIME_KeyDown (infoPtr, wParam);
1614

1615
    case WM_CHAR:
1616
        return DATETIME_Char (infoPtr, wParam);
1617

1618
    case WM_KILLFOCUS:
1619
        return DATETIME_KillFocus (infoPtr, (HWND)wParam);
1620

1621 1622 1623
    case WM_NCCREATE:
        return DATETIME_NCCreate (hwnd, (LPCREATESTRUCTW)lParam);

1624
    case WM_SETFOCUS:
1625
        return DATETIME_SetFocus (infoPtr, (HWND)wParam);
1626

1627
    case WM_SIZE:
1628
        return DATETIME_Size (infoPtr, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
1629

1630
    case WM_LBUTTONDOWN:
1631
        return DATETIME_LButtonDown (infoPtr, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
1632

1633
    case WM_LBUTTONUP:
1634
        return DATETIME_LButtonUp (infoPtr);
1635

Duane Clark's avatar
Duane Clark committed
1636 1637 1638
    case WM_VSCROLL:
        return DATETIME_VScroll (infoPtr, (WORD)wParam);

1639
    case WM_CREATE:
1640
	return DATETIME_Create (hwnd, (LPCREATESTRUCTW)lParam);
1641

1642
    case WM_DESTROY:
1643
	return DATETIME_Destroy (infoPtr);
1644

Huw Davies's avatar
Huw Davies committed
1645
    case WM_COMMAND:
1646
        return DATETIME_Command (infoPtr, wParam, lParam);
Huw Davies's avatar
Huw Davies committed
1647

1648 1649 1650
    case WM_STYLECHANGING:
        return DATETIME_StyleChanging(infoPtr, wParam, (LPSTYLESTRUCT)lParam);

1651 1652 1653
    case WM_STYLECHANGED:
        return DATETIME_StyleChanged(infoPtr, wParam, (LPSTYLESTRUCT)lParam);

1654 1655 1656 1657 1658 1659
    case WM_SETFONT:
        return DATETIME_SetFont(infoPtr, (HFONT)wParam, (BOOL)lParam);

    case WM_GETFONT:
        return (LRESULT) infoPtr->hFont;

1660 1661 1662
    case WM_GETTEXT:
        return (LRESULT) DATETIME_GetText(infoPtr, wParam, (LPWSTR)lParam);

1663 1664 1665
    case WM_SETTEXT:
        return CB_ERR;

1666
    default:
1667
	if ((uMsg >= WM_USER) && (uMsg < WM_APP) && !COMCTL32_IsReflectedMessage(uMsg))
1668
		ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
1669
		     uMsg, wParam, lParam);
1670
	return DefWindowProcW (hwnd, uMsg, wParam, lParam);
1671 1672 1673 1674
    }
}


1675
void
1676
DATETIME_Register (void)
1677
{
1678
    WNDCLASSW wndClass;
1679

1680
    ZeroMemory (&wndClass, sizeof(WNDCLASSW));
1681
    wndClass.style         = CS_GLOBALCLASS;
1682
    wndClass.lpfnWndProc   = DATETIME_WindowProc;
1683 1684
    wndClass.cbClsExtra    = 0;
    wndClass.cbWndExtra    = sizeof(DATETIME_INFO *);
1685
    wndClass.hCursor       = LoadCursorW (0, (LPCWSTR)IDC_ARROW);
1686
    wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
1687
    wndClass.lpszClassName = DATETIMEPICK_CLASSW;
1688

1689
    RegisterClassW (&wndClass);
1690 1691 1692
}


1693
void
1694
DATETIME_Unregister (void)
1695
{
1696
    UnregisterClassW (DATETIMEPICK_CLASSW, NULL);
1697
}