From 598cd4617faeb5b0d79408a34a8db53e43c2e442 Mon Sep 17 00:00:00 2001 From: =?utf-8?q?Miko=C5=82aj_Zalewski?= Date: Fri, 22 Feb 2008 22:32:47 +0100 Subject: [PATCH] comctl32: datetime: support literals in apostrophes (fixes bug #10604) --- dlls/comctl32/datetime.c | 57 +++++++++++++++++++++++---------------- dlls/comctl32/tests/datetime.c | 13 +++++++++ 2 files changed, 47 insertions(+), 23 deletions(-) diff --git a/dlls/comctl32/datetime.c b/dlls/comctl32/datetime.c index 100cd74..29f53ff 100644 --- a/dlls/comctl32/datetime.c +++ b/dlls/comctl32/datetime.c @@ -133,8 +133,8 @@ extern int MONTHCAL_MonthLength(int month, int year); static BOOL DATETIME_SendSimpleNotify (const DATETIME_INFO *infoPtr, UINT code); static BOOL DATETIME_SendDateTimeChangeNotify (const DATETIME_INFO *infoPtr); extern void MONTHCAL_CopyTime(const SYSTEMTIME *from, SYSTEMTIME *to); -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,-1}; +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}; static DWORD @@ -205,6 +205,7 @@ DATETIME_UseFormat (DATETIME_INFO *infoPtr, LPCWSTR formattxt) { unsigned int i; int j, k, len; + BOOL inside_literal = FALSE; /* inside '...' */ int *nrFields = &infoPtr->nrFields; *nrFields = 0; @@ -214,27 +215,37 @@ DATETIME_UseFormat (DATETIME_INFO *infoPtr, LPCWSTR formattxt) for (i = 0; formattxt[i]; i++) { TRACE ("\n%d %c:", i, formattxt[i]); - 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 */ + 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; + } /* char is not a specifier: handle char like a string */ if (j == len) { diff --git a/dlls/comctl32/tests/datetime.c b/dlls/comctl32/tests/datetime.c index 76fdccc..b194cc1 100644 --- a/dlls/comctl32/tests/datetime.c +++ b/dlls/comctl32/tests/datetime.c @@ -193,6 +193,8 @@ static HWND create_datetime_control(DWORD style, DWORD exstyle) static void test_dtm_set_format(HWND hWndDateTime) { + CHAR txt[256]; + SYSTEMTIME systime; LRESULT r; r = SendMessage(hWndDateTime, DTM_SETFORMAT, 0, (LPARAM)NULL); @@ -203,6 +205,17 @@ static void test_dtm_set_format(HWND hWndDateTime) expect(1, r); ok_sequence(sequences, DATETIME_SEQ_INDEX, test_dtm_set_format_seq, "test_dtm_set_format", FALSE); + + r = SendMessage(hWndDateTime, DTM_SETFORMAT, 0, + (LPARAM)"'hh' hh"); + expect(1, r); + ZeroMemory(&systime, sizeof(systime)); + systime.wYear = 2000; + systime.wMonth = systime.wDay = 1; + r = SendMessage(hWndDateTime, DTM_SETSYSTEMTIME, 0, (LPARAM)&systime); + expect(1, r); + GetWindowText(hWndDateTime, txt, 256); + todo_wine ok(strcmp(txt, "hh 12") == 0, "String mismatch (\"%s\" vs \"hh 12\")\n", txt); flush_sequences(sequences, NUM_MSG_SEQUENCES); } -- 1.4.4.2