home *** CD-ROM | disk | FTP | other *** search
- /*
- * $Header: notify.c,v 2.4 91/03/27 16:46:01 billr Exp $
- */
- /*
- * notify.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.
- */
- /**********************************************************
- * *
- * These are the notify routines which are invoked *
- * by events in the control panel subwindow,and the *
- * various popup window panels. *
- * *
- **********************************************************/
-
-
-
- #include <stdio.h>
- #include <suntool/sunview.h>
- #include <suntool/canvas.h>
- #include <suntool/panel.h>
- #include <suntool/menu.h>
- #include "ct.h"
-
- extern int monday_first;
- extern int mainsw_state, nr_weekdays, day_is_open;
- extern int dayslot_width, nr_weekdays;
- extern struct tm today, current;
- extern Cursor month_cursor, week_cursor, day_cursor, year_cursor;
- extern Pixfont *font;
- extern Frame frame;
- extern Panel panel;
- extern Canvas canvas;
- extern Pixwin *main_pixwin;
- extern Menu next_menu, previous_menu, year_menu, month_menu;
- extern Menu day_menu, week_menu, current_menu;
- extern Menu done_menu;
- extern Frame fframe;
- extern Panel_item repeat_pi, remind_pi, daysel_pi;
- extern Panel_item everyx_pi, whichwk_pi, marked_pi;
- extern Panel_item del_choice_pi, setdate_pi;
- extern Panel_item runl_pi, advw_pi;
- #ifndef NO_SUN_MOON
- extern Frame mframe, sframe;
- extern Panel_item moonbutton_pi, sunbutton_pi;
- #endif
- extern Frame fileframe;
- extern Panel_item filename_pi, file_ro_pi;
- #ifndef NO_PRINTER
- extern Panel_item prcmd_pi, prfile_pi;
- extern int print_to_file;
- extern Frame prframe;
- extern Menu print_menu;
- #endif
- extern Frame prompt_frame, date_frame;
- extern struct appt_entry future[];
- extern struct dayslot *slots;
- extern int attr_bi; /* index into currently active day slot */
- extern int new_entry;
- extern struct tm olddate;
- extern int otherfile, read_only;
- extern char *othername, apts_pathname[], orig_apts_pathname[];
- extern int orig_ro;
- extern char printer[];
- extern int show_future;
- extern int show_time;
- extern int update_interval;
- extern struct appt_entry shelf_appt;
- extern int day_first;
- extern void close_frame();
- extern Notify_value leave();
-
- int i;
-
-
- void
- donebutton_notify(item, event)
- Panel_item item;
- Event *event;
- {
- if (event_id(event) == MS_LEFT) {
- /* close to icon */
- close_frame();
- } else
- panel_default_handle_event(item, event);
- }
-
- void
- done_menu_event(item, event)
- Panel_item item;
- Event *event;
- {
- int value;
-
- if (event_id(event) == MS_RIGHT && event_is_down(event)) {
- value = (int) menu_show(done_menu, panel, event, 0);
- if (value == 1)
- /* close frame */
- close_frame();
- else if (value == 2)
- /* quit tool */
- (void)leave((Notify_client)0, 0, (Notify_signal_mode)0);
- } else
- panel_default_handle_event(item, event);
- }
-
- void
- weekbutton_notify(item, event)
- Panel_item item;
- Event *event;
- {
- if (event_id(event) == MS_LEFT) {
- switch (mainsw_state) {
- case DISPLAYING_DAY:
- close_day();
- break;
- case DISPLAYING_WEEK:
- return;
- case DISPLAYING_MONTH:
- /* first week in month */
- current.tm_mday = 1;
- first_wkday();
- break;
- case DISPLAYING_YEAR:
- /* first week in year */
- current.tm_mday = 1;
- current.tm_mon = JAN;
- first_wkday();
- break;
- }
- mainsw_state = DISPLAYING_WEEK;
- draw_week();
- window_set(canvas, WIN_CURSOR, week_cursor, 0);
- } else
- panel_default_handle_event(item, event);
- }
-
-
- void
- week_menu_event(item, event)
- Panel_item item;
- Event *event;
- {
- int value, i;
- Menu_item an_item;
-
- if (event_id(event) == MS_RIGHT && event_is_down(event)) {
- if (mainsw_state > DISPLAYING_MONTH) {
- /* make all entries inactive */
- for (i=1; i<=6; i++) {
- an_item = menu_get(week_menu, MENU_NTH_ITEM, i);
- menu_set(an_item, MENU_INACTIVE, TRUE, 0);
- }
- } else {
- /* make all entries active */
- for (i=1; i<=6; i++) {
- an_item = menu_get(week_menu, MENU_NTH_ITEM, i);
- menu_set(an_item, MENU_INACTIVE, FALSE, 0);
- }
- }
- value = (int) menu_show(week_menu, panel, event, 0);
- if (value > 0) {
- current.tm_mday = (value - 1) * 7 + 1;
- if (current.tm_mday > monthlength(current.tm_mon))
- current.tm_mday = monthlength(current.tm_mon);
- if (mainsw_state == DISPLAYING_DAY)
- close_day();
- if (mainsw_state != DISPLAYING_WEEK) {
- mainsw_state = DISPLAYING_WEEK;
- window_set(canvas, WIN_CURSOR, week_cursor, 0);
- }
- draw_week();
- }
- } else
- panel_default_handle_event(item, event);
- }
-
- lastmonth()
- {
-
- current.tm_mon -= 1;
- current.tm_mday = 1;
- draw_month();
- }
-
-
- nextmonth()
- {
- current.tm_mon += 1;
- current.tm_mday = 1;
- draw_month();
- }
-
-
- void
- monthmenu_notify(item, event)
- Panel_item item;
- Event *event;
- {
- int i, j, new_day;
-
- if (event_id(event) == MS_LEFT) {
- if (mainsw_state == DISPLAYING_YEAR)
- /* go to first month of year */
- current.tm_mon = JAN;
- current.tm_mday = 1;
- if (mainsw_state == DISPLAYING_DAY)
- close_day();
- if (mainsw_state != DISPLAYING_MONTH) {
- mainsw_state = DISPLAYING_MONTH;
- window_set(canvas, WIN_CURSOR, month_cursor, 0);
- }
- draw_month();
- } else
- panel_default_handle_event(item, event);
- }
-
- void
- month_menu_event(item, event)
- Panel_item item;
- Event *event;
- {
- int value;
-
- if (event_id(event) == MS_RIGHT && event_is_down(event)) {
- value = (int) menu_show(month_menu, panel, event, 0);
- if (value > 0) {
- current.tm_mday = 1;
- current.tm_mon = value - 1;
- if (mainsw_state == DISPLAYING_DAY)
- close_day();
- if (mainsw_state != DISPLAYING_MONTH) {
- mainsw_state = DISPLAYING_MONTH;
- window_set(canvas, WIN_CURSOR, month_cursor, 0);
- }
- draw_month();
- }
- } else
- panel_default_handle_event(item, event);
- }
-
-
- lastyear()
- {
- current.tm_mday = 1;
- current.tm_mon = JAN;
- current.tm_year -= 1;
- draw_year();
- }
-
- nextyear()
- {
- current.tm_mday = 1;
- current.tm_mon = JAN;
- current.tm_year += 1;
- draw_year();
- }
-
- void
- yearmenu_notify(item, event)
- Panel_item item;
- Event *event;
- {
- int old_state;
-
- if (event_id(event) == MS_LEFT) {
- if (mainsw_state == DISPLAYING_DAY)
- close_day();
- old_state = mainsw_state;
- mainsw_state = DISPLAYING_YEAR;
- draw_year();
- if (old_state != DISPLAYING_YEAR)
- window_set(canvas, WIN_CURSOR, year_cursor, 0);
- } else
- panel_default_handle_event(item, event);
- }
-
- void
- year_menu_event(item, event)
- Panel_item item;
- Event *event;
- {
- int value, old_state;
-
- if (event_id(event) == MS_RIGHT && event_is_down(event)) {
- value = (int) menu_show(year_menu, panel, event, 0);
- if (value > 0) {
- current.tm_year = START_YEAR + value - 1;
- if (mainsw_state == DISPLAYING_DAY)
- close_day();
- old_state = mainsw_state;
- mainsw_state = DISPLAYING_YEAR;
- draw_year();
- if (old_state != DISPLAYING_YEAR)
- window_set(canvas, WIN_CURSOR, year_cursor, 0);
- }
- } else
- panel_default_handle_event(item, event);
- }
-
-
- lastweek()
- {
- if (mainsw_state == DISPLAYING_DAY) {
- close_day();
- current.tm_mday -= 7;
- draw_day();
- } else if (mainsw_state == DISPLAYING_WEEK) {
- current.tm_mday -= 7;
- draw_week();
- }
- }
-
-
- nextweek()
- {
- if (mainsw_state == DISPLAYING_DAY) {
- close_day();
- current.tm_mday += 7;
- draw_day();
- } else if (mainsw_state == DISPLAYING_WEEK) {
- current.tm_mday += 7;
- draw_week();
- }
- }
-
-
-
- yesterday()
- {
- if (mainsw_state != DISPLAYING_DAY)
- return(0);
- close_day();
- current.tm_mday--;
- draw_day();
- return(1);
- }
-
-
- void
- todaybutton_notify(item, event)
- Panel_item item;
- Event *event;
- {
- if (event_id(event) == MS_LEFT) {
- if (mainsw_state == DISPLAYING_DAY)
- close_day();
- else {
- mainsw_state = DISPLAYING_DAY;
- window_set(canvas, WIN_CURSOR, day_cursor, 0);
- }
- get_today();
- current = today;
- draw_day();
- } else
- panel_default_handle_event(item, event);
- }
-
-
-
- tomorrow()
- {
- if (mainsw_state != DISPLAYING_DAY)
- return(0);
- close_day();
- current.tm_mday++;
- draw_day();
- return(1);
- }
-
-
- void
- currentbutton_notify(item, event)
- Panel_item item;
- Event *event;
- {
- if (event_id(event) == MS_LEFT) {
- if (mainsw_state == DISPLAYING_DAY)
- close_day();
- get_today();
- current = today;
- switch (mainsw_state) {
- case DISPLAYING_DAY:
- draw_day();
- break;
- case DISPLAYING_WEEK:
- draw_week();
- break;
- case DISPLAYING_MONTH:
- draw_month();
- break;
- case DISPLAYING_YEAR:
- draw_year();
- break;
- }
- } else
- panel_default_handle_event(item, event);
- }
-
- void
- current_menu_event(item, event)
- Panel_item item;
- Event *event;
- {
- Menu_item an_item;
- char date[9];
- int value, rtn;
- struct tm Save;
-
- if (event_id(event) == MS_RIGHT && event_is_down(event)) {
- value = (int) menu_show(current_menu, panel, event, 0);
- if (value == 0)
- return; /* no selection made */
- if (mainsw_state == DISPLAYING_DAY)
- close_day();
- get_today();
- Save = current;
- current = today;
- switch (value) {
- case 1: /* current day */
- mainsw_state = DISPLAYING_DAY;
- window_set(canvas, WIN_CURSOR, day_cursor, 0);
- draw_day();
- break;
-
- case 2: /* current week */
- mainsw_state = DISPLAYING_WEEK;
- window_set(canvas, WIN_CURSOR, week_cursor, 0);
- draw_week();
- break;
-
- case 3: /* current month */
- mainsw_state = DISPLAYING_MONTH;
- window_set(canvas, WIN_CURSOR, month_cursor, 0);
- draw_month();
- break;
-
- case 4: /* current year */
- mainsw_state = DISPLAYING_YEAR;
- window_set(canvas, WIN_CURSOR, year_cursor, 0);
- draw_year();
- break;
-
- case 5: /* change date */
- if (day_first)
- sprintf(date, "%d/%d/%02d", Save.tm_mday, Save.tm_mon+1, Save.tm_year);
- else
- sprintf(date, "%d/%d/%02d", Save.tm_mon+1, Save.tm_mday, Save.tm_year);
- panel_set_value(setdate_pi, date);
- do {
- window_loop(date_frame);
- /* change "current" date to reflect entry */
- rtn = parse_date((char *)panel_get_value(setdate_pi), FALSE);
- } while (rtn);
- mainsw_state = DISPLAYING_DAY;
- window_set(canvas, WIN_CURSOR, day_cursor, 0);
- draw_day();
- break;
- }
- } else
- panel_default_handle_event(item, event);
- }
-
- /*
- * notifier for set date frame "Done" button
- */
- void
- dtdone_proc(item, event)
- Panel_item item;
- Event *event;
- {
- if (event_id(event) == MS_LEFT)
- window_return(0);
- }
-
- /* "done" from subframe menu of change date frame */
- void
- dtframe_done(frame)
- Frame frame;
- {
- window_set(date_frame, WIN_SHOW, FALSE, 0);
- }
-
- void
- daybutton_notify(item, event)
- Panel_item item;
- Event *event;
- {
- if (event_id(event) == MS_LEFT) {
- switch (mainsw_state) {
- case DISPLAYING_DAY:
- /* no change */
- return;
- case DISPLAYING_WEEK:
- /* pick first day in week */
- while (current.tm_wday != SUN) {
- current.tm_mday--;
- current.tm_wday--;
- }
- if (nr_weekdays < 7)
- /* start with MON */
- current.tm_mday++;
- break;
- case DISPLAYING_MONTH:
- /* pick first day in month */
- current.tm_mday = 1;
- first_wkday();
- break;
- case DISPLAYING_YEAR:
- /* pick first day in year */
- current.tm_mon = JAN;
- current.tm_mday = 1;
- first_wkday();
- break;
- }
- mainsw_state = DISPLAYING_DAY;
- draw_day();
- window_set(canvas, WIN_CURSOR, day_cursor, 0);
- } else
- panel_default_handle_event(item, event);
- }
-
- void
- day_menu_event(item, event)
- Panel_item item;
- Event *event;
- {
- int value, i;
- Menu_item an_item;
-
- if (event_id(event) == MS_RIGHT && event_is_down(event)) {
- if (mainsw_state > DISPLAYING_WEEK) {
- /* make all entries inactive */
- for (i=1; i<=7; i++) {
- an_item = menu_get(day_menu, MENU_NTH_ITEM, i);
- menu_set(an_item, MENU_INACTIVE, TRUE, 0);
- }
- } else {
- /* make all entries active */
- for (i=1; i<=7; i++) {
- an_item = menu_get(day_menu, MENU_NTH_ITEM, i);
- menu_set(an_item, MENU_INACTIVE, FALSE, 0);
- }
- }
- value = (int) menu_show(day_menu, panel, event, 0);
- if (value > 0) {
- /* find selected day in this week */
- if (monday_first) {
- ++value;
- if (value == 7) value = 0;
- }
- if (--value > current.tm_wday)
- current.tm_mday += value - current.tm_wday;
- else
- current.tm_mday -= current.tm_wday - value;
- mainsw_state = DISPLAYING_DAY;
- draw_day();
- window_set(canvas, WIN_CURSOR, day_cursor, 0);
- }
- } else
- panel_default_handle_event(item, event);
- }
-
- first_wkday()
- {
- /*
- * Set day to first displayable day of the week selected.
- * If we have a 7-day week display, then it will always
- * be the first day of the month. If we have a 5 or 6 day
- * display, the first day may need to be adjusted to the
- * following monday.
- */
- if (nr_weekdays == 7)
- /* it's ok as is */
- return;
- fix_current_day(); /* update wkday, etc. */
- if (current.tm_wday == SUN)
- current.tm_mday++;
- else if (current.tm_wday > nr_weekdays)
- current.tm_mday += 7 - current.tm_wday + 1;
- }
-
- void
- next_menu_event(item, event)
- Panel_item item;
- Event *event;
- {
- Menu_item an_item;
- int value;
-
- if (event_id(event) == MS_RIGHT && event_is_down(event)) {
- i = 0;
- while (++i < mainsw_state) {
- an_item = menu_get(next_menu, MENU_NTH_ITEM, i);
- menu_set(an_item, MENU_INACTIVE, TRUE, 0);
- }
- for (i=mainsw_state; i<=DISPLAYING_YEAR; i++) {
- an_item = menu_get(next_menu, MENU_NTH_ITEM, i);
- menu_set(an_item, MENU_INACTIVE, FALSE, 0);
- }
- value = (int) menu_show(next_menu, panel, event, 0);
- if (value == 0)
- return; /* no selection made */
- value--;
- switch (mainsw_state) {
- case DISPLAYING_DAY:
- switch (value) {
- case 0: /* day */
- tomorrow();
- break;
- case 1: /* week */
- close_day();
- current.tm_mday += 7;
- draw_day();
- break;
- case 2: /* month */
- close_day();
- current.tm_mon++;
- /* make sure day ends up in proper month */
- if (current.tm_mday == monthlength(current.tm_mon-1))
- /* last day of month */
- current.tm_mday = monthlength(current.tm_mon%12);
- else if (current.tm_mday > monthlength(current.tm_mon%12))
- current.tm_mday = monthlength(current.tm_mon%12);
- draw_day();
- break;
- case 3: /* year */
- close_day();
- current.tm_year++;
- draw_day();
- break;
- }
- break;
- case DISPLAYING_WEEK:
- switch (value) {
- case 1: /* week */
- nextweek();
- break;
- case 2: /* month */
- current.tm_mon++;
- draw_week();
- break;
- case 3: /* year */
- current.tm_year++;
- draw_week();
- break;
- }
- break;
- case DISPLAYING_MONTH:
- switch (value) {
- case 2: /* month */
- nextmonth();
- break;
- case 3: /* year */
- current.tm_year++;
- draw_month();
- break;
- }
- break;
- case DISPLAYING_YEAR:
- if (value == 3)
- nextyear();
- break;
- }
- } else
- panel_default_handle_event(item, event);
- }
-
- void
- nextbutton_notify(item, event)
- Panel_item item;
- Event *event;
- {
- if (event_id(event) == MS_LEFT) {
- switch (mainsw_state) {
- case DISPLAYING_DAY:
- tomorrow();
- break;
- case DISPLAYING_WEEK:
- nextweek();
- break;
- case DISPLAYING_MONTH:
- nextmonth();
- break;
- case DISPLAYING_YEAR:
- nextyear();
- break;
- }
- } else
- panel_default_handle_event(item, event);
- }
-
- void
- previous_menu_event(item, event)
- Panel_item item;
- Event *event;
- {
- Menu_item an_item;
- int value;
-
- if (event_id(event) == MS_RIGHT && event_is_down(event)) {
- i = 0;
- while (++i < mainsw_state) {
- an_item = menu_get(previous_menu, MENU_NTH_ITEM, i);
- menu_set(an_item, MENU_INACTIVE, TRUE, 0);
- }
- for (i=mainsw_state; i<=DISPLAYING_YEAR; i++) {
- an_item = menu_get(previous_menu, MENU_NTH_ITEM, i);
- menu_set(an_item, MENU_INACTIVE, FALSE, 0);
- }
- value = (int) menu_show(previous_menu, panel, event, 0);
- if (value == 0)
- return; /* no selection made */
- value--;
- switch (mainsw_state) {
- case DISPLAYING_DAY:
- switch (value) {
- case 0: /* day */
- yesterday();
- break;
- case 1: /* week */
- close_day();
- current.tm_mday -= 7;
- draw_day();
- break;
- case 2: /* month */
- close_day();
- current.tm_mon--;
- /* make sure day ends up in proper month */
- if (current.tm_mday == monthlength(current.tm_mon+1))
- /* last day of month */
- current.tm_mday = monthlength((current.tm_mon+12)%12);
- else if (current.tm_mday > monthlength((current.tm_mon+12)%12))
- current.tm_mday = monthlength((current.tm_mon+12)%12);
- draw_day();
- break;
- case 3: /* year */
- close_day();
- current.tm_year--;
- draw_day();
- break;
- }
- break;
- case DISPLAYING_WEEK:
- switch (value) {
- case 1: /* week */
- lastweek();
- break;
- case 2: /* month */
- current.tm_mon--;
- draw_week();
- break;
- case 3: /* year */
- current.tm_year--;
- draw_week();
- break;
- }
- break;
- case DISPLAYING_MONTH:
- switch (value) {
- case 2: /* month */
- lastmonth();
- break;
- case 3: /* year */
- current.tm_year--;
- draw_month();
- break;
- }
- break;
- case DISPLAYING_YEAR:
- if (value == 3)
- lastyear();
- break;
- }
- } else {
- panel_default_handle_event(item, event);
- }
- }
-
- void
- previous_menu_notify(item, event)
- Panel_item item;
- Event *event;
- {
- if (event_id(event) == MS_LEFT) {
- switch (mainsw_state) {
- case DISPLAYING_DAY:
- yesterday();
- break;
- case DISPLAYING_WEEK:
- lastweek();
- break;
- case DISPLAYING_MONTH:
- lastmonth();
- break;
- case DISPLAYING_YEAR:
- lastyear();
- break;
- }
- } else
- panel_default_handle_event(item, event);
- }
-
- #ifndef NO_SUN_MOON
- void
- moonbutton_notify(item, event)
- Panel_item item;
- Event *event;
- {
- if (event_id(event) == MS_LEFT) {
- /* display popup frame with moon data */
- moon_data_frame();
- panel_set(moonbutton_pi, PANEL_SHOW_ITEM, FALSE, 0);
- } else
- panel_default_handle_event(item, event);
- }
-
- void
- sunbutton_notify(item, event)
- Panel_item item;
- Event *event;
- {
- if (event_id(event) == MS_LEFT) {
- /* display popup frame with moon data */
- sun_data_frame();
- panel_set(sunbutton_pi, PANEL_SHOW_ITEM, FALSE, 0);
- } else
- panel_default_handle_event(item, event);
- }
- #endif
-
- Notify_value
- myframe_interposer(client, event, arg, type)
- Notify_client client;
- Event *event;
- Notify_arg arg;
- Notify_event_type type;
- {
- static int start_up = 1;
- int closed_initial, closed_current;
- Notify_value value;
- void sframe_done(), mframe_done();
-
- /* get initial state */
- closed_initial = (int)window_get(frame, FRAME_CLOSED);
- /* let the frame do its thing */
- value = notify_next_event_func(client, event, arg, type);
- /* get new state */
- closed_current = (int)window_get(frame, FRAME_CLOSED);
- if (start_up) {
- /* first time thru */
- start_up = 0;
- if (closed_initial)
- /* starting up iconic */
- olddate = current;
- else
- /* starting up open */
- if (mainsw_state == DISPLAYING_DAY)
- /* create future appt popup */
- draw_future_appts();
- } else if (closed_current != closed_initial) {
- /* it changed state - either opened or closed */
- if (closed_current) {
- /* frame just closed */
- close_frame();
- } else {
- /* frame just opened */
- /*
- * redraw display in case the "today" changed
- * and a different day needs to be highlighted
- */
- if (day_is_open)
- close_day();
- current = olddate;
- switch (mainsw_state) {
- case DISPLAYING_DAY:
- draw_day1();
- /* create future popup next time thru */
- start_up = 1;
- break;
- case DISPLAYING_WEEK:
- draw_week();
- break;
- case DISPLAYING_MONTH:
- draw_month();
- break;
- case DISPLAYING_YEAR:
- draw_year();
- break;
- }
- }
- }
-
- return(NOTIFY_DONE);
- }
-
- /*
- * notifier for "Done" button in the popup future appt frame
- */
- void
- fdone_proc(item, event)
- Panel_item item;
- Event *event;
- {
- if (event_id(event) == MS_LEFT) {
- window_destroy(fframe);
- fframe = 0;
- show_future = 0;
- }
- }
-
- /*
- * notifier for "Keep" button in the popup future appt frame
- */
- void
- fkeep_proc(item, event)
- Panel_item item;
- Event *event;
- {
- if (event_id(event) == MS_LEFT) {
- window_destroy(fframe);
- fframe = 0;
- }
- }
-
- /*
- * Notifier for future appts. We get here when the user
- * selects one of the displayed messages. When this happens,
- * the day display for the selected future appt is displayed.
- */
- void
- fappt_notify(item, event)
- Panel_item item;
- Event *event;
- {
- int value;
-
- if (event_id(event) != MS_LEFT)
- return;
-
- value = (int)panel_get(item, PANEL_CLIENT_DATA);
- /* set current date to match the selected appt */
- current.tm_year = future[value].year;
- current.tm_mon = future[value].month;
- current.tm_mday = future[value].day;
- fix_current_day();
-
- /* draw new day page */
- draw_day();
- }
-
- /*
- * Notify routine for everyx panel item in the attributes
- * popup window. In this routine, we only care about the state
- * of the "Selected Week" choice, which determines which panel
- * item is displayed.
- */
- void
- everyx_notify(item, event)
- Panel_item item;
- Event *event;
- {
- int value;
-
- value = (int) panel_get_value(everyx_pi);
- if (value & 0x4) {
- if (value & 0x3) {
- /* not allowed for ALL_DAYS or EVERY_MON_FRI */
- value &= ~0x4;
- panel_set_value(everyx_pi, value);
- } else {
- panel_set(repeat_pi, PANEL_SHOW_ITEM, FALSE, 0);
- panel_set(whichwk_pi, PANEL_SHOW_ITEM, TRUE, 0);
- }
- } else {
- panel_set(whichwk_pi, PANEL_SHOW_ITEM, FALSE, 0);
- panel_set(repeat_pi, PANEL_SHOW_ITEM, TRUE, 0);
- }
- }
-
- /*
- * Notify routine for the appointment attributes popup window.
- * Since each panel item does not have its own notify routine,
- * we check the current state of everything when the user
- * selects the accept button and set the slot flags appropriately.
- */
- void
- attr_accept(item, event)
- Panel_item item;
- Event *event;
- {
- int value, flag = 0, repeat = 0;
- int oflag;
- struct appt_entry *apt = slots[attr_bi].cur_appt;
-
- if (event_id(event) != MS_LEFT)
- return; /* ignore everything else */
-
- oflag = apt->flags;
-
- /* get the everyx value (every day, week, month, year) */
- value = (int) panel_get_value(everyx_pi);
- /* value is bitmap of selected choices */
- /* EVERY_MON_FRI and ALL_DAYS are mutually exclusive */
- if (value & 0x1)
- flag |= EVERY_MON_FRI;
- else if (value & 0x2)
- flag |= ALL_DAYS;
- else if (oflag & (EVERY_MON_FRI|ALL_DAYS))
- apt->day = current.tm_mday;
- if (value & 0x4)
- flag |= Setday(current.tm_wday);
- else if (oflag & EVERY_SOMEDAY)
- apt->day = current.tm_mday;
- if (value & 0x8)
- flag |= ALL_MONTHS;
- else if (oflag & ALL_MONTHS)
- apt->month = current.tm_mon;
- if (value & 0x10)
- flag |= ALL_YEARS;
- else if (oflag & ALL_YEARS)
- apt->year = current.tm_year;
-
- if (value & 0x4) {
- /* repeat at week intervals selected by which week pi */
- value = (int) panel_get_value(whichwk_pi);
- if (value == 0 || value == 0x40)
- /* ALL selected or no selection */
- value = ALL_WEEKS;
- flag |= REPEAT;
- repeat = value;
- } else {
- /* get repeat interval */
- value = atoi((char *)panel_get_value(repeat_pi));
- if (value > 0) {
- flag |= REPEAT;
- repeat = value;
- }
- }
-
- /* get lookahead value */
- value = atoi((char *)panel_get_value(remind_pi));
- if (value > 0) {
- flag |= LOOKAHEAD;
- if (apt->lookahead != value) {
- new_entry = 1;
- apt->lookahead = value;
- }
- }
-
- /* get runlength value */
- value = atoi((char *)panel_get_value(runl_pi));
- if (value > 0) {
- flag |= RUN;
- if (apt->runlength != value) {
- new_entry = 1;
- apt->runlength = value;
- }
- }
-
- /* get advance warning value */
- value = atoi((char *)panel_get_value(advw_pi));
- if (apt->warn != value) {
- new_entry = 1;
- apt->warn = value;
- }
-
- if (oflag & A_NOTE) {
- flag |= A_NOTE;
- /* marked indicator */
- value = (int) panel_get_value(marked_pi);
- if (value == 1)
- flag |= MARKED; /* don't show in month/yr display */
- }
- /* shouldn't really be in this routine if the appt
- * was read only, however, this is still here for potential
- * future use.
- */
- if (oflag & READONLY)
- flag |= READONLY;
-
- if (apt->repeat != repeat || oflag != flag)
- new_entry = 1; /* something changed */
-
- /* set the slot info */
- apt->repeat = repeat;
- apt->flags = flag;
-
- window_return(0);
- }
-
- /*
- * abort the attribute setting process, leaving the current
- * appointment unmodified.
- */
- void
- attr_abort(item, event)
- Panel_item item;
- Event *event;
- {
- if (event_id(event) == MS_LEFT)
- window_return(0);
- }
-
- /*
- * Notify routine for the delete mode popup window.
- * Since the panel item does not have its own notify routine,
- * we check the current state when the user
- * selects the done button and set the slot flags appropriately.
- */
- void
- del_done(item, event)
- Panel_item item;
- Event *event;
- {
- int value;
- struct appt_entry tmp;
-
- if (event_id(event) != MS_LEFT)
- return; /* ignore everything else */
-
- value = (int) panel_get_value(del_choice_pi);
- if (value == 0) {
- /* don't show it today */
- /* create duplicate entry with delete flag set */
- tmp = *slots[attr_bi].cur_appt;
- tmp.flags &= ~(ALL_YEARS|ALL_MONTHS|ALL_DAYS|EVERY_SOMEDAY|REPEAT|EVERY_MON_FRI|RUN);
- tmp.flags |= DELETED;
- tmp.year = current.tm_year;
- tmp.month = current.tm_mon;
- tmp.day = current.tm_mday;
- add_to_slot(attr_bi, &tmp, TRUE);
- /* in the case of "cut", modify the shelf appt */
- if ((int)panel_get(del_choice_pi, PANEL_CLIENT_DATA)) {
- shelf_appt.flags &= ~(ALL_YEARS|ALL_MONTHS|ALL_DAYS|EVERY_SOMEDAY|REPEAT|EVERY_MON_FRI|RUN);
- shelf_appt.year = current.tm_year;
- shelf_appt.month = current.tm_mon;
- shelf_appt.day = current.tm_mday;
- }
- } else {
- /* completely kill appt */
- cut_delete(attr_bi);
- }
- new_entry = 1;
-
- window_return(0);
- }
-
- #ifndef NO_SUN_MOON
- /*
- * notifier for "Done" button in the popup sun data frame
- */
- void
- sdone_proc(item, event)
- Panel_item item;
- Event *event;
- {
- if (event_id(event) == MS_LEFT) {
- window_destroy(sframe);
- sframe = 0;
- panel_set(sunbutton_pi, PANEL_SHOW_ITEM, TRUE, 0);
- }
- }
-
- /*
- * notifier for "Done" button in the popup moon data frame
- */
- void
- mdone_proc(item, event)
- Panel_item item;
- Event *event;
- {
- if (event_id(event) == MS_LEFT) {
- window_destroy(mframe);
- mframe = 0;
- panel_set(moonbutton_pi, PANEL_SHOW_ITEM, TRUE, 0);
- }
- }
-
- /* "done" from subframe menu */
- void
- sframe_done(frame)
- Frame frame;
- {
- window_destroy(sframe);
- sframe = 0;
- panel_set(sunbutton_pi, PANEL_SHOW_ITEM, TRUE, 0);
- }
-
- /* "done" from subframe menu */
- void
- mframe_done(frame)
- Frame frame;
- {
- window_destroy(mframe);
- mframe = 0;
- panel_set(moonbutton_pi, PANEL_SHOW_ITEM, TRUE, 0);
- }
- #endif /* NO_SUN_MOON */
-
- /*
- * notifier for file button in main control panel
- */
- void
- filebutton_notify(item, event)
- Panel_item item;
- Event *event;
- {
- if (event_id(event) == MS_LEFT) {
- panel_set_value(filename_pi, apts_pathname);
- panel_set_value(file_ro_pi, (read_only ? 0 : 1));
- window_set(fileframe, WIN_SHOW, TRUE, 0);
- } else
- panel_default_handle_event(item, event);
- }
-
- /*
- * notifier for "Done" button in the popup file frame
- */
- void
- file_done(item, event)
- Panel_item item;
- Event *event;
- {
- if (event_id(event) == MS_LEFT)
- window_set(fileframe, WIN_SHOW, FALSE, 0);
- }
-
- /*
- * notifier for "Accept" button in the popup file frame
- */
- void
- file_accept(item, event)
- Panel_item item;
- Event *event;
- {
- char save_name[160];
- int save_ro;
- struct tm save_date;
-
- if (event_id(event) == MS_LEFT) {
- save_date = current;
- /* cleanup existing appts file and open new one */
- strcpy(save_name, apts_pathname);
- save_ro = read_only;
- cleanup();
- othername = (char *)panel_get_value(filename_pi);
- otherfile = 1;
- read_only = ((int)panel_get_value(file_ro_pi) == 0 ? 1 : 0);
- if (do_files(TRUE)) {
- /* error in opening new file - restore old */
- othername = save_name;
- read_only = save_ro;
- if (do_files(TRUE))
- /* can't restore original */
- err_rpt("can't restore appts file", FATAL);
- } else {
- /* read_only may have been changed by do_files() */
- panel_set_value(file_ro_pi, (read_only ? 0 : 1));
- current = save_date;
- switch(mainsw_state) {
- case DISPLAYING_DAY:
- draw_day();
- break;
- case DISPLAYING_WEEK:
- draw_week();
- break;
- case DISPLAYING_MONTH:
- draw_month();
- break;
- case DISPLAYING_YEAR:
- draw_year();
- break;
- }
- }
- }
- }
-
- /*
- * notifier for "Reset" button in the popup file frame
- */
- void
- file_reset(item, event)
- Panel_item item;
- Event *event;
- {
- if (event_id(event) == MS_LEFT)
- panel_set_value(filename_pi, apts_pathname);
- }
-
- /*
- * notifier for "Save" button in the popup file frame
- */
- void
- file_save(item, event)
- Panel_item item;
- Event *event;
- {
- if (event_id(event) == MS_LEFT) {
- othername = (char *)panel_get_value(filename_pi);
- if (!strcmp(othername, apts_pathname)) {
- /* no filename change */
- if (mainsw_state == DISPLAYING_DAY && day_is_open)
- close_day();
- }
- }
- }
-
- /*
- * notifier for "Original" button in the popup file frame
- */
- void
- file_orig(item, event)
- Panel_item item;
- Event *event;
- {
- if (event_id(event) == MS_LEFT) {
- panel_set_value(filename_pi, orig_apts_pathname);
- panel_set_value(file_ro_pi, (orig_ro ? 0 : 1));
- /* force an Accept button event */
- file_accept(item, event);
- }
- }
-
- /*
- * "Done" from subframe menu of the file selection popup frame
- */
- void
- fileframe_done(frame)
- Frame frame;
- {
- window_set(fileframe, WIN_SHOW, FALSE, 0);
- }
-
- /*
- * notifier for prompt frame "No" button
- */
- void
- prompt_no_notify(item, event)
- Panel_item item;
- Event *event;
- {
- if (event_id(event) == MS_LEFT)
- window_return(1);
- }
-
- /*
- * notifier for prompt frame "Yes" or "Ok" button
- */
- void
- prompt_yes_notify(item, event)
- Panel_item item;
- Event *event;
- {
- if (event_id(event) == MS_LEFT)
- window_return(0);
- }
-
- #ifndef NO_PRINTER
- /*
- * notifier for "Print" button in main control panel
- */
- void
- printbutton_notify(item, event)
- Panel_item item;
- Event *event;
- {
- int prt_fmt;
-
- if (event_id(event) == MS_LEFT) {
- #ifdef RASTER_ONLY
- /* default to printing a raster file */
- print_calendar(PR_RASTER);
- #else
- /* default to printing a postscript file */
- print_calendar(PR_POSTSCRIPT);
- #endif
- } else if (event_id(event) == MS_RIGHT) {
- /* print selected format */
- if ((prt_fmt = (int) panel_get(item, PANEL_CLIENT_DATA)) <= 2)
- print_calendar(prt_fmt);
- } else
- panel_default_handle_event(item, event);
- }
-
- void
- print_menu_event(item, event)
- Panel_item item;
- Event *event;
- {
- int value;
- #ifdef RASTER_ONLY
- Menu_item an_item;
- #endif
-
- if (event_id(event) == MS_RIGHT && event_is_down(event)) {
- #ifdef RASTER_ONLY
- an_item = menu_get(print_menu, MENU_NTH_ITEM, PR_POSTSCRIPT);
- menu_set(an_item, MENU_INACTIVE, TRUE, 0);
- #endif
- value = (int) menu_show(print_menu, panel, event, 0);
- if (value > 0) {
- panel_set(item, PANEL_CLIENT_DATA, value, 0);
- if (value == 3) {
- /* change printer */
- panel_set_value(prfile_pi, print_to_file);
- panel_set_value(prcmd_pi, printer);
- window_set(prframe, WIN_SHOW, TRUE, 0);
- } else {
- panel_begin_preview(item, event);
- panel_accept_preview(item, event);
- }
- }
- } else
- panel_default_handle_event(item, event);
- }
-
- void
- prdone_proc(item, event)
- Panel_item item;
- Event *event;
- {
- char *newstr;
- /**
- int status = 0;
- **/
-
- if (event_id(event) == MS_LEFT) {
- newstr = (char *) panel_get_value(prcmd_pi);
- print_to_file = (int) panel_get_value(prfile_pi);
- window_set(prframe, WIN_SHOW, FALSE, 0);
- if (strcmp(printer, newstr)) {
- /* the string changed */
- strcpy(printer, newstr);
- /******
- * writing to the defaults file doesn't work.
- *
- * create_prompt_frame("Printer changed - overwrite .defaults entry?", TRUE);
- * if (!window_loop(prompt_frame))
- * defaults_set_string("/CalenTool/Printer", printer, &status);
- *****/
- }
- }
- }
-
- void
- prframe_done(frame)
- Frame frame;
- {
- /* mark as no change */
- window_set(prframe, WIN_SHOW, FALSE, 0);
- }
- #endif /* NO_PRINTER */
-