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 */ |
|
|
31 | |
34 | |
32 | #define Menu_PixelWidth(menu) \ |
35 | #define Menu_PixelWidth(menu) \ |
33 | (2 * SHADOW + Width2Pixel ((menu)->width + 3 * HSPACE)) |
36 | (2 * SHADOW + Width2Pixel ((menu)->width + 3 * HSPACE)) |
34 | |
37 | |
35 | static const struct |
38 | static const struct |
… | |
… | |
43 | { 'd', "\003\033[B" }, |
46 | { 'd', "\003\033[B" }, |
44 | { 'r', "\003\033[C" } |
47 | { 'r', "\003\033[C" } |
45 | }; |
48 | }; |
46 | |
49 | |
47 | /*}}} */ |
50 | /*}}} */ |
|
|
51 | |
|
|
52 | static void |
|
|
53 | draw_string (rxvt_drawable &d, GC gc, rxvt_fontset *fs, int x, int y, char *str, int len) |
|
|
54 | { |
|
|
55 | mbstate mbs; |
|
|
56 | |
|
|
57 | while (len) |
|
|
58 | { |
|
|
59 | wchar_t w; |
|
|
60 | int l = mbrtowc (&w, str, len, mbs); |
|
|
61 | |
|
|
62 | if (l <= 0) |
|
|
63 | break; |
|
|
64 | |
|
|
65 | len -= l; |
|
|
66 | str += l; |
|
|
67 | |
|
|
68 | rxvt_font *font = (*fs)[fs->find_font (w)]; |
|
|
69 | text_t ch = w; |
|
|
70 | font->draw (d, x, y, &ch, 1, Color_bg, Color_scroll); |
|
|
71 | |
|
|
72 | x += font->width * wcwidth (w); |
|
|
73 | } |
|
|
74 | } |
48 | |
75 | |
49 | /* |
76 | /* |
50 | * find an item called NAME in MENU |
77 | * find an item called NAME in MENU |
51 | */ |
78 | */ |
52 | menuitem_t * |
79 | menuitem_t * |
… | |
… | |
328 | unsigned int len; |
355 | unsigned int len; |
329 | |
356 | |
330 | if (!parse[i].len) |
357 | if (!parse[i].len) |
331 | continue; |
358 | continue; |
332 | |
359 | |
333 | str = rxvt_malloc (parse[i].len + xtra_len + 1); |
360 | str = (unsigned char *) rxvt_malloc (parse[i].len + xtra_len + 1); |
334 | |
361 | |
335 | len = 0; |
362 | len = 0; |
336 | if (beg.len) |
363 | if (beg.len) |
337 | { |
364 | { |
338 | STRNCPY (str + len, beg.str, beg.len); |
365 | STRNCPY (str + len, beg.str, beg.len); |
… | |
… | |
406 | |
433 | |
407 | item->len2 = 0; |
434 | item->len2 = 0; |
408 | item->name2 = NULL; |
435 | item->name2 = NULL; |
409 | |
436 | |
410 | len = STRLEN (name); |
437 | len = STRLEN (name); |
411 | item->name = rxvt_malloc (len + 1); |
438 | item->name = (char *)rxvt_malloc (len + 1); |
412 | STRCPY (item->name, name); |
439 | STRCPY (item->name, name); |
413 | if (name[0] == '.' && name[1] != '.') |
440 | if (name[0] == '.' && name[1] != '.') |
414 | len = 0; /* hidden menu name */ |
441 | len = 0; /* hidden menu name */ |
415 | item->len = len; |
442 | item->len = len; |
416 | |
443 | |
… | |
… | |
434 | len = STRLEN (name2); |
461 | len = STRLEN (name2); |
435 | if (len == 0) |
462 | if (len == 0) |
436 | item->name2 = NULL; |
463 | item->name2 = NULL; |
437 | else |
464 | else |
438 | { |
465 | { |
439 | item->name2 = rxvt_malloc (len + 1); |
466 | item->name2 = (char *)rxvt_malloc (len + 1); |
440 | STRCPY (item->name2, name2); |
467 | STRCPY (item->name2, name2); |
441 | } |
468 | } |
442 | item->len2 = len; |
469 | item->len2 = len; |
443 | } |
470 | } |
444 | item->entry.type = MenuLabel; |
471 | item->entry.type = MenuLabel; |
… | |
… | |
449 | action = item->name2; |
476 | action = item->name2; |
450 | len = item->len2; |
477 | len = item->len2; |
451 | } |
478 | } |
452 | if (len) |
479 | if (len) |
453 | { |
480 | { |
454 | unsigned char *str = rxvt_malloc (len + 1); |
481 | unsigned char *str = (unsigned char *)rxvt_malloc (len + 1); |
455 | |
482 | |
456 | STRCPY (str, action); |
483 | STRCPY (str, action); |
457 | |
484 | |
458 | if (rxvt_action_type (& (item->entry.action), str) < 0) |
485 | if (rxvt_action_type (& (item->entry.action), str) < 0) |
459 | free (str); |
486 | free (str); |
… | |
… | |
491 | { |
518 | { |
492 | p++; |
519 | p++; |
493 | if (*p == '/') |
520 | if (*p == '/') |
494 | path = p; |
521 | path = p; |
495 | } |
522 | } |
|
|
523 | |
496 | if (path[0] == '/') |
524 | if (path[0] == '/') |
497 | { |
525 | { |
498 | path++; |
526 | path++; |
499 | *menu = NULL; |
527 | *menu = NULL; |
500 | } |
528 | } |
|
|
529 | |
501 | while ((p = STRCHR (path, '/')) != NULL) |
530 | while ((p = STRCHR (path, '/')) != NULL) |
502 | { |
531 | { |
503 | p[0] = '\0'; |
532 | p[0] = '\0'; |
504 | if (path[0] == '\0') |
533 | if (path[0] == '\0') |
505 | return NULL; |
534 | return NULL; |
|
|
535 | |
506 | if (!STRCMP (path, DOT)) |
536 | if (!STRCMP (path, DOT)) |
507 | { |
537 | { |
508 | /* nothing to do */ |
538 | /* nothing to do */ |
509 | } |
539 | } |
510 | else if (!STRCMP (path, DOTS)) |
540 | else if (!STRCMP (path, DOTS)) |
… | |
… | |
523 | } |
553 | } |
524 | |
554 | |
525 | path = (p + 1); |
555 | path = (p + 1); |
526 | } |
556 | } |
527 | } |
557 | } |
|
|
558 | |
528 | if (!STRCMP (path, DOTS)) |
559 | if (!STRCMP (path, DOTS)) |
529 | { |
560 | { |
530 | path += STRLEN (DOTS); |
561 | path += STRLEN (DOTS); |
531 | if (*menu != NULL) |
562 | if (*menu != NULL) |
532 | *menu = (*menu)->parent; |
563 | *menu = (*menu)->parent; |
533 | return path; |
564 | return path; |
534 | } |
565 | } |
|
|
566 | |
535 | /* find this menu */ |
567 | /* find this menu */ |
536 | if (*menu == NULL) |
568 | if (*menu == NULL) |
537 | { |
569 | { |
538 | for (m = CurrentBar->tail; m != NULL; m = m->prev) |
570 | for (m = CurrentBar->tail; m != NULL; m = m->prev) |
539 | { |
|
|
540 | if (!STRCMP (path, m->name)) |
571 | if (!STRCMP (path, m->name)) |
541 | break; |
572 | break; |
542 | } |
|
|
543 | } |
573 | } |
544 | else |
574 | else |
545 | { |
575 | { |
546 | /* find this menu */ |
576 | /* find this menu */ |
547 | for (item = (*menu)->tail; item != NULL; item = item->prev) |
577 | for (item = (*menu)->tail; item != NULL; item = item->prev) |
… | |
… | |
552 | m = (item->entry.submenu.menu); |
582 | m = (item->entry.submenu.menu); |
553 | break; |
583 | break; |
554 | } |
584 | } |
555 | } |
585 | } |
556 | } |
586 | } |
|
|
587 | |
557 | if (m != NULL) |
588 | if (m != NULL) |
558 | { |
589 | { |
559 | *menu = m; |
590 | *menu = m; |
560 | path += STRLEN (path); |
591 | path += STRLEN (path); |
561 | } |
592 | } |
|
|
593 | |
562 | return path; |
594 | return path; |
563 | } |
595 | } |
564 | |
596 | |
565 | /* |
597 | /* |
566 | * delete this entire menu |
598 | * delete this entire menu |
… | |
… | |
568 | menu_t * |
600 | menu_t * |
569 | rxvt_term::menu_delete (menu_t *menu) |
601 | rxvt_term::menu_delete (menu_t *menu) |
570 | { |
602 | { |
571 | menu_t *parent = NULL, *prev, *next; |
603 | menu_t *parent = NULL, *prev, *next; |
572 | menuitem_t *item; |
604 | menuitem_t *item; |
573 | bar_t *CurrentBar = CurrentBar; |
|
|
574 | |
605 | |
575 | #ifdef DEBUG_STRICT |
606 | #ifdef DEBUG_STRICT |
576 | assert (CurrentBar != NULL); |
607 | assert (CurrentBar != NULL); |
577 | #endif |
608 | #endif |
578 | |
609 | |
… | |
… | |
618 | } |
649 | } |
619 | |
650 | |
620 | item = menu->tail; |
651 | item = menu->tail; |
621 | while (item != NULL) |
652 | while (item != NULL) |
622 | { |
653 | { |
623 | menuitem_t *p = item->prev; |
654 | menuitem_t *p = item->prev; |
624 | |
655 | |
625 | menuitem_free (menu, item); |
656 | menuitem_free (menu, item); |
626 | item = p; |
657 | item = p; |
627 | } |
658 | } |
628 | |
659 | |
629 | if (menu->name != NULL) |
|
|
630 | free (menu->name); |
660 | free (menu->name); |
631 | free (menu); |
661 | free (menu); |
632 | |
662 | |
633 | return parent; |
663 | return parent; |
634 | } |
664 | } |
635 | |
665 | |
636 | menu_t * |
666 | menu_t * |
637 | rxvt_term::menu_add (menu_t *parent, char *path) |
667 | rxvt_term::menu_add (menu_t *parent, char *path) |
638 | { |
668 | { |
639 | menu_t *menu; |
669 | menu_t *menu; |
640 | bar_t *CurrentBar = CurrentBar; |
|
|
641 | |
670 | |
642 | #ifdef DEBUG_STRICT |
671 | #ifdef DEBUG_STRICT |
643 | assert (CurrentBar != NULL); |
672 | assert (CurrentBar != NULL); |
644 | #endif |
673 | #endif |
645 | |
674 | |
646 | if (STRCHR (path, '/') != NULL) |
675 | if (STRCHR (path, '/') != NULL) |
647 | { |
676 | { |
648 | char *p; |
677 | char *p; |
649 | |
678 | |
650 | if (path[0] == '/') |
679 | if (path[0] == '/') |
651 | { |
680 | { |
652 | /* shouldn't happen */ |
681 | /* shouldn't happen */ |
653 | path++; |
682 | path++; |
… | |
… | |
673 | menu = (menu_t *) rxvt_malloc (sizeof (menu_t)); |
702 | menu = (menu_t *) rxvt_malloc (sizeof (menu_t)); |
674 | |
703 | |
675 | menu->width = 0; |
704 | menu->width = 0; |
676 | menu->parent = parent; |
705 | menu->parent = parent; |
677 | menu->len = STRLEN (path); |
706 | menu->len = STRLEN (path); |
678 | menu->name = rxvt_malloc ((menu->len + 1)); |
707 | menu->name = (char *)rxvt_malloc ((menu->len + 1)); |
679 | STRCPY (menu->name, path); |
708 | STRCPY (menu->name, path); |
680 | |
709 | |
681 | /* initialize head/tail */ |
710 | /* initialize head/tail */ |
682 | menu->head = menu->tail = NULL; |
711 | menu->head = menu->tail = NULL; |
683 | menu->prev = menu->next = NULL; |
712 | menu->prev = menu->next = NULL; |
684 | |
713 | |
685 | menu->win = None; |
714 | menu->win = None; |
|
|
715 | menu->drawable = 0; |
686 | menu->x = menu->y = menu->w = menu->h = 0; |
716 | menu->x = menu->y = menu->w = menu->h = 0; |
687 | menu->item = NULL; |
717 | menu->item = NULL; |
688 | |
718 | |
689 | /* add to tail of list */ |
719 | /* add to tail of list */ |
690 | if (parent == NULL) |
720 | if (parent == NULL) |
… | |
… | |
779 | w = Height2Pixel (1) - 2 * SHADOW; |
809 | w = Height2Pixel (1) - 2 * SHADOW; |
780 | |
810 | |
781 | x -= SHADOW + (3 * w / 2); |
811 | x -= SHADOW + (3 * w / 2); |
782 | y += SHADOW * 3; |
812 | y += SHADOW * 3; |
783 | |
813 | |
784 | rxvt_Draw_Triangle (display->display, ActiveMenu->win, top, bot, x, y, w, |
814 | rxvt_Draw_Triangle (display->display, ActiveMenu->win, top, bot, x, y, w, 'r'); |
785 | 'r'); |
|
|
786 | } |
815 | } |
787 | |
816 | |
788 | void |
817 | void |
789 | rxvt_term::drawbox_menuitem (int y, int state) |
818 | rxvt_term::drawbox_menuitem (int y, int state) |
790 | { |
819 | { |
… | |
… | |
822 | if (menu == NULL) |
851 | if (menu == NULL) |
823 | { |
852 | { |
824 | fprintf (stderr, "Top Level menu\n"); |
853 | fprintf (stderr, "Top Level menu\n"); |
825 | return; |
854 | return; |
826 | } |
855 | } |
|
|
856 | |
827 | fprintf (stderr, "menu %s ", menu->name); |
857 | fprintf (stderr, "menu %s ", menu->name); |
828 | if (menu->parent != NULL) |
858 | if (menu->parent != NULL) |
829 | { |
859 | { |
830 | menuitem_t *item; |
860 | menuitem_t *item; |
831 | |
861 | |
… | |
… | |
835 | && item->entry.submenu.menu == menu) |
865 | && item->entry.submenu.menu == menu) |
836 | { |
866 | { |
837 | break; |
867 | break; |
838 | } |
868 | } |
839 | } |
869 | } |
|
|
870 | |
840 | if (item == NULL) |
871 | if (item == NULL) |
841 | { |
872 | { |
842 | fprintf (stderr, "is an orphan!\n"); |
873 | fprintf (stderr, "is an orphan!\n"); |
843 | return; |
874 | return; |
844 | } |
875 | } |
845 | } |
876 | } |
|
|
877 | |
846 | fprintf (stderr, "\n"); |
878 | fprintf (stderr, "\n"); |
847 | rxvt_print_menu_ancestors (menu->parent); |
879 | rxvt_print_menu_ancestors (menu->parent); |
848 | } |
880 | } |
849 | |
881 | |
850 | void |
882 | void |
… | |
… | |
893 | |
925 | |
894 | /* pop up/down the current menu and redraw the menuBar button */ |
926 | /* pop up/down the current menu and redraw the menuBar button */ |
895 | void |
927 | void |
896 | rxvt_term::menu_show () |
928 | rxvt_term::menu_show () |
897 | { |
929 | { |
898 | int x, y, xright; |
930 | int x, y, xright; |
899 | menu_t *ActiveMenu = ActiveMenu; |
|
|
900 | menuitem_t *item; |
931 | menuitem_t *item; |
901 | |
932 | |
902 | if (ActiveMenu == NULL) |
933 | if (ActiveMenu == NULL) |
903 | return; |
934 | return; |
904 | |
935 | |
905 | x = ActiveMenu->x; |
936 | x = ActiveMenu->x; |
… | |
… | |
920 | for (h = 0, item = ActiveMenu->head; item != NULL; item = item->next) |
951 | for (h = 0, item = ActiveMenu->head; item != NULL; item = item->next) |
921 | h += isSeparator (item->name) ? HEIGHT_SEPARATOR |
952 | h += isSeparator (item->name) ? HEIGHT_SEPARATOR |
922 | : HEIGHT_TEXT + 2 * SHADOW; |
953 | : HEIGHT_TEXT + 2 * SHADOW; |
923 | ActiveMenu->h = h + 2 * SHADOW; |
954 | ActiveMenu->h = h + 2 * SHADOW; |
924 | } |
955 | } |
|
|
956 | |
925 | if (ActiveMenu->win == None) |
957 | if (ActiveMenu->win == None) |
926 | { |
958 | { |
927 | ActiveMenu->win = XCreateSimpleWindow (display->display, TermWin.vt, |
959 | ActiveMenu->win = XCreateSimpleWindow (display->display, TermWin.vt, |
928 | x, ActiveMenu->y, |
960 | x, ActiveMenu->y, |
929 | ActiveMenu->w, ActiveMenu->h, |
961 | ActiveMenu->w, ActiveMenu->h, |
930 | 0, |
962 | 0, |
931 | PixColors[Color_fg], |
963 | PixColors[Color_fg], |
932 | PixColors[Color_scroll]); |
964 | PixColors[Color_scroll]); |
|
|
965 | ActiveMenu->drawable = new rxvt_drawable (display, ActiveMenu->win); |
933 | XMapWindow (display->display, ActiveMenu->win); |
966 | XMapWindow (display->display, ActiveMenu->win); |
934 | } |
967 | } |
|
|
968 | |
935 | rxvt_Draw_Shadow (display->display, ActiveMenu->win, |
969 | rxvt_Draw_Shadow (display->display, ActiveMenu->win, |
936 | topShadowGC, botShadowGC, |
970 | topShadowGC, botShadowGC, |
937 | 0, 0, ActiveMenu->w, ActiveMenu->h); |
971 | 0, 0, ActiveMenu->w, ActiveMenu->h); |
938 | |
972 | |
939 | /* determine the correct right-alignment */ |
973 | /* determine the correct right-alignment */ |
… | |
… | |
941 | if (item->len2 > xright) |
975 | if (item->len2 > xright) |
942 | xright = item->len2; |
976 | xright = item->len2; |
943 | |
977 | |
944 | for (y = 0, item = ActiveMenu->head; item != NULL; item = item->next) |
978 | for (y = 0, item = ActiveMenu->head; item != NULL; item = item->next) |
945 | { |
979 | { |
946 | const int xoff = (SHADOW + Width2Pixel (HSPACE) / 2); |
980 | const int xoff = (SHADOW + Width2Pixel (HSPACE) / 2); |
947 | register int h; |
981 | register int h; |
948 | GC gc = menubarGC; |
982 | GC gc = menubarGC; |
949 | |
983 | |
950 | if (isSeparator (item->name)) |
984 | if (isSeparator (item->name)) |
951 | { |
985 | { |
952 | rxvt_Draw_Shadow (display->display, ActiveMenu->win, |
986 | rxvt_Draw_Shadow (display->display, ActiveMenu->win, |
953 | topShadowGC, botShadowGC, |
987 | topShadowGC, botShadowGC, |
… | |
… | |
959 | { |
993 | { |
960 | char *name = item->name; |
994 | char *name = item->name; |
961 | int len = item->len; |
995 | int len = item->len; |
962 | |
996 | |
963 | if (item->entry.type == MenuLabel) |
997 | if (item->entry.type == MenuLabel) |
964 | { |
|
|
965 | gc = botShadowGC; |
998 | gc = botShadowGC; |
966 | } |
|
|
967 | else if (item->entry.type == MenuSubMenu) |
999 | else if (item->entry.type == MenuSubMenu) |
968 | { |
1000 | { |
969 | int x1, y1; |
1001 | int x1, y1; |
970 | menuitem_t *it; |
1002 | menuitem_t *it; |
971 | menu_t *menu = item->entry.submenu.menu; |
1003 | menu_t *menu = item->entry.submenu.menu; |
… | |
… | |
1003 | } |
1035 | } |
1004 | else if (item->name2 && !STRCMP (name, item->name2)) |
1036 | else if (item->name2 && !STRCMP (name, item->name2)) |
1005 | name = NULL; |
1037 | name = NULL; |
1006 | |
1038 | |
1007 | if (len && name) |
1039 | if (len && name) |
1008 | { |
1040 | draw_string (*ActiveMenu->drawable, gc, TermWin.fontset, |
1009 | #ifdef USE_XIM |
|
|
1010 | if (TermWin.fontset) |
|
|
1011 | XmbDrawString (display->display, |
|
|
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 (display->display, ActiveMenu->win, gc, xoff, |
|
|
1019 | 2 * SHADOW + y + TermWin.font->ascent + 1, |
|
|
1020 | name, len); |
1041 | xoff, 2 * SHADOW + y, name, len); |
1021 | } |
|
|
1022 | |
1042 | |
1023 | len = item->len2; |
1043 | len = item->len2; |
1024 | name = item->name2; |
1044 | name = item->name2; |
|
|
1045 | |
1025 | if (len && name) |
1046 | if (len && name) |
1026 | { |
1047 | draw_string (*ActiveMenu->drawable, gc, TermWin.fontset, |
1027 | #ifdef USE_XIM |
|
|
1028 | if (TermWin.fontset) |
|
|
1029 | XmbDrawString (display->display, |
|
|
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 (display->display, ActiveMenu->win, gc, |
|
|
1038 | ActiveMenu->w - (xoff + Width2Pixel (xright)), |
1048 | ActiveMenu->w - (xoff + Width2Pixel (xright)), 2 * SHADOW + y, name, len); |
1039 | 2 * SHADOW + y + TermWin.font->ascent + 1, |
1049 | |
1040 | name, len); |
|
|
1041 | } |
|
|
1042 | h = HEIGHT_TEXT + 2 * SHADOW; |
1050 | h = HEIGHT_TEXT + 2 * SHADOW; |
1043 | } |
1051 | } |
1044 | y += h; |
1052 | y += h; |
1045 | } |
1053 | } |
1046 | } |
1054 | } |
1047 | |
1055 | |
1048 | void |
1056 | void |
1049 | rxvt_term::menu_display (void (*update) (rxvt_t *)) |
1057 | rxvt_term::menu_display (void (rxvt_term::*update) ()) |
1050 | { |
1058 | { |
1051 | menu_t *ActiveMenu = ActiveMenu; |
|
|
1052 | |
|
|
1053 | if (ActiveMenu == NULL) |
1059 | if (ActiveMenu == NULL) |
1054 | return; |
1060 | return; |
|
|
1061 | |
|
|
1062 | delete ActiveMenu->drawable; |
1055 | if (ActiveMenu->win != None) |
1063 | if (ActiveMenu->win != None) |
1056 | XDestroyWindow (display->display, ActiveMenu->win); |
1064 | XDestroyWindow (display->display, ActiveMenu->win); |
1057 | ActiveMenu->win = None; |
1065 | ActiveMenu->win = None; |
1058 | ActiveMenu->item = NULL; |
1066 | ActiveMenu->item = NULL; |
1059 | |
1067 | |
1060 | if (ActiveMenu->parent == NULL) |
1068 | if (ActiveMenu->parent == NULL) |
1061 | drawbox_menubar (ActiveMenu->x, ActiveMenu->len, +1); |
1069 | drawbox_menubar (ActiveMenu->x, ActiveMenu->len, +1); |
|
|
1070 | |
1062 | ActiveMenu = ActiveMenu->parent; |
1071 | ActiveMenu = ActiveMenu->parent; |
1063 | update (r); |
1072 | (this->*update) (); |
1064 | } |
1073 | } |
1065 | |
1074 | |
1066 | void |
1075 | void |
1067 | rxvt_term::menu_hide_all () |
1076 | rxvt_term::menu_hide_all () |
1068 | { |
1077 | { |
1069 | menu_display (rxvt_menu_hide_all); |
1078 | menu_display (&rxvt_term::menu_hide_all); |
1070 | } |
1079 | } |
1071 | |
1080 | |
1072 | void |
1081 | void |
1073 | rxvt_term::menu_hide () |
1082 | rxvt_term::menu_hide () |
1074 | { |
1083 | { |
1075 | menu_display (rxvt_menu_show); |
1084 | menu_display (&rxvt_term::menu_show); |
1076 | } |
1085 | } |
1077 | |
1086 | |
1078 | void |
1087 | void |
1079 | rxvt_term::menu_clear (menu_t *menu) |
1088 | rxvt_term::menu_clear (menu_t *menu) |
1080 | { |
1089 | { |
1081 | if (menu != NULL) |
1090 | if (menu != NULL) |
1082 | { |
1091 | { |
1083 | menuitem_t *item = menu->tail; |
1092 | menuitem_t *item = menu->tail; |
1084 | |
1093 | |
1085 | while (item != NULL) |
1094 | while (item != NULL) |
1086 | { |
1095 | { |
1087 | menuitem_free (menu, item); |
1096 | menuitem_free (menu, item); |
1088 | /* it didn't get freed ... why? */ |
1097 | /* it didn't get freed ... why? */ |
… | |
… | |
1095 | } |
1104 | } |
1096 | |
1105 | |
1097 | void |
1106 | void |
1098 | rxvt_term::menubar_clear () |
1107 | rxvt_term::menubar_clear () |
1099 | { |
1108 | { |
1100 | bar_t *CurrentBar = CurrentBar; |
|
|
1101 | |
|
|
1102 | if (CurrentBar != NULL) |
1109 | if (CurrentBar != NULL) |
1103 | { |
1110 | { |
1104 | menu_t *menu = CurrentBar->tail; |
1111 | menu_t *menu = CurrentBar->tail; |
1105 | |
1112 | |
1106 | while (menu != NULL) |
1113 | while (menu != NULL) |
1107 | { |
1114 | { |
1108 | menu_t *prev = menu->prev; |
1115 | menu_t *prev = menu->prev; |
1109 | |
1116 | |
1110 | menu_delete (menu); |
1117 | menu_delete (menu); |
1111 | menu = prev; |
1118 | menu = prev; |
1112 | } |
1119 | } |
1113 | CurrentBar->head = CurrentBar->tail = NULL; |
1120 | CurrentBar->head = CurrentBar->tail = NULL; |
… | |
… | |
1115 | if (CurrentBar->title) |
1122 | if (CurrentBar->title) |
1116 | { |
1123 | { |
1117 | free (CurrentBar->title); |
1124 | free (CurrentBar->title); |
1118 | CurrentBar->title = NULL; |
1125 | CurrentBar->title = NULL; |
1119 | } |
1126 | } |
|
|
1127 | |
1120 | menuarrow_free (0); /* remove all arrow functions */ |
1128 | menuarrow_free (0); /* remove all arrow functions */ |
1121 | } |
1129 | } |
|
|
1130 | |
1122 | ActiveMenu = NULL; |
1131 | ActiveMenu = NULL; |
1123 | } |
1132 | } |
1124 | |
1133 | |
1125 | #if (MENUBAR_MAX > 1) |
1134 | #if (MENUBAR_MAX > 1) |
1126 | /* find if menu already exists */ |
1135 | /* find if menu already exists */ |
1127 | bar_t * |
1136 | bar_t * |
1128 | rxvt_term::menubar_find (const char *name) |
1137 | rxvt_term::menubar_find (const char *name) |
1129 | { |
1138 | { |
1130 | bar_t *bar = CurrentBar; |
1139 | bar_t *bar = CurrentBar; |
1131 | |
1140 | |
1132 | #ifdef DEBUG_MENUBAR_STACKING |
1141 | #ifdef DEBUG_MENUBAR_STACKING |
1133 | fprintf (stderr, "looking for [menu:%s] ...", name ? name : " (nil)"); |
1142 | fprintf (stderr, "looking for [menu:%s] ...", name ? name : " (nil)"); |
1134 | #endif |
1143 | #endif |
1135 | if (bar == NULL || name == NULL) |
1144 | if (bar == NULL || name == NULL) |
… | |
… | |
1159 | } |
1168 | } |
1160 | |
1169 | |
1161 | int |
1170 | int |
1162 | rxvt_term::menubar_push (const char *name) |
1171 | rxvt_term::menubar_push (const char *name) |
1163 | { |
1172 | { |
1164 | int ret = 1; |
1173 | int ret = 1; |
1165 | bar_t *bar; |
1174 | bar_t *bar; |
1166 | |
1175 | |
1167 | if (CurrentBar == NULL) |
1176 | if (CurrentBar == NULL) |
1168 | { |
1177 | { |
1169 | /* allocate first one */ |
1178 | /* allocate first one */ |
1170 | bar = (bar_t *) rxvt_malloc (sizeof (bar_t)); |
1179 | bar = (bar_t *) rxvt_malloc (sizeof (bar_t)); |
… | |
… | |
1218 | Nbars++; |
1227 | Nbars++; |
1219 | } |
1228 | } |
1220 | CurrentBar = bar; |
1229 | CurrentBar = bar; |
1221 | |
1230 | |
1222 | } |
1231 | } |
|
|
1232 | |
1223 | menubar_clear (); |
1233 | menubar_clear (); |
1224 | } |
1234 | } |
1225 | } |
1235 | } |
1226 | |
1236 | |
1227 | /* give menubar this name */ |
1237 | /* give menubar this name */ |
… | |
… | |
1272 | } |
1282 | } |
1273 | |
1283 | |
1274 | void |
1284 | void |
1275 | rxvt_action_decode (FILE *fp, action_t *act) |
1285 | rxvt_action_decode (FILE *fp, action_t *act) |
1276 | { |
1286 | { |
1277 | unsigned char *str; |
1287 | unsigned char *str; |
1278 | short len; |
1288 | short len; |
1279 | |
1289 | |
1280 | if (act == NULL || (len = act->len) == 0 || (str = act->str) == NULL) |
1290 | if (act == NULL || (len = act->len) == 0 || (str = act->str) == NULL) |
1281 | return; |
1291 | return; |
1282 | |
1292 | |
1283 | if (act->type == MenuTerminalAction) |
1293 | if (act->type == MenuTerminalAction) |
… | |
… | |
1306 | str++; |
1316 | str++; |
1307 | len--; |
1317 | len--; |
1308 | break; |
1318 | break; |
1309 | } |
1319 | } |
1310 | } |
1320 | } |
|
|
1321 | |
1311 | /* |
1322 | /* |
1312 | * control character form is preferred, since backslash-escaping |
1323 | * control character form is preferred, since backslash-escaping |
1313 | * can be really ugly looking when the backslashes themselves also |
1324 | * can be really ugly looking when the backslashes themselves also |
1314 | * have to be escaped to avoid Shell (or whatever scripting |
1325 | * have to be escaped to avoid Shell (or whatever scripting |
1315 | * language) interpretation |
1326 | * language) interpretation |
… | |
… | |
1341 | fprintf (fp, "\\%o", ch); |
1352 | fprintf (fp, "\\%o", ch); |
1342 | else |
1353 | else |
1343 | fprintf (fp, "%c", ch); |
1354 | fprintf (fp, "%c", ch); |
1344 | break; |
1355 | break; |
1345 | } |
1356 | } |
|
|
1357 | |
1346 | len--; |
1358 | len--; |
1347 | } |
1359 | } |
|
|
1360 | |
1348 | fprintf (fp, "\n"); |
1361 | fprintf (fp, "\n"); |
1349 | } |
1362 | } |
1350 | |
1363 | |
1351 | void |
1364 | void |
1352 | rxvt_menu_dump (FILE *fp, menu_t *menu) |
1365 | rxvt_menu_dump (FILE *fp, menu_t *menu) |
… | |
… | |
1394 | if (bar == NULL || fp == NULL) |
1407 | if (bar == NULL || fp == NULL) |
1395 | return; |
1408 | return; |
1396 | time (&t); |
1409 | time (&t); |
1397 | |
1410 | |
1398 | fprintf (fp, |
1411 | fprintf (fp, |
1399 | "# " APL_SUBCLASS " (%s) Pid: %u\n# Date: %s\n\n", |
1412 | "# " RESCLASS " (%s) Pid: %u\n# Date: %s\n\n", |
1400 | rs[Rs_name], (unsigned int)getpid (), ctime (&t)); |
1413 | rs[Rs_name], (unsigned int)getpid (), ctime (&t)); |
1401 | |
1414 | |
1402 | /* dump in reverse order */ |
1415 | /* dump in reverse order */ |
1403 | bar = CurrentBar->prev; |
1416 | bar = CurrentBar->prev; |
1404 | do |
1417 | do |
… | |
… | |
1458 | char *p, *file, *tag = NULL; |
1471 | char *p, *file, *tag = NULL; |
1459 | |
1472 | |
1460 | file = (char *)rxvt_File_find (filename, ".menu", rs[Rs_path]); |
1473 | file = (char *)rxvt_File_find (filename, ".menu", rs[Rs_path]); |
1461 | if (file == NULL) |
1474 | if (file == NULL) |
1462 | return; |
1475 | return; |
|
|
1476 | |
1463 | fp = fopen (file, "rb"); |
1477 | fp = fopen (file, "rb"); |
1464 | free (file); |
1478 | free (file); |
1465 | if (fp == NULL) |
1479 | if (fp == NULL) |
1466 | return; |
1480 | return; |
1467 | |
1481 | |
… | |
… | |
1573 | * user interface for building/deleting and otherwise managing menus |
1587 | * user interface for building/deleting and otherwise managing menus |
1574 | */ |
1588 | */ |
1575 | void |
1589 | void |
1576 | rxvt_term::menubar_dispatch (char *str) |
1590 | rxvt_term::menubar_dispatch (char *str) |
1577 | { |
1591 | { |
1578 | int n, cmd; |
1592 | int n, cmd; |
1579 | char *path, *name, *name2; |
1593 | char *path, *name, *name2; |
1580 | |
1594 | |
1581 | if (menubar_visible (r) && ActiveMenu != NULL) |
1595 | if (menubar_visible () && ActiveMenu != NULL) |
1582 | menubar_expose (); |
1596 | menubar_expose (); |
1583 | else |
1597 | else |
1584 | ActiveMenu = NULL; |
1598 | ActiveMenu = NULL; |
1585 | |
1599 | |
1586 | cmd = *str; |
1600 | cmd = *str; |
… | |
… | |
1674 | str += n; |
1688 | str += n; |
1675 | if (CurrentBar != NULL && !menu_readonly) |
1689 | if (CurrentBar != NULL && !menu_readonly) |
1676 | { |
1690 | { |
1677 | if (*str) |
1691 | if (*str) |
1678 | { |
1692 | { |
1679 | name = rxvt_realloc (CurrentBar->title, |
1693 | name = (char *)rxvt_realloc (CurrentBar->title, STRLEN (str) + 1); |
1680 | STRLEN (str) + 1); |
|
|
1681 | if (name != NULL) |
1694 | if (name != NULL) |
1682 | { |
1695 | { |
1683 | STRCPY (name, str); |
1696 | STRCPY (name, str); |
1684 | CurrentBar->title = name; |
1697 | CurrentBar->title = name; |
1685 | } |
1698 | } |
… | |
… | |
1693 | } |
1706 | } |
1694 | } |
1707 | } |
1695 | else if ((n = rxvt_Str_match (str, "pixmap:")) != 0) |
1708 | else if ((n = rxvt_Str_match (str, "pixmap:")) != 0) |
1696 | { |
1709 | { |
1697 | str += n; |
1710 | str += n; |
1698 | xterm_seq (XTerm_Pixmap, str, CHAR_ST); |
1711 | process_xterm_seq (XTerm_Pixmap, str, CHAR_ST); |
1699 | } |
1712 | } |
1700 | #if (MENUBAR_MAX > 1) |
1713 | #if (MENUBAR_MAX > 1) |
1701 | else if ((n = rxvt_Str_match (str, "rm")) != 0) |
1714 | else if ((n = rxvt_Str_match (str, "rm")) != 0) |
1702 | { |
1715 | { |
1703 | str += n; |
1716 | str += n; |
… | |
… | |
1741 | FILE *fp; |
1754 | FILE *fp; |
1742 | |
1755 | |
1743 | /* enough space to hold the results */ |
1756 | /* enough space to hold the results */ |
1744 | char buffer[32]; |
1757 | char buffer[32]; |
1745 | |
1758 | |
1746 | sprintf (buffer, "/tmp/" APL_SUBCLASS "-%u", |
1759 | sprintf (buffer, "/tmp/" RESCLASS "-%u", |
1747 | (unsigned int)getpid ()); |
1760 | (unsigned int)getpid ()); |
1748 | |
1761 | |
1749 | if ((fp = fopen (buffer, "wb")) != NULL) |
1762 | if ((fp = fopen (buffer, "wb")) != NULL) |
1750 | { |
1763 | { |
1751 | xterm_seq (XTerm_title, buffer, CHAR_ST); |
1764 | process_xterm_seq (XTerm_title, buffer, CHAR_ST); |
1752 | menubar_dump (fp); |
1765 | menubar_dump (fp); |
1753 | fclose (fp); |
1766 | fclose (fp); |
1754 | } |
1767 | } |
1755 | } |
1768 | } |
1756 | else if (!STRCMP (str, "next")) |
1769 | else if (!STRCMP (str, "next")) |
… | |
… | |
1833 | if (name != NULL || str != NULL) |
1846 | if (name != NULL || str != NULL) |
1834 | { |
1847 | { |
1835 | if (name == NULL || str == NULL || str <= (name + 1) |
1848 | if (name == NULL || str == NULL || str <= (name + 1) |
1836 | || (name > path && name[-1] != '/')) |
1849 | || (name > path && name[-1] != '/')) |
1837 | { |
1850 | { |
1838 | rxvt_print_error ("menu error <%s>\n", path); |
1851 | rxvt_warn ("menu error A<%s>, continuing.\n", path); |
1839 | break; |
1852 | break; |
1840 | } |
1853 | } |
1841 | if (str[1] == MENUITEM_BEG) |
1854 | if (str[1] == MENUITEM_BEG) |
1842 | { |
1855 | { |
1843 | name2 = (str + 2); |
1856 | name2 = (str + 2); |
1844 | str = STRCHR (name2, MENUITEM_END); |
1857 | str = STRCHR (name2, MENUITEM_END); |
1845 | |
1858 | |
1846 | if (str == NULL) |
1859 | if (str == NULL) |
1847 | { |
1860 | { |
1848 | rxvt_print_error ("menu error <%s>\n", path); |
1861 | rxvt_warn ("menu error B<%s>, continuing.\n", path); |
1849 | break; |
1862 | break; |
1850 | } |
1863 | } |
1851 | name2[-2] = '\0'; /* remove prev MENUITEM_END */ |
1864 | name2[-2] = '\0'; /* remove prev MENUITEM_END */ |
1852 | } |
1865 | } |
1853 | if (name > path && name[-1] == '/') |
1866 | if (name > path && name[-1] == '/') |
… | |
… | |
1996 | if (!Arrows_x) |
2009 | if (!Arrows_x) |
1997 | return; |
2010 | return; |
1998 | |
2011 | |
1999 | for (i = 0; i < NARROWS; i++) |
2012 | for (i = 0; i < NARROWS; i++) |
2000 | { |
2013 | { |
2001 | const int w = Width2Pixel (1); |
2014 | const int w = Width2Pixel (1); |
2002 | const int y = (menuBar_TotalHeight () - w) / 2; |
2015 | const int y = (menuBar_TotalHeight () - w) / 2; |
2003 | int x = Arrows_x + (5 * Width2Pixel (i)) / 4; |
2016 | int x = Arrows_x + (5 * Width2Pixel (i)) / 4; |
2004 | |
2017 | |
2005 | if (!name || name == Arrows[i].name) |
2018 | if (!name || name == Arrows[i].name) |
2006 | rxvt_Draw_Triangle (display->display, menuBar.win, top, bot, x, y, w, |
2019 | rxvt_Draw_Triangle (display->display, menuBar.win, top, bot, x, y, w, |
2007 | Arrows[i].name); |
2020 | Arrows[i].name); |
2008 | } |
2021 | } |
… | |
… | |
2010 | } |
2023 | } |
2011 | |
2024 | |
2012 | void |
2025 | void |
2013 | rxvt_term::menubar_expose () |
2026 | rxvt_term::menubar_expose () |
2014 | { |
2027 | { |
2015 | menu_t *menu; |
2028 | menu_t *menu; |
2016 | int x; |
2029 | int x; |
2017 | |
2030 | |
2018 | if (!menubar_visible (r) || menuBar.win == 0) |
2031 | if (!menubar_visible () || menuBar.win == 0) |
2019 | return; |
2032 | return; |
2020 | |
2033 | |
2021 | if (menubarGC == None) |
2034 | if (menubarGC == None) |
2022 | { |
2035 | { |
2023 | /* Create the graphics context */ |
2036 | /* Create the graphics context */ |
2024 | XGCValues gcvalue; |
2037 | XGCValues gcvalue; |
2025 | |
2038 | |
2026 | gcvalue.font = TermWin.font->fid; |
|
|
2027 | |
|
|
2028 | gcvalue.foreground = (XDEPTH <= 2 ? PixColors[Color_fg] |
2039 | gcvalue.foreground = (display->depth <= 2 ? PixColors[Color_fg] |
2029 | : PixColors[Color_Black]); |
2040 | : PixColors[Color_Black]); |
2030 | menubarGC = XCreateGC (display->display, menuBar.win, |
2041 | menubarGC = XCreateGC (display->display, menuBar.win, |
2031 | GCForeground | GCFont, &gcvalue); |
2042 | GCForeground, &gcvalue); |
2032 | |
2043 | |
2033 | } |
2044 | } |
2034 | /* make sure the font is correct */ |
2045 | /* make sure the font is correct */ |
2035 | XSetFont (display->display, menubarGC, TermWin.font->fid); |
|
|
2036 | XSetFont (display->display, botShadowGC, TermWin.font->fid); |
|
|
2037 | XClearWindow (display->display, menuBar.win); |
2046 | XClearWindow (display->display, menuBar.win); |
2038 | |
2047 | |
2039 | menu_hide_all (); |
2048 | menu_hide_all (); |
2040 | |
2049 | |
2041 | x = 0; |
2050 | x = 0; |
… | |
… | |
2053 | |
2062 | |
2054 | if (x >= TermWin.ncol) |
2063 | if (x >= TermWin.ncol) |
2055 | len = (TermWin.ncol - (menu->x + HSPACE)); |
2064 | len = (TermWin.ncol - (menu->x + HSPACE)); |
2056 | |
2065 | |
2057 | drawbox_menubar (menu->x, len, +1); |
2066 | drawbox_menubar (menu->x, len, +1); |
2058 | #ifdef USE_XIM |
2067 | draw_string (*menuBar.drawable, menubarGC, TermWin.fontset, |
2059 | if (TermWin.fontset) |
|
|
2060 | XmbDrawString (display->display, |
|
|
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 (display->display, menuBar.win, menubarGC, |
|
|
2068 | (Width2Pixel (menu->x) + Width2Pixel (HSPACE) / 2), |
2068 | (Width2Pixel (menu->x) + Width2Pixel (HSPACE) / 2), |
2069 | menuBar_height () - SHADOW, menu->name, len); |
2069 | SHADOW, menu->name, len); |
2070 | |
2070 | |
2071 | if (x >= TermWin.ncol) |
2071 | if (x >= TermWin.ncol) |
2072 | break; |
2072 | break; |
2073 | } |
2073 | } |
2074 | } |
2074 | } |
… | |
… | |
2125 | } |
2125 | } |
2126 | title[len] = '\0'; |
2126 | title[len] = '\0'; |
2127 | |
2127 | |
2128 | ncol -= (x + len + HSPACE); |
2128 | ncol -= (x + len + HSPACE); |
2129 | if (len > 0 && ncol >= 0) |
2129 | if (len > 0 && ncol >= 0) |
2130 | { |
2130 | draw_string (*menuBar.drawable, menubarGC, TermWin.fontset, |
2131 | #ifdef USE_XIM |
|
|
2132 | if (TermWin.fontset) |
|
|
2133 | XmbDrawString (display->display, |
|
|
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 (display->display, menuBar.win, menubarGC, |
|
|
2141 | Width2Pixel (x) + Width2Pixel (ncol + HSPACE) / 2, |
2131 | Width2Pixel (x) + Width2Pixel (ncol + HSPACE) / 2, |
2142 | menuBar_height () - SHADOW, title, len); |
2132 | SHADOW, title, len); |
2143 | } |
|
|
2144 | } |
2133 | } |
2145 | } |
2134 | } |
2146 | |
2135 | |
2147 | int |
2136 | int |
2148 | rxvt_term::menubar_mapping (int map) |
2137 | rxvt_term::menubar_mapping (int map) |
2149 | { |
2138 | { |
2150 | int change = 0; |
2139 | int change = 0; |
2151 | |
2140 | |
2152 | if (map && !menubar_visible (r)) |
2141 | if (map && !menubar_visible ()) |
2153 | { |
2142 | { |
2154 | menuBar.state = 1; |
2143 | menuBar.state = 1; |
2155 | if (menuBar.win == 0) |
2144 | if (menuBar.win == 0) |
2156 | return 0; |
2145 | return 0; |
2157 | XMapWindow (display->display, menuBar.win); |
2146 | XMapWindow (display->display, menuBar.win); |
2158 | change = 1; |
2147 | change = 1; |
2159 | } |
2148 | } |
2160 | else if (!map && menubar_visible (r)) |
2149 | else if (!map && menubar_visible ()) |
2161 | { |
2150 | { |
2162 | menubar_expose (); |
2151 | menubar_expose (); |
2163 | menuBar.state = 0; |
2152 | menuBar.state = 0; |
2164 | XUnmapWindow (display->display, menuBar.win); |
2153 | XUnmapWindow (display->display, menuBar.win); |
2165 | change = 1; |
2154 | change = 1; |
… | |
… | |
2169 | |
2158 | |
2170 | return change; |
2159 | return change; |
2171 | } |
2160 | } |
2172 | |
2161 | |
2173 | int |
2162 | int |
2174 | rxvt_term::menu_select (XButtonEvent *ev) |
2163 | rxvt_term::menu_select (XButtonEvent &ev) |
2175 | { |
2164 | { |
2176 | menuitem_t *thisitem, *item = NULL; |
2165 | menuitem_t *thisitem, *item = NULL; |
2177 | int this_y, y; |
2166 | int this_y, y; |
2178 | menu_t *ActiveMenu = ActiveMenu; |
|
|
2179 | |
2167 | |
2180 | Window unused_root, unused_child; |
2168 | Window unused_root, unused_child; |
2181 | int unused_root_x, unused_root_y; |
2169 | int unused_root_x, unused_root_y; |
2182 | unsigned int unused_mask; |
2170 | unsigned int unused_mask; |
2183 | |
2171 | |
2184 | if (ActiveMenu == NULL) |
2172 | if (ActiveMenu == NULL) |
2185 | return 0; |
2173 | return 0; |
2186 | |
2174 | |
2187 | XQueryPointer (display->display, ActiveMenu->win, |
2175 | XQueryPointer (display->display, ActiveMenu->win, |
2188 | &unused_root, &unused_child, |
2176 | &unused_root, &unused_child, |
2189 | &unused_root_x, &unused_root_y, |
2177 | &unused_root_x, &unused_root_y, |
2190 | & (ev->x), & (ev->y), &unused_mask); |
2178 | &ev.x, &ev.y, &unused_mask); |
2191 | |
2179 | |
2192 | if (ActiveMenu->parent != NULL && (ev->x < 0 || ev->y < 0)) |
2180 | if (ActiveMenu->parent != NULL && (ev.x < 0 || ev.y < 0)) |
2193 | { |
2181 | { |
2194 | menu_hide (); |
2182 | menu_hide (); |
2195 | return 1; |
2183 | return 1; |
2196 | } |
2184 | } |
|
|
2185 | |
2197 | /* determine the menu item corresponding to the Y index */ |
2186 | /* determine the menu item corresponding to the Y index */ |
2198 | y = SHADOW; |
2187 | y = SHADOW; |
2199 | if (ev->x >= 0 && ev->x <= (ActiveMenu->w - SHADOW)) |
2188 | if (ev.x >= 0 && ev.x <= (ActiveMenu->w - SHADOW)) |
2200 | { |
2189 | { |
2201 | for (item = ActiveMenu->head; item != NULL; item = item->next) |
2190 | for (item = ActiveMenu->head; item != NULL; item = item->next) |
2202 | { |
2191 | { |
2203 | int h = HEIGHT_TEXT + 2 * SHADOW; |
2192 | int h = HEIGHT_TEXT + 2 * SHADOW; |
2204 | |
2193 | |
2205 | if (isSeparator (item->name)) |
2194 | if (isSeparator (item->name)) |
2206 | h = HEIGHT_SEPARATOR; |
2195 | h = HEIGHT_SEPARATOR; |
2207 | else if (ev->y >= y && ev->y < (y + h)) |
2196 | else if (ev.y >= y && ev.y < (y + h)) |
2208 | break; |
2197 | break; |
|
|
2198 | |
2209 | y += h; |
2199 | y += h; |
2210 | } |
2200 | } |
2211 | } |
2201 | } |
|
|
2202 | |
2212 | if (item == NULL && ev->type == ButtonRelease) |
2203 | if (item == NULL && ev.type == ButtonRelease) |
2213 | { |
2204 | { |
2214 | menu_hide_all (); |
2205 | menu_hide_all (); |
2215 | return 0; |
2206 | return 0; |
2216 | } |
2207 | } |
|
|
2208 | |
2217 | thisitem = item; |
2209 | thisitem = item; |
2218 | this_y = y - SHADOW; |
2210 | this_y = y - SHADOW; |
2219 | |
2211 | |
2220 | /* erase the last item */ |
2212 | /* erase the last item */ |
2221 | if (ActiveMenu->item != NULL) |
2213 | if (ActiveMenu->item != NULL) |
2222 | { |
2214 | { |
2223 | if (ActiveMenu->item != thisitem) |
2215 | if (ActiveMenu->item != thisitem) |
2224 | { |
2216 | { |
2225 | for (y = 0, item = ActiveMenu->head; item != NULL; |
2217 | for (y = 0, item = ActiveMenu->head; item != NULL; item = item->next) |
2226 | item = item->next) |
|
|
2227 | { |
2218 | { |
2228 | int h; |
2219 | int h; |
2229 | |
2220 | |
2230 | if (isSeparator (item->name)) |
2221 | if (isSeparator (item->name)) |
2231 | h = HEIGHT_SEPARATOR; |
2222 | h = HEIGHT_SEPARATOR; |
2232 | else if (item == ActiveMenu->item) |
2223 | else if (item == ActiveMenu->item) |
2233 | { |
2224 | { |
2234 | /* erase old menuitem */ |
2225 | /* erase old menuitem */ |
2235 | drawbox_menuitem (y, 0); /* No Shadow */ |
2226 | drawbox_menuitem (y, 0); /* No Shadow */ |
2236 | if (item->entry.type == MenuSubMenu) |
2227 | if (item->entry.type == MenuSubMenu) |
2237 | drawtriangle (ActiveMenu->w, y, +1); |
2228 | drawtriangle (ActiveMenu->w, y, +1); |
|
|
2229 | |
2238 | break; |
2230 | break; |
2239 | } |
2231 | } |
2240 | else |
2232 | else |
2241 | h = HEIGHT_TEXT + 2 * SHADOW; |
2233 | h = HEIGHT_TEXT + 2 * SHADOW; |
|
|
2234 | |
2242 | y += h; |
2235 | y += h; |
2243 | } |
2236 | } |
2244 | } |
2237 | } |
2245 | else |
2238 | else |
2246 | { |
2239 | { |
2247 | switch (ev->type) |
2240 | switch (ev.type) |
2248 | { |
2241 | { |
2249 | case ButtonRelease: |
2242 | case ButtonRelease: |
2250 | switch (item->entry.type) |
2243 | switch (item->entry.type) |
2251 | { |
2244 | { |
2252 | case MenuLabel: |
2245 | case MenuLabel: |
… | |
… | |
2254 | menu_hide_all (); |
2247 | menu_hide_all (); |
2255 | break; |
2248 | break; |
2256 | |
2249 | |
2257 | case MenuAction: |
2250 | case MenuAction: |
2258 | case MenuTerminalAction: |
2251 | case MenuTerminalAction: |
2259 | drawbox_menuitem (_y, -1); |
2252 | drawbox_menuitem (this_y, -1); |
2260 | { |
|
|
2261 | #ifdef HAVE_NANOSLEEP |
2253 | #ifdef HAVE_NANOSLEEP |
2262 | struct timespec rqt; |
2254 | struct timespec rqt; |
2263 | |
2255 | |
2264 | rqt.tv_sec = 0; |
2256 | rqt.tv_sec = 0; |
2265 | rqt.tv_nsec = MENU_DELAY_USEC * 1000; |
2257 | rqt.tv_nsec = MENU_DELAY_USEC * 1000; |
2266 | nanosleep (&rqt, NULL); |
2258 | nanosleep (&rqt, NULL); |
2267 | #else |
2259 | #else |
2268 | /* use select for timing */ |
2260 | /* use select for timing */ |
2269 | struct timeval tv; |
2261 | struct timeval tv; |
2270 | |
2262 | |
2271 | tv.tv_sec = 0; |
2263 | tv.tv_sec = 0; |
2272 | tv.tv_usec = MENU_DELAY_USEC; |
2264 | tv.tv_usec = MENU_DELAY_USEC; |
2273 | select (0, NULL, NULL, NULL, &tv); |
2265 | select (0, NULL, NULL, NULL, &tv); |
2274 | #endif |
2266 | #endif |
2275 | |
|
|
2276 | } |
|
|
2277 | /* remove menu before sending keys to the application */ |
2267 | /* remove menu before sending keys to the application */ |
2278 | menu_hide_all (); |
2268 | menu_hide_all (); |
2279 | #ifndef DEBUG_MENU |
2269 | #ifndef DEBUG_MENU |
2280 | action_dispatch (& (item->entry.action)); |
2270 | action_dispatch (& (item->entry.action)); |
2281 | #else /* DEBUG_MENU */ |
2271 | #else /* DEBUG_MENU */ |
… | |
… | |
2292 | break; |
2282 | break; |
2293 | } |
2283 | } |
2294 | return 0; |
2284 | return 0; |
2295 | } |
2285 | } |
2296 | } |
2286 | } |
|
|
2287 | |
2297 | DoMenu: |
2288 | DoMenu: |
2298 | ActiveMenu->item = thisitem; |
2289 | ActiveMenu->item = thisitem; |
2299 | y = this_y; |
2290 | y = this_y; |
|
|
2291 | |
2300 | if (item != NULL) |
2292 | if (thisitem != NULL) |
2301 | { |
2293 | { |
2302 | item = ActiveMenu->item; |
2294 | item = ActiveMenu->item; |
2303 | if (item->entry.type != MenuLabel) |
2295 | if (item->entry.type != MenuLabel) |
2304 | drawbox_menuitem (y, +1); |
2296 | drawbox_menuitem (y, +1); |
|
|
2297 | |
2305 | if (item->entry.type == MenuSubMenu) |
2298 | if (item->entry.type == MenuSubMenu) |
2306 | { |
2299 | { |
2307 | int x; |
2300 | int x; |
2308 | |
2301 | |
2309 | drawtriangle (ActiveMenu->w, y, -1); |
2302 | drawtriangle (ActiveMenu->w, y, -1); |
2310 | |
2303 | |
2311 | x = ev->x + (ActiveMenu->parent |
2304 | x = ev.x + (ActiveMenu->parent |
2312 | ? ActiveMenu->x |
2305 | ? ActiveMenu->x |
2313 | : Width2Pixel (ActiveMenu->x)); |
2306 | : Width2Pixel (ActiveMenu->x)); |
2314 | |
2307 | |
2315 | if (x >= item->entry.submenu.menu->x) |
2308 | if (x >= item->entry.submenu.menu->x) |
2316 | { |
2309 | { |
… | |
… | |
2322 | } |
2315 | } |
2323 | return 0; |
2316 | return 0; |
2324 | } |
2317 | } |
2325 | |
2318 | |
2326 | void |
2319 | void |
2327 | rxvt_term::menubar_select (XButtonEvent *ev) |
2320 | rxvt_term::menubar_select (XButtonEvent &ev) |
2328 | { |
2321 | { |
2329 | menu_t *menu = NULL; |
2322 | menu_t *menu = NULL; |
2330 | |
2323 | |
2331 | /* determine the pulldown menu corresponding to the X index */ |
2324 | /* determine the pulldown menu corresponding to the X index */ |
2332 | if (ev->y >= 0 && ev->y <= menuBar_height () && CurrentBar != NULL) |
2325 | if (ev.y >= 0 && ev.y <= menuBar_height () && CurrentBar != NULL) |
2333 | { |
2326 | { |
2334 | for (menu = CurrentBar->head; menu != NULL; menu = menu->next) |
2327 | for (menu = CurrentBar->head; menu != NULL; menu = menu->next) |
2335 | { |
2328 | { |
2336 | int x = Width2Pixel (menu->x); |
2329 | int x = Width2Pixel (menu->x); |
2337 | int w = Width2Pixel (menu->len + HSPACE); |
2330 | int w = Width2Pixel (menu->len + HSPACE); |
2338 | |
2331 | |
2339 | if ((ev->x >= x && ev->x < x + w)) |
2332 | if ((ev.x >= x && ev.x < x + w)) |
2340 | break; |
2333 | break; |
2341 | } |
2334 | } |
2342 | } |
2335 | } |
2343 | switch (ev->type) |
2336 | switch (ev.type) |
2344 | { |
2337 | { |
2345 | case ButtonRelease: |
2338 | case ButtonRelease: |
2346 | menu_hide_all (); |
2339 | menu_hide_all (); |
2347 | break; |
2340 | break; |
2348 | |
2341 | |
2349 | case ButtonPress: |
2342 | case ButtonPress: |
2350 | if (menu == NULL && Arrows_x && ev->x >= Arrows_x) |
2343 | if (menu == NULL && Arrows_x && ev.x >= Arrows_x) |
2351 | { |
2344 | { |
2352 | int i; |
2345 | int i; |
2353 | |
2346 | |
2354 | for (i = 0; i < NARROWS; i++) |
2347 | for (i = 0; i < NARROWS; i++) |
2355 | { |
2348 | { |
2356 | if (ev->x >= (Arrows_x + (Width2Pixel (4 * i + i)) / 4) |
2349 | if (ev.x >= (Arrows_x + (Width2Pixel (4 * i + i)) / 4) |
2357 | && ev->x < (Arrows_x |
2350 | && ev.x < (Arrows_x |
2358 | + (Width2Pixel (4 * i + i + 4)) / 4)) |
2351 | + (Width2Pixel (4 * i + i + 4)) / 4)) |
2359 | { |
2352 | { |
2360 | draw_Arrows (Arrows[i].name, -1); |
2353 | draw_Arrows (Arrows[i].name, -1); |
2361 | { |
2354 | { |
2362 | #ifdef HAVE_NANOSLEEP |
2355 | #ifdef HAVE_NANOSLEEP |
… | |
… | |
2392 | { |
2385 | { |
2393 | fprintf (stderr, "%s\n", |
2386 | fprintf (stderr, "%s\n", |
2394 | CurrentBar->arrows[i].str); |
2387 | CurrentBar->arrows[i].str); |
2395 | } |
2388 | } |
2396 | #else /* DEBUG_MENUARROWS */ |
2389 | #else /* DEBUG_MENUARROWS */ |
2397 | if (CurrentBar == NULL |
2390 | if (CurrentBar == NULL || action_dispatch (&CurrentBar->arrows[i])) |
2398 | || rxvt_action_dispatch (r, |
|
|
2399 | & (CurrentBar->arrows[i])) |
|
|
2400 | ) |
|
|
2401 | { |
2391 | { |
2402 | if (Arrows[i].str != NULL && Arrows[i].str[0] != 0) |
2392 | if (Arrows[i].str != NULL && Arrows[i].str[0] != 0) |
2403 | tt_write ((Arrows[i].str + 1), |
2393 | tt_write ((Arrows[i].str + 1), |
2404 | Arrows[i].str[0]); |
2394 | Arrows[i].str[0]); |
2405 | } |
2395 | } |
… | |
… | |
2427 | /* |
2417 | /* |
2428 | * general dispatch routine, |
2418 | * general dispatch routine, |
2429 | * it would be nice to have `sticky' menus |
2419 | * it would be nice to have `sticky' menus |
2430 | */ |
2420 | */ |
2431 | void |
2421 | void |
2432 | rxvt_term::menubar_control (XButtonEvent *ev) |
2422 | rxvt_term::menubar_control (XButtonEvent &ev) |
2433 | { |
2423 | { |
2434 | switch (ev->type) |
2424 | switch (ev.type) |
2435 | { |
2425 | { |
2436 | case ButtonPress: |
2426 | case ButtonPress: |
2437 | if (ev->button == Button1) |
2427 | if (ev.button == Button1) |
2438 | menubar_select (ev); |
2428 | menubar_select (ev); |
2439 | break; |
2429 | break; |
2440 | |
2430 | |
2441 | case ButtonRelease: |
2431 | case ButtonRelease: |
2442 | if (ev->button == Button1) |
2432 | if (ev.button == Button1) |
2443 | menu_select (ev); |
2433 | menu_select (ev); |
2444 | break; |
2434 | break; |
2445 | |
2435 | |
2446 | case MotionNotify: |
2436 | case MotionNotify: |
2447 | while (XCheckTypedWindowEvent (display->display, TermWin.parent[0], |
2437 | while (XCheckTypedWindowEvent (display->display, TermWin.parent[0], |
2448 | MotionNotify, (XEvent *) ev)) ; |
2438 | MotionNotify, (XEvent *)&ev)) ; |
2449 | |
2439 | |
2450 | if (ActiveMenu) |
2440 | if (ActiveMenu) |
2451 | while (menu_select (ev)) ; |
2441 | while (menu_select (ev)) ; |
2452 | else |
2442 | else |
2453 | ev->y = -1; |
2443 | ev.y = -1; |
2454 | if (ev->y < 0) |
2444 | if (ev.y < 0) |
2455 | { |
2445 | { |
2456 | Window unused_root, unused_child; |
2446 | Window unused_root, unused_child; |
2457 | int unused_root_x, unused_root_y; |
2447 | int unused_root_x, unused_root_y; |
2458 | unsigned int unused_mask; |
2448 | unsigned int unused_mask; |
2459 | |
2449 | |
2460 | XQueryPointer (display->display, menuBar.win, |
2450 | XQueryPointer (display->display, menuBar.win, |
2461 | &unused_root, &unused_child, |
2451 | &unused_root, &unused_child, |
2462 | &unused_root_x, &unused_root_y, |
2452 | &unused_root_x, &unused_root_y, |
2463 | & (ev->x), & (ev->y), &unused_mask); |
2453 | &ev.x, &ev.y, &unused_mask); |
2464 | menubar_select (ev); |
2454 | menubar_select (ev); |
2465 | } |
2455 | } |
2466 | break; |
2456 | break; |
2467 | } |
2457 | } |
2468 | } |
2458 | } |