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

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