home *** CD-ROM | disk | FTP | other *** search
- /*
- * $Header: ypaint.c,v 2.5 91/03/27 16:46:51 billr Exp $
- */
- /*
- * ypaint.c
- *
- * Author: Bill Randle, Tektronix, Inc. <billr@saab.CNA.TEK.COM>
- *
- * Copyright (C) 1988, 1989, 1991 Tektronix, Inc. All Rights Reserved
- *
- * Permission is hereby granted to use and modify this code in source
- * or binary form as long as it is not sold for profit and this copyright
- * notice remains intact.
- */
- /***************************************************
- * *
- * Artistic routines that draw in the main *
- * subwindow for the year display. *
- * *
- ***************************************************/
-
- #include <suntool/sunview.h>
- #include <suntool/canvas.h>
- #include <ctype.h>
- #include <stdio.h>
- #include "ct.h"
- #include "paint.h"
- #ifndef NO_HOLIDAYS
- extern struct appt_entry a_appts[], c_appts[];
- extern struct appt_entry i_appts[], j_appts[];
- extern struct appt_entry s_appts[];
- #endif
-
- /*
- * draw calendar for a whole year.
- */
- draw_year()
- {
- int monthnr, daynr, boxnr, i, j, k, thismonth;
- int row, col, x, y;
- int busy_today[367], startbox, nrdays, yrday, extra_days;
- char title[5], c[3], buf[100];
- Rect *rect;
- struct tm Save;
- struct appt_entry appt;
- int read_stat;
- FILE *apts;
- int runl;
-
- lock_cursors();
- /* destory future appts popup, if it exists */
- if (fframe) {
- window_destroy(fframe);
- fframe = 0;
- }
- fix_current_day();
-
- working(TRUE);
- pw_batch_on(main_pixwin);
- rect = (Rect *) window_get(canvas, WIN_RECT);
- /* Erase the window */
- pw_writebackground(main_pixwin,0,0,rect->r_width,rect->r_height,PIX_CLR);
- startx = (rect->r_width - 3*8*ybox_width)/2 + font->pf_defaultsize.x+1;
- starty = rect->r_height - 4*8*ybox_height + ybox_height/2;
- sun_moon_buttons(FALSE);
- print_button(TRUE);
-
- /* Which days have appointments? */
- for (i=1; i<=dysize(current.tm_year + 1900); i++)
- busy_today[i] = 0;
- Save = current;
- current.tm_mon = JAN;
- current.tm_mday = 1;
- fix_current_day();
- First = current;
- current.tm_mon = DEC;
- current.tm_mday = monthlength(DEC);
- fix_current_day();
- Last = current;
- if ((apts = fopen(apts_pathname, "r")) == NULL)
- err_rpt("can't open appointments file", FATAL);
-
- working(FALSE);
- while ((read_stat = get_aentry(apts, &appt, FALSE, 1, 0)) != EOF) {
- if (read_stat)
- continue; /* read error */
- if (appt.flags & A_COMMENT)
- continue;
- if ((appt.flags & MARKED_NOTE) == MARKED_NOTE)
- continue;
- current.tm_year = appt.year;
- current.tm_mon = appt.month;
- current.tm_mday = appt.day;
- if (appt.flags & ALL_YEARS)
- current.tm_year = First.tm_year;
- if (current.tm_year == First.tm_year) {
- if (appt.flags & ALL_MONTHS) {
- for (current.tm_mon = JAN;
- current.tm_mon <= DEC;
- current.tm_mon++) {
- if ((appt.flags & ALL_DAYS)
- || (appt.flags & EVERY_MON_FRI)) {
- for (current.tm_mday = 1; current.tm_mday <=
- monthlength(current.tm_mon); current.tm_mday++) {
- fix_current_day();
- if (current.tm_wday >= MON && current.tm_wday <=FRI)
- busy_today[current.tm_yday]++;
- else if (appt.flags & ALL_DAYS)
- /* pick up Sat and Sun */
- busy_today[current.tm_yday]++;
- }
- } else if (appt.flags & EVERY_SOMEDAY) {
- i = Pickday(appt.flags);
- for (current.tm_mday = 1; current.tm_mday <=
- monthlength(current.tm_mon); current.tm_mday++) {
- fix_current_day();
- if (current.tm_wday == i)
- if (chk_week(appt.repeat, current.tm_mday))
- busy_today[current.tm_yday]++;
- }
- } else {
- fix_current_day();
- busy_today[current.tm_yday]++;
- }
- }
- } else if ((appt.flags & ALL_DAYS)
- || (appt.flags & EVERY_MON_FRI)) {
- for (current.tm_mday = 1; current.tm_mday <=
- monthlength(current.tm_mon); current.tm_mday++) {
- fix_current_day();
- if (current.tm_wday >= MON && current.tm_wday <=FRI)
- busy_today[current.tm_yday]++;
- else if (appt.flags & ALL_DAYS)
- /* pick up Sat and Sun */
- busy_today[current.tm_yday]++;
- }
- } else if (appt.flags & REPEAT) {
- if (appt.flags & EVERY_SOMEDAY) {
- current.tm_mday = 1;
- find_date(&appt);
- if (appt.flags & RUN)
- runl = appt.runlength;
- else
- runl = 1;
- while (ymd_compare(current, Last) <= 0 && runl) {
- if (chk_week(appt.repeat, current.tm_mday)) {
- if (runl)
- busy_today[current.tm_yday]++;
- if (appt.flags & RUN)
- --runl;
- }
- current.tm_mday += 7;
- fix_current_day();
- if (current.tm_mon != appt.month && !(appt.flags & RUN))
- break;
- }
- } else {
- fix_current_day();
- if (appt.flags & RUN)
- runl = appt.runlength;
- else
- runl = 1;
- while (ymd_compare(current, Last) <= 0 && runl) {
- if (runl) {
- busy_today[current.tm_yday]++;
- current.tm_mday += appt.repeat;
- fix_current_day();
- if (appt.flags & RUN)
- --runl;
- }
- }
- }
- } else {
- fix_current_day();
- if (appt.flags & DELETED)
- busy_today[current.tm_yday]--;
- else
- busy_today[current.tm_yday]++;
- }
- } else if ((appt.flags & REPEAT) || (appt.flags & EVERY_SOMEDAY)) {
- /* find 1st appt in this year */
- if (appt.flags & RUN)
- runl = appt.runlength;
- else
- runl = 1;
- if (appt.flags & EVERY_SOMEDAY)
- find_date(&appt);
- while (ymd_compare(current, First) < 0 && runl) {
- if (appt.flags & RUN)
- --runl;
- if (runl) {
- if (appt.flags & EVERY_SOMEDAY) {
- current.tm_mday += 7;
- find_date(&appt);
- } else {
- current.tm_mday += appt.repeat;
- fix_current_day();
- }
- }
- }
- while (ymd_compare(current, Last) <= 0 && runl) {
- if (runl) {
- busy_today[current.tm_yday]++;
- if (appt.flags & RUN)
- --runl;
- if (appt.flags & EVERY_SOMEDAY) {
- current.tm_mday += 7;
- find_date(&appt);
- } else {
- current.tm_mday += appt.repeat;
- fix_current_day();
- }
- }
- }
- }
- }
- fclose(apts);
- current = First;
- fix_current_day();
- #ifndef NO_HOLIDAYS
- /*
- * now that we've gone thru the appointments file,
- * check to see if the user has selected any holiday
- * options and add them in.
- */
- for (i=0; i<dysize(current.tm_year + 1900); i++) {
- working(TRUE);
- if (holiday_a == 1) {
- j = a_dates(holiday_a);
- for (k=0; k<j; k++)
- if (ymd2_compare(¤t, &a_appts[k]) == 0)
- busy_today[i]++;
- }
- if (holiday_c == 1) {
- j = c_dates(holiday_c);
- for (k=0; k<j; k++)
- if (ymd2_compare(¤t, &c_appts[k]) == 0)
- busy_today[i]++;
- }
- working(FALSE);
- if (holiday_i == 1) {
- j = i_dates(holiday_i);
- for (k=0; k<j; k++)
- if (ymd2_compare(¤t, &i_appts[k]) == 0)
- busy_today[i]++;
- }
- working(TRUE);
- if (holiday_j == 1) {
- j = j_dates(holiday_j);
- for (k=0; k<j; k++)
- if (ymd2_compare(¤t, &j_appts[k]) == 0)
- busy_today[i]++;
- }
- if (holiday_s == 1) {
- j = s_dates(holiday_s);
- for (k=0; k<j; k++)
- if (ymd2_compare(¤t, &s_appts[k]) == 0)
- busy_today[i]++;
- }
- current.tm_mday++;
- fix_current_day();
- working(FALSE);
- }
- current = First;
- fix_current_day();
- #endif /* NO_HOLIDAYS */
-
- /* display year title */
- sprintf(title, "%d", 1900 + First.tm_year);
- pw_text(main_pixwin, (rect->r_width - bigfont->pf_defaultsize.x*strlen(title))/2, starty - bigfont->pf_defaultsize.y,
- PIX_SRC, bigfont, title);
-
- /* display day names */
- if (monday_first) {
- strcpy(buf, "Mo Tu We Th Fr Sa Su ");
- strcat(buf, "Mo Tu We Th Fr Sa Su ");
- strcat(buf, "Mo Tu We Th Fr Sa Su");
- } else {
- strcpy(buf, "Su Mo Tu We Th Fr Sa ");
- strcat(buf, "Su Mo Tu We Th Fr Sa ");
- strcat(buf, "Su Mo Tu We Th Fr Sa");
- }
- pw_text(main_pixwin, startx+4, starty-2, PIX_SRC, font, buf);
-
- /* draw months */
- monthnr = 0;
- yrday = 0;
- extra_days = 0;
- if (monday_first) {
- if (First.tm_wday == SUN)
- startbox = 6;
- else
- startbox = First.tm_wday - 1;
- } else
- startbox = First.tm_wday;
- for (row=0; row<4; row++) {
- for (col=0; col<3; col++) {
- x = startx + 8*ybox_width*col;
- y = starty + 8*ybox_height*row;
- mboxlims[monthnr].lowx = x;
- mboxlims[monthnr].lowy = y;
- mboxlims[monthnr].highx = x + 7*ybox_width;
- mboxlims[monthnr].highy = y + 7*ybox_height;
- /* draw month box and label */
- pw_write(main_pixwin, x, y, 8*ybox_width,
- ybox_height, PIX_SRC, ymonthbox_pr, 0, 0);
- pw_text(main_pixwin, x+8, y+font->pf_defaultsize.y, PIX_SRC, font,
- monthnames[row*3 + col]);
- if (!extra_days) {
- nrdays = monthlength(monthnr);
- daynr = 1;
- }
- boxnr = 0;
- for (j=0; j<6; j++) {
- y += ybox_height;
- /* foreach week in the month */
- for (k=0; k<7; k++) {
- /* foreach day in the week */
- /* draw day boxes */
- pw_write(main_pixwin, x, y, ybox_width, ybox_height, PIX_SRC, ydaybox_pr, 0, 0);
- /* label day boxes */
- if (boxnr >= startbox && daynr <= nrdays) {
- if (ymd_compare(today, current) == 0)
- /* gray box */
- pw_write(main_pixwin, x, y, ybox_width, ybox_height, PIX_SRC, ydaybox_td_pr, 0, 0);
- c[0] = (daynr<10 ? ' ' : daynr/10 + '0');
- c[1] = daynr%10 + '0';
- c[2] = '\0';
- pw_text(main_pixwin, x+4, y+14,
- PIX_SRC|PIX_DST, font, c);
- /* if appointment exists, reverse video box */
- if (busy_today[yrday] > 0)
- pw_write(main_pixwin, x+2, y+2,
- ybox_width-4, ybox_height-4,
- PIX_NOT(PIX_DST), NULL, 0, 0);
- if (daynr == nrdays)
- startbox = (k + 1) % 7;
- ++daynr;
- ++yrday;
- current.tm_mday++;
- fix_current_day();
- }
- x += ybox_width;
- ++boxnr;
- }
- x -= 7*ybox_width;
- }
- ++monthnr;
- }
- }
- pw_batch_off(main_pixwin);
- current = Save;
- fix_current_day();
- unlock_cursors();
- }
-
-