diff --git a/dlls/comctl32/monthcal.c b/dlls/comctl32/monthcal.c index e9aeac6259e..384efe78432 100644 --- a/dlls/comctl32/monthcal.c +++ b/dlls/comctl32/monthcal.c @@ -1937,6 +1937,24 @@ static INT MONTHCAL_StyleChanged(MONTHCAL_INFO *infoPtr, WPARAM wStyleType, return 0; } +static INT MONTHCAL_StyleChanging(MONTHCAL_INFO *infoPtr, WPARAM wStyleType, + STYLESTRUCT *lpss) +{ + TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n", + wStyleType, lpss->styleOld, lpss->styleNew); + + /* block MCS_MULTISELECT change */ + if ((lpss->styleNew ^ lpss->styleOld) & MCS_MULTISELECT) + { + if (lpss->styleOld & MCS_MULTISELECT) + lpss->styleNew |= MCS_MULTISELECT; + else + lpss->styleNew &= ~MCS_MULTISELECT; + } + + return 0; +} + /* FIXME: check whether dateMin/dateMax need to be adjusted. */ static LRESULT MONTHCAL_Create(HWND hwnd, LPCREATESTRUCTW lpcs) @@ -1965,7 +1983,7 @@ MONTHCAL_Create(HWND hwnd, LPCREATESTRUCTW lpcs) infoPtr->firstDayHighWord = FALSE; MONTHCAL_SetFirstDayOfWeek(infoPtr, -1); - infoPtr->maxSelCount = 7; + infoPtr->maxSelCount = (infoPtr->dwStyle & MCS_MULTISELECT) ? 7 : 1; infoPtr->monthRange = 3; infoPtr->monthdayState = Alloc(infoPtr->monthRange * sizeof(MONTHDAYSTATE)); infoPtr->titlebk = comctl32_color.clrActiveCaption; @@ -2131,6 +2149,9 @@ MONTHCAL_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) case WM_STYLECHANGED: return MONTHCAL_StyleChanged(infoPtr, wParam, (LPSTYLESTRUCT)lParam); + case WM_STYLECHANGING: + return MONTHCAL_StyleChanging(infoPtr, wParam, (LPSTYLESTRUCT)lParam); + default: if ((uMsg >= WM_USER) && (uMsg < WM_APP) && !COMCTL32_IsReflectedMessage(uMsg)) ERR( "unknown msg %04x wp=%08lx lp=%08lx\n", uMsg, wParam, lParam); diff --git a/dlls/comctl32/tests/monthcal.c b/dlls/comctl32/tests/monthcal.c index 268c25aa67c..cd9d15eb863 100644 --- a/dlls/comctl32/tests/monthcal.c +++ b/dlls/comctl32/tests/monthcal.c @@ -580,6 +580,14 @@ static LRESULT WINAPI monthcal_subclass_proc(HWND hwnd, UINT message, WPARAM wPa msg.lParam = lParam; add_message(sequences, MONTHCAL_SEQ_INDEX, &msg); + /* some debug output for style changing */ + if ((message == WM_STYLECHANGING || + message == WM_STYLECHANGED) && lParam) + { + STYLESTRUCT *style = (STYLESTRUCT*)lParam; + trace("\told style: 0x%08x, new style: 0x%08x\n", style->styleOld, style->styleNew); + } + defwndproc_counter++; ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam); defwndproc_counter--; @@ -1302,8 +1310,33 @@ static void test_monthcal_maxselday(void) { int res; HWND hwnd; + DWORD style; + + hwnd = create_monthcal_control(0); + /* if no style specified default to 1 */ + res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0); + expect(1, res); + + /* try to set style */ + style = GetWindowLong(hwnd, GWL_STYLE); + SetWindowLong(hwnd, GWL_STYLE, style | MCS_MULTISELECT); + style = GetWindowLong(hwnd, GWL_STYLE); + ok(!(style & MCS_MULTISELECT), "Expected MCS_MULTISELECT not to be set\n"); + DestroyWindow(hwnd); hwnd = create_monthcal_control(MCS_MULTISELECT); + /* try to remove style */ + style = GetWindowLong(hwnd, GWL_STYLE); + SetWindowLong(hwnd, GWL_STYLE, style & ~MCS_MULTISELECT); + style = GetWindowLong(hwnd, GWL_STYLE); + ok(style & MCS_MULTISELECT, "Expected MCS_MULTISELECT to be set\n"); + DestroyWindow(hwnd); + + hwnd = create_monthcal_control(MCS_MULTISELECT); + + /* default width is a week */ + res = SendMessage(hwnd, MCM_GETMAXSELCOUNT, 0, 0); + expect(7, res); flush_sequences(sequences, NUM_MSG_SEQUENCES);