comparison os2/dw.c @ 1349:19aa1af6855e

OS/2 calendar fix to make sure the selected day does not exceed the number of days in the currently selected month.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 15 Nov 2011 12:45:52 +0000
parents 64c8eba7c0fc
children 1f22addc2722
comparison
equal deleted inserted replaced
1348:64c8eba7c0fc 1349:19aa1af6855e
1650 case WM_BUTTON1DOWN: 1650 case WM_BUTTON1DOWN:
1651 case WM_BUTTON2DOWN: 1651 case WM_BUTTON2DOWN:
1652 case WM_BUTTON3DOWN: 1652 case WM_BUTTON3DOWN:
1653 { 1653 {
1654 POINTS pts = (*((POINTS*)&mp1)); 1654 POINTS pts = (*((POINTS*)&mp1));
1655 int day = DW_POINTER_TO_INT(dw_window_get_data(hWnd, "_dw_day"));
1655 int month = DW_POINTER_TO_INT(dw_window_get_data(hWnd, "_dw_month")); 1656 int month = DW_POINTER_TO_INT(dw_window_get_data(hWnd, "_dw_month"));
1656 int year = DW_POINTER_TO_INT(dw_window_get_data(hWnd, "_dw_year")); 1657 int year = DW_POINTER_TO_INT(dw_window_get_data(hWnd, "_dw_year"));
1657 int dayofweek = 1, x, height, isleapyear = ((year+1) % 4 == 0); 1658 int dayofweek = 1, x, height, isleapyear = ((year+1) % 4 == 0);
1658 int daysthismonth = days[month] + (isleapyear && month == 1); 1659 int daysthismonth = days[month] + (isleapyear && month == 1);
1659 RECTL rclArea; 1660 RECTL rclArea;
1660 1661
1661 /* Figure out what day of the week the first day of the month falls on */ 1662 /* Figure out what day of the week the first day of the month falls on */
1662 for(x=0;x<month;x++) 1663 for(x=0;x<month;x++)
1663 dayofweek += days[x]; 1664 dayofweek += days[x] + (isleapyear && x == 1);
1664 dayofweek += (year/4) + year - 1; 1665 dayofweek += (year/4) + year - 1;
1665 dayofweek = dayofweek % 7; 1666 dayofweek = dayofweek % 7;
1666 1667
1667 WinQueryWindowRect(hWnd, &rclArea); 1668 WinQueryWindowRect(hWnd, &rclArea);
1668 height = ((rclArea.yTop - (CALENDAR_BORDER*2))/7); 1669 height = ((rclArea.yTop - (CALENDAR_BORDER*2))/7);
1669 1670
1670 /* Check for the left arrow */ 1671 /* Check for the left arrow */
1671 if(pts.x > rclArea.xLeft + CALENDAR_BORDER && pts.x < rclArea.xLeft + CALENDAR_BORDER + CALENDAR_ARROW && 1672 if(pts.x > rclArea.xLeft + CALENDAR_BORDER && pts.x < rclArea.xLeft + CALENDAR_BORDER + CALENDAR_ARROW &&
1672 pts.y > rclArea.yTop - (CALENDAR_BORDER + height) && pts.y < rclArea.yTop - CALENDAR_BORDER) 1673 pts.y > rclArea.yTop - (CALENDAR_BORDER + height) && pts.y < rclArea.yTop - CALENDAR_BORDER)
1673 { 1674 {
1675 int daysthismonth;
1676
1674 if(month == 0) 1677 if(month == 0)
1675 { 1678 {
1676 month = 11; 1679 month = 11;
1677 year--; 1680 year--;
1678 dw_window_set_data(hWnd, "_dw_year", DW_INT_TO_POINTER(year)); 1681 dw_window_set_data(hWnd, "_dw_year", DW_INT_TO_POINTER(year));
1680 else if(month > 0) 1683 else if(month > 0)
1681 { 1684 {
1682 month--; 1685 month--;
1683 } 1686 }
1684 dw_window_set_data(hWnd, "_dw_month", DW_INT_TO_POINTER(month)); 1687 dw_window_set_data(hWnd, "_dw_month", DW_INT_TO_POINTER(month));
1688 /* Make sure we aren't higher than the number of days
1689 * in our new month... keeping track of leap years.
1690 */
1691 daysthismonth = days[month] + (isleapyear && month == 1);
1692 if(day >= daysthismonth)
1693 {
1694 day = daysthismonth - 1;
1695 dw_window_set_data(hWnd, "_dw_day", DW_INT_TO_POINTER(day));
1696 }
1685 WinInvalidateRect(hWnd, &rclArea, FALSE); 1697 WinInvalidateRect(hWnd, &rclArea, FALSE);
1686 WinPostMsg(hWnd, WM_PAINT, 0, 0); 1698 WinPostMsg(hWnd, WM_PAINT, 0, 0);
1687 return (MRESULT)TRUE; 1699 return (MRESULT)TRUE;
1688 } 1700 }
1689 1701
1690 /* Check for the right arrow */ 1702 /* Check for the right arrow */
1691 if(pts.x < rclArea.xRight - CALENDAR_BORDER && pts.x > rclArea.xRight - CALENDAR_BORDER - CALENDAR_ARROW && 1703 if(pts.x < rclArea.xRight - CALENDAR_BORDER && pts.x > rclArea.xRight - CALENDAR_BORDER - CALENDAR_ARROW &&
1692 pts.y > rclArea.yTop - (CALENDAR_BORDER + height) && pts.y < rclArea.yTop - CALENDAR_BORDER) 1704 pts.y > rclArea.yTop - (CALENDAR_BORDER + height) && pts.y < rclArea.yTop - CALENDAR_BORDER)
1693 { 1705 {
1706 int daysthismonth;
1707
1694 if(month == 11) 1708 if(month == 11)
1695 { 1709 {
1696 month = 0; 1710 month = 0;
1697 year++; 1711 year++;
1698 dw_window_set_data(hWnd, "_dw_year", DW_INT_TO_POINTER(year)); 1712 dw_window_set_data(hWnd, "_dw_year", DW_INT_TO_POINTER(year));
1700 else if(month < 11) 1714 else if(month < 11)
1701 { 1715 {
1702 month++; 1716 month++;
1703 } 1717 }
1704 dw_window_set_data(hWnd, "_dw_month", DW_INT_TO_POINTER(month)); 1718 dw_window_set_data(hWnd, "_dw_month", DW_INT_TO_POINTER(month));
1719 /* Make sure we aren't higher than the number of days
1720 * in our new month... keeping track of leap years.
1721 */
1722 daysthismonth = days[month] + (isleapyear && month == 1);
1723 if(day >= daysthismonth)
1724 {
1725 day = daysthismonth - 1;
1726 dw_window_set_data(hWnd, "_dw_day", DW_INT_TO_POINTER(day));
1727 }
1705 WinInvalidateRect(hWnd, &rclArea, FALSE); 1728 WinInvalidateRect(hWnd, &rclArea, FALSE);
1706 WinPostMsg(hWnd, WM_PAINT, 0, 0); 1729 WinPostMsg(hWnd, WM_PAINT, 0, 0);
1707 return (MRESULT)TRUE; 1730 return (MRESULT)TRUE;
1708 } 1731 }
1709 1732