# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1321360390 0 # Node ID 64c8eba7c0fce9c2c481c8d9f59c3256f049b9c1 # Parent 2bc23978cfcd8b74d8fd880adb2e8aabcd3ae755 Fixes for handling leap years on the OS/2 calendar control. diff -r 2bc23978cfcd -r 64c8eba7c0fc os2/dw.c --- a/os2/dw.c Tue Nov 15 05:21:32 2011 +0000 +++ b/os2/dw.c Tue Nov 15 12:33:10 2011 +0000 @@ -1654,7 +1654,8 @@ POINTS pts = (*((POINTS*)&mp1)); 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; + int dayofweek = 1, x, height, isleapyear = ((year+1) % 4 == 0); + int daysthismonth = days[month] + (isleapyear && month == 1); RECTL rclArea; /* Figure out what day of the week the first day of the month falls on */ @@ -1707,7 +1708,7 @@ } /* Check all the valid days of the month */ - for(x=dayofweek+7;x<(days[month]+dayofweek+7);x++) + for(x=dayofweek+7;x<(daysthismonth+dayofweek+7);x++) { RECTL rclThis = _CalendarDayRect(x, rclArea); if(pts.x < rclThis.xRight && pts.x > rclThis.xLeft && pts.y < rclThis.yTop && pts.y > rclThis.yBottom) @@ -1728,7 +1729,7 @@ 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, lastmonth = 11, height; + int dayofweek = 1, x, lastmonth = 11, height, isleapyear = ((year+1) % 4 == 0); POINTL pptl[3]; /* Figure out the previous month for later use */ @@ -1740,7 +1741,7 @@ /* Figure out what day of the week the first day of the month falls on */ for(x=0;x days[month]) + else if(x - dayofweek + 1 > daysthismonth) { GpiSetColor(hpsPaint, CLR_DARKGRAY); - sprintf(buf, "%d", x - dayofweek - days[month] + 1); + sprintf(buf, "%d", x - dayofweek - daysthismonth + 1); } else {