[comp.sources.sun] v01i015: Calendar/planning tool: Part 06/09

mcgrew@dartagnan.rutgers.edu (Charles Mcgrew) (05/28/89)

Submitted-by: Bill Randle <billr@saab.cna.tek.com>
Posting-number: Volume 1, Issue 15
Archive-name: calentool/part06

#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	mpaint.c
#	mt2ct.1
#	mt2ct.c
#	nap.icon
#	notify.c
#	paint.h
# This archive created: Sat May 27 13:12:55 1989
export PATH; PATH=/bin:$PATH
echo shar: extracting "'mpaint.c'" '(7869 characters)'
if test -f 'mpaint.c'
then
	echo shar: will not over-write existing file "'mpaint.c'"
else
sed 's/^	X//' << \SHAR_EOF > 'mpaint.c'
	X/*
	X * $Header: mpaint.c,v 2.1 89/05/09 14:19:29 billr Exp $
	X */
	X/*
	X * mpaint.c
	X *
	X * Author: Philip Heller, Sun Microsystems. Inc. <terrapin!heller@sun.com>
	X *
	X * Original source Copyright (C) 1987, Sun Microsystems, Inc.
	X *	All Rights Reserved
	X * Permission is hereby granted to use and modify this program in source
	X * or binary form as long as it is not sold for profit and this copyright
	X * notice remains intact.
	X *
	X *
	X * Changes/additions by: Bill Randle, Tektronix, Inc. <billr@saab.CNA.TEK.COM>
	X *
	X * Changes and additions Copyright (C) 1988, 1989 Tektronix, Inc.
	X *	All Rights Reserved
	X * Permission is hereby granted to use and modify the modifications in source
	X * or binary form as long as they are not sold for profit and this copyright
	X * notice remains intact.
	X */
	X/***************************************************
	X *						   *
	X *	Artistic routines that draw in the main    *
	X * subwindow for the month display.		   *
	X *						   *
	X ***************************************************/
	X
	X#include <suntool/sunview.h>
	X#include <suntool/canvas.h>
	X#include <ctype.h>
	X#include <stdio.h>
	X#include "ct.h"
	X#include "paint.h"
	X
	X/*
	X * Routine to draw month calendar.
	X */
	X
	Xdraw_month()
	X{
	X	int start_dow, i, x, y, n_days, n_weeks;
	X	int histo[7], days_in_week;
	X	int arrow_index, last_top, index;
	X	char c[4], title[20], *cp;
	X	int left_border, right_border, top_border, bottom_border;
	X	Rect *rect;
	X	int busy_today[31];
	X	FILE *apts;
	X	int read_stat;
	X	struct tm Save;
	X	struct appt_entry appt;
	X
	X	lock_cursors();
	X	/* destory future appts popup, if it exists */
	X	if (fframe) {
	X		window_destroy(fframe);
	X		fframe = 0;
	X	}
	X	fix_current_day();
	X	Save = current;
	X	current.tm_mday = 1;
	X	fix_current_day();
	X	working(TRUE);
	X	start_dow = current.tm_wday;
	X	n_days = monthlength(current.tm_mon);
	X	for (i=0; i<7; i++)	/* Calculate # of full/partial weeks. */
	X		histo[i] = 0;
	X	for (i=0; i<n_days; i++)
	X		histo[(start_dow + i) % 7] += 1;
	X	n_weeks = 0;
	X	for (i=0; i<7; i++)
	X		if (histo[i] > n_weeks)
	X			n_weeks = histo[i];
	X
	X	pw_batch_on(main_pixwin);
	X        rect = (Rect *) window_get(canvas, WIN_RECT);
	X	/* Erase the window */
	X        pw_writebackground(main_pixwin,0,0,rect->r_width,rect->r_height,PIX_CLR);
	X        left_border = (rect->r_width - 7*64)/2 + 32;
	X        top_border = (rect->r_height - n_weeks*64) / 2;
	X        right_border = left_border + 7*64;
	X         
	X	sprintf(title, "%s, %d",
	X		monthnames[current.tm_mon], 1900 + current.tm_year);
	X        pw_text(main_pixwin, (rect->r_width - bigfont->pf_defaultsize.x*strlen(title))/2 + 32, top_border/2 +  7,
	X          PIX_SRC, bigfont, title);
	X	sun_moon_buttons(FALSE);
	X	print_button(TRUE);
	X
	X	for (i=0; i<31; i++)		/* Which days have appointments? */
	X		busy_today[i] = 0;
	X	if ((apts = fopen(apts_pathname, "r")) == NULL)
	X		err_rpt("can't open appointments file");
	X	First = current;
	X	current.tm_mday = monthlength(current.tm_mon);
	X	fix_current_day();
	X	Last = current;
	X	working(FALSE);
	X	while ((read_stat = get_aentry(apts, &appt)) != EOF) {
	X		if (read_stat)
	X			continue;	/* read error (ignore) */
	X		if (appt.flags & A_COMMENT)
	X			continue;
	X		if ((appt.flags & MARKED_NOTE) == MARKED_NOTE)
	X			continue;
	X		current.tm_year = appt.year;
	X		current.tm_mon = appt.month;
	X		current.tm_mday = appt.day;
	X		if (appt.flags & ALL_YEARS)
	X			current.tm_year = First.tm_year;
	X		if (appt.flags & ALL_MONTHS)
	X			current.tm_mon = First.tm_mon;
	X		if ((appt.flags & EVERY_SOMEDAY) && (current.tm_mon == First.tm_mon) && (current.tm_year == First.tm_year)) {
	X			/* find first occurance of this day this month */
	X			current.tm_mday = First.tm_mday;
	X			current.tm_wday = First.tm_wday;
	X			i = Pickday(appt.flags);
	X			while (current.tm_wday != i) {
	X				current.tm_mday++;
	X				current.tm_wday = (current.tm_wday + 1) % 7;
	X			}
	X			fix_current_day();
	X			while (ymd_compare(current, Last) <= 0) {
	X				if (chk_week(appt.repeat, current.tm_mday)) {
	X					busy_today[current.tm_mday-1]++;
	X				}
	X				current.tm_mday += 7;
	X				fix_current_day();
	X			}
	X		} else if ((appt.flags & REPEAT) && !(appt.flags & ALL_DAYS)) {
	X			if (appt.flags & EVERY_SOMEDAY)
	X				continue;
	X			while (ymd_compare(current, First) < 0) {
	X				current.tm_mday += appt.repeat;
	X				fix_current_day();
	X			}
	X			while (ymd_compare(current, Last) <= 0) {
	X				busy_today[current.tm_mday-1]++;
	X				current.tm_mday += appt.repeat;
	X				fix_current_day();
	X			}
	X		} else if (current.tm_year == First.tm_year 
	X			&& current.tm_mon == First.tm_mon) {
	X			if (appt.flags & ALL_DAYS)
	X				for (i=0; i<monthlength(First.tm_mon); i++)
	X					busy_today[i]++;
	X			else if (appt.flags & DELETED)
	X				busy_today[appt.day-1]--;
	X			else
	X				busy_today[appt.day-1]++;
	X		}
	X				
	X	}
	X	fclose(apts);
	X	current = First;
	X	fix_current_day();
	X#ifndef NO_HOLIDAYS
	X	/*
	X	 * now that we've gone thru the appointments file,
	X	 * check to see if the user has selected any holiday
	X	 * options and add them in.
	X	 */
	X	for (i=0; i<monthlength(First.tm_mon); i++) {
	X		working(TRUE);
	X		if (holiday_a == 1 && a_dates(&appt, holiday_a))
	X			busy_today[i]++;
	X		if (holiday_c == 1 && c_dates(&appt, holiday_c))
	X			busy_today[i]++;
	X		working(FALSE);
	X		if (holiday_i == 1 && i_dates(&appt, holiday_i))
	X			busy_today[i]++;
	X		working(TRUE);
	X		if (holiday_j == 1 && j_dates(&appt, holiday_j))
	X			busy_today[i]++;
	X		if (holiday_s == 1 && s_dates(&appt, holiday_s))
	X			busy_today[i]++;
	X		current.tm_mday++;
	X		working(FALSE);
	X	}
	X	current = First;
	X	fix_current_day();
	X#endif
	X
	X	y = top_border;				/* Draw all day boxes. */
	X	x = 64*start_dow + left_border;
	X        days_in_week = start_dow;
	X        c[0] = ' ';
	X        c[1] = '1';
	X        c[2] = ' ';
	X        c[3] = '\0';
	X        for (i=0; i<n_days; i++){
	X		if (ymd_compare(today, current) == 0)
	X			/* gray box */
	X			pw_write(main_pixwin,x,y,64,64,PIX_SRC,daybox_td_pr,0,0);
	X		else
	X			pw_write(main_pixwin,x,y,64,64,PIX_SRC,daybox_pr,0,0);
	X		if (busy_today[i] > 0)
	X			pw_write(main_pixwin, x+46, y+2, 16, 16,
	X			  PIX_SRC|PIX_DST, triangle_pr, 0, 0);
	X                boxlims[i].lowx = x;
	X                boxlims[i].lowy = y;
	X                boxlims[i].highx = x + 63;
	X                boxlims[i].highy = y + 63;
	X		pw_text(main_pixwin,x+6,y+21,PIX_SRC|PIX_DST,bigfont,c);
	X                days_in_week++;
	X		current.tm_mday++;
	X                if (days_in_week == 7){
	X                        days_in_week = 0;
	X                        x = left_border;
	X                        y += 64;
	X                }
	X		else
	X                        x += 64;
	X                if (c[1] != '9')
	X                        c[1]++;
	X                else {
	X                        c[1] = '0';
	X                        if (c[0] == ' ')
	X                                c[0] = '1';
	X                        else
	X                                c[0]++;
	X                }
	X        }
	X        x = left_border + 27;
	X        y = top_border - 16;
	X	for (i=0; i<7; i++) {		/* Sun Mon ... Sat */
	X		pw_char(main_pixwin,x,y,PIX_SRC,bigfont,daynames[i][0]);
	X                x += 64;
	X        }
	X
	X	bottom_border = boxlims[n_days-1].highy;
	X
	X        /* Draw the "week arrows" */
	X        arrow_index = 0;
	X        last_top = -1;
	X        for (i=0; i<n_days; i++)
	X                if (boxlims[i].lowy > last_top) {
	X                        last_top = boxlims[i].lowy;
	X                        week_arrows[arrow_index].active = 1;
	X                        week_arrows[arrow_index].left = left_border - 64;
	X                        week_arrows[arrow_index].top = last_top + 12;
	X                        week_arrows[arrow_index].right =
	X                          week_arrows[arrow_index].left + 43;
	X                        week_arrows[arrow_index].bottom =
	X                          week_arrows[arrow_index].top + 28;
	X                        pw_write(main_pixwin, left_border-64, last_top + 12,
	X                          43, 29, PIX_SRC, weekarrow_pr, 0, 0);
	X                        arrow_index++;
	X                }
	X	pw_batch_off(main_pixwin);
	X	current = Save;
	X	unlock_cursors();
	X}
