1 | /*--------------------------------*-C-*---------------------------------* |
1 | /*--------------------------------*-C-*---------------------------------* |
2 | * File: menubar.c |
2 | * File: menubar.c |
3 | *----------------------------------------------------------------------* |
3 | *----------------------------------------------------------------------* |
4 | * $Id: menubar.C,v 1.2 2003/11/24 17:31:27 pcg Exp $ |
4 | * $Id: menubar.C,v 1.4 2004/01/31 00:20:21 pcg Exp $ |
5 | * |
5 | * |
6 | * Copyright (c) 1997,1998 mj olesen <olesen@me.QueensU.CA> |
6 | * Copyright (c) 1997,1998 mj olesen <olesen@me.QueensU.CA> |
7 | * |
7 | * |
8 | * 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 |
9 | * 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 |
… | |
… | |
46 | /*}}} */ |
46 | /*}}} */ |
47 | |
47 | |
48 | /* |
48 | /* |
49 | * find an item called NAME in MENU |
49 | * find an item called NAME in MENU |
50 | */ |
50 | */ |
51 | /* INTPROTO */ |
|
|
52 | menuitem_t * |
51 | menuitem_t * |
53 | rxvt_menuitem_find(const menu_t *menu, const char *name) |
52 | rxvt_menuitem_find(const menu_t *menu, const char *name) |
54 | { |
53 | { |
55 | menuitem_t *item; |
54 | menuitem_t *item; |
56 | |
55 | |
… | |
… | |
72 | } |
71 | } |
73 | |
72 | |
74 | /* |
73 | /* |
75 | * unlink ITEM from its MENU and free its memory |
74 | * unlink ITEM from its MENU and free its memory |
76 | */ |
75 | */ |
77 | /* INTPROTO */ |
|
|
78 | void |
76 | void |
79 | rxvt_menuitem_free(pR_ menu_t *menu, menuitem_t *item) |
77 | rxvt_term::menuitem_free (menu_t *menu, menuitem_t *item) |
80 | { |
78 | { |
81 | /* disconnect */ |
79 | /* disconnect */ |
82 | menuitem_t *prev, *next; |
80 | menuitem_t *prev, *next; |
83 | |
81 | |
84 | #ifdef DEBUG_STRICT |
82 | #ifdef DEBUG_STRICT |
… | |
… | |
102 | case MenuAction: |
100 | case MenuAction: |
103 | case MenuTerminalAction: |
101 | case MenuTerminalAction: |
104 | free(item->entry.action.str); |
102 | free(item->entry.action.str); |
105 | break; |
103 | break; |
106 | case MenuSubMenu: |
104 | case MenuSubMenu: |
107 | rxvt_menu_delete(aR_ item->entry.submenu.menu); |
105 | menu_delete (item->entry.submenu.menu); |
108 | break; |
106 | break; |
109 | } |
107 | } |
110 | if (item->name != NULL) |
108 | if (item->name != NULL) |
111 | free(item->name); |
109 | free(item->name); |
112 | if (item->name2 != NULL) |
110 | if (item->name2 != NULL) |
… | |
… | |
116 | |
114 | |
117 | /* |
115 | /* |
118 | * sort command vs. terminal actions and |
116 | * sort command vs. terminal actions and |
119 | * remove the first character of STR if it's '\0' |
117 | * remove the first character of STR if it's '\0' |
120 | */ |
118 | */ |
121 | /* INTPROTO */ |
|
|
122 | int |
119 | int |
123 | rxvt_action_type(action_t *action, unsigned char *str) |
120 | rxvt_action_type(action_t *action, unsigned char *str) |
124 | { |
121 | { |
125 | unsigned int len; |
122 | unsigned int len; |
126 | |
123 | |
… | |
… | |
153 | action->len = len; |
150 | action->len = len; |
154 | |
151 | |
155 | return 0; |
152 | return 0; |
156 | } |
153 | } |
157 | |
154 | |
158 | /* INTPROTO */ |
|
|
159 | int |
155 | int |
160 | rxvt_action_dispatch(pR_ action_t *action) |
156 | rxvt_term::action_dispatch (action_t *action) |
161 | { |
157 | { |
162 | switch (action->type) { |
158 | switch (action->type) { |
163 | case MenuTerminalAction: |
159 | case MenuTerminalAction: |
164 | rxvt_cmd_write(aR_ action->str, action->len); |
160 | cmd_write (action->str, action->len); |
165 | break; |
161 | break; |
166 | |
162 | |
167 | case MenuAction: |
163 | case MenuAction: |
168 | rxvt_tt_write(aR_ action->str, action->len); |
164 | tt_write (action->str, action->len); |
169 | break; |
165 | break; |
170 | |
166 | |
171 | default: |
167 | default: |
172 | return -1; |
168 | return -1; |
173 | break; |
169 | break; |
174 | } |
170 | } |
175 | return 0; |
171 | return 0; |
176 | } |
172 | } |
177 | |
173 | |
178 | /* return the arrow index corresponding to NAME */ |
174 | /* return the arrow index corresponding to NAME */ |
179 | /* INTPROTO */ |
|
|
180 | int |
175 | int |
181 | rxvt_menuarrow_find(char name) |
176 | rxvt_menuarrow_find(char name) |
182 | { |
177 | { |
183 | int i; |
178 | int i; |
184 | |
179 | |
… | |
… | |
187 | return i; |
182 | return i; |
188 | return -1; |
183 | return -1; |
189 | } |
184 | } |
190 | |
185 | |
191 | /* free the memory associated with arrow NAME of the current menubar */ |
186 | /* free the memory associated with arrow NAME of the current menubar */ |
192 | /* INTPROTO */ |
|
|
193 | void |
187 | void |
194 | rxvt_menuarrow_free(pR_ char name) |
188 | rxvt_term::menuarrow_free (char name) |
195 | { |
189 | { |
196 | int i; |
190 | int i; |
197 | |
191 | |
198 | if (name) { |
192 | if (name) { |
199 | i = rxvt_menuarrow_find(name); |
193 | i = rxvt_menuarrow_find(name); |
200 | if (i >= 0) { |
194 | if (i >= 0) { |
201 | action_t *act = &(R->h->CurrentBar->arrows[i]); |
195 | action_t *act = &(CurrentBar->arrows[i]); |
202 | |
196 | |
203 | switch (act->type) { |
197 | switch (act->type) { |
204 | case MenuAction: |
198 | case MenuAction: |
205 | case MenuTerminalAction: |
199 | case MenuTerminalAction: |
206 | free(act->str); |
200 | free(act->str); |
… | |
… | |
210 | } |
204 | } |
211 | act->type = MenuLabel; |
205 | act->type = MenuLabel; |
212 | } |
206 | } |
213 | } else { |
207 | } else { |
214 | for (i = 0; i < NARROWS; i++) |
208 | for (i = 0; i < NARROWS; i++) |
215 | rxvt_menuarrow_free(aR_ Arrows[i].name); |
209 | menuarrow_free (Arrows[i].name); |
216 | } |
210 | } |
217 | } |
211 | } |
218 | |
212 | |
219 | /* INTPROTO */ |
|
|
220 | void |
213 | void |
221 | rxvt_menuarrow_add(pR_ char *string) |
214 | rxvt_term::menuarrow_add (char *string) |
222 | { |
215 | { |
223 | int i; |
216 | int i; |
224 | unsigned xtra_len; |
217 | unsigned xtra_len; |
225 | char *p; |
218 | char *p; |
226 | struct { |
219 | struct { |
… | |
… | |
300 | #endif |
293 | #endif |
301 | |
294 | |
302 | xtra_len = (beg.len + end.len); |
295 | xtra_len = (beg.len + end.len); |
303 | for (i = 0; i < NARROWS; i++) { |
296 | for (i = 0; i < NARROWS; i++) { |
304 | if (xtra_len || parse[i].len) |
297 | if (xtra_len || parse[i].len) |
305 | rxvt_menuarrow_free(aR_ Arrows[i].name); |
298 | menuarrow_free (Arrows[i].name); |
306 | } |
299 | } |
307 | |
300 | |
308 | for (i = 0; i < NARROWS; i++) { |
301 | for (i = 0; i < NARROWS; i++) { |
309 | unsigned char *str; |
302 | unsigned char *str; |
310 | unsigned int len; |
303 | unsigned int len; |
… | |
… | |
329 | str[len] = '\0'; |
322 | str[len] = '\0'; |
330 | |
323 | |
331 | #ifdef DEBUG_MENUARROWS |
324 | #ifdef DEBUG_MENUARROWS |
332 | fprintf(stderr, "<%c>(len %d) = %s\n", Arrows[i].name, len, str); |
325 | fprintf(stderr, "<%c>(len %d) = %s\n", Arrows[i].name, len, str); |
333 | #endif |
326 | #endif |
334 | if (rxvt_action_type(&(R->h->CurrentBar->arrows[i]), str) < 0) |
327 | if (rxvt_action_type(&(CurrentBar->arrows[i]), str) < 0) |
335 | free(str); |
328 | free(str); |
336 | } |
329 | } |
337 | } |
330 | } |
338 | |
331 | |
339 | /* INTPROTO */ |
|
|
340 | menuitem_t * |
332 | menuitem_t * |
341 | rxvt_menuitem_add(menu_t *menu, const char *name, const char *name2, const char *action) |
333 | rxvt_menuitem_add(menu_t *menu, const char *name, const char *name2, const char *action) |
342 | { |
334 | { |
343 | menuitem_t *item; |
335 | menuitem_t *item; |
344 | unsigned int len; |
336 | unsigned int len; |
… | |
… | |
438 | |
430 | |
439 | /* |
431 | /* |
440 | * search for the base starting menu for NAME. |
432 | * search for the base starting menu for NAME. |
441 | * return a pointer to the portion of NAME that remains |
433 | * return a pointer to the portion of NAME that remains |
442 | */ |
434 | */ |
443 | /* INTPROTO */ |
|
|
444 | char * |
435 | char * |
445 | rxvt_menu_find_base(pR_ menu_t **menu, char *path) |
436 | rxvt_term::menu_find_base (menu_t **menu, char *path) |
446 | { |
437 | { |
447 | menu_t *m = NULL; |
438 | menu_t *m = NULL; |
448 | menuitem_t *item; |
439 | menuitem_t *item; |
449 | |
440 | |
450 | #ifdef DEBUG_STRICT |
441 | #ifdef DEBUG_STRICT |
451 | assert(menu != NULL); |
442 | assert(menu != NULL); |
452 | assert(R->h->CurrentBar != NULL); |
443 | assert(CurrentBar != NULL); |
453 | #endif |
444 | #endif |
454 | |
445 | |
455 | if (path[0] == '\0') |
446 | if (path[0] == '\0') |
456 | return path; |
447 | return path; |
457 | |
448 | |
… | |
… | |
475 | /* nothing to do */ |
466 | /* nothing to do */ |
476 | } else if (!STRCMP(path, DOTS)) { |
467 | } else if (!STRCMP(path, DOTS)) { |
477 | if (*menu != NULL) |
468 | if (*menu != NULL) |
478 | *menu = (*menu)->parent; |
469 | *menu = (*menu)->parent; |
479 | } else { |
470 | } else { |
480 | path = rxvt_menu_find_base(aR_ menu, path); |
471 | path = menu_find_base (menu, path); |
481 | if (path[0] != '\0') { /* not found */ |
472 | if (path[0] != '\0') { /* not found */ |
482 | p[0] = '/'; /* fix-up name again */ |
473 | p[0] = '/'; /* fix-up name again */ |
483 | return path; |
474 | return path; |
484 | } |
475 | } |
485 | } |
476 | } |
… | |
… | |
493 | *menu = (*menu)->parent; |
484 | *menu = (*menu)->parent; |
494 | return path; |
485 | return path; |
495 | } |
486 | } |
496 | /* find this menu */ |
487 | /* find this menu */ |
497 | if (*menu == NULL) { |
488 | if (*menu == NULL) { |
498 | for (m = R->h->CurrentBar->tail; m != NULL; m = m->prev) { |
489 | for (m = CurrentBar->tail; m != NULL; m = m->prev) { |
499 | if (!STRCMP(path, m->name)) |
490 | if (!STRCMP(path, m->name)) |
500 | break; |
491 | break; |
501 | } |
492 | } |
502 | } else { |
493 | } else { |
503 | /* find this menu */ |
494 | /* find this menu */ |
… | |
… | |
517 | } |
508 | } |
518 | |
509 | |
519 | /* |
510 | /* |
520 | * delete this entire menu |
511 | * delete this entire menu |
521 | */ |
512 | */ |
522 | /* INTPROTO */ |
|
|
523 | menu_t * |
513 | menu_t * |
524 | rxvt_menu_delete(pR_ menu_t *menu) |
514 | rxvt_term::menu_delete (menu_t *menu) |
525 | { |
515 | { |
526 | menu_t *parent = NULL, *prev, *next; |
516 | menu_t *parent = NULL, *prev, *next; |
527 | menuitem_t *item; |
517 | menuitem_t *item; |
528 | bar_t *CurrentBar = R->h->CurrentBar; |
518 | bar_t *CurrentBar = CurrentBar; |
529 | |
519 | |
530 | #ifdef DEBUG_STRICT |
520 | #ifdef DEBUG_STRICT |
531 | assert(CurrentBar != NULL); |
521 | assert(CurrentBar != NULL); |
532 | #endif |
522 | #endif |
533 | |
523 | |
… | |
… | |
559 | } else { |
549 | } else { |
560 | for (item = parent->tail; item != NULL; item = item->prev) { |
550 | for (item = parent->tail; item != NULL; item = item->prev) { |
561 | if (item->entry.type == MenuSubMenu |
551 | if (item->entry.type == MenuSubMenu |
562 | && item->entry.submenu.menu == menu) { |
552 | && item->entry.submenu.menu == menu) { |
563 | item->entry.submenu.menu = NULL; |
553 | item->entry.submenu.menu = NULL; |
564 | rxvt_menuitem_free(aR_ menu->parent, item); |
554 | menuitem_free (menu->parent, item); |
565 | break; |
555 | break; |
566 | } |
556 | } |
567 | } |
557 | } |
568 | } |
558 | } |
569 | |
559 | |
570 | item = menu->tail; |
560 | item = menu->tail; |
571 | while (item != NULL) { |
561 | while (item != NULL) { |
572 | menuitem_t *p = item->prev; |
562 | menuitem_t *p = item->prev; |
573 | |
563 | |
574 | rxvt_menuitem_free(aR_ menu, item); |
564 | menuitem_free (menu, item); |
575 | item = p; |
565 | item = p; |
576 | } |
566 | } |
577 | |
567 | |
578 | if (menu->name != NULL) |
568 | if (menu->name != NULL) |
579 | free(menu->name); |
569 | free(menu->name); |
580 | free(menu); |
570 | free(menu); |
581 | |
571 | |
582 | return parent; |
572 | return parent; |
583 | } |
573 | } |
584 | |
574 | |
585 | /* INTPROTO */ |
|
|
586 | menu_t * |
575 | menu_t * |
587 | rxvt_menu_add(pR_ menu_t *parent, char *path) |
576 | rxvt_term::menu_add (menu_t *parent, char *path) |
588 | { |
577 | { |
589 | menu_t *menu; |
578 | menu_t *menu; |
590 | bar_t *CurrentBar = R->h->CurrentBar; |
579 | bar_t *CurrentBar = CurrentBar; |
591 | |
580 | |
592 | #ifdef DEBUG_STRICT |
581 | #ifdef DEBUG_STRICT |
593 | assert(CurrentBar != NULL); |
582 | assert(CurrentBar != NULL); |
594 | #endif |
583 | #endif |
595 | |
584 | |
… | |
… | |
604 | while ((p = STRCHR(path, '/')) != NULL) { |
593 | while ((p = STRCHR(path, '/')) != NULL) { |
605 | p[0] = '\0'; |
594 | p[0] = '\0'; |
606 | if (path[0] == '\0') |
595 | if (path[0] == '\0') |
607 | return NULL; |
596 | return NULL; |
608 | |
597 | |
609 | parent = rxvt_menu_add(aR_ parent, path); |
598 | parent = menu_add (parent, path); |
610 | path = (p + 1); |
599 | path = (p + 1); |
611 | } |
600 | } |
612 | } |
601 | } |
613 | if (!STRCMP(path, DOTS)) |
602 | if (!STRCMP(path, DOTS)) |
614 | return (parent != NULL ? parent->parent : parent); |
603 | return (parent != NULL ? parent->parent : parent); |
… | |
… | |
659 | } |
648 | } |
660 | |
649 | |
661 | return menu; |
650 | return menu; |
662 | } |
651 | } |
663 | |
652 | |
664 | /* INTPROTO */ |
|
|
665 | void |
653 | void |
666 | rxvt_drawbox_menubar(pR_ int x, int len, int state) |
654 | rxvt_term::drawbox_menubar (int x, int len, int state) |
667 | { |
655 | { |
668 | GC top, bot; |
656 | GC top, bot; |
669 | |
657 | |
670 | x = Width2Pixel(x); |
658 | x = Width2Pixel(x); |
671 | len = Width2Pixel(len + HSPACE); |
659 | len = Width2Pixel(len + HSPACE); |
672 | if (x >= R->TermWin.width) |
660 | if (x >= TermWin.width) |
673 | return; |
661 | return; |
674 | else if (x + len >= R->TermWin.width) |
662 | else if (x + len >= TermWin.width) |
675 | len = (TermWin_TotalWidth() - x); |
663 | len = (TermWin_TotalWidth() - x); |
676 | |
664 | |
677 | #ifdef MENUBAR_SHADOW_IN |
665 | #ifdef MENUBAR_SHADOW_IN |
678 | state = -state; |
666 | state = -state; |
679 | #endif |
667 | #endif |
680 | switch (state) { |
668 | switch (state) { |
681 | case +1: |
669 | case +1: |
682 | top = R->h->topShadowGC; |
670 | top = topShadowGC; |
683 | bot = R->h->botShadowGC; |
671 | bot = botShadowGC; |
684 | break; /* SHADOW_OUT */ |
672 | break; /* SHADOW_OUT */ |
685 | case -1: |
673 | case -1: |
686 | top = R->h->botShadowGC; |
674 | top = botShadowGC; |
687 | bot = R->h->topShadowGC; |
675 | bot = topShadowGC; |
688 | break; /* SHADOW_IN */ |
676 | break; /* SHADOW_IN */ |
689 | default: |
677 | default: |
690 | top = bot = R->h->scrollbarGC; |
678 | top = bot = scrollbarGC; |
691 | break; /* neutral */ |
679 | break; /* neutral */ |
692 | } |
680 | } |
693 | |
681 | |
694 | rxvt_Draw_Shadow(R->Xdisplay, R->menuBar.win, top, bot, |
682 | rxvt_Draw_Shadow(Xdisplay, menuBar.win, top, bot, |
695 | x, 0, len, menuBar_TotalHeight()); |
683 | x, 0, len, menuBar_TotalHeight()); |
696 | } |
684 | } |
697 | |
685 | |
698 | /* INTPROTO */ |
|
|
699 | void |
686 | void |
700 | rxvt_drawtriangle(pR_ int x, int y, int state) |
687 | rxvt_term::drawtriangle (int x, int y, int state) |
701 | { |
688 | { |
702 | GC top, bot; |
689 | GC top, bot; |
703 | int w; |
690 | int w; |
704 | |
691 | |
705 | #ifdef MENU_SHADOW_IN |
692 | #ifdef MENU_SHADOW_IN |
706 | state = -state; |
693 | state = -state; |
707 | #endif |
694 | #endif |
708 | switch (state) { |
695 | switch (state) { |
709 | case +1: |
696 | case +1: |
710 | top = R->h->topShadowGC; |
697 | top = topShadowGC; |
711 | bot = R->h->botShadowGC; |
698 | bot = botShadowGC; |
712 | break; /* SHADOW_OUT */ |
699 | break; /* SHADOW_OUT */ |
713 | case -1: |
700 | case -1: |
714 | top = R->h->botShadowGC; |
701 | top = botShadowGC; |
715 | bot = R->h->topShadowGC; |
702 | bot = topShadowGC; |
716 | break; /* SHADOW_IN */ |
703 | break; /* SHADOW_IN */ |
717 | default: |
704 | default: |
718 | top = bot = R->h->scrollbarGC; |
705 | top = bot = scrollbarGC; |
719 | break; /* neutral */ |
706 | break; /* neutral */ |
720 | } |
707 | } |
721 | |
708 | |
722 | w = Height2Pixel(1) - 2 * SHADOW; |
709 | w = Height2Pixel(1) - 2 * SHADOW; |
723 | |
710 | |
724 | x -= SHADOW + (3 * w / 2); |
711 | x -= SHADOW + (3 * w / 2); |
725 | y += SHADOW * 3; |
712 | y += SHADOW * 3; |
726 | |
713 | |
727 | rxvt_Draw_Triangle(R->Xdisplay, R->h->ActiveMenu->win, top, bot, x, y, w, |
714 | rxvt_Draw_Triangle(Xdisplay, ActiveMenu->win, top, bot, x, y, w, |
728 | 'r'); |
715 | 'r'); |
729 | } |
716 | } |
730 | |
717 | |
731 | /* INTPROTO */ |
|
|
732 | void |
718 | void |
733 | rxvt_drawbox_menuitem(pR_ int y, int state) |
719 | rxvt_term::drawbox_menuitem (int y, int state) |
734 | { |
720 | { |
735 | GC top, bot; |
721 | GC top, bot; |
736 | |
722 | |
737 | #ifdef MENU_SHADOW_IN |
723 | #ifdef MENU_SHADOW_IN |
738 | state = -state; |
724 | state = -state; |
739 | #endif |
725 | #endif |
740 | switch (state) { |
726 | switch (state) { |
741 | case +1: |
727 | case +1: |
742 | top = R->h->topShadowGC; |
728 | top = topShadowGC; |
743 | bot = R->h->botShadowGC; |
729 | bot = botShadowGC; |
744 | break; /* SHADOW_OUT */ |
730 | break; /* SHADOW_OUT */ |
745 | case -1: |
731 | case -1: |
746 | top = R->h->botShadowGC; |
732 | top = botShadowGC; |
747 | bot = R->h->topShadowGC; |
733 | bot = topShadowGC; |
748 | break; /* SHADOW_IN */ |
734 | break; /* SHADOW_IN */ |
749 | default: |
735 | default: |
750 | top = bot = R->h->scrollbarGC; |
736 | top = bot = scrollbarGC; |
751 | break; /* neutral */ |
737 | break; /* neutral */ |
752 | } |
738 | } |
753 | |
739 | |
754 | rxvt_Draw_Shadow(R->Xdisplay, R->h->ActiveMenu->win, top, bot, |
740 | rxvt_Draw_Shadow(Xdisplay, ActiveMenu->win, top, bot, |
755 | SHADOW + 0, SHADOW + y, |
741 | SHADOW + 0, SHADOW + y, |
756 | R->h->ActiveMenu->w - 2 * (SHADOW), |
742 | ActiveMenu->w - 2 * (SHADOW), |
757 | HEIGHT_TEXT + 2 * SHADOW); |
743 | HEIGHT_TEXT + 2 * SHADOW); |
758 | XFlush(R->Xdisplay); |
744 | XFlush(Xdisplay); |
759 | } |
745 | } |
760 | |
746 | |
761 | #ifdef DEBUG_MENU_LAYOUT |
747 | #ifdef DEBUG_MENU_LAYOUT |
762 | /* INTPROTO */ |
|
|
763 | void |
748 | void |
764 | rxvt_print_menu_ancestors(menu_t *menu) |
749 | rxvt_print_menu_ancestors(menu_t *menu) |
765 | { |
750 | { |
766 | if (menu == NULL) { |
751 | if (menu == NULL) { |
767 | fprintf(stderr, "Top Level menu\n"); |
752 | fprintf(stderr, "Top Level menu\n"); |
… | |
… | |
784 | } |
769 | } |
785 | fprintf(stderr, "\n"); |
770 | fprintf(stderr, "\n"); |
786 | rxvt_print_menu_ancestors(menu->parent); |
771 | rxvt_print_menu_ancestors(menu->parent); |
787 | } |
772 | } |
788 | |
773 | |
789 | /* INTPROTO */ |
|
|
790 | void |
774 | void |
791 | rxvt_print_menu_descendants(menu_t *menu) |
775 | rxvt_print_menu_descendants(menu_t *menu) |
792 | { |
776 | { |
793 | menuitem_t *item; |
777 | menuitem_t *item; |
794 | menu_t *parent; |
778 | menu_t *parent; |
… | |
… | |
825 | fprintf(stderr, "\n"); |
809 | fprintf(stderr, "\n"); |
826 | } |
810 | } |
827 | #endif |
811 | #endif |
828 | |
812 | |
829 | /* pop up/down the current menu and redraw the menuBar button */ |
813 | /* pop up/down the current menu and redraw the menuBar button */ |
830 | /* INTPROTO */ |
|
|
831 | void |
814 | void |
832 | rxvt_menu_show(pR) |
815 | rxvt_term::menu_show () |
833 | { |
816 | { |
834 | int x, y, xright; |
817 | int x, y, xright; |
835 | menu_t *ActiveMenu = R->h->ActiveMenu; |
818 | menu_t *ActiveMenu = ActiveMenu; |
836 | menuitem_t *item; |
819 | menuitem_t *item; |
837 | |
820 | |
838 | if (ActiveMenu == NULL) |
821 | if (ActiveMenu == NULL) |
839 | return; |
822 | return; |
840 | |
823 | |
841 | x = ActiveMenu->x; |
824 | x = ActiveMenu->x; |
842 | if (ActiveMenu->parent == NULL) { |
825 | if (ActiveMenu->parent == NULL) { |
843 | register int h; |
826 | register int h; |
844 | |
827 | |
845 | rxvt_drawbox_menubar(aR_ x, ActiveMenu->len, -1); |
828 | drawbox_menubar (x, ActiveMenu->len, -1); |
846 | x = Width2Pixel(x); |
829 | x = Width2Pixel(x); |
847 | |
830 | |
848 | ActiveMenu->y = 1; |
831 | ActiveMenu->y = 1; |
849 | ActiveMenu->w = Menu_PixelWidth(ActiveMenu); |
832 | ActiveMenu->w = Menu_PixelWidth(ActiveMenu); |
850 | |
833 | |
851 | if ((x + ActiveMenu->w) >= R->TermWin.width) |
834 | if ((x + ActiveMenu->w) >= TermWin.width) |
852 | x = (TermWin_TotalWidth() - ActiveMenu->w); |
835 | x = (TermWin_TotalWidth() - ActiveMenu->w); |
853 | |
836 | |
854 | /* find the height */ |
837 | /* find the height */ |
855 | for (h = 0, item = ActiveMenu->head; item != NULL; item = item->next) |
838 | for (h = 0, item = ActiveMenu->head; item != NULL; item = item->next) |
856 | h += isSeparator(item->name) ? HEIGHT_SEPARATOR |
839 | h += isSeparator(item->name) ? HEIGHT_SEPARATOR |
857 | : HEIGHT_TEXT + 2 * SHADOW; |
840 | : HEIGHT_TEXT + 2 * SHADOW; |
858 | ActiveMenu->h = h + 2 * SHADOW; |
841 | ActiveMenu->h = h + 2 * SHADOW; |
859 | } |
842 | } |
860 | if (ActiveMenu->win == None) { |
843 | if (ActiveMenu->win == None) { |
861 | ActiveMenu->win = XCreateSimpleWindow(R->Xdisplay, R->TermWin.vt, |
844 | ActiveMenu->win = XCreateSimpleWindow(Xdisplay, TermWin.vt, |
862 | x, ActiveMenu->y, |
845 | x, ActiveMenu->y, |
863 | ActiveMenu->w, ActiveMenu->h, |
846 | ActiveMenu->w, ActiveMenu->h, |
864 | 0, |
847 | 0, |
865 | R->PixColors[Color_fg], |
848 | PixColors[Color_fg], |
866 | R->PixColors[Color_scroll]); |
849 | PixColors[Color_scroll]); |
867 | XMapWindow(R->Xdisplay, ActiveMenu->win); |
850 | XMapWindow(Xdisplay, ActiveMenu->win); |
868 | } |
851 | } |
869 | rxvt_Draw_Shadow(R->Xdisplay, ActiveMenu->win, |
852 | rxvt_Draw_Shadow(Xdisplay, ActiveMenu->win, |
870 | R->h->topShadowGC, R->h->botShadowGC, |
853 | topShadowGC, botShadowGC, |
871 | 0, 0, ActiveMenu->w, ActiveMenu->h); |
854 | 0, 0, ActiveMenu->w, ActiveMenu->h); |
872 | |
855 | |
873 | /* determine the correct right-alignment */ |
856 | /* determine the correct right-alignment */ |
874 | for (xright = 0, item = ActiveMenu->head; item != NULL; item = item->next) |
857 | for (xright = 0, item = ActiveMenu->head; item != NULL; item = item->next) |
875 | if (item->len2 > xright) |
858 | if (item->len2 > xright) |
876 | xright = item->len2; |
859 | xright = item->len2; |
877 | |
860 | |
878 | for (y = 0, item = ActiveMenu->head; item != NULL; item = item->next) { |
861 | for (y = 0, item = ActiveMenu->head; item != NULL; item = item->next) { |
879 | const int xoff = (SHADOW + Width2Pixel(HSPACE) / 2); |
862 | const int xoff = (SHADOW + Width2Pixel(HSPACE) / 2); |
880 | register int h; |
863 | register int h; |
881 | GC gc = R->h->menubarGC; |
864 | GC gc = menubarGC; |
882 | |
865 | |
883 | if (isSeparator(item->name)) { |
866 | if (isSeparator(item->name)) { |
884 | rxvt_Draw_Shadow(R->Xdisplay, ActiveMenu->win, |
867 | rxvt_Draw_Shadow(Xdisplay, ActiveMenu->win, |
885 | R->h->topShadowGC, R->h->botShadowGC, |
868 | topShadowGC, botShadowGC, |
886 | SHADOW, y + SHADOW + 1, |
869 | SHADOW, y + SHADOW + 1, |
887 | ActiveMenu->w - 2 * SHADOW, 0); |
870 | ActiveMenu->w - 2 * SHADOW, 0); |
888 | h = HEIGHT_SEPARATOR; |
871 | h = HEIGHT_SEPARATOR; |
889 | } else { |
872 | } else { |
890 | char *name = item->name; |
873 | char *name = item->name; |
891 | int len = item->len; |
874 | int len = item->len; |
892 | |
875 | |
893 | if (item->entry.type == MenuLabel) { |
876 | if (item->entry.type == MenuLabel) { |
894 | gc = R->h->botShadowGC; |
877 | gc = botShadowGC; |
895 | } else if (item->entry.type == MenuSubMenu) { |
878 | } else if (item->entry.type == MenuSubMenu) { |
896 | int x1, y1; |
879 | int x1, y1; |
897 | menuitem_t *it; |
880 | menuitem_t *it; |
898 | menu_t *menu = item->entry.submenu.menu; |
881 | menu_t *menu = item->entry.submenu.menu; |
899 | |
882 | |
900 | rxvt_drawtriangle(aR_ ActiveMenu->w, y, +1); |
883 | drawtriangle (ActiveMenu->w, y, +1); |
901 | |
884 | |
902 | name = menu->name; |
885 | name = menu->name; |
903 | len = menu->len; |
886 | len = menu->len; |
904 | |
887 | |
905 | y1 = ActiveMenu->y + y; |
888 | y1 = ActiveMenu->y + y; |
… | |
… | |
917 | h += isSeparator(it->name) ? HEIGHT_SEPARATOR |
900 | h += isSeparator(it->name) ? HEIGHT_SEPARATOR |
918 | : HEIGHT_TEXT + 2 * SHADOW; |
901 | : HEIGHT_TEXT + 2 * SHADOW; |
919 | menu->h = h + 2 * SHADOW; |
902 | menu->h = h + 2 * SHADOW; |
920 | |
903 | |
921 | /* ensure menu is in window limits */ |
904 | /* ensure menu is in window limits */ |
922 | if ((x1 + menu->w) >= R->TermWin.width) |
905 | if ((x1 + menu->w) >= TermWin.width) |
923 | x1 = (TermWin_TotalWidth() - menu->w); |
906 | x1 = (TermWin_TotalWidth() - menu->w); |
924 | |
907 | |
925 | if ((y1 + menu->h) >= R->TermWin.height) |
908 | if ((y1 + menu->h) >= TermWin.height) |
926 | y1 = (TermWin_TotalHeight() - menu->h); |
909 | y1 = (TermWin_TotalHeight() - menu->h); |
927 | |
910 | |
928 | menu->x = (x1 < 0 ? 0 : x1); |
911 | menu->x = (x1 < 0 ? 0 : x1); |
929 | menu->y = (y1 < 0 ? 0 : y1); |
912 | menu->y = (y1 < 0 ? 0 : y1); |
930 | } else if (item->name2 && !STRCMP(name, item->name2)) |
913 | } else if (item->name2 && !STRCMP(name, item->name2)) |
931 | name = NULL; |
914 | name = NULL; |
932 | |
915 | |
933 | if (len && name) { |
916 | if (len && name) { |
934 | #ifdef USE_XIM |
917 | #ifdef USE_XIM |
935 | if (R->TermWin.fontset) |
918 | if (TermWin.fontset) |
936 | XmbDrawString(R->Xdisplay, |
919 | XmbDrawString(Xdisplay, |
937 | ActiveMenu->win, R->TermWin.fontset, |
920 | ActiveMenu->win, TermWin.fontset, |
938 | gc, xoff, |
921 | gc, xoff, |
939 | 2 * SHADOW + y + R->TermWin.font->ascent + 1, |
922 | 2 * SHADOW + y + TermWin.font->ascent + 1, |
940 | name, len); |
923 | name, len); |
941 | else |
924 | else |
942 | #endif |
925 | #endif |
943 | XDrawString(R->Xdisplay, ActiveMenu->win, gc, xoff, |
926 | XDrawString(Xdisplay, ActiveMenu->win, gc, xoff, |
944 | 2 * SHADOW + y + R->TermWin.font->ascent + 1, |
927 | 2 * SHADOW + y + TermWin.font->ascent + 1, |
945 | name, len); |
928 | name, len); |
946 | } |
929 | } |
947 | |
930 | |
948 | len = item->len2; |
931 | len = item->len2; |
949 | name = item->name2; |
932 | name = item->name2; |
950 | if (len && name) { |
933 | if (len && name) { |
951 | #ifdef USE_XIM |
934 | #ifdef USE_XIM |
952 | if (R->TermWin.fontset) |
935 | if (TermWin.fontset) |
953 | XmbDrawString(R->Xdisplay, |
936 | XmbDrawString(Xdisplay, |
954 | ActiveMenu->win, R->TermWin.fontset, |
937 | ActiveMenu->win, TermWin.fontset, |
955 | gc, |
938 | gc, |
956 | ActiveMenu->w - (xoff + Width2Pixel(xright)), |
939 | ActiveMenu->w - (xoff + Width2Pixel(xright)), |
957 | 2 * SHADOW + y + R->TermWin.font->ascent + 1, |
940 | 2 * SHADOW + y + TermWin.font->ascent + 1, |
958 | name, len); |
941 | name, len); |
959 | else |
942 | else |
960 | #endif |
943 | #endif |
961 | XDrawString(R->Xdisplay, ActiveMenu->win, gc, |
944 | XDrawString(Xdisplay, ActiveMenu->win, gc, |
962 | ActiveMenu->w - (xoff + Width2Pixel(xright)), |
945 | ActiveMenu->w - (xoff + Width2Pixel(xright)), |
963 | 2 * SHADOW + y + R->TermWin.font->ascent + 1, |
946 | 2 * SHADOW + y + TermWin.font->ascent + 1, |
964 | name, len); |
947 | name, len); |
965 | } |
948 | } |
966 | h = HEIGHT_TEXT + 2 * SHADOW; |
949 | h = HEIGHT_TEXT + 2 * SHADOW; |
967 | } |
950 | } |
968 | y += h; |
951 | y += h; |
969 | } |
952 | } |
970 | } |
953 | } |
971 | |
954 | |
972 | /* INTPROTO */ |
|
|
973 | void |
955 | void |
974 | rxvt_menu_display(pR_ void (*update)(rxvt_t *)) |
956 | rxvt_term::menu_display (void (*update)(rxvt_t *)) |
975 | { |
957 | { |
976 | menu_t *ActiveMenu = R->h->ActiveMenu; |
958 | menu_t *ActiveMenu = ActiveMenu; |
977 | |
959 | |
978 | if (ActiveMenu == NULL) |
960 | if (ActiveMenu == NULL) |
979 | return; |
961 | return; |
980 | if (ActiveMenu->win != None) |
962 | if (ActiveMenu->win != None) |
981 | XDestroyWindow(R->Xdisplay, ActiveMenu->win); |
963 | XDestroyWindow(Xdisplay, ActiveMenu->win); |
982 | ActiveMenu->win = None; |
964 | ActiveMenu->win = None; |
983 | ActiveMenu->item = NULL; |
965 | ActiveMenu->item = NULL; |
984 | |
966 | |
985 | if (ActiveMenu->parent == NULL) |
967 | if (ActiveMenu->parent == NULL) |
986 | rxvt_drawbox_menubar(aR_ ActiveMenu->x, ActiveMenu->len, +1); |
968 | drawbox_menubar (ActiveMenu->x, ActiveMenu->len, +1); |
987 | R->h->ActiveMenu = ActiveMenu->parent; |
969 | ActiveMenu = ActiveMenu->parent; |
988 | update(r); |
970 | update(r); |
989 | } |
971 | } |
990 | |
972 | |
991 | /* INTPROTO */ |
|
|
992 | void |
973 | void |
993 | rxvt_menu_hide_all(pR) |
974 | rxvt_term::menu_hide_all () |
994 | { |
975 | { |
995 | rxvt_menu_display(aR_ rxvt_menu_hide_all); |
976 | menu_display (rxvt_menu_hide_all); |
996 | } |
977 | } |
997 | |
978 | |
998 | /* INTPROTO */ |
|
|
999 | void |
979 | void |
1000 | rxvt_menu_hide(pR) |
980 | rxvt_term::menu_hide () |
1001 | { |
981 | { |
1002 | rxvt_menu_display(aR_ rxvt_menu_show); |
982 | menu_display (rxvt_menu_show); |
1003 | } |
983 | } |
1004 | |
984 | |
1005 | /* INTPROTO */ |
|
|
1006 | void |
985 | void |
1007 | rxvt_menu_clear(pR_ menu_t *menu) |
986 | rxvt_term::menu_clear (menu_t *menu) |
1008 | { |
987 | { |
1009 | if (menu != NULL) { |
988 | if (menu != NULL) { |
1010 | menuitem_t *item = menu->tail; |
989 | menuitem_t *item = menu->tail; |
1011 | |
990 | |
1012 | while (item != NULL) { |
991 | while (item != NULL) { |
1013 | rxvt_menuitem_free(aR_ menu, item); |
992 | menuitem_free (menu, item); |
1014 | /* it didn't get freed ... why? */ |
993 | /* it didn't get freed ... why? */ |
1015 | if (item == menu->tail) |
994 | if (item == menu->tail) |
1016 | return; |
995 | return; |
1017 | item = menu->tail; |
996 | item = menu->tail; |
1018 | } |
997 | } |
1019 | menu->width = 0; |
998 | menu->width = 0; |
1020 | } |
999 | } |
1021 | } |
1000 | } |
1022 | |
1001 | |
1023 | /* INTPROTO */ |
|
|
1024 | void |
1002 | void |
1025 | rxvt_menubar_clear(pR) |
1003 | rxvt_term::menubar_clear () |
1026 | { |
1004 | { |
1027 | bar_t *CurrentBar = R->h->CurrentBar; |
1005 | bar_t *CurrentBar = CurrentBar; |
1028 | |
1006 | |
1029 | if (CurrentBar != NULL) { |
1007 | if (CurrentBar != NULL) { |
1030 | menu_t *menu = CurrentBar->tail; |
1008 | menu_t *menu = CurrentBar->tail; |
1031 | |
1009 | |
1032 | while (menu != NULL) { |
1010 | while (menu != NULL) { |
1033 | menu_t *prev = menu->prev; |
1011 | menu_t *prev = menu->prev; |
1034 | |
1012 | |
1035 | rxvt_menu_delete(aR_ menu); |
1013 | menu_delete (menu); |
1036 | menu = prev; |
1014 | menu = prev; |
1037 | } |
1015 | } |
1038 | CurrentBar->head = CurrentBar->tail = NULL; |
1016 | CurrentBar->head = CurrentBar->tail = NULL; |
1039 | |
1017 | |
1040 | if (CurrentBar->title) { |
1018 | if (CurrentBar->title) { |
1041 | free(CurrentBar->title); |
1019 | free(CurrentBar->title); |
1042 | CurrentBar->title = NULL; |
1020 | CurrentBar->title = NULL; |
1043 | } |
1021 | } |
1044 | rxvt_menuarrow_free(aR_ 0); /* remove all arrow functions */ |
1022 | menuarrow_free (0); /* remove all arrow functions */ |
1045 | } |
1023 | } |
1046 | R->h->ActiveMenu = NULL; |
1024 | ActiveMenu = NULL; |
1047 | } |
1025 | } |
1048 | |
1026 | |
1049 | #if (MENUBAR_MAX > 1) |
1027 | #if (MENUBAR_MAX > 1) |
1050 | /* find if menu already exists */ |
1028 | /* find if menu already exists */ |
1051 | /* INTPROTO */ |
|
|
1052 | bar_t * |
1029 | bar_t * |
1053 | rxvt_menubar_find(pR_ const char *name) |
1030 | rxvt_term::menubar_find (const char *name) |
1054 | { |
1031 | { |
1055 | bar_t *bar = R->h->CurrentBar; |
1032 | bar_t *bar = CurrentBar; |
1056 | |
1033 | |
1057 | #ifdef DEBUG_MENUBAR_STACKING |
1034 | #ifdef DEBUG_MENUBAR_STACKING |
1058 | fprintf(stderr, "looking for [menu:%s] ...", name ? name : "(nil)"); |
1035 | fprintf(stderr, "looking for [menu:%s] ...", name ? name : "(nil)"); |
1059 | #endif |
1036 | #endif |
1060 | if (bar == NULL || name == NULL) |
1037 | if (bar == NULL || name == NULL) |
… | |
… | |
1068 | #endif |
1045 | #endif |
1069 | return bar; |
1046 | return bar; |
1070 | } |
1047 | } |
1071 | bar = bar->next; |
1048 | bar = bar->next; |
1072 | } |
1049 | } |
1073 | while (bar != R->h->CurrentBar); |
1050 | while (bar != CurrentBar); |
1074 | bar = NULL; |
1051 | bar = NULL; |
1075 | } |
1052 | } |
1076 | #ifdef DEBUG_MENUBAR_STACKING |
1053 | #ifdef DEBUG_MENUBAR_STACKING |
1077 | fprintf(stderr, "%s found!\n", (bar ? "" : " NOT")); |
1054 | fprintf(stderr, "%s found!\n", (bar ? "" : " NOT")); |
1078 | #endif |
1055 | #endif |
1079 | |
1056 | |
1080 | return bar; |
1057 | return bar; |
1081 | } |
1058 | } |
1082 | |
1059 | |
1083 | /* INTPROTO */ |
|
|
1084 | int |
1060 | int |
1085 | rxvt_menubar_push(pR_ const char *name) |
1061 | rxvt_term::menubar_push (const char *name) |
1086 | { |
1062 | { |
1087 | int ret = 1; |
1063 | int ret = 1; |
1088 | bar_t *bar; |
1064 | bar_t *bar; |
1089 | |
1065 | |
1090 | if (R->h->CurrentBar == NULL) { |
1066 | if (CurrentBar == NULL) { |
1091 | /* allocate first one */ |
1067 | /* allocate first one */ |
1092 | bar = (bar_t *) rxvt_malloc(sizeof(bar_t)); |
1068 | bar = (bar_t *) rxvt_malloc(sizeof(bar_t)); |
1093 | |
1069 | |
1094 | MEMSET(bar, 0, sizeof(bar_t)); |
1070 | MEMSET(bar, 0, sizeof(bar_t)); |
1095 | /* circular linked-list */ |
1071 | /* circular linked-list */ |
1096 | bar->next = bar->prev = bar; |
1072 | bar->next = bar->prev = bar; |
1097 | bar->head = bar->tail = NULL; |
1073 | bar->head = bar->tail = NULL; |
1098 | bar->title = NULL; |
1074 | bar->title = NULL; |
1099 | R->h->CurrentBar = bar; |
1075 | CurrentBar = bar; |
1100 | R->h->Nbars++; |
1076 | Nbars++; |
1101 | |
1077 | |
1102 | rxvt_menubar_clear(aR); |
1078 | menubar_clear (); |
1103 | } else { |
1079 | } else { |
1104 | /* find if menu already exists */ |
1080 | /* find if menu already exists */ |
1105 | bar = rxvt_menubar_find(aR_ name); |
1081 | bar = menubar_find (name); |
1106 | if (bar != NULL) { |
1082 | if (bar != NULL) { |
1107 | /* found it, use it */ |
1083 | /* found it, use it */ |
1108 | R->h->CurrentBar = bar; |
1084 | CurrentBar = bar; |
1109 | } else { |
1085 | } else { |
1110 | /* create if needed, or reuse the existing empty menubar */ |
1086 | /* create if needed, or reuse the existing empty menubar */ |
1111 | if (R->h->CurrentBar->head != NULL) { |
1087 | if (CurrentBar->head != NULL) { |
1112 | /* need to malloc another one */ |
1088 | /* need to malloc another one */ |
1113 | if (R->h->Nbars < MENUBAR_MAX) |
1089 | if (Nbars < MENUBAR_MAX) |
1114 | bar = (bar_t *) rxvt_malloc(sizeof(bar_t)); |
1090 | bar = (bar_t *) rxvt_malloc(sizeof(bar_t)); |
1115 | else |
1091 | else |
1116 | bar = NULL; |
1092 | bar = NULL; |
1117 | |
1093 | |
1118 | /* malloc failed or too many menubars, reuse another */ |
1094 | /* malloc failed or too many menubars, reuse another */ |
1119 | if (bar == NULL) { |
1095 | if (bar == NULL) { |
1120 | bar = R->h->CurrentBar->next; |
1096 | bar = CurrentBar->next; |
1121 | ret = -1; |
1097 | ret = -1; |
1122 | } else { |
1098 | } else { |
1123 | bar->head = bar->tail = NULL; |
1099 | bar->head = bar->tail = NULL; |
1124 | bar->title = NULL; |
1100 | bar->title = NULL; |
1125 | |
1101 | |
1126 | bar->next = R->h->CurrentBar->next; |
1102 | bar->next = CurrentBar->next; |
1127 | R->h->CurrentBar->next = bar; |
1103 | CurrentBar->next = bar; |
1128 | bar->prev = R->h->CurrentBar; |
1104 | bar->prev = CurrentBar; |
1129 | bar->next->prev = bar; |
1105 | bar->next->prev = bar; |
1130 | |
1106 | |
1131 | R->h->Nbars++; |
1107 | Nbars++; |
1132 | } |
1108 | } |
1133 | R->h->CurrentBar = bar; |
1109 | CurrentBar = bar; |
1134 | |
1110 | |
1135 | } |
1111 | } |
1136 | rxvt_menubar_clear(aR); |
1112 | menubar_clear (); |
1137 | } |
1113 | } |
1138 | } |
1114 | } |
1139 | |
1115 | |
1140 | /* give menubar this name */ |
1116 | /* give menubar this name */ |
1141 | STRNCPY(R->h->CurrentBar->name, name, MAXNAME); |
1117 | STRNCPY(CurrentBar->name, name, MAXNAME); |
1142 | R->h->CurrentBar->name[MAXNAME - 1] = '\0'; |
1118 | CurrentBar->name[MAXNAME - 1] = '\0'; |
1143 | |
1119 | |
1144 | return ret; |
1120 | return ret; |
1145 | } |
1121 | } |
1146 | |
1122 | |
1147 | /* switch to a menu called NAME and remove it */ |
1123 | /* switch to a menu called NAME and remove it */ |
1148 | /* INTPROTO */ |
|
|
1149 | void |
1124 | void |
1150 | rxvt_menubar_remove(pR_ const char *name) |
1125 | rxvt_term::menubar_remove (const char *name) |
1151 | { |
1126 | { |
1152 | bar_t *bar; |
1127 | bar_t *bar; |
1153 | |
1128 | |
1154 | if ((bar = rxvt_menubar_find(aR_ name)) == NULL) |
1129 | if ((bar = menubar_find (name)) == NULL) |
1155 | return; |
1130 | return; |
1156 | R->h->CurrentBar = bar; |
1131 | CurrentBar = bar; |
1157 | |
1132 | |
1158 | do { |
1133 | do { |
1159 | rxvt_menubar_clear(aR); |
1134 | menubar_clear (); |
1160 | /* |
1135 | /* |
1161 | * pop a menubar, clean it up first |
1136 | * pop a menubar, clean it up first |
1162 | */ |
1137 | */ |
1163 | if (R->h->CurrentBar != NULL) { |
1138 | if (CurrentBar != NULL) { |
1164 | bar_t *prev = R->h->CurrentBar->prev; |
1139 | bar_t *prev = CurrentBar->prev; |
1165 | bar_t *next = R->h->CurrentBar->next; |
1140 | bar_t *next = CurrentBar->next; |
1166 | |
1141 | |
1167 | if (prev == next && prev == R->h->CurrentBar) { /* only 1 left */ |
1142 | if (prev == next && prev == CurrentBar) { /* only 1 left */ |
1168 | prev = NULL; |
1143 | prev = NULL; |
1169 | R->h->Nbars = 0; /* safety */ |
1144 | Nbars = 0; /* safety */ |
1170 | } else { |
1145 | } else { |
1171 | next->prev = prev; |
1146 | next->prev = prev; |
1172 | prev->next = next; |
1147 | prev->next = next; |
1173 | R->h->Nbars--; |
1148 | Nbars--; |
1174 | } |
|
|
1175 | |
|
|
1176 | free(R->h->CurrentBar); |
|
|
1177 | R->h->CurrentBar = prev; |
|
|
1178 | } |
|
|
1179 | } |
1149 | } |
|
|
1150 | |
|
|
1151 | free(CurrentBar); |
|
|
1152 | CurrentBar = prev; |
|
|
1153 | } |
|
|
1154 | } |
1180 | while (R->h->CurrentBar && !STRCMP(name, "*")); |
1155 | while (CurrentBar && !STRCMP(name, "*")); |
1181 | } |
1156 | } |
1182 | |
1157 | |
1183 | /* INTPROTO */ |
|
|
1184 | void |
1158 | void |
1185 | rxvt_action_decode(FILE *fp, action_t *act) |
1159 | rxvt_action_decode(FILE *fp, action_t *act) |
1186 | { |
1160 | { |
1187 | unsigned char *str; |
1161 | unsigned char *str; |
1188 | short len; |
1162 | short len; |
… | |
… | |
1250 | len--; |
1224 | len--; |
1251 | } |
1225 | } |
1252 | fprintf(fp, "\n"); |
1226 | fprintf(fp, "\n"); |
1253 | } |
1227 | } |
1254 | |
1228 | |
1255 | /* INTPROTO */ |
|
|
1256 | void |
1229 | void |
1257 | rxvt_menu_dump(FILE *fp, menu_t *menu) |
1230 | rxvt_menu_dump(FILE *fp, menu_t *menu) |
1258 | { |
1231 | { |
1259 | menuitem_t *item; |
1232 | menuitem_t *item; |
1260 | |
1233 | |
… | |
… | |
1286 | } |
1259 | } |
1287 | |
1260 | |
1288 | fprintf(fp, (menu->parent ? "../\n" : "/\n\n")); |
1261 | fprintf(fp, (menu->parent ? "../\n" : "/\n\n")); |
1289 | } |
1262 | } |
1290 | |
1263 | |
1291 | /* INTPROTO */ |
|
|
1292 | void |
1264 | void |
1293 | rxvt_menubar_dump(pR_ FILE *fp) |
1265 | rxvt_term::menubar_dump (FILE *fp) |
1294 | { |
1266 | { |
1295 | bar_t *bar = R->h->CurrentBar; |
1267 | bar_t *bar = CurrentBar; |
1296 | time_t t; |
1268 | time_t t; |
1297 | |
1269 | |
1298 | if (bar == NULL || fp == NULL) |
1270 | if (bar == NULL || fp == NULL) |
1299 | return; |
1271 | return; |
1300 | time(&t); |
1272 | time(&t); |
1301 | |
1273 | |
1302 | fprintf(fp, |
1274 | fprintf(fp, |
1303 | "# " APL_SUBCLASS " (%s) Pid: %u\n# Date: %s\n\n", |
1275 | "# " APL_SUBCLASS " (%s) Pid: %u\n# Date: %s\n\n", |
1304 | R->h->rs[Rs_name], (unsigned int)getpid(), ctime(&t)); |
1276 | rs[Rs_name], (unsigned int)getpid(), ctime(&t)); |
1305 | |
1277 | |
1306 | /* dump in reverse order */ |
1278 | /* dump in reverse order */ |
1307 | bar = R->h->CurrentBar->prev; |
1279 | bar = CurrentBar->prev; |
1308 | do { |
1280 | do { |
1309 | menu_t *menu; |
1281 | menu_t *menu; |
1310 | int i; |
1282 | int i; |
1311 | |
1283 | |
1312 | fprintf(fp, "[menu:%s]\n", bar->name); |
1284 | fprintf(fp, "[menu:%s]\n", bar->name); |
… | |
… | |
1329 | rxvt_menu_dump(fp, menu); |
1301 | rxvt_menu_dump(fp, menu); |
1330 | |
1302 | |
1331 | fprintf(fp, "\n[done:%s]\n\n", bar->name); |
1303 | fprintf(fp, "\n[done:%s]\n\n", bar->name); |
1332 | bar = bar->prev; |
1304 | bar = bar->prev; |
1333 | } |
1305 | } |
1334 | while (bar != R->h->CurrentBar->prev); |
1306 | while (bar != CurrentBar->prev); |
1335 | } |
1307 | } |
1336 | #endif /* (MENUBAR_MAX > 1) */ |
1308 | #endif /* (MENUBAR_MAX > 1) */ |
1337 | |
1309 | |
1338 | /* |
1310 | /* |
1339 | * read in menubar commands from FILENAME |
1311 | * read in menubar commands from FILENAME |
… | |
… | |
1348 | * read `file' starting with first [menu] or [menu:???] line |
1320 | * read `file' starting with first [menu] or [menu:???] line |
1349 | * |
1321 | * |
1350 | * FILENAME = "file;tag" |
1322 | * FILENAME = "file;tag" |
1351 | * read `file' starting with [menu:tag] |
1323 | * read `file' starting with [menu:tag] |
1352 | */ |
1324 | */ |
1353 | /* EXTPROTO */ |
|
|
1354 | void |
1325 | void |
1355 | rxvt_menubar_read(pR_ const char *filename) |
1326 | rxvt_term::menubar_read (const char *filename) |
1356 | { |
1327 | { |
1357 | /* read in a menu from a file */ |
1328 | /* read in a menu from a file */ |
1358 | FILE *fp; |
1329 | FILE *fp; |
1359 | char buffer[256]; |
1330 | char buffer[256]; |
1360 | char *p, *file, *tag = NULL; |
1331 | char *p, *file, *tag = NULL; |
1361 | |
1332 | |
1362 | file = (char *)rxvt_File_find(filename, ".menu", R->h->rs[Rs_path]); |
1333 | file = (char *)rxvt_File_find(filename, ".menu", rs[Rs_path]); |
1363 | if (file == NULL) |
1334 | if (file == NULL) |
1364 | return; |
1335 | return; |
1365 | fp = fopen(file, "rb"); |
1336 | fp = fopen(file, "rb"); |
1366 | free(file); |
1337 | free(file); |
1367 | if (fp == NULL) |
1338 | if (fp == NULL) |
… | |
… | |
1411 | #endif |
1382 | #endif |
1412 | |
1383 | |
1413 | /* looking for [done:tag] or [done:] */ |
1384 | /* looking for [done:tag] or [done:] */ |
1414 | if ((n = rxvt_Str_match(p, "[done")) != 0) { |
1385 | if ((n = rxvt_Str_match(p, "[done")) != 0) { |
1415 | if (p[n] == ']') { |
1386 | if (p[n] == ']') { |
1416 | R->h->menu_readonly = 1; |
1387 | menu_readonly = 1; |
1417 | break; |
1388 | break; |
1418 | } else if (p[n] == ':') { |
1389 | } else if (p[n] == ':') { |
1419 | n++; |
1390 | n++; |
1420 | if (p[n] == ']') { |
1391 | if (p[n] == ']') { |
1421 | R->h->menu_readonly = 1; |
1392 | menu_readonly = 1; |
1422 | break; |
1393 | break; |
1423 | } else if (tag) { |
1394 | } else if (tag) { |
1424 | n += rxvt_Str_match(p + n, tag); |
1395 | n += rxvt_Str_match(p + n, tag); |
1425 | if (p[n] == ']') { |
1396 | if (p[n] == ']') { |
1426 | #ifdef DEBUG_MENU |
1397 | #ifdef DEBUG_MENU |
1427 | fprintf(stderr, "[done:%s]\n", tag); |
1398 | fprintf(stderr, "[done:%s]\n", tag); |
1428 | #endif |
1399 | #endif |
1429 | R->h->menu_readonly = 1; |
1400 | menu_readonly = 1; |
1430 | break; |
1401 | break; |
1431 | } |
1402 | } |
1432 | } else { |
1403 | } else { |
1433 | /* what? ... skip this line */ |
1404 | /* what? ... skip this line */ |
1434 | p[0] = COMMENT_CHAR; |
1405 | p[0] = COMMENT_CHAR; |
… | |
… | |
1440 | * and strip-off leading/trailing quotes |
1411 | * and strip-off leading/trailing quotes |
1441 | * skip blank or comment lines |
1412 | * skip blank or comment lines |
1442 | */ |
1413 | */ |
1443 | rxvt_Str_trim(p); |
1414 | rxvt_Str_trim(p); |
1444 | if (*p && *p != '#') { |
1415 | if (*p && *p != '#') { |
1445 | R->h->menu_readonly = 0; /* if case we read another file */ |
1416 | menu_readonly = 0; /* if case we read another file */ |
1446 | rxvt_menubar_dispatch(aR_ p); |
1417 | menubar_dispatch (p); |
1447 | } |
1418 | } |
1448 | /* get another line */ |
1419 | /* get another line */ |
1449 | p = fgets(buffer, sizeof(buffer), fp); |
1420 | p = fgets(buffer, sizeof(buffer), fp); |
1450 | } |
1421 | } |
1451 | |
1422 | |
… | |
… | |
1453 | } |
1424 | } |
1454 | |
1425 | |
1455 | /* |
1426 | /* |
1456 | * user interface for building/deleting and otherwise managing menus |
1427 | * user interface for building/deleting and otherwise managing menus |
1457 | */ |
1428 | */ |
1458 | /* EXTPROTO */ |
|
|
1459 | void |
1429 | void |
1460 | rxvt_menubar_dispatch(pR_ char *str) |
1430 | rxvt_term::menubar_dispatch (char *str) |
1461 | { |
1431 | { |
1462 | int n, cmd; |
1432 | int n, cmd; |
1463 | char *path, *name, *name2; |
1433 | char *path, *name, *name2; |
1464 | |
1434 | |
1465 | if (menubar_visible(r) && R->h->ActiveMenu != NULL) |
1435 | if (menubar_visible(r) && ActiveMenu != NULL) |
1466 | rxvt_menubar_expose(aR); |
1436 | menubar_expose (); |
1467 | else |
1437 | else |
1468 | R->h->ActiveMenu = NULL; |
1438 | ActiveMenu = NULL; |
1469 | |
1439 | |
1470 | cmd = *str; |
1440 | cmd = *str; |
1471 | switch (cmd) { |
1441 | switch (cmd) { |
1472 | case '.': |
1442 | case '.': |
1473 | case '/': /* absolute & relative path */ |
1443 | case '/': /* absolute & relative path */ |
… | |
… | |
1481 | str++; /* skip cmd character */ |
1451 | str++; /* skip cmd character */ |
1482 | break; |
1452 | break; |
1483 | |
1453 | |
1484 | case '<': |
1454 | case '<': |
1485 | #if (MENUBAR_MAX > 1) |
1455 | #if (MENUBAR_MAX > 1) |
1486 | if (R->h->CurrentBar == NULL) |
1456 | if (CurrentBar == NULL) |
1487 | break; |
1457 | break; |
1488 | #endif /* (MENUBAR_MAX > 1) */ |
1458 | #endif /* (MENUBAR_MAX > 1) */ |
1489 | if (str[1] && str[2] == '>') /* arrow commands */ |
1459 | if (str[1] && str[2] == '>') /* arrow commands */ |
1490 | rxvt_menuarrow_add(aR_ str); |
1460 | menuarrow_add (str); |
1491 | break; |
1461 | break; |
1492 | |
1462 | |
1493 | case '[': /* extended command */ |
1463 | case '[': /* extended command */ |
1494 | while (str[0] == '[') { |
1464 | while (str[0] == '[') { |
1495 | char *next = (++str); /* skip leading '[' */ |
1465 | char *next = (++str); /* skip leading '[' */ |
… | |
… | |
1514 | |
1484 | |
1515 | if (str[0] == ':') { |
1485 | if (str[0] == ':') { |
1516 | int saved; |
1486 | int saved; |
1517 | |
1487 | |
1518 | /* try and dispatch it, regardless of read/write status */ |
1488 | /* try and dispatch it, regardless of read/write status */ |
1519 | saved = R->h->menu_readonly; |
1489 | saved = menu_readonly; |
1520 | R->h->menu_readonly = 0; |
1490 | menu_readonly = 0; |
1521 | rxvt_menubar_dispatch(aR_ str + 1); |
1491 | menubar_dispatch (str + 1); |
1522 | R->h->menu_readonly = saved; |
1492 | menu_readonly = saved; |
1523 | } |
1493 | } |
1524 | /* these ones don't require menu stacking */ |
1494 | /* these ones don't require menu stacking */ |
1525 | else if (!STRCMP(str, "clear")) { |
1495 | else if (!STRCMP(str, "clear")) { |
1526 | rxvt_menubar_clear(aR); |
1496 | menubar_clear (); |
1527 | } else if (!STRCMP(str, "done") || rxvt_Str_match(str, "done:")) { |
1497 | } else if (!STRCMP(str, "done") || rxvt_Str_match(str, "done:")) { |
1528 | R->h->menu_readonly = 1; |
1498 | menu_readonly = 1; |
1529 | } else if (!STRCMP(str, "show")) { |
1499 | } else if (!STRCMP(str, "show")) { |
1530 | rxvt_map_menuBar(aR_ 1); |
1500 | map_menuBar (1); |
1531 | R->h->menu_readonly = 1; |
1501 | menu_readonly = 1; |
1532 | } else if (!STRCMP(str, "hide")) { |
1502 | } else if (!STRCMP(str, "hide")) { |
1533 | rxvt_map_menuBar(aR_ 0); |
1503 | map_menuBar (0); |
1534 | R->h->menu_readonly = 1; |
1504 | menu_readonly = 1; |
1535 | } else if ((n = rxvt_Str_match(str, "read:")) != 0) { |
1505 | } else if ((n = rxvt_Str_match(str, "read:")) != 0) { |
1536 | /* read in a menu from a file */ |
1506 | /* read in a menu from a file */ |
1537 | str += n; |
1507 | str += n; |
1538 | rxvt_menubar_read(aR_ str); |
1508 | menubar_read (str); |
1539 | } else if ((n = rxvt_Str_match(str, "title:")) != 0) { |
1509 | } else if ((n = rxvt_Str_match(str, "title:")) != 0) { |
1540 | str += n; |
1510 | str += n; |
1541 | if (R->h->CurrentBar != NULL && !R->h->menu_readonly) { |
1511 | if (CurrentBar != NULL && !menu_readonly) { |
1542 | if (*str) { |
1512 | if (*str) { |
1543 | name = rxvt_realloc(R->h->CurrentBar->title, |
1513 | name = rxvt_realloc(CurrentBar->title, |
1544 | STRLEN(str) + 1); |
1514 | STRLEN(str) + 1); |
1545 | if (name != NULL) { |
1515 | if (name != NULL) { |
1546 | STRCPY(name, str); |
1516 | STRCPY(name, str); |
1547 | R->h->CurrentBar->title = name; |
1517 | CurrentBar->title = name; |
1548 | } |
1518 | } |
1549 | rxvt_menubar_expose(aR); |
1519 | menubar_expose (); |
1550 | } else { |
1520 | } else { |
1551 | free(R->h->CurrentBar->title); |
1521 | free(CurrentBar->title); |
1552 | R->h->CurrentBar->title = NULL; |
1522 | CurrentBar->title = NULL; |
1553 | } |
1523 | } |
1554 | } |
1524 | } |
1555 | } else if ((n = rxvt_Str_match(str, "pixmap:")) != 0) { |
1525 | } else if ((n = rxvt_Str_match(str, "pixmap:")) != 0) { |
1556 | str += n; |
1526 | str += n; |
1557 | rxvt_xterm_seq(aR_ XTerm_Pixmap, str, CHAR_ST); |
1527 | xterm_seq (XTerm_Pixmap, str, CHAR_ST); |
1558 | } |
1528 | } |
1559 | #if (MENUBAR_MAX > 1) |
1529 | #if (MENUBAR_MAX > 1) |
1560 | else if ((n = rxvt_Str_match(str, "rm")) != 0) { |
1530 | else if ((n = rxvt_Str_match(str, "rm")) != 0) { |
1561 | str += n; |
1531 | str += n; |
1562 | switch (str[0]) { |
1532 | switch (str[0]) { |
… | |
… | |
1564 | str++; |
1534 | str++; |
1565 | /* FALLTHROUGH */ |
1535 | /* FALLTHROUGH */ |
1566 | case '\0': |
1536 | case '\0': |
1567 | /* FALLTHROUGH */ |
1537 | /* FALLTHROUGH */ |
1568 | case '*': |
1538 | case '*': |
1569 | rxvt_menubar_remove(aR_ str); |
1539 | menubar_remove (str); |
1570 | break; |
1540 | break; |
1571 | } |
1541 | } |
1572 | R->h->menu_readonly = 1; |
1542 | menu_readonly = 1; |
1573 | } else if ((n = rxvt_Str_match(str, "menu")) != 0) { |
1543 | } else if ((n = rxvt_Str_match(str, "menu")) != 0) { |
1574 | str += n; |
1544 | str += n; |
1575 | switch (str[0]) { |
1545 | switch (str[0]) { |
1576 | case ':': |
1546 | case ':': |
1577 | str++; |
1547 | str++; |
1578 | /* add/access menuBar */ |
1548 | /* add/access menuBar */ |
1579 | if (*str != '\0' && *str != '*') |
1549 | if (*str != '\0' && *str != '*') |
1580 | rxvt_menubar_push(aR_ str); |
1550 | menubar_push (str); |
1581 | break; |
1551 | break; |
1582 | default: |
1552 | default: |
1583 | if (R->h->CurrentBar == NULL) { |
1553 | if (CurrentBar == NULL) { |
1584 | rxvt_menubar_push(aR_ "default"); |
1554 | menubar_push ("default"); |
1585 | } |
1555 | } |
1586 | } |
1556 | } |
1587 | |
1557 | |
1588 | if (R->h->CurrentBar != NULL) |
1558 | if (CurrentBar != NULL) |
1589 | R->h->menu_readonly = 0; /* allow menu build commands */ |
1559 | menu_readonly = 0; /* allow menu build commands */ |
1590 | } else if (!STRCMP(str, "dump")) { |
1560 | } else if (!STRCMP(str, "dump")) { |
1591 | /* dump current menubars to a file */ |
1561 | /* dump current menubars to a file */ |
1592 | FILE *fp; |
1562 | FILE *fp; |
1593 | |
1563 | |
1594 | /* enough space to hold the results */ |
1564 | /* enough space to hold the results */ |
… | |
… | |
1596 | |
1566 | |
1597 | sprintf(buffer, "/tmp/" APL_SUBCLASS "-%u", |
1567 | sprintf(buffer, "/tmp/" APL_SUBCLASS "-%u", |
1598 | (unsigned int)getpid()); |
1568 | (unsigned int)getpid()); |
1599 | |
1569 | |
1600 | if ((fp = fopen(buffer, "wb")) != NULL) { |
1570 | if ((fp = fopen(buffer, "wb")) != NULL) { |
1601 | rxvt_xterm_seq(aR_ XTerm_title, buffer, CHAR_ST); |
1571 | xterm_seq (XTerm_title, buffer, CHAR_ST); |
1602 | rxvt_menubar_dump(aR_ fp); |
1572 | menubar_dump (fp); |
1603 | fclose(fp); |
1573 | fclose(fp); |
1604 | } |
1574 | } |
1605 | } else if (!STRCMP(str, "next")) { |
1575 | } else if (!STRCMP(str, "next")) { |
1606 | if (R->h->CurrentBar) { |
1576 | if (CurrentBar) { |
1607 | R->h->CurrentBar = R->h->CurrentBar->next; |
1577 | CurrentBar = CurrentBar->next; |
1608 | R->h->menu_readonly = 1; |
1578 | menu_readonly = 1; |
1609 | } |
1579 | } |
1610 | } else if (!STRCMP(str, "prev")) { |
1580 | } else if (!STRCMP(str, "prev")) { |
1611 | if (R->h->CurrentBar) { |
1581 | if (CurrentBar) { |
1612 | R->h->CurrentBar = R->h->CurrentBar->prev; |
1582 | CurrentBar = CurrentBar->prev; |
1613 | R->h->menu_readonly = 1; |
1583 | menu_readonly = 1; |
1614 | } |
1584 | } |
1615 | } else if (!STRCMP(str, "swap")) { |
1585 | } else if (!STRCMP(str, "swap")) { |
1616 | /* swap the top 2 menus */ |
1586 | /* swap the top 2 menus */ |
1617 | if (R->h->CurrentBar) { |
1587 | if (CurrentBar) { |
1618 | bar_t *cbprev = R->h->CurrentBar->prev; |
1588 | bar_t *cbprev = CurrentBar->prev; |
1619 | bar_t *cbnext = R->h->CurrentBar->next; |
1589 | bar_t *cbnext = CurrentBar->next; |
1620 | |
1590 | |
1621 | cbprev->next = cbnext; |
1591 | cbprev->next = cbnext; |
1622 | cbnext->prev = cbprev; |
1592 | cbnext->prev = cbprev; |
1623 | |
1593 | |
1624 | R->h->CurrentBar->next = cbprev; |
1594 | CurrentBar->next = cbprev; |
1625 | R->h->CurrentBar->prev = cbprev->prev; |
1595 | CurrentBar->prev = cbprev->prev; |
1626 | |
1596 | |
1627 | cbprev->prev->next = R->h->CurrentBar; |
1597 | cbprev->prev->next = CurrentBar; |
1628 | cbprev->prev = R->h->CurrentBar; |
1598 | cbprev->prev = CurrentBar; |
1629 | |
1599 | |
1630 | R->h->CurrentBar = cbprev; |
1600 | CurrentBar = cbprev; |
1631 | R->h->menu_readonly = 1; |
1601 | menu_readonly = 1; |
1632 | } |
1602 | } |
1633 | } |
1603 | } |
1634 | #endif /* (MENUBAR_MAX > 1) */ |
1604 | #endif /* (MENUBAR_MAX > 1) */ |
1635 | str = next; |
1605 | str = next; |
1636 | |
1606 | |
1637 | R->h->BuildMenu = R->h->ActiveMenu = NULL; |
1607 | BuildMenu = ActiveMenu = NULL; |
1638 | rxvt_menubar_expose(aR); |
1608 | menubar_expose (); |
1639 | #ifdef DEBUG_MENUBAR_STACKING |
1609 | #ifdef DEBUG_MENUBAR_STACKING |
1640 | fprintf(stderr, "menus are read%s\n", |
1610 | fprintf(stderr, "menus are read%s\n", |
1641 | R->h->menu_readonly ? "only" : "/write"); |
1611 | menu_readonly ? "only" : "/write"); |
1642 | #endif |
1612 | #endif |
1643 | } |
1613 | } |
1644 | return; |
1614 | return; |
1645 | break; |
1615 | break; |
1646 | } |
1616 | } |
1647 | |
1617 | |
1648 | #if (MENUBAR_MAX > 1) |
1618 | #if (MENUBAR_MAX > 1) |
1649 | if (R->h->CurrentBar == NULL) |
1619 | if (CurrentBar == NULL) |
1650 | return; |
1620 | return; |
1651 | if (R->h->menu_readonly) { |
1621 | if (menu_readonly) { |
1652 | #ifdef DEBUG_MENUBAR_STACKING |
1622 | #ifdef DEBUG_MENUBAR_STACKING |
1653 | fprintf(stderr, "menus are read%s\n", |
1623 | fprintf(stderr, "menus are read%s\n", |
1654 | R->h->menu_readonly ? "only" : "/write"); |
1624 | menu_readonly ? "only" : "/write"); |
1655 | #endif |
1625 | #endif |
1656 | return; |
1626 | return; |
1657 | } |
1627 | } |
1658 | #endif /* (MENUBAR_MAX > 1) */ |
1628 | #endif /* (MENUBAR_MAX > 1) */ |
1659 | |
1629 | |
… | |
… | |
1704 | switch (cmd) { |
1674 | switch (cmd) { |
1705 | case '+': /* add/replace existing menu or menuitem */ |
1675 | case '+': /* add/replace existing menu or menuitem */ |
1706 | if (path[0] != '\0') { |
1676 | if (path[0] != '\0') { |
1707 | int len; |
1677 | int len; |
1708 | |
1678 | |
1709 | path = rxvt_menu_find_base(aR_ &(R->h->BuildMenu), path); |
1679 | path = menu_find_base (&(BuildMenu), path); |
1710 | len = STRLEN(path); |
1680 | len = STRLEN(path); |
1711 | |
1681 | |
1712 | /* don't allow menus called `*' */ |
1682 | /* don't allow menus called `*' */ |
1713 | if (path[0] == '*') { |
1683 | if (path[0] == '*') { |
1714 | rxvt_menu_clear(aR_ R->h->BuildMenu); |
1684 | menu_clear (BuildMenu); |
1715 | break; |
1685 | break; |
1716 | } else if (len >= 2 && !STRCMP((path + len - 2), "/*")) { |
1686 | } else if (len >= 2 && !STRCMP((path + len - 2), "/*")) { |
1717 | path[len - 2] = '\0'; |
1687 | path[len - 2] = '\0'; |
1718 | } |
1688 | } |
1719 | if (path[0] != '\0') |
1689 | if (path[0] != '\0') |
1720 | R->h->BuildMenu = rxvt_menu_add(aR_ R->h->BuildMenu, path); |
1690 | BuildMenu = menu_add (BuildMenu, path); |
1721 | } |
1691 | } |
1722 | if (name != NULL && name[0] != '\0') |
1692 | if (name != NULL && name[0] != '\0') |
1723 | rxvt_menuitem_add(R->h->BuildMenu, |
1693 | rxvt_menuitem_add(BuildMenu, |
1724 | (STRCMP(name, SEPARATOR_NAME) ? name : ""), |
1694 | (STRCMP(name, SEPARATOR_NAME) ? name : ""), |
1725 | name2, str); |
1695 | name2, str); |
1726 | break; |
1696 | break; |
1727 | |
1697 | |
1728 | case '-': /* delete menu entry */ |
1698 | case '-': /* delete menu entry */ |
1729 | if (!STRCMP(path, "/*") && (name == NULL || name[0] == '\0')) { |
1699 | if (!STRCMP(path, "/*") && (name == NULL || name[0] == '\0')) { |
1730 | rxvt_menubar_clear(aR); |
1700 | menubar_clear (); |
1731 | R->h->BuildMenu = NULL; |
1701 | BuildMenu = NULL; |
1732 | rxvt_menubar_expose(aR); |
1702 | menubar_expose (); |
1733 | break; |
1703 | break; |
1734 | } else if (path[0] != '\0') { |
1704 | } else if (path[0] != '\0') { |
1735 | int len; |
1705 | int len; |
1736 | menu_t *menu = R->h->BuildMenu; |
1706 | menu_t *menu = BuildMenu; |
1737 | |
1707 | |
1738 | path = rxvt_menu_find_base(aR_ &menu, path); |
1708 | path = menu_find_base (&menu, path); |
1739 | len = STRLEN(path); |
1709 | len = STRLEN(path); |
1740 | |
1710 | |
1741 | /* submenu called `*' clears all menu items */ |
1711 | /* submenu called `*' clears all menu items */ |
1742 | if (path[0] == '*') { |
1712 | if (path[0] == '*') { |
1743 | rxvt_menu_clear(aR_ menu); |
1713 | menu_clear (menu); |
1744 | break; /* done */ |
1714 | break; /* done */ |
1745 | } else if (len >= 2 && !STRCMP(&path[len - 2], "/*")) { |
1715 | } else if (len >= 2 && !STRCMP(&path[len - 2], "/*")) { |
1746 | /* done */ |
1716 | /* done */ |
1747 | break; |
1717 | break; |
1748 | } else if (path[0] != '\0') { |
1718 | } else if (path[0] != '\0') { |
1749 | R->h->BuildMenu = NULL; |
1719 | BuildMenu = NULL; |
1750 | break; |
1720 | break; |
1751 | } else |
1721 | } else |
1752 | R->h->BuildMenu = menu; |
1722 | BuildMenu = menu; |
1753 | } |
1723 | } |
1754 | if (R->h->BuildMenu != NULL) { |
1724 | if (BuildMenu != NULL) { |
1755 | if (name == NULL || name[0] == '\0') |
1725 | if (name == NULL || name[0] == '\0') |
1756 | R->h->BuildMenu = rxvt_menu_delete(aR_ R->h->BuildMenu); |
1726 | BuildMenu = menu_delete (BuildMenu); |
1757 | else { |
1727 | else { |
1758 | const char *n1; |
1728 | const char *n1; |
1759 | menuitem_t *item; |
1729 | menuitem_t *item; |
1760 | menu_t *BuildMenu = R->h->BuildMenu; |
1730 | menu_t *BuildMenu = BuildMenu; |
1761 | |
1731 | |
1762 | n1 = STRCMP(name, SEPARATOR_NAME) ? name : ""; |
1732 | n1 = STRCMP(name, SEPARATOR_NAME) ? name : ""; |
1763 | item = rxvt_menuitem_find(BuildMenu, n1); |
1733 | item = rxvt_menuitem_find(BuildMenu, n1); |
1764 | if (item != NULL && item->entry.type != MenuSubMenu) { |
1734 | if (item != NULL && item->entry.type != MenuSubMenu) { |
1765 | rxvt_menuitem_free(aR_ BuildMenu, item); |
1735 | menuitem_free (BuildMenu, item); |
1766 | |
1736 | |
1767 | /* fix up the width */ |
1737 | /* fix up the width */ |
1768 | BuildMenu->width = 0; |
1738 | BuildMenu->width = 0; |
1769 | for (item = BuildMenu->head; item != NULL; |
1739 | for (item = BuildMenu->head; item != NULL; |
1770 | item = item->next) { |
1740 | item = item->next) { |
… | |
… | |
1772 | |
1742 | |
1773 | MAX_IT(BuildMenu->width, l); |
1743 | MAX_IT(BuildMenu->width, l); |
1774 | } |
1744 | } |
1775 | } |
1745 | } |
1776 | } |
1746 | } |
1777 | rxvt_menubar_expose(aR); |
1747 | menubar_expose (); |
1778 | } |
1748 | } |
1779 | break; |
1749 | break; |
1780 | } |
1750 | } |
1781 | break; |
1751 | break; |
1782 | } |
1752 | } |
1783 | } |
1753 | } |
1784 | |
1754 | |
1785 | /* INTPROTO */ |
|
|
1786 | void |
1755 | void |
1787 | rxvt_draw_Arrows(pR_ int name, int state) |
1756 | rxvt_term::draw_Arrows (int name, int state) |
1788 | { |
1757 | { |
1789 | GC top, bot; |
1758 | GC top, bot; |
1790 | |
1759 | |
1791 | int i; |
1760 | int i; |
1792 | |
1761 | |
1793 | #ifdef MENU_SHADOW_IN |
1762 | #ifdef MENU_SHADOW_IN |
1794 | state = -state; |
1763 | state = -state; |
1795 | #endif |
1764 | #endif |
1796 | switch (state) { |
1765 | switch (state) { |
1797 | case +1: |
1766 | case +1: |
1798 | top = R->h->topShadowGC; |
1767 | top = topShadowGC; |
1799 | bot = R->h->botShadowGC; |
1768 | bot = botShadowGC; |
1800 | break; /* SHADOW_OUT */ |
1769 | break; /* SHADOW_OUT */ |
1801 | case -1: |
1770 | case -1: |
1802 | top = R->h->botShadowGC; |
1771 | top = botShadowGC; |
1803 | bot = R->h->topShadowGC; |
1772 | bot = topShadowGC; |
1804 | break; /* SHADOW_IN */ |
1773 | break; /* SHADOW_IN */ |
1805 | default: |
1774 | default: |
1806 | top = bot = R->h->scrollbarGC; |
1775 | top = bot = scrollbarGC; |
1807 | break; /* neutral */ |
1776 | break; /* neutral */ |
1808 | } |
1777 | } |
1809 | |
1778 | |
1810 | if (!R->h->Arrows_x) |
1779 | if (!Arrows_x) |
1811 | return; |
1780 | return; |
1812 | |
1781 | |
1813 | for (i = 0; i < NARROWS; i++) { |
1782 | for (i = 0; i < NARROWS; i++) { |
1814 | const int w = Width2Pixel(1); |
1783 | const int w = Width2Pixel(1); |
1815 | const int y = (menuBar_TotalHeight() - w) / 2; |
1784 | const int y = (menuBar_TotalHeight() - w) / 2; |
1816 | int x = R->h->Arrows_x + (5 * Width2Pixel(i)) / 4; |
1785 | int x = Arrows_x + (5 * Width2Pixel(i)) / 4; |
1817 | |
1786 | |
1818 | if (!name || name == Arrows[i].name) |
1787 | if (!name || name == Arrows[i].name) |
1819 | rxvt_Draw_Triangle(R->Xdisplay, R->menuBar.win, top, bot, x, y, w, |
1788 | rxvt_Draw_Triangle(Xdisplay, menuBar.win, top, bot, x, y, w, |
1820 | Arrows[i].name); |
1789 | Arrows[i].name); |
1821 | } |
1790 | } |
1822 | XFlush(R->Xdisplay); |
1791 | XFlush(Xdisplay); |
1823 | } |
1792 | } |
1824 | |
1793 | |
1825 | /* EXTPROTO */ |
|
|
1826 | void |
1794 | void |
1827 | rxvt_menubar_expose(pR) |
1795 | rxvt_term::menubar_expose () |
1828 | { |
1796 | { |
1829 | menu_t *menu; |
1797 | menu_t *menu; |
1830 | int x; |
1798 | int x; |
1831 | |
1799 | |
1832 | if (!menubar_visible(r) || R->menuBar.win == 0) |
1800 | if (!menubar_visible(r) || menuBar.win == 0) |
1833 | return; |
1801 | return; |
1834 | |
1802 | |
1835 | if (R->h->menubarGC == None) { |
1803 | if (menubarGC == None) { |
1836 | /* Create the graphics context */ |
1804 | /* Create the graphics context */ |
1837 | XGCValues gcvalue; |
1805 | XGCValues gcvalue; |
1838 | |
1806 | |
1839 | gcvalue.font = R->TermWin.font->fid; |
1807 | gcvalue.font = TermWin.font->fid; |
1840 | |
1808 | |
1841 | gcvalue.foreground = (XDEPTH <= 2 ? R->PixColors[Color_fg] |
1809 | gcvalue.foreground = (XDEPTH <= 2 ? PixColors[Color_fg] |
1842 | : R->PixColors[Color_Black]); |
1810 | : PixColors[Color_Black]); |
1843 | R->h->menubarGC = XCreateGC(R->Xdisplay, R->menuBar.win, |
1811 | menubarGC = XCreateGC(Xdisplay, menuBar.win, |
1844 | GCForeground | GCFont, &gcvalue); |
1812 | GCForeground | GCFont, &gcvalue); |
1845 | |
1813 | |
1846 | } |
1814 | } |
1847 | /* make sure the font is correct */ |
1815 | /* make sure the font is correct */ |
1848 | XSetFont(R->Xdisplay, R->h->menubarGC, R->TermWin.font->fid); |
1816 | XSetFont(Xdisplay, menubarGC, TermWin.font->fid); |
1849 | XSetFont(R->Xdisplay, R->h->botShadowGC, R->TermWin.font->fid); |
1817 | XSetFont(Xdisplay, botShadowGC, TermWin.font->fid); |
1850 | XClearWindow(R->Xdisplay, R->menuBar.win); |
1818 | XClearWindow(Xdisplay, menuBar.win); |
1851 | |
1819 | |
1852 | rxvt_menu_hide_all(aR); |
1820 | menu_hide_all (); |
1853 | |
1821 | |
1854 | x = 0; |
1822 | x = 0; |
1855 | if (R->h->CurrentBar != NULL) { |
1823 | if (CurrentBar != NULL) { |
1856 | for (menu = R->h->CurrentBar->head; menu != NULL; menu = menu->next) { |
1824 | for (menu = CurrentBar->head; menu != NULL; menu = menu->next) { |
1857 | int len = menu->len; |
1825 | int len = menu->len; |
1858 | |
1826 | |
1859 | x = (menu->x + menu->len + HSPACE); |
1827 | x = (menu->x + menu->len + HSPACE); |
1860 | |
1828 | |
1861 | #ifdef DEBUG_MENU_LAYOUT |
1829 | #ifdef DEBUG_MENU_LAYOUT |
1862 | rxvt_print_menu_descendants(menu); |
1830 | rxvt_print_menu_descendants(menu); |
1863 | #endif |
1831 | #endif |
1864 | |
1832 | |
1865 | if (x >= R->TermWin.ncol) |
1833 | if (x >= TermWin.ncol) |
1866 | len = (R->TermWin.ncol - (menu->x + HSPACE)); |
1834 | len = (TermWin.ncol - (menu->x + HSPACE)); |
1867 | |
1835 | |
1868 | rxvt_drawbox_menubar(aR_ menu->x, len, +1); |
1836 | drawbox_menubar (menu->x, len, +1); |
1869 | #ifdef USE_XIM |
1837 | #ifdef USE_XIM |
1870 | if (R->TermWin.fontset) |
1838 | if (TermWin.fontset) |
1871 | XmbDrawString(R->Xdisplay, |
1839 | XmbDrawString(Xdisplay, |
1872 | R->menuBar.win, R->TermWin.fontset, |
1840 | menuBar.win, TermWin.fontset, |
1873 | R->h->menubarGC, |
1841 | menubarGC, |
1874 | (Width2Pixel(menu->x) + Width2Pixel(HSPACE) / 2), |
1842 | (Width2Pixel(menu->x) + Width2Pixel(HSPACE) / 2), |
1875 | menuBar_height() - SHADOW, menu->name, len); |
1843 | menuBar_height() - SHADOW, menu->name, len); |
1876 | else |
1844 | else |
1877 | #endif |
1845 | #endif |
1878 | XDrawString(R->Xdisplay, R->menuBar.win, R->h->menubarGC, |
1846 | XDrawString(Xdisplay, menuBar.win, menubarGC, |
1879 | (Width2Pixel(menu->x) + Width2Pixel(HSPACE) / 2), |
1847 | (Width2Pixel(menu->x) + Width2Pixel(HSPACE) / 2), |
1880 | menuBar_height() - SHADOW, menu->name, len); |
1848 | menuBar_height() - SHADOW, menu->name, len); |
1881 | |
1849 | |
1882 | if (x >= R->TermWin.ncol) |
1850 | if (x >= TermWin.ncol) |
1883 | break; |
1851 | break; |
1884 | } |
1852 | } |
1885 | } |
1853 | } |
1886 | rxvt_drawbox_menubar(aR_ x, R->TermWin.ncol, (R->h->CurrentBar ? +1 : -1)); |
1854 | drawbox_menubar (x, TermWin.ncol, (CurrentBar ? +1 : -1)); |
1887 | |
1855 | |
1888 | /* add the menuBar title, if it exists and there's plenty of room */ |
1856 | /* add the menuBar title, if it exists and there's plenty of room */ |
1889 | R->h->Arrows_x = 0; |
1857 | Arrows_x = 0; |
1890 | if (x < R->TermWin.ncol) { |
1858 | if (x < TermWin.ncol) { |
1891 | const char *str; |
1859 | const char *str; |
1892 | int ncol; |
1860 | int ncol; |
1893 | unsigned int len; |
1861 | unsigned int len; |
1894 | char title[256]; |
1862 | char title[256]; |
1895 | |
1863 | |
1896 | ncol = (int)R->TermWin.ncol; |
1864 | ncol = (int)TermWin.ncol; |
1897 | if (x < (ncol - (NARROWS + 1))) { |
1865 | if (x < (ncol - (NARROWS + 1))) { |
1898 | ncol -= (NARROWS + 1); |
1866 | ncol -= (NARROWS + 1); |
1899 | R->h->Arrows_x = Width2Pixel(ncol); |
1867 | Arrows_x = Width2Pixel(ncol); |
1900 | } |
1868 | } |
1901 | rxvt_draw_Arrows(aR_ 0, +1); |
1869 | draw_Arrows (0, +1); |
1902 | |
1870 | |
1903 | str = (R->h->CurrentBar |
1871 | str = (CurrentBar |
1904 | && R->h->CurrentBar->title) ? R->h->CurrentBar->title : "%n-%v"; |
1872 | && CurrentBar->title) ? CurrentBar->title : "%n-%v"; |
1905 | for (len = 0; str[0] && len < sizeof(title) - 1; str++) { |
1873 | for (len = 0; str[0] && len < sizeof(title) - 1; str++) { |
1906 | const char *s = NULL; |
1874 | const char *s = NULL; |
1907 | |
1875 | |
1908 | switch (str[0]) { |
1876 | switch (str[0]) { |
1909 | case '%': |
1877 | case '%': |
1910 | str++; |
1878 | str++; |
1911 | switch (str[0]) { |
1879 | switch (str[0]) { |
1912 | case 'n': |
1880 | case 'n': |
1913 | s = R->h->rs[Rs_name]; |
1881 | s = rs[Rs_name]; |
1914 | break; /* resource name */ |
1882 | break; /* resource name */ |
1915 | case 'v': |
1883 | case 'v': |
1916 | s = VERSION; |
1884 | s = VERSION; |
1917 | break; /* version number */ |
1885 | break; /* version number */ |
1918 | case '%': |
1886 | case '%': |
… | |
… | |
1932 | title[len] = '\0'; |
1900 | title[len] = '\0'; |
1933 | |
1901 | |
1934 | ncol -= (x + len + HSPACE); |
1902 | ncol -= (x + len + HSPACE); |
1935 | if (len > 0 && ncol >= 0) { |
1903 | if (len > 0 && ncol >= 0) { |
1936 | #ifdef USE_XIM |
1904 | #ifdef USE_XIM |
1937 | if (R->TermWin.fontset) |
1905 | if (TermWin.fontset) |
1938 | XmbDrawString(R->Xdisplay, |
1906 | XmbDrawString(Xdisplay, |
1939 | R->menuBar.win, R->TermWin.fontset, |
1907 | menuBar.win, TermWin.fontset, |
1940 | R->h->menubarGC, |
1908 | menubarGC, |
1941 | Width2Pixel(x) + Width2Pixel(ncol + HSPACE) / 2, |
1909 | Width2Pixel(x) + Width2Pixel(ncol + HSPACE) / 2, |
1942 | menuBar_height() - SHADOW, title, len); |
1910 | menuBar_height() - SHADOW, title, len); |
1943 | else |
1911 | else |
1944 | #endif |
1912 | #endif |
1945 | XDrawString(R->Xdisplay, R->menuBar.win, R->h->menubarGC, |
1913 | XDrawString(Xdisplay, menuBar.win, menubarGC, |
1946 | Width2Pixel(x) + Width2Pixel(ncol + HSPACE) / 2, |
1914 | Width2Pixel(x) + Width2Pixel(ncol + HSPACE) / 2, |
1947 | menuBar_height() - SHADOW, title, len); |
1915 | menuBar_height() - SHADOW, title, len); |
1948 | } |
1916 | } |
1949 | } |
1917 | } |
1950 | } |
1918 | } |
1951 | |
1919 | |
1952 | /* INTPROTO */ |
|
|
1953 | int |
1920 | int |
1954 | rxvt_menubar_mapping(pR_ int map) |
1921 | rxvt_term::menubar_mapping (int map) |
1955 | { |
1922 | { |
1956 | int change = 0; |
1923 | int change = 0; |
1957 | |
1924 | |
1958 | if (map && !menubar_visible(r)) { |
1925 | if (map && !menubar_visible(r)) { |
1959 | R->menuBar.state = 1; |
1926 | menuBar.state = 1; |
1960 | if (R->menuBar.win == 0) |
1927 | if (menuBar.win == 0) |
1961 | return 0; |
1928 | return 0; |
1962 | XMapWindow(R->Xdisplay, R->menuBar.win); |
1929 | XMapWindow(Xdisplay, menuBar.win); |
1963 | change = 1; |
1930 | change = 1; |
1964 | } else if (!map && menubar_visible(r)) { |
1931 | } else if (!map && menubar_visible(r)) { |
1965 | rxvt_menubar_expose(aR); |
1932 | menubar_expose (); |
1966 | R->menuBar.state = 0; |
1933 | menuBar.state = 0; |
1967 | XUnmapWindow(R->Xdisplay, R->menuBar.win); |
1934 | XUnmapWindow(Xdisplay, menuBar.win); |
1968 | change = 1; |
1935 | change = 1; |
1969 | } else |
1936 | } else |
1970 | rxvt_menubar_expose(aR); |
1937 | menubar_expose (); |
1971 | |
1938 | |
1972 | return change; |
1939 | return change; |
1973 | } |
1940 | } |
1974 | |
1941 | |
1975 | /* INTPROTO */ |
|
|
1976 | int |
1942 | int |
1977 | rxvt_menu_select(pR_ XButtonEvent *ev) |
1943 | rxvt_term::menu_select (XButtonEvent *ev) |
1978 | { |
1944 | { |
1979 | menuitem_t *thisitem, *item = NULL; |
1945 | menuitem_t *thisitem, *item = NULL; |
1980 | int this_y, y; |
1946 | int this_y, y; |
1981 | menu_t *ActiveMenu = R->h->ActiveMenu; |
1947 | menu_t *ActiveMenu = ActiveMenu; |
1982 | |
1948 | |
1983 | Window unused_root, unused_child; |
1949 | Window unused_root, unused_child; |
1984 | int unused_root_x, unused_root_y; |
1950 | int unused_root_x, unused_root_y; |
1985 | unsigned int unused_mask; |
1951 | unsigned int unused_mask; |
1986 | |
1952 | |
1987 | if (ActiveMenu == NULL) |
1953 | if (ActiveMenu == NULL) |
1988 | return 0; |
1954 | return 0; |
1989 | |
1955 | |
1990 | XQueryPointer(R->Xdisplay, ActiveMenu->win, |
1956 | XQueryPointer(Xdisplay, ActiveMenu->win, |
1991 | &unused_root, &unused_child, |
1957 | &unused_root, &unused_child, |
1992 | &unused_root_x, &unused_root_y, |
1958 | &unused_root_x, &unused_root_y, |
1993 | &(ev->x), &(ev->y), &unused_mask); |
1959 | &(ev->x), &(ev->y), &unused_mask); |
1994 | |
1960 | |
1995 | if (ActiveMenu->parent != NULL && (ev->x < 0 || ev->y < 0)) { |
1961 | if (ActiveMenu->parent != NULL && (ev->x < 0 || ev->y < 0)) { |
1996 | rxvt_menu_hide(aR); |
1962 | menu_hide (); |
1997 | return 1; |
1963 | return 1; |
1998 | } |
1964 | } |
1999 | /* determine the menu item corresponding to the Y index */ |
1965 | /* determine the menu item corresponding to the Y index */ |
2000 | y = SHADOW; |
1966 | y = SHADOW; |
2001 | if (ev->x >= 0 && ev->x <= (ActiveMenu->w - SHADOW)) { |
1967 | if (ev->x >= 0 && ev->x <= (ActiveMenu->w - SHADOW)) { |
… | |
… | |
2008 | break; |
1974 | break; |
2009 | y += h; |
1975 | y += h; |
2010 | } |
1976 | } |
2011 | } |
1977 | } |
2012 | if (item == NULL && ev->type == ButtonRelease) { |
1978 | if (item == NULL && ev->type == ButtonRelease) { |
2013 | rxvt_menu_hide_all(aR); |
1979 | menu_hide_all (); |
2014 | return 0; |
1980 | return 0; |
2015 | } |
1981 | } |
2016 | thisitem = item; |
1982 | thisitem = item; |
2017 | this_y = y - SHADOW; |
1983 | this_y = y - SHADOW; |
2018 | |
1984 | |
… | |
… | |
2025 | |
1991 | |
2026 | if (isSeparator(item->name)) |
1992 | if (isSeparator(item->name)) |
2027 | h = HEIGHT_SEPARATOR; |
1993 | h = HEIGHT_SEPARATOR; |
2028 | else if (item == ActiveMenu->item) { |
1994 | else if (item == ActiveMenu->item) { |
2029 | /* erase old menuitem */ |
1995 | /* erase old menuitem */ |
2030 | rxvt_drawbox_menuitem(aR_ y, 0); /* No Shadow */ |
1996 | drawbox_menuitem (y, 0); /* No Shadow */ |
2031 | if (item->entry.type == MenuSubMenu) |
1997 | if (item->entry.type == MenuSubMenu) |
2032 | rxvt_drawtriangle(aR_ ActiveMenu->w, y, +1); |
1998 | drawtriangle (ActiveMenu->w, y, +1); |
2033 | break; |
1999 | break; |
2034 | } else |
2000 | } else |
2035 | h = HEIGHT_TEXT + 2 * SHADOW; |
2001 | h = HEIGHT_TEXT + 2 * SHADOW; |
2036 | y += h; |
2002 | y += h; |
2037 | } |
2003 | } |
… | |
… | |
2039 | switch (ev->type) { |
2005 | switch (ev->type) { |
2040 | case ButtonRelease: |
2006 | case ButtonRelease: |
2041 | switch (item->entry.type) { |
2007 | switch (item->entry.type) { |
2042 | case MenuLabel: |
2008 | case MenuLabel: |
2043 | case MenuSubMenu: |
2009 | case MenuSubMenu: |
2044 | rxvt_menu_hide_all(aR); |
2010 | menu_hide_all (); |
2045 | break; |
2011 | break; |
2046 | |
2012 | |
2047 | case MenuAction: |
2013 | case MenuAction: |
2048 | case MenuTerminalAction: |
2014 | case MenuTerminalAction: |
2049 | rxvt_drawbox_menuitem(aR_ this_y, -1); |
2015 | drawbox_menuitem (_y, -1); |
2050 | { |
2016 | { |
2051 | #ifdef HAVE_NANOSLEEP |
2017 | #ifdef HAVE_NANOSLEEP |
2052 | struct timespec rqt; |
2018 | struct timespec rqt; |
2053 | |
2019 | |
2054 | rqt.tv_sec = 0; |
2020 | rqt.tv_sec = 0; |
… | |
… | |
2062 | tv.tv_usec = MENU_DELAY_USEC; |
2028 | tv.tv_usec = MENU_DELAY_USEC; |
2063 | select(0, NULL, NULL, NULL, &tv); |
2029 | select(0, NULL, NULL, NULL, &tv); |
2064 | #endif |
2030 | #endif |
2065 | } |
2031 | } |
2066 | /* remove menu before sending keys to the application */ |
2032 | /* remove menu before sending keys to the application */ |
2067 | rxvt_menu_hide_all(aR); |
2033 | menu_hide_all (); |
2068 | #ifndef DEBUG_MENU |
2034 | #ifndef DEBUG_MENU |
2069 | rxvt_action_dispatch(aR_ &(item->entry.action)); |
2035 | action_dispatch (&(item->entry.action)); |
2070 | #else /* DEBUG_MENU */ |
2036 | #else /* DEBUG_MENU */ |
2071 | fprintf(stderr, "%s: %s\n", item->name, |
2037 | fprintf(stderr, "%s: %s\n", item->name, |
2072 | item->entry.action.str); |
2038 | item->entry.action.str); |
2073 | #endif /* DEBUG_MENU */ |
2039 | #endif /* DEBUG_MENU */ |
2074 | break; |
2040 | break; |
… | |
… | |
2084 | } |
2050 | } |
2085 | } |
2051 | } |
2086 | DoMenu: |
2052 | DoMenu: |
2087 | ActiveMenu->item = thisitem; |
2053 | ActiveMenu->item = thisitem; |
2088 | y = this_y; |
2054 | y = this_y; |
2089 | if (thisitem != NULL) { |
2055 | if (item != NULL) { |
2090 | item = ActiveMenu->item; |
2056 | item = ActiveMenu->item; |
2091 | if (item->entry.type != MenuLabel) |
2057 | if (item->entry.type != MenuLabel) |
2092 | rxvt_drawbox_menuitem(aR_ y, +1); |
2058 | drawbox_menuitem (y, +1); |
2093 | if (item->entry.type == MenuSubMenu) { |
2059 | if (item->entry.type == MenuSubMenu) { |
2094 | int x; |
2060 | int x; |
2095 | |
2061 | |
2096 | rxvt_drawtriangle(aR_ ActiveMenu->w, y, -1); |
2062 | drawtriangle (ActiveMenu->w, y, -1); |
2097 | |
2063 | |
2098 | x = ev->x + (ActiveMenu->parent |
2064 | x = ev->x + (ActiveMenu->parent |
2099 | ? ActiveMenu->x |
2065 | ? ActiveMenu->x |
2100 | : Width2Pixel(ActiveMenu->x)); |
2066 | : Width2Pixel(ActiveMenu->x)); |
2101 | |
2067 | |
2102 | if (x >= item->entry.submenu.menu->x) { |
2068 | if (x >= item->entry.submenu.menu->x) { |
2103 | R->h->ActiveMenu = item->entry.submenu.menu; |
2069 | ActiveMenu = item->entry.submenu.menu; |
2104 | rxvt_menu_show(aR); |
2070 | menu_show (); |
2105 | return 1; |
2071 | return 1; |
2106 | } |
2072 | } |
2107 | } |
2073 | } |
2108 | } |
2074 | } |
2109 | return 0; |
2075 | return 0; |
2110 | } |
2076 | } |
2111 | |
2077 | |
2112 | /* INTPROTO */ |
|
|
2113 | void |
2078 | void |
2114 | rxvt_menubar_select(pR_ XButtonEvent *ev) |
2079 | rxvt_term::menubar_select (XButtonEvent *ev) |
2115 | { |
2080 | { |
2116 | menu_t *menu = NULL; |
2081 | menu_t *menu = NULL; |
2117 | |
2082 | |
2118 | /* determine the pulldown menu corresponding to the X index */ |
2083 | /* determine the pulldown menu corresponding to the X index */ |
2119 | if (ev->y >= 0 && ev->y <= menuBar_height() && R->h->CurrentBar != NULL) { |
2084 | if (ev->y >= 0 && ev->y <= menuBar_height() && CurrentBar != NULL) { |
2120 | for (menu = R->h->CurrentBar->head; menu != NULL; menu = menu->next) { |
2085 | for (menu = CurrentBar->head; menu != NULL; menu = menu->next) { |
2121 | int x = Width2Pixel(menu->x); |
2086 | int x = Width2Pixel(menu->x); |
2122 | int w = Width2Pixel(menu->len + HSPACE); |
2087 | int w = Width2Pixel(menu->len + HSPACE); |
2123 | |
2088 | |
2124 | if ((ev->x >= x && ev->x < x + w)) |
2089 | if ((ev->x >= x && ev->x < x + w)) |
2125 | break; |
2090 | break; |
2126 | } |
2091 | } |
2127 | } |
2092 | } |
2128 | switch (ev->type) { |
2093 | switch (ev->type) { |
2129 | case ButtonRelease: |
2094 | case ButtonRelease: |
2130 | rxvt_menu_hide_all(aR); |
2095 | menu_hide_all (); |
2131 | break; |
2096 | break; |
2132 | |
2097 | |
2133 | case ButtonPress: |
2098 | case ButtonPress: |
2134 | if (menu == NULL && R->h->Arrows_x && ev->x >= R->h->Arrows_x) { |
2099 | if (menu == NULL && Arrows_x && ev->x >= Arrows_x) { |
2135 | int i; |
2100 | int i; |
2136 | |
2101 | |
2137 | for (i = 0; i < NARROWS; i++) { |
2102 | for (i = 0; i < NARROWS; i++) { |
2138 | if (ev->x >= (R->h->Arrows_x + (Width2Pixel(4 * i + i)) / 4) |
2103 | if (ev->x >= (Arrows_x + (Width2Pixel(4 * i + i)) / 4) |
2139 | && ev->x < (R->h->Arrows_x |
2104 | && ev->x < (Arrows_x |
2140 | + (Width2Pixel(4 * i + i + 4)) / 4)) { |
2105 | + (Width2Pixel(4 * i + i + 4)) / 4)) { |
2141 | rxvt_draw_Arrows(aR_ Arrows[i].name, -1); |
2106 | draw_Arrows (Arrows[i].name, -1); |
2142 | { |
2107 | { |
2143 | #ifdef HAVE_NANOSLEEP |
2108 | #ifdef HAVE_NANOSLEEP |
2144 | struct timespec rqt; |
2109 | struct timespec rqt; |
2145 | |
2110 | |
2146 | rqt.tv_sec = 0; |
2111 | rqt.tv_sec = 0; |
… | |
… | |
2153 | tv.tv_sec = 0; |
2118 | tv.tv_sec = 0; |
2154 | tv.tv_usec = MENU_DELAY_USEC; |
2119 | tv.tv_usec = MENU_DELAY_USEC; |
2155 | select(0, NULL, NULL, NULL, &tv); |
2120 | select(0, NULL, NULL, NULL, &tv); |
2156 | #endif |
2121 | #endif |
2157 | } |
2122 | } |
2158 | rxvt_draw_Arrows(aR_ Arrows[i].name, +1); |
2123 | draw_Arrows (Arrows[i].name, +1); |
2159 | #ifdef DEBUG_MENUARROWS |
2124 | #ifdef DEBUG_MENUARROWS |
2160 | fprintf(stderr, "'%c': ", Arrows[i].name); |
2125 | fprintf(stderr, "'%c': ", Arrows[i].name); |
2161 | |
2126 | |
2162 | if (R->h->CurrentBar == NULL |
2127 | if (CurrentBar == NULL |
2163 | || (R->h->CurrentBar->arrows[i].type != MenuAction |
2128 | || (CurrentBar->arrows[i].type != MenuAction |
2164 | && R->h->CurrentBar->arrows[i].type != |
2129 | && CurrentBar->arrows[i].type != |
2165 | MenuTerminalAction)) { |
2130 | MenuTerminalAction)) { |
2166 | if (Arrows[i].str != NULL && Arrows[i].str[0]) |
2131 | if (Arrows[i].str != NULL && Arrows[i].str[0]) |
2167 | fprintf(stderr, "(default) \\033%s\n", |
2132 | fprintf(stderr, "(default) \\033%s\n", |
2168 | &(Arrows[i].str[2])); |
2133 | &(Arrows[i].str[2])); |
2169 | } else { |
2134 | } else { |
2170 | fprintf(stderr, "%s\n", |
2135 | fprintf(stderr, "%s\n", |
2171 | R->h->CurrentBar->arrows[i].str); |
2136 | CurrentBar->arrows[i].str); |
2172 | } |
2137 | } |
2173 | #else /* DEBUG_MENUARROWS */ |
2138 | #else /* DEBUG_MENUARROWS */ |
2174 | if (R->h->CurrentBar == NULL |
2139 | if (CurrentBar == NULL |
2175 | || rxvt_action_dispatch(r, |
2140 | || rxvt_action_dispatch(r, |
2176 | &(R->h->CurrentBar->arrows[i])) |
2141 | &(CurrentBar->arrows[i])) |
2177 | ) { |
2142 | ) { |
2178 | if (Arrows[i].str != NULL && Arrows[i].str[0] != 0) |
2143 | if (Arrows[i].str != NULL && Arrows[i].str[0] != 0) |
2179 | rxvt_tt_write(aR_ (Arrows[i].str + 1), |
2144 | tt_write ((Arrows[i].str + 1), |
2180 | Arrows[i].str[0]); |
2145 | Arrows[i].str[0]); |
2181 | } |
2146 | } |
2182 | #endif /* DEBUG_MENUARROWS */ |
2147 | #endif /* DEBUG_MENUARROWS */ |
2183 | return; |
2148 | return; |
2184 | } |
2149 | } |
… | |
… | |
2188 | |
2153 | |
2189 | default: |
2154 | default: |
2190 | /* |
2155 | /* |
2191 | * press menubar or move to a new entry |
2156 | * press menubar or move to a new entry |
2192 | */ |
2157 | */ |
2193 | if (menu != NULL && menu != R->h->ActiveMenu) { |
2158 | if (menu != NULL && menu != ActiveMenu) { |
2194 | rxvt_menu_hide_all(aR); /* pop down old menu */ |
2159 | menu_hide_all (); /* pop down old menu */ |
2195 | R->h->ActiveMenu = menu; |
2160 | ActiveMenu = menu; |
2196 | rxvt_menu_show(aR); /* pop up new menu */ |
2161 | menu_show (); /* pop up new menu */ |
2197 | } |
2162 | } |
2198 | break; |
2163 | break; |
2199 | } |
2164 | } |
2200 | } |
2165 | } |
2201 | |
2166 | |
2202 | /* |
2167 | /* |
2203 | * general dispatch routine, |
2168 | * general dispatch routine, |
2204 | * it would be nice to have `sticky' menus |
2169 | * it would be nice to have `sticky' menus |
2205 | */ |
2170 | */ |
2206 | /* EXTPROTO */ |
|
|
2207 | void |
2171 | void |
2208 | rxvt_menubar_control(pR_ XButtonEvent *ev) |
2172 | rxvt_term::menubar_control (XButtonEvent *ev) |
2209 | { |
2173 | { |
2210 | switch (ev->type) { |
2174 | switch (ev->type) { |
2211 | case ButtonPress: |
2175 | case ButtonPress: |
2212 | if (ev->button == Button1) |
2176 | if (ev->button == Button1) |
2213 | rxvt_menubar_select(aR_ ev); |
2177 | menubar_select (ev); |
2214 | break; |
2178 | break; |
2215 | |
2179 | |
2216 | case ButtonRelease: |
2180 | case ButtonRelease: |
2217 | if (ev->button == Button1) |
2181 | if (ev->button == Button1) |
2218 | rxvt_menu_select(aR_ ev); |
2182 | menu_select (ev); |
2219 | break; |
2183 | break; |
2220 | |
2184 | |
2221 | case MotionNotify: |
2185 | case MotionNotify: |
2222 | while (XCheckTypedWindowEvent(R->Xdisplay, R->TermWin.parent[0], |
2186 | while (XCheckTypedWindowEvent(Xdisplay, TermWin.parent[0], |
2223 | MotionNotify, (XEvent *) ev)) ; |
2187 | MotionNotify, (XEvent *) ev)) ; |
2224 | |
2188 | |
2225 | if (R->h->ActiveMenu) |
2189 | if (ActiveMenu) |
2226 | while (rxvt_menu_select(aR_ ev)) ; |
2190 | while (menu_select (ev)) ; |
2227 | else |
2191 | else |
2228 | ev->y = -1; |
2192 | ev->y = -1; |
2229 | if (ev->y < 0) { |
2193 | if (ev->y < 0) { |
2230 | Window unused_root, unused_child; |
2194 | Window unused_root, unused_child; |
2231 | int unused_root_x, unused_root_y; |
2195 | int unused_root_x, unused_root_y; |
2232 | unsigned int unused_mask; |
2196 | unsigned int unused_mask; |
2233 | |
2197 | |
2234 | XQueryPointer(R->Xdisplay, R->menuBar.win, |
2198 | XQueryPointer(Xdisplay, menuBar.win, |
2235 | &unused_root, &unused_child, |
2199 | &unused_root, &unused_child, |
2236 | &unused_root_x, &unused_root_y, |
2200 | &unused_root_x, &unused_root_y, |
2237 | &(ev->x), &(ev->y), &unused_mask); |
2201 | &(ev->x), &(ev->y), &unused_mask); |
2238 | rxvt_menubar_select(aR_ ev); |
2202 | menubar_select (ev); |
2239 | } |
2203 | } |
2240 | break; |
2204 | break; |
2241 | } |
2205 | } |
2242 | } |
2206 | } |
2243 | |
2207 | |
2244 | /* EXTPROTO */ |
|
|
2245 | void |
2208 | void |
2246 | rxvt_map_menuBar(pR_ int map) |
2209 | rxvt_term::map_menuBar (int map) |
2247 | { |
2210 | { |
2248 | if (rxvt_menubar_mapping(aR_ map)) |
2211 | if (menubar_mapping (map)) |
2249 | rxvt_resize_all_windows(aR_ 0, 0, 0); |
2212 | resize_all_windows (0, 0, 0); |
2250 | } |
2213 | } |
2251 | #endif |
2214 | #endif |
2252 | /*----------------------- end-of-file (C source) -----------------------*/ |
2215 | /*----------------------- end-of-file (C source) -----------------------*/ |