From 74d1c11684b91cb88c663b016f423876ab8c028f Mon Sep 17 00:00:00 2001 From: Owen Rudge Date: Thu, 8 Mar 2012 11:34:33 +0000 Subject: [PATCH] comctl32/datetime: Allow entering 'AM' or 'PM' via keyboard. --- dlls/comctl32/datetime.c | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/dlls/comctl32/datetime.c b/dlls/comctl32/datetime.c index f29b2d2deb..f65691ee4f 100644 --- a/dlls/comctl32/datetime.c +++ b/dlls/comctl32/datetime.c @@ -852,8 +852,13 @@ DATETIME_ApplySelectedField (DATETIME_INFO *infoPtr) if (infoPtr->select == -1 || infoPtr->nCharsEntered == 0) return; - for (i=0; inCharsEntered; 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; inCharsEntered; 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; } -- 2.32.0.93.g670b81a890