SHAR_EOF
if test 7869 -ne "`wc -c < 'mpaint.c'`"
then
	echo shar: error transmitting "'mpaint.c'" '(should have been 7869 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'mt2ct.1'" '(1682 characters)'
if test -f 'mt2ct.1'
then
	echo shar: will not over-write existing file "'mt2ct.1'"
else
sed 's/^	X//' << \SHAR_EOF > 'mt2ct.1'
	X.\" $Header: mt2ct.1,v 2.1 89/05/09 14:29:45 billr Exp $
	X.\"
	X.TH MT2CT 1L "22 February 1989"
	X.SH NAME
	Xmt2ct, month2ct, cal2ct - appointment file conversion utilities
	X.SH SYNOPSIS
	X.B mt2ct
	X[
	X.I file
	X]
	X.br
	X.B month2ct
	X[
	X.I file
	X]
	X.br
	X.B cal2ct
	X[
	X.I file
	X]
	X.SH DESCRIPTION
	X.I Calentool
	Xuses an appointment file format that is incompatable with several
	Xother calendar or reminder programs.  These utilities may be used
	Xto convert from one of those formats to the format
	X.I calentool
	Xuses.
	X.LP
	X.I Mt2ct
	Xconverts files maintained by
	X.I monthtool(1L)
	Xto calentool's .appointment format.
	X.I Month2ct
	Xconverts files maintained by
	X.I month(1L)
	Xto calentool's .appointment format.
	X.I Cal2ct
	Xconverts files maintained by
	X.I calendar(1)
	Xto calentool's .appointment format.
	XIn all cases the converted file is written to "$HOME/.appointments".
	X.SH OPTIONS
	XAn optional filename may be specified to convert.  The default filename
	Xdepends on the specific conversion.  For
	X.I monthtool
	Xit is "$HOME/.monthtool".  For
	X.I month
	Xit is "$HOME/.month".  For
	X.I calendar
	Xit is "$HOME/.calendar".
	X.SH "SEE ALSO"
	Xcalentool(1L), monthtool(1L), month(1L), calendar(1)
	X.SH AUTHOR
	XBill Randle (Tektronix, Inc., billr@saab.CNA.TEK.COM)
	X.SH BUGS
	X.I Monthtool
	Xand
	X.I month
	Xallow any time selections.  Because
	X.I calentool
	Xonly has 30 minute timeslots, all times are rounded to the nearest
	X30 minute interval (e.g. 1:10 becomes 1:00, 1:20 becomes 1:30 and
	X1:50 becomes 2:00).  All
	X.I calendar
	Xfile entries are converted to
	X.I calentool
	Xnotes, since
	X.I calendar
	Xdoes not have a standardized way of indicating times.  They can be
	Xmanually moved to the proper timeslot using
	X.I calentool's
	X.BR cut and paste
	Xoperations.
SHAR_EOF
if test 1682 -ne "`wc -c < 'mt2ct.1'`"
then
	echo shar: error transmitting "'mt2ct.1'" '(should have been 1682 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'mt2ct.c'" '(3283 characters)'
if test -f 'mt2ct.c'
then
	echo shar: will not over-write existing file "'mt2ct.c'"
else
sed 's/^	X//' << \SHAR_EOF > 'mt2ct.c'
	X/*
	X * $Header: mt2ct.c,v 2.1 89/05/09 14:19:31 billr Exp $
	X */
	X/*
	X * mt2ct - convert monthtool reminder files to calentool style files
	X *
	X * Author: Bill Randle, Tektronix, Inc. <billr@saab.CNA.TEK.COM>
	X *
	X * Copyright (C) 1989 Tektronix, Inc.  All Rights Reserved
	X *
	X * Permission is hereby granted to use and modify this code in source
	X * or binary form as long as it is not sold for profit and this copyright
	X * notice remains intact.
	X */
	X
	X#include "ct.h"
	X#include <stdio.h>
	X#include <ctype.h>
	X
	Xstruct appt_entry appts;
	Xstruct appt_entry *aptr;
	Xchar filename[128], *file;
	XFILE *fp;
	X
	Xextern char *getenv();
	X
	Xmain(argc, argv)
	Xint argc;
	Xchar *argv[];
	X{
	X	if (argc > 1)
	X		file = argv[1];
	X	else {
	X		strcpy(filename, getenv("HOME"));
	X		strcat(filename, "/.monthtool");
	X		file = filename;
	X	}
	X
	X	if ((fp = fopen(file, "r")) == NULL) {
	X		fprintf(stderr, "can't open monthtool file <%s> for reading\n", file);
	X		exit(1);
	X	}
	X	if (!read_mt_file()) {
	X		fprintf(stderr, "no reminders read from %s\n", file);
	X		exit(1);
	X	}
	X	fclose(fp);
	X	strcpy(filename, getenv("HOME"));
	X	strcat(filename, "/.appointments");
	X	if ((fp = fopen(filename, "w")) == NULL) {
	X		fprintf(stderr, "can't open .appointments file for writing\n");
	X		exit(1);
	X	}
	X	write_ct_file();
	X}
	X
	X/*
	X * read in the monthtool file, filling the appts records
	X */
	Xint
	Xread_mt_file()
	X{
	X	char *ptr, *fgets();
	X	char buf[512];
	X	struct appt_entry *optr;
	X
	X	aptr = &appts;
	X	while (fgets(buf, 512, fp) != NULL) {
	X		aptr->flags = aptr->repeat = aptr->lookahead = 0;
	X		aptr->sindex = 0;
	X		aptr->next = NULL;
	X		ptr = buf;
	X		while (isspace(*ptr))
	X			++ptr;
	X		aptr->month = *ptr++ - '0';
	X		if (isdigit(*ptr))
	X			aptr->month = aptr->month * 10 + (*ptr++ - '0');
	X		++ptr;	/* skip ',' */
	X		aptr->day = *ptr++ - '0';
	X		if (isdigit(*ptr))
	X			aptr->day = aptr->day * 10 + (*ptr++ - '0');
	X		++ptr;	/* skip ',' */
	X		aptr->year = 0;
	X		while (isdigit(*ptr))
	X			aptr->year = aptr->year * 10 + (*ptr++ - '0');
	X		if (aptr->year > 1900)
	X			aptr->year -= 1900;
	X		++ptr;	/* skip ',' */
	X		if (!strncmp(ptr, "    ", 4)) {
	X			aptr->flags |= A_NOTE;
	X			ptr += 5;
	X		} else {
	X			aptr->hour = (*ptr++ - '0') * 10;
	X			aptr->hour += *ptr++ - '0';
	X			aptr->minute = (*ptr++ - '0') * 10;
	X			aptr->minute += *ptr++ - '0';
	X			if (aptr->minute < 15)
	X				aptr->minute = 0;
	X			else if (aptr->minute < 45)
	X				aptr->minute = 30;
	X			else {
	X				aptr->minute = 0;
	X				aptr->hour++;
	X			}
	X			++ptr;	/* skip ',' */
	X		}
	X		strcpy(aptr->str, ptr);
	X		if (aptr->year == 0)
	X			aptr->flags |= ALL_YEARS;
	X		if (aptr->month == 0)
	X			aptr->flags |= ALL_MONTHS;
	X		if (aptr->day == 0)
	X			aptr->flags |= ALL_DAYS;
	X		if (aptr->month == 99) {
	X			/* weekly reminder */
	X			aptr->flags |= ALL_MONTHS;
	X			aptr->flags |= Setday(aptr->day-1);
	X		}
	X		aptr->next = (struct appt_entry *)malloc(sizeof(struct appt_entry));
	X		if (aptr->next == NULL) {
	X			fprintf(stderr, "out of memory\n");
	X			return;
	X		}
	X		optr = aptr;
	X		aptr = aptr->next;
	X	}
	X	if (aptr == &appts)
	X		return(0);	/* nothing read */
	X	/* don't need the last one */
	X	free(aptr);
	X	optr->next = NULL;
	X	return(1);
	X}
	X
	X/*
	X * write out the new .appointments file
	X */
	Xwrite_ct_file()
	X{
	X	aptr = &appts;
	X	fputs(HEADER, fp);
	X	while (aptr) {
	X		if (put_aentry(fp, aptr)) {
	X			fprintf(stderr, "error writing .appointments file\n");
	X			return;
	X		}
	X		aptr = aptr->next;
	X	}
	X}
