home *** CD-ROM | disk | FTP | other *** search
- /*
- * $Header: ypaint.c,v 2.1 89/05/09 14:20:15 billr Exp $
- */
- /*
- * ypaint.c
- *
- * Author: Bill Randle, Tektronix, Inc. <billr@saab.CNA.TEK.COM>
- *
- * Copyright (C) 1988, 1989 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"
-
- /*
- * draw calendar for a whole year.
- */
- draw_year()
- {
- int monthnr, daynr, boxnr, i, j, k, thismonth;
- int row, col, x, y;
- int busy_today[366], 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;
-
- 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*7*ybox_height) / 2;
- sun_moon_buttons(FALSE);
- print_button(TRUE);
-
- /* Which days have appointments? */
- for (i=0; 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)) != 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) {
- for (current.tm_mday = 1; current.tm_mday <= monthlength(current.tm_mon); current.tm_mday++) {
- fix_current_day();
- 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 & REPEAT) {
- if (appt.flags & EVERY_SOMEDAY) {
- i = Pickday(appt.flags);
- current.tm_mday = 1;
- fix_current_day();
- while (current.tm_wday != i) {
- current.tm_mday++;
- current.tm_wday = (current.tm_wday + 1) % 7;
- }
- fix_current_day();
- while (ymd_compare(current, Last) <= 0) {
- if (chk_week(appt.repeat, current.tm_mday))
- busy_today[current.tm_yday]++;
- current.tm_mday += 7;
- fix_current_day();
- if (current.tm_mon != appt.month)
- break;
- }
- } else {
- fix_current_day();
- while (ymd_compare(current, Last) <= 0) {
- busy_today[current.tm_yday]++;
- current.tm_mday += appt.repeat;
- fix_current_day();
- }
- }
- } 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 */
- while (ymd_compare(current, First) < 0) {
- current.tm_mday += appt.repeat;
- fix_current_day();
- }
- while (ymd_compare(current, Last) <= 0) {
- busy_today[current.tm_yday]++;
- 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 && a_dates(&appt, holiday_a))
- busy_today[i]++;
- if (holiday_c == 1 && c_dates(&appt, holiday_c))
- busy_today[i]++;
- working(FALSE);
- if (holiday_i == 1 && i_dates(&appt, holiday_i))
- busy_today[i]++;
- working(TRUE);
- if (holiday_j == 1 && j_dates(&appt, holiday_j))
- busy_today[i]++;
- if (holiday_s == 1 && s_dates(&appt, holiday_s))
- 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 */
- 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;
- startbox = First.tm_wday;
- for (row=0; row<4; row++) {
- for (col=0; col<3; col++) {
- x = startx + 8*ybox_width*col;
- y = starty + 7*ybox_height*row;
- mboxlims[monthnr].lowx = x;
- mboxlims[monthnr].lowy = y;
- mboxlims[monthnr].highx = x + 7*ybox_width;
- mboxlims[monthnr].highy = y + 6*ybox_width;
- /* draw month box and label */
- pw_write(main_pixwin, x, y, 7*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<5; 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;
- if (extra_days && daynr > nrdays) {
- /* time to start new month */
- extra_days = 0;
- nrdays = monthlength(monthnr);
- daynr = 1;
- }
- }
- x -= 7*ybox_width;
- }
- if (daynr <= nrdays) {
- /* leftover goes in next month */
- extra_days++;
- startbox = 0;
- }
- ++monthnr;
- }
- }
- pw_batch_off(main_pixwin);
- current = Save;
- fix_current_day();
- unlock_cursors();
- }
-
-