comctl32/datetime: Allow entering 'AM' or 'PM' via keyboard.

This commit is contained in:
Owen Rudge 2012-03-08 11:34:33 +00:00 committed by Alexandre Julliard
parent 9147e7fd22
commit 74d1c11684

View File

@ -852,8 +852,13 @@ DATETIME_ApplySelectedField (DATETIME_INFO *infoPtr)
if (infoPtr->select == -1 || infoPtr->nCharsEntered == 0)
return;
for (i=0; i<infoPtr->nCharsEntered; i++)
val = val * 10 + infoPtr->charsEntered[i] - '0';
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';
}
infoPtr->nCharsEntered = 0;
@ -904,6 +909,16 @@ DATETIME_ApplySelectedField (DATETIME_INFO *infoPtr)
case TWODIGITSECOND:
date.wSecond = val;
break;
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;
}
if (clamp_day && date.wDay > MONTHCAL_MonthLength(date.wMonth, date.wYear))
@ -1197,16 +1212,21 @@ DATETIME_KeyDown (DATETIME_INFO *infoPtr, DWORD vkCode)
static LRESULT
DATETIME_Char (DATETIME_INFO *infoPtr, WPARAM vkCode)
{
int fieldNum = infoPtr->select & DTHT_DATEFIELD;
int fieldNum, fieldSpec;
if (vkCode >= '0' && vkCode <= '9') {
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') {
int maxChars;
int fieldSpec;
infoPtr->charsEntered[infoPtr->nCharsEntered++] = vkCode;
fieldSpec = infoPtr->fieldspec[fieldNum];
if (fieldSpec == INVALIDFULLYEAR || fieldSpec == FULLYEAR)
maxChars = 4;
else
@ -1215,6 +1235,7 @@ DATETIME_Char (DATETIME_INFO *infoPtr, WPARAM vkCode)
if (maxChars == infoPtr->nCharsEntered)
DATETIME_ApplySelectedField(infoPtr);
}
return 0;
}