1 /***************************************************************************
2 * This program is Copyright (C) 1991-1996 by C.H.Lindsey, University of *
3 * Manchester. (X)JOVETOOL is provided to you without charge, and with no *
4 * warranty. You may give away copies of (X)JOVETOOL, including sources, *
5 * provided that this notice is included in all the files, except insofar *
6 * as a more specific copyright notices attaches to the file (x)jovetool.c *
7 ***************************************************************************/
8
9 #include <xview/xview.h>
10 #include <xview/font.h>
11 #include <xview/tty.h>
12 #include <xview/ttysw.h> /* is this missing on some systems? */
13 #include <stdio.h>
14 #include "exts.h"
15 #include "xjovewindows.h"
16
17 private char command_prefix[] = "\033X"; /* ESC-X */
18 #define command_prefix_length (sizeof(command_prefix) - 1)
19
20 Menu main_menu;
21
22 private Menu
23 file_menu,
24 mode_menu,
25 help_menu,
26 move_menu,
27 bind_menu,
28 macro_menu,
29 buffer_menu,
30 window_menu,
31 mark_menu,
32 edit_menu,
33 directory_menu,
34 compile_menu,
35 format_menu,
36 search_menu,
37 process_menu,
38 abbrev_menu,
39 misc_menu,
40 print_variables_menu,
41 set_variables_menu,
42 variables_menu,
43 another_help_menu,
44 commands_menu,
45 var_files_menu,
46 var_modes_menu,
47 var_move_menu,
48 var_search_menu,
49 var_process_menu,
50 var_compile_menu,
51 var_format_menu,
52 var_misc_menu,
53 var_abbrev_menu,
54 empty_menu,
55 on_off_menu;
56
57 private Menu_item empty_menu_item;
58
59 private int
60 describing,
61 printing,
62 climbing,
63 falling;
64
65 private void
do_ancestor(m,mi)66 do_ancestor(m, mi)
67 Menu m;
68 Menu_item mi;
69 {
70 Menu parent_menu;
71 Menu_item parent_item;
72 caddr_t (*proc)();
73
74 parent_item = xv_get(m, MENU_PARENT);
75 if (parent_item != XV_NULL) {
76 parent_menu = xv_get(parent_item, MENU_PARENT);
77 proc = (caddr_t (*)())xv_get(parent_item, MENU_NOTIFY_PROC);
78 if (proc == NULL)
79 proc = (caddr_t (*)())xv_get(parent_menu, MENU_NOTIFY_PROC);
80 if (proc == NULL)
81 do_ancestor(parent_menu, parent_item);
82 else
83 (*proc)(parent_menu, parent_item);
84 }
85 }
86
87 private void
do_notify(m,mi,p)88 do_notify(m, mi, p)
89 Menu m;
90 Menu_item mi;
91 void (*p)();
92 {
93 Menu pull;
94 Menu_item deft;
95 caddr_t (*proc)();
96 int local_climbing,
97 local_falling;
98
99 if (!(local_climbing = climbing))
100 ttysw_input (ttysw, command_prefix, command_prefix_length);
101 climbing = 1;
102 if (!(local_falling = falling)) do_ancestor(m, mi);
103 (*p)(m, mi);
104 if (!local_climbing && (pull = xv_get(mi, MENU_PULLRIGHT)) != XV_NULL) {
105 falling = 1;
106 deft = xv_get(pull, MENU_DEFAULT_ITEM);
107 proc = (caddr_t (*)())xv_get(deft, MENU_NOTIFY_PROC);
108 if (proc == NULL)
109 proc = (caddr_t (*)())xv_get(pull, MENU_NOTIFY_PROC);
110 (*proc)(pull, deft);
111 falling = local_falling;
112 }
113 climbing = local_climbing;
114 if (!climbing)
115 ttysw_input (ttysw, "\n", 1);
116 }
117
118
119 void
do_print_client_data(m,mi)120 do_print_client_data(m, mi)
121 Menu m;
122 Menu_item mi;
123 {
124 char *menu_string;
125
126 menu_string = (char *)xv_get(mi, MENU_CLIENT_DATA);
127 ttysw_input(ttysw, menu_string, strlen(menu_string));
128 }
129
130 private void
print_client_data(m,mi)131 print_client_data(m, mi)
132 Menu m;
133 Menu_item mi;
134 {
135 do_notify(m, mi, do_print_client_data);
136 }
137
138 private void
main_notify(m,mi)139 main_notify(m, mi)
140 Menu m;
141 Menu_item mi;
142 {
143 char *menu_string;
144
145 print_client_data(m, mi);
146 }
147
148 void
do_sp_printit(m,mi)149 do_sp_printit(m, mi)
150 Menu m;
151 Menu_item mi;
152 {
153 char *menu_string;
154
155 menu_string = (char *)xv_get(mi, MENU_CLIENT_DATA);
156 if (mi != empty_menu_item)
157 ttysw_input(ttysw, " ", 1);
158 ttysw_input(ttysw, menu_string, strlen(menu_string));
159 }
160
161 private void
sp_printit(m,mi)162 sp_printit(m, mi)
163 Menu m;
164 Menu_item mi;
165 {
166 do_notify(m, mi, do_sp_printit);
167 }
168
169 private Menu_item
commands_proc(item,operation)170 commands_proc(item, operation)
171 Menu_item item;
172 Menu_generate operation;
173 {
174 return commands_menu;
175 }
176
177 private Menu_item
on_off_proc(item,operation)178 on_off_proc(item, operation)
179 Menu_item item;
180 Menu_generate operation;
181 {
182 switch (operation) {
183 case MENU_DISPLAY:
184 if (!describing & !printing) {
185 xv_set(item, MENU_PULLRIGHT, on_off_menu, 0);
186 } else {
187 xv_set(item, MENU_PULLRIGHT, XV_NULL, 0);
188 }
189 break;
190 case MENU_DISPLAY_DONE:
191 case MENU_NOTIFY:
192 case MENU_NOTIFY_DONE:
193 break;
194 }
195 return item;
196 }
197
198 private Menu
do_set_proc(mi,operation,menu)199 do_set_proc(mi, operation, menu)
200 Menu_item mi;
201 Menu_generate operation;
202 Menu menu;
203 {
204 if (!describing) {
205 switch (operation) {
206 case MENU_DISPLAY:
207 if (!strcmp((char *)xv_get(mi, MENU_CLIENT_DATA), "print"))
208 printing = 1;
209 return menu;
210
211 case MENU_DISPLAY_DONE:
212 printing = 0;
213 /*FALLTHROUGH*/
214 case MENU_NOTIFY:
215 case MENU_NOTIFY_DONE:
216 return empty_menu;
217 }
218 return empty_menu; /* ??? what should this function return */
219 } else return empty_menu;
220 }
221
222 private Menu
do_describing_proc(m,operation)223 do_describing_proc(m, operation)
224 Menu m;
225 Menu_generate operation;
226 {
227 switch (operation) {
228 case MENU_DISPLAY:
229 describing = 1;
230 break;
231 case MENU_DISPLAY_DONE:
232 describing = 0;
233 break;
234 case MENU_NOTIFY:
235 case MENU_NOTIFY_DONE:
236 break;
237 }
238 return m;
239 }
240
241 #define X
242
243 #include "jovemenu.c"
244