home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / sun / volume1 / tooltool2.1c / part04 / events.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-06-06  |  10.6 KB  |  370 lines

  1. /************************************************************************/
  2. /*    Copyright 1988 by Chuck Musciano and Harris Corporation        */
  3. /*                                    */
  4. /*    Permission to use, copy, modify, and distribute this software    */
  5. /*    and its documentation for any purpose and without fee is    */
  6. /*    hereby granted, provided that the above copyright notice    */
  7. /*    appear in all copies and that both that copyright notice and    */
  8. /*    this permission notice appear in supporting documentation, and    */
  9. /*    that the name of Chuck Musciano and Harris Corporation not be    */
  10. /*    used in advertising or publicity pertaining to distribution    */
  11. /*    of the software without specific, written prior permission.    */
  12. /*    Chuck Musciano and Harris Corporation make no representations    */
  13. /*    about the suitability of this software for any purpose.  It is    */
  14. /*    provided "as is" without express or implied warranty.        */
  15. /*                                    */
  16. /*    The sale of any product based wholely or in part upon the     */
  17. /*    technology provided by tooltool is strictly forbidden without    */
  18. /*    specific, prior written permission from Harris Corporation.    */
  19. /*    Tooltool technology includes, but is not limited to, the source    */
  20. /*    code, executable binary files, specification language, and    */
  21. /*    sample specification files.                    */
  22. /************************************************************************/
  23.  
  24. #include    <stdio.h>
  25. #include    <ctype.h>
  26.  
  27. #include    "tooltool.h"
  28.  
  29. #include    <suntool/tty.h>
  30.  
  31. PUBLIC    Tty    tty;
  32.  
  33. PRIVATE    int    value_invalid = FALSE;
  34. PRIVATE    struct    itimerval    timer_int;
  35.  
  36. /************************************************************************/
  37. /* These routines deal with managing tooltool events            */
  38. /************************************************************************/
  39.  
  40. /************************************************************************/
  41. PRIVATE    int    get_shifts(event)
  42.  
  43. Event    *event;
  44.  
  45. {    int    shifts = 0;
  46.  
  47.     if (event_shift_is_down(event))
  48.        shifts += S_SHIFT;
  49.     if (event_ctrl_is_down(event))
  50.        shifts += S_CONTROL;
  51.     if (event_meta_is_down(event))
  52.        shifts += S_META;
  53.     return(shifts);
  54. }
  55.  
  56. /************************************************************************/
  57. PRIVATE    int    is_a_function_key(event)
  58.  
  59. Event    *event;
  60.  
  61. {
  62.     return(event_is_key_left(event) || event_is_key_top(event) || event_is_key_right(event));
  63. }
  64.  
  65. /************************************************************************/
  66. PRIVATE    a_ptr    key_is_mapped(event)
  67.  
  68. Event    *event;
  69.  
  70. {    int    set, key;
  71.     a_ptr    a;
  72.  
  73.     if (event_is_key_left(event)) {
  74.        set = LEFT_KEY_SET;
  75.        key = event_id(event) - KEY_LEFT(1);
  76.        }
  77.     else if (event_is_key_top(event)) {
  78.        set = TOP_KEY_SET;
  79.        key = event_id(event) - KEY_TOP(1);
  80.        }
  81.     else if (event_is_key_right(event)) {
  82.        set = RIGHT_KEY_SET;
  83.        key = event_id(event) - KEY_RIGHT(1);
  84.        }
  85.     else
  86.        return(NULL);
  87.     return(tt_func_keys[set][key][get_shifts(event)]);
  88. }
  89.  
  90. /************************************************************************/
  91. PRIVATE    timer_proc()
  92.  
  93. {
  94.     if (tt_action_depth > 0)
  95.        tt_timer_pending = TRUE;
  96.     else
  97.        tt_do_action(tt_timer_action);
  98. }
  99.  
  100. /************************************************************************/
  101. EXPORT    Panel_setting    notify_proc(item, event)
  102.  
  103. Panel_item    item;
  104. Event        *event;
  105.  
  106. {    g_ptr    b;
  107.     char    *p, buf[1024];
  108.     int    i;
  109.     cv_ptr    cv;
  110.  
  111.     b = (g_ptr) panel_get(item, PANEL_CLIENT_DATA);
  112.     if (b->kind == GADGET_BUTTON)
  113.        tt_do_action(b->u.but.action[get_shifts(event)]);
  114.     else if (b->kind == GADGET_TEXT) {
  115.        if (index(b->u.tex.completion, event_id(event))) {
  116.           p = (char *) panel_get(item, PANEL_VALUE);
  117.           if (p = (char *) expand_filename(p))
  118.              panel_set(item, PANEL_VALUE, p, 0);
  119.           else
  120.              window_bell(panel_get(item, PANEL_PARENT_PANEL));
  121.           }
  122.        else if (index(b->u.tex.trigger, event_id(event)))
  123.           tt_do_action(b->u.tex.action);
  124.        else if (event_id(event) == '\t')
  125.           if (event_shift_is_down(event))
  126.              panel_backup_caret(panel_get(item, PANEL_PARENT_PANEL));
  127.           else
  128.              panel_advance_caret(panel_get(item, PANEL_PARENT_PANEL));
  129.        else if (!index(b->u.tex.ignore, event_id(event)))
  130.           return(PANEL_INSERT);
  131.        return(PANEL_NONE);
  132.        }
  133.     else if (b->kind == GADGET_CHOICE) {
  134.        i = (int) panel_get(item, PANEL_VALUE);
  135.        for (cv = b->u.cho.value; i && cv; i--, cv = cv->next)
  136.           ;
  137.        if (cv)
  138.           tt_do_action(cv->action);
  139.        }
  140.     else if (b->kind == GADGET_SLIDER)
  141.        tt_do_action(b->u.sli.action);
  142. }
  143.  
  144. /************************************************************************/
  145. EXPORT    event_proc(item, event)
  146.  
  147. Panel_item    item;
  148. Event        *event;
  149.  
  150. {    char    c;
  151.     g_ptr    b;
  152.     a_ptr    a;
  153.     d_ptr    d;
  154.  
  155.     d = (d_ptr) window_get(panel_get(item, PANEL_PARENT_PANEL), WIN_CLIENT_DATA);
  156.     b = (g_ptr) panel_get(item, PANEL_CLIENT_DATA);
  157.     if (event_is_ascii(event) || event_is_meta(event))
  158.        if (d->text_items_exist || tt_normal_off)
  159.           if (b->kind == GADGET_TEXT && event_id(event) == '\t')
  160.              notify_proc(item, event);
  161.           else
  162.              panel_default_handle_event(item, event);
  163.        else {
  164.           c = event_id(event);
  165.           if (tty)
  166.              ttysw_input(tty, &c, 1);
  167.           }
  168.     else if (is_a_function_key(event)) {
  169.        if (a = key_is_mapped(event)) {
  170.           if (event_is_down(event))
  171.              tt_do_action(a);
  172.           }
  173.        else if (!tt_function_off)
  174.           panel_default_handle_event(item, event);
  175.        }
  176.     else { /* handle each panel item type separately */
  177.        if (b->kind == GADGET_BUTTON) {
  178.           if (event_is_down(event) && event_id(event) == MS_RIGHT)
  179.              tt_do_action(menu_show(b->u.but.menu, d->panel, event, 0));
  180.           else
  181.              panel_default_handle_event(item, event);
  182.           }
  183.        else if (b->kind == GADGET_MENU) {
  184.           if (event_is_down(event) && event_id(event) == MS_RIGHT) {
  185.              a = (a_ptr) menu_show(b->u.men.menu, d->panel, event, 0);
  186.              if (value_invalid)
  187.                 value_invalid = FALSE;
  188.              else
  189.                 tt_do_action(a);
  190.              }
  191.           else
  192.              panel_default_handle_event(item, event);
  193.           }
  194.        else
  195.           panel_default_handle_event(item, event);
  196.        }
  197. }
  198.  
  199. /************************************************************************/
  200. EXPORT    background_proc(panel, event)
  201.  
  202. Panel    panel;
  203. Event    *event;
  204.  
  205. {    char    c;
  206.     a_ptr    a;
  207.     d_ptr    d;
  208.  
  209.     d = (d_ptr) window_get(panel, WIN_CLIENT_DATA);
  210.     if (event_is_ascii(event) || event_is_meta(event))
  211.        if (d->text_items_exist || tt_normal_off)
  212.           panel_default_handle_event(panel, event);
  213.        else {
  214.           c = event_id(event);
  215.           if (tty)
  216.              ttysw_input(tty, &c, 1);
  217.           }
  218.     else if (is_a_function_key(event)) {
  219.        if (a = key_is_mapped(event)) {
  220.           if (event_is_down(event))
  221.              tt_do_action(a);
  222.           }
  223.        else if (!tt_function_off)
  224.           panel_default_handle_event(panel, event);
  225.        }
  226.     else
  227.        panel_default_handle_event(panel, event);
  228. }
  229.  
  230. /************************************************************************/
  231. PRIVATE    Notify_value    handle_mouse(button, shift, tty, event, arg, type)
  232.  
  233. int            button;
  234. int            shift;
  235. Tty            tty;
  236. Event            *event;
  237. Notify_arg        arg;
  238. Notify_event_type    type;
  239.  
  240. {    int    x, y;
  241.     a_ptr    a;
  242.  
  243.     if (tt_mouse_chars) {
  244.        x = event_x(event) / charwidth_of(tt_a_font) + tt_mouse_base;
  245.        y = event_y(event) / charheight_of(tt_a_font) + tt_mouse_base;
  246.        }
  247.     else {
  248.        x = event_x(event) + tt_mouse_base;
  249.        y = event_y(event) + tt_mouse_base;
  250.        }
  251.     if (tt_mouse[button][shift].defined == MOUSE_UNDEFINED)
  252.        return(notify_next_event_func(tty, event, arg, type));
  253.     else if (tt_mouse[button][shift].defined == MOUSE_STRING)
  254.        a = tt_mouse[button][shift].action;
  255.     else if (tt_mouse[button][shift].defined == MOUSE_MENU) {
  256.        a = (a_ptr) menu_show(tt_mouse[button][shift].menu, tty, event, 0);
  257.        if (value_invalid) {
  258.           a = NULL;
  259.           value_invalid = FALSE;
  260.           }
  261.        }
  262.     tt_mouse_x->value->number = x;
  263.     tt_mouse_y->value->number = y;
  264.     tt_do_action(a);
  265.     return(NOTIFY_DONE);
  266. }
  267.  
  268. /************************************************************************/
  269. EXPORT    Menu    ttymenu_proc(m, op)
  270.  
  271. Menu    m;
  272. Menu_generate    op;
  273.  
  274. {
  275.     value_invalid = TRUE;
  276.     return(tt_ttymenu);
  277. }
  278.  
  279. /************************************************************************/
  280. EXPORT    Notify_value    close_proc(win, event, arg, type)
  281.  
  282. Window    win;
  283. Event    *event;
  284. Notify_arg    arg;
  285. Notify_event_type    type;
  286.  
  287. {    int    init_closed, curr_closed;
  288.     Notify_value    value;
  289.     d_ptr    d;
  290.  
  291.     init_closed = (int) window_get(tt_base_window->frame, FRAME_CLOSED);
  292.     value = notify_next_event_func(win, event, arg, type);
  293.     curr_closed = (int) window_get(tt_base_window->frame, FRAME_CLOSED);
  294.     if (init_closed != curr_closed)
  295.        if (curr_closed) { /* transition from open to closed */
  296.           tt_do_action(tt_base_window->close_action);
  297.           for (d = tt_base_window->next; d; d = d->next)
  298.              if (d->is_open)
  299.                 window_set(d->frame, WIN_SHOW, FALSE, 0);
  300.           }
  301.        else { /* transition from closed to open */
  302.           tt_do_action(tt_base_window->open_action);
  303.           for (d = tt_base_window->next; d; d = d->next)
  304.              if (d->is_open)
  305.                 window_set(d->frame, WIN_SHOW, TRUE, 0);
  306.           }
  307.     return(value);
  308. }
  309.  
  310. /************************************************************************/
  311. EXPORT    Notify_value    tty_handler(tty, event, arg, type)
  312.  
  313. Tty            tty;
  314. Event            *event;
  315. Notify_arg        arg;
  316. Notify_event_type    type;
  317.  
  318. {    a_ptr    a;
  319.  
  320.     if ((event_is_ascii(event) || event_is_meta(event)) && tt_normal_off)
  321.        return(NOTIFY_DONE);
  322.     else if (is_a_function_key(event)) {
  323.        if (a = key_is_mapped(event)) {
  324.           if (event_is_down(event))
  325.              tt_do_action(a);
  326.           }
  327.        else if (!tt_function_off)
  328.           return(close_proc(tty, event, arg, type));
  329.        return(NOTIFY_DONE);
  330.        }
  331.     else if (event_id(event) == MS_LEFT && event_is_down(event))
  332.        return(handle_mouse(MOUSE_LEFT, get_shifts(event), tty, event, arg, type));
  333.     else if (event_id(event) == MS_MIDDLE && event_is_down(event))
  334.        return(handle_mouse(MOUSE_CENTER, get_shifts(event), tty, event, arg, type));
  335.     else if (event_id(event) == MS_RIGHT && event_is_down(event))
  336.        return(handle_mouse(MOUSE_RIGHT, get_shifts(event), tty, event, arg, type));
  337.     else
  338.        return(close_proc(tty, event, arg, type));
  339. }
  340.  
  341. /************************************************************************/
  342. EXPORT    Notify_value    tt_dialog_done(frame)
  343.  
  344. Frame    frame;
  345.  
  346. {    d_ptr    d;
  347.  
  348.     d = (d_ptr) window_get(frame, WIN_CLIENT_DATA);
  349.     d->is_open = FALSE;
  350.     tt_do_action(d->close_action);
  351.     window_set(frame, WIN_SHOW, FALSE, 0);
  352.     return(NOTIFY_DONE);
  353. }
  354.  
  355. /************************************************************************/
  356. EXPORT    tt_set_timer(sec, usec)
  357.  
  358. int    sec;
  359. int    usec;
  360.  
  361. {
  362.     if (sec != 0 || usec != 0) {
  363.        timer_int.it_value.tv_sec = timer_int.it_interval.tv_sec = sec;
  364.        timer_int.it_value.tv_usec = timer_int.it_interval.tv_usec = usec;
  365.        notify_set_itimer_func(tt_base_window->frame, timer_proc, ITIMER_REAL, &timer_int, NULL);
  366.        }
  367.     else
  368.        notify_set_itimer_func(tt_base_window->frame, timer_proc, ITIMER_REAL, NULL, NULL);
  369. }
  370.