home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume17 / calentool / part20 / wevent.c < prev   
Encoding:
C/C++ Source or Header  |  1991-04-07  |  3.8 KB  |  126 lines

  1. /*
  2.  * $Header: wevent.c,v 2.3 91/02/01 12:21:14 billr Exp $
  3.  */
  4. /*
  5.  * wevent.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, 1991 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.  *      Week event routines for main subwindow.        *
  27.  *                            *
  28.  ********************************************************/
  29.  
  30.  
  31. #include <stdio.h>
  32. #include <suntool/sunview.h>
  33. #include <suntool/canvas.h>
  34. #include <suntool/panel.h>
  35. #include "ct.h"
  36. #include "event.h"
  37.  
  38. extern Frame prompt_frame;
  39. extern int monday_first;
  40. extern int n_slots;
  41.  
  42. week_inputevent(canvas, event) 
  43. Canvas canvas;
  44. Event *event;
  45.     int i = -1;
  46.     int x, y;
  47.     static int day_chosen_from_week;
  48.     extern void fix_current_day();
  49.  
  50.     /* translate coordinates to pixwin space */
  51.     event = canvas_window_event(canvas, event);
  52.         if (event_id(event) != MS_LEFT)        /* Ignore kbd events. */
  53.                 return;
  54.  
  55.         if (event_is_down(event)) {               /* Button down. */
  56.         day_chosen_from_week = -1;
  57.                 for (i=0; i<nr_weekdays; i++) {
  58.             x = event_x(event);
  59.             y = event_y(event);
  60.                         if (x >= week_boxes[i].wday_pos.left && x <= week_boxes[i].wday_pos.right &&
  61.                             y >= week_boxes[i].wday_pos.top && y <= week_boxes[i].wday_pos.bottom) {
  62.                 day_chosen_from_week = i;
  63.                 pw_write(main_pixwin, week_boxes[i].wday_pos.left+1,
  64.                                   week_boxes[i].wday_pos.top+1, weekslot_width-2,
  65.                                   (weekslot_height)*n_slots-2, PIX_NOT(PIX_DST), NULL,0,0);
  66.                 return;
  67.             }
  68.             /* is cursor inside a "more" button ? */
  69.             if (x>=week_boxes[i].moreb_pos.left && x<=week_boxes[i].moreb_pos.right &&
  70.                 y>=week_boxes[i].moreb_pos.top && y<=week_boxes[i].moreb_pos.bottom) {
  71.                 if (week_boxes[i].more) {
  72.                     /* "more" button is active */
  73.                     day_chosen_from_week = i+10;
  74.                     return;
  75.                 }
  76.             }
  77.         }
  78.         return;            /* Mouse wasn't in any square. */
  79.     } else {                        /* Button up. */
  80.         if (day_chosen_from_week == -1)
  81.             return;
  82.         if (day_chosen_from_week >= 10) {
  83.             /* more button selected */
  84.             /* print info message */
  85.             do_more_msg(day_chosen_from_week-10);
  86.             return;
  87.         }
  88.         current.tm_mday -= current.tm_wday;
  89.         if (monday_first) {
  90.             if (current.tm_wday == SUN)
  91.                 current.tm_mday -= 7;
  92.             if (nr_weekdays == 7)
  93.                 current.tm_mday++;
  94.         }
  95.         current.tm_mday += day_chosen_from_week;
  96.         fix_current_day();
  97.         if (nr_weekdays < 7) {
  98.             current.tm_mday++;
  99.             fix_current_day();
  100.         }
  101.         mainsw_state = DISPLAYING_DAY;
  102.         window_set(canvas, WIN_CURSOR, day_cursor, 0);
  103.         draw_day();
  104.     }
  105. }
  106.  
  107. /* display more popup message */
  108. do_more_msg(i)
  109. int i;
  110. {
  111.     int width, height, left, bottom;
  112.  
  113.     /* get x,y position of canvas window on the screen so we
  114.      * can center this one in it.
  115.      */
  116.     create_prompt_frame("Select this day to view additional appointments.", FALSE);
  117.     width = (int) window_get(prompt_frame, WIN_WIDTH);
  118.     height = (int) window_get(prompt_frame, WIN_HEIGHT);
  119.     left = (week_boxes[i].wday_pos.right + week_boxes[i].wday_pos.left - width) / 2;
  120.     bottom = (week_boxes[i].wday_pos.top + week_boxes[i].wday_pos.bottom - height) / 2;
  121.     window_set(prompt_frame, WIN_X, left, WIN_Y, bottom, 0);
  122.     (void) window_loop(prompt_frame);
  123.     window_set(prompt_frame, WIN_SHOW, FALSE, 0);
  124. }
  125.