home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / sun / volume1 / calentool / part06 / notify.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-05-27  |  29.8 KB  |  1,399 lines

  1. /*
  2.  * $Header: notify.c,v 2.1 89/05/09 14:23:13 billr Exp $
  3.  */
  4. /*
  5.  * notify.c
  6.  *
  7.  * Author: Philip Heller, Sun Microsystems. Inc. <terrapin!heller@sun.com>
  8.  *
  9.  * Original source Copyright (C) 1987, Sun Microsystems, Inc.
  10.  *    All Rights Reserved
  11.  * Permission is hereby granted to use and modify this program in source
  12.  * or binary form as long as it is not sold for profit and this copyright
  13.  * notice remains intact.
  14.  *
  15.  *
  16.  * Changes/additions by: Bill Randle, Tektronix, Inc. <billr@saab.CNA.TEK.COM>
  17.  *
  18.  * Changes and additions Copyright (C) 1988, 1989 Tektronix, Inc.
  19.  *    All Rights Reserved
  20.  * Permission is hereby granted to use and modify the modifications in source
  21.  * or binary form as long as they are not sold for profit and this copyright
  22.  * notice remains intact.
  23.  */
  24. /**********************************************************
  25.  *                              *
  26.  *     These are the notify routines which are invoked  *
  27.  * by events in the control panel subwindow,and the      *
  28.  * various popup window panels.                  *
  29.  *                              *
  30.  **********************************************************/
  31.  
  32.  
  33.  
  34. #include <stdio.h>
  35. #include <suntool/sunview.h>
  36. #include <suntool/canvas.h>
  37. #include <suntool/panel.h>
  38. #include <suntool/menu.h>
  39. #include "ct.h"
  40.  
  41. extern int mainsw_state, nr_weekdays, day_is_open;
  42. extern int dayslot_width, nr_weekdays;
  43. extern struct tm today, current;
  44. extern Cursor month_cursor, week_cursor, day_cursor, year_cursor;
  45. extern Pixfont *font;
  46. extern Frame frame;
  47. extern Panel panel;
  48. extern Canvas canvas;
  49. extern Pixwin *main_pixwin;
  50. extern Menu next_menu, previous_menu, year_menu, month_menu;
  51. extern Menu day_menu, week_menu, current_menu;
  52. extern Frame fframe;
  53. extern Panel_item repeat_pi, remind_pi, daysel_pi;
  54. extern Panel_item everyx_pi, whichwk_pi, marked_pi;
  55. extern Panel_item del_choice_pi, setdate_pi;
  56. #ifndef NO_SUN_MOON
  57. extern Frame mframe, sframe;
  58. extern Panel_item moonbutton_pi, sunbutton_pi;
  59. #endif
  60. extern Frame fileframe;
  61. extern Panel_item filename_pi, file_ro_pi;
  62. #ifndef NO_PRINTER
  63. extern Panel_item prcmd_pi;
  64. extern Frame prframe;
  65. extern Menu print_menu;
  66. #endif
  67. extern Frame prompt_frame, date_frame;
  68. extern struct appt_entry future[];
  69. extern struct dayslot slots[];
  70. extern int attr_bi;  /* index into currently active day slot */
  71. extern int new_entry;
  72. extern struct tm olddate;
  73. extern int otherfile, read_only;
  74. extern char *othername, apts_pathname[], orig_apts_pathname[];
  75. extern int orig_ro;
  76. extern char printer[];
  77. extern int show_future;
  78. extern int show_time;
  79. extern int update_interval;
  80. extern char todays_date[], timestr[];
  81. extern struct appt_entry shelf_appt;
  82.  
  83. int i;
  84.  
  85.  
  86. void
  87. weekbutton_notify(item, event)
  88. Panel_item item;
  89. Event *event;
  90. {
  91.     if (event_id(event) == MS_LEFT) {
  92.         switch (mainsw_state) {
  93.             case DISPLAYING_DAY:
  94.                 close_day();
  95.                 break;
  96.             case DISPLAYING_WEEK:
  97.                 return;
  98.             case DISPLAYING_MONTH:
  99.                 /* first week in month */
  100.                 current.tm_mday = 1;
  101.                 first_wkday();
  102.                 break;
  103.             case DISPLAYING_YEAR:
  104.                 /* first week in year */
  105.                 current.tm_mday = 1;
  106.                 current.tm_mon = JAN;
  107.                 first_wkday();
  108.                 break;
  109.         }
  110.         mainsw_state = DISPLAYING_WEEK;
  111.         draw_week();
  112.         window_set(canvas, WIN_CURSOR, week_cursor, 0);
  113.     } else
  114.         panel_default_handle_event(item, event);
  115. }
  116.  
  117.  
  118. void
  119. week_menu_event(item, event)
  120. Panel_item item;
  121. Event *event;
  122. {
  123.     int value, i;
  124.     Menu_item an_item;
  125.  
  126.     if (event_id(event) == MS_RIGHT && event_is_down(event)) {
  127.         if (mainsw_state > DISPLAYING_MONTH) {
  128.             /* make all entries inactive */
  129.             for (i=1; i<=6; i++) {
  130.                 an_item = menu_get(week_menu, MENU_NTH_ITEM, i);
  131.                 menu_set(an_item, MENU_INACTIVE, TRUE, 0);
  132.             }
  133.         } else {
  134.             /* make all entries active */
  135.             for (i=1; i<=6; i++) {
  136.                 an_item = menu_get(week_menu, MENU_NTH_ITEM, i);
  137.                 menu_set(an_item, MENU_INACTIVE, FALSE, 0);
  138.             }
  139.         }
  140.         value = (int) menu_show(week_menu, panel, event, 0);
  141.         if (value > 0) {
  142.             current.tm_mday = (value - 1) * 7 + 1;
  143.             if (current.tm_mday > monthlength(current.tm_mon))
  144.                 current.tm_mday = monthlength(current.tm_mon);
  145.             if (mainsw_state == DISPLAYING_DAY)
  146.                 close_day();
  147.             if (mainsw_state != DISPLAYING_WEEK) {
  148.                 mainsw_state = DISPLAYING_WEEK;
  149.                 window_set(canvas, WIN_CURSOR, week_cursor, 0);
  150.             }
  151.             draw_week();
  152.         }
  153.     } else
  154.         panel_default_handle_event(item, event);
  155. }
  156.  
  157. lastmonth()
  158. {
  159.  
  160.     current.tm_mon -= 1;
  161.     current.tm_mday = 1;
  162.     draw_month();
  163. }
  164.  
  165.  
  166. nextmonth()
  167.     current.tm_mon += 1;
  168.     current.tm_mday = 1;
  169.         draw_month();
  170.  
  171.  
  172. void
  173. monthmenu_notify(item, event)  
  174. Panel_item item;  
  175. Event *event;
  176. {  
  177.     int i, j, new_day;
  178.  
  179.     if (event_id(event) == MS_LEFT) {
  180.         if (mainsw_state == DISPLAYING_YEAR)
  181.             /* go to first month of year */
  182.             current.tm_mon = JAN;
  183.         current.tm_mday = 1;
  184.         if (mainsw_state == DISPLAYING_DAY)
  185.             close_day();
  186.         if (mainsw_state != DISPLAYING_MONTH) {
  187.             mainsw_state = DISPLAYING_MONTH;
  188.             window_set(canvas, WIN_CURSOR, month_cursor, 0);
  189.         }
  190.         draw_month();
  191.     } else
  192.         panel_default_handle_event(item, event);
  193. }
  194.  
  195. void
  196. month_menu_event(item, event)
  197. Panel_item item;
  198. Event *event;
  199. {
  200.     int value;
  201.  
  202.     if (event_id(event) == MS_RIGHT && event_is_down(event)) {
  203.         value = (int) menu_show(month_menu, panel, event, 0);
  204.         if (value > 0) {
  205.             current.tm_mday = 1;
  206.             current.tm_mon = value - 1;
  207.             if (mainsw_state == DISPLAYING_DAY)
  208.                 close_day();
  209.             if (mainsw_state != DISPLAYING_MONTH) {
  210.                 mainsw_state = DISPLAYING_MONTH;
  211.                 window_set(canvas, WIN_CURSOR, month_cursor, 0);
  212.             }
  213.             draw_month();
  214.         }
  215.     } else
  216.         panel_default_handle_event(item, event);
  217. }
  218.  
  219.  
  220. lastyear()
  221. {
  222.     current.tm_mday = 1;
  223.     current.tm_mon = JAN;
  224.     current.tm_year -= 1;
  225.     draw_year();
  226. }
  227.  
  228. nextyear()
  229. {
  230.     current.tm_mday = 1;
  231.     current.tm_mon = JAN;
  232.     current.tm_year += 1;
  233.     draw_year();
  234. }
  235.  
  236. void
  237. yearmenu_notify(item, event)
  238. Panel_item item;
  239. Event *event;
  240. {
  241.     int old_state;
  242.  
  243.     if (event_id(event) == MS_LEFT) {
  244.         if (mainsw_state == DISPLAYING_DAY) 
  245.             close_day(); 
  246.         old_state = mainsw_state;
  247.         mainsw_state = DISPLAYING_YEAR; 
  248.         draw_year(); 
  249.         if (old_state != DISPLAYING_YEAR)
  250.             window_set(canvas, WIN_CURSOR, year_cursor, 0);
  251.     } else
  252.         panel_default_handle_event(item, event);
  253.  
  254. void
  255. year_menu_event(item, event)
  256. Panel_item item;
  257. Event *event;
  258. {
  259.     int value, old_state;
  260.  
  261.     if (event_id(event) == MS_RIGHT && event_is_down(event)) {
  262.         value = (int) menu_show(year_menu, panel, event, 0);
  263.         if (value > 0) {
  264.             current.tm_year = START_YEAR + value - 1;
  265.             if (mainsw_state == DISPLAYING_DAY) 
  266.                 close_day(); 
  267.             old_state = mainsw_state;
  268.             mainsw_state = DISPLAYING_YEAR; 
  269.             draw_year(); 
  270.             if (old_state != DISPLAYING_YEAR)
  271.                 window_set(canvas, WIN_CURSOR, year_cursor, 0);
  272.         }
  273.     } else
  274.         panel_default_handle_event(item, event);
  275. }
  276.  
  277.  
  278. lastweek()
  279. {
  280.     if (mainsw_state == DISPLAYING_DAY) {
  281.         close_day();
  282.         current.tm_mday -= 7;
  283.         draw_day();
  284.     } else if (mainsw_state == DISPLAYING_WEEK) {
  285.         current.tm_mday -= 7;
  286.         draw_week();
  287.     }
  288. }
  289.  
  290.  
  291. nextweek()
  292. {
  293.         if (mainsw_state == DISPLAYING_DAY) {
  294.                 close_day();
  295.         current.tm_mday += 7;
  296.                 draw_day();
  297.         } else if (mainsw_state == DISPLAYING_WEEK) {
  298.         current.tm_mday += 7;
  299.                 draw_week();
  300.     }
  301. }
  302.  
  303.  
  304.  
  305. yesterday()
  306. {
  307.     if (mainsw_state != DISPLAYING_DAY)
  308.         return(0);
  309.     close_day();
  310.     current.tm_mday--;
  311.     draw_day();
  312. }
  313.  
  314.  
  315. void
  316. todaybutton_notify(item, event)
  317. Panel_item item;
  318. Event *event;
  319. {
  320.     if (event_id(event) == MS_LEFT) {
  321.         if (mainsw_state == DISPLAYING_DAY)
  322.             close_day();
  323.         else {
  324.             mainsw_state = DISPLAYING_DAY;
  325.             window_set(canvas, WIN_CURSOR, day_cursor, 0);
  326.         }
  327.         get_today();
  328.         current = today;
  329.         draw_day();
  330.     } else
  331.         panel_default_handle_event(item, event);
  332. }
  333.  
  334.  
  335.  
  336. tomorrow()
  337.         if (mainsw_state != DISPLAYING_DAY)
  338.                 return(0);
  339.         close_day(); 
  340.     current.tm_mday++;
  341.         draw_day(); 
  342.  
  343.  
  344. void
  345. currentbutton_notify(item, event)
  346. Panel_item item;
  347. Event *event;
  348. {
  349.     if (event_id(event) == MS_LEFT) {
  350.         if (mainsw_state == DISPLAYING_DAY)
  351.             close_day();
  352.         get_today();
  353.         current = today;
  354.         switch (mainsw_state) {
  355.             case DISPLAYING_DAY:
  356.                 draw_day();
  357.                 break;
  358.             case DISPLAYING_WEEK:
  359.                 draw_week();
  360.                 break;
  361.             case DISPLAYING_MONTH:
  362.                 draw_month();
  363.                 break;
  364.             case DISPLAYING_YEAR:
  365.                 draw_year();
  366.                 break;
  367.         }
  368.     } else
  369.         panel_default_handle_event(item, event);
  370. }
  371.  
  372. void
  373. current_menu_event(item, event)
  374. Panel_item item;
  375. Event *event;
  376. {
  377.     Menu_item an_item;
  378.     char date[9];
  379.     int value, rtn;
  380.     struct tm Save;
  381.  
  382.     if (event_id(event) == MS_RIGHT && event_is_down(event)) {
  383.         value = (int) menu_show(current_menu, panel, event, 0);
  384.         if (value == 0)
  385.             return;    /* no selection made */
  386.         if (mainsw_state == DISPLAYING_DAY)
  387.             close_day();
  388.         get_today();
  389.         Save = current;
  390.         current = today;
  391.         switch (value) {
  392.             case 1:    /* current day */
  393.                 mainsw_state = DISPLAYING_DAY;
  394.                 window_set(canvas, WIN_CURSOR, day_cursor, 0);
  395.                 draw_day();
  396.                 break;
  397.  
  398.             case 2:    /* current week */
  399.                 mainsw_state = DISPLAYING_WEEK;
  400.                 window_set(canvas, WIN_CURSOR, week_cursor, 0);
  401.                 draw_week();
  402.                 break;
  403.  
  404.             case 3:    /* current month */
  405.                 mainsw_state = DISPLAYING_MONTH;
  406.                 window_set(canvas, WIN_CURSOR, month_cursor, 0);
  407.                 draw_month();
  408.                 break;
  409.  
  410.             case 4:    /* current year */
  411.                 mainsw_state = DISPLAYING_YEAR;
  412.                 window_set(canvas, WIN_CURSOR, year_cursor, 0);
  413.                 draw_year();
  414.                 break;
  415.  
  416.             case 5:    /* change date */
  417.                 sprintf(date, "%d/%d/%02d", Save.tm_mon+1, Save.tm_mday, Save.tm_year);
  418.                 panel_set_value(setdate_pi, date);
  419.                 do {
  420.                     window_loop(date_frame);
  421.                     /* change "current" date to reflect entry */
  422.                     rtn = parse_date((char *)panel_get_value(setdate_pi), FALSE);
  423.                 } while (rtn);
  424.                 mainsw_state = DISPLAYING_DAY;
  425.                 window_set(canvas, WIN_CURSOR, day_cursor, 0);
  426.                 draw_day();
  427.                 break;
  428.         }
  429.     } else
  430.         panel_default_handle_event(item, event);
  431. }
  432.  
  433. /*
  434.  * notifier for set date frame "Done" button
  435.  */
  436. void
  437. dtdone_proc(item, event)
  438. Panel_item item;
  439. Event *event;
  440. {
  441.     if (event_id(event) == MS_LEFT)
  442.         window_return(0);
  443. }
  444.  
  445. /* "done" from subframe menu of change date frame */
  446. void
  447. dtframe_done(frame)
  448. Frame frame;
  449. {
  450.     window_set(date_frame, WIN_SHOW, FALSE, 0);
  451. }
  452.  
  453. void
  454. daybutton_notify(item, event)
  455. Panel_item item;
  456. Event *event;
  457. {
  458.     if (event_id(event) == MS_LEFT) {
  459.         switch (mainsw_state) {
  460.             case DISPLAYING_DAY:
  461.                 /* no change */
  462.                 return;
  463.             case DISPLAYING_WEEK:
  464.                 /* pick first day in week */
  465.                 while (current.tm_wday != SUN) {
  466.                     current.tm_mday--;
  467.                     current.tm_wday--;
  468.                 }
  469.                 if (nr_weekdays < 7)
  470.                     /* start with MON */
  471.                     current.tm_mday++;
  472.                 break;
  473.             case DISPLAYING_MONTH:
  474.                 /* pick first day in month */
  475.                 current.tm_mday = 1;
  476.                 first_wkday();
  477.                 break;
  478.             case DISPLAYING_YEAR:
  479.                 /* pick first day in year */
  480.                 current.tm_mon = JAN;
  481.                 current.tm_mday = 1;
  482.                 first_wkday();
  483.                 break;
  484.         }
  485.         mainsw_state = DISPLAYING_DAY;
  486.         draw_day();
  487.         window_set(canvas, WIN_CURSOR, day_cursor, 0);
  488.     } else
  489.         panel_default_handle_event(item, event);
  490. }
  491.  
  492. void
  493. day_menu_event(item, event)
  494. Panel_item item;
  495. Event *event;
  496. {
  497.     int value, i;
  498.     Menu_item an_item;
  499.  
  500.     if (event_id(event) == MS_RIGHT && event_is_down(event)) {
  501.         if (mainsw_state > DISPLAYING_WEEK) {
  502.             /* make all entries inactive */
  503.             for (i=1; i<=7; i++) {
  504.                 an_item = menu_get(day_menu, MENU_NTH_ITEM, i);
  505.                 menu_set(an_item, MENU_INACTIVE, TRUE, 0);
  506.             }
  507.         } else {
  508.             /* make all entries active */
  509.             for (i=1; i<=7; i++) {
  510.                 an_item = menu_get(day_menu, MENU_NTH_ITEM, i);
  511.                 menu_set(an_item, MENU_INACTIVE, FALSE, 0);
  512.             }
  513.         }
  514.         value = (int) menu_show(day_menu, panel, event, 0);
  515.         if (value > 0) {
  516.             /* find selected day in this week */
  517.             if (--value > current.tm_wday)
  518.                 current.tm_mday += value - current.tm_wday;
  519.             else
  520.                 current.tm_mday -= current.tm_wday - value;
  521.             mainsw_state = DISPLAYING_DAY;
  522.             draw_day();
  523.             window_set(canvas, WIN_CURSOR, day_cursor, 0);
  524.         }
  525.     } else
  526.         panel_default_handle_event(item, event);
  527. }
  528.  
  529. first_wkday()
  530. {
  531.     /*
  532.      * Set day to first displayable day of the week selected.
  533.      * If we have a 7-day week display, then it will always
  534.      * be the first day of the month. If we have a 5 or 6 day
  535.      * display, the first day may need to be adjusted to the
  536.      * following monday.
  537.      */
  538.     if (nr_weekdays == 7)
  539.         /* it's ok as is */
  540.         return;
  541.     fix_current_day();    /* update wkday, etc. */
  542.     if (current.tm_wday == SUN)
  543.         current.tm_mday++;
  544.     else if (current.tm_wday > nr_weekdays)
  545.         current.tm_mday += 7 - current.tm_wday + 1;
  546. }
  547.  
  548. void
  549. next_menu_event(item, event)
  550. Panel_item item;
  551. Event *event;
  552. {
  553.     Menu_item an_item;
  554.     int value;
  555.  
  556.     if (event_id(event) == MS_RIGHT && event_is_down(event)) {
  557.         i = 0;
  558.         while (++i < mainsw_state) {
  559.             an_item = menu_get(next_menu, MENU_NTH_ITEM, i);
  560.             menu_set(an_item, MENU_INACTIVE, TRUE, 0);
  561.         }
  562.         for (i=mainsw_state; i<=DISPLAYING_YEAR; i++) {
  563.             an_item = menu_get(next_menu, MENU_NTH_ITEM, i);
  564.             menu_set(an_item, MENU_INACTIVE, FALSE, 0);
  565.         }
  566.         value = (int) menu_show(next_menu, panel, event, 0);
  567.         if (value == 0)
  568.             return;    /* no selection made */
  569.         value--;
  570.         switch (mainsw_state) {
  571.             case DISPLAYING_DAY:
  572.                 switch (value) {
  573.                     case 0:    /* day */
  574.                         tomorrow();
  575.                         break;
  576.                     case 1: /* week */
  577.                         close_day();
  578.                         current.tm_mday += 7;
  579.                         draw_day();
  580.                         break;
  581.                     case 2:    /* month */
  582.                         close_day();
  583.                         current.tm_mon++;
  584.                         /* make sure day ends up in proper month */
  585.                         if (current.tm_mday == monthlength(current.tm_mon-1))
  586.                             /* last day of month */
  587.                             current.tm_mday = monthlength(current.tm_mon%12);
  588.                         else if (current.tm_mday > monthlength(current.tm_mon%12))
  589.                             current.tm_mday = monthlength(current.tm_mon%12);
  590.                         draw_day();
  591.                         break;
  592.                     case 3: /* year */
  593.                         close_day();
  594.                         current.tm_year++;
  595.                         draw_day();
  596.                         break;
  597.                 }
  598.                 break;
  599.             case DISPLAYING_WEEK:
  600.                 switch (value) {
  601.                     case 1:    /* week */
  602.                         nextweek();
  603.                         break;
  604.                     case 2:    /* month */
  605.                         current.tm_mon++;
  606.                         draw_week();
  607.                         break;
  608.                     case 3:    /* year */
  609.                         current.tm_year++;
  610.                         draw_week();
  611.                         break;
  612.                 }
  613.                 break;
  614.             case DISPLAYING_MONTH:
  615.                 switch (value) {
  616.                     case 2: /* month */
  617.                         nextmonth();
  618.                         break;
  619.                     case 3:    /* year */
  620.                         current.tm_year++;
  621.                         draw_month();
  622.                         break;
  623.                 }
  624.                 break;
  625.             case DISPLAYING_YEAR:
  626.                 if (value == 3)
  627.                     nextyear();
  628.                 break;
  629.         }
  630.     } else
  631.         panel_default_handle_event(item, event);
  632. }
  633.  
  634. void
  635. nextbutton_notify(item, event) 
  636. Panel_item item; 
  637. Event *event; 
  638.     if (event_id(event) == MS_LEFT) {
  639.         switch (mainsw_state) {
  640.             case DISPLAYING_DAY:
  641.                 tomorrow();
  642.                 break;
  643.             case DISPLAYING_WEEK:
  644.                 nextweek();
  645.                 break;
  646.             case DISPLAYING_MONTH:
  647.                 nextmonth();
  648.                 break;
  649.             case DISPLAYING_YEAR:
  650.                 nextyear();
  651.                 break;
  652.         }
  653.     } else
  654.         panel_default_handle_event(item, event);
  655. }
  656.  
  657. void
  658. previous_menu_event(item, event)
  659. Panel_item item;
  660. Event *event;
  661. {
  662.     Menu_item an_item;
  663.     int value;
  664.  
  665.     if (event_id(event) == MS_RIGHT && event_is_down(event)) {
  666.         i = 0;
  667.         while (++i < mainsw_state) {
  668.             an_item = menu_get(previous_menu, MENU_NTH_ITEM, i);
  669.             menu_set(an_item, MENU_INACTIVE, TRUE, 0);
  670.         }
  671.         for (i=mainsw_state; i<=DISPLAYING_YEAR; i++) {
  672.             an_item = menu_get(previous_menu, MENU_NTH_ITEM, i);
  673.             menu_set(an_item, MENU_INACTIVE, FALSE, 0);
  674.         }
  675.         value = (int) menu_show(previous_menu, panel, event, 0);
  676.         if (value == 0)
  677.             return;    /* no selection made */
  678.         value--;
  679.         switch (mainsw_state) {
  680.             case DISPLAYING_DAY:
  681.                 switch (value) {
  682.                     case 0:    /* day */
  683.                         yesterday();
  684.                         break;
  685.                     case 1: /* week */
  686.                         close_day();
  687.                         current.tm_mday -= 7;
  688.                         draw_day();
  689.                         break;
  690.                     case 2:    /* month */
  691.                         close_day();
  692.                         current.tm_mon--;
  693.                         /* make sure day ends up in proper month */
  694.                         if (current.tm_mday == monthlength(current.tm_mon+1))
  695.                             /* last day of month */
  696.                             current.tm_mday = monthlength((current.tm_mon+12)%12);
  697.                         else if (current.tm_mday > monthlength((current.tm_mon+12)%12))
  698.                             current.tm_mday = monthlength((current.tm_mon+12)%12);
  699.                         draw_day();
  700.                         break;
  701.                     case 3: /* year */
  702.                         close_day();
  703.                         current.tm_year--;
  704.                         draw_day();
  705.                         break;
  706.                 }
  707.                 break;
  708.             case DISPLAYING_WEEK:
  709.                 switch (value) {
  710.                     case 1:    /* week */
  711.                         lastweek();
  712.                         break;
  713.                     case 2:    /* month */
  714.                         current.tm_mon--;
  715.                         draw_week();
  716.                         break;
  717.                     case 3:    /* year */
  718.                         current.tm_year--;
  719.                         draw_week();
  720.                         break;
  721.                 }
  722.                 break;
  723.             case DISPLAYING_MONTH:
  724.                 switch (value) {
  725.                     case 2: /* month */
  726.                         lastmonth();
  727.                         break;
  728.                     case 3:    /* year */
  729.                         current.tm_year--;
  730.                         draw_month();
  731.                         break;
  732.                 }
  733.                 break;
  734.             case DISPLAYING_YEAR:
  735.                 if (value == 3)
  736.                     lastyear();
  737.                 break;
  738.         }
  739.     } else {
  740.         panel_default_handle_event(item, event);
  741.     }
  742. }
  743.  
  744. void
  745. previous_menu_notify(item, event)
  746. Panel_item item; 
  747. Event *event; 
  748.     if (event_id(event) == MS_LEFT) {
  749.         switch (mainsw_state) {
  750.             case DISPLAYING_DAY:
  751.                 yesterday();
  752.                 break;
  753.             case DISPLAYING_WEEK:
  754.                 lastweek();
  755.                 break;
  756.             case DISPLAYING_MONTH:
  757.                 lastmonth();
  758.                 break;
  759.             case DISPLAYING_YEAR:
  760.                 lastyear();
  761.                 break;
  762.         }
  763.     } else
  764.         panel_default_handle_event(item, event);
  765. }
  766.  
  767. #ifndef NO_SUN_MOON
  768. void
  769. moonbutton_notify(item, event) 
  770. Panel_item item; 
  771. Event *event; 
  772.     /*** DEBUG ***/
  773.     if (event_id(event) != MS_LEFT)
  774.         return;
  775.  
  776.     if (event_id(event) == MS_LEFT) {
  777.         /* display popup frame with moon data */
  778.         moon_data_frame();
  779.         panel_set(moonbutton_pi, PANEL_SHOW_ITEM, FALSE, 0);
  780.     } else
  781.         panel_default_handle_event(item, event);
  782. }
  783.  
  784. void
  785. sunbutton_notify(item, event) 
  786. Panel_item item; 
  787. Event *event; 
  788.     if (event_id(event) == MS_LEFT) {
  789.         /* display popup frame with moon data */
  790.         sun_data_frame();
  791.         panel_set(sunbutton_pi, PANEL_SHOW_ITEM, FALSE, 0);
  792.     } else
  793.         panel_default_handle_event(item, event);
  794. }
  795. #endif
  796.  
  797. Notify_value
  798. myframe_interposer(client, event, arg, type)
  799. Notify_client client;
  800. Event *event;
  801. Notify_arg arg;
  802. Notify_event_type type;
  803. {
  804.     static int start_up = 1;
  805.     int closed_initial, closed_current;
  806.     Notify_value value;
  807.     void sframe_done(), mframe_done();
  808.  
  809.     /* get initial state */
  810.     closed_initial = (int)window_get(frame, FRAME_CLOSED);
  811.     /***** debug *****/
  812.     /*
  813.     fprintf(stderr,"interposer: event=%d, start_up=%d, closed_initial=%d, ", event_id(event), start_up, closed_initial);
  814.      */
  815.     /* let the frame do its thing */
  816.     value = notify_next_event_func(client, event, arg, type);
  817.     /* get new state */
  818.     closed_current = (int)window_get(frame, FRAME_CLOSED);
  819.     /**** debug ****/
  820.     /*
  821.     fprintf(stderr,"event=%d, closed_current=%d\n", event_id(event), closed_current);
  822.     */
  823.     if (start_up) {
  824.         /* first time thru */
  825.         start_up = 0;
  826.         if (closed_initial)
  827.             /* starting up iconic */
  828.             olddate = current;
  829.         else
  830.             /* starting up open */
  831.             if (mainsw_state == DISPLAYING_DAY)
  832.                 /* create future appt popup */
  833.                 draw_future_appts();
  834.     } else if (closed_current != closed_initial) {
  835.         /* it changed state - either opened or closed */
  836.         if (closed_current) {
  837.             /* frame just closed */
  838.             close_frame();
  839.         } else {
  840.             /* frame just opened */
  841.             /*
  842.              * redraw display in case the "today" changed
  843.              * and a different day needs to be highlighted
  844.              */
  845.             switch (mainsw_state) {
  846.                 case DISPLAYING_DAY:
  847.                     if (day_is_open)
  848.                         close_day();
  849.                     current = olddate;
  850.                     draw_day1();
  851.                     /* create future popup next time thru */
  852.                     start_up = 1;
  853.                     break;
  854.                 case DISPLAYING_WEEK:
  855.                     draw_week();
  856.                     break;
  857.                 case DISPLAYING_MONTH:
  858.                     draw_month();
  859.                     break;
  860.                 case DISPLAYING_YEAR:
  861.                     draw_year();
  862.                     break;
  863.             }
  864.         }
  865.     }
  866.  
  867.     return(NOTIFY_DONE);
  868. }
  869.  
  870. /*
  871.  * notifier for "Done" button in the popup future appt frame
  872.  */
  873. void
  874. fdone_proc(item, event)
  875. Panel_item item;
  876. Event *event;
  877. {
  878.     if (event_id(event) == MS_LEFT) {
  879.         window_destroy(fframe);
  880.         fframe = 0;
  881.         show_future = 0;
  882.     }
  883. }
  884.  
  885. /*
  886.  * notifier for "Keep" button in the popup future appt frame
  887.  */
  888. void
  889. fkeep_proc(item, event)
  890. Panel_item item;
  891. Event *event;
  892. {
  893.     if (event_id(event) == MS_LEFT) {
  894.         window_destroy(fframe);
  895.         fframe = 0;
  896.     }
  897. }
  898.  
  899. /*
  900.  * Notifier for future appts. We get here when the user
  901.  * selects one of the displayed messages. When this happens,
  902.  * the day display for the selected future appt is displayed.
  903.  */
  904. void
  905. fappt_notify(item, event)
  906. Panel_item item;
  907. Event *event;
  908. {
  909.     int value;
  910.  
  911.     if (event_id(event) != MS_LEFT)
  912.         return;
  913.     
  914.     value = (int)panel_get(item, PANEL_CLIENT_DATA);
  915.     /* set current date to match the selected appt */
  916.     current.tm_year = future[value].year;
  917.     current.tm_mon = future[value].month;
  918.     current.tm_mday = future[value].day;
  919.     fix_current_day();
  920.  
  921.     /* draw new day page */
  922.     draw_day();
  923. }
  924.  
  925. /*
  926.  * Notify routine for everyx panel item in the attributes
  927.  * popup window. In this routine, we only care about the state
  928.  * of the "Selected Week" choice, which determines which panel
  929.  * item is displayed.
  930.  */
  931. void
  932. everyx_notify(item, event)
  933. Panel_item item;
  934. Event *event;
  935. {
  936.     int value;
  937.  
  938.     value = (int) panel_get_value(everyx_pi);
  939.     if (value & 0x2) {
  940.         panel_set(repeat_pi, PANEL_SHOW_ITEM, FALSE, 0);
  941.         panel_set(whichwk_pi, PANEL_SHOW_ITEM, TRUE, 0);
  942.     } else {
  943.         panel_set(whichwk_pi, PANEL_SHOW_ITEM, FALSE, 0);
  944.         panel_set(repeat_pi, PANEL_SHOW_ITEM, TRUE, 0);
  945.     }
  946. }
  947.  
  948. /*
  949.  * Notify routine for the appointment attributes popup window.
  950.  * Since each panel item does not have its own notify routine,
  951.  * we check the current state of everything when the user
  952.  * selects the accept button and set the slot flags appropriately.
  953.  */
  954. void
  955. attr_accept(item, event)
  956. Panel_item item;
  957. Event *event;
  958. {
  959.     int value, flag = 0, repeat = 0;
  960.     int oflag;
  961.     struct appt_entry *apt = slots[attr_bi].cur_appt;
  962.  
  963.     if (event_id(event) != MS_LEFT)
  964.         return;  /* ignore everything else */
  965.     
  966.     oflag = apt->flags;
  967.  
  968.     /* get the everyx value (every day, week, month, year) */
  969.     value = (int) panel_get_value(everyx_pi);
  970.     /* value is bitmap of selected choices */
  971.     if (value & 0x1)
  972.         flag |= ALL_DAYS;
  973.     else if (oflag & ALL_DAYS)
  974.         apt->day = current.tm_mday;
  975.     if (value & 0x2)
  976.         flag |= Setday(current.tm_wday);
  977.     else if (oflag & EVERY_SOMEDAY)
  978.         apt->day = current.tm_mday;
  979.     if (value & 0x4)
  980.         flag |= ALL_MONTHS;
  981.     else if (oflag & ALL_MONTHS)
  982.         apt->month = current.tm_mon;
  983.     if (value & 0x8)
  984.         flag |= ALL_YEARS;
  985.     else if (oflag & ALL_YEARS)
  986.         apt->year = current.tm_year;
  987.     
  988.     if (value & 0x2) {
  989.         /* repeat at week intervals selected by which week pi */
  990.         value = (int) panel_get_value(whichwk_pi);
  991.         if (value == 0)
  992.             /* ALL selected or no selection */
  993.             value = ALL_WEEKS;
  994.         flag |= REPEAT;
  995.         repeat = value;
  996.     } else {
  997.         /* get repeat interval */
  998.         value = atoi((char *)panel_get_value(repeat_pi));
  999.         if (value > 0) {
  1000.             flag |= REPEAT;
  1001.             repeat = value;
  1002.         }
  1003.     }
  1004.  
  1005.     /* get lookahead value */
  1006.     value = atoi((char *)panel_get_value(remind_pi));
  1007.     if (value > 0) {
  1008.         if (apt->lookahead != value) {
  1009.             new_entry = 1;
  1010.             flag |= LOOKAHEAD;
  1011.             apt->lookahead = value;
  1012.         }
  1013.     }
  1014.  
  1015.     if (oflag & A_NOTE) {
  1016.         flag |= A_NOTE;
  1017.         /* marked indicator */
  1018.         value = (int) panel_get_value(marked_pi);
  1019.         if (value == 1)
  1020.             flag |= MARKED;  /* don't show in month/yr display */
  1021.     }
  1022.     /* shouldn't really be in this routine if the appt
  1023.      * was read only, however, this is still here for potential
  1024.      * future use.
  1025.      */
  1026.     if (oflag & READONLY)
  1027.         flag |= READONLY;
  1028.  
  1029.     if (apt->repeat != repeat || oflag != flag)
  1030.         new_entry = 1;    /* something changed */
  1031.  
  1032.     /* set the slot info */
  1033.     apt->repeat = repeat;
  1034.     apt->flags = flag;
  1035.  
  1036.     window_return(0);
  1037. }
  1038.  
  1039. /*
  1040.  * abort the attribute setting process, leaving the current
  1041.  * appointment unmodified.
  1042.  */
  1043. void
  1044. attr_abort(item, event)
  1045. Panel_item item;
  1046. Event *event;
  1047. {
  1048.     if (event_id(event) == MS_LEFT)
  1049.         window_return(0);
  1050. }
  1051.  
  1052. /*
  1053.  * Notify routine for the delete mode popup window.
  1054.  * Since the panel item does not have its own notify routine,
  1055.  * we check the current state when the user
  1056.  * selects the done button and set the slot flags appropriately.
  1057.  */
  1058. void
  1059. del_done(item, event)
  1060. Panel_item item;
  1061. Event *event;
  1062. {
  1063.     int value;
  1064.     struct appt_entry tmp;
  1065.  
  1066.     if (event_id(event) != MS_LEFT)
  1067.         return;  /* ignore everything else */
  1068.     
  1069.     value = (int) panel_get_value(del_choice_pi);
  1070.     if (value == 0) {
  1071.         /* don't show it today */
  1072.         /* create duplicate entry with delete flag set */
  1073.         tmp = *slots[attr_bi].cur_appt;
  1074.         tmp.flags &= ~(ALL_YEARS|ALL_MONTHS|ALL_DAYS|EVERY_SOMEDAY|REPEAT);
  1075.         tmp.flags |= DELETED;
  1076.         tmp.year = current.tm_year;
  1077.         tmp.month = current.tm_mon;
  1078.         tmp.day = current.tm_mday;
  1079.         add_to_slot(attr_bi, &tmp, TRUE);
  1080.         /* in the case of "cut", modify the shelf appt */
  1081.         if ((int)panel_get(del_choice_pi, PANEL_CLIENT_DATA)) {
  1082.             shelf_appt.flags &= ~(ALL_YEARS|ALL_MONTHS|ALL_DAYS|EVERY_SOMEDAY|REPEAT);
  1083.             shelf_appt.year = current.tm_year;
  1084.             shelf_appt.month = current.tm_mon;
  1085.             shelf_appt.day = current.tm_mday;
  1086.         }
  1087.     } else {
  1088.         /* completely kill appt */
  1089.         cut_delete(attr_bi);
  1090.     }
  1091.     new_entry = 1;
  1092.  
  1093.     window_return(0);
  1094. }
  1095.  
  1096. #ifndef NO_SUN_MOON
  1097. /*
  1098.  * notifier for "Done" button in the popup sun data frame
  1099.  */
  1100. void
  1101. sdone_proc(item, event)
  1102. Panel_item item;
  1103. Event *event;
  1104. {
  1105.     if (event_id(event) == MS_LEFT) {
  1106.         window_destroy(sframe);
  1107.         sframe = 0;
  1108.         panel_set(sunbutton_pi, PANEL_SHOW_ITEM, TRUE, 0);
  1109.     }
  1110. }
  1111.  
  1112. /*
  1113.  * notifier for "Done" button in the popup moon data frame
  1114.  */
  1115. void
  1116. mdone_proc(item, event)
  1117. Panel_item item;
  1118. Event *event;
  1119. {
  1120.     if (event_id(event) == MS_LEFT) {
  1121.         window_destroy(mframe);
  1122.         mframe = 0;
  1123.         panel_set(moonbutton_pi, PANEL_SHOW_ITEM, TRUE, 0);
  1124.     }
  1125. }
  1126.  
  1127. /* "done" from subframe menu */
  1128. void
  1129. sframe_done(frame)
  1130. Frame frame;
  1131. {
  1132.     window_destroy(sframe);
  1133.     sframe = 0;
  1134.     panel_set(sunbutton_pi, PANEL_SHOW_ITEM, TRUE, 0);
  1135. }
  1136.  
  1137. /* "done" from subframe menu */
  1138. void
  1139. mframe_done(frame)
  1140. Frame frame;
  1141. {
  1142.     window_destroy(mframe);
  1143.     mframe = 0;
  1144.     panel_set(moonbutton_pi, PANEL_SHOW_ITEM, TRUE, 0);
  1145. }
  1146. #endif    /* NO_SUN_MOON */
  1147.  
  1148. /*
  1149.  * notifier for file button in main control panel
  1150.  */
  1151. void
  1152. filebutton_notify(item, event)
  1153. Panel_item item;
  1154. Event *event;
  1155. {
  1156.     if (event_id(event) == MS_LEFT) {
  1157.         panel_set_value(filename_pi, apts_pathname);
  1158.         panel_set_value(file_ro_pi, (read_only ? 0 : 1));
  1159.         window_set(fileframe, WIN_SHOW, TRUE, 0);
  1160.     } else
  1161.         panel_default_handle_event(item, event);
  1162. }
  1163.  
  1164. /*
  1165.  * notifier for "Done" button in the popup file frame
  1166.  */
  1167. void
  1168. file_done(item, event)
  1169. Panel_item item;
  1170. Event *event;
  1171. {
  1172.     if (event_id(event) == MS_LEFT)
  1173.         window_set(fileframe, WIN_SHOW, FALSE, 0);
  1174. }
  1175.  
  1176. /*
  1177.  * notifier for "Accept" button in the popup file frame
  1178.  */
  1179. void
  1180. file_accept(item, event)
  1181. Panel_item item;
  1182. Event *event;
  1183. {
  1184.     char save_name[160];
  1185.     int save_ro;
  1186.  
  1187.     if (event_id(event) == MS_LEFT) {
  1188.         /* cleanup existing appts file and open new one */
  1189.         strcpy(save_name, apts_pathname);
  1190.         save_ro = read_only;
  1191.         cleanup();
  1192.         othername = (char *)panel_get_value(filename_pi);
  1193.         otherfile = 1;
  1194.         read_only = ((int)panel_get_value(file_ro_pi) == 0 ? 1 : 0);
  1195.         if (do_files(TRUE)) {
  1196.             /* error in opening new file - restore old */
  1197.             othername = save_name;
  1198.             read_only = save_ro;
  1199.             if (do_files(TRUE))
  1200.                 /* can't restore original */
  1201.                 err_rpt("can't restore appts file", FATAL);
  1202.         } else {
  1203.             switch(mainsw_state) {
  1204.                 case DISPLAYING_DAY:
  1205.                     draw_day();
  1206.                     break;
  1207.                 case DISPLAYING_WEEK:
  1208.                     draw_week();
  1209.                     break;
  1210.                 case DISPLAYING_MONTH:
  1211.                     draw_month();
  1212.                     break;
  1213.                 case DISPLAYING_YEAR:
  1214.                     draw_year();
  1215.                     break;
  1216.             }
  1217.         }
  1218.     }
  1219. }
  1220.  
  1221. /*
  1222.  * notifier for "Reset" button in the popup file frame
  1223.  */
  1224. void
  1225. file_reset(item, event)
  1226. Panel_item item;
  1227. Event *event;
  1228. {
  1229.     if (event_id(event) == MS_LEFT)
  1230.         panel_set_value(filename_pi, apts_pathname);
  1231. }
  1232.  
  1233. /*
  1234.  * notifier for "Save" button in the popup file frame
  1235.  */
  1236. void
  1237. file_save(item, event)
  1238. Panel_item item;
  1239. Event *event;
  1240. {
  1241.     if (event_id(event) == MS_LEFT) {
  1242.         othername = (char *)panel_get_value(filename_pi);
  1243.         if (!strcmp(othername, apts_pathname)) {
  1244.             /* no filename change */
  1245.             if (mainsw_state == DISPLAYING_DAY && day_is_open)
  1246.                 close_day();
  1247.         }
  1248.     }
  1249. }
  1250.  
  1251. /*
  1252.  * notifier for "Original" button in the popup file frame
  1253.  */
  1254. void
  1255. file_orig(item, event)
  1256. Panel_item item;
  1257. Event *event;
  1258. {
  1259.     if (event_id(event) == MS_LEFT) {
  1260.         panel_set_value(filename_pi, orig_apts_pathname);
  1261.         panel_set_value(file_ro_pi, (orig_ro ? 0 : 1));
  1262.     }
  1263. }
  1264.  
  1265. /*
  1266.  * "Done" from subframe menu of the file selection popup frame
  1267.  */
  1268. void
  1269. fileframe_done(frame)
  1270. Frame frame;
  1271. {
  1272.     window_set(fileframe, WIN_SHOW, FALSE, 0);
  1273. }
  1274.  
  1275. /*
  1276.  * notifier for prompt frame "No" button
  1277.  */
  1278. void
  1279. prompt_no_notify(item, event)
  1280. Panel_item item;
  1281. Event *event;
  1282. {
  1283.     if (event_id(event) == MS_LEFT)
  1284.         window_return(1);
  1285. }
  1286.  
  1287. /*
  1288.  * notifier for prompt frame "Yes" or "Ok" button
  1289.  */
  1290. void
  1291. prompt_yes_notify(item, event)
  1292. Panel_item item;
  1293. Event *event;
  1294. {
  1295.     if (event_id(event) == MS_LEFT)
  1296.         window_return(0);
  1297. }
  1298.  
  1299. #ifndef NO_PRINTER
  1300. /*
  1301.  * notifier for "Print" button in main control panel
  1302.  */
  1303. void
  1304. printbutton_notify(item, event)
  1305. Panel_item item;
  1306. Event *event;
  1307. {
  1308.     int prt_fmt;
  1309.  
  1310.     if (event_id(event) == MS_LEFT) {
  1311. #ifdef RASTER_ONLY
  1312.         /* default to printing a raster file */
  1313.         print_calendar(PR_RASTER);
  1314. #else
  1315.         /* default to printing a postscript file */
  1316.         print_calendar(PR_POSTSCRIPT);
  1317. #endif
  1318.     } else if (event_id(event) == MS_RIGHT) {
  1319.         /* print selected format */
  1320.         if ((prt_fmt = (int) panel_get(item, PANEL_CLIENT_DATA)) <= 2)
  1321.             print_calendar(prt_fmt);
  1322.     } else
  1323.         panel_default_handle_event(item, event);
  1324. }
  1325.  
  1326. void
  1327. print_menu_event(item, event)
  1328. Panel_item item;
  1329. Event *event;
  1330. {
  1331.     int value;
  1332. #ifdef RASTER_ONLY
  1333.     Menu_item an_item;
  1334. #endif
  1335.  
  1336.     if (event_id(event) == MS_RIGHT && event_is_down(event)) {
  1337. #ifdef RASTER_ONLY
  1338.         an_item = menu_get(print_menu, MENU_NTH_ITEM, PR_POSTSCRIPT);
  1339.         menu_set(an_item, MENU_INACTIVE, TRUE, 0);
  1340. #endif
  1341.         value = (int) menu_show(print_menu, panel, event, 0);
  1342.         if (value > 0) {
  1343.             panel_set(item, PANEL_CLIENT_DATA, value, 0);
  1344.             if (value == 3) {
  1345.                 /* change printer */
  1346.                 panel_set_value(prcmd_pi, printer);
  1347.                 window_set(prframe, WIN_SHOW, TRUE, 0);
  1348.             } else {
  1349.                 panel_begin_preview(item, event);
  1350.                 panel_accept_preview(item, event);
  1351.             }
  1352.         }
  1353.     } else
  1354.         panel_default_handle_event(item, event);
  1355. }
  1356.  
  1357. void
  1358. prdone_proc(item, event)
  1359. Panel_item item;
  1360. Event *event;
  1361. {
  1362.     char *newstr;
  1363.     int status = 0;
  1364.  
  1365.     if (event_id(event) == MS_LEFT) {
  1366.         newstr = (char *) panel_get_value(prcmd_pi);
  1367.         window_set(prframe, WIN_SHOW, FALSE, 0);
  1368.         if (strcmp(printer, newstr)) {
  1369.             /* the string changed */
  1370.             strcpy(printer, newstr);
  1371.             /******
  1372.              * writing to the defaults file doesn't work.
  1373.              *
  1374.              * create_prompt_frame("Printer changed - overwrite .defaults entry?", TRUE);
  1375.              * if (!window_loop(prompt_frame))
  1376.              *     defaults_set_string("/CalenTool/Printer", printer, &status);
  1377.              *****/
  1378.         }
  1379.     }
  1380. }
  1381.  
  1382. void
  1383. prframe_done(frame)
  1384. Frame frame;
  1385. {
  1386.     /* mark as no change */
  1387.     window_set(prframe, WIN_SHOW, FALSE, 0);
  1388. }
  1389. #endif    /* NO_PRINTER */
  1390.