home *** CD-ROM | disk | FTP | other *** search
- /*
- * $Header: mpaint.c,v 2.5 91/03/27 16:45:56 billr Exp $
- */
- /*
- * mpaint.c
- *
- * Author: Philip Heller, Sun Microsystems. Inc. <terrapin!heller@sun.com>
- *
- * Original source Copyright (C) 1987, Sun Microsystems, Inc.
- * All Rights Reserved
- * Permission is hereby granted to use and modify this program in source
- * or binary form as long as it is not sold for profit and this copyright
- * notice remains intact.
- *
- *
- * Changes/additions by: Bill Randle, Tektronix, Inc. <billr@saab.CNA.TEK.COM>
- *
- * Changes and additions Copyright (C) 1988, 1989, 1991 Tektronix, Inc.
- * All Rights Reserved
- * Permission is hereby granted to use and modify the modifications in source
- * or binary form as long as they are not sold for profit and this copyright
- * notice remains intact.
- */
- /***************************************************
- * *
- * Artistic routines that draw in the main *
- * subwindow for the month 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
-
- /*
- * Routine to draw month calendar.
- */
-
- draw_month()
- {
- int start_dow, i, j, k, x, y, n_days;
- int days_in_week;
- int arrow_index, last_top, index;
- char c[4], title[20], *cp;
- int left_border, right_border, top_border, bottom_border;
- Rect *rect;
- int busy_today[31];
- FILE *apts;
- int read_stat;
- struct tm Save;
- struct appt_entry appt;
- int runl;
-
- lock_cursors();
- /* destory future appts popup, if it exists */
- if (fframe) {
- window_destroy(fframe);
- fframe = 0;
- }
- fix_current_day();
- Save = current;
- current.tm_mday = 1;
- fix_current_day();
- working(TRUE);
- start_dow = current.tm_wday;
- n_days = monthlength(current.tm_mon);
-
- 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);
- left_border = (rect->r_width - 7*64)/2 + 32;
- top_border = (rect->r_height - 5*64) / 2;
- right_border = left_border + 7*64;
-
- sprintf(title, "%s, %d",
- monthnames[current.tm_mon], 1900 + current.tm_year);
- pw_text(main_pixwin, (rect->r_width - bigfont->pf_defaultsize.x*strlen(title))/2 + 32, top_border/2 + 7,
- PIX_SRC, bigfont, title);
- sun_moon_buttons(FALSE);
- print_button(TRUE);
-
- for (i=0; i<31; i++) /* Which days have appointments? */
- busy_today[i] = 0;
- if ((apts = fopen(apts_pathname, "r")) == NULL)
- err_rpt("can't open appointments file", FATAL);
- First = current;
- current.tm_mday = monthlength(current.tm_mon);
- fix_current_day();
- Last = current;
- working(FALSE);
- while ((read_stat = get_aentry(apts, &appt, FALSE, 1, First.tm_mon+1)) != EOF) {
- if (read_stat)
- continue; /* read error (ignore) */
- 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 (appt.flags & ALL_MONTHS)
- current.tm_mon = First.tm_mon;
- if (appt.flags & EVERY_SOMEDAY) {
- if ((current.tm_mon == First.tm_mon) && (current.tm_year == First.tm_year)) {
- /* find first occurance of this day this month */
- current.tm_mday = First.tm_mday;
- find_date(&appt);
- if (appt.flags & RUN)
- runl = appt.runlength;
- else
- runl = 1;
- } else if (appt.flags & RUN) {
- runl = appt.runlength;
- find_date(&appt);
- while (ymd_compare(current, First) < 0 && --runl) {
- current.tm_mday += 7;
- find_date(&appt);
- }
- if (ymd_compare(current, First) < 0) {
- /* ran out of runlength */
- continue;
- }
- } else
- continue;
- while (ymd_compare(current, Last) <= 0 && runl) {
- if (chk_week(appt.repeat, current.tm_mday)) {
- if (runl)
- busy_today[current.tm_mday-1]++;
- if (appt.flags & RUN)
- --runl;
- }
- current.tm_mday += 7;
- fix_current_day();
- }
- } else if ((appt.flags & REPEAT) && !(appt.flags & ALL_DAYS)
- && !(appt.flags & EVERY_MON_FRI)) {
- if (appt.flags & EVERY_SOMEDAY)
- continue;
- if (appt.flags & RUN)
- runl = appt.runlength;
- else
- runl = 1;
- while (ymd_compare(current, First) < 0 && runl) {
- if (appt.flags & RUN)
- --runl;
- if (runl) {
- current.tm_mday += appt.repeat;
- fix_current_day();
- }
- }
- while (ymd_compare(current, Last) <= 0 && runl) {
- if (runl) {
- busy_today[current.tm_mday-1]++;
- current.tm_mday += appt.repeat;
- fix_current_day();
- if (appt.flags & RUN)
- --runl;
- }
- }
- } else if (current.tm_year == First.tm_year
- && current.tm_mon == First.tm_mon) {
- if (appt.flags & ALL_DAYS)
- for (i=0; i<monthlength(First.tm_mon); i++)
- busy_today[i]++;
- else if (appt.flags & EVERY_MON_FRI)
- for (i=0,j=First.tm_wday; i<monthlength(First.tm_mon); i++,j++) {
- if (j > SAT)
- j = SUN;
- else if (j >= MON && j <= FRI)
- busy_today[i]++;
- }
- else if (appt.flags & DELETED)
- busy_today[appt.day-1]--;
- else
- busy_today[appt.day-1]++;
- }
-
- }
- 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<monthlength(First.tm_mon); 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++;
- working(FALSE);
- }
- current = First;
- fix_current_day();
- #endif
-
- y = top_border; /* Draw all day boxes. */
- if (monday_first) {
- if (start_dow == SUN) {
- x = 64*6 + left_border;
- days_in_week = 6;
- } else {
- x = 64*(start_dow - 1) + left_border;
- days_in_week = start_dow -1 ;
- }
- } else {
- x = 64*start_dow + left_border;
- days_in_week = start_dow;
- }
- c[0] = ' ';
- c[1] = '1';
- c[2] = ' ';
- c[3] = '\0';
- for (i=0; i<n_days; i++){
- if (ymd_compare(today, current) == 0)
- /* gray box */
- pw_write(main_pixwin,x,y,64,64,PIX_SRC,daybox_td_pr,0,0);
- else
- pw_write(main_pixwin,x,y,64,64,PIX_SRC,daybox_pr,0,0);
- if (busy_today[i] > 0)
- pw_write(main_pixwin, x+46, y+2, 16, 16,
- PIX_SRC|PIX_DST, triangle_pr, 0, 0);
- boxlims[i].lowx = x;
- boxlims[i].lowy = y;
- boxlims[i].highx = x + 63;
- boxlims[i].highy = y + 63;
- pw_text(main_pixwin,x+6,y+21,PIX_SRC|PIX_DST,bigfont,c);
- days_in_week++;
- current.tm_mday++;
- if (days_in_week == 7){
- days_in_week = 0;
- x = left_border;
- y += 64;
- }
- else
- x += 64;
- if (c[1] != '9')
- c[1]++;
- else {
- c[1] = '0';
- if (c[0] == ' ')
- c[0] = '1';
- else
- c[0]++;
- }
- }
- x = left_border + 27;
- y = top_border - 16;
- if (monday_first) {
- for (i=1; i<7; i++) { /* Mon ... Sat Sun */
- pw_char(main_pixwin,x,y,PIX_SRC,bigfont,daynames[i][0]);
- x += 64;
- }
- pw_char(main_pixwin,x,y,PIX_SRC,bigfont,daynames[0][0]);
- } else {
- for (i=0; i<7; i++) { /* Sun Mon ... Sat */
- pw_char(main_pixwin,x,y,PIX_SRC,bigfont,daynames[i][0]);
- x += 64;
- }
- }
-
- bottom_border = boxlims[n_days-1].highy;
-
- /* Draw the "week arrows" */
- arrow_index = 0;
- last_top = -1;
-
- current = First;
- for (i=0; i<n_days; i++)
- if (boxlims[i].lowy > last_top) {
- last_top = boxlims[i].lowy;
- week_arrows[arrow_index].active = 1;
- week_arrows[arrow_index].left = left_border - 64;
- week_arrows[arrow_index].top = last_top + 12;
- week_arrows[arrow_index].right =
- week_arrows[arrow_index].left + 43;
- week_arrows[arrow_index].bottom =
- week_arrows[arrow_index].top + 28;
- pw_write(main_pixwin, left_border-64, last_top + 12,
- 43, 29, PIX_SRC, weekarrow_pr, 0, 0);
-
- /* Week numbers */
- sprintf(c, "%2d", week_number());
- pw_text(main_pixwin, left_border-54, last_top+32,
- PIX_SRC, font, c);
- current.tm_mday += 7;
- fix_current_day();
-
- arrow_index++;
- }
- pw_batch_off(main_pixwin);
- current = Save;
- unlock_cursors();
- }
-