comparison os2/dw.c @ 1346:1436bcd68ee4

Ok some final work on the Calendar control for OS/2... Should work now. Didn't get the code to work to make the Month/Year bold but... skipping that for now.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 15 Nov 2011 05:14:09 +0000
parents e29e24af9b6d
children 2bc23978cfcd
comparison
equal deleted inserted replaced
1345:e29e24af9b6d 1346:1436bcd68ee4
1605 GpiLine(hpsPaint, &ptl2); 1605 GpiLine(hpsPaint, &ptl2);
1606 } 1606 }
1607 1607
1608 1608
1609 #define CALENDAR_BORDER 3 1609 #define CALENDAR_BORDER 3
1610 #define CALENDAR_ARROW 8
1610 1611
1611 /* Returns a rectangle for a single day on the calendar */ 1612 /* Returns a rectangle for a single day on the calendar */
1612 RECTL _CalendarDayRect(int position, RECTL rclPaint) 1613 RECTL _CalendarDayRect(int position, RECTL rclPaint)
1613 { 1614 {
1614 int height = rclPaint.yTop - rclPaint.yBottom - (CALENDAR_BORDER*2); 1615 int height = rclPaint.yTop - rclPaint.yBottom - (CALENDAR_BORDER*2);
1617 * 1 for the Month/Year and 1 for the day names. 1618 * 1 for the Month/Year and 1 for the day names.
1618 */ 1619 */
1619 int row = position / 7; 1620 int row = position / 7;
1620 int col = position % 7; 1621 int col = position % 7;
1621 int cellwidth = width / 7; 1622 int cellwidth = width / 7;
1622 int cellheight = height / 7; 1623 int cellheight = height / 8;
1623 1624
1624 /* Create a new box */ 1625 /* Create a new box */
1625 rclPaint.xLeft = (cellwidth * col) + CALENDAR_BORDER; 1626 rclPaint.xLeft = (cellwidth * col) + CALENDAR_BORDER;
1626 rclPaint.xRight = rclPaint.xLeft + cellwidth; 1627 rclPaint.xRight = rclPaint.xLeft + cellwidth;
1627 /* We only handle 6 of the 7 rows */ 1628 /* We only handle 6 of the 7 rows */
1628 rclPaint.yBottom = (cellheight * (5-row)) + CALENDAR_BORDER; 1629 rclPaint.yBottom = (cellheight * (6-row)) + CALENDAR_BORDER;
1629 rclPaint.yTop = rclPaint.yBottom + cellheight; 1630 rclPaint.yTop = rclPaint.yBottom + cellheight;
1630 return rclPaint; 1631 return rclPaint;
1631 } 1632 }
1632 1633
1633 /* This procedure handles drawing of a status border */ 1634 /* This procedure handles drawing of a status border */
1634 MRESULT EXPENTRY _calendarproc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2) 1635 MRESULT EXPENTRY _calendarproc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
1635 { 1636 {
1637 /* How many days are in each month usually (not including leap years) */
1638 static int days[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
1639 static char *months[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
1640 static char *daysofweek[] = { "Sunday", "Monday", "Tuesday","Wednesday", "Thursday", "Friday", "Saturday" };
1636 WindowData *blah = (WindowData *)WinQueryWindowPtr(hWnd, QWP_USER); 1641 WindowData *blah = (WindowData *)WinQueryWindowPtr(hWnd, QWP_USER);
1637 PFNWP oldproc = 0; 1642 PFNWP oldproc = 0;
1638 1643
1639 if(blah) 1644 if(blah)
1640 { 1645 {
1641 oldproc = blah->oldproc; 1646 oldproc = blah->oldproc;
1642 1647
1643 switch(msg) 1648 switch(msg)
1644 { 1649 {
1650 case WM_BUTTON1DOWN:
1651 case WM_BUTTON2DOWN:
1652 case WM_BUTTON3DOWN:
1653 {
1654 POINTS pts = (*((POINTS*)&mp1));
1655 int day = DW_POINTER_TO_INT(dw_window_get_data(hWnd, "_dw_day"));
1656 int month = DW_POINTER_TO_INT(dw_window_get_data(hWnd, "_dw_month"));
1657 int year = DW_POINTER_TO_INT(dw_window_get_data(hWnd, "_dw_year"));
1658 int dayofweek = 1, x, height;
1659 RECTL rclArea;
1660
1661 /* Figure out what day of the week the first day of the month falls on */
1662 for(x=0;x<month;x++)
1663 dayofweek += days[x];
1664 dayofweek += (year/4) + year - 1;
1665 dayofweek = dayofweek % 7;
1666
1667 WinQueryWindowRect(hWnd, &rclArea);
1668 height = ((rclArea.yTop - (CALENDAR_BORDER*2))/7);
1669
1670 /* Check for the left arrow */
1671 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 {
1674 if(month == 0)
1675 {
1676 month = 11;
1677 year--;
1678 dw_window_set_data(hWnd, "_dw_year", DW_INT_TO_POINTER(year));
1679 }
1680 else if(month > 0)
1681 {
1682 month--;
1683 }
1684 dw_window_set_data(hWnd, "_dw_month", DW_INT_TO_POINTER(month));
1685 WinInvalidateRect(hWnd, &rclArea, FALSE);
1686 WinPostMsg(hWnd, WM_PAINT, 0, 0);
1687 return (MRESULT)TRUE;
1688 }
1689
1690 /* Check for the right arrow */
1691 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)
1693 {
1694 if(month == 11)
1695 {
1696 month = 0;
1697 year++;
1698 dw_window_set_data(hWnd, "_dw_year", DW_INT_TO_POINTER(year));
1699 }
1700 else if(month < 11)
1701 {
1702 month++;
1703 }
1704 dw_window_set_data(hWnd, "_dw_month", DW_INT_TO_POINTER(month));
1705 WinInvalidateRect(hWnd, &rclArea, FALSE);
1706 WinPostMsg(hWnd, WM_PAINT, 0, 0);
1707 return (MRESULT)TRUE;
1708 }
1709
1710 /* Check all the valid days of the month */
1711 for(x=dayofweek+7;x<(days[month]+dayofweek+7);x++)
1712 {
1713 RECTL rclThis = _CalendarDayRect(x, rclArea);
1714 if(pts.x < rclThis.xRight && pts.x > rclThis.xLeft && pts.y < rclThis.yTop && pts.y > rclThis.yBottom)
1715 {
1716 dw_window_set_data(hWnd, "_dw_day", DW_INT_TO_POINTER((x-(dayofweek+7))));
1717 WinInvalidateRect(hWnd, &rclArea, FALSE);
1718 WinPostMsg(hWnd, WM_PAINT, 0, 0);
1719 return (MRESULT)TRUE;
1720 }
1721 }
1722 }
1723 break;
1645 case WM_PAINT: 1724 case WM_PAINT:
1646 { 1725 {
1647 HPS hpsPaint; 1726 HPS hpsPaint;
1648 RECTL rclPaint, rclDraw; 1727 RECTL rclPaint, rclDraw;
1649 char buf[100], font[50] = { 0 }; 1728 char buf[100], font[50] = { 0 };
1650 /* How many days are in each month usually (not including leap years) */
1651 static int days[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
1652 static char *months[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
1653 static char *daysofweek[] = { "Sunday", "Monday", "Tuesday","Wednesday", "Thursday", "Friday", "Saturday" };
1654 int day = DW_POINTER_TO_INT(dw_window_get_data(hWnd, "_dw_day")); 1729 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")); 1730 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")); 1731 int year = DW_POINTER_TO_INT(dw_window_get_data(hWnd, "_dw_year"));
1657 int dayofweek = 1, x, lastmonth = 11, height; 1732 int dayofweek = 1, x, lastmonth = 11, height;
1658 POINTL pptl[3]; 1733 POINTL pptl[3];
1659 1734
1660 /* Figure out the previous month for later use */ 1735 /* Figure out the previous month for later use */
1661 if(month > 0) 1736 if(month > 0)
1662 lastmonth = month - 1; 1737 lastmonth = month - 1;
1663 1738
1664 #if 0
1665 /* Check the current font and create a bold one to draw the month and selected */
1666 if(WinQueryPresParam(hWnd, PP_FONTNAMESIZE, 0, NULL, 50, font, QPF_NOINHERIT))
1667 {
1668 strcpy(buf, font);
1669 /* Check to make sure it isn't already bold */
1670 if(!strstr(buf, " Bold"))
1671 strcat(buf, " Bold");
1672 WinSetPresParam(hWnd, PP_FONTNAMESIZE, strlen(buf)+1, buf);
1673 }
1674 #endif
1675
1676 /* Make the title */ 1739 /* Make the title */
1677 sprintf(buf, "%s, %d", months[month], year + 1); 1740 sprintf(buf, "%s, %d", months[month], year + 1);
1678 1741
1679 /* Figure out what day of the week the first day of the month falls on */ 1742 /* Figure out what day of the week the first day of the month falls on */
1680 for(x=0;x<month;x++) 1743 for(x=0;x<month;x++)
1695 WinDrawText(hpsPaint, -1, (PCH)buf, &rclDraw, DT_TEXTATTRS, DT_TEXTATTRS, DT_VCENTER | DT_CENTER | DT_TEXTATTRS); 1758 WinDrawText(hpsPaint, -1, (PCH)buf, &rclDraw, DT_TEXTATTRS, DT_TEXTATTRS, DT_VCENTER | DT_CENTER | DT_TEXTATTRS);
1696 1759
1697 /* Draw the left arrow */ 1760 /* Draw the left arrow */
1698 GpiSetColor(hpsPaint, CLR_DARKGRAY); 1761 GpiSetColor(hpsPaint, CLR_DARKGRAY);
1699 GpiBeginArea(hpsPaint, 0); 1762 GpiBeginArea(hpsPaint, 0);
1700 pptl[2].x = rclDraw.xLeft + CALENDAR_BORDER + 5; 1763 pptl[2].x = rclDraw.xLeft + CALENDAR_BORDER + CALENDAR_ARROW;
1701 pptl[2].y = rclDraw.yTop - CALENDAR_BORDER; 1764 pptl[2].y = rclDraw.yTop - CALENDAR_BORDER;
1702 GpiMove(hpsPaint, &pptl[2]); 1765 GpiMove(hpsPaint, &pptl[2]);
1703 pptl[0].x = rclDraw.xLeft + CALENDAR_BORDER; 1766 pptl[0].x = rclDraw.xLeft + CALENDAR_BORDER;
1704 pptl[0].y = rclDraw.yTop - (CALENDAR_BORDER+ (height/2)); 1767 pptl[0].y = rclDraw.yTop - (CALENDAR_BORDER+ (height/2));
1705 pptl[1].x = rclDraw.xLeft + CALENDAR_BORDER + 5; 1768 pptl[1].x = rclDraw.xLeft + CALENDAR_BORDER + CALENDAR_ARROW;
1706 pptl[1].y = rclDraw.yTop - CALENDAR_BORDER - height; 1769 pptl[1].y = rclDraw.yTop - CALENDAR_BORDER - height;
1707 GpiPolyLine(hpsPaint, 3, pptl); 1770 GpiPolyLine(hpsPaint, 3, pptl);
1708 GpiEndArea(hpsPaint); 1771 GpiEndArea(hpsPaint);
1709 1772
1710 /* Draw the left arrow */ 1773 /* Draw the left arrow */
1711 GpiBeginArea(hpsPaint, 0); 1774 GpiBeginArea(hpsPaint, 0);
1712 pptl[2].x = rclDraw.xRight - CALENDAR_BORDER - 5; 1775 pptl[2].x = rclDraw.xRight - CALENDAR_BORDER - CALENDAR_ARROW;
1713 pptl[2].y = rclDraw.yTop - CALENDAR_BORDER; 1776 pptl[2].y = rclDraw.yTop - CALENDAR_BORDER;
1714 GpiMove(hpsPaint, &pptl[2]); 1777 GpiMove(hpsPaint, &pptl[2]);
1715 pptl[0].x = rclDraw.xRight - CALENDAR_BORDER; 1778 pptl[0].x = rclDraw.xRight - CALENDAR_BORDER;
1716 pptl[0].y = rclDraw.yTop - (CALENDAR_BORDER + (height/2)); 1779 pptl[0].y = rclDraw.yTop - (CALENDAR_BORDER + (height/2));
1717 pptl[1].x = rclDraw.xRight - CALENDAR_BORDER - 5; 1780 pptl[1].x = rclDraw.xRight - CALENDAR_BORDER - CALENDAR_ARROW;
1718 pptl[1].y = rclDraw.yTop - CALENDAR_BORDER - height; 1781 pptl[1].y = rclDraw.yTop - CALENDAR_BORDER - height;
1719 GpiPolyLine(hpsPaint, 3, pptl); 1782 GpiPolyLine(hpsPaint, 3, pptl);
1720 GpiEndArea(hpsPaint); 1783 GpiEndArea(hpsPaint);
1721
1722 #if 0
1723 /* Restore the original font */
1724 WinSetPresParam(hWnd, PP_FONTNAMESIZE, strlen(font)+1, font);
1725 #endif
1726 1784
1727 /* Draw a border around control */ 1785 /* Draw a border around control */
1728 _Top(hpsPaint, rclPaint); 1786 _Top(hpsPaint, rclPaint);
1729 _Left(hpsPaint, rclPaint); 1787 _Left(hpsPaint, rclPaint);
1730 /* With shadow */ 1788 /* With shadow */
1731 GpiSetColor(hpsPaint, CLR_WHITE); 1789 GpiSetColor(hpsPaint, CLR_WHITE);
1732 _Right(hpsPaint, rclPaint); 1790 _Right(hpsPaint, rclPaint);
1733 _Bottom(hpsPaint, rclPaint); 1791 _Bottom(hpsPaint, rclPaint);
1734 1792
1735 /* Draw the days of the week */ 1793 /* Draw the days of the week */
1736 GpiSetColor(hpsPaint, CLR_DARKBLUE); 1794 GpiSetColor(hpsPaint, CLR_BLACK);
1737 for(x=0;x<7;x++) 1795 for(x=0;x<7;x++)
1738 { 1796 {
1739 char *title = daysofweek[x]; 1797 char *title = daysofweek[x];
1740 1798
1741 rclDraw = _CalendarDayRect(x, rclPaint); 1799 rclDraw = _CalendarDayRect(x, rclPaint);
1747 } 1805 }
1748 WinDrawText(hpsPaint, -1, (PCH)title, &rclDraw, DT_TEXTATTRS, DT_TEXTATTRS, DT_VCENTER | DT_CENTER | DT_TEXTATTRS); 1806 WinDrawText(hpsPaint, -1, (PCH)title, &rclDraw, DT_TEXTATTRS, DT_TEXTATTRS, DT_VCENTER | DT_CENTER | DT_TEXTATTRS);
1749 } 1807 }
1750 1808
1751 /* Go through all the days */ 1809 /* Go through all the days */
1752 for(x=0;x<35;x++) 1810 for(x=0;x<42;x++)
1753 { 1811 {
1754 rclDraw = _CalendarDayRect(x+7, rclPaint); 1812 rclDraw = _CalendarDayRect(x+7, rclPaint);
1755 if(x < dayofweek) 1813 if(x < dayofweek)
1814 {
1815 GpiSetColor(hpsPaint, CLR_DARKGRAY);
1756 sprintf(buf, "%d", days[lastmonth] - (dayofweek - x - 1)); 1816 sprintf(buf, "%d", days[lastmonth] - (dayofweek - x - 1));
1817 }
1757 else if(x - dayofweek + 1 > days[month]) 1818 else if(x - dayofweek + 1 > days[month])
1819 {
1820 GpiSetColor(hpsPaint, CLR_DARKGRAY);
1758 sprintf(buf, "%d", x - dayofweek - days[month] + 1); 1821 sprintf(buf, "%d", x - dayofweek - days[month] + 1);
1822 }
1759 else 1823 else
1824 {
1825 GpiSetColor(hpsPaint, CLR_DARKBLUE);
1760 sprintf(buf, "%d", x - dayofweek + 1); 1826 sprintf(buf, "%d", x - dayofweek + 1);
1827 }
1761 WinDrawText(hpsPaint, -1, (PCH)buf, &rclDraw, DT_TEXTATTRS, DT_TEXTATTRS, DT_VCENTER | DT_CENTER | DT_TEXTATTRS); 1828 WinDrawText(hpsPaint, -1, (PCH)buf, &rclDraw, DT_TEXTATTRS, DT_TEXTATTRS, DT_VCENTER | DT_CENTER | DT_TEXTATTRS);
1762 } 1829 }
1763 1830
1764 /* Draw a border around selected day */ 1831 /* Draw a border around selected day */
1765 rclPaint = _CalendarDayRect(day + dayofweek + 7, rclPaint); 1832 rclPaint = _CalendarDayRect(day + dayofweek + 7, rclPaint);