SHAR_EOF
if test 3283 -ne "`wc -c < 'mt2ct.c'`"
then
	echo shar: error transmitting "'mt2ct.c'" '(should have been 3283 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'nap.icon'" '(2591 characters)'
if test -f 'nap.icon'
then
	echo shar: will not over-write existing file "'nap.icon'"
else
sed 's/^	X//' << \SHAR_EOF > 'nap.icon'
	X/* Format_version=1, Width=64, Height=64, Depth=1, Valid_bits_per_item=16
	X *
	X * $Header: nap.icon,v 2.1 89/05/09 14:30:48 billr Exp $
	X *      Copyright (C) 1988, The Regents of the University of California
	X *                            All rights Reserved
	X *                       Author: R. P. C. Rodgers, M.D.
	X *
	X * Redistribution and use in source and binary forms are permitted
	X * provided that this notice is preserved and that due credit is given
	X * to the University of California at San Francisco. The name of the University
	X * may not be used to endorse or promote products derived from this
	X * software without specific prior written permission. This software
	X * is provided ``as is'' without express or implied warranty.
	X */
	X	0xFFFF,0xFFFF,0xFFFF,0xFFFF,0x8000,0x0000,0x0000,0x0001,
	X	0x8000,0x0000,0x0000,0x0001,0x8000,0x1800,0x0400,0x0181,
	X	0x81C6,0x0862,0x8F18,0x6081,0x8201,0x0893,0x4424,0x9081,
	X	0x8207,0x08E2,0x4424,0x9081,0x8209,0x0882,0x4424,0x9081,
	X	0x81C5,0x0872,0x4318,0x6081,0x8000,0x0000,0x0000,0x0001,
	X	0x8000,0x0001,0xE000,0x0001,0x8000,0x0007,0xF800,0x0001,
	X	0x8000,0x000C,0x0C00,0x0001,0x8000,0x0018,0x0600,0x0001,
	X	0x83FF,0xFFDB,0x36FF,0xFFF1,0x8600,0x0019,0x6600,0x0011,
	X	0x8E00,0x0019,0xA600,0x0011,0x9A00,0x0019,0x2600,0x0011,
	X	0x9200,0x0019,0x6600,0x0011,0x9600,0x0019,0xA600,0x0011,
	X	0x9A00,0x0019,0x2600,0x0011,0x9200,0x003D,0x6F00,0x0011,
	X	0x9600,0x003D,0xAF00,0x0011,0x9A00,0x003D,0x2F00,0x0011,
	X	0x9200,0x0019,0x6600,0x0011,0x9600,0x0001,0xA000,0x0011,
	X	0x9A00,0x0001,0x2000,0x0011,0x9200,0x0001,0x6000,0x0011,
	X	0x9600,0x0001,0xA000,0x0011,0x9A00,0x0001,0x2000,0x0011,
	X	0x9200,0x0001,0x6000,0x0011,0x9600,0x0000,0x0000,0x0011,
	X	0x9A00,0x0001,0xE000,0x0011,0x9200,0x0007,0xF800,0x0011,
	X	0x9600,0x000C,0x0C00,0x0011,0x9A00,0x0019,0xA600,0x0011,
	X	0x9200,0x0019,0x2600,0x0011,0x9600,0x0019,0x6600,0x0011,
	X	0x9A00,0x0019,0xA600,0x0011,0x9200,0x0019,0x2600,0x0011,
	X	0x9600,0x0019,0x6600,0x0011,0x9A00,0x0019,0xA600,0x0011,
	X	0x9200,0x0019,0x2600,0x0011,0x9600,0x003D,0x6F00,0x0011,
	X	0x9A00,0x003D,0xAF00,0x0011,0x9200,0x003D,0x2F00,0x0011,
	X	0x9600,0x0019,0x6600,0x0011,0x9A00,0x0001,0xA000,0x0011,
	X	0x9200,0x0001,0x2000,0x0011,0x9600,0x0001,0x6000,0x0011,
	X	0x9A00,0x0001,0xA000,0x0011,0x9200,0x0001,0x2000,0x0011,
	X	0x9600,0x0001,0x6000,0x0011,0x9A00,0x0001,0xA000,0x0011,
	X	0x9200,0x0001,0x2000,0x0011,0x9600,0x0001,0x6000,0x0011,
	X	0x9A00,0x0001,0xA000,0x0011,0x93FF,0xFFFF,0x3FFF,0xFFF1,
	X	0x9649,0x2492,0x4924,0x9261,0x9C92,0x4924,0x9249,0x24C1,
	X	0x9FFF,0xFFFF,0xFFFF,0xFF81,0x8000,0x0000,0x0000,0x0001,
	X	0x8000,0x0000,0x0000,0x0001,0xFFFF,0xFFFF,0xFFFF,0xFFFF
SHAR_EOF
if test 2591 -ne "`wc -c < 'nap.icon'`"
then
	echo shar: error transmitting "'nap.icon'" '(should have been 2591 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'notify.c'" '(30523 characters)'
if test -f 'notify.c'
then
	echo shar: will not over-write existing file "'notify.c'"
