# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1321361152 0 # Node ID 19aa1af6855e43abb2612d809961cff4a7d7bc38 # Parent 64c8eba7c0fce9c2c481c8d9f59c3256f049b9c1 OS/2 calendar fix to make sure the selected day does not exceed the number of days in the currently selected month. diff -r 64c8eba7c0fc -r 19aa1af6855e os2/dw.c --- a/os2/dw.c Tue Nov 15 12:33:10 2011 +0000 +++ b/os2/dw.c Tue Nov 15 12:45:52 2011 +0000 @@ -1652,6 +1652,7 @@ case WM_BUTTON3DOWN: { POINTS pts = (*((POINTS*)&mp1)); + int day = DW_POINTER_TO_INT(dw_window_get_data(hWnd, "_dw_day")); int month = DW_POINTER_TO_INT(dw_window_get_data(hWnd, "_dw_month")); int year = DW_POINTER_TO_INT(dw_window_get_data(hWnd, "_dw_year")); int dayofweek = 1, x, height, isleapyear = ((year+1) % 4 == 0); @@ -1660,7 +1661,7 @@ /* Figure out what day of the week the first day of the month falls on */ for(x=0;x rclArea.xLeft + CALENDAR_BORDER && pts.x < rclArea.xLeft + CALENDAR_BORDER + CALENDAR_ARROW && pts.y > rclArea.yTop - (CALENDAR_BORDER + height) && pts.y < rclArea.yTop - CALENDAR_BORDER) { + int daysthismonth; + if(month == 0) { month = 11; @@ -1682,6 +1685,15 @@ month--; } dw_window_set_data(hWnd, "_dw_month", DW_INT_TO_POINTER(month)); + /* Make sure we aren't higher than the number of days + * in our new month... keeping track of leap years. + */ + daysthismonth = days[month] + (isleapyear && month == 1); + if(day >= daysthismonth) + { + day = daysthismonth - 1; + dw_window_set_data(hWnd, "_dw_day", DW_INT_TO_POINTER(day)); + } WinInvalidateRect(hWnd, &rclArea, FALSE); WinPostMsg(hWnd, WM_PAINT, 0, 0); return (MRESULT)TRUE; @@ -1691,6 +1703,8 @@ if(pts.x < rclArea.xRight - CALENDAR_BORDER && pts.x > rclArea.xRight - CALENDAR_BORDER - CALENDAR_ARROW && pts.y > rclArea.yTop - (CALENDAR_BORDER + height) && pts.y < rclArea.yTop - CALENDAR_BORDER) { + int daysthismonth; + if(month == 11) { month = 0; @@ -1702,6 +1716,15 @@ month++; } dw_window_set_data(hWnd, "_dw_month", DW_INT_TO_POINTER(month)); + /* Make sure we aren't higher than the number of days + * in our new month... keeping track of leap years. + */ + daysthismonth = days[month] + (isleapyear && month == 1); + if(day >= daysthismonth) + { + day = daysthismonth - 1; + dw_window_set_data(hWnd, "_dw_day", DW_INT_TO_POINTER(day)); + } WinInvalidateRect(hWnd, &rclArea, FALSE); WinPostMsg(hWnd, WM_PAINT, 0, 0); return (MRESULT)TRUE;