… | |
… | |
30 | #include "menubar.intpro" /* PROTOS for internal routines */ |
30 | #include "menubar.intpro" /* PROTOS for internal routines */ |
31 | |
31 | |
32 | #define Menu_PixelWidth(menu) \ |
32 | #define Menu_PixelWidth(menu) \ |
33 | (2 * SHADOW + Width2Pixel ((menu)->width + 3 * HSPACE)) |
33 | (2 * SHADOW + Width2Pixel ((menu)->width + 3 * HSPACE)) |
34 | |
34 | |
35 | static const struct { |
35 | static const struct |
|
|
36 | { |
36 | const char name; /* (l)eft, (u)p, (d)own, (r)ight */ |
37 | const char name; /* (l)eft, (u)p, (d)own, (r)ight */ |
37 | const unsigned char str[5]; /* str[0] = STRLEN (str+1) */ |
38 | const unsigned char str[5]; /* str[0] = STRLEN (str+1) */ |
|
|
39 | } |
38 | } Arrows[NARROWS] = { |
40 | Arrows[NARROWS] = { |
39 | { 'l', "\003\033[D" }, |
41 | { 'l', "\003\033[D" }, |
40 | { 'u', "\003\033[A" }, |
42 | { 'u', "\003\033[A" }, |
41 | { 'd', "\003\033[B" }, |
43 | { 'd', "\003\033[B" }, |
42 | { 'r', "\003\033[C" } |
44 | { 'r', "\003\033[C" } |
43 | }; |
45 | }; |
44 | |
46 | |
45 | /*}}} */ |
47 | /*}}} */ |
46 | |
48 | |
47 | /* |
49 | /* |
48 | * find an item called NAME in MENU |
50 | * find an item called NAME in MENU |
49 | */ |
51 | */ |
50 | menuitem_t * |
52 | menuitem_t * |
51 | rxvt_menuitem_find(const menu_t *menu, const char *name) |
53 | rxvt_menuitem_find (const menu_t *menu, const char *name) |
52 | { |
54 | { |
53 | menuitem_t *item; |
55 | menuitem_t *item; |
54 | |
56 | |
55 | #ifdef DEBUG_STRICT |
57 | #ifdef DEBUG_STRICT |
56 | assert(name != NULL); |
58 | assert (name != NULL); |
57 | assert(menu != NULL); |
59 | assert (menu != NULL); |
58 | #endif |
60 | #endif |
59 | |
61 | |
60 | /* find the last item in the menu, this is good for separators */ |
62 | /* find the last item in the menu, this is good for separators */ |
61 | for (item = menu->tail; item != NULL; item = item->prev) { |
63 | for (item = menu->tail; item != NULL; item = item->prev) |
|
|
64 | { |
62 | if (item->entry.type == MenuSubMenu) { |
65 | if (item->entry.type == MenuSubMenu) |
|
|
66 | { |
63 | if (!STRCMP(name, (item->entry.submenu.menu)->name)) |
67 | if (!STRCMP (name, (item->entry.submenu.menu)->name)) |
64 | break; |
68 | break; |
|
|
69 | } |
65 | } else if ((isSeparator(name) && isSeparator(item->name)) |
70 | else if ((isSeparator (name) && isSeparator (item->name)) |
66 | || !STRCMP(name, item->name)) |
71 | || !STRCMP (name, item->name)) |
67 | break; |
72 | break; |
68 | } |
73 | } |
69 | return item; |
74 | return item; |
70 | } |
75 | } |
71 | |
76 | |
72 | /* |
77 | /* |
73 | * unlink ITEM from its MENU and free its memory |
78 | * unlink ITEM from its MENU and free its memory |
74 | */ |
79 | */ |
75 | void |
80 | void |
76 | rxvt_term::menuitem_free (menu_t *menu, menuitem_t *item) |
81 | rxvt_term::menuitem_free (menu_t *menu, menuitem_t *item) |
77 | { |
82 | { |
78 | /* disconnect */ |
83 | /* disconnect */ |
79 | menuitem_t *prev, *next; |
84 | menuitem_t *prev, *next; |
80 | |
85 | |
81 | #ifdef DEBUG_STRICT |
86 | #ifdef DEBUG_STRICT |
82 | assert(menu != NULL); |
87 | assert (menu != NULL); |
83 | #endif |
88 | #endif |
84 | |
89 | |
85 | prev = item->prev; |
90 | prev = item->prev; |
86 | next = item->next; |
91 | next = item->next; |
87 | if (prev != NULL) |
92 | if (prev != NULL) |
88 | prev->next = next; |
93 | prev->next = next; |
89 | if (next != NULL) |
94 | if (next != NULL) |
90 | next->prev = prev; |
95 | next->prev = prev; |
91 | |
96 | |
92 | /* new head, tail */ |
97 | /* new head, tail */ |
93 | if (menu->tail == item) |
98 | if (menu->tail == item) |
94 | menu->tail = prev; |
99 | menu->tail = prev; |
95 | if (menu->head == item) |
100 | if (menu->head == item) |
96 | menu->head = next; |
101 | menu->head = next; |
97 | |
102 | |
98 | switch (item->entry.type) { |
103 | switch (item->entry.type) |
|
|
104 | { |
99 | case MenuAction: |
105 | case MenuAction: |
100 | case MenuTerminalAction: |
106 | case MenuTerminalAction: |
101 | free(item->entry.action.str); |
107 | free (item->entry.action.str); |
102 | break; |
108 | break; |
103 | case MenuSubMenu: |
109 | case MenuSubMenu: |
104 | menu_delete (item->entry.submenu.menu); |
110 | menu_delete (item->entry.submenu.menu); |
105 | break; |
111 | break; |
106 | } |
112 | } |
107 | if (item->name != NULL) |
113 | if (item->name != NULL) |
108 | free(item->name); |
114 | free (item->name); |
109 | if (item->name2 != NULL) |
115 | if (item->name2 != NULL) |
110 | free(item->name2); |
116 | free (item->name2); |
111 | free(item); |
117 | free (item); |
112 | } |
118 | } |
113 | |
119 | |
114 | /* |
120 | /* |
115 | * sort command vs. terminal actions and |
121 | * sort command vs. terminal actions and |
116 | * remove the first character of STR if it's '\0' |
122 | * remove the first character of STR if it's '\0' |
117 | */ |
123 | */ |
118 | int |
124 | int |
119 | rxvt_action_type(action_t *action, unsigned char *str) |
125 | rxvt_action_type (action_t *action, unsigned char *str) |
120 | { |
126 | { |
121 | unsigned int len; |
127 | unsigned int len; |
122 | |
128 | |
123 | #if defined (DEBUG_MENU) || defined (DEBUG_MENUARROWS) |
129 | #if defined (DEBUG_MENU) || defined (DEBUG_MENUARROWS) |
124 | len = STRLEN(str); |
130 | len = STRLEN (str); |
125 | fprintf(stderr, "(len %d) = %s\n", len, str); |
131 | fprintf (stderr, " (len %d) = %s\n", len, str); |
126 | #else |
132 | #else |
127 | len = rxvt_Str_escaped((char *)str); |
133 | len = rxvt_Str_escaped ((char *)str); |
128 | #endif |
134 | #endif |
129 | |
135 | |
130 | if (!len) |
136 | if (!len) |
131 | return -1; |
137 | return -1; |
132 | |
138 | |
133 | /* sort command vs. terminal actions */ |
139 | /* sort command vs. terminal actions */ |
134 | action->type = MenuAction; |
140 | action->type = MenuAction; |
135 | if (str[0] == '\0') { |
141 | if (str[0] == '\0') |
|
|
142 | { |
136 | /* the functional equivalent: memmove (str, str+1, len); */ |
143 | /* the functional equivalent: memmove (str, str+1, len); */ |
137 | unsigned char *dst = (str); |
144 | unsigned char *dst = (str); |
138 | unsigned char *src = (str + 1); |
145 | unsigned char *src = (str + 1); |
139 | unsigned char *end = (str + len); |
146 | unsigned char *end = (str + len); |
140 | |
147 | |
141 | while (src <= end) |
148 | while (src <= end) |
142 | *dst++ = *src++; |
149 | *dst++ = *src++; |
143 | |
150 | |
144 | len--; /* decrement length */ |
151 | len--; /* decrement length */ |
145 | if (str[0] != '\0') |
152 | if (str[0] != '\0') |
146 | action->type = MenuTerminalAction; |
153 | action->type = MenuTerminalAction; |
147 | } |
154 | } |
148 | action->str = str; |
155 | action->str = str; |
149 | action->len = len; |
156 | action->len = len; |
150 | |
157 | |
151 | return 0; |
158 | return 0; |
152 | } |
159 | } |
153 | |
160 | |
154 | int |
161 | int |
155 | rxvt_term::action_dispatch (action_t *action) |
162 | rxvt_term::action_dispatch (action_t *action) |
156 | { |
163 | { |
157 | switch (action->type) { |
164 | switch (action->type) |
|
|
165 | { |
158 | case MenuTerminalAction: |
166 | case MenuTerminalAction: |
159 | cmd_write (action->str, action->len); |
167 | cmd_write (action->str, action->len); |
160 | break; |
168 | break; |
161 | |
169 | |
162 | case MenuAction: |
170 | case MenuAction: |
163 | tt_write (action->str, action->len); |
171 | tt_write (action->str, action->len); |
164 | break; |
172 | break; |
165 | |
173 | |
166 | default: |
174 | default: |
167 | return -1; |
175 | return -1; |
168 | break; |
176 | break; |
169 | } |
177 | } |
170 | return 0; |
178 | return 0; |
171 | } |
179 | } |
172 | |
180 | |
173 | /* return the arrow index corresponding to NAME */ |
181 | /* return the arrow index corresponding to NAME */ |
174 | int |
182 | int |
175 | rxvt_menuarrow_find(char name) |
183 | rxvt_menuarrow_find (char name) |
176 | { |
184 | { |
177 | int i; |
185 | int i; |
178 | |
186 | |
179 | for (i = 0; i < NARROWS; i++) |
187 | for (i = 0; i < NARROWS; i++) |
180 | if (name == Arrows[i].name) |
188 | if (name == Arrows[i].name) |
181 | return i; |
189 | return i; |
182 | return -1; |
190 | return -1; |
183 | } |
191 | } |
184 | |
192 | |
185 | /* free the memory associated with arrow NAME of the current menubar */ |
193 | /* free the memory associated with arrow NAME of the current menubar */ |
186 | void |
194 | void |
187 | rxvt_term::menuarrow_free (char name) |
195 | rxvt_term::menuarrow_free (char name) |
188 | { |
196 | { |
189 | int i; |
197 | int i; |
190 | |
198 | |
191 | if (name) { |
199 | if (name) |
|
|
200 | { |
192 | i = rxvt_menuarrow_find(name); |
201 | i = rxvt_menuarrow_find (name); |
193 | if (i >= 0) { |
202 | if (i >= 0) |
|
|
203 | { |
194 | action_t *act = &(CurrentBar->arrows[i]); |
204 | action_t *act = & (CurrentBar->arrows[i]); |
195 | |
205 | |
196 | switch (act->type) { |
206 | switch (act->type) |
|
|
207 | { |
197 | case MenuAction: |
208 | case MenuAction: |
198 | case MenuTerminalAction: |
209 | case MenuTerminalAction: |
199 | free(act->str); |
210 | free (act->str); |
200 | act->str = NULL; |
211 | act->str = NULL; |
201 | act->len = 0; |
212 | act->len = 0; |
202 | break; |
213 | break; |
|
|
214 | } |
|
|
215 | act->type = MenuLabel; |
|
|
216 | } |
203 | } |
217 | } |
204 | act->type = MenuLabel; |
218 | else |
205 | } |
219 | { |
206 | } else { |
|
|
207 | for (i = 0; i < NARROWS; i++) |
220 | for (i = 0; i < NARROWS; i++) |
208 | menuarrow_free (Arrows[i].name); |
221 | menuarrow_free (Arrows[i].name); |
209 | } |
222 | } |
210 | } |
223 | } |
211 | |
224 | |
212 | void |
225 | void |
213 | rxvt_term::menuarrow_add (char *string) |
226 | rxvt_term::menuarrow_add (char *string) |
214 | { |
227 | { |
215 | int i; |
228 | int i; |
216 | unsigned xtra_len; |
229 | unsigned xtra_len; |
217 | char *p; |
230 | char *p; |
218 | struct { |
231 | struct |
|
|
232 | { |
219 | char *str; |
233 | char *str; |
220 | int len; |
234 | int len; |
221 | } |
235 | } |
222 | beg = { NULL, 0 }, |
236 | beg = { NULL, 0 }, |
223 | end = { NULL, 0 }, |
237 | end = { NULL, 0 }, |
224 | *cur, |
238 | *cur, |
225 | parse[NARROWS]; |
239 | parse[NARROWS]; |
226 | |
240 | |
227 | MEMSET(parse, 0, sizeof(parse)); |
241 | MEMSET (parse, 0, sizeof (parse)); |
228 | |
242 | |
229 | /* fprintf(stderr, "add arrows = `%s'\n", string); */ |
243 | /* fprintf (stderr, "add arrows = `%s'\n", string); */ |
230 | for (p = string; p != NULL && *p; string = p) { |
244 | for (p = string; p != NULL && *p; string = p) |
|
|
245 | { |
231 | p = (string + 3); |
246 | p = (string + 3); |
232 | /* fprintf(stderr, "parsing at %s\n", string); */ |
247 | /* fprintf (stderr, "parsing at %s\n", string); */ |
233 | switch (string[1]) { |
248 | switch (string[1]) |
234 | case 'b': |
249 | { |
|
|
250 | case 'b': |
235 | cur = &beg; |
251 | cur = &beg; |
236 | break; |
252 | break; |
237 | case 'e': |
253 | case 'e': |
238 | cur = &end; |
254 | cur = &end; |
239 | break; |
255 | break; |
240 | |
256 | |
241 | default: |
257 | default: |
242 | i = rxvt_menuarrow_find(string[1]); |
258 | i = rxvt_menuarrow_find (string[1]); |
243 | if (i >= 0) |
259 | if (i >= 0) |
244 | cur = &(parse[i]); |
260 | cur = & (parse[i]); |
245 | else |
261 | else |
246 | continue; /* not found */ |
262 | continue; /* not found */ |
247 | break; |
263 | break; |
248 | } |
264 | } |
249 | |
265 | |
250 | string = p; |
266 | string = p; |
251 | cur->str = string; |
267 | cur->str = string; |
252 | cur->len = 0; |
268 | cur->len = 0; |
253 | |
269 | |
254 | if (cur == &end) { |
270 | if (cur == &end) |
|
|
271 | { |
255 | p = STRCHR(string, '\0'); |
272 | p = STRCHR (string, '\0'); |
256 | } else { |
273 | } |
|
|
274 | else |
|
|
275 | { |
257 | char *next = string; |
276 | char *next = string; |
258 | |
277 | |
259 | while (1) { |
278 | while (1) |
260 | p = STRCHR(next, '<'); |
279 | { |
261 | if (p != NULL) { |
280 | p = STRCHR (next, '<'); |
|
|
281 | if (p != NULL) |
|
|
282 | { |
262 | if (p[1] && p[2] == '>') |
283 | if (p[1] && p[2] == '>') |
263 | break; |
284 | break; |
264 | /* parsed */ |
285 | /* parsed */ |
265 | } else { |
286 | } |
|
|
287 | else |
|
|
288 | { |
266 | if (beg.str == NULL) /* no end needed */ |
289 | if (beg.str == NULL) /* no end needed */ |
267 | p = STRCHR(next, '\0'); |
290 | p = STRCHR (next, '\0'); |
268 | break; |
291 | break; |
269 | } |
292 | } |
270 | next = (p + 1); |
293 | next = (p + 1); |
271 | } |
294 | } |
272 | } |
295 | } |
273 | |
296 | |
274 | if (p == NULL) |
297 | if (p == NULL) |
275 | return; |
298 | return; |
276 | cur->len = (p - string); |
299 | cur->len = (p - string); |
277 | } |
300 | } |
278 | |
301 | |
279 | #ifdef DEBUG_MENUARROWS |
302 | #ifdef DEBUG_MENUARROWS |
280 | cur = &beg; |
303 | cur = &beg; |
281 | fprintf(stderr, "<b>(len %d) = %.*s\n", |
304 | fprintf (stderr, "<b> (len %d) = %.*s\n", |
282 | cur->len, cur->len, (cur->str ? cur->str : "")); |
305 | cur->len, cur->len, (cur->str ? cur->str : "")); |
283 | for (i = 0; i < NARROWS; i++) { |
306 | for (i = 0; i < NARROWS; i++) |
|
|
307 | { |
284 | cur = &(parse[i]); |
308 | cur = & (parse[i]); |
285 | fprintf(stderr, "<%c>(len %d) = %.*s\n", |
309 | fprintf (stderr, "<%c> (len %d) = %.*s\n", |
286 | Arrows[i].name, |
310 | Arrows[i].name, |
287 | cur->len, cur->len, (cur->str ? cur->str : "")); |
311 | cur->len, cur->len, (cur->str ? cur->str : "")); |
288 | } |
312 | } |
289 | cur = &end; |
313 | cur = &end; |
290 | fprintf(stderr, "<e>(len %d) = %.*s\n", |
314 | fprintf (stderr, "<e> (len %d) = %.*s\n", |
291 | cur->len, cur->len, (cur->str ? cur->str : "")); |
315 | cur->len, cur->len, (cur->str ? cur->str : "")); |
292 | #endif |
316 | #endif |
293 | |
317 | |
294 | xtra_len = (beg.len + end.len); |
318 | xtra_len = (beg.len + end.len); |
295 | for (i = 0; i < NARROWS; i++) { |
319 | for (i = 0; i < NARROWS; i++) |
|
|
320 | { |
296 | if (xtra_len || parse[i].len) |
321 | if (xtra_len || parse[i].len) |
297 | menuarrow_free (Arrows[i].name); |
322 | menuarrow_free (Arrows[i].name); |
298 | } |
323 | } |
299 | |
324 | |
300 | for (i = 0; i < NARROWS; i++) { |
325 | for (i = 0; i < NARROWS; i++) |
|
|
326 | { |
301 | unsigned char *str; |
327 | unsigned char *str; |
302 | unsigned int len; |
328 | unsigned int len; |
303 | |
329 | |
304 | if (!parse[i].len) |
330 | if (!parse[i].len) |
305 | continue; |
331 | continue; |
306 | |
332 | |
307 | str = rxvt_malloc(parse[i].len + xtra_len + 1); |
333 | str = (unsigned char *) rxvt_malloc (parse[i].len + xtra_len + 1); |
308 | |
334 | |
309 | len = 0; |
335 | len = 0; |
310 | if (beg.len) { |
336 | if (beg.len) |
|
|
337 | { |
311 | STRNCPY(str + len, beg.str, beg.len); |
338 | STRNCPY (str + len, beg.str, beg.len); |
312 | len += beg.len; |
339 | len += beg.len; |
313 | } |
340 | } |
314 | STRNCPY(str + len, parse[i].str, parse[i].len); |
341 | STRNCPY (str + len, parse[i].str, parse[i].len); |
315 | len += parse[i].len; |
342 | len += parse[i].len; |
316 | |
343 | |
317 | if (end.len) { |
344 | if (end.len) |
|
|
345 | { |
318 | STRNCPY(str + len, end.str, end.len); |
346 | STRNCPY (str + len, end.str, end.len); |
319 | len += end.len; |
347 | len += end.len; |
320 | } |
348 | } |
321 | str[len] = '\0'; |
349 | str[len] = '\0'; |
322 | |
350 | |
323 | #ifdef DEBUG_MENUARROWS |
351 | #ifdef DEBUG_MENUARROWS |
324 | fprintf(stderr, "<%c>(len %d) = %s\n", Arrows[i].name, len, str); |
352 | fprintf (stderr, "<%c> (len %d) = %s\n", Arrows[i].name, len, str); |
325 | #endif |
353 | #endif |
326 | if (rxvt_action_type(&(CurrentBar->arrows[i]), str) < 0) |
354 | if (rxvt_action_type (& (CurrentBar->arrows[i]), str) < 0) |
327 | free(str); |
355 | free (str); |
328 | } |
356 | } |
329 | } |
357 | } |
330 | |
358 | |
331 | menuitem_t * |
359 | menuitem_t * |
332 | rxvt_menuitem_add(menu_t *menu, const char *name, const char *name2, const char *action) |
360 | rxvt_menuitem_add (menu_t *menu, const char *name, const char *name2, const char *action) |
333 | { |
361 | { |
334 | menuitem_t *item; |
362 | menuitem_t *item; |
335 | unsigned int len; |
363 | unsigned int len; |
336 | |
364 | |
337 | #ifdef DEBUG_STRICT |
365 | #ifdef DEBUG_STRICT |
338 | assert(name != NULL); |
366 | assert (name != NULL); |
339 | assert(action != NULL); |
367 | assert (action != NULL); |
340 | #endif |
368 | #endif |
341 | |
369 | |
342 | if (menu == NULL) |
370 | if (menu == NULL) |
343 | return NULL; |
371 | return NULL; |
344 | |
372 | |
345 | if (isSeparator(name)) { |
373 | if (isSeparator (name)) |
|
|
374 | { |
346 | /* add separator, no action */ |
375 | /* add separator, no action */ |
347 | name = ""; |
376 | name = ""; |
348 | action = ""; |
377 | action = ""; |
349 | } else { |
|
|
350 | /* |
|
|
351 | * add/replace existing menu item |
|
|
352 | */ |
|
|
353 | item = rxvt_menuitem_find(menu, name); |
|
|
354 | if (item != NULL) { |
|
|
355 | if (item->name2 != NULL && name2 != NULL) { |
|
|
356 | free(item->name2); |
|
|
357 | item->len2 = 0; |
|
|
358 | item->name2 = NULL; |
|
|
359 | } |
378 | } |
|
|
379 | else |
|
|
380 | { |
|
|
381 | /* |
|
|
382 | * add/replace existing menu item |
|
|
383 | */ |
|
|
384 | item = rxvt_menuitem_find (menu, name); |
|
|
385 | if (item != NULL) |
|
|
386 | { |
|
|
387 | if (item->name2 != NULL && name2 != NULL) |
|
|
388 | { |
|
|
389 | free (item->name2); |
|
|
390 | item->len2 = 0; |
|
|
391 | item->name2 = NULL; |
|
|
392 | } |
360 | switch (item->entry.type) { |
393 | switch (item->entry.type) |
|
|
394 | { |
361 | case MenuAction: |
395 | case MenuAction: |
362 | case MenuTerminalAction: |
396 | case MenuTerminalAction: |
363 | free(item->entry.action.str); |
397 | free (item->entry.action.str); |
364 | item->entry.action.str = NULL; |
398 | item->entry.action.str = NULL; |
365 | break; |
399 | break; |
|
|
400 | } |
|
|
401 | goto Item_Found; |
|
|
402 | } |
366 | } |
403 | } |
367 | goto Item_Found; |
|
|
368 | } |
|
|
369 | } |
|
|
370 | /* allocate a new itemect */ |
404 | /* allocate a new itemect */ |
371 | item = (menuitem_t *) rxvt_malloc(sizeof(menuitem_t)); |
405 | item = (menuitem_t *) rxvt_malloc (sizeof (menuitem_t)); |
372 | |
406 | |
373 | item->len2 = 0; |
407 | item->len2 = 0; |
374 | item->name2 = NULL; |
408 | item->name2 = NULL; |
375 | |
409 | |
376 | len = STRLEN(name); |
410 | len = STRLEN (name); |
377 | item->name = rxvt_malloc(len + 1); |
411 | item->name = (char *)rxvt_malloc (len + 1); |
378 | STRCPY(item->name, name); |
412 | STRCPY (item->name, name); |
379 | if (name[0] == '.' && name[1] != '.') |
413 | if (name[0] == '.' && name[1] != '.') |
380 | len = 0; /* hidden menu name */ |
414 | len = 0; /* hidden menu name */ |
381 | item->len = len; |
415 | item->len = len; |
382 | |
416 | |
383 | /* add to tail of list */ |
417 | /* add to tail of list */ |
384 | item->prev = menu->tail; |
418 | item->prev = menu->tail; |
385 | item->next = NULL; |
419 | item->next = NULL; |
386 | |
420 | |
387 | if (menu->tail != NULL) |
421 | if (menu->tail != NULL) |
388 | (menu->tail)->next = item; |
422 | (menu->tail)->next = item; |
389 | menu->tail = item; |
423 | menu->tail = item; |
390 | /* fix head */ |
424 | /* fix head */ |
391 | if (menu->head == NULL) |
425 | if (menu->head == NULL) |
392 | menu->head = item; |
426 | menu->head = item; |
393 | |
427 | |
394 | /* |
428 | /* |
395 | * add action |
429 | * add action |
396 | */ |
430 | */ |
397 | Item_Found: |
431 | Item_Found: |
398 | if (name2 != NULL && item->name2 == NULL) { |
432 | if (name2 != NULL && item->name2 == NULL) |
|
|
433 | { |
399 | len = STRLEN(name2); |
434 | len = STRLEN (name2); |
400 | if (len == 0) |
435 | if (len == 0) |
401 | item->name2 = NULL; |
436 | item->name2 = NULL; |
402 | else { |
437 | else |
|
|
438 | { |
403 | item->name2 = rxvt_malloc(len + 1); |
439 | item->name2 = (char *)rxvt_malloc (len + 1); |
404 | STRCPY(item->name2, name2); |
440 | STRCPY (item->name2, name2); |
405 | } |
441 | } |
406 | item->len2 = len; |
442 | item->len2 = len; |
407 | } |
443 | } |
408 | item->entry.type = MenuLabel; |
444 | item->entry.type = MenuLabel; |
409 | len = STRLEN(action); |
445 | len = STRLEN (action); |
410 | |
446 | |
411 | if (len == 0 && item->name2 != NULL) { |
447 | if (len == 0 && item->name2 != NULL) |
|
|
448 | { |
412 | action = item->name2; |
449 | action = item->name2; |
413 | len = item->len2; |
450 | len = item->len2; |
414 | } |
451 | } |
415 | if (len) { |
452 | if (len) |
|
|
453 | { |
416 | unsigned char *str = rxvt_malloc(len + 1); |
454 | unsigned char *str = (unsigned char *)rxvt_malloc (len + 1); |
417 | |
455 | |
418 | STRCPY(str, action); |
456 | STRCPY (str, action); |
419 | |
457 | |
420 | if (rxvt_action_type(&(item->entry.action), str) < 0) |
458 | if (rxvt_action_type (& (item->entry.action), str) < 0) |
421 | free(str); |
459 | free (str); |
422 | } |
460 | } |
423 | /* new item and a possible increase in width */ |
461 | /* new item and a possible increase in width */ |
424 | if (menu->width < (item->len + item->len2)) |
462 | if (menu->width < (item->len + item->len2)) |
425 | menu->width = (item->len + item->len2); |
463 | menu->width = (item->len + item->len2); |
426 | |
464 | |
427 | return item; |
465 | return item; |
428 | } |
466 | } |
429 | |
467 | |
430 | /* |
468 | /* |
431 | * search for the base starting menu for NAME. |
469 | * search for the base starting menu for NAME. |
432 | * return a pointer to the portion of NAME that remains |
470 | * return a pointer to the portion of NAME that remains |
433 | */ |
471 | */ |
434 | char * |
472 | char * |
435 | rxvt_term::menu_find_base (menu_t **menu, char *path) |
473 | rxvt_term::menu_find_base (menu_t **menu, char *path) |
436 | { |
474 | { |
437 | menu_t *m = NULL; |
475 | menu_t *m = NULL; |
438 | menuitem_t *item; |
476 | menuitem_t *item; |
439 | |
477 | |
440 | #ifdef DEBUG_STRICT |
478 | #ifdef DEBUG_STRICT |
441 | assert(menu != NULL); |
479 | assert (menu != NULL); |
442 | assert(CurrentBar != NULL); |
480 | assert (CurrentBar != NULL); |
443 | #endif |
481 | #endif |
444 | |
482 | |
445 | if (path[0] == '\0') |
483 | if (path[0] == '\0') |
446 | return path; |
|
|
447 | |
|
|
448 | if (STRCHR(path, '/') != NULL) { |
|
|
449 | char *p = path; |
|
|
450 | |
|
|
451 | while ((p = STRCHR(p, '/')) != NULL) { |
|
|
452 | p++; |
|
|
453 | if (*p == '/') |
|
|
454 | path = p; |
|
|
455 | } |
|
|
456 | if (path[0] == '/') { |
|
|
457 | path++; |
|
|
458 | *menu = NULL; |
|
|
459 | } |
|
|
460 | while ((p = STRCHR(path, '/')) != NULL) { |
|
|
461 | p[0] = '\0'; |
|
|
462 | if (path[0] == '\0') |
|
|
463 | return NULL; |
|
|
464 | if (!STRCMP(path, DOT)) { |
|
|
465 | /* nothing to do */ |
|
|
466 | } else if (!STRCMP(path, DOTS)) { |
|
|
467 | if (*menu != NULL) |
|
|
468 | *menu = (*menu)->parent; |
|
|
469 | } else { |
|
|
470 | path = menu_find_base (menu, path); |
|
|
471 | if (path[0] != '\0') { /* not found */ |
|
|
472 | p[0] = '/'; /* fix-up name again */ |
|
|
473 | return path; |
|
|
474 | } |
|
|
475 | } |
|
|
476 | |
|
|
477 | path = (p + 1); |
|
|
478 | } |
|
|
479 | } |
|
|
480 | if (!STRCMP(path, DOTS)) { |
|
|
481 | path += STRLEN(DOTS); |
|
|
482 | if (*menu != NULL) |
|
|
483 | *menu = (*menu)->parent; |
|
|
484 | return path; |
|
|
485 | } |
|
|
486 | /* find this menu */ |
|
|
487 | if (*menu == NULL) { |
|
|
488 | for (m = CurrentBar->tail; m != NULL; m = m->prev) { |
|
|
489 | if (!STRCMP(path, m->name)) |
|
|
490 | break; |
|
|
491 | } |
|
|
492 | } else { |
|
|
493 | /* find this menu */ |
|
|
494 | for (item = (*menu)->tail; item != NULL; item = item->prev) { |
|
|
495 | if (item->entry.type == MenuSubMenu |
|
|
496 | && !STRCMP(path, (item->entry.submenu.menu)->name)) { |
|
|
497 | m = (item->entry.submenu.menu); |
|
|
498 | break; |
|
|
499 | } |
|
|
500 | } |
|
|
501 | } |
|
|
502 | if (m != NULL) { |
|
|
503 | *menu = m; |
|
|
504 | path += STRLEN(path); |
|
|
505 | } |
|
|
506 | return path; |
484 | return path; |
|
|
485 | |
|
|
486 | if (STRCHR (path, '/') != NULL) |
|
|
487 | { |
|
|
488 | char *p = path; |
|
|
489 | |
|
|
490 | while ((p = STRCHR (p, '/')) != NULL) |
|
|
491 | { |
|
|
492 | p++; |
|
|
493 | if (*p == '/') |
|
|
494 | path = p; |
|
|
495 | } |
|
|
496 | if (path[0] == '/') |
|
|
497 | { |
|
|
498 | path++; |
|
|
499 | *menu = NULL; |
|
|
500 | } |
|
|
501 | while ((p = STRCHR (path, '/')) != NULL) |
|
|
502 | { |
|
|
503 | p[0] = '\0'; |
|
|
504 | if (path[0] == '\0') |
|
|
505 | return NULL; |
|
|
506 | if (!STRCMP (path, DOT)) |
|
|
507 | { |
|
|
508 | /* nothing to do */ |
|
|
509 | } |
|
|
510 | else if (!STRCMP (path, DOTS)) |
|
|
511 | { |
|
|
512 | if (*menu != NULL) |
|
|
513 | *menu = (*menu)->parent; |
|
|
514 | } |
|
|
515 | else |
|
|
516 | { |
|
|
517 | path = menu_find_base (menu, path); |
|
|
518 | if (path[0] != '\0') |
|
|
519 | { /* not found */ |
|
|
520 | p[0] = '/'; /* fix-up name again */ |
|
|
521 | return path; |
|
|
522 | } |
|
|
523 | } |
|
|
524 | |
|
|
525 | path = (p + 1); |
|
|
526 | } |
|
|
527 | } |
|
|
528 | if (!STRCMP (path, DOTS)) |
|
|
529 | { |
|
|
530 | path += STRLEN (DOTS); |
|
|
531 | if (*menu != NULL) |
|
|
532 | *menu = (*menu)->parent; |
|
|
533 | return path; |
|
|
534 | } |
|
|
535 | /* find this menu */ |
|
|
536 | if (*menu == NULL) |
|
|
537 | { |
|
|
538 | for (m = CurrentBar->tail; m != NULL; m = m->prev) |
|
|
539 | { |
|
|
540 | if (!STRCMP (path, m->name)) |
|
|
541 | break; |
|
|
542 | } |
|
|
543 | } |
|
|
544 | else |
|
|
545 | { |
|
|
546 | /* find this menu */ |
|
|
547 | for (item = (*menu)->tail; item != NULL; item = item->prev) |
|
|
548 | { |
|
|
549 | if (item->entry.type == MenuSubMenu |
|
|
550 | && !STRCMP (path, (item->entry.submenu.menu)->name)) |
|
|
551 | { |
|
|
552 | m = (item->entry.submenu.menu); |
|
|
553 | break; |
|
|
554 | } |
|
|
555 | } |
|
|
556 | } |
|
|
557 | if (m != NULL) |
|
|
558 | { |
|
|
559 | *menu = m; |
|
|
560 | path += STRLEN (path); |
|
|
561 | } |
|
|
562 | return path; |
507 | } |
563 | } |
508 | |
564 | |
509 | /* |
565 | /* |
510 | * delete this entire menu |
566 | * delete this entire menu |
511 | */ |
567 | */ |
512 | menu_t * |
568 | menu_t * |
513 | rxvt_term::menu_delete (menu_t *menu) |
569 | rxvt_term::menu_delete (menu_t *menu) |
514 | { |
570 | { |
515 | menu_t *parent = NULL, *prev, *next; |
571 | menu_t *parent = NULL, *prev, *next; |
516 | menuitem_t *item; |
572 | menuitem_t *item; |
517 | bar_t *CurrentBar = CurrentBar; |
573 | bar_t *CurrentBar = CurrentBar; |
518 | |
574 | |
519 | #ifdef DEBUG_STRICT |
575 | #ifdef DEBUG_STRICT |
520 | assert(CurrentBar != NULL); |
576 | assert (CurrentBar != NULL); |
521 | #endif |
577 | #endif |
522 | |
578 | |
523 | /* delete the entire menu */ |
579 | /* delete the entire menu */ |
524 | if (menu == NULL) |
580 | if (menu == NULL) |
525 | return NULL; |
581 | return NULL; |
526 | |
582 | |
527 | parent = menu->parent; |
583 | parent = menu->parent; |
528 | |
584 | |
529 | /* unlink MENU */ |
585 | /* unlink MENU */ |
530 | prev = menu->prev; |
586 | prev = menu->prev; |
531 | next = menu->next; |
587 | next = menu->next; |
532 | if (prev != NULL) |
588 | if (prev != NULL) |
533 | prev->next = next; |
589 | prev->next = next; |
534 | if (next != NULL) |
590 | if (next != NULL) |
535 | next->prev = prev; |
591 | next->prev = prev; |
536 | |
592 | |
537 | /* fix the index */ |
593 | /* fix the index */ |
538 | if (parent == NULL) { |
594 | if (parent == NULL) |
|
|
595 | { |
539 | const int len = (menu->len + HSPACE); |
596 | const int len = (menu->len + HSPACE); |
540 | |
597 | |
541 | if (CurrentBar->tail == menu) |
598 | if (CurrentBar->tail == menu) |
542 | CurrentBar->tail = prev; |
599 | CurrentBar->tail = prev; |
543 | if (CurrentBar->head == menu) |
600 | if (CurrentBar->head == menu) |
544 | CurrentBar->head = next; |
601 | CurrentBar->head = next; |
545 | |
602 | |
546 | for (next = menu->next; next != NULL; next = next->next) |
603 | for (next = menu->next; next != NULL; next = next->next) |
547 | next->x -= len; |
604 | next->x -= len; |
548 | } else { |
605 | } |
|
|
606 | else |
|
|
607 | { |
549 | for (item = parent->tail; item != NULL; item = item->prev) { |
608 | for (item = parent->tail; item != NULL; item = item->prev) |
|
|
609 | { |
550 | if (item->entry.type == MenuSubMenu |
610 | if (item->entry.type == MenuSubMenu |
551 | && item->entry.submenu.menu == menu) { |
611 | && item->entry.submenu.menu == menu) |
|
|
612 | { |
552 | item->entry.submenu.menu = NULL; |
613 | item->entry.submenu.menu = NULL; |
553 | menuitem_free (menu->parent, item); |
614 | menuitem_free (menu->parent, item); |
554 | break; |
615 | break; |
|
|
616 | } |
|
|
617 | } |
555 | } |
618 | } |
556 | } |
|
|
557 | } |
|
|
558 | |
619 | |
559 | item = menu->tail; |
620 | item = menu->tail; |
560 | while (item != NULL) { |
621 | while (item != NULL) |
|
|
622 | { |
561 | menuitem_t *p = item->prev; |
623 | menuitem_t *p = item->prev; |
562 | |
624 | |
563 | menuitem_free (menu, item); |
625 | menuitem_free (menu, item); |
564 | item = p; |
626 | item = p; |
565 | } |
627 | } |
566 | |
628 | |
567 | if (menu->name != NULL) |
629 | if (menu->name != NULL) |
568 | free(menu->name); |
630 | free (menu->name); |
569 | free(menu); |
631 | free (menu); |
570 | |
632 | |
571 | return parent; |
633 | return parent; |
572 | } |
634 | } |
573 | |
635 | |
574 | menu_t * |
636 | menu_t * |
575 | rxvt_term::menu_add (menu_t *parent, char *path) |
637 | rxvt_term::menu_add (menu_t *parent, char *path) |
576 | { |
638 | { |
577 | menu_t *menu; |
639 | menu_t *menu; |
578 | bar_t *CurrentBar = CurrentBar; |
640 | bar_t *CurrentBar = CurrentBar; |
579 | |
641 | |
580 | #ifdef DEBUG_STRICT |
642 | #ifdef DEBUG_STRICT |
581 | assert(CurrentBar != NULL); |
643 | assert (CurrentBar != NULL); |
582 | #endif |
644 | #endif |
583 | |
645 | |
584 | if (STRCHR(path, '/') != NULL) { |
646 | if (STRCHR (path, '/') != NULL) |
|
|
647 | { |
585 | char *p; |
648 | char *p; |
586 | |
649 | |
587 | if (path[0] == '/') { |
650 | if (path[0] == '/') |
|
|
651 | { |
588 | /* shouldn't happen */ |
652 | /* shouldn't happen */ |
589 | path++; |
653 | path++; |
590 | parent = NULL; |
654 | parent = NULL; |
591 | } |
655 | } |
592 | while ((p = STRCHR(path, '/')) != NULL) { |
656 | while ((p = STRCHR (path, '/')) != NULL) |
|
|
657 | { |
593 | p[0] = '\0'; |
658 | p[0] = '\0'; |
594 | if (path[0] == '\0') |
659 | if (path[0] == '\0') |
595 | return NULL; |
660 | return NULL; |
596 | |
661 | |
597 | parent = menu_add (parent, path); |
662 | parent = menu_add (parent, path); |
598 | path = (p + 1); |
663 | path = (p + 1); |
599 | } |
664 | } |
600 | } |
665 | } |
601 | if (!STRCMP(path, DOTS)) |
666 | if (!STRCMP (path, DOTS)) |
602 | return (parent != NULL ? parent->parent : parent); |
667 | return (parent != NULL ? parent->parent : parent); |
603 | |
668 | |
604 | if (!STRCMP(path, DOT) || path[0] == '\0') |
669 | if (!STRCMP (path, DOT) || path[0] == '\0') |
605 | return parent; |
670 | return parent; |
606 | |
671 | |
607 | /* allocate a new menu */ |
672 | /* allocate a new menu */ |
608 | menu = (menu_t *) rxvt_malloc(sizeof(menu_t)); |
673 | menu = (menu_t *) rxvt_malloc (sizeof (menu_t)); |
609 | |
674 | |
610 | menu->width = 0; |
675 | menu->width = 0; |
611 | menu->parent = parent; |
676 | menu->parent = parent; |
612 | menu->len = STRLEN(path); |
677 | menu->len = STRLEN (path); |
613 | menu->name = rxvt_malloc((menu->len + 1)); |
678 | menu->name = (char *)rxvt_malloc ((menu->len + 1)); |
614 | STRCPY(menu->name, path); |
679 | STRCPY (menu->name, path); |
615 | |
680 | |
616 | /* initialize head/tail */ |
681 | /* initialize head/tail */ |
617 | menu->head = menu->tail = NULL; |
682 | menu->head = menu->tail = NULL; |
618 | menu->prev = menu->next = NULL; |
683 | menu->prev = menu->next = NULL; |
619 | |
684 | |
620 | menu->win = None; |
685 | menu->win = None; |
621 | menu->x = menu->y = menu->w = menu->h = 0; |
686 | menu->x = menu->y = menu->w = menu->h = 0; |
622 | menu->item = NULL; |
687 | menu->item = NULL; |
623 | |
688 | |
624 | /* add to tail of list */ |
689 | /* add to tail of list */ |
625 | if (parent == NULL) { |
690 | if (parent == NULL) |
|
|
691 | { |
626 | menu->prev = CurrentBar->tail; |
692 | menu->prev = CurrentBar->tail; |
627 | if (CurrentBar->tail != NULL) |
693 | if (CurrentBar->tail != NULL) |
628 | CurrentBar->tail->next = menu; |
694 | CurrentBar->tail->next = menu; |
629 | CurrentBar->tail = menu; |
695 | CurrentBar->tail = menu; |
630 | if (CurrentBar->head == NULL) |
696 | if (CurrentBar->head == NULL) |
631 | CurrentBar->head = menu; /* fix head */ |
697 | CurrentBar->head = menu; /* fix head */ |
632 | if (menu->prev) |
698 | if (menu->prev) |
633 | menu->x = (menu->prev->x + menu->prev->len + HSPACE); |
699 | menu->x = (menu->prev->x + menu->prev->len + HSPACE); |
634 | } else { |
700 | } |
|
|
701 | else |
|
|
702 | { |
635 | menuitem_t *item; |
703 | menuitem_t *item; |
636 | |
704 | |
637 | item = rxvt_menuitem_add(parent, path, "", ""); |
705 | item = rxvt_menuitem_add (parent, path, "", ""); |
638 | if (item == NULL) { |
706 | if (item == NULL) |
|
|
707 | { |
639 | free(menu); |
708 | free (menu); |
640 | return parent; |
709 | return parent; |
641 | } |
710 | } |
642 | #ifdef DEBUG_STRICT |
711 | #ifdef DEBUG_STRICT |
643 | assert(item->entry.type == MenuLabel); |
712 | assert (item->entry.type == MenuLabel); |
644 | #endif |
713 | #endif |
645 | item->entry.type = MenuSubMenu; |
714 | item->entry.type = MenuSubMenu; |
646 | item->entry.submenu.menu = menu; |
715 | item->entry.submenu.menu = menu; |
647 | } |
716 | } |
648 | |
717 | |
649 | return menu; |
718 | return menu; |
650 | } |
719 | } |
651 | |
720 | |
652 | void |
721 | void |
653 | rxvt_term::drawbox_menubar (int x, int len, int state) |
722 | rxvt_term::drawbox_menubar (int x, int len, int state) |
654 | { |
723 | { |
655 | GC top, bot; |
724 | GC top, bot; |
656 | |
725 | |
657 | x = Width2Pixel(x); |
726 | x = Width2Pixel (x); |
658 | len = Width2Pixel(len + HSPACE); |
727 | len = Width2Pixel (len + HSPACE); |
659 | if (x >= TermWin.width) |
728 | if (x >= TermWin.width) |
660 | return; |
729 | return; |
661 | else if (x + len >= TermWin.width) |
730 | else if (x + len >= TermWin.width) |
662 | len = (TermWin_TotalWidth() - x); |
731 | len = (TermWin_TotalWidth () - x); |
663 | |
732 | |
664 | #ifdef MENUBAR_SHADOW_IN |
733 | #ifdef MENUBAR_SHADOW_IN |
665 | state = -state; |
734 | state = -state; |
666 | #endif |
735 | #endif |
667 | switch (state) { |
736 | switch (state) |
|
|
737 | { |
668 | case +1: |
738 | case +1: |
669 | top = topShadowGC; |
739 | top = topShadowGC; |
670 | bot = botShadowGC; |
740 | bot = botShadowGC; |
671 | break; /* SHADOW_OUT */ |
741 | break; /* SHADOW_OUT */ |
672 | case -1: |
742 | case -1: |
673 | top = botShadowGC; |
743 | top = botShadowGC; |
674 | bot = topShadowGC; |
744 | bot = topShadowGC; |
675 | break; /* SHADOW_IN */ |
745 | break; /* SHADOW_IN */ |
676 | default: |
746 | default: |
677 | top = bot = scrollbarGC; |
747 | top = bot = scrollbarGC; |
678 | break; /* neutral */ |
748 | break; /* neutral */ |
679 | } |
749 | } |
680 | |
750 | |
681 | rxvt_Draw_Shadow(Xdisplay, menuBar.win, top, bot, |
751 | rxvt_Draw_Shadow (display->display, menuBar.win, top, bot, |
682 | x, 0, len, menuBar_TotalHeight()); |
752 | x, 0, len, menuBar_TotalHeight ()); |
683 | } |
753 | } |
684 | |
754 | |
685 | void |
755 | void |
686 | rxvt_term::drawtriangle (int x, int y, int state) |
756 | rxvt_term::drawtriangle (int x, int y, int state) |
687 | { |
757 | { |
688 | GC top, bot; |
758 | GC top, bot; |
689 | int w; |
759 | int w; |
690 | |
760 | |
691 | #ifdef MENU_SHADOW_IN |
761 | #ifdef MENU_SHADOW_IN |
692 | state = -state; |
762 | state = -state; |
693 | #endif |
763 | #endif |
694 | switch (state) { |
764 | switch (state) |
|
|
765 | { |
695 | case +1: |
766 | case +1: |
696 | top = topShadowGC; |
767 | top = topShadowGC; |
697 | bot = botShadowGC; |
768 | bot = botShadowGC; |
698 | break; /* SHADOW_OUT */ |
769 | break; /* SHADOW_OUT */ |
699 | case -1: |
770 | case -1: |
700 | top = botShadowGC; |
771 | top = botShadowGC; |
701 | bot = topShadowGC; |
772 | bot = topShadowGC; |
702 | break; /* SHADOW_IN */ |
773 | break; /* SHADOW_IN */ |
703 | default: |
774 | default: |
704 | top = bot = scrollbarGC; |
775 | top = bot = scrollbarGC; |
705 | break; /* neutral */ |
776 | break; /* neutral */ |
706 | } |
777 | } |
707 | |
778 | |
708 | w = Height2Pixel(1) - 2 * SHADOW; |
779 | w = Height2Pixel (1) - 2 * SHADOW; |
709 | |
780 | |
710 | x -= SHADOW + (3 * w / 2); |
781 | x -= SHADOW + (3 * w / 2); |
711 | y += SHADOW * 3; |
782 | y += SHADOW * 3; |
712 | |
783 | |
713 | rxvt_Draw_Triangle(Xdisplay, ActiveMenu->win, top, bot, x, y, w, |
784 | rxvt_Draw_Triangle (display->display, ActiveMenu->win, top, bot, x, y, w, |
714 | 'r'); |
785 | 'r'); |
715 | } |
786 | } |
716 | |
787 | |
717 | void |
788 | void |
718 | rxvt_term::drawbox_menuitem (int y, int state) |
789 | rxvt_term::drawbox_menuitem (int y, int state) |
719 | { |
790 | { |
720 | GC top, bot; |
791 | GC top, bot; |
721 | |
792 | |
722 | #ifdef MENU_SHADOW_IN |
793 | #ifdef MENU_SHADOW_IN |
723 | state = -state; |
794 | state = -state; |
724 | #endif |
795 | #endif |
725 | switch (state) { |
796 | switch (state) |
|
|
797 | { |
726 | case +1: |
798 | case +1: |
727 | top = topShadowGC; |
799 | top = topShadowGC; |
728 | bot = botShadowGC; |
800 | bot = botShadowGC; |
729 | break; /* SHADOW_OUT */ |
801 | break; /* SHADOW_OUT */ |
730 | case -1: |
802 | case -1: |
731 | top = botShadowGC; |
803 | top = botShadowGC; |
732 | bot = topShadowGC; |
804 | bot = topShadowGC; |
733 | break; /* SHADOW_IN */ |
805 | break; /* SHADOW_IN */ |
734 | default: |
806 | default: |
735 | top = bot = scrollbarGC; |
807 | top = bot = scrollbarGC; |
736 | break; /* neutral */ |
808 | break; /* neutral */ |
737 | } |
809 | } |
738 | |
810 | |
739 | rxvt_Draw_Shadow(Xdisplay, ActiveMenu->win, top, bot, |
811 | rxvt_Draw_Shadow (display->display, ActiveMenu->win, top, bot, |
740 | SHADOW + 0, SHADOW + y, |
812 | SHADOW + 0, SHADOW + y, |
741 | ActiveMenu->w - 2 * (SHADOW), |
813 | ActiveMenu->w - 2 * (SHADOW), |
742 | HEIGHT_TEXT + 2 * SHADOW); |
814 | HEIGHT_TEXT + 2 * SHADOW); |
743 | XFlush(Xdisplay); |
815 | XFlush (display->display); |
744 | } |
816 | } |
745 | |
817 | |
746 | #ifdef DEBUG_MENU_LAYOUT |
818 | #ifdef DEBUG_MENU_LAYOUT |
747 | void |
819 | void |
748 | rxvt_print_menu_ancestors(menu_t *menu) |
820 | rxvt_print_menu_ancestors (menu_t *menu) |
749 | { |
821 | { |
750 | if (menu == NULL) { |
822 | if (menu == NULL) |
|
|
823 | { |
751 | fprintf(stderr, "Top Level menu\n"); |
824 | fprintf (stderr, "Top Level menu\n"); |
752 | return; |
825 | return; |
753 | } |
826 | } |
754 | fprintf(stderr, "menu %s ", menu->name); |
827 | fprintf (stderr, "menu %s ", menu->name); |
755 | if (menu->parent != NULL) { |
828 | if (menu->parent != NULL) |
|
|
829 | { |
756 | menuitem_t *item; |
830 | menuitem_t *item; |
757 | |
831 | |
758 | for (item = menu->parent->head; item != NULL; item = item->next) { |
832 | for (item = menu->parent->head; item != NULL; item = item->next) |
|
|
833 | { |
759 | if (item->entry.type == MenuSubMenu |
834 | if (item->entry.type == MenuSubMenu |
760 | && item->entry.submenu.menu == menu) { |
835 | && item->entry.submenu.menu == menu) |
761 | break; |
836 | { |
|
|
837 | break; |
|
|
838 | } |
|
|
839 | } |
|
|
840 | if (item == NULL) |
|
|
841 | { |
|
|
842 | fprintf (stderr, "is an orphan!\n"); |
|
|
843 | return; |
|
|
844 | } |
762 | } |
845 | } |
763 | } |
|
|
764 | if (item == NULL) { |
|
|
765 | fprintf(stderr, "is an orphan!\n"); |
|
|
766 | return; |
|
|
767 | } |
|
|
768 | } |
|
|
769 | fprintf(stderr, "\n"); |
846 | fprintf (stderr, "\n"); |
770 | rxvt_print_menu_ancestors(menu->parent); |
847 | rxvt_print_menu_ancestors (menu->parent); |
771 | } |
848 | } |
772 | |
849 | |
773 | void |
850 | void |
774 | rxvt_print_menu_descendants(menu_t *menu) |
851 | rxvt_print_menu_descendants (menu_t *menu) |
775 | { |
852 | { |
776 | menuitem_t *item; |
853 | menuitem_t *item; |
777 | menu_t *parent; |
854 | menu_t *parent; |
778 | int i, level = 0; |
855 | int i, level = 0; |
779 | |
856 | |
780 | parent = menu; |
857 | parent = menu; |
|
|
858 | do |
781 | do { |
859 | { |
782 | level++; |
860 | level++; |
783 | parent = parent->parent; |
861 | parent = parent->parent; |
784 | } |
862 | } |
785 | while (parent != NULL); |
863 | while (parent != NULL); |
786 | |
864 | |
787 | for (i = 0; i < level; i++) |
865 | for (i = 0; i < level; i++) |
788 | fprintf(stderr, ">"); |
866 | fprintf (stderr, ">"); |
789 | fprintf(stderr, "%s\n", menu->name); |
867 | fprintf (stderr, "%s\n", menu->name); |
790 | |
868 | |
791 | for (item = menu->head; item != NULL; item = item->next) { |
869 | for (item = menu->head; item != NULL; item = item->next) |
|
|
870 | { |
792 | if (item->entry.type == MenuSubMenu) { |
871 | if (item->entry.type == MenuSubMenu) |
|
|
872 | { |
793 | if (item->entry.submenu.menu == NULL) |
873 | if (item->entry.submenu.menu == NULL) |
794 | fprintf(stderr, "> %s == NULL\n", item->name); |
874 | fprintf (stderr, "> %s == NULL\n", item->name); |
795 | else |
875 | else |
796 | rxvt_print_menu_descendants(item->entry.submenu.menu); |
876 | rxvt_print_menu_descendants (item->entry.submenu.menu); |
797 | } else { |
877 | } |
|
|
878 | else |
|
|
879 | { |
798 | for (i = 0; i < level; i++) |
880 | for (i = 0; i < level; i++) |
799 | fprintf(stderr, "+"); |
881 | fprintf (stderr, "+"); |
800 | if (item->entry.type == MenuLabel) |
882 | if (item->entry.type == MenuLabel) |
801 | fprintf(stderr, "label: "); |
883 | fprintf (stderr, "label: "); |
802 | fprintf(stderr, "%s\n", item->name); |
884 | fprintf (stderr, "%s\n", item->name); |
803 | } |
885 | } |
804 | } |
886 | } |
805 | |
887 | |
806 | for (i = 0; i < level; i++) |
888 | for (i = 0; i < level; i++) |
807 | fprintf(stderr, "<"); |
889 | fprintf (stderr, "<"); |
808 | fprintf(stderr, "\n"); |
890 | fprintf (stderr, "\n"); |
809 | } |
891 | } |
810 | #endif |
892 | #endif |
811 | |
893 | |
812 | /* pop up/down the current menu and redraw the menuBar button */ |
894 | /* pop up/down the current menu and redraw the menuBar button */ |
813 | void |
895 | void |
814 | rxvt_term::menu_show () |
896 | rxvt_term::menu_show () |
815 | { |
897 | { |
816 | int x, y, xright; |
898 | int x, y, xright; |
817 | menu_t *ActiveMenu = ActiveMenu; |
899 | menu_t *ActiveMenu = ActiveMenu; |
818 | menuitem_t *item; |
900 | menuitem_t *item; |
819 | |
901 | |
820 | if (ActiveMenu == NULL) |
902 | if (ActiveMenu == NULL) |
821 | return; |
903 | return; |
822 | |
904 | |
823 | x = ActiveMenu->x; |
905 | x = ActiveMenu->x; |
824 | if (ActiveMenu->parent == NULL) { |
906 | if (ActiveMenu->parent == NULL) |
|
|
907 | { |
825 | register int h; |
908 | register int h; |
826 | |
909 | |
827 | drawbox_menubar (x, ActiveMenu->len, -1); |
910 | drawbox_menubar (x, ActiveMenu->len, -1); |
828 | x = Width2Pixel(x); |
911 | x = Width2Pixel (x); |
829 | |
912 | |
830 | ActiveMenu->y = 1; |
913 | ActiveMenu->y = 1; |
831 | ActiveMenu->w = Menu_PixelWidth(ActiveMenu); |
914 | ActiveMenu->w = Menu_PixelWidth (ActiveMenu); |
832 | |
915 | |
833 | if ((x + ActiveMenu->w) >= TermWin.width) |
916 | if ((x + ActiveMenu->w) >= TermWin.width) |
834 | x = (TermWin_TotalWidth() - ActiveMenu->w); |
917 | x = (TermWin_TotalWidth () - ActiveMenu->w); |
835 | |
918 | |
836 | /* find the height */ |
919 | /* find the height */ |
837 | for (h = 0, item = ActiveMenu->head; item != NULL; item = item->next) |
920 | for (h = 0, item = ActiveMenu->head; item != NULL; item = item->next) |
838 | h += isSeparator(item->name) ? HEIGHT_SEPARATOR |
921 | h += isSeparator (item->name) ? HEIGHT_SEPARATOR |
839 | : HEIGHT_TEXT + 2 * SHADOW; |
922 | : HEIGHT_TEXT + 2 * SHADOW; |
840 | ActiveMenu->h = h + 2 * SHADOW; |
923 | ActiveMenu->h = h + 2 * SHADOW; |
841 | } |
924 | } |
842 | if (ActiveMenu->win == None) { |
925 | if (ActiveMenu->win == None) |
|
|
926 | { |
843 | ActiveMenu->win = XCreateSimpleWindow(Xdisplay, TermWin.vt, |
927 | ActiveMenu->win = XCreateSimpleWindow (display->display, TermWin.vt, |
844 | x, ActiveMenu->y, |
928 | x, ActiveMenu->y, |
845 | ActiveMenu->w, ActiveMenu->h, |
929 | ActiveMenu->w, ActiveMenu->h, |
846 | 0, |
930 | 0, |
847 | PixColors[Color_fg], |
931 | PixColors[Color_fg], |
848 | PixColors[Color_scroll]); |
932 | PixColors[Color_scroll]); |
849 | XMapWindow(Xdisplay, ActiveMenu->win); |
933 | XMapWindow (display->display, ActiveMenu->win); |
850 | } |
934 | } |
851 | rxvt_Draw_Shadow(Xdisplay, ActiveMenu->win, |
935 | rxvt_Draw_Shadow (display->display, ActiveMenu->win, |
852 | topShadowGC, botShadowGC, |
936 | topShadowGC, botShadowGC, |
853 | 0, 0, ActiveMenu->w, ActiveMenu->h); |
937 | 0, 0, ActiveMenu->w, ActiveMenu->h); |
854 | |
938 | |
855 | /* determine the correct right-alignment */ |
939 | /* determine the correct right-alignment */ |
856 | for (xright = 0, item = ActiveMenu->head; item != NULL; item = item->next) |
940 | for (xright = 0, item = ActiveMenu->head; item != NULL; item = item->next) |
857 | if (item->len2 > xright) |
941 | if (item->len2 > xright) |
858 | xright = item->len2; |
942 | xright = item->len2; |
859 | |
943 | |
860 | for (y = 0, item = ActiveMenu->head; item != NULL; item = item->next) { |
944 | for (y = 0, item = ActiveMenu->head; item != NULL; item = item->next) |
|
|
945 | { |
861 | const int xoff = (SHADOW + Width2Pixel(HSPACE) / 2); |
946 | const int xoff = (SHADOW + Width2Pixel (HSPACE) / 2); |
862 | register int h; |
947 | register int h; |
863 | GC gc = menubarGC; |
948 | GC gc = menubarGC; |
864 | |
949 | |
865 | if (isSeparator(item->name)) { |
950 | if (isSeparator (item->name)) |
|
|
951 | { |
866 | rxvt_Draw_Shadow(Xdisplay, ActiveMenu->win, |
952 | rxvt_Draw_Shadow (display->display, ActiveMenu->win, |
867 | topShadowGC, botShadowGC, |
953 | topShadowGC, botShadowGC, |
868 | SHADOW, y + SHADOW + 1, |
954 | SHADOW, y + SHADOW + 1, |
869 | ActiveMenu->w - 2 * SHADOW, 0); |
955 | ActiveMenu->w - 2 * SHADOW, 0); |
870 | h = HEIGHT_SEPARATOR; |
956 | h = HEIGHT_SEPARATOR; |
871 | } else { |
957 | } |
|
|
958 | else |
|
|
959 | { |
872 | char *name = item->name; |
960 | char *name = item->name; |
873 | int len = item->len; |
961 | int len = item->len; |
874 | |
962 | |
875 | if (item->entry.type == MenuLabel) { |
963 | if (item->entry.type == MenuLabel) |
876 | gc = botShadowGC; |
964 | { |
|
|
965 | gc = botShadowGC; |
|
|
966 | } |
877 | } else if (item->entry.type == MenuSubMenu) { |
967 | else if (item->entry.type == MenuSubMenu) |
878 | int x1, y1; |
968 | { |
879 | menuitem_t *it; |
969 | int x1, y1; |
|
|
970 | menuitem_t *it; |
880 | menu_t *menu = item->entry.submenu.menu; |
971 | menu_t *menu = item->entry.submenu.menu; |
881 | |
972 | |
882 | drawtriangle (ActiveMenu->w, y, +1); |
973 | drawtriangle (ActiveMenu->w, y, +1); |
883 | |
974 | |
884 | name = menu->name; |
975 | name = menu->name; |
885 | len = menu->len; |
976 | len = menu->len; |
886 | |
977 | |
887 | y1 = ActiveMenu->y + y; |
978 | y1 = ActiveMenu->y + y; |
888 | |
979 | |
889 | menu->w = Menu_PixelWidth(menu); |
980 | menu->w = Menu_PixelWidth (menu); |
890 | |
981 | |
891 | /* place sub-menu at midpoint of parent menu */ |
982 | /* place sub-menu at midpoint of parent menu */ |
892 | x1 = ActiveMenu->w / 2; |
983 | x1 = ActiveMenu->w / 2; |
893 | if (x1 > menu->w) /* right-flush menu if too small */ |
984 | if (x1 > menu->w) /* right-flush menu if too small */ |
894 | x1 += (x1 - menu->w); |
985 | x1 += (x1 - menu->w); |
895 | x1 += x; |
986 | x1 += x; |
896 | |
987 | |
897 | /* find the height of this submenu */ |
988 | /* find the height of this submenu */ |
898 | for (h = 0, it = menu->head; it != NULL; it = it->next) |
989 | for (h = 0, it = menu->head; it != NULL; it = it->next) |
899 | h += isSeparator(it->name) ? HEIGHT_SEPARATOR |
990 | h += isSeparator (it->name) ? HEIGHT_SEPARATOR |
900 | : HEIGHT_TEXT + 2 * SHADOW; |
991 | : HEIGHT_TEXT + 2 * SHADOW; |
901 | menu->h = h + 2 * SHADOW; |
992 | menu->h = h + 2 * SHADOW; |
902 | |
993 | |
903 | /* ensure menu is in window limits */ |
994 | /* ensure menu is in window limits */ |
904 | if ((x1 + menu->w) >= TermWin.width) |
995 | if ((x1 + menu->w) >= TermWin.width) |
905 | x1 = (TermWin_TotalWidth() - menu->w); |
996 | x1 = (TermWin_TotalWidth () - menu->w); |
906 | |
997 | |
907 | if ((y1 + menu->h) >= TermWin.height) |
998 | if ((y1 + menu->h) >= TermWin.height) |
908 | y1 = (TermWin_TotalHeight() - menu->h); |
999 | y1 = (TermWin_TotalHeight () - menu->h); |
909 | |
1000 | |
910 | menu->x = (x1 < 0 ? 0 : x1); |
1001 | menu->x = (x1 < 0 ? 0 : x1); |
911 | menu->y = (y1 < 0 ? 0 : y1); |
1002 | menu->y = (y1 < 0 ? 0 : y1); |
|
|
1003 | } |
912 | } else if (item->name2 && !STRCMP(name, item->name2)) |
1004 | else if (item->name2 && !STRCMP (name, item->name2)) |
913 | name = NULL; |
1005 | name = NULL; |
914 | |
1006 | |
915 | if (len && name) { |
1007 | if (len && name) |
916 | #ifdef USE_XIM |
1008 | draw_string (display->display, ActiveMenu->win, gc, xoff, |
917 | if (TermWin.fontset) |
|
|
918 | XmbDrawString(Xdisplay, |
|
|
919 | ActiveMenu->win, TermWin.fontset, |
|
|
920 | gc, xoff, |
|
|
921 | 2 * SHADOW + y + TermWin.font->ascent + 1, |
1009 | 2 * SHADOW + y + TermWin.font->ascent + 1, |
922 | name, len); |
1010 | name, len); |
923 | else |
|
|
924 | #endif |
|
|
925 | XDrawString(Xdisplay, ActiveMenu->win, gc, xoff, |
|
|
926 | 2 * SHADOW + y + TermWin.font->ascent + 1, |
|
|
927 | name, len); |
|
|
928 | } |
|
|
929 | |
1011 | |
930 | len = item->len2; |
1012 | len = item->len2; |
931 | name = item->name2; |
1013 | name = item->name2; |
|
|
1014 | |
932 | if (len && name) { |
1015 | if (len && name) |
933 | #ifdef USE_XIM |
1016 | draw_string (display->display, ActiveMenu->win, gc, |
934 | if (TermWin.fontset) |
|
|
935 | XmbDrawString(Xdisplay, |
|
|
936 | ActiveMenu->win, TermWin.fontset, |
|
|
937 | gc, |
|
|
938 | ActiveMenu->w - (xoff + Width2Pixel(xright)), |
1017 | ActiveMenu->w - (xoff + Width2Pixel (xright)), |
939 | 2 * SHADOW + y + TermWin.font->ascent + 1, |
1018 | 2 * SHADOW + y + TermWin.font->ascent + 1, |
940 | name, len); |
1019 | name, len); |
941 | else |
1020 | |
942 | #endif |
|
|
943 | XDrawString(Xdisplay, ActiveMenu->win, gc, |
|
|
944 | ActiveMenu->w - (xoff + Width2Pixel(xright)), |
|
|
945 | 2 * SHADOW + y + TermWin.font->ascent + 1, |
|
|
946 | name, len); |
|
|
947 | } |
|
|
948 | h = HEIGHT_TEXT + 2 * SHADOW; |
1021 | h = HEIGHT_TEXT + 2 * SHADOW; |
949 | } |
1022 | } |
950 | y += h; |
1023 | y += h; |
951 | } |
1024 | } |
952 | } |
1025 | } |
953 | |
1026 | |
954 | void |
1027 | void |
955 | rxvt_term::menu_display (void (*update)(rxvt_t *)) |
1028 | rxvt_term::menu_display (void (rxvt_term::*update) ()) |
956 | { |
1029 | { |
957 | menu_t *ActiveMenu = ActiveMenu; |
1030 | menu_t *ActiveMenu = ActiveMenu; |
958 | |
1031 | |
959 | if (ActiveMenu == NULL) |
1032 | if (ActiveMenu == NULL) |
960 | return; |
1033 | return; |
961 | if (ActiveMenu->win != None) |
1034 | if (ActiveMenu->win != None) |
962 | XDestroyWindow(Xdisplay, ActiveMenu->win); |
1035 | XDestroyWindow (display->display, ActiveMenu->win); |
963 | ActiveMenu->win = None; |
1036 | ActiveMenu->win = None; |
964 | ActiveMenu->item = NULL; |
1037 | ActiveMenu->item = NULL; |
965 | |
1038 | |
966 | if (ActiveMenu->parent == NULL) |
1039 | if (ActiveMenu->parent == NULL) |
967 | drawbox_menubar (ActiveMenu->x, ActiveMenu->len, +1); |
1040 | drawbox_menubar (ActiveMenu->x, ActiveMenu->len, +1); |
968 | ActiveMenu = ActiveMenu->parent; |
1041 | ActiveMenu = ActiveMenu->parent; |
969 | update(r); |
1042 | (this->*update) (); |
970 | } |
1043 | } |
971 | |
1044 | |
972 | void |
1045 | void |
973 | rxvt_term::menu_hide_all () |
1046 | rxvt_term::menu_hide_all () |
974 | { |
1047 | { |
975 | menu_display (rxvt_menu_hide_all); |
1048 | menu_display (&rxvt_term::menu_hide_all); |
976 | } |
1049 | } |
977 | |
1050 | |
978 | void |
1051 | void |
979 | rxvt_term::menu_hide () |
1052 | rxvt_term::menu_hide () |
980 | { |
1053 | { |
981 | menu_display (rxvt_menu_show); |
1054 | menu_display (&rxvt_term::menu_show); |
982 | } |
1055 | } |
983 | |
1056 | |
984 | void |
1057 | void |
985 | rxvt_term::menu_clear (menu_t *menu) |
1058 | rxvt_term::menu_clear (menu_t *menu) |
986 | { |
1059 | { |
987 | if (menu != NULL) { |
1060 | if (menu != NULL) |
|
|
1061 | { |
988 | menuitem_t *item = menu->tail; |
1062 | menuitem_t *item = menu->tail; |
989 | |
1063 | |
990 | while (item != NULL) { |
1064 | while (item != NULL) |
|
|
1065 | { |
991 | menuitem_free (menu, item); |
1066 | menuitem_free (menu, item); |
992 | /* it didn't get freed ... why? */ |
1067 | /* it didn't get freed ... why? */ |
993 | if (item == menu->tail) |
1068 | if (item == menu->tail) |
994 | return; |
1069 | return; |
995 | item = menu->tail; |
1070 | item = menu->tail; |
996 | } |
1071 | } |
997 | menu->width = 0; |
1072 | menu->width = 0; |
998 | } |
1073 | } |
999 | } |
1074 | } |
1000 | |
1075 | |
1001 | void |
1076 | void |
1002 | rxvt_term::menubar_clear () |
1077 | rxvt_term::menubar_clear () |
1003 | { |
1078 | { |
1004 | bar_t *CurrentBar = CurrentBar; |
1079 | bar_t *CurrentBar = CurrentBar; |
1005 | |
1080 | |
1006 | if (CurrentBar != NULL) { |
1081 | if (CurrentBar != NULL) |
|
|
1082 | { |
1007 | menu_t *menu = CurrentBar->tail; |
1083 | menu_t *menu = CurrentBar->tail; |
1008 | |
1084 | |
1009 | while (menu != NULL) { |
1085 | while (menu != NULL) |
|
|
1086 | { |
1010 | menu_t *prev = menu->prev; |
1087 | menu_t *prev = menu->prev; |
1011 | |
1088 | |
1012 | menu_delete (menu); |
1089 | menu_delete (menu); |
1013 | menu = prev; |
1090 | menu = prev; |
1014 | } |
1091 | } |
1015 | CurrentBar->head = CurrentBar->tail = NULL; |
1092 | CurrentBar->head = CurrentBar->tail = NULL; |
1016 | |
1093 | |
1017 | if (CurrentBar->title) { |
1094 | if (CurrentBar->title) |
|
|
1095 | { |
1018 | free(CurrentBar->title); |
1096 | free (CurrentBar->title); |
1019 | CurrentBar->title = NULL; |
1097 | CurrentBar->title = NULL; |
1020 | } |
1098 | } |
1021 | menuarrow_free (0); /* remove all arrow functions */ |
1099 | menuarrow_free (0); /* remove all arrow functions */ |
1022 | } |
1100 | } |
1023 | ActiveMenu = NULL; |
1101 | ActiveMenu = NULL; |
1024 | } |
1102 | } |
1025 | |
1103 | |
1026 | #if (MENUBAR_MAX > 1) |
1104 | #if (MENUBAR_MAX > 1) |
1027 | /* find if menu already exists */ |
1105 | /* find if menu already exists */ |
1028 | bar_t * |
1106 | bar_t * |
1029 | rxvt_term::menubar_find (const char *name) |
1107 | rxvt_term::menubar_find (const char *name) |
1030 | { |
1108 | { |
1031 | bar_t *bar = CurrentBar; |
1109 | bar_t *bar = CurrentBar; |
1032 | |
1110 | |
1033 | #ifdef DEBUG_MENUBAR_STACKING |
1111 | #ifdef DEBUG_MENUBAR_STACKING |
1034 | fprintf(stderr, "looking for [menu:%s] ...", name ? name : "(nil)"); |
1112 | fprintf (stderr, "looking for [menu:%s] ...", name ? name : " (nil)"); |
1035 | #endif |
1113 | #endif |
1036 | if (bar == NULL || name == NULL) |
1114 | if (bar == NULL || name == NULL) |
1037 | return NULL; |
1115 | return NULL; |
1038 | |
1116 | |
1039 | if (STRLEN(name) && STRCMP(name, "*")) { |
1117 | if (STRLEN (name) && STRCMP (name, "*")) |
1040 | do { |
1118 | { |
|
|
1119 | do |
|
|
1120 | { |
1041 | if (!STRCMP(bar->name, name)) { |
1121 | if (!STRCMP (bar->name, name)) |
|
|
1122 | { |
1042 | #ifdef DEBUG_MENUBAR_STACKING |
1123 | #ifdef DEBUG_MENUBAR_STACKING |
1043 | fprintf(stderr, " found!\n"); |
1124 | fprintf (stderr, " found!\n"); |
1044 | #endif |
1125 | #endif |
1045 | return bar; |
1126 | return bar; |
1046 | } |
1127 | } |
1047 | bar = bar->next; |
1128 | bar = bar->next; |
1048 | } |
1129 | } |
1049 | while (bar != CurrentBar); |
1130 | while (bar != CurrentBar); |
1050 | bar = NULL; |
1131 | bar = NULL; |
1051 | } |
1132 | } |
1052 | #ifdef DEBUG_MENUBAR_STACKING |
1133 | #ifdef DEBUG_MENUBAR_STACKING |
1053 | fprintf(stderr, "%s found!\n", (bar ? "" : " NOT")); |
1134 | fprintf (stderr, "%s found!\n", (bar ? "" : " NOT")); |
1054 | #endif |
1135 | #endif |
1055 | |
1136 | |
1056 | return bar; |
1137 | return bar; |
1057 | } |
1138 | } |
1058 | |
1139 | |
1059 | int |
1140 | int |
1060 | rxvt_term::menubar_push (const char *name) |
1141 | rxvt_term::menubar_push (const char *name) |
1061 | { |
1142 | { |
1062 | int ret = 1; |
1143 | int ret = 1; |
1063 | bar_t *bar; |
1144 | bar_t *bar; |
1064 | |
1145 | |
1065 | if (CurrentBar == NULL) { |
1146 | if (CurrentBar == NULL) |
|
|
1147 | { |
1066 | /* allocate first one */ |
1148 | /* allocate first one */ |
1067 | bar = (bar_t *) rxvt_malloc(sizeof(bar_t)); |
1149 | bar = (bar_t *) rxvt_malloc (sizeof (bar_t)); |
1068 | |
1150 | |
1069 | MEMSET(bar, 0, sizeof(bar_t)); |
1151 | MEMSET (bar, 0, sizeof (bar_t)); |
1070 | /* circular linked-list */ |
1152 | /* circular linked-list */ |
1071 | bar->next = bar->prev = bar; |
1153 | bar->next = bar->prev = bar; |
1072 | bar->head = bar->tail = NULL; |
1154 | bar->head = bar->tail = NULL; |
1073 | bar->title = NULL; |
1155 | bar->title = NULL; |
1074 | CurrentBar = bar; |
|
|
1075 | Nbars++; |
|
|
1076 | |
|
|
1077 | menubar_clear (); |
|
|
1078 | } else { |
|
|
1079 | /* find if menu already exists */ |
|
|
1080 | bar = menubar_find (name); |
|
|
1081 | if (bar != NULL) { |
|
|
1082 | /* found it, use it */ |
|
|
1083 | CurrentBar = bar; |
1156 | CurrentBar = bar; |
1084 | } else { |
1157 | Nbars++; |
|
|
1158 | |
|
|
1159 | menubar_clear (); |
|
|
1160 | } |
|
|
1161 | else |
|
|
1162 | { |
|
|
1163 | /* find if menu already exists */ |
|
|
1164 | bar = menubar_find (name); |
|
|
1165 | if (bar != NULL) |
|
|
1166 | { |
|
|
1167 | /* found it, use it */ |
|
|
1168 | CurrentBar = bar; |
|
|
1169 | } |
|
|
1170 | else |
|
|
1171 | { |
1085 | /* create if needed, or reuse the existing empty menubar */ |
1172 | /* create if needed, or reuse the existing empty menubar */ |
1086 | if (CurrentBar->head != NULL) { |
1173 | if (CurrentBar->head != NULL) |
|
|
1174 | { |
1087 | /* need to malloc another one */ |
1175 | /* need to malloc another one */ |
1088 | if (Nbars < MENUBAR_MAX) |
1176 | if (Nbars < MENUBAR_MAX) |
1089 | bar = (bar_t *) rxvt_malloc(sizeof(bar_t)); |
1177 | bar = (bar_t *) rxvt_malloc (sizeof (bar_t)); |
1090 | else |
1178 | else |
1091 | bar = NULL; |
1179 | bar = NULL; |
1092 | |
1180 | |
1093 | /* malloc failed or too many menubars, reuse another */ |
1181 | /* malloc failed or too many menubars, reuse another */ |
1094 | if (bar == NULL) { |
1182 | if (bar == NULL) |
|
|
1183 | { |
1095 | bar = CurrentBar->next; |
1184 | bar = CurrentBar->next; |
1096 | ret = -1; |
1185 | ret = -1; |
1097 | } else { |
1186 | } |
|
|
1187 | else |
|
|
1188 | { |
1098 | bar->head = bar->tail = NULL; |
1189 | bar->head = bar->tail = NULL; |
1099 | bar->title = NULL; |
1190 | bar->title = NULL; |
1100 | |
1191 | |
1101 | bar->next = CurrentBar->next; |
1192 | bar->next = CurrentBar->next; |
1102 | CurrentBar->next = bar; |
1193 | CurrentBar->next = bar; |
1103 | bar->prev = CurrentBar; |
1194 | bar->prev = CurrentBar; |
1104 | bar->next->prev = bar; |
1195 | bar->next->prev = bar; |
1105 | |
1196 | |
1106 | Nbars++; |
1197 | Nbars++; |
1107 | } |
1198 | } |
1108 | CurrentBar = bar; |
1199 | CurrentBar = bar; |
1109 | |
1200 | |
|
|
1201 | } |
|
|
1202 | menubar_clear (); |
|
|
1203 | } |
1110 | } |
1204 | } |
1111 | menubar_clear (); |
|
|
1112 | } |
|
|
1113 | } |
|
|
1114 | |
1205 | |
1115 | /* give menubar this name */ |
1206 | /* give menubar this name */ |
1116 | STRNCPY(CurrentBar->name, name, MAXNAME); |
1207 | STRNCPY (CurrentBar->name, name, MAXNAME); |
1117 | CurrentBar->name[MAXNAME - 1] = '\0'; |
1208 | CurrentBar->name[MAXNAME - 1] = '\0'; |
1118 | |
1209 | |
1119 | return ret; |
1210 | return ret; |
1120 | } |
1211 | } |
1121 | |
1212 | |
1122 | /* switch to a menu called NAME and remove it */ |
1213 | /* switch to a menu called NAME and remove it */ |
1123 | void |
1214 | void |
1124 | rxvt_term::menubar_remove (const char *name) |
1215 | rxvt_term::menubar_remove (const char *name) |
1125 | { |
1216 | { |
1126 | bar_t *bar; |
1217 | bar_t *bar; |
1127 | |
1218 | |
1128 | if ((bar = menubar_find (name)) == NULL) |
1219 | if ((bar = menubar_find (name)) == NULL) |
1129 | return; |
1220 | return; |
1130 | CurrentBar = bar; |
1221 | CurrentBar = bar; |
1131 | |
1222 | |
|
|
1223 | do |
1132 | do { |
1224 | { |
1133 | menubar_clear (); |
1225 | menubar_clear (); |
1134 | /* |
1226 | /* |
1135 | * pop a menubar, clean it up first |
1227 | * pop a menubar, clean it up first |
1136 | */ |
1228 | */ |
1137 | if (CurrentBar != NULL) { |
1229 | if (CurrentBar != NULL) |
|
|
1230 | { |
1138 | bar_t *prev = CurrentBar->prev; |
1231 | bar_t *prev = CurrentBar->prev; |
1139 | bar_t *next = CurrentBar->next; |
1232 | bar_t *next = CurrentBar->next; |
1140 | |
1233 | |
1141 | if (prev == next && prev == CurrentBar) { /* only 1 left */ |
1234 | if (prev == next && prev == CurrentBar) |
1142 | prev = NULL; |
1235 | { /* only 1 left */ |
1143 | Nbars = 0; /* safety */ |
1236 | prev = NULL; |
1144 | } else { |
1237 | Nbars = 0; /* safety */ |
1145 | next->prev = prev; |
1238 | } |
1146 | prev->next = next; |
1239 | else |
1147 | Nbars--; |
1240 | { |
|
|
1241 | next->prev = prev; |
|
|
1242 | prev->next = next; |
|
|
1243 | Nbars--; |
|
|
1244 | } |
|
|
1245 | |
|
|
1246 | free (CurrentBar); |
|
|
1247 | CurrentBar = prev; |
|
|
1248 | } |
1148 | } |
1249 | } |
1149 | |
|
|
1150 | free(CurrentBar); |
|
|
1151 | CurrentBar = prev; |
|
|
1152 | } |
|
|
1153 | } |
|
|
1154 | while (CurrentBar && !STRCMP(name, "*")); |
1250 | while (CurrentBar && !STRCMP (name, "*")); |
1155 | } |
1251 | } |
1156 | |
1252 | |
1157 | void |
1253 | void |
1158 | rxvt_action_decode(FILE *fp, action_t *act) |
1254 | rxvt_action_decode (FILE *fp, action_t *act) |
1159 | { |
1255 | { |
1160 | unsigned char *str; |
1256 | unsigned char *str; |
1161 | short len; |
1257 | short len; |
1162 | |
1258 | |
1163 | if (act == NULL || (len = act->len) == 0 || (str = act->str) == NULL) |
1259 | if (act == NULL || (len = act->len) == 0 || (str = act->str) == NULL) |
1164 | return; |
1260 | return; |
1165 | |
1261 | |
1166 | if (act->type == MenuTerminalAction) { |
1262 | if (act->type == MenuTerminalAction) |
|
|
1263 | { |
1167 | fprintf(fp, "^@"); |
1264 | fprintf (fp, "^@"); |
1168 | /* can strip trailing ^G from XTerm sequence */ |
1265 | /* can strip trailing ^G from XTerm sequence */ |
1169 | if (str[0] == C0_ESC && str[1] == ']' && str[len - 1] == C0_BEL) |
1266 | if (str[0] == C0_ESC && str[1] == ']' && str[len - 1] == C0_BEL) |
1170 | len--; |
1267 | len--; |
|
|
1268 | } |
1171 | } else if (str[0] == C0_ESC) { |
1269 | else if (str[0] == C0_ESC) |
|
|
1270 | { |
1172 | switch (str[1]) { |
1271 | switch (str[1]) |
1173 | case '[': |
1272 | { |
1174 | case ']': |
1273 | case '[': |
1175 | break; |
1274 | case ']': |
|
|
1275 | break; |
1176 | |
1276 | |
1177 | case 'x': |
1277 | case 'x': |
1178 | /* can strip trailing '\r' from M-x sequence */ |
1278 | /* can strip trailing '\r' from M-x sequence */ |
1179 | if (str[len - 1] == '\r') |
1279 | if (str[len - 1] == '\r') |
1180 | len--; |
1280 | len--; |
1181 | /* FALLTHROUGH */ |
1281 | /* FALLTHROUGH */ |
1182 | |
1282 | |
1183 | default: |
1283 | default: |
1184 | fprintf(fp, "M-"); /* meta prefix */ |
1284 | fprintf (fp, "M-"); /* meta prefix */ |
1185 | str++; |
1285 | str++; |
1186 | len--; |
1286 | len--; |
1187 | break; |
1287 | break; |
1188 | } |
1288 | } |
1189 | } |
1289 | } |
1190 | /* |
1290 | /* |
1191 | * control character form is preferred, since backslash-escaping |
1291 | * control character form is preferred, since backslash-escaping |
1192 | * can be really ugly looking when the backslashes themselves also |
1292 | * can be really ugly looking when the backslashes themselves also |
1193 | * have to be escaped to avoid Shell (or whatever scripting |
1293 | * have to be escaped to avoid Shell (or whatever scripting |
1194 | * language) interpretation |
1294 | * language) interpretation |
1195 | */ |
1295 | */ |
1196 | while (len > 0) { |
1296 | while (len > 0) |
|
|
1297 | { |
1197 | unsigned char ch = *str++; |
1298 | unsigned char ch = *str++; |
1198 | |
1299 | |
1199 | switch (ch) { |
1300 | switch (ch) |
1200 | case C0_ESC: |
1301 | { |
|
|
1302 | case C0_ESC: |
1201 | fprintf(fp, "\\E"); |
1303 | fprintf (fp, "\\E"); |
1202 | break; /* escape */ |
1304 | break; /* escape */ |
1203 | case '\r': |
1305 | case '\r': |
1204 | fprintf(fp, "\\r"); |
1306 | fprintf (fp, "\\r"); |
1205 | break; /* carriage-return */ |
1307 | break; /* carriage-return */ |
1206 | case '\\': |
1308 | case '\\': |
1207 | fprintf(fp, "\\\\"); |
1309 | fprintf (fp, "\\\\"); |
1208 | break; /* backslash */ |
1310 | break; /* backslash */ |
1209 | case '^': |
1311 | case '^': |
1210 | fprintf(fp, "\\^"); |
1312 | fprintf (fp, "\\^"); |
1211 | break; /* caret */ |
1313 | break; /* caret */ |
1212 | case 127: |
1314 | case 127: |
1213 | fprintf(fp, "^?"); |
1315 | fprintf (fp, "^?"); |
1214 | default: |
1316 | default: |
1215 | if (ch <= 31) |
1317 | if (ch <= 31) |
1216 | fprintf(fp, "^%c", ('@' + ch)); |
1318 | fprintf (fp, "^%c", ('@' + ch)); |
1217 | else if (ch > 127) |
1319 | else if (ch > 127) |
1218 | fprintf(fp, "\\%o", ch); |
1320 | fprintf (fp, "\\%o", ch); |
1219 | else |
1321 | else |
1220 | fprintf(fp, "%c", ch); |
1322 | fprintf (fp, "%c", ch); |
1221 | break; |
1323 | break; |
1222 | } |
1324 | } |
1223 | len--; |
1325 | len--; |
1224 | } |
1326 | } |
1225 | fprintf(fp, "\n"); |
1327 | fprintf (fp, "\n"); |
1226 | } |
1328 | } |
1227 | |
1329 | |
1228 | void |
1330 | void |
1229 | rxvt_menu_dump(FILE *fp, menu_t *menu) |
1331 | rxvt_menu_dump (FILE *fp, menu_t *menu) |
1230 | { |
1332 | { |
1231 | menuitem_t *item; |
1333 | menuitem_t *item; |
1232 | |
1334 | |
1233 | /* create a new menu and clear it */ |
1335 | /* create a new menu and clear it */ |
1234 | fprintf(fp, (menu->parent ? "./%s/*\n" : "/%s/*\n"), menu->name); |
1336 | fprintf (fp, (menu->parent ? "./%s/*\n" : "/%s/*\n"), menu->name); |
1235 | |
1337 | |
1236 | for (item = menu->head; item != NULL; item = item->next) { |
1338 | for (item = menu->head; item != NULL; item = item->next) |
|
|
1339 | { |
1237 | switch (item->entry.type) { |
1340 | switch (item->entry.type) |
|
|
1341 | { |
1238 | case MenuSubMenu: |
1342 | case MenuSubMenu: |
1239 | if (item->entry.submenu.menu == NULL) |
1343 | if (item->entry.submenu.menu == NULL) |
1240 | fprintf(fp, "> %s == NULL\n", item->name); |
1344 | fprintf (fp, "> %s == NULL\n", item->name); |
1241 | else |
1345 | else |
1242 | rxvt_menu_dump(fp, item->entry.submenu.menu); |
1346 | rxvt_menu_dump (fp, item->entry.submenu.menu); |
1243 | break; |
1347 | break; |
1244 | |
1348 | |
1245 | case MenuLabel: |
1349 | case MenuLabel: |
1246 | fprintf(fp, "{%s}\n", (STRLEN(item->name) ? item->name : "-")); |
1350 | fprintf (fp, "{%s}\n", (STRLEN (item->name) ? item->name : "-")); |
1247 | break; |
1351 | break; |
1248 | |
1352 | |
1249 | case MenuTerminalAction: |
1353 | case MenuTerminalAction: |
1250 | case MenuAction: |
1354 | case MenuAction: |
1251 | fprintf(fp, "{%s}", item->name); |
1355 | fprintf (fp, "{%s}", item->name); |
1252 | if (item->name2 != NULL && STRLEN(item->name2)) |
1356 | if (item->name2 != NULL && STRLEN (item->name2)) |
1253 | fprintf(fp, "{%s}", item->name2); |
1357 | fprintf (fp, "{%s}", item->name2); |
1254 | fprintf(fp, "\t"); |
1358 | fprintf (fp, "\t"); |
1255 | rxvt_action_decode(fp, &(item->entry.action)); |
1359 | rxvt_action_decode (fp, & (item->entry.action)); |
1256 | break; |
1360 | break; |
1257 | } |
1361 | } |
1258 | } |
1362 | } |
1259 | |
1363 | |
1260 | fprintf(fp, (menu->parent ? "../\n" : "/\n\n")); |
1364 | fprintf (fp, (menu->parent ? "../\n" : "/\n\n")); |
1261 | } |
1365 | } |
1262 | |
1366 | |
1263 | void |
1367 | void |
1264 | rxvt_term::menubar_dump (FILE *fp) |
1368 | rxvt_term::menubar_dump (FILE *fp) |
1265 | { |
1369 | { |
1266 | bar_t *bar = CurrentBar; |
1370 | bar_t *bar = CurrentBar; |
1267 | time_t t; |
1371 | time_t t; |
1268 | |
1372 | |
1269 | if (bar == NULL || fp == NULL) |
1373 | if (bar == NULL || fp == NULL) |
1270 | return; |
1374 | return; |
1271 | time(&t); |
1375 | time (&t); |
1272 | |
1376 | |
1273 | fprintf(fp, |
1377 | fprintf (fp, |
1274 | "# " APL_SUBCLASS " (%s) Pid: %u\n# Date: %s\n\n", |
1378 | "# " APL_SUBCLASS " (%s) Pid: %u\n# Date: %s\n\n", |
1275 | rs[Rs_name], (unsigned int)getpid(), ctime(&t)); |
1379 | rs[Rs_name], (unsigned int)getpid (), ctime (&t)); |
1276 | |
1380 | |
1277 | /* dump in reverse order */ |
1381 | /* dump in reverse order */ |
1278 | bar = CurrentBar->prev; |
1382 | bar = CurrentBar->prev; |
|
|
1383 | do |
1279 | do { |
1384 | { |
1280 | menu_t *menu; |
1385 | menu_t *menu; |
1281 | int i; |
1386 | int i; |
1282 | |
1387 | |
1283 | fprintf(fp, "[menu:%s]\n", bar->name); |
1388 | fprintf (fp, "[menu:%s]\n", bar->name); |
1284 | |
1389 | |
1285 | if (bar->title != NULL) |
1390 | if (bar->title != NULL) |
1286 | fprintf(fp, "[title:%s]\n", bar->title); |
1391 | fprintf (fp, "[title:%s]\n", bar->title); |
1287 | |
1392 | |
1288 | for (i = 0; i < NARROWS; i++) { |
1393 | for (i = 0; i < NARROWS; i++) |
|
|
1394 | { |
1289 | switch (bar->arrows[i].type) { |
1395 | switch (bar->arrows[i].type) |
|
|
1396 | { |
1290 | case MenuTerminalAction: |
1397 | case MenuTerminalAction: |
1291 | case MenuAction: |
1398 | case MenuAction: |
1292 | fprintf(fp, "<%c>", Arrows[i].name); |
1399 | fprintf (fp, "<%c>", Arrows[i].name); |
1293 | rxvt_action_decode(fp, &(bar->arrows[i])); |
1400 | rxvt_action_decode (fp, & (bar->arrows[i])); |
1294 | break; |
1401 | break; |
1295 | } |
1402 | } |
1296 | } |
1403 | } |
1297 | fprintf(fp, "\n"); |
1404 | fprintf (fp, "\n"); |
1298 | |
1405 | |
1299 | for (menu = bar->head; menu != NULL; menu = menu->next) |
1406 | for (menu = bar->head; menu != NULL; menu = menu->next) |
1300 | rxvt_menu_dump(fp, menu); |
1407 | rxvt_menu_dump (fp, menu); |
1301 | |
1408 | |
1302 | fprintf(fp, "\n[done:%s]\n\n", bar->name); |
1409 | fprintf (fp, "\n[done:%s]\n\n", bar->name); |
1303 | bar = bar->prev; |
1410 | bar = bar->prev; |
1304 | } |
1411 | } |
1305 | while (bar != CurrentBar->prev); |
1412 | while (bar != CurrentBar->prev); |
1306 | } |
1413 | } |
1307 | #endif /* (MENUBAR_MAX > 1) */ |
1414 | #endif /* (MENUBAR_MAX > 1) */ |
1308 | |
1415 | |
1309 | /* |
1416 | /* |
1310 | * read in menubar commands from FILENAME |
1417 | * read in menubar commands from FILENAME |
… | |
… | |
1322 | * read `file' starting with [menu:tag] |
1429 | * read `file' starting with [menu:tag] |
1323 | */ |
1430 | */ |
1324 | void |
1431 | void |
1325 | rxvt_term::menubar_read (const char *filename) |
1432 | rxvt_term::menubar_read (const char *filename) |
1326 | { |
1433 | { |
1327 | /* read in a menu from a file */ |
1434 | /* read in a menu from a file */ |
1328 | FILE *fp; |
1435 | FILE *fp; |
1329 | char buffer[256]; |
1436 | char buffer[256]; |
1330 | char *p, *file, *tag = NULL; |
1437 | char *p, *file, *tag = NULL; |
1331 | |
1438 | |
1332 | file = (char *)rxvt_File_find(filename, ".menu", rs[Rs_path]); |
1439 | file = (char *)rxvt_File_find (filename, ".menu", rs[Rs_path]); |
1333 | if (file == NULL) |
1440 | if (file == NULL) |
1334 | return; |
1441 | return; |
1335 | fp = fopen(file, "rb"); |
1442 | fp = fopen (file, "rb"); |
1336 | free(file); |
1443 | free (file); |
1337 | if (fp == NULL) |
1444 | if (fp == NULL) |
1338 | return; |
1445 | return; |
1339 | |
1446 | |
1340 | #if (MENUBAR_MAX > 1) |
1447 | #if (MENUBAR_MAX > 1) |
1341 | /* semi-colon delimited */ |
1448 | /* semi-colon delimited */ |
1342 | if ((tag = STRCHR(filename, ';')) != NULL) { |
1449 | if ((tag = STRCHR (filename, ';')) != NULL) |
1343 | tag++; |
1450 | { |
|
|
1451 | tag++; |
1344 | if (*tag == '\0') |
1452 | if (*tag == '\0') |
1345 | tag = NULL; |
1453 | tag = NULL; |
1346 | } |
1454 | } |
1347 | #endif /* (MENUBAR_MAX > 1) */ |
1455 | #endif /* (MENUBAR_MAX > 1) */ |
1348 | #ifdef DEBUG_MENU |
1456 | #ifdef DEBUG_MENU |
1349 | fprintf(stderr, "[read:%s]\n", p); |
1457 | fprintf (stderr, "[read:%s]\n", p); |
1350 | if (tag) |
1458 | if (tag) |
1351 | fprintf(stderr, "looking for [menu:%s]\n", tag); |
1459 | fprintf (stderr, "looking for [menu:%s]\n", tag); |
1352 | #endif |
1460 | #endif |
1353 | |
1461 | |
1354 | while ((p = fgets(buffer, sizeof(buffer), fp)) != NULL) { |
1462 | while ((p = fgets (buffer, sizeof (buffer), fp)) != NULL) |
|
|
1463 | { |
1355 | int n; |
1464 | int n; |
1356 | |
1465 | |
1357 | if ((n = rxvt_Str_match(p, "[menu")) != 0) { |
1466 | if ((n = rxvt_Str_match (p, "[menu")) != 0) |
1358 | if (tag) { |
1467 | { |
|
|
1468 | if (tag) |
|
|
1469 | { |
1359 | /* looking for [menu:tag] */ |
1470 | /* looking for [menu:tag] */ |
1360 | if (p[n] == ':' && p[n + 1] != ']') { |
1471 | if (p[n] == ':' && p[n + 1] != ']') |
1361 | n++; |
1472 | { |
|
|
1473 | n++; |
1362 | n += rxvt_Str_match(p + n, tag); |
1474 | n += rxvt_Str_match (p + n, tag); |
1363 | if (p[n] == ']') { |
1475 | if (p[n] == ']') |
|
|
1476 | { |
1364 | #ifdef DEBUG_MENU |
1477 | #ifdef DEBUG_MENU |
1365 | fprintf(stderr, "[menu:%s]\n", tag); |
1478 | fprintf (stderr, "[menu:%s]\n", tag); |
1366 | #endif |
1479 | #endif |
1367 | break; |
1480 | break; |
|
|
1481 | } |
|
|
1482 | } |
|
|
1483 | } |
|
|
1484 | else if (p[n] == ':' || p[n] == ']') |
|
|
1485 | break; |
|
|
1486 | } |
1368 | } |
1487 | } |
1369 | } |
|
|
1370 | } else if (p[n] == ':' || p[n] == ']') |
|
|
1371 | break; |
|
|
1372 | } |
|
|
1373 | } |
|
|
1374 | |
1488 | |
1375 | /* found [menu], [menu:???] tag */ |
1489 | /* found [menu], [menu:???] tag */ |
1376 | while (p != NULL) { |
1490 | while (p != NULL) |
|
|
1491 | { |
1377 | int n; |
1492 | int n; |
1378 | |
1493 | |
1379 | #ifdef DEBUG_MENU |
1494 | #ifdef DEBUG_MENU |
1380 | fprintf(stderr, "read line = %s\n", p); |
1495 | fprintf (stderr, "read line = %s\n", p); |
1381 | #endif |
1496 | #endif |
1382 | |
1497 | |
1383 | /* looking for [done:tag] or [done:] */ |
1498 | /* looking for [done:tag] or [done:] */ |
1384 | if ((n = rxvt_Str_match(p, "[done")) != 0) { |
1499 | if ((n = rxvt_Str_match (p, "[done")) != 0) |
|
|
1500 | { |
1385 | if (p[n] == ']') { |
1501 | if (p[n] == ']') |
1386 | menu_readonly = 1; |
1502 | { |
1387 | break; |
|
|
1388 | } else if (p[n] == ':') { |
|
|
1389 | n++; |
|
|
1390 | if (p[n] == ']') { |
|
|
1391 | menu_readonly = 1; |
1503 | menu_readonly = 1; |
1392 | break; |
1504 | break; |
1393 | } else if (tag) { |
1505 | } |
|
|
1506 | else if (p[n] == ':') |
|
|
1507 | { |
|
|
1508 | n++; |
|
|
1509 | if (p[n] == ']') |
|
|
1510 | { |
|
|
1511 | menu_readonly = 1; |
|
|
1512 | break; |
|
|
1513 | } |
|
|
1514 | else if (tag) |
|
|
1515 | { |
1394 | n += rxvt_Str_match(p + n, tag); |
1516 | n += rxvt_Str_match (p + n, tag); |
1395 | if (p[n] == ']') { |
1517 | if (p[n] == ']') |
|
|
1518 | { |
1396 | #ifdef DEBUG_MENU |
1519 | #ifdef DEBUG_MENU |
1397 | fprintf(stderr, "[done:%s]\n", tag); |
1520 | fprintf (stderr, "[done:%s]\n", tag); |
1398 | #endif |
1521 | #endif |
1399 | menu_readonly = 1; |
1522 | menu_readonly = 1; |
1400 | break; |
1523 | break; |
1401 | } |
1524 | } |
1402 | } else { |
1525 | } |
|
|
1526 | else |
|
|
1527 | { |
1403 | /* what? ... skip this line */ |
1528 | /* what? ... skip this line */ |
1404 | p[0] = COMMENT_CHAR; |
1529 | p[0] = COMMENT_CHAR; |
1405 | } |
1530 | } |
1406 | } |
1531 | } |
1407 | } |
1532 | } |
1408 | /* |
1533 | /* |
1409 | * remove leading/trailing space |
1534 | * remove leading/trailing space |
1410 | * and strip-off leading/trailing quotes |
1535 | * and strip-off leading/trailing quotes |
1411 | * skip blank or comment lines |
1536 | * skip blank or comment lines |
1412 | */ |
1537 | */ |
1413 | rxvt_Str_trim(p); |
1538 | rxvt_Str_trim (p); |
1414 | if (*p && *p != '#') { |
1539 | if (*p && *p != '#') |
|
|
1540 | { |
1415 | menu_readonly = 0; /* if case we read another file */ |
1541 | menu_readonly = 0; /* if case we read another file */ |
1416 | menubar_dispatch (p); |
1542 | menubar_dispatch (p); |
1417 | } |
1543 | } |
1418 | /* get another line */ |
1544 | /* get another line */ |
1419 | p = fgets(buffer, sizeof(buffer), fp); |
1545 | p = fgets (buffer, sizeof (buffer), fp); |
1420 | } |
1546 | } |
1421 | |
1547 | |
1422 | fclose(fp); |
1548 | fclose (fp); |
1423 | } |
1549 | } |
1424 | |
1550 | |
1425 | /* |
1551 | /* |
1426 | * user interface for building/deleting and otherwise managing menus |
1552 | * user interface for building/deleting and otherwise managing menus |
1427 | */ |
1553 | */ |
1428 | void |
1554 | void |
1429 | rxvt_term::menubar_dispatch (char *str) |
1555 | rxvt_term::menubar_dispatch (char *str) |
1430 | { |
1556 | { |
1431 | int n, cmd; |
1557 | int n, cmd; |
1432 | char *path, *name, *name2; |
1558 | char *path, *name, *name2; |
1433 | |
1559 | |
1434 | if (menubar_visible(r) && ActiveMenu != NULL) |
1560 | if (menubar_visible () && ActiveMenu != NULL) |
1435 | menubar_expose (); |
1561 | menubar_expose (); |
1436 | else |
1562 | else |
1437 | ActiveMenu = NULL; |
1563 | ActiveMenu = NULL; |
1438 | |
1564 | |
1439 | cmd = *str; |
1565 | cmd = *str; |
1440 | switch (cmd) { |
1566 | switch (cmd) |
|
|
1567 | { |
1441 | case '.': |
1568 | case '.': |
1442 | case '/': /* absolute & relative path */ |
1569 | case '/': /* absolute & relative path */ |
1443 | case MENUITEM_BEG: /* menuitem */ |
1570 | case MENUITEM_BEG: /* menuitem */ |
1444 | /* add `+' prefix for these cases */ |
1571 | /* add `+' prefix for these cases */ |
1445 | cmd = '+'; |
1572 | cmd = '+'; |
1446 | break; |
1573 | break; |
1447 | |
1574 | |
1448 | case '+': |
1575 | case '+': |
1449 | case '-': |
1576 | case '-': |
1450 | str++; /* skip cmd character */ |
1577 | str++; /* skip cmd character */ |
1451 | break; |
1578 | break; |
1452 | |
1579 | |
1453 | case '<': |
1580 | case '<': |
1454 | #if (MENUBAR_MAX > 1) |
1581 | #if (MENUBAR_MAX > 1) |
1455 | if (CurrentBar == NULL) |
1582 | if (CurrentBar == NULL) |
1456 | break; |
1583 | break; |
1457 | #endif /* (MENUBAR_MAX > 1) */ |
1584 | #endif /* (MENUBAR_MAX > 1) */ |
1458 | if (str[1] && str[2] == '>') /* arrow commands */ |
1585 | if (str[1] && str[2] == '>') /* arrow commands */ |
1459 | menuarrow_add (str); |
1586 | menuarrow_add (str); |
1460 | break; |
1587 | break; |
1461 | |
1588 | |
1462 | case '[': /* extended command */ |
1589 | case '[': /* extended command */ |
1463 | while (str[0] == '[') { |
1590 | while (str[0] == '[') |
|
|
1591 | { |
1464 | char *next = (++str); /* skip leading '[' */ |
1592 | char *next = (++str); /* skip leading '[' */ |
1465 | |
1593 | |
1466 | if (str[0] == ':') { /* [:command:] */ |
1594 | if (str[0] == ':') |
1467 | do { |
1595 | { /* [:command:] */ |
1468 | next++; |
1596 | do |
|
|
1597 | { |
|
|
1598 | next++; |
|
|
1599 | if ((next = STRCHR (next, ':')) == NULL) |
|
|
1600 | return; /* parse error */ |
|
|
1601 | } |
|
|
1602 | while (next[1] != ']'); |
|
|
1603 | /* remove and skip ':]' */ |
|
|
1604 | *next = '\0'; |
|
|
1605 | next += 2; |
|
|
1606 | } |
|
|
1607 | else |
|
|
1608 | { |
1469 | if ((next = STRCHR(next, ':')) == NULL) |
1609 | if ((next = STRCHR (next, ']')) == NULL) |
1470 | return; /* parse error */ |
|
|
1471 | } |
|
|
1472 | while (next[1] != ']'); |
|
|
1473 | /* remove and skip ':]' */ |
|
|
1474 | *next = '\0'; |
|
|
1475 | next += 2; |
|
|
1476 | } else { |
|
|
1477 | if ((next = STRCHR(next, ']')) == NULL) |
|
|
1478 | return; /* parse error */ |
1610 | return; /* parse error */ |
1479 | /* remove and skip ']' */ |
1611 | /* remove and skip ']' */ |
1480 | *next = '\0'; |
1612 | *next = '\0'; |
1481 | next++; |
1613 | next++; |
1482 | } |
1614 | } |
1483 | |
1615 | |
1484 | if (str[0] == ':') { |
1616 | if (str[0] == ':') |
1485 | int saved; |
1617 | { |
|
|
1618 | int saved; |
1486 | |
1619 | |
1487 | /* try and dispatch it, regardless of read/write status */ |
1620 | /* try and dispatch it, regardless of read/write status */ |
1488 | saved = menu_readonly; |
1621 | saved = menu_readonly; |
1489 | menu_readonly = 0; |
1622 | menu_readonly = 0; |
1490 | menubar_dispatch (str + 1); |
1623 | menubar_dispatch (str + 1); |
1491 | menu_readonly = saved; |
1624 | menu_readonly = saved; |
1492 | } |
1625 | } |
1493 | /* these ones don't require menu stacking */ |
1626 | /* these ones don't require menu stacking */ |
1494 | else if (!STRCMP(str, "clear")) { |
1627 | else if (!STRCMP (str, "clear")) |
1495 | menubar_clear (); |
1628 | { |
|
|
1629 | menubar_clear (); |
|
|
1630 | } |
1496 | } else if (!STRCMP(str, "done") || rxvt_Str_match(str, "done:")) { |
1631 | else if (!STRCMP (str, "done") || rxvt_Str_match (str, "done:")) |
1497 | menu_readonly = 1; |
1632 | { |
|
|
1633 | menu_readonly = 1; |
|
|
1634 | } |
1498 | } else if (!STRCMP(str, "show")) { |
1635 | else if (!STRCMP (str, "show")) |
1499 | map_menuBar (1); |
1636 | { |
1500 | menu_readonly = 1; |
1637 | map_menuBar (1); |
|
|
1638 | menu_readonly = 1; |
|
|
1639 | } |
1501 | } else if (!STRCMP(str, "hide")) { |
1640 | else if (!STRCMP (str, "hide")) |
1502 | map_menuBar (0); |
1641 | { |
1503 | menu_readonly = 1; |
1642 | map_menuBar (0); |
|
|
1643 | menu_readonly = 1; |
|
|
1644 | } |
1504 | } else if ((n = rxvt_Str_match(str, "read:")) != 0) { |
1645 | else if ((n = rxvt_Str_match (str, "read:")) != 0) |
|
|
1646 | { |
1505 | /* read in a menu from a file */ |
1647 | /* read in a menu from a file */ |
1506 | str += n; |
1648 | str += n; |
1507 | menubar_read (str); |
1649 | menubar_read (str); |
|
|
1650 | } |
1508 | } else if ((n = rxvt_Str_match(str, "title:")) != 0) { |
1651 | else if ((n = rxvt_Str_match (str, "title:")) != 0) |
1509 | str += n; |
1652 | { |
|
|
1653 | str += n; |
1510 | if (CurrentBar != NULL && !menu_readonly) { |
1654 | if (CurrentBar != NULL && !menu_readonly) |
1511 | if (*str) { |
1655 | { |
1512 | name = rxvt_realloc(CurrentBar->title, |
1656 | if (*str) |
1513 | STRLEN(str) + 1); |
1657 | { |
1514 | if (name != NULL) { |
1658 | name = (char *)rxvt_realloc (CurrentBar->title, STRLEN (str) + 1); |
1515 | STRCPY(name, str); |
1659 | if (name != NULL) |
1516 | CurrentBar->title = name; |
1660 | { |
1517 | } |
1661 | STRCPY (name, str); |
1518 | menubar_expose (); |
1662 | CurrentBar->title = name; |
1519 | } else { |
1663 | } |
1520 | free(CurrentBar->title); |
1664 | menubar_expose (); |
1521 | CurrentBar->title = NULL; |
1665 | } |
1522 | } |
1666 | else |
1523 | } |
1667 | { |
|
|
1668 | free (CurrentBar->title); |
|
|
1669 | CurrentBar->title = NULL; |
|
|
1670 | } |
|
|
1671 | } |
|
|
1672 | } |
1524 | } else if ((n = rxvt_Str_match(str, "pixmap:")) != 0) { |
1673 | else if ((n = rxvt_Str_match (str, "pixmap:")) != 0) |
1525 | str += n; |
1674 | { |
|
|
1675 | str += n; |
1526 | xterm_seq (XTerm_Pixmap, str, CHAR_ST); |
1676 | xterm_seq (XTerm_Pixmap, str, CHAR_ST); |
1527 | } |
1677 | } |
1528 | #if (MENUBAR_MAX > 1) |
1678 | #if (MENUBAR_MAX > 1) |
1529 | else if ((n = rxvt_Str_match(str, "rm")) != 0) { |
1679 | else if ((n = rxvt_Str_match (str, "rm")) != 0) |
1530 | str += n; |
1680 | { |
1531 | switch (str[0]) { |
1681 | str += n; |
1532 | case ':': |
1682 | switch (str[0]) |
1533 | str++; |
1683 | { |
1534 | /* FALLTHROUGH */ |
1684 | case ':': |
1535 | case '\0': |
1685 | str++; |
1536 | /* FALLTHROUGH */ |
1686 | /* FALLTHROUGH */ |
1537 | case '*': |
1687 | case '\0': |
1538 | menubar_remove (str); |
1688 | /* FALLTHROUGH */ |
1539 | break; |
1689 | case '*': |
1540 | } |
1690 | menubar_remove (str); |
1541 | menu_readonly = 1; |
1691 | break; |
|
|
1692 | } |
|
|
1693 | menu_readonly = 1; |
|
|
1694 | } |
1542 | } else if ((n = rxvt_Str_match(str, "menu")) != 0) { |
1695 | else if ((n = rxvt_Str_match (str, "menu")) != 0) |
1543 | str += n; |
1696 | { |
1544 | switch (str[0]) { |
1697 | str += n; |
1545 | case ':': |
1698 | switch (str[0]) |
1546 | str++; |
1699 | { |
1547 | /* add/access menuBar */ |
1700 | case ':': |
|
|
1701 | str++; |
|
|
1702 | /* add/access menuBar */ |
1548 | if (*str != '\0' && *str != '*') |
1703 | if (*str != '\0' && *str != '*') |
1549 | menubar_push (str); |
1704 | menubar_push (str); |
1550 | break; |
1705 | break; |
1551 | default: |
1706 | default: |
1552 | if (CurrentBar == NULL) { |
1707 | if (CurrentBar == NULL) |
1553 | menubar_push ("default"); |
1708 | { |
1554 | } |
1709 | menubar_push ("default"); |
1555 | } |
1710 | } |
|
|
1711 | } |
1556 | |
1712 | |
1557 | if (CurrentBar != NULL) |
1713 | if (CurrentBar != NULL) |
1558 | menu_readonly = 0; /* allow menu build commands */ |
1714 | menu_readonly = 0; /* allow menu build commands */ |
|
|
1715 | } |
1559 | } else if (!STRCMP(str, "dump")) { |
1716 | else if (!STRCMP (str, "dump")) |
|
|
1717 | { |
1560 | /* dump current menubars to a file */ |
1718 | /* dump current menubars to a file */ |
1561 | FILE *fp; |
1719 | FILE *fp; |
1562 | |
1720 | |
1563 | /* enough space to hold the results */ |
1721 | /* enough space to hold the results */ |
1564 | char buffer[32]; |
1722 | char buffer[32]; |
1565 | |
1723 | |
1566 | sprintf(buffer, "/tmp/" APL_SUBCLASS "-%u", |
1724 | sprintf (buffer, "/tmp/" APL_SUBCLASS "-%u", |
1567 | (unsigned int)getpid()); |
1725 | (unsigned int)getpid ()); |
1568 | |
1726 | |
1569 | if ((fp = fopen(buffer, "wb")) != NULL) { |
1727 | if ((fp = fopen (buffer, "wb")) != NULL) |
|
|
1728 | { |
1570 | xterm_seq (XTerm_title, buffer, CHAR_ST); |
1729 | xterm_seq (XTerm_title, buffer, CHAR_ST); |
1571 | menubar_dump (fp); |
1730 | menubar_dump (fp); |
1572 | fclose(fp); |
1731 | fclose (fp); |
1573 | } |
1732 | } |
|
|
1733 | } |
1574 | } else if (!STRCMP(str, "next")) { |
1734 | else if (!STRCMP (str, "next")) |
1575 | if (CurrentBar) { |
1735 | { |
|
|
1736 | if (CurrentBar) |
|
|
1737 | { |
1576 | CurrentBar = CurrentBar->next; |
1738 | CurrentBar = CurrentBar->next; |
1577 | menu_readonly = 1; |
1739 | menu_readonly = 1; |
1578 | } |
1740 | } |
|
|
1741 | } |
1579 | } else if (!STRCMP(str, "prev")) { |
1742 | else if (!STRCMP (str, "prev")) |
1580 | if (CurrentBar) { |
1743 | { |
|
|
1744 | if (CurrentBar) |
|
|
1745 | { |
1581 | CurrentBar = CurrentBar->prev; |
1746 | CurrentBar = CurrentBar->prev; |
1582 | menu_readonly = 1; |
1747 | menu_readonly = 1; |
1583 | } |
1748 | } |
|
|
1749 | } |
1584 | } else if (!STRCMP(str, "swap")) { |
1750 | else if (!STRCMP (str, "swap")) |
1585 | /* swap the top 2 menus */ |
1751 | { |
1586 | if (CurrentBar) { |
1752 | /* swap the top 2 menus */ |
|
|
1753 | if (CurrentBar) |
|
|
1754 | { |
1587 | bar_t *cbprev = CurrentBar->prev; |
1755 | bar_t *cbprev = CurrentBar->prev; |
1588 | bar_t *cbnext = CurrentBar->next; |
1756 | bar_t *cbnext = CurrentBar->next; |
1589 | |
1757 | |
1590 | cbprev->next = cbnext; |
1758 | cbprev->next = cbnext; |
1591 | cbnext->prev = cbprev; |
1759 | cbnext->prev = cbprev; |
1592 | |
1760 | |
1593 | CurrentBar->next = cbprev; |
1761 | CurrentBar->next = cbprev; |
1594 | CurrentBar->prev = cbprev->prev; |
1762 | CurrentBar->prev = cbprev->prev; |
1595 | |
1763 | |
1596 | cbprev->prev->next = CurrentBar; |
1764 | cbprev->prev->next = CurrentBar; |
1597 | cbprev->prev = CurrentBar; |
1765 | cbprev->prev = CurrentBar; |
1598 | |
1766 | |
1599 | CurrentBar = cbprev; |
1767 | CurrentBar = cbprev; |
1600 | menu_readonly = 1; |
1768 | menu_readonly = 1; |
1601 | } |
1769 | } |
1602 | } |
1770 | } |
1603 | #endif /* (MENUBAR_MAX > 1) */ |
1771 | #endif /* (MENUBAR_MAX > 1) */ |
1604 | str = next; |
1772 | str = next; |
1605 | |
1773 | |
1606 | BuildMenu = ActiveMenu = NULL; |
1774 | BuildMenu = ActiveMenu = NULL; |
1607 | menubar_expose (); |
1775 | menubar_expose (); |
1608 | #ifdef DEBUG_MENUBAR_STACKING |
1776 | #ifdef DEBUG_MENUBAR_STACKING |
1609 | fprintf(stderr, "menus are read%s\n", |
1777 | fprintf (stderr, "menus are read%s\n", |
1610 | menu_readonly ? "only" : "/write"); |
1778 | menu_readonly ? "only" : "/write"); |
1611 | #endif |
1779 | #endif |
1612 | } |
1780 | |
1613 | return; |
1781 | } |
1614 | break; |
1782 | return; |
|
|
1783 | break; |
1615 | } |
1784 | } |
1616 | |
1785 | |
1617 | #if (MENUBAR_MAX > 1) |
1786 | #if (MENUBAR_MAX > 1) |
1618 | if (CurrentBar == NULL) |
1787 | if (CurrentBar == NULL) |
1619 | return; |
1788 | return; |
1620 | if (menu_readonly) { |
1789 | if (menu_readonly) |
|
|
1790 | { |
1621 | #ifdef DEBUG_MENUBAR_STACKING |
1791 | #ifdef DEBUG_MENUBAR_STACKING |
1622 | fprintf(stderr, "menus are read%s\n", |
1792 | fprintf (stderr, "menus are read%s\n", |
1623 | menu_readonly ? "only" : "/write"); |
1793 | menu_readonly ? "only" : "/write"); |
1624 | #endif |
1794 | #endif |
1625 | return; |
1795 | return; |
1626 | } |
1796 | } |
1627 | #endif /* (MENUBAR_MAX > 1) */ |
1797 | #endif /* (MENUBAR_MAX > 1) */ |
1628 | |
1798 | |
1629 | switch (cmd) { |
1799 | switch (cmd) |
|
|
1800 | { |
1630 | case '+': |
1801 | case '+': |
1631 | case '-': |
1802 | case '-': |
1632 | path = name = str; |
1803 | path = name = str; |
1633 | |
1804 | |
1634 | name2 = NULL; |
1805 | name2 = NULL; |
1635 | /* parse STR, allow spaces inside (name) */ |
1806 | /* parse STR, allow spaces inside (name) */ |
1636 | if (path[0] != '\0') { |
1807 | if (path[0] != '\0') |
|
|
1808 | { |
1637 | name = STRCHR(path, MENUITEM_BEG); |
1809 | name = STRCHR (path, MENUITEM_BEG); |
1638 | str = STRCHR(path, MENUITEM_END); |
1810 | str = STRCHR (path, MENUITEM_END); |
1639 | if (name != NULL || str != NULL) { |
1811 | if (name != NULL || str != NULL) |
|
|
1812 | { |
1640 | if (name == NULL || str == NULL || str <= (name + 1) |
1813 | if (name == NULL || str == NULL || str <= (name + 1) |
1641 | || (name > path && name[-1] != '/')) { |
1814 | || (name > path && name[-1] != '/')) |
|
|
1815 | { |
1642 | rxvt_print_error("menu error <%s>\n", path); |
1816 | rxvt_print_error ("menu error <%s>\n", path); |
1643 | break; |
1817 | break; |
1644 | } |
1818 | } |
1645 | if (str[1] == MENUITEM_BEG) { |
1819 | if (str[1] == MENUITEM_BEG) |
1646 | name2 = (str + 2); |
1820 | { |
|
|
1821 | name2 = (str + 2); |
1647 | str = STRCHR(name2, MENUITEM_END); |
1822 | str = STRCHR (name2, MENUITEM_END); |
1648 | |
1823 | |
1649 | if (str == NULL) { |
1824 | if (str == NULL) |
|
|
1825 | { |
1650 | rxvt_print_error("menu error <%s>\n", path); |
1826 | rxvt_print_error ("menu error <%s>\n", path); |
1651 | break; |
1827 | break; |
1652 | } |
1828 | } |
1653 | name2[-2] = '\0'; /* remove prev MENUITEM_END */ |
1829 | name2[-2] = '\0'; /* remove prev MENUITEM_END */ |
1654 | } |
1830 | } |
1655 | if (name > path && name[-1] == '/') |
1831 | if (name > path && name[-1] == '/') |
1656 | name[-1] = '\0'; |
1832 | name[-1] = '\0'; |
1657 | |
1833 | |
1658 | *name++ = '\0'; /* delimit */ |
1834 | *name++ = '\0'; /* delimit */ |
1659 | *str++ = '\0'; /* delimit */ |
1835 | *str++ = '\0'; /* delimit */ |
1660 | |
1836 | |
1661 | while (isspace(*str)) |
1837 | while (isspace (*str)) |
1662 | str++; /* skip space */ |
1838 | str++; /* skip space */ |
1663 | } |
1839 | } |
1664 | #ifdef DEBUG_MENU |
1840 | #ifdef DEBUG_MENU |
1665 | fprintf(stderr, |
1841 | fprintf (stderr, |
1666 | "`%c' path = <%s>, name = <%s>, name2 = <%s>, action = <%s>\n", |
1842 | "`%c' path = <%s>, name = <%s>, name2 = <%s>, action = <%s>\n", |
1667 | cmd, (path ? path : "(nil)"), (name ? name : "(nil)"), |
1843 | cmd, (path ? path : " (nil)"), (name ? name : " (nil)"), |
1668 | (name2 ? name2 : "(nil)"), (str ? str : "(nil)") |
1844 | (name2 ? name2 : " (nil)"), (str ? str : " (nil)") |
1669 | ); |
1845 | ); |
1670 | #endif |
1846 | #endif |
1671 | } |
1847 | |
|
|
1848 | } |
1672 | /* process the different commands */ |
1849 | /* process the different commands */ |
1673 | switch (cmd) { |
1850 | switch (cmd) |
|
|
1851 | { |
1674 | case '+': /* add/replace existing menu or menuitem */ |
1852 | case '+': /* add/replace existing menu or menuitem */ |
1675 | if (path[0] != '\0') { |
1853 | if (path[0] != '\0') |
1676 | int len; |
1854 | { |
|
|
1855 | int len; |
1677 | |
1856 | |
1678 | path = menu_find_base (&(BuildMenu), path); |
1857 | path = menu_find_base (& (BuildMenu), path); |
1679 | len = STRLEN(path); |
1858 | len = STRLEN (path); |
1680 | |
1859 | |
1681 | /* don't allow menus called `*' */ |
1860 | /* don't allow menus called `*' */ |
1682 | if (path[0] == '*') { |
1861 | if (path[0] == '*') |
1683 | menu_clear (BuildMenu); |
1862 | { |
1684 | break; |
1863 | menu_clear (BuildMenu); |
|
|
1864 | break; |
|
|
1865 | } |
1685 | } else if (len >= 2 && !STRCMP((path + len - 2), "/*")) { |
1866 | else if (len >= 2 && !STRCMP ((path + len - 2), "/*")) |
1686 | path[len - 2] = '\0'; |
1867 | { |
1687 | } |
1868 | path[len - 2] = '\0'; |
1688 | if (path[0] != '\0') |
1869 | } |
|
|
1870 | if (path[0] != '\0') |
1689 | BuildMenu = menu_add (BuildMenu, path); |
1871 | BuildMenu = menu_add (BuildMenu, path); |
1690 | } |
1872 | } |
1691 | if (name != NULL && name[0] != '\0') |
1873 | if (name != NULL && name[0] != '\0') |
1692 | rxvt_menuitem_add(BuildMenu, |
1874 | rxvt_menuitem_add (BuildMenu, |
1693 | (STRCMP(name, SEPARATOR_NAME) ? name : ""), |
1875 | (STRCMP (name, SEPARATOR_NAME) ? name : ""), |
1694 | name2, str); |
1876 | name2, str); |
1695 | break; |
1877 | break; |
1696 | |
1878 | |
1697 | case '-': /* delete menu entry */ |
1879 | case '-': /* delete menu entry */ |
1698 | if (!STRCMP(path, "/*") && (name == NULL || name[0] == '\0')) { |
1880 | if (!STRCMP (path, "/*") && (name == NULL || name[0] == '\0')) |
1699 | menubar_clear (); |
1881 | { |
1700 | BuildMenu = NULL; |
1882 | menubar_clear (); |
1701 | menubar_expose (); |
1883 | BuildMenu = NULL; |
1702 | break; |
1884 | menubar_expose (); |
1703 | } else if (path[0] != '\0') { |
1885 | break; |
1704 | int len; |
1886 | } |
|
|
1887 | else if (path[0] != '\0') |
|
|
1888 | { |
|
|
1889 | int len; |
1705 | menu_t *menu = BuildMenu; |
1890 | menu_t *menu = BuildMenu; |
1706 | |
1891 | |
1707 | path = menu_find_base (&menu, path); |
1892 | path = menu_find_base (&menu, path); |
1708 | len = STRLEN(path); |
1893 | len = STRLEN (path); |
1709 | |
1894 | |
1710 | /* submenu called `*' clears all menu items */ |
1895 | /* submenu called `*' clears all menu items */ |
1711 | if (path[0] == '*') { |
1896 | if (path[0] == '*') |
1712 | menu_clear (menu); |
1897 | { |
1713 | break; /* done */ |
1898 | menu_clear (menu); |
|
|
1899 | break; /* done */ |
|
|
1900 | } |
1714 | } else if (len >= 2 && !STRCMP(&path[len - 2], "/*")) { |
1901 | else if (len >= 2 && !STRCMP (&path[len - 2], "/*")) |
1715 | /* done */ |
1902 | { |
1716 | break; |
1903 | /* done */ |
1717 | } else if (path[0] != '\0') { |
1904 | break; |
1718 | BuildMenu = NULL; |
1905 | } |
1719 | break; |
1906 | else if (path[0] != '\0') |
1720 | } else |
1907 | { |
1721 | BuildMenu = menu; |
1908 | BuildMenu = NULL; |
1722 | } |
1909 | break; |
|
|
1910 | } |
|
|
1911 | else |
|
|
1912 | BuildMenu = menu; |
|
|
1913 | } |
1723 | if (BuildMenu != NULL) { |
1914 | if (BuildMenu != NULL) |
|
|
1915 | { |
1724 | if (name == NULL || name[0] == '\0') |
1916 | if (name == NULL || name[0] == '\0') |
1725 | BuildMenu = menu_delete (BuildMenu); |
1917 | BuildMenu = menu_delete (BuildMenu); |
1726 | else { |
1918 | else |
1727 | const char *n1; |
1919 | { |
1728 | menuitem_t *item; |
1920 | const char *n1; |
|
|
1921 | menuitem_t *item; |
1729 | menu_t *BuildMenu = BuildMenu; |
1922 | menu_t *BuildMenu = BuildMenu; |
1730 | |
1923 | |
1731 | n1 = STRCMP(name, SEPARATOR_NAME) ? name : ""; |
1924 | n1 = STRCMP (name, SEPARATOR_NAME) ? name : ""; |
1732 | item = rxvt_menuitem_find(BuildMenu, n1); |
1925 | item = rxvt_menuitem_find (BuildMenu, n1); |
1733 | if (item != NULL && item->entry.type != MenuSubMenu) { |
1926 | if (item != NULL && item->entry.type != MenuSubMenu) |
1734 | menuitem_free (BuildMenu, item); |
1927 | { |
|
|
1928 | menuitem_free (BuildMenu, item); |
1735 | |
1929 | |
1736 | /* fix up the width */ |
1930 | /* fix up the width */ |
1737 | BuildMenu->width = 0; |
1931 | BuildMenu->width = 0; |
1738 | for (item = BuildMenu->head; item != NULL; |
1932 | for (item = BuildMenu->head; item != NULL; |
1739 | item = item->next) { |
1933 | item = item->next) |
|
|
1934 | { |
1740 | short l = item->len + item->len2; |
1935 | short l = item->len + item->len2; |
1741 | |
1936 | |
1742 | MAX_IT(BuildMenu->width, l); |
1937 | MAX_IT (BuildMenu->width, l); |
1743 | } |
1938 | } |
1744 | } |
1939 | } |
1745 | } |
1940 | } |
1746 | menubar_expose (); |
1941 | menubar_expose (); |
1747 | } |
1942 | } |
|
|
1943 | break; |
|
|
1944 | } |
1748 | break; |
1945 | break; |
1749 | } |
|
|
1750 | break; |
|
|
1751 | } |
1946 | } |
1752 | } |
1947 | } |
1753 | |
1948 | |
1754 | void |
1949 | void |
1755 | rxvt_term::draw_Arrows (int name, int state) |
1950 | rxvt_term::draw_Arrows (int name, int state) |
1756 | { |
1951 | { |
1757 | GC top, bot; |
1952 | GC top, bot; |
1758 | |
1953 | |
1759 | int i; |
1954 | int i; |
1760 | |
1955 | |
1761 | #ifdef MENU_SHADOW_IN |
1956 | #ifdef MENU_SHADOW_IN |
1762 | state = -state; |
1957 | state = -state; |
1763 | #endif |
1958 | #endif |
1764 | switch (state) { |
1959 | switch (state) |
|
|
1960 | { |
1765 | case +1: |
1961 | case +1: |
1766 | top = topShadowGC; |
1962 | top = topShadowGC; |
1767 | bot = botShadowGC; |
1963 | bot = botShadowGC; |
1768 | break; /* SHADOW_OUT */ |
1964 | break; /* SHADOW_OUT */ |
1769 | case -1: |
1965 | case -1: |
1770 | top = botShadowGC; |
1966 | top = botShadowGC; |
1771 | bot = topShadowGC; |
1967 | bot = topShadowGC; |
1772 | break; /* SHADOW_IN */ |
1968 | break; /* SHADOW_IN */ |
1773 | default: |
1969 | default: |
1774 | top = bot = scrollbarGC; |
1970 | top = bot = scrollbarGC; |
1775 | break; /* neutral */ |
1971 | break; /* neutral */ |
1776 | } |
1972 | } |
1777 | |
1973 | |
1778 | if (!Arrows_x) |
1974 | if (!Arrows_x) |
1779 | return; |
1975 | return; |
1780 | |
1976 | |
1781 | for (i = 0; i < NARROWS; i++) { |
1977 | for (i = 0; i < NARROWS; i++) |
|
|
1978 | { |
1782 | const int w = Width2Pixel(1); |
1979 | const int w = Width2Pixel (1); |
1783 | const int y = (menuBar_TotalHeight() - w) / 2; |
1980 | const int y = (menuBar_TotalHeight () - w) / 2; |
1784 | int x = Arrows_x + (5 * Width2Pixel(i)) / 4; |
1981 | int x = Arrows_x + (5 * Width2Pixel (i)) / 4; |
1785 | |
1982 | |
1786 | if (!name || name == Arrows[i].name) |
1983 | if (!name || name == Arrows[i].name) |
1787 | rxvt_Draw_Triangle(Xdisplay, menuBar.win, top, bot, x, y, w, |
1984 | rxvt_Draw_Triangle (display->display, menuBar.win, top, bot, x, y, w, |
1788 | Arrows[i].name); |
1985 | Arrows[i].name); |
1789 | } |
1986 | } |
1790 | XFlush(Xdisplay); |
1987 | XFlush (display->display); |
1791 | } |
1988 | } |
1792 | |
1989 | |
1793 | void |
1990 | void |
1794 | rxvt_term::menubar_expose () |
1991 | rxvt_term::menubar_expose () |
1795 | { |
1992 | { |
1796 | menu_t *menu; |
1993 | menu_t *menu; |
1797 | int x; |
1994 | int x; |
1798 | |
1995 | |
1799 | if (!menubar_visible(r) || menuBar.win == 0) |
1996 | if (!menubar_visible () || menuBar.win == 0) |
1800 | return; |
1997 | return; |
1801 | |
1998 | |
1802 | if (menubarGC == None) { |
1999 | if (menubarGC == None) |
|
|
2000 | { |
1803 | /* Create the graphics context */ |
2001 | /* Create the graphics context */ |
1804 | XGCValues gcvalue; |
2002 | XGCValues gcvalue; |
1805 | |
2003 | |
1806 | gcvalue.font = TermWin.font->fid; |
2004 | gcvalue.font = TermWin.font->fid; |
1807 | |
2005 | |
1808 | gcvalue.foreground = (XDEPTH <= 2 ? PixColors[Color_fg] |
2006 | gcvalue.foreground = (XDEPTH <= 2 ? PixColors[Color_fg] |
1809 | : PixColors[Color_Black]); |
2007 | : PixColors[Color_Black]); |
1810 | menubarGC = XCreateGC(Xdisplay, menuBar.win, |
2008 | menubarGC = XCreateGC (display->display, menuBar.win, |
1811 | GCForeground | GCFont, &gcvalue); |
2009 | GCForeground | GCFont, &gcvalue); |
1812 | |
2010 | |
1813 | } |
2011 | } |
1814 | /* make sure the font is correct */ |
2012 | /* make sure the font is correct */ |
1815 | XSetFont(Xdisplay, menubarGC, TermWin.font->fid); |
2013 | XSetFont (display->display, menubarGC, TermWin.font->fid); |
1816 | XSetFont(Xdisplay, botShadowGC, TermWin.font->fid); |
2014 | XSetFont (display->display, botShadowGC, TermWin.font->fid); |
1817 | XClearWindow(Xdisplay, menuBar.win); |
2015 | XClearWindow (display->display, menuBar.win); |
1818 | |
2016 | |
1819 | menu_hide_all (); |
2017 | menu_hide_all (); |
1820 | |
2018 | |
1821 | x = 0; |
2019 | x = 0; |
1822 | if (CurrentBar != NULL) { |
2020 | if (CurrentBar != NULL) |
|
|
2021 | { |
1823 | for (menu = CurrentBar->head; menu != NULL; menu = menu->next) { |
2022 | for (menu = CurrentBar->head; menu != NULL; menu = menu->next) |
|
|
2023 | { |
1824 | int len = menu->len; |
2024 | int len = menu->len; |
1825 | |
2025 | |
1826 | x = (menu->x + menu->len + HSPACE); |
2026 | x = (menu->x + menu->len + HSPACE); |
1827 | |
2027 | |
1828 | #ifdef DEBUG_MENU_LAYOUT |
2028 | #ifdef DEBUG_MENU_LAYOUT |
1829 | rxvt_print_menu_descendants(menu); |
2029 | rxvt_print_menu_descendants (menu); |
1830 | #endif |
2030 | #endif |
1831 | |
2031 | |
1832 | if (x >= TermWin.ncol) |
2032 | if (x >= TermWin.ncol) |
1833 | len = (TermWin.ncol - (menu->x + HSPACE)); |
2033 | len = (TermWin.ncol - (menu->x + HSPACE)); |
1834 | |
2034 | |
1835 | drawbox_menubar (menu->x, len, +1); |
2035 | drawbox_menubar (menu->x, len, +1); |
1836 | #ifdef USE_XIM |
2036 | draw_string (display->display, menuBar.win, menubarGC, |
1837 | if (TermWin.fontset) |
|
|
1838 | XmbDrawString(Xdisplay, |
|
|
1839 | menuBar.win, TermWin.fontset, |
|
|
1840 | menubarGC, |
|
|
1841 | (Width2Pixel(menu->x) + Width2Pixel(HSPACE) / 2), |
2037 | (Width2Pixel (menu->x) + Width2Pixel (HSPACE) / 2), |
1842 | menuBar_height() - SHADOW, menu->name, len); |
2038 | menuBar_height () - SHADOW, menu->name, len); |
1843 | else |
|
|
1844 | #endif |
|
|
1845 | XDrawString(Xdisplay, menuBar.win, menubarGC, |
|
|
1846 | (Width2Pixel(menu->x) + Width2Pixel(HSPACE) / 2), |
|
|
1847 | menuBar_height() - SHADOW, menu->name, len); |
|
|
1848 | |
2039 | |
1849 | if (x >= TermWin.ncol) |
2040 | if (x >= TermWin.ncol) |
1850 | break; |
2041 | break; |
1851 | } |
2042 | } |
1852 | } |
2043 | } |
1853 | drawbox_menubar (x, TermWin.ncol, (CurrentBar ? +1 : -1)); |
2044 | drawbox_menubar (x, TermWin.ncol, (CurrentBar ? +1 : -1)); |
1854 | |
2045 | |
1855 | /* add the menuBar title, if it exists and there's plenty of room */ |
2046 | /* add the menuBar title, if it exists and there's plenty of room */ |
1856 | Arrows_x = 0; |
2047 | Arrows_x = 0; |
1857 | if (x < TermWin.ncol) { |
2048 | if (x < TermWin.ncol) |
|
|
2049 | { |
1858 | const char *str; |
2050 | const char *str; |
1859 | int ncol; |
2051 | int ncol; |
1860 | unsigned int len; |
2052 | unsigned int len; |
1861 | char title[256]; |
2053 | char title[256]; |
1862 | |
2054 | |
1863 | ncol = (int)TermWin.ncol; |
2055 | ncol = (int)TermWin.ncol; |
1864 | if (x < (ncol - (NARROWS + 1))) { |
2056 | if (x < (ncol - (NARROWS + 1))) |
|
|
2057 | { |
1865 | ncol -= (NARROWS + 1); |
2058 | ncol -= (NARROWS + 1); |
1866 | Arrows_x = Width2Pixel(ncol); |
2059 | Arrows_x = Width2Pixel (ncol); |
1867 | } |
2060 | } |
1868 | draw_Arrows (0, +1); |
2061 | draw_Arrows (0, +1); |
1869 | |
2062 | |
1870 | str = (CurrentBar |
2063 | str = (CurrentBar |
1871 | && CurrentBar->title) ? CurrentBar->title : "%n-%v"; |
2064 | && CurrentBar->title) ? CurrentBar->title : "%n-%v"; |
1872 | for (len = 0; str[0] && len < sizeof(title) - 1; str++) { |
2065 | for (len = 0; str[0] && len < sizeof (title) - 1; str++) |
|
|
2066 | { |
1873 | const char *s = NULL; |
2067 | const char *s = NULL; |
1874 | |
2068 | |
1875 | switch (str[0]) { |
2069 | switch (str[0]) |
1876 | case '%': |
2070 | { |
1877 | str++; |
2071 | case '%': |
1878 | switch (str[0]) { |
2072 | str++; |
1879 | case 'n': |
2073 | switch (str[0]) |
1880 | s = rs[Rs_name]; |
2074 | { |
|
|
2075 | case 'n': |
|
|
2076 | s = rs[Rs_name]; |
1881 | break; /* resource name */ |
2077 | break; /* resource name */ |
1882 | case 'v': |
2078 | case 'v': |
1883 | s = VERSION; |
2079 | s = VERSION; |
1884 | break; /* version number */ |
2080 | break; /* version number */ |
1885 | case '%': |
2081 | case '%': |
1886 | s = "%"; |
2082 | s = "%"; |
1887 | break; /* literal '%' */ |
2083 | break; /* literal '%' */ |
1888 | } |
2084 | } |
1889 | if (s != NULL) |
2085 | if (s != NULL) |
1890 | while (*s && len < sizeof(title) - 1) |
2086 | while (*s && len < sizeof (title) - 1) |
1891 | title[len++] = *s++; |
2087 | title[len++] = *s++; |
1892 | break; |
2088 | break; |
1893 | |
2089 | |
1894 | default: |
2090 | default: |
1895 | title[len++] = str[0]; |
2091 | title[len++] = str[0]; |
1896 | break; |
2092 | break; |
1897 | } |
2093 | } |
1898 | } |
2094 | } |
1899 | title[len] = '\0'; |
2095 | title[len] = '\0'; |
1900 | |
2096 | |
1901 | ncol -= (x + len + HSPACE); |
2097 | ncol -= (x + len + HSPACE); |
1902 | if (len > 0 && ncol >= 0) { |
2098 | if (len > 0 && ncol >= 0) |
1903 | #ifdef USE_XIM |
2099 | draw_string (display->display, menuBar.win, menubarGC, |
1904 | if (TermWin.fontset) |
|
|
1905 | XmbDrawString(Xdisplay, |
|
|
1906 | menuBar.win, TermWin.fontset, |
|
|
1907 | menubarGC, |
|
|
1908 | Width2Pixel(x) + Width2Pixel(ncol + HSPACE) / 2, |
2100 | Width2Pixel (x) + Width2Pixel (ncol + HSPACE) / 2, |
1909 | menuBar_height() - SHADOW, title, len); |
2101 | menuBar_height () - SHADOW, title, len); |
1910 | else |
|
|
1911 | #endif |
|
|
1912 | XDrawString(Xdisplay, menuBar.win, menubarGC, |
|
|
1913 | Width2Pixel(x) + Width2Pixel(ncol + HSPACE) / 2, |
|
|
1914 | menuBar_height() - SHADOW, title, len); |
|
|
1915 | } |
|
|
1916 | } |
2102 | } |
1917 | } |
2103 | } |
1918 | |
2104 | |
1919 | int |
2105 | int |
1920 | rxvt_term::menubar_mapping (int map) |
2106 | rxvt_term::menubar_mapping (int map) |
1921 | { |
2107 | { |
1922 | int change = 0; |
2108 | int change = 0; |
1923 | |
2109 | |
1924 | if (map && !menubar_visible(r)) { |
2110 | if (map && !menubar_visible ()) |
|
|
2111 | { |
1925 | menuBar.state = 1; |
2112 | menuBar.state = 1; |
1926 | if (menuBar.win == 0) |
2113 | if (menuBar.win == 0) |
1927 | return 0; |
2114 | return 0; |
1928 | XMapWindow(Xdisplay, menuBar.win); |
2115 | XMapWindow (display->display, menuBar.win); |
1929 | change = 1; |
2116 | change = 1; |
|
|
2117 | } |
1930 | } else if (!map && menubar_visible(r)) { |
2118 | else if (!map && menubar_visible ()) |
|
|
2119 | { |
|
|
2120 | menubar_expose (); |
|
|
2121 | menuBar.state = 0; |
|
|
2122 | XUnmapWindow (display->display, menuBar.win); |
|
|
2123 | change = 1; |
|
|
2124 | } |
|
|
2125 | else |
1931 | menubar_expose (); |
2126 | menubar_expose (); |
1932 | menuBar.state = 0; |
|
|
1933 | XUnmapWindow(Xdisplay, menuBar.win); |
|
|
1934 | change = 1; |
|
|
1935 | } else |
|
|
1936 | menubar_expose (); |
|
|
1937 | |
2127 | |
1938 | return change; |
2128 | return change; |
1939 | } |
2129 | } |
1940 | |
2130 | |
1941 | int |
2131 | int |
1942 | rxvt_term::menu_select (XButtonEvent *ev) |
2132 | rxvt_term::menu_select (XButtonEvent &ev) |
1943 | { |
2133 | { |
1944 | menuitem_t *thisitem, *item = NULL; |
2134 | menuitem_t *thisitem, *item = NULL; |
1945 | int this_y, y; |
2135 | int this_y, y; |
1946 | menu_t *ActiveMenu = ActiveMenu; |
2136 | menu_t *ActiveMenu = ActiveMenu; |
1947 | |
2137 | |
1948 | Window unused_root, unused_child; |
2138 | Window unused_root, unused_child; |
1949 | int unused_root_x, unused_root_y; |
2139 | int unused_root_x, unused_root_y; |
1950 | unsigned int unused_mask; |
2140 | unsigned int unused_mask; |
1951 | |
2141 | |
1952 | if (ActiveMenu == NULL) |
2142 | if (ActiveMenu == NULL) |
1953 | return 0; |
2143 | return 0; |
1954 | |
2144 | |
1955 | XQueryPointer(Xdisplay, ActiveMenu->win, |
2145 | XQueryPointer (display->display, ActiveMenu->win, |
1956 | &unused_root, &unused_child, |
2146 | &unused_root, &unused_child, |
1957 | &unused_root_x, &unused_root_y, |
2147 | &unused_root_x, &unused_root_y, |
1958 | &(ev->x), &(ev->y), &unused_mask); |
2148 | &ev.x, &ev.y, &unused_mask); |
1959 | |
2149 | |
1960 | if (ActiveMenu->parent != NULL && (ev->x < 0 || ev->y < 0)) { |
2150 | if (ActiveMenu->parent != NULL && (ev.x < 0 || ev.y < 0)) |
1961 | menu_hide (); |
|
|
1962 | return 1; |
|
|
1963 | } |
2151 | { |
|
|
2152 | menu_hide (); |
|
|
2153 | return 1; |
|
|
2154 | } |
1964 | /* determine the menu item corresponding to the Y index */ |
2155 | /* determine the menu item corresponding to the Y index */ |
1965 | y = SHADOW; |
2156 | y = SHADOW; |
1966 | if (ev->x >= 0 && ev->x <= (ActiveMenu->w - SHADOW)) { |
2157 | if (ev.x >= 0 && ev.x <= (ActiveMenu->w - SHADOW)) |
|
|
2158 | { |
1967 | for (item = ActiveMenu->head; item != NULL; item = item->next) { |
2159 | for (item = ActiveMenu->head; item != NULL; item = item->next) |
|
|
2160 | { |
1968 | int h = HEIGHT_TEXT + 2 * SHADOW; |
2161 | int h = HEIGHT_TEXT + 2 * SHADOW; |
1969 | |
2162 | |
1970 | if (isSeparator(item->name)) |
2163 | if (isSeparator (item->name)) |
1971 | h = HEIGHT_SEPARATOR; |
2164 | h = HEIGHT_SEPARATOR; |
1972 | else if (ev->y >= y && ev->y < (y + h)) |
2165 | else if (ev.y >= y && ev.y < (y + h)) |
1973 | break; |
2166 | break; |
1974 | y += h; |
2167 | y += h; |
1975 | } |
2168 | } |
1976 | } |
2169 | } |
1977 | if (item == NULL && ev->type == ButtonRelease) { |
2170 | if (item == NULL && ev.type == ButtonRelease) |
|
|
2171 | { |
1978 | menu_hide_all (); |
2172 | menu_hide_all (); |
1979 | return 0; |
2173 | return 0; |
1980 | } |
2174 | } |
1981 | thisitem = item; |
2175 | thisitem = item; |
1982 | this_y = y - SHADOW; |
2176 | this_y = y - SHADOW; |
1983 | |
2177 | |
1984 | /* erase the last item */ |
2178 | /* erase the last item */ |
1985 | if (ActiveMenu->item != NULL) { |
2179 | if (ActiveMenu->item != NULL) |
|
|
2180 | { |
1986 | if (ActiveMenu->item != thisitem) { |
2181 | if (ActiveMenu->item != thisitem) |
|
|
2182 | { |
1987 | for (y = 0, item = ActiveMenu->head; item != NULL; |
2183 | for (y = 0, item = ActiveMenu->head; item != NULL; |
1988 | item = item->next) { |
2184 | item = item->next) |
1989 | int h; |
2185 | { |
|
|
2186 | int h; |
1990 | |
2187 | |
1991 | if (isSeparator(item->name)) |
2188 | if (isSeparator (item->name)) |
1992 | h = HEIGHT_SEPARATOR; |
2189 | h = HEIGHT_SEPARATOR; |
1993 | else if (item == ActiveMenu->item) { |
2190 | else if (item == ActiveMenu->item) |
|
|
2191 | { |
1994 | /* erase old menuitem */ |
2192 | /* erase old menuitem */ |
1995 | drawbox_menuitem (y, 0); /* No Shadow */ |
2193 | drawbox_menuitem (y, 0); /* No Shadow */ |
1996 | if (item->entry.type == MenuSubMenu) |
2194 | if (item->entry.type == MenuSubMenu) |
1997 | drawtriangle (ActiveMenu->w, y, +1); |
2195 | drawtriangle (ActiveMenu->w, y, +1); |
1998 | break; |
2196 | break; |
1999 | } else |
2197 | } |
|
|
2198 | else |
2000 | h = HEIGHT_TEXT + 2 * SHADOW; |
2199 | h = HEIGHT_TEXT + 2 * SHADOW; |
2001 | y += h; |
2200 | y += h; |
2002 | } |
2201 | } |
2003 | } else { |
2202 | } |
|
|
2203 | else |
|
|
2204 | { |
2004 | switch (ev->type) { |
2205 | switch (ev.type) |
|
|
2206 | { |
2005 | case ButtonRelease: |
2207 | case ButtonRelease: |
2006 | switch (item->entry.type) { |
2208 | switch (item->entry.type) |
2007 | case MenuLabel: |
2209 | { |
2008 | case MenuSubMenu: |
2210 | case MenuLabel: |
2009 | menu_hide_all (); |
2211 | case MenuSubMenu: |
2010 | break; |
2212 | menu_hide_all (); |
|
|
2213 | break; |
2011 | |
2214 | |
2012 | case MenuAction: |
2215 | case MenuAction: |
2013 | case MenuTerminalAction: |
2216 | case MenuTerminalAction: |
2014 | drawbox_menuitem (_y, -1); |
2217 | drawbox_menuitem (this_y, -1); |
2015 | { |
2218 | { |
2016 | #ifdef HAVE_NANOSLEEP |
2219 | #ifdef HAVE_NANOSLEEP |
2017 | struct timespec rqt; |
2220 | struct timespec rqt; |
2018 | |
2221 | |
2019 | rqt.tv_sec = 0; |
2222 | rqt.tv_sec = 0; |
2020 | rqt.tv_nsec = MENU_DELAY_USEC * 1000; |
2223 | rqt.tv_nsec = MENU_DELAY_USEC * 1000; |
2021 | nanosleep(&rqt, NULL); |
2224 | nanosleep (&rqt, NULL); |
2022 | #else |
2225 | #else |
2023 | /* use select for timing */ |
2226 | /* use select for timing */ |
2024 | struct timeval tv; |
2227 | struct timeval tv; |
2025 | |
2228 | |
2026 | tv.tv_sec = 0; |
2229 | tv.tv_sec = 0; |
2027 | tv.tv_usec = MENU_DELAY_USEC; |
2230 | tv.tv_usec = MENU_DELAY_USEC; |
2028 | select(0, NULL, NULL, NULL, &tv); |
2231 | select (0, NULL, NULL, NULL, &tv); |
2029 | #endif |
2232 | #endif |
2030 | } |
2233 | |
|
|
2234 | } |
2031 | /* remove menu before sending keys to the application */ |
2235 | /* remove menu before sending keys to the application */ |
2032 | menu_hide_all (); |
2236 | menu_hide_all (); |
2033 | #ifndef DEBUG_MENU |
2237 | #ifndef DEBUG_MENU |
2034 | action_dispatch (&(item->entry.action)); |
2238 | action_dispatch (& (item->entry.action)); |
2035 | #else /* DEBUG_MENU */ |
2239 | #else /* DEBUG_MENU */ |
2036 | fprintf(stderr, "%s: %s\n", item->name, |
2240 | fprintf (stderr, "%s: %s\n", item->name, |
2037 | item->entry.action.str); |
2241 | item->entry.action.str); |
2038 | #endif /* DEBUG_MENU */ |
2242 | #endif /* DEBUG_MENU */ |
2039 | break; |
2243 | break; |
2040 | } |
2244 | } |
2041 | break; |
2245 | break; |
2042 | |
2246 | |
2043 | default: |
2247 | default: |
2044 | if (item->entry.type == MenuSubMenu) |
2248 | if (item->entry.type == MenuSubMenu) |
2045 | goto DoMenu; |
2249 | goto DoMenu; |
2046 | break; |
2250 | break; |
|
|
2251 | } |
|
|
2252 | return 0; |
|
|
2253 | } |
2047 | } |
2254 | } |
2048 | return 0; |
|
|
2049 | } |
|
|
2050 | } |
|
|
2051 | DoMenu: |
2255 | DoMenu: |
2052 | ActiveMenu->item = thisitem; |
2256 | ActiveMenu->item = thisitem; |
2053 | y = this_y; |
2257 | y = this_y; |
2054 | if (item != NULL) { |
2258 | if (item != NULL) |
|
|
2259 | { |
2055 | item = ActiveMenu->item; |
2260 | item = ActiveMenu->item; |
2056 | if (item->entry.type != MenuLabel) |
2261 | if (item->entry.type != MenuLabel) |
2057 | drawbox_menuitem (y, +1); |
2262 | drawbox_menuitem (y, +1); |
2058 | if (item->entry.type == MenuSubMenu) { |
2263 | if (item->entry.type == MenuSubMenu) |
|
|
2264 | { |
2059 | int x; |
2265 | int x; |
2060 | |
2266 | |
2061 | drawtriangle (ActiveMenu->w, y, -1); |
2267 | drawtriangle (ActiveMenu->w, y, -1); |
2062 | |
2268 | |
2063 | x = ev->x + (ActiveMenu->parent |
2269 | x = ev.x + (ActiveMenu->parent |
2064 | ? ActiveMenu->x |
2270 | ? ActiveMenu->x |
2065 | : Width2Pixel(ActiveMenu->x)); |
2271 | : Width2Pixel (ActiveMenu->x)); |
2066 | |
2272 | |
2067 | if (x >= item->entry.submenu.menu->x) { |
2273 | if (x >= item->entry.submenu.menu->x) |
|
|
2274 | { |
2068 | ActiveMenu = item->entry.submenu.menu; |
2275 | ActiveMenu = item->entry.submenu.menu; |
2069 | menu_show (); |
2276 | menu_show (); |
2070 | return 1; |
2277 | return 1; |
|
|
2278 | } |
|
|
2279 | } |
2071 | } |
2280 | } |
2072 | } |
|
|
2073 | } |
|
|
2074 | return 0; |
2281 | return 0; |
2075 | } |
2282 | } |
2076 | |
2283 | |
2077 | void |
2284 | void |
2078 | rxvt_term::menubar_select (XButtonEvent *ev) |
2285 | rxvt_term::menubar_select (XButtonEvent &ev) |
2079 | { |
2286 | { |
2080 | menu_t *menu = NULL; |
2287 | menu_t *menu = NULL; |
2081 | |
2288 | |
2082 | /* determine the pulldown menu corresponding to the X index */ |
2289 | /* determine the pulldown menu corresponding to the X index */ |
2083 | if (ev->y >= 0 && ev->y <= menuBar_height() && CurrentBar != NULL) { |
2290 | if (ev.y >= 0 && ev.y <= menuBar_height () && CurrentBar != NULL) |
|
|
2291 | { |
2084 | for (menu = CurrentBar->head; menu != NULL; menu = menu->next) { |
2292 | for (menu = CurrentBar->head; menu != NULL; menu = menu->next) |
|
|
2293 | { |
2085 | int x = Width2Pixel(menu->x); |
2294 | int x = Width2Pixel (menu->x); |
2086 | int w = Width2Pixel(menu->len + HSPACE); |
2295 | int w = Width2Pixel (menu->len + HSPACE); |
2087 | |
2296 | |
2088 | if ((ev->x >= x && ev->x < x + w)) |
2297 | if ((ev.x >= x && ev.x < x + w)) |
2089 | break; |
2298 | break; |
2090 | } |
2299 | } |
2091 | } |
2300 | } |
2092 | switch (ev->type) { |
2301 | switch (ev.type) |
|
|
2302 | { |
2093 | case ButtonRelease: |
2303 | case ButtonRelease: |
2094 | menu_hide_all (); |
2304 | menu_hide_all (); |
2095 | break; |
2305 | break; |
2096 | |
2306 | |
2097 | case ButtonPress: |
2307 | case ButtonPress: |
2098 | if (menu == NULL && Arrows_x && ev->x >= Arrows_x) { |
2308 | if (menu == NULL && Arrows_x && ev.x >= Arrows_x) |
|
|
2309 | { |
2099 | int i; |
2310 | int i; |
2100 | |
2311 | |
2101 | for (i = 0; i < NARROWS; i++) { |
2312 | for (i = 0; i < NARROWS; i++) |
|
|
2313 | { |
2102 | if (ev->x >= (Arrows_x + (Width2Pixel(4 * i + i)) / 4) |
2314 | if (ev.x >= (Arrows_x + (Width2Pixel (4 * i + i)) / 4) |
2103 | && ev->x < (Arrows_x |
2315 | && ev.x < (Arrows_x |
2104 | + (Width2Pixel(4 * i + i + 4)) / 4)) { |
2316 | + (Width2Pixel (4 * i + i + 4)) / 4)) |
|
|
2317 | { |
2105 | draw_Arrows (Arrows[i].name, -1); |
2318 | draw_Arrows (Arrows[i].name, -1); |
2106 | { |
2319 | { |
2107 | #ifdef HAVE_NANOSLEEP |
2320 | #ifdef HAVE_NANOSLEEP |
2108 | struct timespec rqt; |
2321 | struct timespec rqt; |
2109 | |
2322 | |
2110 | rqt.tv_sec = 0; |
2323 | rqt.tv_sec = 0; |
2111 | rqt.tv_nsec = MENU_DELAY_USEC * 1000; |
2324 | rqt.tv_nsec = MENU_DELAY_USEC * 1000; |
2112 | nanosleep(&rqt, NULL); |
2325 | nanosleep (&rqt, NULL); |
2113 | #else |
2326 | #else |
2114 | /* use select for timing */ |
2327 | /* use select for timing */ |
2115 | struct timeval tv; |
2328 | struct timeval tv; |
2116 | |
2329 | |
2117 | tv.tv_sec = 0; |
2330 | tv.tv_sec = 0; |
2118 | tv.tv_usec = MENU_DELAY_USEC; |
2331 | tv.tv_usec = MENU_DELAY_USEC; |
2119 | select(0, NULL, NULL, NULL, &tv); |
2332 | select (0, NULL, NULL, NULL, &tv); |
2120 | #endif |
2333 | #endif |
2121 | } |
2334 | |
|
|
2335 | } |
2122 | draw_Arrows (Arrows[i].name, +1); |
2336 | draw_Arrows (Arrows[i].name, +1); |
2123 | #ifdef DEBUG_MENUARROWS |
2337 | #ifdef DEBUG_MENUARROWS |
2124 | fprintf(stderr, "'%c': ", Arrows[i].name); |
2338 | fprintf (stderr, "'%c': ", Arrows[i].name); |
2125 | |
2339 | |
2126 | if (CurrentBar == NULL |
2340 | if (CurrentBar == NULL |
2127 | || (CurrentBar->arrows[i].type != MenuAction |
2341 | || (CurrentBar->arrows[i].type != MenuAction |
2128 | && CurrentBar->arrows[i].type != |
2342 | && CurrentBar->arrows[i].type != |
2129 | MenuTerminalAction)) { |
2343 | MenuTerminalAction)) |
|
|
2344 | { |
2130 | if (Arrows[i].str != NULL && Arrows[i].str[0]) |
2345 | if (Arrows[i].str != NULL && Arrows[i].str[0]) |
2131 | fprintf(stderr, "(default) \\033%s\n", |
2346 | fprintf (stderr, " (default) \\033%s\n", |
2132 | &(Arrows[i].str[2])); |
2347 | & (Arrows[i].str[2])); |
2133 | } else { |
2348 | } |
2134 | fprintf(stderr, "%s\n", |
2349 | else |
2135 | CurrentBar->arrows[i].str); |
2350 | { |
2136 | } |
2351 | fprintf (stderr, "%s\n", |
|
|
2352 | CurrentBar->arrows[i].str); |
|
|
2353 | } |
2137 | #else /* DEBUG_MENUARROWS */ |
2354 | #else /* DEBUG_MENUARROWS */ |
2138 | if (CurrentBar == NULL |
2355 | if (CurrentBar == NULL || action_dispatch (&CurrentBar->arrows[i])) |
2139 | || rxvt_action_dispatch(r, |
2356 | { |
2140 | &(CurrentBar->arrows[i])) |
|
|
2141 | ) { |
|
|
2142 | if (Arrows[i].str != NULL && Arrows[i].str[0] != 0) |
2357 | if (Arrows[i].str != NULL && Arrows[i].str[0] != 0) |
2143 | tt_write ((Arrows[i].str + 1), |
2358 | tt_write ((Arrows[i].str + 1), |
2144 | Arrows[i].str[0]); |
2359 | Arrows[i].str[0]); |
2145 | } |
2360 | } |
2146 | #endif /* DEBUG_MENUARROWS */ |
2361 | #endif /* DEBUG_MENUARROWS */ |
2147 | return; |
2362 | return; |
2148 | } |
2363 | } |
2149 | } |
2364 | } |
2150 | } |
2365 | } |
2151 | /* FALLTHROUGH */ |
2366 | /* FALLTHROUGH */ |
2152 | |
2367 | |
2153 | default: |
2368 | default: |
2154 | /* |
2369 | /* |
2155 | * press menubar or move to a new entry |
2370 | * press menubar or move to a new entry |
2156 | */ |
2371 | */ |
2157 | if (menu != NULL && menu != ActiveMenu) { |
2372 | if (menu != NULL && menu != ActiveMenu) |
|
|
2373 | { |
2158 | menu_hide_all (); /* pop down old menu */ |
2374 | menu_hide_all (); /* pop down old menu */ |
2159 | ActiveMenu = menu; |
2375 | ActiveMenu = menu; |
2160 | menu_show (); /* pop up new menu */ |
2376 | menu_show (); /* pop up new menu */ |
2161 | } |
2377 | } |
2162 | break; |
2378 | break; |
2163 | } |
2379 | } |
2164 | } |
2380 | } |
2165 | |
2381 | |
2166 | /* |
2382 | /* |
2167 | * general dispatch routine, |
2383 | * general dispatch routine, |
2168 | * it would be nice to have `sticky' menus |
2384 | * it would be nice to have `sticky' menus |
2169 | */ |
2385 | */ |
2170 | void |
2386 | void |
2171 | rxvt_term::menubar_control (XButtonEvent *ev) |
2387 | rxvt_term::menubar_control (XButtonEvent &ev) |
2172 | { |
2388 | { |
2173 | switch (ev->type) { |
2389 | switch (ev.type) |
|
|
2390 | { |
2174 | case ButtonPress: |
2391 | case ButtonPress: |
2175 | if (ev->button == Button1) |
2392 | if (ev.button == Button1) |
2176 | menubar_select (ev); |
2393 | menubar_select (ev); |
2177 | break; |
2394 | break; |
2178 | |
2395 | |
2179 | case ButtonRelease: |
2396 | case ButtonRelease: |
2180 | if (ev->button == Button1) |
2397 | if (ev.button == Button1) |
2181 | menu_select (ev); |
2398 | menu_select (ev); |
2182 | break; |
2399 | break; |
2183 | |
2400 | |
2184 | case MotionNotify: |
2401 | case MotionNotify: |
2185 | while (XCheckTypedWindowEvent(Xdisplay, TermWin.parent[0], |
2402 | while (XCheckTypedWindowEvent (display->display, TermWin.parent[0], |
2186 | MotionNotify, (XEvent *) ev)) ; |
2403 | MotionNotify, (XEvent *)&ev)) ; |
2187 | |
2404 | |
2188 | if (ActiveMenu) |
2405 | if (ActiveMenu) |
2189 | while (menu_select (ev)) ; |
2406 | while (menu_select (ev)) ; |
2190 | else |
2407 | else |
2191 | ev->y = -1; |
2408 | ev.y = -1; |
2192 | if (ev->y < 0) { |
2409 | if (ev.y < 0) |
|
|
2410 | { |
2193 | Window unused_root, unused_child; |
2411 | Window unused_root, unused_child; |
2194 | int unused_root_x, unused_root_y; |
2412 | int unused_root_x, unused_root_y; |
2195 | unsigned int unused_mask; |
2413 | unsigned int unused_mask; |
2196 | |
2414 | |
2197 | XQueryPointer(Xdisplay, menuBar.win, |
2415 | XQueryPointer (display->display, menuBar.win, |
2198 | &unused_root, &unused_child, |
2416 | &unused_root, &unused_child, |
2199 | &unused_root_x, &unused_root_y, |
2417 | &unused_root_x, &unused_root_y, |
2200 | &(ev->x), &(ev->y), &unused_mask); |
2418 | &ev.x, &ev.y, &unused_mask); |
2201 | menubar_select (ev); |
2419 | menubar_select (ev); |
2202 | } |
2420 | } |
2203 | break; |
2421 | break; |
2204 | } |
2422 | } |
2205 | } |
2423 | } |
2206 | |
2424 | |
2207 | void |
2425 | void |
2208 | rxvt_term::map_menuBar (int map) |
2426 | rxvt_term::map_menuBar (int map) |
2209 | { |
2427 | { |
2210 | if (menubar_mapping (map)) |
2428 | if (menubar_mapping (map)) |
2211 | resize_all_windows (0, 0, 0); |
2429 | resize_all_windows (0, 0, 0); |
2212 | } |
2430 | } |
2213 | #endif |
2431 | #endif |
2214 | /*----------------------- end-of-file (C source) -----------------------*/ |
2432 | /*----------------------- end-of-file (C source) -----------------------*/ |