home *** CD-ROM | disk | FTP | other *** search
- /*
- * $Header: devent.c,v 2.8 91/03/27 16:45:23 billr Exp $
- */
- /*
- * devent.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.
- */
- /********************************************************
- * *
- * Day event routines for main subwindow. *
- * *
- ********************************************************/
-
-
- #include <stdio.h>
- #include <suntool/sunview.h>
- #include <suntool/canvas.h>
- #include <suntool/panel.h>
- #include <suntool/menu.h>
- #include <suntool/seln.h>
- #include <sys/time.h>
- #include <fcntl.h>
- #include "ct.h"
- #include "event.h"
-
- extern Menu day_sel_menu;
- extern Frame attr_frame;
- extern Panel_item everyx_pi, repeat_pi, remind_pi;
- extern Panel_item whichwk_pi, marked_pi, advw_pi;
- extern Panel_item del_choice_pi;
- extern Panel_item runl_pi;
- extern Frame del_frame;
- extern Panel del_panel;
- extern Pixrect tri_right_pr, tri_up_pr;
- extern Pixrect *leftarrow, *rightarrow, *morebutton;
- extern int n_tslots, n_slots, start_hour;
- extern Seln_client s_client;
- int attr_bi;
- struct appt_entry shelf_appt = {0};
- int old_slot = -1; /* for text cursor location */
- int box_index, found_flag;
- char sel_text[MAX_STRLEN];
- static char *get_shelf();
- extern int chk_deleted();
-
- day_inputevent(canvas, event)
- Canvas canvas;
- Event *event;
- {
- Menu_item an_item;
- int x, y;
- int i, j, active_above, strl;
- struct appt_entry *aptr;
- static int start_arrow_box = -1, prev_box = 0;
- static int expecting = 0;
- char *paste_str;
-
- found_flag = 0; /* See if cursor is in a box. */
- /* translate coordinates back to pixwin space */
- event = canvas_window_event(canvas, event);
- x = event_x(event);
- y = event_y(event);
- if (event_id(event) == LOC_RGNEXIT && old_slot >= 0) {
- /* erase text cursor */
- text_cursor(old_slot);
- old_slot = -1;
- }
-
- for (box_index=0; box_index<n_slots; box_index++) {
- /* is cursor inside a slot ? */
- if (x>=slots[box_index].slot_pos.left && x<=slots[box_index].slot_pos.right &&
- y>=slots[box_index].slot_pos.top && y<=slots[box_index].slot_pos.bottom) {
- found_flag = FOUND_SLOT;
- break;
- }
- /* is cursor inside a "more" button ? */
- if (x>=slots[box_index].moreb_pos.left && x<=slots[box_index].moreb_pos.right &&
- y>=slots[box_index].moreb_pos.top && y<=slots[box_index].moreb_pos.bottom) {
- if (slots[box_index].active > 1) {
- /* "more" button is active */
- found_flag = FOUND_MORE;
- break;
- }
- }
- /* is cursor inside a "leftarrow" button ? */
- if (x>=slots[box_index].larrow_pos.left && x<=slots[box_index].larrow_pos.right &&
- y>=slots[box_index].larrow_pos.top && y<=slots[box_index].larrow_pos.bottom) {
- found_flag = FOUND_LARROW;
- break;
- }
- /* is cursor inside a "rightarrow" button ? */
- if (x>=slots[box_index].rarrow_pos.left && x<=slots[box_index].rarrow_pos.right &&
- y>=slots[box_index].rarrow_pos.top && y<=slots[box_index].rarrow_pos.bottom) {
- found_flag = FOUND_RARROW;
- break;
- }
- }
- if (old_slot >= 0) {
- /* erase text cursor at old location */
- text_cursor(old_slot);
- old_slot = -1;
- }
-
- if (!found_flag && !expecting)
- return(0); /* Not in a box => ignore. */
-
- if (event_id(event) == LOC_STILL || (event_is_button(event) && event_is_up(event))) {
- if (found_flag == FOUND_SLOT && box_index != old_slot)
- /* in a different slot than we were before */
- if (slots[box_index].active)
- /* display cursor at new location */
- text_cursor(box_index);
- }
- if (found_flag == FOUND_SLOT && event_id(event) == KEY_LEFT(8)
- && event_is_up(event)) {
- /*
- * Process a "Paste" ("Get") event by pasting the text
- * from the SHELF. Note that this is different from
- * pasting an appointment.
- */
- if (!slots[box_index].active)
- return(0);
- new_entry = 1; /* flag for file updating */
- strl = strlen(slots[box_index].cur_appt->str);
- paste_str = get_shelf();
- if (paste_str == NULL) {
- text_cursor(box_index);
- return(0);
- }
- strncpy(slots[box_index].cur_appt->str + strl, paste_str,
- min(strlen(paste_str),MAX_STRLEN - strl ));
- slots[box_index].cur_appt->str[min(strlen(paste_str) + strl, MAX_STRLEN)] = '\0';
- rewrite_string(box_index, JUSTIFY_LEFT);
- /* display cursor at new location */
- text_cursor(box_index);
- } else if (event_id(event) == KEY_LEFT(6) && event_is_up(event)) {
- /* put string for current appt on the shelf */
- if (found_flag == FOUND_SLOT && slots[box_index].active)
- /* we're in an active slot */
- strcpy(sel_text, slots[box_index].cur_appt->str);
- else
- sel_text[0] = '\0';
- } else if (found_flag == FOUND_SLOT && event_id(event) <= ASCII_LAST) {
- /* Process a kbd event. */
- if (!slots[box_index].active)
- return(0);
- if (event_id(event) == CTRL_R) {
- rewrite_string(box_index, JUSTIFY_LEFT);
- return(0);
- }
- if (slots[box_index].cur_appt->flags & READONLY)
- return(0);
- new_entry = 1; /* flag for file updating */
- strl = strlen(slots[box_index].cur_appt->str);
- if (event_id(event) == CTRL_U) {
- slots[box_index].cur_appt->str[0] = '\0';
- rewrite_string(box_index, JUSTIFY_LEFT);
- } else if (event_id(event) == CTRL_W) {
- while (strl > 0 && slots[box_index].cur_appt->str[strl-1] != ' ') {
- slots[box_index].cur_appt->str[strl-1] = '\0';
- strl--;
- }
- rewrite_string(box_index, JUSTIFY_RIGHT);
- } else if (event_id(event) == DEL || event_id(event) == BACKSPACE) {
- if (strl > 0) {
- slots[box_index].cur_appt->str[strl-1] = '\0';
- rewrite_string(box_index, JUSTIFY_RIGHT);
- }
- } else if (event_id(event) >= (int)' ' && strl < MAX_STRLEN-2) {
- slots[box_index].cur_appt->str[strl] = (char)event_id(event);
- slots[box_index].cur_appt->str[strl+1] = '\0';
- rewrite_string(box_index, JUSTIFY_RIGHT);
- }
- /* display cursor at new location */
- text_cursor(box_index);
- } else if (event_id(event) == MS_LEFT && event_is_down(event)) {
- /* LB down event */
- switch (found_flag) {
- case FOUND_SLOT:
- break;
- case FOUND_MORE:
- /* reverse video "more" button */
- pw_rop(main_pixwin, slots[box_index].moreb_pos.left, slots[box_index].moreb_pos.top,
- morebutton->pr_width, morebutton->pr_height, PIX_NOT(PIX_DST),
- morebutton, 0, 0);
- expecting = box_index + (FOUND_MORE<<8);
- break;
- case FOUND_LARROW:
- do_left_arrow(canvas, box_index);
- break;
- case FOUND_RARROW:
- do_right_arrow(canvas, box_index);
- break;
- }
- } else if (event_id(event) == MS_LEFT && event_is_up(event)) {
- /* Process an LB up click. */
- i = expecting>>8;
- if (expecting && found_flag != i) {
- /* return button to normal video */
- if (i == FOUND_MORE) {
- /* "more" button */
- i = expecting & 0xff;
- pw_rop(main_pixwin, slots[i].moreb_pos.left, slots[i].moreb_pos.top,
- morebutton->pr_width, morebutton->pr_height, PIX_SRC,
- morebutton, 0, 0);
- }
- } else {
- switch (found_flag) {
- case FOUND_SLOT:
- if (!read_only) {
- make_box_active(box_index);
- new_entry = 1;
- }
- break;
- case FOUND_MORE:
- next_appt(box_index, TRUE);
- /* normal video "more" button */
- pw_rop(main_pixwin, slots[box_index].moreb_pos.left, slots[box_index].moreb_pos.top,
- morebutton->pr_width, morebutton->pr_height, PIX_SRC,
- morebutton, 0, 0);
- break;
- case FOUND_LARROW:
- break;
- case FOUND_RARROW:
- break;
- }
- }
- expecting = 0;
- } else if (found_flag == FOUND_SLOT && event_id(event) == MS_MIDDLE) {
- /* Process a MB click. */
- if (event_is_down(event)) {
- /* try to start dragging from here */
- if (!slots[box_index].active || box_index >= n_tslots) {
- /* not allowed in notes slots, either */
- start_arrow_box = -1;
- return(0);
- }
- if ((slots[box_index].cur_appt->flags & READONLY) || read_only) {
- start_arrow_box = -1;
- return(0);
- }
- if (slots[box_index].cur_appt->arrows > 0) {
- /* remove old arrows and adjust counts */
- deactivate_lower_arrows(box_index, TRUE);
- j = slots[box_index].cur_appt->arrows;
- while (j > 0)
- slots[box_index+(j--)].count--;
- slots[box_index].cur_appt->arrows = 0;
- }
- prev_box = start_arrow_box = box_index;
- } else {
- if (box_index >= n_tslots) {
- /* mouse currently in notes section */
- if (start_arrow_box == -1)
- /* started in notes section, too */
- return(0);
- else
- /* truncate at start of notes section */
- box_index = n_tslots - 1;
- }
- /* end of dragging => end of arrow */
- if (box_index > start_arrow_box && start_arrow_box != -1) {
- int left = (dayslot_width-2)/2 - 8;
-
- i = start_arrow_box;
- slots[i].cur_appt->arrows = box_index - start_arrow_box;
- while (++i < box_index) {
- slots[i].count++;
- /*
- * erase arrow shaft on boxes - it will be
- * replaced by a real arrowshaft during redraw
- */
- pw_rop(main_pixwin, slots[i].slot_pos.left+left,
- slots[i].slot_pos.top+1,
- 16, dayslot_height-2,
- PIX_SRC^PIX_DST, arrowshaft_pr,
- 0, 0);
- }
- slots[i].count++;
- /*
- * erase arrow shaft on last box - it will be
- * replaced by an arrowhead during redraw
- */
- pw_rop(main_pixwin, slots[i].slot_pos.left+left,
- slots[i].slot_pos.top+1,
- 16, dayslot_height-2,
- PIX_SRC^PIX_DST, arrowshaft_pr,
- 0, 0);
- }
- start_arrow_box = -1;
- new_entry = 1;
- draw_day_appts();
- }
- } else if (found_flag == FOUND_SLOT && event_id(event) == LOC_DRAG) {
- /* mouse dragging - is it the middle button ? */
- if ((int)window_get(canvas, WIN_EVENT_STATE, MS_MIDDLE) && start_arrow_box >= 0) {
- int left = (dayslot_width-2)/2 - 8;
-
- if (box_index >= n_tslots)
- /* don't flow into notes section */
- box_index = n_tslots - 1;
- /*
- * xor arrow shaft thru current slot so
- * we can see where we're dragging
- */
- if (box_index > prev_box) {
- while (++prev_box <= box_index) {
- pw_rop(main_pixwin, slots[prev_box].slot_pos.left+left,
- slots[prev_box].slot_pos.top+1,
- 16, dayslot_height-2,
- PIX_SRC^PIX_DST, arrowshaft_pr,
- 0, 0);
- }
- prev_box = box_index;
- } else if (box_index < prev_box && box_index >= start_arrow_box) {
- /* going backwards - cleanup as we go */
- while (prev_box > box_index) {
- pw_rop(main_pixwin, slots[prev_box].slot_pos.left+left,
- slots[prev_box].slot_pos.top+1,
- 16, dayslot_height-2,
- PIX_SRC^PIX_DST, arrowshaft_pr,
- 0, 0);
- --prev_box;
- }
- }
- }
- } else if (found_flag == FOUND_SLOT && event_id(event) == MS_RIGHT && event_is_down(event)) {
- /* Process a RB click. */
- /*
- * display popup menu of choices, but first disable
- * certain entries if this is a readonly appointment
- * or an empty slot.
- */
- /* undelete - almost always inactive */
- an_item = menu_get(day_sel_menu, MENU_NTH_ITEM, MUNDELETE);
- menu_set(an_item, MENU_INACTIVE, TRUE, 0);
- if (!slots[box_index].first) {
- /* empty slot. only paste active */
- paste_only();
- } else if (slots[box_index].cur_appt->flags & READONLY) {
- /* readonly => paste and copy only */
- paste_only();
- /* copy */
- an_item = menu_get(day_sel_menu, MENU_NTH_ITEM, MCOPY);
- menu_set(an_item, MENU_INACTIVE, FALSE, 0);
- } else {
- /* delete */
- an_item = menu_get(day_sel_menu, MENU_NTH_ITEM, MDELETE);
- menu_set(an_item, MENU_INACTIVE, FALSE, 0);
- /* cut */
- an_item = menu_get(day_sel_menu, MENU_NTH_ITEM, MCUT);
- menu_set(an_item, MENU_INACTIVE, FALSE, 0);
- /* copy */
- an_item = menu_get(day_sel_menu, MENU_NTH_ITEM, MCOPY);
- menu_set(an_item, MENU_INACTIVE, FALSE, 0);
- /* modify */
- an_item = menu_get(day_sel_menu, MENU_NTH_ITEM, MMODIFY);
- menu_set(an_item, MENU_INACTIVE, FALSE, 0);
- for (aptr=slots[box_index].first; aptr; aptr=aptr->next)
- if (aptr->flags & DELETED) {
- if (!slots[box_index].active)
- /* only paste and undelete */
- paste_only();
- /* undelete */
- an_item = menu_get(day_sel_menu, MENU_NTH_ITEM, MUNDELETE);
- menu_set(an_item, MENU_INACTIVE, FALSE, 0);
- break;
- }
- }
- i = (int) menu_show(day_sel_menu, canvas, event, 0);
- if (i > 0) {
- switch (i) {
- case MDELETE:
- delete_appt(box_index, canvas);
- break;
- case MCUT:
- cut_appt(box_index, canvas);
- break;
- case MCOPY:
- copy_appt(box_index);
- break;
- case MPASTE:
- paste_appt(box_index);
- break;
- case MMODIFY:
- modify_appt(box_index, canvas);
- break;
- case MUNDELETE:
- undelete_appt(box_index);
- break;
- }
- if (new_entry) {
- close_day();
- draw_day(); /* redraw display */
- }
- }
- } else
- window_default_event_proc(canvas, event, 0);
- return(1);
- }
-
-
- /* make "paste" the only active menu entry */
- paste_only()
- {
- Menu_item an_item;
-
- /* delete */
- an_item = menu_get(day_sel_menu, MENU_NTH_ITEM, MDELETE);
- menu_set(an_item, MENU_INACTIVE, TRUE, 0);
- /* cut */
- an_item = menu_get(day_sel_menu, MENU_NTH_ITEM, MCUT);
- menu_set(an_item, MENU_INACTIVE, TRUE, 0);
- /* copy */
- an_item = menu_get(day_sel_menu, MENU_NTH_ITEM, MCOPY);
- menu_set(an_item, MENU_INACTIVE, TRUE, 0);
- /* modify */
- an_item = menu_get(day_sel_menu, MENU_NTH_ITEM, MMODIFY);
- menu_set(an_item, MENU_INACTIVE, TRUE, 0);
- }
-
- /* draw (or erase) text cursor in a day slot */
- text_cursor(slotno)
- int slotno;
- {
- int strl, x;
-
- strl = strlen(&slots[slotno].cur_appt->str[slots[slotno].cur_appt->sindex]);
- if (strl <= (day_message_size-1)) {
- x = slots[slotno].slot_pos.left + strl * font->pf_defaultsize.x;
- pw_write(main_pixwin, x, slots[slotno].slot_pos.bottom-4,
- 16, 16, PIX_SRC^PIX_DST, &tri_up_pr, 0, 0);
- }
- old_slot = slotno;
- }
-
- /* make slot active */
- make_box_active(bi)
- int bi;
- {
- add_to_slot(bi, NULL, TRUE);
- fill_appt(bi);
- rewrite_string(bi, JUSTIFY_LEFT);
- text_cursor(bi);
- }
-
- /* activate a hidden appt and make it visible */
- int
- activate_slot(bi, dpyflag)
- int bi;
- int dpyflag;
- {
- if (slots[bi].active <= 0)
- /* nothing to activate */
- return(0);
-
- if (dpyflag)
- draw_day_appts(); /* redraw display */
-
- return(1);
- }
-
- /* clears a day slot */
- deactivate_slot(bi, dpyflag)
- int bi, dpyflag;
- {
- if (!dpyflag)
- return;
- /* erase text cursor at old location */
- if (old_slot >= 0) {
- text_cursor(old_slot);
- old_slot = -1;
- }
- /* erase displayed slot */
- if (!ymd_compare(current, today))
- pw_write(main_pixwin, slots[bi].slot_pos.left, slots[bi].slot_pos.top,
- dayslot_width, dayslot_height, PIX_SRC, timeslot_td_pr, 0, 0);
- else
- pw_write(main_pixwin, slots[bi].slot_pos.left+1, slots[bi].slot_pos.top+1,
- dayslot_width-2, dayslot_height-2, PIX_CLR, NULL, 0, 0);
- if (slots[bi].cur_appt->arrows > 0)
- deactivate_lower_arrows(bi, dpyflag);
- }
-
- /* clear any displayed arrowshafts and arrowheads */
- deactivate_lower_arrows(bi, dpyflag)
- int bi, dpyflag;
- {
- int narrows, offset;
-
- if (!dpyflag)
- return;
- narrows = slots[bi].cur_appt->arrows;
- offset = (slots[bi].count - slots[bi].active + 1) * 40;
- while (narrows-- > 0) {
- bi++;
- if (slots[bi].active)
- continue;
- /* erase displayed arrowshaft or arrowhead */
- if (!ymd_compare(current, today))
- pw_write(main_pixwin, slots[bi].slot_pos.left+1+offset,
- slots[bi].slot_pos.top+1, 16,
- dayslot_height-2, PIX_SRC, timeslot_td_pr, 0, 0);
- else
- pw_write(main_pixwin, slots[bi].slot_pos.left+1+offset,
- slots[bi].slot_pos.top+1, 16,
- dayslot_height-2, PIX_CLR, NULL, 0, 0);
- }
- }
-
- /* fill in appt struct with current info */
- fill_appt(bi)
- int bi;
- {
- int s_hour, s_minute, n_arrows;
-
- slots[bi].cur_appt->year = current.tm_year;
- slots[bi].cur_appt->month = current.tm_mon;
- slots[bi].cur_appt->day = current.tm_mday;
- slots[bi].cur_appt->arrows = 0;
- slots[bi].cur_appt->flags = slots[bi].cur_appt->repeat = 0;
- slots[bi].cur_appt->lookahead = slots[bi].cur_appt->sindex = 0;
- slots[bi].cur_appt->runlength = 0;
- slots[bi].cur_appt->warn = 10;
- if (bi >= n_tslots) {
- /* notes section */
- slots[bi].cur_appt->hour = 99;
- slots[bi].cur_appt->minute = 0;
- slots[bi].cur_appt->flags = A_NOTE;
- } else {
- /* regular appt */
- slots[bi].cur_appt->hour = bi/2 + start_hour;
- slots[bi].cur_appt->minute = (bi % 2) * 30;
- }
- slots[bi].cur_appt->str[0] = '\0';
- }
-
- /*
- * Display delete popup window to let user choose delete mode for
- * recurring appts (delete this one only or delete all), otherwise,
- * just wipe it out with no options.
- */
- delete_appt(bi, canvas)
- int bi;
- Canvas canvas;
- {
- Rect *canvas_r;
- int top, left, width, height;
-
- if (slots[bi].cur_appt->flags & READONLY) {
- err_rpt("Can't delete a read-only appt", NON_FATAL);
- return;
- }
- if (Repeating(slots[bi].cur_appt->flags)) {
- attr_bi = bi; /* set global index for notify func */
-
- /* get x,y position of canvas window on the screen so we
- * can center popup window in it.
- */
- canvas_r = (Rect *) window_get(canvas, WIN_RECT);
- panel_set(del_choice_pi, PANEL_CHOICE_STRINGS,
- "Delete this occurrance only",
- "Delete all occurrances", 0,
- PANEL_CLIENT_DATA, 0,
- 0);
- window_fit(del_panel);
- window_fit(del_frame);
- width = (int) window_get(del_frame, WIN_WIDTH);
- height = (int) window_get(del_frame, WIN_HEIGHT);
- left = canvas_r->r_left + (canvas_r->r_width - width) / 2;
- top = canvas_r->r_top + (canvas_r->r_height - height) / 2;
- window_set(del_frame, WIN_X, left, WIN_Y, top, 0);
- panel_set_value(del_choice_pi, 0);
-
- window_loop(del_frame); /* let user select things */
- } else {
- cut_delete(bi);
- new_entry = 1;
- }
- }
-
- cut_appt(bi, canvas)
- int bi;
- Canvas canvas;
- {
- Rect *canvas_r;
- int top, left, width, height;
- int i;
-
- /* cut (delete) current entry, saving the info on the "shelf" */
- if (slots[bi].cur_appt->flags & READONLY) {
- err_rpt("Can't cut a read-only appt", NON_FATAL);
- return;
- }
- shelf_appt = *slots[bi].cur_appt;
- if (Repeating(slots[bi].cur_appt->flags)) {
- attr_bi = bi; /* set global index for notify func */
-
- /* get x,y position of canvas window on the screen so we
- * can center popup window in it.
- */
- canvas_r = (Rect *) window_get(canvas, WIN_RECT);
- panel_set(del_choice_pi, PANEL_CHOICE_STRINGS,
- "Move this occurrance only",
- "Move all occurrances", 0,
- PANEL_CLIENT_DATA, 1,
- 0);
- window_fit(del_panel);
- window_fit(del_frame);
- width = (int) window_get(del_frame, WIN_WIDTH);
- height = (int) window_get(del_frame, WIN_HEIGHT);
- left = canvas_r->r_left + (canvas_r->r_width - width) / 2;
- top = canvas_r->r_top + (canvas_r->r_height - height) / 2;
- window_set(del_frame, WIN_X, left, WIN_Y, top, 0);
- panel_set_value(del_choice_pi, 0);
-
- window_loop(del_frame); /* let user select things */
- } else {
- cut_delete(bi);
- new_entry = 1;
- }
- }
-
- cut_delete(bi)
- int bi;
- {
- int j;
- struct appt_entry *aptr, *cptr, *optr;
-
- cptr = slots[bi].cur_appt;
- slots[bi].count--;
- slots[bi].active--;
- deactivate_slot(bi, TRUE);
- if ( (j = cptr->arrows) > 0) {
- /* adjust counts */
- while (j > 0)
- slots[bi+(j--)].count--;
- }
- if (slots[bi].cur_appt == slots[bi].first) {
- /* displaying first entry in list */
- /* see if there's any more */
- if (slots[bi].first->next)
- slots[bi].first = slots[bi].first->next;
- else {
- /* last one */
- slots[bi].first = NULL;
- slots[bi].active = 0;
- }
- slots[bi].cur_appt = slots[bi].first;
- } else {
- /* not first, so find previous one to this */
- for (aptr=slots[bi].first; slots[bi].cur_appt!=aptr; optr=aptr,aptr=aptr->next)
- ;
- slots[bi].cur_appt = optr->next = aptr->next;
- if (!optr->next)
- slots[bi].cur_appt = slots[bi].first;
- }
- free(cptr);
- (void)activate_slot(bi, TRUE); /* show any hidden appts */
- }
-
- copy_appt(bi)
- int bi;
- {
- /* copy current entry, saving the info on the "shelf" */
- shelf_appt = *slots[bi].cur_appt;
- }
-
- paste_appt(bi)
- int bi;
- {
- int j;
-
- /* insert the saved entry (if any) */
- if (shelf_appt.str[0] == '\0') {
- err_rpt("nothing to paste", NON_FATAL);
- return;
- }
- shelf_appt.year = current.tm_year;
- shelf_appt.month = current.tm_mon;
- shelf_appt.day = current.tm_mday;
- if (shelf_appt.flags & EVERY_SOMEDAY) {
- /* change repeating appt to this day */
- shelf_appt.flags &= ~EVERY_SOMEDAY;
- shelf_appt.flags |= Setday(current.tm_wday);
- }
- if (bi >= n_tslots) {
- /* notes section */
- shelf_appt.hour = 99;
- shelf_appt.minute = 0;
- /* just in case converting from time to note */
- shelf_appt.flags |= A_NOTE;
- } else {
- /* regular appt */
- shelf_appt.hour = bi/2 + start_hour;
- shelf_appt.minute = (bi % 2) * 30;
- /* just in case converting from note to time */
- shelf_appt.flags &= ~MARKED_NOTE;
- }
- add_to_slot(bi, &shelf_appt, TRUE);
- new_entry = 1;
- }
-
- /*
- * Display attributes popup window to let user modify
- * various appointment options (such as repeat interval,
- * etc.)
- */
- modify_appt(bi, canvas)
- int bi;
- Canvas canvas;
- {
- Rect *canvas_r;
- int top, left, width, height;
-
- if (slots[bi].cur_appt->flags & READONLY) {
- err_rpt("Can't modify a read-only appt", NON_FATAL);
- return;
- }
- attr_bi = bi; /* set global index for notify func */
- set_attr(); /* set panel item current values */
-
- /* get x,y position of canvas window on the screen so we
- * can center this one in it.
- */
- canvas_r = (Rect *) window_get(canvas, WIN_RECT);
- width = (int) window_get(attr_frame, WIN_WIDTH);
- height = (int) window_get(attr_frame, WIN_HEIGHT);
- left = canvas_r->r_left + (canvas_r->r_width - width) / 2;
- top = canvas_r->r_top + (canvas_r->r_height - height) / 2;
- window_set(attr_frame, WIN_X, left, WIN_Y, top, 0);
-
- window_loop(attr_frame); /* let user select things */
- window_set(attr_frame, WIN_SHOW, FALSE, 0);
- }
-
- /* undelete a recurring appointment for this day */
- /* we only get here if a deleted appt exists */
- undelete_appt(bi)
- int bi;
- {
- struct appt_entry *aptr, *optr;
-
- /* search list to find deleted entry */
- for (optr=aptr=slots[bi].first; aptr; optr=aptr,aptr=aptr->next)
- if (aptr->flags & DELETED)
- break;
- if (aptr == slots[bi].first)
- slots[bi].first = aptr->next;
- else
- optr->next = aptr->next;
- slots[bi].count++;
- slots[bi].active++;
- if (slots[bi].active == 1) {
- slots[bi].cur_appt = slots[bi].first;
- (void)activate_slot(bi, TRUE);
- }
- free(aptr);
- new_entry = 1;
- }
-
- set_attr()
- {
- int everyx_val = 0, whichwk_val = 0;
- char str[5];
- struct appt_entry *apt = slots[attr_bi].cur_appt;
-
- panel_set_value(repeat_pi, ""); /* set default */
- panel_set_value(remind_pi, ""); /* set default */
- panel_set_value(runl_pi, ""); /* set default */
- if (apt->flags & EVERY_MON_FRI)
- everyx_val |= 0x1;
- else if (apt->flags & ALL_DAYS)
- everyx_val |= 0x2;
- if (apt->flags & ALL_MONTHS)
- everyx_val |= 0x8;
- if (apt->flags & ALL_YEARS)
- everyx_val |= 0x10;
- if (apt->flags & EVERY_SOMEDAY) {
- everyx_val |= 0x4;
- if (apt->repeat == ALL_WEEKS)
- whichwk_val = 0x40;
- else
- whichwk_val = apt->repeat;
- panel_set(repeat_pi, PANEL_SHOW_ITEM, FALSE, 0);
- panel_set(whichwk_pi, PANEL_SHOW_ITEM, TRUE, 0);
- } else {
- if (apt->repeat) {
- sprintf(str, "%d", apt->repeat);
- panel_set_value(repeat_pi, str);
- }
- panel_set(whichwk_pi, PANEL_SHOW_ITEM, FALSE, 0);
- panel_set(repeat_pi, PANEL_SHOW_ITEM, TRUE, 0);
- }
- panel_set_value(everyx_pi, everyx_val);
- panel_set_value(whichwk_pi, whichwk_val);
- if (apt->flags & LOOKAHEAD) {
- sprintf(str, "%d", apt->lookahead);
- panel_set_value(remind_pi, str);
- }
- if (apt->flags & RUN) {
- sprintf(str, "%d", apt->runlength);
- panel_set_value(runl_pi, str);
- }
- panel_set_value(marked_pi, (apt->flags & MARKED ? 1 : 0));
- sprintf(str, "%d", apt->warn);
- panel_set_value(advw_pi, str);
- if (apt->flags & A_NOTE)
- panel_set(marked_pi, PANEL_SHOW_ITEM, TRUE, 0);
- else
- panel_set(marked_pi, PANEL_SHOW_ITEM, FALSE, 0);
- }
-
- /* "more" button selected. Display next appt in rotation. */
- next_appt(bi, dpyflag)
- int bi;
- int dpyflag;
- {
- static int loopcnt = 0;
-
- if (slots[bi].active)
- deactivate_slot(bi, dpyflag);
-
- if (slots[bi].cur_appt->next == NULL) {
- /* end of the chain */
- slots[bi].cur_appt = slots[bi].first;
- if (loopcnt) {
- /* infinite loop detected */
- loopcnt = 0;
- return;
- } else
- ++loopcnt;
- } else
- /* activate next in chain */
- slots[bi].cur_appt = slots[bi].cur_appt->next;
- /* make sure it is not a deleted one */
- if (chk_deleted(&slots[bi], slots[bi].cur_appt))
- next_appt(bi, dpyflag); /* try next in chain */
- else if (!activate_slot(bi, dpyflag))
- next_appt(bi, dpyflag); /* try next in chain */
- loopcnt = 0;
- }
-
- /* left scroll arrow selected */
- do_left_arrow(canvas, bi)
- Canvas canvas;
- int bi;
- {
- struct timeval timeout;
- Event event;
- int fd, ertn, flags;
-
- if (!slots[bi].active || strlen(slots[bi].cur_appt->str) < day_message_size)
- return;
- timeout.tv_sec = 0L;
- timeout.tv_usec = 100000L; /* 1/10 sec */
- fd = (int)window_get(canvas, WIN_FD);
- flags = fcntl(fd, F_GETFL, 0);
- (void)fcntl(fd, F_SETFL, flags|FNDELAY);
- /* reverse video the arrow */
- pw_rop(main_pixwin, slots[bi].larrow_pos.left, slots[bi].larrow_pos.top,
- 19, 14, PIX_NOT(PIX_DST), leftarrow, 0, 0);
- while (TRUE) {
- if (slots[bi].cur_appt->sindex < strlen(slots[bi].cur_appt->str)) {
- ++slots[bi].cur_appt->sindex;
- rewrite_string(bi, JUSTIFY_INDEX);
- /* reverse video the arrow (rewrite changed it) */
- pw_rop(main_pixwin, slots[bi].larrow_pos.left, slots[bi].larrow_pos.top,
- 19, 14, PIX_NOT(PIX_DST), leftarrow, 0, 0);
- }
- /* do this garbage to handle a repeat function */
- (void)select(0, NULL, NULL, NULL, &timeout);
- ertn = window_read_event(canvas, &event);
- if (ertn != -1 && event_is_up(&event))
- break;
- }
- /* put arrow back to normal */
- pw_rop(main_pixwin, slots[bi].larrow_pos.left, slots[bi].larrow_pos.top,
- 19, 14, PIX_SRC, leftarrow, 0, 0);
- (void)fcntl(fd, F_SETFL, flags & ~FNDELAY);
- }
-
- /* right scroll arrow selected */
- do_right_arrow(canvas, bi)
- Canvas canvas;
- int bi;
- {
- struct timeval timeout;
- Event event;
- int fd, ertn, flags;
-
- if (!slots[bi].active || strlen(slots[bi].cur_appt->str) < day_message_size)
- return;
- timeout.tv_sec = 0L;
- timeout.tv_usec = 100000L; /* 1/10 sec */
- fd = (int)window_get(canvas, WIN_FD);
- flags = fcntl(fd, F_GETFL, 0);
- (void)fcntl(fd, F_SETFL, flags|FNDELAY);
- /* reverse video the arrow */
- pw_rop(main_pixwin, slots[bi].rarrow_pos.left, slots[bi].rarrow_pos.top,
- 19, 14, PIX_NOT(PIX_DST), rightarrow, 0, 0);
- while (TRUE) {
- if (slots[bi].cur_appt->sindex > 0) {
- --slots[bi].cur_appt->sindex;
- rewrite_string(bi, JUSTIFY_INDEX);
- /* reverse video the arrow (rewrite changed it) */
- pw_rop(main_pixwin, slots[bi].rarrow_pos.left, slots[bi].rarrow_pos.top,
- 19, 14, PIX_NOT(PIX_DST), rightarrow, 0, 0);
- }
- /* do this garbage to handle a repeat function */
- (void)select(0, NULL, NULL, NULL, &timeout);
- ertn = window_read_event(canvas, &event);
- if (ertn != -1 && event_is_up(&event))
- break;
- }
- pw_rop(main_pixwin, slots[bi].rarrow_pos.left, slots[bi].rarrow_pos.top,
- 19, 14, PIX_SRC, rightarrow, 0, 0);
- (void)fcntl(fd, F_SETFL, flags & ~FNDELAY);
- }
-
- /*
- * get_shelf - get text from selection service shelf for copy
- * operation. From Mark Feblowitz <mdf0%shemesh@gte.COM>.
- */
- static
- char *
- get_shelf()
- {
- Seln_holder holder;
- Seln_request *buffer;
-
- holder = seln_inquire(SELN_SHELF);
- /* do we have the shelf? */
- if (!seln_holder_same_process(&holder)) {
- buffer = seln_ask(&holder, SELN_REQ_CONTENTS_ASCII, 0, 0);
- (void) strncpy(sel_text, buffer->data + sizeof(Seln_attribute),
- MAX_STRLEN-1);
- sel_text[MAX_STRLEN-1] = '\0';
- if (strlen(sel_text) == 0)
- /* empty string is no sel. */
- return(NULL);
- sel_text[MAX_STRLEN-1] = '\0';
- }
- return(sel_text);
- }
-
- /*
- * respond to function keys the selection service thinks
- * are important
- */
- void
- sel_func_key_proc(client_data, args)
- char *client_data;
- Seln_function_buffer *args;
- {
- Seln_holder *holder;
- Seln_response resp;
-
- if ((resp = seln_figure_response(args, &holder)) == SELN_SHELVE) {
- /* put string for current appt on the shelf */
- if (found_flag == FOUND_SLOT && slots[box_index].active)
- /* we're in an active slot */
- strcpy(sel_text, slots[box_index].cur_appt->str);
- else
- sel_text[0] = '\0';
- }
- }
-
- /*
- * called by selection svc library when someone requests our shelf
- * text. Abridged from the seln_demo() in the SunView manual.
- */
- Seln_result
- sel_reply_proc(item, context, length)
- Seln_attribute item;
- Seln_replier_data *context;
- int length;
- {
- char *destp, *seln = NULL;
- int size;
-
- if (context->rank == SELN_SHELF)
- seln = sel_text;
-
- switch (item) {
- case SELN_REQ_CONTENTS_ASCII:
- /* send the contents of the selection buffer */
- if (seln == NULL)
- return(SELN_DIDNT_HAVE);
- context->context = seln;
- size = strlen(seln);
- destp = (char *)context->response_pointer;
- /* allow for padding */
- (void) strncpy(destp, seln, length-8);
- destp += size;
- /* pad to long word */
- while ((int)destp % 4 != 0)
- *destp++ = '\0';
- context->response_pointer = (char **)destp;
- *context->response_pointer++ = 0;
- break;
-
- case SELN_REQ_YIELD:
- *context->response_pointer++ = (char *)SELN_SUCCESS;
- break;
-
- case SELN_REQ_BYTESIZE:
- if (seln == NULL)
- return(SELN_DIDNT_HAVE);
- *context->response_pointer++ = (char *)strlen(seln);
- break;
-
- case SELN_REQ_END_REQUEST:
- break;
-
- default:
- return(SELN_UNRECOGNIZED);
- }
-
- return(SELN_SUCCESS);
- }
-