home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / sun / volume1 / tooltool2.1c / part04 / tooltool.h < prev   
Encoding:
C/C++ Source or Header  |  1989-06-06  |  10.4 KB  |  433 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.  
  25. #include    <suntool/sunview.h>
  26. #include    <suntool/panel.h>
  27.  
  28. /* Help delineate where routines are used and defined
  29.  */
  30. #define        PUBLIC            extern
  31. #define        PRIVATE            static
  32. #define        EXPORT
  33.  
  34. #define        strsave(s)        ((char *) strcpy((char *) safe_malloc(strlen(s) + 1), s))
  35. #define        estrsave(s)        ((char *) strcpy((char *) tt_emalloc(strlen(s) + 1), s))
  36. #define        baseline_of(f)        (-((f)->pf_char['0'].pc_home.y))
  37. #define        charwidth_of(f)        ((f)->pf_char['0'].pc_adv.x)
  38. #define        charheight_of(f)    ((f)->pf_defaultsize.y)
  39. #define        value_of(v)        ((v)->is_number? (v)->number : 0.0)
  40.  
  41. /* The gadget position possibilities
  42.  */
  43. #define        G_NOPOS            -1
  44. #define        G_TOP            0
  45. #define        G_BOTTOM        1
  46. #define        G_LEFT            2
  47. #define        G_RIGHT            3
  48.  
  49. /* The shift states available for various function keys
  50.  */
  51. #define        S_NORMAL        0
  52. #define        S_SHIFT            1
  53. #define        S_CONTROL        2
  54. #define        S_META            4
  55. #define        MAX_SHIFT_SETS        8
  56.  
  57. /* The kind of gadgets we can create
  58.  */
  59. #define        GADGET_BUTTON        0
  60. #define        GADGET_CHOICE        1
  61. #define        GADGET_LABEL        2
  62. #define        GADGET_MENU        3
  63. #define        GADGET_SLIDER        4
  64. #define        GADGET_TEXT        5
  65.  
  66. /* Special functions that gadgets can perform
  67.  */
  68. #define        BEEP_OP            0
  69. #define        BREAK_OP        1
  70. #define        CLOSE_OP        2
  71. #define        CONTINUE_OP        3
  72. #define        DISPLAY_OP        4
  73. #define        EXIT_OP            5
  74. #define        EXPR_OP            6
  75. #define        FOR_OP            7
  76. #define        IF_OP            8
  77. #define        OPEN_OP            9
  78. #define        POPUP_OP        10
  79. #define        REMOVE_OP        11
  80. #define        SEND_OP            12
  81. #define        WHILE_OP        13
  82.  
  83. /* How labels are aligned with respect to each other
  84.  */
  85. #define        NO_ALIGN        0
  86. #define        ALIGN_TOP        1
  87. #define        ALIGN_MIDDLE        2
  88. #define        ALIGN_BOTTOM        3
  89.  
  90. /* The different function key sets on a Sun-3 keyboard
  91.  */
  92. #define        LEFT_KEY_SET        0
  93. #define        TOP_KEY_SET        1
  94. #define        RIGHT_KEY_SET        2
  95. #define        MAX_KEY_SETS        3
  96.  
  97. #define        MAX_FUNC_KEYS        15
  98.  
  99. /* Mouse buttons
  100.  */
  101. #define        MOUSE_LEFT        0
  102. #define        MOUSE_CENTER        1
  103. #define        MOUSE_RIGHT        2
  104.  
  105. #define        MAX_MOUSE_BUTTONS    3
  106.  
  107. /* The functions a mouse key can perform
  108.  */
  109. #define        MOUSE_UNDEFINED        0
  110. #define        MOUSE_STRING        1
  111. #define        MOUSE_MENU        2
  112.  
  113. /* The ways a choice gadget can be laid out
  114.  */
  115. #define        CHOICE_CURRENT        0
  116. #define        CHOICE_CYCLE        1
  117. #define        CHOICE_HORIZONTAL    2
  118. #define        CHOICE_VERTICAL        3
  119.  
  120. /* The kinds of symbols a user can define
  121.  */
  122. #define        SYMBOL_SYMBOL        0
  123. #define        SYMBOL_GADGET        1
  124. #define        SYMBOL_DIALOG        2
  125.  
  126. /* Various expression operators
  127.  */
  128. #define        E_AND            0
  129. #define        E_ARRAY_REF        1
  130. #define        E_ASSIGN_AND        2
  131. #define        E_ASSIGN_DIVIDE        3
  132. #define        E_ASSIGN_MINUS        4
  133. #define        E_ASSIGN_MODULO        5
  134. #define        E_ASSIGN_OR        6
  135. #define        E_ASSIGN_PLUS        7
  136. #define        E_ASSIGN_TIMES        8
  137. #define        E_ASSIGN_XOR        9
  138. #define        E_ASSIGNMENT        10
  139. #define        E_COMMA            11
  140. #define        E_COMPLEMENT        12
  141. #define        E_DIVIDE        13
  142. #define        E_EQUAL            14
  143. #define        E_FUNC_ID        15
  144. #define        E_GREATER        16
  145. #define        E_GREATER_EQUAL        17
  146. #define        E_LEFT_SHIFT        18
  147. #define        E_LESS            19
  148. #define        E_LESS_EQUAL        20
  149. #define        E_LOGICAL_AND        21
  150. #define        E_LOGICAL_NOT        22
  151. #define        E_LOGICAL_OR        23
  152. #define        E_MINUS            24
  153. #define        E_MODULO        25
  154. #define        E_NOT_EQUAL        26
  155. #define        E_NUMBER        27
  156. #define        E_OR            28
  157. #define        E_PAREN            29
  158. #define        E_PLUS            30
  159. #define        E_POSTDECREMENT        31
  160. #define        E_POSTINCREMENT        32
  161. #define        E_PREDECREMENT        33
  162. #define        E_PREINCREMENT        34
  163. #define        E_QUESTION        35
  164. #define        E_RIGHT_SHIFT        36
  165. #define        E_STRING        37
  166. #define        E_SYMBOL        38
  167. #define        E_TIMES            39
  168. #define        E_UMINUS        40
  169. #define        E_XOR            41
  170.  
  171. /* The kinds of values we can express.
  172.  */
  173. #define        V_NOTHING        0
  174. #define        V_ARRAY            1
  175. #define        V_GADGET        2
  176. #define        V_NUMBER        4
  177. #define        V_INTERVAL        8
  178.  
  179. #define        V_TYPES            (V_ARRAY | V_NUMBER)
  180. #define        V_SPECIAL        (V_GADGET | V_INTERVAL)
  181.  
  182. #define        is_array(v)        ((v)->kind & V_ARRAY)
  183. #define        is_gadget(v)        ((v)->kind & V_GADGET)
  184. #define        is_number(v)        ((v)->kind & V_NUMBER)
  185. #define        is_interval(v)        ((v)->kind & V_INTERVAL)
  186.  
  187. /* Special things used to beat a Suntools window size bug
  188.  */
  189. #define        POLLING_MAGIC_NUMBER    "\001\002\003\004"
  190. #define        POLLING_TIME_OUT    20000 /* milliseconds */
  191.  
  192. /* The data necessary to describe a label.  If "is_icon" is FALSE,
  193.  * "label" holds the label text, and "font" holds the label font.
  194.  * If TRUE, "image" holds the bitmap of the icon for the label.
  195.  */
  196. typedef    struct    l_rec    l_data, *l_ptr;
  197.  
  198. struct    l_rec    {int    is_icon;
  199.          char    *label;
  200.          struct    pixfont    *font;
  201.          struct    pixrect    *image;
  202.         };
  203.  
  204. /* The data needed to describe a gadget.  "Kind" is one of 
  205.  * GADGET_*, above, and indicates which portion of the union
  206.  * is valid for this gadget.  "Image" contains the image bitmap
  207.  * for buttons and menus, and labels if they are icons.  Sliders
  208.  * and choices have their own, SunView-created, images.  For all
  209.  * gadgets, "width" and "height" are set to reflect the image
  210.  * bounding box, for gadget layout purposes.  The gadgets are 
  211.  * linked together via "next".
  212.  */
  213.  
  214. typedef    struct    a_rec    a_data, *a_ptr;
  215. typedef    struct    cv_rec    cv_data, *cv_ptr;
  216. typedef struct    d_rec    d_data, *d_ptr;
  217. typedef    struct    e_rec    e_data, *e_ptr;
  218. typedef    struct    g_rec    g_data, *g_ptr;
  219. typedef    struct    s_rec    s_data, *s_ptr;
  220. typedef    struct    v_rec    v_data, *v_ptr;
  221.  
  222. typedef    v_ptr    (*f_ptr)();
  223.  
  224. struct    but_rec    {l_ptr    label[MAX_SHIFT_SETS];
  225.          a_ptr    action[MAX_SHIFT_SETS];
  226.          Menu    menu;
  227.         };
  228.  
  229. struct    cv_rec    {l_ptr    label;
  230.          a_ptr    action;
  231.          cv_ptr    next;
  232.         };
  233.  
  234. struct    cho_rec    {l_ptr    label;
  235.          int    mode;
  236.          int    ch_width;
  237.          int    ch_height;
  238.          l_ptr    mark;
  239.          l_ptr    nomark;
  240.          cv_ptr    value;
  241.         };
  242.  
  243. struct    lab_rec    {l_ptr    label;
  244.         };
  245.  
  246. struct    men_rec    {l_ptr    label;
  247.          Menu    menu;
  248.         };
  249.  
  250. struct    sli_rec    {l_ptr    label;
  251.          int    minimum;
  252.          int    maximum;
  253.          int    initial;
  254.          int    value;
  255.          int    range;
  256.          int    width;
  257.          a_ptr    action;
  258.          struct    pixfont    *font;
  259.         };
  260.  
  261. struct    tex_rec    {l_ptr    label;
  262.          char    *trigger;
  263.          char    *completion;
  264.          char    *ignore;
  265.          int    display_len;
  266.          int    retain_len;
  267.          a_ptr    action; 
  268.          struct    pixfont    *font;
  269.         };
  270.  
  271. struct    g_rec    {int    kind;
  272.          char    *name;
  273.          Panel_item    panel_item;
  274.          struct    pixrect    *image;
  275.          int    width;
  276.          int    height;
  277.          int    x;
  278.          int    y;
  279.          g_ptr    next;
  280.          union    {struct    but_rec    but;
  281.               struct    cho_rec    cho;
  282.               struct    lab_rec    lab;
  283.               struct    men_rec    men;
  284.               struct    sli_rec    sli;
  285.               struct    tex_rec    tex;
  286.              } u;
  287.         };
  288.  
  289. /* The data necessary to describe an action.
  290.  */
  291. struct    a_rec    {int    op;
  292.          e_ptr    init;
  293.          e_ptr    expr;
  294.          e_ptr    term;
  295.          a_ptr    body;
  296.          a_ptr    else_part;
  297.          a_ptr    next;
  298.         };
  299.  
  300. /* The data necessary to describe an expression
  301.  */
  302. struct    e_rec    {int    op;
  303.          e_ptr    left;
  304.          e_ptr    right;
  305.          e_ptr    extra;
  306.          s_ptr    symbol;
  307.          char    *string;
  308.          double    value;
  309.          f_ptr    func;
  310.         };
  311.  
  312. /* The data necessary to describe a value
  313.  */
  314. struct    v_rec    {int    kind;
  315.          char    *str;    /* except when an array */
  316.          double    number;    /* if a number */
  317.          g_ptr    gadget;    /* if a gadget */
  318.          char    *index; /* array element index string */
  319.          v_ptr    value;    /* if an array */
  320.          v_ptr    left;    /* links for array element tree */
  321.          v_ptr    right;
  322.         };
  323.  
  324. /* The data necessary to describe a symbol.
  325.  */
  326. struct    s_rec    {int    kind;
  327.          char    *name;
  328.          g_ptr    gadget;        /* if a gadget */
  329.          d_ptr    dialog;        /* if a dialog */
  330.          v_ptr    value;        /* if a symbol */
  331.          s_ptr    left;
  332.          s_ptr    right;
  333.         };
  334.  
  335. /* The data necessary to describe a panel
  336.  */
  337. struct    d_rec    {Frame    frame;
  338.          Panel    panel;
  339.          int    is_base_frame;
  340.          int    is_open;
  341.          int    is_popup;
  342.          int    rows;
  343.          int    columns;
  344.          int    win_x;
  345.          int    win_y;
  346.          int    is_chars;
  347.          int    g_align;
  348.          int    proportional;
  349.          int    justified;
  350.          int    text_items_exist;
  351.          int    gadget_pos;
  352.          g_ptr    gadgets;
  353.          char    *label;
  354.          a_ptr    open_action;
  355.          a_ptr    close_action;
  356.          struct    pixfont    *g_font;
  357.          d_ptr    next;
  358.         };
  359.  
  360. /* A mouse record holds operation to be performed by one mouse
  361.  * button/shift-state combination.  "Defined" is one of 
  362.  * MOUSE_{UNDEFINED,STRING,MENU}.  If MOUSE_STRING, "value" holds
  363.  * the text to be transmitted.  If MOUSE_MENU, "menu" holds
  364.  * the menu to be displayed.
  365.  */
  366. typedef    struct    m_rec    m_data;
  367.  
  368. struct    m_rec    {int    defined;
  369.          a_ptr    action;
  370.          Menu    menu;
  371.         };
  372.  
  373. /* A variety of public data.  All globals begin with "tt_".
  374.  */
  375. PUBLIC    a_ptr    tt_initial_action,
  376.         tt_timer_action,
  377.         tt_func_keys[MAX_KEY_SETS][MAX_FUNC_KEYS][MAX_SHIFT_SETS];
  378.  
  379. PUBLIC    char    *tt_application,
  380.         *tt_curr_file,
  381.         *tt_icon,
  382.         *tt_program;
  383.  
  384. PUBLIC    d_ptr    tt_base_window;
  385.  
  386. PUBLIC    int    tt_mouse_base,
  387.         tt_mouse_chars,
  388.         tt_errors_occured,
  389.         tt_normal_off,
  390.         tt_function_off,
  391.         tt_action_depth,
  392.         tt_timer_pending;
  393.  
  394. PUBLIC    l_ptr    tt_default_mark,
  395.         tt_default_nomark,
  396.         tt_default_cycle;
  397.  
  398. PUBLIC    m_data    tt_mouse[MAX_MOUSE_BUTTONS][MAX_SHIFT_SETS];
  399.  
  400. PUBLIC    Menu    tt_ttymenu;
  401.  
  402. PUBLIC    struct    pixfont    *tt_default_font,
  403.             *tt_a_font;
  404.  
  405. PUBLIC    struct    pixrect    tt_mark_image,
  406.             tt_nomark_image,
  407.             tt_cycle_image;
  408.  
  409. PUBLIC    s_ptr    tt_mouse_x, tt_mouse_y, tt_delimiters;
  410.  
  411. /* Public routines which do not return void.
  412.  */
  413. PUBLIC    char    *safe_malloc();
  414. PUBLIC    struct    pixrect    *tt_load_icon();
  415. PUBLIC    struct    pixfont    *tt_open_font();
  416. PUBLIC    l_ptr    tt_make_label();
  417. PUBLIC    a_ptr    tt_make_action();
  418. PUBLIC    s_ptr    tt_find_symbol();
  419. PUBLIC    v_ptr    tt_get_value();
  420. PUBLIC    d_ptr    tt_make_base_window();
  421. PUBLIC    e_ptr    tt_make_expr();
  422. PUBLIC    v_ptr    tt_eval();
  423. PUBLIC    char    *tt_string_of();
  424. PUBLIC    f_ptr    tt_is_function();
  425. PUBLIC    char    *tt_emalloc();
  426. PUBLIC    v_ptr    tt_int_result();
  427. PUBLIC    v_ptr    tt_double_result();
  428. PUBLIC    v_ptr    tt_string_result();
  429. PUBLIC    v_ptr    tt_insert_array();
  430. PUBLIC    char    *tt_get_selection();
  431. PUBLIC    char    *tt_expand_ranges();
  432. PUBLIC    char    *tt_full_path_of();
  433.