home *** CD-ROM | disk | FTP | other *** search
- /*
- * $Header: event.c,v 2.4 91/03/27 16:45:33 billr Exp $
- */
- /*
- * event.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.
- */
- /********************************************************
- * *
- * Main driver and month and year event routines *
- * for main subwindow *
- * *
- ********************************************************/
-
-
- #include <stdio.h>
- #include <suntool/sunview.h>
- #include <suntool/panel.h>
- #include <suntool/canvas.h>
- #include <suntool/seln.h>
- #include <sys/file.h>
- #include "ct.h"
- #include "event.h"
-
- extern Frame frame;
- extern Frame fframe, sframe, mframe, fileframe;
- extern struct tm olddate, closedate;
- extern int update_interval, show_time;
- extern char timestr[];
- extern Icon icon;
- extern int monday_first, hour24;
- extern Pixfont *sfont;
- extern Seln_client s_client;
- extern int locked;
- Notify_value myframe_interposer();
-
- void
- mainsw_inputevent(canvas, event)
- Canvas canvas;
- Event *event;
- {
- if (locked) /* no updates allowed */
- return;
-
- /* check for L7 key and close frame if found */
- if (event_id(event) == KEY_LEFT(7) && event_is_up(event)) {
- close_frame();
- #ifdef SUN3_5
- } else if (event_id(event) == KEY_LEFT(5) && event_is_up(event)) {
- /* expose (L5) event */
- int rootfd, myfd;
- struct screen frame_screen;
-
- /* Get root window from frame's desktop */
- myfd = (int)window_get(frame, WIN_FD);
- (void)win_screenget(myfd, &frame_screen);
- rootfd = open(frame_screen.scr_rootname, O_RDONLY, 0);
- if (rootfd == -1) {
- err_rpt("couldn't open root screen", NON_FATAL);
- return;
- }
- if (win_fdtonumber(myfd) == win_getlink(rootfd, WL_TOPCHILD))
- /* we're on top */
- wmgr_bottom(myfd, rootfd);
- else
- wmgr_top(myfd, rootfd);
- close(rootfd);
- #endif
- } else {
- switch (mainsw_state) {
- case DISPLAYING_DAY:
- if (event_id(event) == KEY_LEFT(6) && event_is_up(event)) {
- if (seln_acquire(s_client, SELN_PRIMARY) != SELN_PRIMARY) {
- err_rpt("Can't acquire selection primary", NON_FATAL);
- return;
- }
- if (seln_acquire(s_client, SELN_SHELF) != SELN_SHELF) {
- err_rpt("Can't acquire selection shelf", NON_FATAL);
- return;
- }
- seln_report_event(s_client, event);
- }
- day_inputevent(canvas, event);
- break;
- case DISPLAYING_WEEK:
- week_inputevent(canvas, event);
- break;
- case DISPLAYING_MONTH:
- month_inputevent(canvas, event);
- break;
- case DISPLAYING_YEAR:
- year_inputevent(canvas, event);
- break;
- }
- }
- }
-
- month_inputevent(canvas, event)
- Canvas canvas;
- Event *event;
- {
- int i, x, y, week_index, new_day;
-
- /* translate coordinates to pixwin space */
- event = canvas_window_event(canvas, event);
- x = event_x(event);
- y = event_y(event);
- if (event_id(event) != MS_LEFT)
- return;
-
- if (event_is_up(event)) { /* Button up. */
- fix_current_day();
- if (selected_type == DAY) {
- mainsw_state = DISPLAYING_DAY;
- window_set(canvas, WIN_CURSOR, day_cursor, 0);
- draw_day();
- }
- else if (selected_type == WEEK) {
- mainsw_state = DISPLAYING_WEEK;
- window_set(canvas, WIN_CURSOR, week_cursor, 0);
- draw_week();
- }
- return;
- }
-
- /* Button down. */
- selected_type = NONE;
- for (i=0; i<monthlength(current.tm_mon); i++) { /* In a day? */
- if ((x >= boxlims[i].lowx) &&
- (x <= boxlims[i].highx) &&
- (y >= boxlims[i].lowy) &&
- (y <= boxlims[i].highy)) {
- current.tm_mday = i + 1;
- selected_type = DAY;
- pw_write(main_pixwin,boxlims[i].lowx+3,
- boxlims[i].lowy+3,58,58,PIX_NOT(PIX_DST),NULL,0,0);
- return;
- }
- }
- for (i=0; i<6; i++) { /* No. In a week? */
- if (week_arrows[i].active == 0)
- return;
- if ((x >= week_arrows[i].left) &&
- (x <= week_arrows[i].right) &&
- (y >= week_arrows[i].top) &&
- (y <= week_arrows[i].bottom)) {
- week_index = i;
- current.tm_mday = -current.tm_wday + 1 + (7 * week_index);
- if (monday_first) {
- current.tm_mday++;
- if (current.tm_wday == SUN)
- current.tm_mday -= 7;
- }
- selected_type = WEEK;
- pw_write(main_pixwin,week_arrows[week_index].left,
- week_arrows[week_index].top,smallarrow_pr->pr_size.x,
- smallarrow_pr->pr_size.y,PIX_SRC^PIX_DST,
- smallarrow_pr,0,0);
- return;
- }
- }
- }
-
- year_inputevent(canvas, event)
- Canvas canvas;
- Event *event;
- {
- int x, y, i;
- static int mday;
-
- /* translate coordinates to pixwin space */
- event = canvas_window_event(canvas, event);
- x = event_x(event);
- y = event_y(event);
- if (event_id(event) != MS_LEFT)
- return;
- if (event_is_up(event)) { /* Button up. */
- if (selected_type == MONTH) {
- mainsw_state = DISPLAYING_MONTH;
- window_set(canvas, WIN_CURSOR, month_cursor, 0);
- draw_month();
- }
- return;
- }
-
- /* Button down. */
- selected_type = NONE;
- for (i=0; i<12; i++) { /* In a month? */
- if ((x >= mboxlims[i].lowx) &&
- (x <= mboxlims[i].highx) &&
- (y >= mboxlims[i].lowy) &&
- (y <= mboxlims[i].highy)) {
- selected_type = MONTH;
- current.tm_mday = 1;
- current.tm_mon = i;
- pw_write(main_pixwin,mboxlims[i].lowx,
- mboxlims[i].lowy,7*ybox_width,ybox_height-1,PIX_NOT(PIX_DST),NULL,0,0);
- break;
- }
- }
- }
-
- Notify_value
- check_close(client, event, arg, when)
- Notify_client client;
- Event *event;
- Notify_arg arg;
- Notify_event_type when;
- {
- /* check for L7 key and close frame if found */
- /*** DEBUG ***/
- /*
- fprintf(stderr, "checking for L7: event = %d\n", event_id(event));
- */
- if (event_id(event) == KEY_LEFT(7) && event_is_up(event))
- return (myframe_interposer(client, event, arg, when));
- else
- return (notify_next_event_func(client, event, arg, when));
- }
-
- close_frame()
- {
- Icon cur_icon;
-
- /* save some information as we close */
- if (mainsw_state == DISPLAYING_DAY && day_is_open)
- close_day();
- /* if frame not closed yet, close it now (for the canvas) */
- if (!(int)window_get(frame, FRAME_CLOSED))
- window_set(frame, FRAME_CLOSED, TRUE, 0);
- olddate = current;
- get_today();
- closedate = today;
- if (fframe) {
- /* kill off future appt popup */
- window_destroy(fframe);
- fframe = 0;
- }
- /* hide file frame */
- window_set(fileframe, WIN_SHOW, FALSE, 0);
- #ifndef NO_SUN_MOON
- /* kill sun/moon data frames */
- if (mframe)
- mframe_done(0);
- if (sframe)
- sframe_done(0);
- #endif
- check_calendar(); /* update icon */
- if (show_time)
- /* update time label */
- update_icon_time();
- }
-
- /* update the time field of the current icon */
- update_icon_time()
- {
- Icon cur_icon;
-
- format_icon_time();
- cur_icon = (Icon) window_get(frame, FRAME_ICON);
- icon_set(cur_icon, ICON_LABEL, timestr, 0);
- window_set(frame, FRAME_ICON, cur_icon, 0);
- }
-
- format_icon_time()
- {
- if (update_interval >= 60)
- /* display hh:mm */
- sprintf(timestr, " %2d:%02d", today.tm_hour, today.tm_min);
- else
- /* display hh:mm:ss */
- sprintf(timestr, " %2d:%02d:%02d", today.tm_hour, today.tm_min, today.tm_sec);
- if (!hour24) {
- /* display am/pm for 12-hour time */
- if (today.tm_hour > 12) {
- strcat(timestr, "pm");
- timestr[1] = ((today.tm_hour - 12) / 10) + '0';
- timestr[2] = ((today.tm_hour - 12) % 10) + '0';
- } else if (today.tm_hour == 12) {
- strcat(timestr, "pm");
- } else {
- strcat(timestr, "am");
- }
- if (timestr[1] == '0')
- timestr[1] = ' ';
- }
- }
-