else
sed 's/^	X//' << \SHAR_EOF > 'notify.c'
	X/*
	X * $Header: notify.c,v 2.1 89/05/09 14:23:13 billr Exp $
	X */
	X/*
	X * notify.c
	X *
	X * Author: Philip Heller, Sun Microsystems. Inc. <terrapin!heller@sun.com>
	X *
	X * Original source Copyright (C) 1987, Sun Microsystems, Inc.
	X *	All Rights Reserved
	X * Permission is hereby granted to use and modify this program in source
	X * or binary form as long as it is not sold for profit and this copyright
	X * notice remains intact.
	X *
	X *
	X * Changes/additions by: Bill Randle, Tektronix, Inc. <billr@saab.CNA.TEK.COM>
	X *
	X * Changes and additions Copyright (C) 1988, 1989 Tektronix, Inc.
	X *	All Rights Reserved
	X * Permission is hereby granted to use and modify the modifications in source
	X * or binary form as long as they are not sold for profit and this copyright
	X * notice remains intact.
	X */
	X/**********************************************************
	X *							  *
	X *	 These are the notify routines which are invoked  *
	X * by events in the control panel subwindow,and the	  *
	X * various popup window panels.				  *
	X *							  *
	X **********************************************************/
	X
	X
	X
	X#include <stdio.h>
	X#include <suntool/sunview.h>
	X#include <suntool/canvas.h>
	X#include <suntool/panel.h>
	X#include <suntool/menu.h>
	X#include "ct.h"
	X
	Xextern int mainsw_state, nr_weekdays, day_is_open;
	Xextern int dayslot_width, nr_weekdays;
	Xextern struct tm today, current;
	Xextern Cursor month_cursor, week_cursor, day_cursor, year_cursor;
	Xextern Pixfont *font;
	Xextern Frame frame;
	Xextern Panel panel;
	Xextern Canvas canvas;
	Xextern Pixwin *main_pixwin;
	Xextern Menu next_menu, previous_menu, year_menu, month_menu;
	Xextern Menu day_menu, week_menu, current_menu;
	Xextern Frame fframe;
	Xextern Panel_item repeat_pi, remind_pi, daysel_pi;
	Xextern Panel_item everyx_pi, whichwk_pi, marked_pi;
	Xextern Panel_item del_choice_pi, setdate_pi;
	X#ifndef NO_SUN_MOON
	Xextern Frame mframe, sframe;
	Xextern Panel_item moonbutton_pi, sunbutton_pi;
	X#endif
	Xextern Frame fileframe;
	Xextern Panel_item filename_pi, file_ro_pi;
	X#ifndef NO_PRINTER
	Xextern Panel_item prcmd_pi;
	Xextern Frame prframe;
	Xextern Menu print_menu;
	X#endif
	Xextern Frame prompt_frame, date_frame;
	Xextern struct appt_entry future[];
	Xextern struct dayslot slots[];
	Xextern int attr_bi;  /* index into currently active day slot */
	Xextern int new_entry;
	Xextern struct tm olddate;
	Xextern int otherfile, read_only;
	Xextern char *othername, apts_pathname[], orig_apts_pathname[];
	Xextern int orig_ro;
	Xextern char printer[];
	Xextern int show_future;
	Xextern int show_time;
	Xextern int update_interval;
	Xextern char todays_date[], timestr[];
	Xextern struct appt_entry shelf_appt;
	X
	Xint i;
	X
	X
	Xvoid
	Xweekbutton_notify(item, event)
	XPanel_item item;
	XEvent *event;
	X{
	X	if (event_id(event) == MS_LEFT) {
	X		switch (mainsw_state) {
	X			case DISPLAYING_DAY:
	X				close_day();
	X				break;
	X			case DISPLAYING_WEEK:
	X				return;
	X			case DISPLAYING_MONTH:
	X				/* first week in month */
	X				current.tm_mday = 1;
	X				first_wkday();
	X				break;
	X			case DISPLAYING_YEAR:
	X				/* first week in year */
	X				current.tm_mday = 1;
	X				current.tm_mon = JAN;
	X				first_wkday();
	X				break;
	X		}
	X		mainsw_state = DISPLAYING_WEEK;
	X		draw_week();
	X		window_set(canvas, WIN_CURSOR, week_cursor, 0);
	X	} else
	X		panel_default_handle_event(item, event);
	X}
	X
	X
	Xvoid
	Xweek_menu_event(item, event)
	XPanel_item item;
	XEvent *event;
	X{
	X	int value, i;
	X	Menu_item an_item;
	X
	X	if (event_id(event) == MS_RIGHT && event_is_down(event)) {
	X		if (mainsw_state > DISPLAYING_MONTH) {
	X			/* make all entries inactive */
	X			for (i=1; i<=6; i++) {
	X				an_item = menu_get(week_menu, MENU_NTH_ITEM, i);
	X				menu_set(an_item, MENU_INACTIVE, TRUE, 0);
	X			}
	X		} else {
	X			/* make all entries active */
	X			for (i=1; i<=6; i++) {
	X				an_item = menu_get(week_menu, MENU_NTH_ITEM, i);
	X				menu_set(an_item, MENU_INACTIVE, FALSE, 0);
	X			}
	X		}
	X		value = (int) menu_show(week_menu, panel, event, 0);
	X		if (value > 0) {
	X			current.tm_mday = (value - 1) * 7 + 1;
	X			if (current.tm_mday > monthlength(current.tm_mon))
	X				current.tm_mday = monthlength(current.tm_mon);
	X			if (mainsw_state == DISPLAYING_DAY)
	X				close_day();
	X			if (mainsw_state != DISPLAYING_WEEK) {
	X				mainsw_state = DISPLAYING_WEEK;
	X				window_set(canvas, WIN_CURSOR, week_cursor, 0);
	X			}
	X			draw_week();
	X		}
	X	} else
	X		panel_default_handle_event(item, event);
	X}
	X
	Xlastmonth()
	X{
	X
	X	current.tm_mon -= 1;
	X	current.tm_mday = 1;
	X	draw_month();
	X}
	X
	X 
	Xnextmonth()
	X{ 
	X	current.tm_mon += 1;
	X	current.tm_mday = 1;
	X        draw_month();
	X} 
	X 
	X
	Xvoid
	Xmonthmenu_notify(item, event)  
	XPanel_item item;  
	XEvent *event;
	X{  
	X	int i, j, new_day;
	X
	X	if (event_id(event) == MS_LEFT) {
	X		if (mainsw_state == DISPLAYING_YEAR)
	X			/* go to first month of year */
	X			current.tm_mon = JAN;
	X		current.tm_mday = 1;
	X		if (mainsw_state == DISPLAYING_DAY)
	X			close_day();
	X		if (mainsw_state != DISPLAYING_MONTH) {
	X			mainsw_state = DISPLAYING_MONTH;
	X			window_set(canvas, WIN_CURSOR, month_cursor, 0);
	X		}
	X		draw_month();
	X	} else
	X		panel_default_handle_event(item, event);
	X}
	X
	Xvoid
	Xmonth_menu_event(item, event)
	XPanel_item item;
	XEvent *event;
	X{
	X	int value;
	X
	X	if (event_id(event) == MS_RIGHT && event_is_down(event)) {
	X		value = (int) menu_show(month_menu, panel, event, 0);
	X		if (value > 0) {
	X			current.tm_mday = 1;
	X			current.tm_mon = value - 1;
	X			if (mainsw_state == DISPLAYING_DAY)
	X				close_day();
	X			if (mainsw_state != DISPLAYING_MONTH) {
	X				mainsw_state = DISPLAYING_MONTH;
	X				window_set(canvas, WIN_CURSOR, month_cursor, 0);
	X			}
	X			draw_month();
	X		}
	X	} else
	X		panel_default_handle_event(item, event);
	X}
	X
	X
	Xlastyear()
	X{
	X	current.tm_mday = 1;
	X	current.tm_mon = JAN;
	X	current.tm_year -= 1;
	X	draw_year();
	X}
	X
	Xnextyear()
	X{
	X	current.tm_mday = 1;
	X	current.tm_mon = JAN;
	X	current.tm_year += 1;
	X	draw_year();
	X}
	X
	Xvoid
	Xyearmenu_notify(item, event)
	XPanel_item item;
	XEvent *event;
	X{
	X	int old_state;
	X
	X	if (event_id(event) == MS_LEFT) {
	X		if (mainsw_state == DISPLAYING_DAY) 
	X			close_day(); 
	X		old_state = mainsw_state;
	X		mainsw_state = DISPLAYING_YEAR; 
	X		draw_year(); 
	X		if (old_state != DISPLAYING_YEAR)
	X			window_set(canvas, WIN_CURSOR, year_cursor, 0);
	X	} else
	X		panel_default_handle_event(item, event);
	X} 
	X
	Xvoid
	Xyear_menu_event(item, event)
	XPanel_item item;
	XEvent *event;
	X{
	X	int value, old_state;
	X
	X	if (event_id(event) == MS_RIGHT && event_is_down(event)) {
	X		value = (int) menu_show(year_menu, panel, event, 0);
	X		if (value > 0) {
	X			current.tm_year = START_YEAR + value - 1;
	X			if (mainsw_state == DISPLAYING_DAY) 
	X				close_day(); 
	X			old_state = mainsw_state;
	X			mainsw_state = DISPLAYING_YEAR; 
	X			draw_year(); 
	X			if (old_state != DISPLAYING_YEAR)
	X				window_set(canvas, WIN_CURSOR, year_cursor, 0);
	X		}
	X	} else
	X		panel_default_handle_event(item, event);
	X}
	X
	X
	Xlastweek()
	X{
	X	if (mainsw_state == DISPLAYING_DAY) {
	X		close_day();
	X		current.tm_mday -= 7;
	X		draw_day();
	X	} else if (mainsw_state == DISPLAYING_WEEK) {
	X		current.tm_mday -= 7;
	X		draw_week();
	X	}
	X}
	X
	X
	Xnextweek()
	X{
	X        if (mainsw_state == DISPLAYING_DAY) {
	X                close_day();
	X		current.tm_mday += 7;
	X                draw_day();
	X        } else if (mainsw_state == DISPLAYING_WEEK) {
	X		current.tm_mday += 7;
	X                draw_week();
	X	}
	X}
	X
	X
	X
	Xyesterday()
	X{
	X	if (mainsw_state != DISPLAYING_DAY)
	X		return(0);
	X	close_day();
	X	current.tm_mday--;
	X	draw_day();
	X}
	X
	X
	Xvoid
	Xtodaybutton_notify(item, event)
	XPanel_item item;
	XEvent *event;
	X{
	X	if (event_id(event) == MS_LEFT) {
	X		if (mainsw_state == DISPLAYING_DAY)
	X			close_day();
	X		else {
	X			mainsw_state = DISPLAYING_DAY;
	X			window_set(canvas, WIN_CURSOR, day_cursor, 0);
	X		}
	X		get_today();
	X		current = today;
	X		draw_day();
	X	} else
	X		panel_default_handle_event(item, event);
	X}
	X
	X
	X
	Xtomorrow()
	X{ 
	X        if (mainsw_state != DISPLAYING_DAY)
	X                return(0);
	X        close_day(); 
	X	current.tm_mday++;
	X        draw_day(); 
	X} 
	X 
	X
	Xvoid
	Xcurrentbutton_notify(item, event)
	XPanel_item item;
	XEvent *event;
	X{
	X	if (event_id(event) == MS_LEFT) {
	X		if (mainsw_state == DISPLAYING_DAY)
	X			close_day();
	X		get_today();
	X		current = today;
	X		switch (mainsw_state) {
	X			case DISPLAYING_DAY:
	X				draw_day();
	X				break;
	X			case DISPLAYING_WEEK:
	X				draw_week();
	X				break;
	X			case DISPLAYING_MONTH:
	X				draw_month();
	X				break;
	X			case DISPLAYING_YEAR:
	X				draw_year();
	X				break;
	X		}
	X	} else
	X		panel_default_handle_event(item, event);
	X}
	X
	Xvoid
	Xcurrent_menu_event(item, event)
	XPanel_item item;
	XEvent *event;
	X{
	X	Menu_item an_item;
	X	char date[9];
	X	int value, rtn;
	X	struct tm Save;
	X
	X	if (event_id(event) == MS_RIGHT && event_is_down(event)) {
	X		value = (int) menu_show(current_menu, panel, event, 0);
	X		if (value == 0)
	X			return;	/* no selection made */
	X		if (mainsw_state == DISPLAYING_DAY)
	X			close_day();
	X		get_today();
	X		Save = current;
	X		current = today;
	X		switch (value) {
	X			case 1:	/* current day */
	X				mainsw_state = DISPLAYING_DAY;
	X				window_set(canvas, WIN_CURSOR, day_cursor, 0);
	X				draw_day();
	X				break;
	X
	X			case 2:	/* current week */
	X				mainsw_state = DISPLAYING_WEEK;
	X				window_set(canvas, WIN_CURSOR, week_cursor, 0);
	X				draw_week();
	X				break;
	X
	X			case 3:	/* current month */
	X				mainsw_state = DISPLAYING_MONTH;
	X				window_set(canvas, WIN_CURSOR, month_cursor, 0);
	X				draw_month();
	X				break;
	X
	X			case 4:	/* current year */
	X				mainsw_state = DISPLAYING_YEAR;
	X				window_set(canvas, WIN_CURSOR, year_cursor, 0);
	X				draw_year();
	X				break;
	X
	X			case 5:	/* change date */
	X				sprintf(date, "%d/%d/%02d", Save.tm_mon+1, Save.tm_mday, Save.tm_year);
	X				panel_set_value(setdate_pi, date);
	X				do {
	X					window_loop(date_frame);
	X					/* change "current" date to reflect entry */
	X					rtn = parse_date((char *)panel_get_value(setdate_pi), FALSE);
	X				} while (rtn);
	X				mainsw_state = DISPLAYING_DAY;
	X				window_set(canvas, WIN_CURSOR, day_cursor, 0);
	X				draw_day();
	X				break;
	X		}
	X	} else
	X		panel_default_handle_event(item, event);
	X}
	X
	X/*
	X * notifier for set date frame "Done" button
	X */
	Xvoid
	Xdtdone_proc(item, event)
	XPanel_item item;
	XEvent *event;
	X{
	X	if (event_id(event) == MS_LEFT)
	X		window_return(0);
	X}
	X
	X/* "done" from subframe menu of change date frame */
	Xvoid
	Xdtframe_done(frame)
	XFrame frame;
	X{
	X	window_set(date_frame, WIN_SHOW, FALSE, 0);
	X}
	X
	Xvoid
	Xdaybutton_notify(item, event)
	XPanel_item item;
	XEvent *event;
	X{
	X	if (event_id(event) == MS_LEFT) {
	X		switch (mainsw_state) {
	X			case DISPLAYING_DAY:
	X				/* no change */
	X				return;
	X			case DISPLAYING_WEEK:
	X				/* pick first day in week */
	X				while (current.tm_wday != SUN) {
	X					current.tm_mday--;
	X					current.tm_wday--;
	X				}
	X				if (nr_weekdays < 7)
	X					/* start with MON */
	X					current.tm_mday++;
	X				break;
	X			case DISPLAYING_MONTH:
	X				/* pick first day in month */
	X				current.tm_mday = 1;
	X				first_wkday();
	X				break;
	X			case DISPLAYING_YEAR:
	X				/* pick first day in year */
	X				current.tm_mon = JAN;
	X				current.tm_mday = 1;
	X				first_wkday();
	X				break;
	X		}
	X		mainsw_state = DISPLAYING_DAY;
	X		draw_day();
	X		window_set(canvas, WIN_CURSOR, day_cursor, 0);
	X	} else
	X		panel_default_handle_event(item, event);
	X}
	X
	Xvoid
	Xday_menu_event(item, event)
	XPanel_item item;
	XEvent *event;
	X{
	X	int value, i;
	X	Menu_item an_item;
	X
	X	if (event_id(event) == MS_RIGHT && event_is_down(event)) {
	X		if (mainsw_state > DISPLAYING_WEEK) {
	X			/* make all entries inactive */
	X			for (i=1; i<=7; i++) {
	X				an_item = menu_get(day_menu, MENU_NTH_ITEM, i);
	X				menu_set(an_item, MENU_INACTIVE, TRUE, 0);
	X			}
	X		} else {
	X			/* make all entries active */
	X			for (i=1; i<=7; i++) {
	X				an_item = menu_get(day_menu, MENU_NTH_ITEM, i);
	X				menu_set(an_item, MENU_INACTIVE, FALSE, 0);
	X			}
	X		}
	X		value = (int) menu_show(day_menu, panel, event, 0);
	X		if (value > 0) {
	X			/* find selected day in this week */
	X			if (--value > current.tm_wday)
	X				current.tm_mday += value - current.tm_wday;
	X			else
	X				current.tm_mday -= current.tm_wday - value;
	X			mainsw_state = DISPLAYING_DAY;
	X			draw_day();
	X			window_set(canvas, WIN_CURSOR, day_cursor, 0);
	X		}
	X	} else
	X		panel_default_handle_event(item, event);
	X}
	X
	Xfirst_wkday()
	X{
	X	/*
	X	 * Set day to first displayable day of the week selected.
	X	 * If we have a 7-day week display, then it will always
	X	 * be the first day of the month. If we have a 5 or 6 day
	X	 * display, the first day may need to be adjusted to the
	X	 * following monday.
	X	 */
	X	if (nr_weekdays == 7)
	X		/* it's ok as is */
	X		return;
	X	fix_current_day();	/* update wkday, etc. */
	X	if (current.tm_wday == SUN)
	X		current.tm_mday++;
	X	else if (current.tm_wday > nr_weekdays)
	X		current.tm_mday += 7 - current.tm_wday + 1;
	X}
	X
	Xvoid
	Xnext_menu_event(item, event)
	XPanel_item item;
	XEvent *event;
	X{
	X	Menu_item an_item;
	X	int value;
	X
	X	if (event_id(event) == MS_RIGHT && event_is_down(event)) {
	X		i = 0;
	X		while (++i < mainsw_state) {
	X			an_item = menu_get(next_menu, MENU_NTH_ITEM, i);
	X			menu_set(an_item, MENU_INACTIVE, TRUE, 0);
	X		}
	X		for (i=mainsw_state; i<=DISPLAYING_YEAR; i++) {
	X			an_item = menu_get(next_menu, MENU_NTH_ITEM, i);
	X			menu_set(an_item, MENU_INACTIVE, FALSE, 0);
	X		}
	X		value = (int) menu_show(next_menu, panel, event, 0);
	X		if (value == 0)
	X			return;	/* no selection made */
	X		value--;
	X		switch (mainsw_state) {
	X			case DISPLAYING_DAY:
	X				switch (value) {
	X					case 0:	/* day */
	X						tomorrow();
	X						break;
	X					case 1: /* week */
	X						close_day();
	X						current.tm_mday += 7;
	X						draw_day();
	X						break;
	X					case 2:	/* month */
	X						close_day();
	X						current.tm_mon++;
	X						/* make sure day ends up in proper month */
	X						if (current.tm_mday == monthlength(current.tm_mon-1))
	X							/* last day of month */
	X							current.tm_mday = monthlength(current.tm_mon%12);
	X						else if (current.tm_mday > monthlength(current.tm_mon%12))
	X							current.tm_mday = monthlength(current.tm_mon%12);
	X						draw_day();
	X						break;
	X					case 3: /* year */
	X						close_day();
	X						current.tm_year++;
	X						draw_day();
	X						break;
	X				}
	X				break;
	X			case DISPLAYING_WEEK:
	X				switch (value) {
	X					case 1:	/* week */
	X						nextweek();
	X						break;
	X					case 2:	/* month */
	X						current.tm_mon++;
	X						draw_week();
	X						break;
	X					case 3:	/* year */
	X						current.tm_year++;
	X						draw_week();
	X						break;
	X				}
	X				break;
	X			case DISPLAYING_MONTH:
	X				switch (value) {
	X					case 2: /* month */
	X						nextmonth();
	X						break;
	X					case 3:	/* year */
	X						current.tm_year++;
	X						draw_month();
	X						break;
	X				}
	X				break;
	X			case DISPLAYING_YEAR:
	X				if (value == 3)
	X					nextyear();
	X				break;
	X		}
	X	} else
	X		panel_default_handle_event(item, event);
	X}
	X
	Xvoid
	Xnextbutton_notify(item, event) 
	XPanel_item item; 
	XEvent *event; 
	X{ 
	X	if (event_id(event) == MS_LEFT) {
	X		switch (mainsw_state) {
	X			case DISPLAYING_DAY:
	X				tomorrow();
	X				break;
	X			case DISPLAYING_WEEK:
	X				nextweek();
	X				break;
	X			case DISPLAYING_MONTH:
	X				nextmonth();
	X				break;
	X			case DISPLAYING_YEAR:
	X				nextyear();
	X				break;
	X		}
	X	} else
	X		panel_default_handle_event(item, event);
	X}
	X
	Xvoid
	Xprevious_menu_event(item, event)
	XPanel_item item;
	XEvent *event;
	X{
	X	Menu_item an_item;
	X	int value;
	X
	X	if (event_id(event) == MS_RIGHT && event_is_down(event)) {
	X		i = 0;
	X		while (++i < mainsw_state) {
	X			an_item = menu_get(previous_menu, MENU_NTH_ITEM, i);
	X			menu_set(an_item, MENU_INACTIVE, TRUE, 0);
	X		}
	X		for (i=mainsw_state; i<=DISPLAYING_YEAR; i++) {
	X			an_item = menu_get(previous_menu, MENU_NTH_ITEM, i);
	X			menu_set(an_item, MENU_INACTIVE, FALSE, 0);
	X		}
	X		value = (int) menu_show(previous_menu, panel, event, 0);
	X		if (value == 0)
	X			return;	/* no selection made */
	X		value--;
	X		switch (mainsw_state) {
	X			case DISPLAYING_DAY:
	X				switch (value) {
	X					case 0:	/* day */
	X						yesterday();
	X						break;
	X					case 1: /* week */
	X						close_day();
	X						current.tm_mday -= 7;
	X						draw_day();
	X						break;
	X					case 2:	/* month */
	X						close_day();
	X						current.tm_mon--;
	X						/* make sure day ends up in proper month */
	X						if (current.tm_mday == monthlength(current.tm_mon+1))
	X							/* last day of month */
	X							current.tm_mday = monthlength((current.tm_mon+12)%12);
	X						else if (current.tm_mday > monthlength((current.tm_mon+12)%12))
	X							current.tm_mday = monthlength((current.tm_mon+12)%12);
	X						draw_day();
	X						break;
	X					case 3: /* year */
	X						close_day();
	X						current.tm_year--;
	X						draw_day();
	X						break;
	X				}
	X				break;
	X			case DISPLAYING_WEEK:
	X				switch (value) {
	X					case 1:	/* week */
	X						lastweek();
	X						break;
	X					case 2:	/* month */
	X						current.tm_mon--;
	X						draw_week();
	X						break;
	X					case 3:	/* year */
	X						current.tm_year--;
	X						draw_week();
	X						break;
	X				}
	X				break;
	X			case DISPLAYING_MONTH:
	X				switch (value) {
	X					case 2: /* month */
	X						lastmonth();
	X						break;
	X					case 3:	/* year */
	X						current.tm_year--;
	X						draw_month();
	X						break;
	X				}
	X				break;
	X			case DISPLAYING_YEAR:
	X				if (value == 3)
	X					lastyear();
	X				break;
	X		}
	X	} else {
	X		panel_default_handle_event(item, event);
	X	}
	X}
	X
	Xvoid
	Xprevious_menu_notify(item, event)
	XPanel_item item; 
	XEvent *event; 
	X{ 
	X	if (event_id(event) == MS_LEFT) {
	X		switch (mainsw_state) {
	X			case DISPLAYING_DAY:
	X				yesterday();
	X				break;
	X			case DISPLAYING_WEEK:
	X				lastweek();
	X				break;
	X			case DISPLAYING_MONTH:
	X				lastmonth();
	X				break;
	X			case DISPLAYING_YEAR:
	X				lastyear();
	X				break;
	X		}
	X	} else
	X		panel_default_handle_event(item, event);
	X}
	X
	X#ifndef NO_SUN_MOON
	Xvoid
	Xmoonbutton_notify(item, event) 
	XPanel_item item; 
	XEvent *event; 
	X{ 
	X	/*** DEBUG ***/
	X	if (event_id(event) != MS_LEFT)
	X		return;
	X
	X	if (event_id(event) == MS_LEFT) {
	X		/* display popup frame with moon data */
	X		moon_data_frame();
	X		panel_set(moonbutton_pi, PANEL_SHOW_ITEM, FALSE, 0);
	X	} else
	X		panel_default_handle_event(item, event);
	X}
	X
	Xvoid
	Xsunbutton_notify(item, event) 
	XPanel_item item; 
	XEvent *event; 
	X{ 
	X	if (event_id(event) == MS_LEFT) {
	X		/* display popup frame with moon data */
	X		sun_data_frame();
	X		panel_set(sunbutton_pi, PANEL_SHOW_ITEM, FALSE, 0);
	X	} else
	X		panel_default_handle_event(item, event);
	X}
	X#endif
	X
	XNotify_value
	Xmyframe_interposer(client, event, arg, type)
	XNotify_client client;
	XEvent *event;
	XNotify_arg arg;
	XNotify_event_type type;
	X{
	X	static int start_up = 1;
	X	int closed_initial, closed_current;
	X	Notify_value value;
	X	void sframe_done(), mframe_done();
	X
	X	/* get initial state */
	X	closed_initial = (int)window_get(frame, FRAME_CLOSED);
	X	/***** debug *****/
	X	/*
	X	fprintf(stderr,"interposer: event=%d, start_up=%d, closed_initial=%d, ", event_id(event), start_up, closed_initial);
	X	 */
	X	/* let the frame do its thing */
	X	value = notify_next_event_func(client, event, arg, type);
	X	/* get new state */
	X	closed_current = (int)window_get(frame, FRAME_CLOSED);
	X	/**** debug ****/
	X	/*
	X	fprintf(stderr,"event=%d, closed_current=%d\n", event_id(event), closed_current);
	X	*/
	X	if (start_up) {
	X		/* first time thru */
	X		start_up = 0;
	X		if (closed_initial)
	X			/* starting up iconic */
	X			olddate = current;
	X		else
	X			/* starting up open */
	X			if (mainsw_state == DISPLAYING_DAY)
	X				/* create future appt popup */
	X				draw_future_appts();
	X	} else if (closed_current != closed_initial) {
	X		/* it changed state - either opened or closed */
	X		if (closed_current) {
	X			/* frame just closed */
	X			close_frame();
	X		} else {
	X			/* frame just opened */
	X			/*
	X			 * redraw display in case the "today" changed
	X			 * and a different day needs to be highlighted
	X			 */
	X			switch (mainsw_state) {
	X				case DISPLAYING_DAY:
	X					if (day_is_open)
	X						close_day();
	X					current = olddate;
	X					draw_day1();
	X					/* create future popup next time thru */
	X					start_up = 1;
	X					break;
	X				case DISPLAYING_WEEK:
	X					draw_week();
	X					break;
	X				case DISPLAYING_MONTH:
	X					draw_month();
	X					break;
	X				case DISPLAYING_YEAR:
	X					draw_year();
	X					break;
	X			}
	X		}
	X	}
	X
	X	return(NOTIFY_DONE);
	X}
	X
	X/*
	X * notifier for "Done" button in the popup future appt frame
	X */
	Xvoid
	Xfdone_proc(item, event)
	XPanel_item item;
	XEvent *event;
	X{
	X	if (event_id(event) == MS_LEFT) {
	X		window_destroy(fframe);
	X		fframe = 0;
	X		show_future = 0;
	X	}
	X}
	X
	X/*
	X * notifier for "Keep" button in the popup future appt frame
	X */
	Xvoid
	Xfkeep_proc(item, event)
	XPanel_item item;
	XEvent *event;
	X{
	X	if (event_id(event) == MS_LEFT) {
	X		window_destroy(fframe);
	X		fframe = 0;
	X	}
	X}
	X
	X/*
	X * Notifier for future appts. We get here when the user
	X * selects one of the displayed messages. When this happens,
	X * the day display for the selected future appt is displayed.
	X */
	Xvoid
	Xfappt_notify(item, event)
	XPanel_item item;
	XEvent *event;
	X{
	X	int value;
	X
	X	if (event_id(event) != MS_LEFT)
	X		return;
	X	
	X	value = (int)panel_get(item, PANEL_CLIENT_DATA);
	X	/* set current date to match the selected appt */
	X	current.tm_year = future[value].year;
	X	current.tm_mon = future[value].month;
	X	current.tm_mday = future[value].day;
	X	fix_current_day();
	X
	X	/* draw new day page */
	X	draw_day();
	X}
	X
	X/*
	X * Notify routine for everyx panel item in the attributes
	X * popup window. In this routine, we only care about the state
	X * of the "Selected Week" choice, which determines which panel
	X * item is displayed.
	X */
	Xvoid
	Xeveryx_notify(item, event)
	XPanel_item item;
	XEvent *event;
	X{
	X	int value;
	X
	X	value = (int) panel_get_value(everyx_pi);
	X	if (value & 0x2) {
	X		panel_set(repeat_pi, PANEL_SHOW_ITEM, FALSE, 0);
	X		panel_set(whichwk_pi, PANEL_SHOW_ITEM, TRUE, 0);
	X	} else {
	X		panel_set(whichwk_pi, PANEL_SHOW_ITEM, FALSE, 0);
	X		panel_set(repeat_pi, PANEL_SHOW_ITEM, TRUE, 0);
	X	}
	X}
	X
	X/*
	X * Notify routine for the appointment attributes popup window.
	X * Since each panel item does not have its own notify routine,
	X * we check the current state of everything when the user
	X * selects the accept button and set the slot flags appropriately.
	X */
	Xvoid
	Xattr_accept(item, event)
	XPanel_item item;
	XEvent *event;
	X{
	X	int value, flag = 0, repeat = 0;
	X	int oflag;
	X	struct appt_entry *apt = slots[attr_bi].cur_appt;
	X
	X	if (event_id(event) != MS_LEFT)
	X		return;  /* ignore everything else */
	X	
	X	oflag = apt->flags;
	X
	X	/* get the everyx value (every day, week, month, year) */
	X	value = (int) panel_get_value(everyx_pi);
	X	/* value is bitmap of selected choices */
	X	if (value & 0x1)
	X		flag |= ALL_DAYS;
	X	else if (oflag & ALL_DAYS)
	X		apt->day = current.tm_mday;
	X	if (value & 0x2)
	X		flag |= Setday(current.tm_wday);
	X	else if (oflag & EVERY_SOMEDAY)
	X		apt->day = current.tm_mday;
	X	if (value & 0x4)
	X		flag |= ALL_MONTHS;
	X	else if (oflag & ALL_MONTHS)
	X		apt->month = current.tm_mon;
	X	if (value & 0x8)
	X		flag |= ALL_YEARS;
	X	else if (oflag & ALL_YEARS)
	X		apt->year = current.tm_year;
	X	
	X	if (value & 0x2) {
	X		/* repeat at week intervals selected by which week pi */
	X		value = (int) panel_get_value(whichwk_pi);
	X		if (value == 0)
	X			/* ALL selected or no selection */
	X			value = ALL_WEEKS;
	X		flag |= REPEAT;
	X		repeat = value;
	X	} else {
	X		/* get repeat interval */
	X		value = atoi((char *)panel_get_value(repeat_pi));
	X		if (value > 0) {
	X			flag |= REPEAT;
	X			repeat = value;
	X		}
	X	}
	X
	X	/* get lookahead value */
	X	value = atoi((char *)panel_get_value(remind_pi));
	X	if (value > 0) {
	X		if (apt->lookahead != value) {
	X			new_entry = 1;
	X			flag |= LOOKAHEAD;
	X			apt->lookahead = value;
	X		}
	X	}
	X
	X	if (oflag & A_NOTE) {
	X		flag |= A_NOTE;
	X		/* marked indicator */
	X		value = (int) panel_get_value(marked_pi);
	X		if (value == 1)
	X			flag |= MARKED;  /* don't show in month/yr display */
	X	}
	X	/* shouldn't really be in this routine if the appt
	X	 * was read only, however, this is still here for potential
	X	 * future use.
	X	 */
	X	if (oflag & READONLY)
	X		flag |= READONLY;
	X
	X	if (apt->repeat != repeat || oflag != flag)
	X		new_entry = 1;	/* something changed */
	X
	X	/* set the slot info */
	X	apt->repeat = repeat;
	X	apt->flags = flag;
	X
	X	window_return(0);
	X}
	X
	X/*
	X * abort the attribute setting process, leaving the current
	X * appointment unmodified.
	X */
	Xvoid
	Xattr_abort(item, event)
	XPanel_item item;
	XEvent *event;
	X{
	X	if (event_id(event) == MS_LEFT)
	X		window_return(0);
	X}
	X
	X/*
	X * Notify routine for the delete mode popup window.
	X * Since the panel item does not have its own notify routine,
	X * we check the current state when the user
	X * selects the done button and set the slot flags appropriately.
	X */
	Xvoid
	Xdel_done(item, event)
	XPanel_item item;
	XEvent *event;
	X{
	X	int value;
	X	struct appt_entry tmp;
	X
	X	if (event_id(event) != MS_LEFT)
	X		return;  /* ignore everything else */
	X	
	X	value = (int) panel_get_value(del_choice_pi);
	X	if (value == 0) {
	X		/* don't show it today */
	X		/* create duplicate entry with delete flag set */
	X		tmp = *slots[attr_bi].cur_appt;
	X		tmp.flags &= ~(ALL_YEARS|ALL_MONTHS|ALL_DAYS|EVERY_SOMEDAY|REPEAT);
	X		tmp.flags |= DELETED;
	X		tmp.year = current.tm_year;
	X		tmp.month = current.tm_mon;
	X		tmp.day = current.tm_mday;
	X		add_to_slot(attr_bi, &tmp, TRUE);
	X		/* in the case of "cut", modify the shelf appt */
	X		if ((int)panel_get(del_choice_pi, PANEL_CLIENT_DATA)) {
	X			shelf_appt.flags &= ~(ALL_YEARS|ALL_MONTHS|ALL_DAYS|EVERY_SOMEDAY|REPEAT);
	X			shelf_appt.year = current.tm_year;
	X			shelf_appt.month = current.tm_mon;
	X			shelf_appt.day = current.tm_mday;
	X		}
	X	} else {
	X		/* completely kill appt */
	X		cut_delete(attr_bi);
	X	}
	X	new_entry = 1;
	X
	X	window_return(0);
	X}
	X
	X#ifndef NO_SUN_MOON
	X/*
	X * notifier for "Done" button in the popup sun data frame
	X */
	Xvoid
	Xsdone_proc(item, event)
	XPanel_item item;
	XEvent *event;
	X{
	X	if (event_id(event) == MS_LEFT) {
	X		window_destroy(sframe);
	X		sframe = 0;
	X		panel_set(sunbutton_pi, PANEL_SHOW_ITEM, TRUE, 0);
	X	}
	X}
	X
	X/*
	X * notifier for "Done" button in the popup moon data frame
	X */
	Xvoid
	Xmdone_proc(item, event)
	XPanel_item item;
	XEvent *event;
	X{
	X	if (event_id(event) == MS_LEFT) {
	X		window_destroy(mframe);
	X		mframe = 0;
	X		panel_set(moonbutton_pi, PANEL_SHOW_ITEM, TRUE, 0);
	X	}
	X}
	X
	X/* "done" from subframe menu */
	Xvoid
	Xsframe_done(frame)
	XFrame frame;
	X{
	X	window_destroy(sframe);
	X	sframe = 0;
	X	panel_set(sunbutton_pi, PANEL_SHOW_ITEM, TRUE, 0);
	X}
	X
	X/* "done" from subframe menu */
	Xvoid
	Xmframe_done(frame)
	XFrame frame;
	X{
	X	window_destroy(mframe);
	X	mframe = 0;
	X	panel_set(moonbutton_pi, PANEL_SHOW_ITEM, TRUE, 0);
	X}
	X#endif	/* NO_SUN_MOON */
	X
	X/*
	X * notifier for file button in main control panel
	X */
	Xvoid
	Xfilebutton_notify(item, event)
	XPanel_item item;
	XEvent *event;
	X{
	X	if (event_id(event) == MS_LEFT) {
	X		panel_set_value(filename_pi, apts_pathname);
	X		panel_set_value(file_ro_pi, (read_only ? 0 : 1));
	X		window_set(fileframe, WIN_SHOW, TRUE, 0);
	X	} else
	X		panel_default_handle_event(item, event);
	X}
	X
	X/*
	X * notifier for "Done" button in the popup file frame
	X */
	Xvoid
	Xfile_done(item, event)
	XPanel_item item;
	XEvent *event;
	X{
	X	if (event_id(event) == MS_LEFT)
	X		window_set(fileframe, WIN_SHOW, FALSE, 0);
	X}
	X
	X/*
	X * notifier for "Accept" button in the popup file frame
	X */
	Xvoid
	Xfile_accept(item, event)
	XPanel_item item;
	XEvent *event;
	X{
	X	char save_name[160];
	X	int save_ro;
	X
	X	if (event_id(event) == MS_LEFT) {
	X		/* cleanup existing appts file and open new one */
	X		strcpy(save_name, apts_pathname);
	X		save_ro = read_only;
	X		cleanup();
	X		othername = (char *)panel_get_value(filename_pi);
	X		otherfile = 1;
	X		read_only = ((int)panel_get_value(file_ro_pi) == 0 ? 1 : 0);
	X		if (do_files(TRUE)) {
	X			/* error in opening new file - restore old */
	X			othername = save_name;
	X			read_only = save_ro;
	X			if (do_files(TRUE))
	X				/* can't restore original */
	X				err_rpt("can't restore appts file", FATAL);
	X		} else {
	X			switch(mainsw_state) {
	X				case DISPLAYING_DAY:
	X					draw_day();
	X					break;
	X				case DISPLAYING_WEEK:
	X					draw_week();
	X					break;
	X				case DISPLAYING_MONTH:
	X					draw_month();
	X					break;
	X				case DISPLAYING_YEAR:
	X					draw_year();
	X					break;
	X			}
	X		}
	X	}
	X}
	X
	X/*
	X * notifier for "Reset" button in the popup file frame
	X */
	Xvoid
	Xfile_reset(item, event)
	XPanel_item item;
	XEvent *event;
	X{
	X	if (event_id(event) == MS_LEFT)
	X		panel_set_value(filename_pi, apts_pathname);
	X}
	X
	X/*
	X * notifier for "Save" button in the popup file frame
	X */
	Xvoid
	Xfile_save(item, event)
	XPanel_item item;
	XEvent *event;
	X{
	X	if (event_id(event) == MS_LEFT) {
	X		othername = (char *)panel_get_value(filename_pi);
	X		if (!strcmp(othername, apts_pathname)) {
	X			/* no filename change */
	X			if (mainsw_state == DISPLAYING_DAY && day_is_open)
	X				close_day();
	X		}
	X	}
	X}
	X
	X/*
	X * notifier for "Original" button in the popup file frame
	X */
	Xvoid
	Xfile_orig(item, event)
	XPanel_item item;
	XEvent *event;
	X{
	X	if (event_id(event) == MS_LEFT) {
	X		panel_set_value(filename_pi, orig_apts_pathname);
	X		panel_set_value(file_ro_pi, (orig_ro ? 0 : 1));
	X	}
	X}
	X
	X/*
	X * "Done" from subframe menu of the file selection popup frame
	X */
	Xvoid
	Xfileframe_done(frame)
	XFrame frame;
	X{
	X	window_set(fileframe, WIN_SHOW, FALSE, 0);
	X}
	X
	X/*
	X * notifier for prompt frame "No" button
	X */
	Xvoid
	Xprompt_no_notify(item, event)
	XPanel_item item;
	XEvent *event;
	X{
	X	if (event_id(event) == MS_LEFT)
	X		window_return(1);
	X}
	X
	X/*
	X * notifier for prompt frame "Yes" or "Ok" button
	X */
	Xvoid
	Xprompt_yes_notify(item, event)
	XPanel_item item;
	XEvent *event;
	X{
	X	if (event_id(event) == MS_LEFT)
	X		window_return(0);
	X}
	X
	X#ifndef NO_PRINTER
	X/*
	X * notifier for "Print" button in main control panel
	X */
	Xvoid
	Xprintbutton_notify(item, event)
	XPanel_item item;
	XEvent *event;
	X{
	X	int prt_fmt;
	X
	X	if (event_id(event) == MS_LEFT) {
	X#ifdef RASTER_ONLY
	X		/* default to printing a raster file */
	X		print_calendar(PR_RASTER);
	X#else
	X		/* default to printing a postscript file */
	X		print_calendar(PR_POSTSCRIPT);
	X#endif
	X	} else if (event_id(event) == MS_RIGHT) {
	X		/* print selected format */
	X		if ((prt_fmt = (int) panel_get(item, PANEL_CLIENT_DATA)) <= 2)
	X			print_calendar(prt_fmt);
	X	} else
	X		panel_default_handle_event(item, event);
	X}
	X
	Xvoid
	Xprint_menu_event(item, event)
	XPanel_item item;
	XEvent *event;
	X{
	X	int value;
	X#ifdef RASTER_ONLY
	X	Menu_item an_item;
	X#endif
	X
	X	if (event_id(event) == MS_RIGHT && event_is_down(event)) {
	X#ifdef RASTER_ONLY
	X		an_item = menu_get(print_menu, MENU_NTH_ITEM, PR_POSTSCRIPT);
	X		menu_set(an_item, MENU_INACTIVE, TRUE, 0);
	X#endif
	X		value = (int) menu_show(print_menu, panel, event, 0);
	X		if (value > 0) {
	X			panel_set(item, PANEL_CLIENT_DATA, value, 0);
	X			if (value == 3) {
	X				/* change printer */
	X				panel_set_value(prcmd_pi, printer);
	X				window_set(prframe, WIN_SHOW, TRUE, 0);
	X			} else {
	X				panel_begin_preview(item, event);
	X				panel_accept_preview(item, event);
	X			}
	X		}
	X	} else
	X		panel_default_handle_event(item, event);
	X}
	X
	Xvoid
	Xprdone_proc(item, event)
	XPanel_item item;
	XEvent *event;
	X{
	X	char *newstr;
	X	int status = 0;
	X
	X	if (event_id(event) == MS_LEFT) {
	X		newstr = (char *) panel_get_value(prcmd_pi);
	X		window_set(prframe, WIN_SHOW, FALSE, 0);
	X		if (strcmp(printer, newstr)) {
	X			/* the string changed */
	X			strcpy(printer, newstr);
	X			/******
	X			 * writing to the defaults file doesn't work.
	X			 *
	X			 * create_prompt_frame("Printer changed - overwrite .defaults entry?", TRUE);
	X			 * if (!window_loop(prompt_frame))
	X			 * 	defaults_set_string("/CalenTool/Printer", printer, &status);
	X			 *****/
	X		}
	X	}
	X}
	X
	Xvoid
	Xprframe_done(frame)
	XFrame frame;
	X{
	X	/* mark as no change */
	X	window_set(prframe, WIN_SHOW, FALSE, 0);
	X}
	X#endif	/* NO_PRINTER */
