home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / sun / volume1 / calentool / part03 / event.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-05-27  |  6.4 KB  |  228 lines

  1. /*
  2.  * $Header: event.c,v 2.1 89/05/09 14:23:23 billr Exp $
  3.  */
  4. /*
  5.  * event.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.  *    Main driver and month and year event routines    *
  27.  *    for main subwindow                  *
  28.  *                            *
  29.  ********************************************************/
  30.  
  31.  
  32. #include <stdio.h>
  33. #include <suntool/sunview.h>
  34. #include <suntool/panel.h>
  35. #include <suntool/canvas.h>
  36. #include "ct.h"
  37. #include "event.h"
  38.  
  39. extern Frame frame;
  40. extern Frame fframe, sframe, mframe;
  41. extern struct tm olddate;
  42. extern int update_interval, show_time;
  43. extern char timestr[], todays_date[];
  44. extern Icon icon;
  45. Notify_value myframe_interposer();
  46.  
  47. void
  48. mainsw_inputevent(canvas, event)
  49. Canvas canvas;
  50. Event *event;
  51. {
  52.     /* check for L7 key and close frame if found */
  53.     if (event_id(event) == KEY_LEFT(7) && event_is_up(event))
  54.         close_frame();
  55.     else
  56.         switch (mainsw_state) {
  57.             case DISPLAYING_DAY:
  58.                 day_inputevent(canvas, event);
  59.                 break;
  60.             case DISPLAYING_WEEK:
  61.                 week_inputevent(canvas, event);
  62.                 break;
  63.             case DISPLAYING_MONTH:
  64.                 month_inputevent(canvas, event);
  65.                 break;
  66.             case DISPLAYING_YEAR:
  67.                 year_inputevent(canvas, event);
  68.                 break;
  69.         }
  70. }
  71.  
  72. month_inputevent(canvas, event)
  73. Canvas canvas;
  74. Event *event;
  75. {
  76.         int i, x, y, week_index, new_day;
  77.  
  78.     /* translate coordinates to pixwin space */
  79.     event = canvas_window_event(canvas, event);
  80.         x = event_x(event);
  81.         y = event_y(event);          
  82.         if (event_id(event) != MS_LEFT)
  83.                 return;
  84.  
  85.         if (event_is_up(event))  {   /* Button up. */
  86.         fix_current_day();
  87.                 if (selected_type == DAY) {
  88.                         mainsw_state = DISPLAYING_DAY;
  89.                         window_set(canvas, WIN_CURSOR, day_cursor, 0);
  90.             draw_day();
  91.                 }
  92.                 else if (selected_type == WEEK) {
  93.             mainsw_state = DISPLAYING_WEEK;
  94.             window_set(canvas, WIN_CURSOR, week_cursor, 0);
  95.             draw_week();
  96.         }
  97.         return;
  98.     }
  99.  
  100.     /* Button down. */
  101.         selected_type = NONE;
  102.         for (i=0; i<monthlength(current.tm_mon); i++) {   /* In a day? */
  103.                 if ((x >= boxlims[i].lowx) &&
  104.                     (x <= boxlims[i].highx) &&
  105.                     (y >= boxlims[i].lowy) &&
  106.                     (y <= boxlims[i].highy)) {
  107.                 current.tm_mday = i + 1;
  108.                                 selected_type = DAY;
  109.                                 pw_write(main_pixwin,boxlims[i].lowx+3,
  110.                                   boxlims[i].lowy+3,58,58,PIX_NOT(PIX_DST),NULL,0,0);
  111.                                 return;
  112.                 }              
  113.         }                      
  114.         for (i=0; i<6; i++) {              /* No.  In a week? */
  115.                 if (week_arrows[i].active == 0)
  116.                         return;
  117.                 if ((x >= week_arrows[i].left) &&
  118.                     (x <= week_arrows[i].right) &&
  119.                     (y >= week_arrows[i].top) &&
  120.                     (y <= week_arrows[i].bottom))  {
  121.             week_index = i;
  122.             current.tm_mday = -current.tm_wday + 1 + (7 * week_index);
  123.                         selected_type = WEEK;
  124.                         pw_write(main_pixwin,week_arrows[week_index].left,
  125.                           week_arrows[week_index].top,smallarrow_pr->pr_size.x,
  126.               smallarrow_pr->pr_size.y,PIX_SRC^PIX_DST,
  127.                           smallarrow_pr,0,0);
  128.                         return;
  129.                 }              
  130.         }                      
  131. }                               
  132.  
  133. year_inputevent(canvas, event)
  134. Canvas canvas;
  135. Event *event;
  136. {
  137.     int x, y, i;
  138.     static int mday;
  139.  
  140.     /* translate coordinates to pixwin space */
  141.     event = canvas_window_event(canvas, event);
  142.         x = event_x(event);
  143.         y = event_y(event);          
  144.         if (event_id(event) != MS_LEFT)
  145.                 return;
  146.         if (event_is_up(event))  {       /* Button up. */
  147.         if (selected_type == MONTH) {
  148.             mainsw_state = DISPLAYING_MONTH;
  149.             window_set(canvas, WIN_CURSOR, month_cursor, 0);
  150.             draw_month();
  151.         }
  152.         return;
  153.     }
  154.  
  155.     /* Button down. */
  156.     selected_type = NONE;
  157.         for (i=0; i<12; i++) {                   /* In a month? */
  158.                 if ((x >= mboxlims[i].lowx) &&
  159.                     (x <= mboxlims[i].highx) &&
  160.                     (y >= mboxlims[i].lowy) &&
  161.                     (y <= mboxlims[i].highy)) {
  162.             selected_type = MONTH;
  163.             current.tm_mday = 1;
  164.             current.tm_mon = i;
  165.             pw_write(main_pixwin,mboxlims[i].lowx,
  166.               mboxlims[i].lowy,7*ybox_width,ybox_height-1,PIX_NOT(PIX_DST),NULL,0,0);
  167.             break;
  168.         }
  169.     }
  170. }
  171.  
  172. Notify_value
  173. check_close(client, event, arg, when)
  174. Notify_client client;
  175. Event *event;
  176. Notify_arg arg;
  177. Notify_event_type when;
  178. {
  179.     /* check for L7 key and close frame if found */
  180.     /*** DEBUG ***/
  181.     /*
  182.     fprintf(stderr, "checking for L7: event = %d\n", event_id(event));
  183.     */
  184.     if (event_id(event) == KEY_LEFT(7) && event_is_up(event))
  185.         return (myframe_interposer(client, event, arg, when));
  186.     else
  187.         return (notify_next_event_func(client, event, arg, when));
  188. }
  189.  
  190. close_frame()
  191. {
  192.     Icon cur_icon;
  193.  
  194.     /* save some information as we close */
  195.     if (mainsw_state == DISPLAYING_DAY && day_is_open)
  196.         close_day();
  197.     /* if frame not closed yet, close it now (for the canvas) */
  198.     if (!(int)window_get(frame, FRAME_CLOSED))
  199.         window_set(frame, FRAME_CLOSED, TRUE, 0);
  200.     olddate = current;
  201.     if (fframe) {
  202.         /* kill off future appt popup */
  203.         window_destroy(fframe);
  204.         fframe = 0;
  205.     }
  206. #ifndef NO_SUN_MOON
  207.     /* kill sun/moon data frames */
  208.     if (mframe)
  209.         mframe_done(0);
  210.     if (sframe)
  211.         sframe_done(0);
  212. #endif
  213.     check_calendar();    /* update icon */
  214.     if (show_time) {
  215.         /* update time label */
  216.         strcpy(timestr, todays_date+10);
  217.         if (update_interval == 60)
  218.             /* display hh:mm */
  219.             timestr[6] = '\0';
  220.         else
  221.             /* display hh:mm:ss */
  222.             timestr[9] = '\0';
  223.         cur_icon = (Icon) window_get(frame, FRAME_ICON);
  224.         icon_set(cur_icon, ICON_LABEL, timestr, 0);
  225.         window_set(frame, FRAME_ICON, cur_icon, 0);
  226.     }
  227. }
  228.