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