SHAR_EOF
if test 30523 -ne "`wc -c < 'notify.c'`"
then
	echo shar: error transmitting "'notify.c'" '(should have been 30523 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'paint.h'" '(2024 characters)'
if test -f 'paint.h'
then
	echo shar: will not over-write existing file "'paint.h'"
else
sed 's/^	X//' << \SHAR_EOF > 'paint.h'
	X/*
	X * $Header: paint.h,v 2.1 89/05/09 14:25:24 billr Exp $
	X */
	X/*
	X * paint.h
	X *
	X * Author: Philip Heller, Sun Microsystems. Inc. <terrapin!heller@sun.com>
	X *
	X * Original source Copyright (C) 1987, Sun Microsystems, Inc.
	X *	All Rights Reserved
	X * Permission is hereby granted to use and modify this program in source
	X * or binary form as long as it is not sold for profit and this copyright
	X * notice remains intact.
	X *
	X *
	X * Changes/additions by: Bill Randle, Tektronix, Inc. <billr@saab.CNA.TEK.COM>
	X *
	X * Changes and additions Copyright (C) 1988, 1989 Tektronix, Inc.
	X *	All Rights Reserved
	X * Permission is hereby granted to use and modify the modifications in source
	X * or binary form as long as they are not sold for profit and this copyright
	X * notice remains intact.
	X */
	X
	X#include <suntool/panel.h>
	X
	Xextern Pixfont *font, *bigfont;
	Xextern Canvas canvas;
	Xextern Pixwin *main_pixwin;
	Xextern struct tm current, today, First, Last;
	Xextern struct dayslot slots[];
	Xextern Pixrect *timeslot_pr, *daybox_pr, *weekarrow_pr,  *weekslot_pr;
	Xextern Pixrect *weekarrowshaft_pr, *weekarrowhead_pr;
	Xextern Pixrect *triangle_pr;
	Xextern Pixrect *ydaybox_pr, *ymonthbox_pr;
	Xextern Pixrect *timeslot_td_pr, *daybox_td_pr, *weekslot_td_pr, *ydaybox_td_pr;
	Xextern Pixrect *morebutton;
	Xextern struct weekrect week_boxes[];
	Xextern int x_coord, y_coord, startx, starty;
	Xextern int mainsw_state;
	Xextern int dayslot_width, nr_weekdays, max_strlen, n_tslots;
	Xextern int dayslot_height, weekslot_height, weekslot_width;
	Xextern int ybox_height, ybox_width;
	Xextern struct rect_limits boxlims[];
	Xextern struct rect_limits mboxlims[];
	Xextern struct week_arrow week_arrows[];
	Xextern char apts_pathname[], tmpapts_pathname[];
	Xextern int read_only, day_is_open, version2;
	Xextern char *progname;
	Xextern Frame fframe;
	Xextern char *daynames[], *monthnames[];
	X#ifndef NO_HOLIDAYS
	Xextern int holiday_a, holiday_c, holiday_i, holiday_j, holiday_s;
	X
	Xextern int a_dates(), c_dates(), i_dates(), j_dates(), s_dates();
	X#endif
	Xextern char *strcpy(), *strncpy();
	X
SHAR_EOF
if test 2024 -ne "`wc -c < 'paint.h'`"
then
	echo shar: error transmitting "'paint.h'" '(should have been 2024 characters)'
fi
fi # end of overwriting check
#	End of shell archive
exit 0