comparison os2/dw.c @ 1345:e29e24af9b6d

Ok get basic drawing working... on the calendar control on OS/2. Font changing code is causing crashes and need to handle clicks next.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 15 Nov 2011 03:38:55 +0000
parents af989b9f1767
children 1436bcd68ee4
comparison
equal deleted inserted replaced
1344:af989b9f1767 1345:e29e24af9b6d
1616 /* There are 7 rows... 5 for the day numbers... 1616 /* There are 7 rows... 5 for the day numbers...
1617 * 1 for the Month/Year and 1 for the day names. 1617 * 1 for the Month/Year and 1 for the day names.
1618 */ 1618 */
1619 int row = position / 7; 1619 int row = position / 7;
1620 int col = position % 7; 1620 int col = position % 7;
1621 int cellwidth = height / 7; 1621 int cellwidth = width / 7;
1622 int cellheight = width / 7; 1622 int cellheight = height / 7;
1623 1623
1624 /* Create a new box */ 1624 /* Create a new box */
1625 rclPaint.xLeft = cellwidth * col; 1625 rclPaint.xLeft = (cellwidth * col) + CALENDAR_BORDER;
1626 rclPaint.xRight = rclPaint.xLeft + cellwidth; 1626 rclPaint.xRight = rclPaint.xLeft + cellwidth;
1627 /* We only handle 6 of the 7 rows */ 1627 /* We only handle 6 of the 7 rows */
1628 rclPaint.yBottom = cellheight * (6-row); 1628 rclPaint.yBottom = (cellheight * (5-row)) + CALENDAR_BORDER;
1629 rclPaint.yTop = rclPaint.yBottom + cellheight; 1629 rclPaint.yTop = rclPaint.yBottom + cellheight;
1630 dw_debug("Cell height %d width %d position %d row %d, col %d (%d,%d)-(%d,%d)\n", cellheight, cellwidth, position, row, col, rclPaint.xLeft, rclPaint.yBottom, rclPaint.xRight, rclPaint.yTop);
1631 return rclPaint; 1630 return rclPaint;
1632 } 1631 }
1633 1632
1634 /* This procedure handles drawing of a status border */ 1633 /* This procedure handles drawing of a status border */
1635 MRESULT EXPENTRY _calendarproc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2) 1634 MRESULT EXPENTRY _calendarproc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
1653 static char *months[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; 1652 static char *months[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
1654 static char *daysofweek[] = { "Sunday", "Monday", "Tuesday","Wednesday", "Thursday", "Friday", "Saturday" }; 1653 static char *daysofweek[] = { "Sunday", "Monday", "Tuesday","Wednesday", "Thursday", "Friday", "Saturday" };
1655 int day = DW_POINTER_TO_INT(dw_window_get_data(hWnd, "_dw_day")); 1654 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")); 1655 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")); 1656 int year = DW_POINTER_TO_INT(dw_window_get_data(hWnd, "_dw_year"));
1658 int dayofweek = 1, x, lastmonth = 11; 1657 int dayofweek = 1, x, lastmonth = 11, height;
1658 POINTL pptl[3];
1659 1659
1660 /* Figure out the previous month for later use */ 1660 /* Figure out the previous month for later use */
1661 if(month > 0) 1661 if(month > 0)
1662 lastmonth = month - 1; 1662 lastmonth = month - 1;
1663
1664 dw_debug("day %d month %d year %d lastmonth %d\n", day, month, year, lastmonth);
1665 1663
1666 #if 0 1664 #if 0
1667 /* Check the current font and create a bold one to draw the month and selected */ 1665 /* Check the current font and create a bold one to draw the month and selected */
1668 if(WinQueryPresParam(hWnd, PP_FONTNAMESIZE, 0, NULL, 50, font, QPF_NOINHERIT)) 1666 if(WinQueryPresParam(hWnd, PP_FONTNAMESIZE, 0, NULL, 50, font, QPF_NOINHERIT))
1669 { 1667 {
1671 /* Check to make sure it isn't already bold */ 1669 /* Check to make sure it isn't already bold */
1672 if(!strstr(buf, " Bold")) 1670 if(!strstr(buf, " Bold"))
1673 strcat(buf, " Bold"); 1671 strcat(buf, " Bold");
1674 WinSetPresParam(hWnd, PP_FONTNAMESIZE, strlen(buf)+1, buf); 1672 WinSetPresParam(hWnd, PP_FONTNAMESIZE, strlen(buf)+1, buf);
1675 } 1673 }
1676
1677 dw_debug("Original font %s bold font %s\n", font, buf);
1678 #endif 1674 #endif
1679 1675
1680 /* Make the title */ 1676 /* Make the title */
1681 sprintf(buf, "%s, %d", months[month], year + 1); 1677 sprintf(buf, "%s, %d", months[month], year + 1);
1682 1678
1684 for(x=0;x<month;x++) 1680 for(x=0;x<month;x++)
1685 dayofweek += days[x]; 1681 dayofweek += days[x];
1686 dayofweek += (year/4) + year - 1; 1682 dayofweek += (year/4) + year - 1;
1687 dayofweek = dayofweek % 7; 1683 dayofweek = dayofweek % 7;
1688 1684
1689 dw_debug("Title %s dayofweek %d\n", buf, dayofweek);
1690
1691 /* Actually draw the control */ 1685 /* Actually draw the control */
1692 hpsPaint = WinBeginPaint(hWnd, 0, 0); 1686 hpsPaint = WinBeginPaint(hWnd, 0, 0);
1693 WinQueryWindowRect(hWnd, &rclPaint); 1687 WinQueryWindowRect(hWnd, &rclPaint);
1694 WinFillRect(hpsPaint, &rclPaint, CLR_PALEGRAY); 1688 WinFillRect(hpsPaint, &rclPaint, CLR_PALEGRAY);
1689 height = ((rclPaint.yTop - (CALENDAR_BORDER*2))/7);
1695 1690
1696 /* Draw the Month and Year at the top */ 1691 /* Draw the Month and Year at the top */
1697 GpiSetColor(hpsPaint, CLR_BLACK); 1692 GpiSetColor(hpsPaint, CLR_BLACK);
1698 rclDraw = rclPaint; 1693 rclDraw = rclPaint;
1699 rclDraw.yBottom = ((rclDraw.yTop - (CALENDAR_BORDER*2))/7) * 6; 1694 rclDraw.yBottom = height * 6;
1700 WinDrawText(hpsPaint, -1, (PCH)buf, &rclDraw, DT_TEXTATTRS, DT_TEXTATTRS, DT_VCENTER | DT_CENTER | DT_TEXTATTRS); 1695 WinDrawText(hpsPaint, -1, (PCH)buf, &rclDraw, DT_TEXTATTRS, DT_TEXTATTRS, DT_VCENTER | DT_CENTER | DT_TEXTATTRS);
1701 1696
1697 /* Draw the left arrow */
1698 GpiSetColor(hpsPaint, CLR_DARKGRAY);
1699 GpiBeginArea(hpsPaint, 0);
1700 pptl[2].x = rclDraw.xLeft + CALENDAR_BORDER + 5;
1701 pptl[2].y = rclDraw.yTop - CALENDAR_BORDER;
1702 GpiMove(hpsPaint, &pptl[2]);
1703 pptl[0].x = rclDraw.xLeft + CALENDAR_BORDER;
1704 pptl[0].y = rclDraw.yTop - (CALENDAR_BORDER+ (height/2));
1705 pptl[1].x = rclDraw.xLeft + CALENDAR_BORDER + 5;
1706 pptl[1].y = rclDraw.yTop - CALENDAR_BORDER - height;
1707 GpiPolyLine(hpsPaint, 3, pptl);
1708 GpiEndArea(hpsPaint);
1709
1710 /* Draw the left arrow */
1711 GpiBeginArea(hpsPaint, 0);
1712 pptl[2].x = rclDraw.xRight - CALENDAR_BORDER - 5;
1713 pptl[2].y = rclDraw.yTop - CALENDAR_BORDER;
1714 GpiMove(hpsPaint, &pptl[2]);
1715 pptl[0].x = rclDraw.xRight - CALENDAR_BORDER;
1716 pptl[0].y = rclDraw.yTop - (CALENDAR_BORDER + (height/2));
1717 pptl[1].x = rclDraw.xRight - CALENDAR_BORDER - 5;
1718 pptl[1].y = rclDraw.yTop - CALENDAR_BORDER - height;
1719 GpiPolyLine(hpsPaint, 3, pptl);
1720 GpiEndArea(hpsPaint);
1721
1702 #if 0 1722 #if 0
1703 dw_debug("Restoring font\n");
1704 /* Restore the original font */ 1723 /* Restore the original font */
1705 WinSetPresParam(hWnd, PP_FONTNAMESIZE, strlen(font)+1, font); 1724 WinSetPresParam(hWnd, PP_FONTNAMESIZE, strlen(font)+1, font);
1706 #endif 1725 #endif
1707 1726
1708 /* Draw a border around control */ 1727 /* Draw a border around control */
1709 GpiSetColor(hpsPaint, CLR_DARKGRAY);
1710 _Top(hpsPaint, rclPaint); 1728 _Top(hpsPaint, rclPaint);
1711 _Left(hpsPaint, rclPaint); 1729 _Left(hpsPaint, rclPaint);
1712 /* With shadow */ 1730 /* With shadow */
1713 GpiSetColor(hpsPaint, CLR_WHITE); 1731 GpiSetColor(hpsPaint, CLR_WHITE);
1714 _Right(hpsPaint, rclPaint); 1732 _Right(hpsPaint, rclPaint);
1716 1734
1717 /* Draw the days of the week */ 1735 /* Draw the days of the week */
1718 GpiSetColor(hpsPaint, CLR_DARKBLUE); 1736 GpiSetColor(hpsPaint, CLR_DARKBLUE);
1719 for(x=0;x<7;x++) 1737 for(x=0;x<7;x++)
1720 { 1738 {
1739 char *title = daysofweek[x];
1740
1721 rclDraw = _CalendarDayRect(x, rclPaint); 1741 rclDraw = _CalendarDayRect(x, rclPaint);
1722 dw_debug("Pos %d day of week %s\n", x, daysofweek[x]); 1742
1723 WinDrawText(hpsPaint, -1, (PCH)daysofweek[x], &rclDraw, DT_TEXTATTRS, DT_TEXTATTRS, DT_VCENTER | DT_CENTER | DT_TEXTATTRS); 1743 if(rclDraw.xRight - rclDraw.xLeft < 60)
1744 {
1745 buf[0] = daysofweek[x][0]; buf[1] = daysofweek[x][1]; buf[2] = 0;
1746 title = buf;
1747 }
1748 WinDrawText(hpsPaint, -1, (PCH)title, &rclDraw, DT_TEXTATTRS, DT_TEXTATTRS, DT_VCENTER | DT_CENTER | DT_TEXTATTRS);
1724 } 1749 }
1725 1750
1726 /* Go through all the days */ 1751 /* Go through all the days */
1727 for(x=0;x<35;x++) 1752 for(x=0;x<35;x++)
1728 { 1753 {
1731 sprintf(buf, "%d", days[lastmonth] - (dayofweek - x - 1)); 1756 sprintf(buf, "%d", days[lastmonth] - (dayofweek - x - 1));
1732 else if(x - dayofweek + 1 > days[month]) 1757 else if(x - dayofweek + 1 > days[month])
1733 sprintf(buf, "%d", x - dayofweek - days[month] + 1); 1758 sprintf(buf, "%d", x - dayofweek - days[month] + 1);
1734 else 1759 else
1735 sprintf(buf, "%d", x - dayofweek + 1); 1760 sprintf(buf, "%d", x - dayofweek + 1);
1736 dw_debug("Pos %d day %s\n", x, buf);
1737 WinDrawText(hpsPaint, -1, (PCH)buf, &rclDraw, DT_TEXTATTRS, DT_TEXTATTRS, DT_VCENTER | DT_CENTER | DT_TEXTATTRS); 1761 WinDrawText(hpsPaint, -1, (PCH)buf, &rclDraw, DT_TEXTATTRS, DT_TEXTATTRS, DT_VCENTER | DT_CENTER | DT_TEXTATTRS);
1738 } 1762 }
1739 1763
1740 /* Draw a border around selected day */ 1764 /* Draw a border around selected day */
1741 rclPaint = _CalendarDayRect(day + dayofweek + 8, rclPaint); 1765 rclPaint = _CalendarDayRect(day + dayofweek + 7, rclPaint);
1742 GpiSetColor(hpsPaint, CLR_DARKGRAY); 1766 GpiSetColor(hpsPaint, CLR_DARKGRAY);
1743 _Top(hpsPaint, rclPaint); 1767 _Top(hpsPaint, rclPaint);
1744 _Left(hpsPaint, rclPaint); 1768 _Left(hpsPaint, rclPaint);
1745 /* With shadow */ 1769 /* With shadow */
1746 GpiSetColor(hpsPaint, CLR_WHITE); 1770 GpiSetColor(hpsPaint, CLR_WHITE);
1747 _Right(hpsPaint, rclPaint); 1771 _Right(hpsPaint, rclPaint);
1748 _Bottom(hpsPaint, rclPaint); 1772 _Bottom(hpsPaint, rclPaint);
1749 dw_debug("Done\n");
1750 1773
1751 WinEndPaint(hpsPaint); 1774 WinEndPaint(hpsPaint);
1752 1775
1753 return (MRESULT)TRUE; 1776 return (MRESULT)TRUE;
1754 } 1777 }