ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/menubar.C
(Generate patch)

Comparing rxvt-unicode/src/menubar.C (file contents):
Revision 1.9 by pcg, Tue Feb 24 00:02:44 2004 UTC vs.
Revision 1.12 by pcg, Wed Mar 3 04:07:52 2004 UTC

21 * refer.html (or refer.txt) contains up-to-date documentation. The 21 * 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. 22 * summary that appears at the end of this file was taken from there.
23 *----------------------------------------------------------------------*/ 23 *----------------------------------------------------------------------*/
24 24
25#include "../config.h" /* NECESSARY */ 25#include "../config.h" /* NECESSARY */
26
27#include <stdlib.h>
28#include <wchar.h>
29
26#include "rxvt.h" /* NECESSARY */ 30#include "rxvt.h" /* NECESSARY */
27#ifdef MENUBAR 31#ifdef MENUBAR
28#include "version.h" 32#include "version.h"
29#include "menubar.h" 33#include "menubar.h"
30#include "menubar.intpro" /* PROTOS for internal routines */ 34#include "menubar.intpro" /* PROTOS for internal routines */
43 { 'd', "\003\033[B" }, 47 { 'd', "\003\033[B" },
44 { 'r', "\003\033[C" } 48 { 'r', "\003\033[C" }
45 }; 49 };
46 50
47/*}}} */ 51/*}}} */
52
53static void
54draw_string (rxvt_drawable &d, GC gc, rxvt_fontset *fs, int x, int y, char *str, int len)
55{
56 mbstate mbs;
57
58 while (len)
59 {
60 wchar_t w;
61 int l = mbrtowc (&w, str, len, mbs);
62
63 if (l <= 0)
64 break;
65
66 len -= l;
67 str += l;
68
69 rxvt_font *font = (*fs)[fs->find_font (w)];
70 text_t ch = w;
71 font->draw (d, x, y, &ch, 1, Color_bg, Color_scroll);
72
73 x += font->width * wcwidth (w);
74 }
75}
48 76
49/* 77/*
50 * find an item called NAME in MENU 78 * find an item called NAME in MENU
51 */ 79 */
52menuitem_t * 80menuitem_t *
491 { 519 {
492 p++; 520 p++;
493 if (*p == '/') 521 if (*p == '/')
494 path = p; 522 path = p;
495 } 523 }
524
496 if (path[0] == '/') 525 if (path[0] == '/')
497 { 526 {
498 path++; 527 path++;
499 *menu = NULL; 528 *menu = NULL;
500 } 529 }
530
501 while ((p = STRCHR (path, '/')) != NULL) 531 while ((p = STRCHR (path, '/')) != NULL)
502 { 532 {
503 p[0] = '\0'; 533 p[0] = '\0';
504 if (path[0] == '\0') 534 if (path[0] == '\0')
505 return NULL; 535 return NULL;
536
506 if (!STRCMP (path, DOT)) 537 if (!STRCMP (path, DOT))
507 { 538 {
508 /* nothing to do */ 539 /* nothing to do */
509 } 540 }
510 else if (!STRCMP (path, DOTS)) 541 else if (!STRCMP (path, DOTS))
523 } 554 }
524 555
525 path = (p + 1); 556 path = (p + 1);
526 } 557 }
527 } 558 }
559
528 if (!STRCMP (path, DOTS)) 560 if (!STRCMP (path, DOTS))
529 { 561 {
530 path += STRLEN (DOTS); 562 path += STRLEN (DOTS);
531 if (*menu != NULL) 563 if (*menu != NULL)
532 *menu = (*menu)->parent; 564 *menu = (*menu)->parent;
533 return path; 565 return path;
534 } 566 }
567
535 /* find this menu */ 568 /* find this menu */
536 if (*menu == NULL) 569 if (*menu == NULL)
537 { 570 {
538 for (m = CurrentBar->tail; m != NULL; m = m->prev) 571 for (m = CurrentBar->tail; m != NULL; m = m->prev)
539 {
540 if (!STRCMP (path, m->name)) 572 if (!STRCMP (path, m->name))
541 break; 573 break;
542 }
543 } 574 }
544 else 575 else
545 { 576 {
546 /* find this menu */ 577 /* find this menu */
547 for (item = (*menu)->tail; item != NULL; item = item->prev) 578 for (item = (*menu)->tail; item != NULL; item = item->prev)
552 m = (item->entry.submenu.menu); 583 m = (item->entry.submenu.menu);
553 break; 584 break;
554 } 585 }
555 } 586 }
556 } 587 }
588
557 if (m != NULL) 589 if (m != NULL)
558 { 590 {
559 *menu = m; 591 *menu = m;
560 path += STRLEN (path); 592 path += STRLEN (path);
561 } 593 }
594
562 return path; 595 return path;
563} 596}
564 597
565/* 598/*
566 * delete this entire menu 599 * delete this entire menu
568menu_t * 601menu_t *
569rxvt_term::menu_delete (menu_t *menu) 602rxvt_term::menu_delete (menu_t *menu)
570{ 603{
571 menu_t *parent = NULL, *prev, *next; 604 menu_t *parent = NULL, *prev, *next;
572 menuitem_t *item; 605 menuitem_t *item;
573 bar_t *CurrentBar = CurrentBar;
574 606
575#ifdef DEBUG_STRICT 607#ifdef DEBUG_STRICT
576 assert (CurrentBar != NULL); 608 assert (CurrentBar != NULL);
577#endif 609#endif
578 610
618 } 650 }
619 651
620 item = menu->tail; 652 item = menu->tail;
621 while (item != NULL) 653 while (item != NULL)
622 { 654 {
623 menuitem_t *p = item->prev; 655 menuitem_t *p = item->prev;
624 656
625 menuitem_free (menu, item); 657 menuitem_free (menu, item);
626 item = p; 658 item = p;
627 } 659 }
628 660
629 if (menu->name != NULL)
630 free (menu->name); 661 free (menu->name);
631 free (menu); 662 free (menu);
632 663
633 return parent; 664 return parent;
634} 665}
635 666
636menu_t * 667menu_t *
637rxvt_term::menu_add (menu_t *parent, char *path) 668rxvt_term::menu_add (menu_t *parent, char *path)
638{ 669{
639 menu_t *menu; 670 menu_t *menu;
640 bar_t *CurrentBar = CurrentBar;
641 671
642#ifdef DEBUG_STRICT 672#ifdef DEBUG_STRICT
643 assert (CurrentBar != NULL); 673 assert (CurrentBar != NULL);
644#endif 674#endif
645 675
646 if (STRCHR (path, '/') != NULL) 676 if (STRCHR (path, '/') != NULL)
647 { 677 {
648 char *p; 678 char *p;
649 679
650 if (path[0] == '/') 680 if (path[0] == '/')
651 { 681 {
652 /* shouldn't happen */ 682 /* shouldn't happen */
653 path++; 683 path++;
681 /* initialize head/tail */ 711 /* initialize head/tail */
682 menu->head = menu->tail = NULL; 712 menu->head = menu->tail = NULL;
683 menu->prev = menu->next = NULL; 713 menu->prev = menu->next = NULL;
684 714
685 menu->win = None; 715 menu->win = None;
716 menu->drawable = 0;
686 menu->x = menu->y = menu->w = menu->h = 0; 717 menu->x = menu->y = menu->w = menu->h = 0;
687 menu->item = NULL; 718 menu->item = NULL;
688 719
689 /* add to tail of list */ 720 /* add to tail of list */
690 if (parent == NULL) 721 if (parent == NULL)
779 w = Height2Pixel (1) - 2 * SHADOW; 810 w = Height2Pixel (1) - 2 * SHADOW;
780 811
781 x -= SHADOW + (3 * w / 2); 812 x -= SHADOW + (3 * w / 2);
782 y += SHADOW * 3; 813 y += SHADOW * 3;
783 814
784 rxvt_Draw_Triangle (display->display, ActiveMenu->win, top, bot, x, y, w, 815 rxvt_Draw_Triangle (display->display, ActiveMenu->win, top, bot, x, y, w, 'r');
785 'r');
786} 816}
787 817
788void 818void
789rxvt_term::drawbox_menuitem (int y, int state) 819rxvt_term::drawbox_menuitem (int y, int state)
790{ 820{
822 if (menu == NULL) 852 if (menu == NULL)
823 { 853 {
824 fprintf (stderr, "Top Level menu\n"); 854 fprintf (stderr, "Top Level menu\n");
825 return; 855 return;
826 } 856 }
857
827 fprintf (stderr, "menu %s ", menu->name); 858 fprintf (stderr, "menu %s ", menu->name);
828 if (menu->parent != NULL) 859 if (menu->parent != NULL)
829 { 860 {
830 menuitem_t *item; 861 menuitem_t *item;
831 862
835 && item->entry.submenu.menu == menu) 866 && item->entry.submenu.menu == menu)
836 { 867 {
837 break; 868 break;
838 } 869 }
839 } 870 }
871
840 if (item == NULL) 872 if (item == NULL)
841 { 873 {
842 fprintf (stderr, "is an orphan!\n"); 874 fprintf (stderr, "is an orphan!\n");
843 return; 875 return;
844 } 876 }
845 } 877 }
878
846 fprintf (stderr, "\n"); 879 fprintf (stderr, "\n");
847 rxvt_print_menu_ancestors (menu->parent); 880 rxvt_print_menu_ancestors (menu->parent);
848} 881}
849 882
850void 883void
893 926
894/* pop up/down the current menu and redraw the menuBar button */ 927/* pop up/down the current menu and redraw the menuBar button */
895void 928void
896rxvt_term::menu_show () 929rxvt_term::menu_show ()
897{ 930{
898 int x, y, xright; 931 int x, y, xright;
899 menu_t *ActiveMenu = ActiveMenu;
900 menuitem_t *item; 932 menuitem_t *item;
901 933
902 if (ActiveMenu == NULL) 934 if (ActiveMenu == NULL)
903 return; 935 return;
904 936
905 x = ActiveMenu->x; 937 x = ActiveMenu->x;
920 for (h = 0, item = ActiveMenu->head; item != NULL; item = item->next) 952 for (h = 0, item = ActiveMenu->head; item != NULL; item = item->next)
921 h += isSeparator (item->name) ? HEIGHT_SEPARATOR 953 h += isSeparator (item->name) ? HEIGHT_SEPARATOR
922 : HEIGHT_TEXT + 2 * SHADOW; 954 : HEIGHT_TEXT + 2 * SHADOW;
923 ActiveMenu->h = h + 2 * SHADOW; 955 ActiveMenu->h = h + 2 * SHADOW;
924 } 956 }
957
925 if (ActiveMenu->win == None) 958 if (ActiveMenu->win == None)
926 { 959 {
927 ActiveMenu->win = XCreateSimpleWindow (display->display, TermWin.vt, 960 ActiveMenu->win = XCreateSimpleWindow (display->display, TermWin.vt,
928 x, ActiveMenu->y, 961 x, ActiveMenu->y,
929 ActiveMenu->w, ActiveMenu->h, 962 ActiveMenu->w, ActiveMenu->h,
930 0, 963 0,
931 PixColors[Color_fg], 964 PixColors[Color_fg],
932 PixColors[Color_scroll]); 965 PixColors[Color_scroll]);
966 ActiveMenu->drawable = new rxvt_drawable (display, ActiveMenu->win);
933 XMapWindow (display->display, ActiveMenu->win); 967 XMapWindow (display->display, ActiveMenu->win);
934 } 968 }
969
935 rxvt_Draw_Shadow (display->display, ActiveMenu->win, 970 rxvt_Draw_Shadow (display->display, ActiveMenu->win,
936 topShadowGC, botShadowGC, 971 topShadowGC, botShadowGC,
937 0, 0, ActiveMenu->w, ActiveMenu->h); 972 0, 0, ActiveMenu->w, ActiveMenu->h);
938 973
939 /* determine the correct right-alignment */ 974 /* determine the correct right-alignment */
941 if (item->len2 > xright) 976 if (item->len2 > xright)
942 xright = item->len2; 977 xright = item->len2;
943 978
944 for (y = 0, item = ActiveMenu->head; item != NULL; item = item->next) 979 for (y = 0, item = ActiveMenu->head; item != NULL; item = item->next)
945 { 980 {
946 const int xoff = (SHADOW + Width2Pixel (HSPACE) / 2); 981 const int xoff = (SHADOW + Width2Pixel (HSPACE) / 2);
947 register int h; 982 register int h;
948 GC gc = menubarGC; 983 GC gc = menubarGC;
949 984
950 if (isSeparator (item->name)) 985 if (isSeparator (item->name))
951 { 986 {
952 rxvt_Draw_Shadow (display->display, ActiveMenu->win, 987 rxvt_Draw_Shadow (display->display, ActiveMenu->win,
953 topShadowGC, botShadowGC, 988 topShadowGC, botShadowGC,
959 { 994 {
960 char *name = item->name; 995 char *name = item->name;
961 int len = item->len; 996 int len = item->len;
962 997
963 if (item->entry.type == MenuLabel) 998 if (item->entry.type == MenuLabel)
964 {
965 gc = botShadowGC; 999 gc = botShadowGC;
966 }
967 else if (item->entry.type == MenuSubMenu) 1000 else if (item->entry.type == MenuSubMenu)
968 { 1001 {
969 int x1, y1; 1002 int x1, y1;
970 menuitem_t *it; 1003 menuitem_t *it;
971 menu_t *menu = item->entry.submenu.menu; 1004 menu_t *menu = item->entry.submenu.menu;
1003 } 1036 }
1004 else if (item->name2 && !STRCMP (name, item->name2)) 1037 else if (item->name2 && !STRCMP (name, item->name2))
1005 name = NULL; 1038 name = NULL;
1006 1039
1007 if (len && name) 1040 if (len && name)
1008 draw_string (display->display, ActiveMenu->win, gc, xoff, 1041 draw_string (*ActiveMenu->drawable, gc, TermWin.fontset,
1009 2 * SHADOW + y + TermWin.font->ascent + 1,
1010 name, len); 1042 xoff, 2 * SHADOW + y, name, len);
1011 1043
1012 len = item->len2; 1044 len = item->len2;
1013 name = item->name2; 1045 name = item->name2;
1014 1046
1015 if (len && name) 1047 if (len && name)
1016 draw_string (display->display, ActiveMenu->win, gc, 1048 draw_string (*ActiveMenu->drawable, gc, TermWin.fontset,
1017 ActiveMenu->w - (xoff + Width2Pixel (xright)), 1049 ActiveMenu->w - (xoff + Width2Pixel (xright)), 2 * SHADOW + y, name, len);
1018 2 * SHADOW + y + TermWin.font->ascent + 1,
1019 name, len);
1020 1050
1021 h = HEIGHT_TEXT + 2 * SHADOW; 1051 h = HEIGHT_TEXT + 2 * SHADOW;
1022 } 1052 }
1023 y += h; 1053 y += h;
1024 } 1054 }
1025} 1055}
1026 1056
1027void 1057void
1028rxvt_term::menu_display (void (rxvt_term::*update) ()) 1058rxvt_term::menu_display (void (rxvt_term::*update) ())
1029{ 1059{
1030 menu_t *ActiveMenu = ActiveMenu;
1031
1032 if (ActiveMenu == NULL) 1060 if (ActiveMenu == NULL)
1033 return; 1061 return;
1062
1063 delete ActiveMenu->drawable;
1034 if (ActiveMenu->win != None) 1064 if (ActiveMenu->win != None)
1035 XDestroyWindow (display->display, ActiveMenu->win); 1065 XDestroyWindow (display->display, ActiveMenu->win);
1036 ActiveMenu->win = None; 1066 ActiveMenu->win = None;
1037 ActiveMenu->item = NULL; 1067 ActiveMenu->item = NULL;
1038 1068
1039 if (ActiveMenu->parent == NULL) 1069 if (ActiveMenu->parent == NULL)
1040 drawbox_menubar (ActiveMenu->x, ActiveMenu->len, +1); 1070 drawbox_menubar (ActiveMenu->x, ActiveMenu->len, +1);
1071
1041 ActiveMenu = ActiveMenu->parent; 1072 ActiveMenu = ActiveMenu->parent;
1042 (this->*update) (); 1073 (this->*update) ();
1043} 1074}
1044 1075
1045void 1076void
1057void 1088void
1058rxvt_term::menu_clear (menu_t *menu) 1089rxvt_term::menu_clear (menu_t *menu)
1059{ 1090{
1060 if (menu != NULL) 1091 if (menu != NULL)
1061 { 1092 {
1062 menuitem_t *item = menu->tail; 1093 menuitem_t *item = menu->tail;
1063 1094
1064 while (item != NULL) 1095 while (item != NULL)
1065 { 1096 {
1066 menuitem_free (menu, item); 1097 menuitem_free (menu, item);
1067 /* it didn't get freed ... why? */ 1098 /* it didn't get freed ... why? */
1074} 1105}
1075 1106
1076void 1107void
1077rxvt_term::menubar_clear () 1108rxvt_term::menubar_clear ()
1078{ 1109{
1079 bar_t *CurrentBar = CurrentBar;
1080
1081 if (CurrentBar != NULL) 1110 if (CurrentBar != NULL)
1082 { 1111 {
1083 menu_t *menu = CurrentBar->tail; 1112 menu_t *menu = CurrentBar->tail;
1084 1113
1085 while (menu != NULL) 1114 while (menu != NULL)
1086 { 1115 {
1087 menu_t *prev = menu->prev; 1116 menu_t *prev = menu->prev;
1088 1117
1089 menu_delete (menu); 1118 menu_delete (menu);
1090 menu = prev; 1119 menu = prev;
1091 } 1120 }
1092 CurrentBar->head = CurrentBar->tail = NULL; 1121 CurrentBar->head = CurrentBar->tail = NULL;
1094 if (CurrentBar->title) 1123 if (CurrentBar->title)
1095 { 1124 {
1096 free (CurrentBar->title); 1125 free (CurrentBar->title);
1097 CurrentBar->title = NULL; 1126 CurrentBar->title = NULL;
1098 } 1127 }
1128
1099 menuarrow_free (0); /* remove all arrow functions */ 1129 menuarrow_free (0); /* remove all arrow functions */
1100 } 1130 }
1131
1101 ActiveMenu = NULL; 1132 ActiveMenu = NULL;
1102} 1133}
1103 1134
1104#if (MENUBAR_MAX > 1) 1135#if (MENUBAR_MAX > 1)
1105/* find if menu already exists */ 1136/* find if menu already exists */
1106bar_t * 1137bar_t *
1107rxvt_term::menubar_find (const char *name) 1138rxvt_term::menubar_find (const char *name)
1108{ 1139{
1109 bar_t *bar = CurrentBar; 1140 bar_t *bar = CurrentBar;
1110 1141
1111#ifdef DEBUG_MENUBAR_STACKING 1142#ifdef DEBUG_MENUBAR_STACKING
1112 fprintf (stderr, "looking for [menu:%s] ...", name ? name : " (nil)"); 1143 fprintf (stderr, "looking for [menu:%s] ...", name ? name : " (nil)");
1113#endif 1144#endif
1114 if (bar == NULL || name == NULL) 1145 if (bar == NULL || name == NULL)
1138} 1169}
1139 1170
1140int 1171int
1141rxvt_term::menubar_push (const char *name) 1172rxvt_term::menubar_push (const char *name)
1142{ 1173{
1143 int ret = 1; 1174 int ret = 1;
1144 bar_t *bar; 1175 bar_t *bar;
1145 1176
1146 if (CurrentBar == NULL) 1177 if (CurrentBar == NULL)
1147 { 1178 {
1148 /* allocate first one */ 1179 /* allocate first one */
1149 bar = (bar_t *) rxvt_malloc (sizeof (bar_t)); 1180 bar = (bar_t *) rxvt_malloc (sizeof (bar_t));
1197 Nbars++; 1228 Nbars++;
1198 } 1229 }
1199 CurrentBar = bar; 1230 CurrentBar = bar;
1200 1231
1201 } 1232 }
1233
1202 menubar_clear (); 1234 menubar_clear ();
1203 } 1235 }
1204 } 1236 }
1205 1237
1206 /* give menubar this name */ 1238 /* give menubar this name */
1251} 1283}
1252 1284
1253void 1285void
1254rxvt_action_decode (FILE *fp, action_t *act) 1286rxvt_action_decode (FILE *fp, action_t *act)
1255{ 1287{
1256 unsigned char *str; 1288 unsigned char *str;
1257 short len; 1289 short len;
1258 1290
1259 if (act == NULL || (len = act->len) == 0 || (str = act->str) == NULL) 1291 if (act == NULL || (len = act->len) == 0 || (str = act->str) == NULL)
1260 return; 1292 return;
1261 1293
1262 if (act->type == MenuTerminalAction) 1294 if (act->type == MenuTerminalAction)
1285 str++; 1317 str++;
1286 len--; 1318 len--;
1287 break; 1319 break;
1288 } 1320 }
1289 } 1321 }
1322
1290 /* 1323 /*
1291 * control character form is preferred, since backslash-escaping 1324 * control character form is preferred, since backslash-escaping
1292 * can be really ugly looking when the backslashes themselves also 1325 * can be really ugly looking when the backslashes themselves also
1293 * have to be escaped to avoid Shell (or whatever scripting 1326 * have to be escaped to avoid Shell (or whatever scripting
1294 * language) interpretation 1327 * language) interpretation
1320 fprintf (fp, "\\%o", ch); 1353 fprintf (fp, "\\%o", ch);
1321 else 1354 else
1322 fprintf (fp, "%c", ch); 1355 fprintf (fp, "%c", ch);
1323 break; 1356 break;
1324 } 1357 }
1358
1325 len--; 1359 len--;
1326 } 1360 }
1361
1327 fprintf (fp, "\n"); 1362 fprintf (fp, "\n");
1328} 1363}
1329 1364
1330void 1365void
1331rxvt_menu_dump (FILE *fp, menu_t *menu) 1366rxvt_menu_dump (FILE *fp, menu_t *menu)
1373 if (bar == NULL || fp == NULL) 1408 if (bar == NULL || fp == NULL)
1374 return; 1409 return;
1375 time (&t); 1410 time (&t);
1376 1411
1377 fprintf (fp, 1412 fprintf (fp,
1378 "# " APL_SUBCLASS " (%s) Pid: %u\n# Date: %s\n\n", 1413 "# " RESCLASS " (%s) Pid: %u\n# Date: %s\n\n",
1379 rs[Rs_name], (unsigned int)getpid (), ctime (&t)); 1414 rs[Rs_name], (unsigned int)getpid (), ctime (&t));
1380 1415
1381 /* dump in reverse order */ 1416 /* dump in reverse order */
1382 bar = CurrentBar->prev; 1417 bar = CurrentBar->prev;
1383 do 1418 do
1437 char *p, *file, *tag = NULL; 1472 char *p, *file, *tag = NULL;
1438 1473
1439 file = (char *)rxvt_File_find (filename, ".menu", rs[Rs_path]); 1474 file = (char *)rxvt_File_find (filename, ".menu", rs[Rs_path]);
1440 if (file == NULL) 1475 if (file == NULL)
1441 return; 1476 return;
1477
1442 fp = fopen (file, "rb"); 1478 fp = fopen (file, "rb");
1443 free (file); 1479 free (file);
1444 if (fp == NULL) 1480 if (fp == NULL)
1445 return; 1481 return;
1446 1482
1552 * user interface for building/deleting and otherwise managing menus 1588 * user interface for building/deleting and otherwise managing menus
1553 */ 1589 */
1554void 1590void
1555rxvt_term::menubar_dispatch (char *str) 1591rxvt_term::menubar_dispatch (char *str)
1556{ 1592{
1557 int n, cmd; 1593 int n, cmd;
1558 char *path, *name, *name2; 1594 char *path, *name, *name2;
1559 1595
1560 if (menubar_visible () && ActiveMenu != NULL) 1596 if (menubar_visible () && ActiveMenu != NULL)
1561 menubar_expose (); 1597 menubar_expose ();
1562 else 1598 else
1563 ActiveMenu = NULL; 1599 ActiveMenu = NULL;
1719 FILE *fp; 1755 FILE *fp;
1720 1756
1721 /* enough space to hold the results */ 1757 /* enough space to hold the results */
1722 char buffer[32]; 1758 char buffer[32];
1723 1759
1724 sprintf (buffer, "/tmp/" APL_SUBCLASS "-%u", 1760 sprintf (buffer, "/tmp/" RESCLASS "-%u",
1725 (unsigned int)getpid ()); 1761 (unsigned int)getpid ());
1726 1762
1727 if ((fp = fopen (buffer, "wb")) != NULL) 1763 if ((fp = fopen (buffer, "wb")) != NULL)
1728 { 1764 {
1729 xterm_seq (XTerm_title, buffer, CHAR_ST); 1765 xterm_seq (XTerm_title, buffer, CHAR_ST);
1974 if (!Arrows_x) 2010 if (!Arrows_x)
1975 return; 2011 return;
1976 2012
1977 for (i = 0; i < NARROWS; i++) 2013 for (i = 0; i < NARROWS; i++)
1978 { 2014 {
1979 const int w = Width2Pixel (1); 2015 const int w = Width2Pixel (1);
1980 const int y = (menuBar_TotalHeight () - w) / 2; 2016 const int y = (menuBar_TotalHeight () - w) / 2;
1981 int x = Arrows_x + (5 * Width2Pixel (i)) / 4; 2017 int x = Arrows_x + (5 * Width2Pixel (i)) / 4;
1982 2018
1983 if (!name || name == Arrows[i].name) 2019 if (!name || name == Arrows[i].name)
1984 rxvt_Draw_Triangle (display->display, menuBar.win, top, bot, x, y, w, 2020 rxvt_Draw_Triangle (display->display, menuBar.win, top, bot, x, y, w,
1985 Arrows[i].name); 2021 Arrows[i].name);
1986 } 2022 }
1988} 2024}
1989 2025
1990void 2026void
1991rxvt_term::menubar_expose () 2027rxvt_term::menubar_expose ()
1992{ 2028{
1993 menu_t *menu; 2029 menu_t *menu;
1994 int x; 2030 int x;
1995 2031
1996 if (!menubar_visible () || menuBar.win == 0) 2032 if (!menubar_visible () || menuBar.win == 0)
1997 return; 2033 return;
1998 2034
1999 if (menubarGC == None) 2035 if (menubarGC == None)
2000 { 2036 {
2001 /* Create the graphics context */ 2037 /* Create the graphics context */
2002 XGCValues gcvalue; 2038 XGCValues gcvalue;
2003
2004 gcvalue.font = TermWin.font->fid;
2005 2039
2006 gcvalue.foreground = (XDEPTH <= 2 ? PixColors[Color_fg] 2040 gcvalue.foreground = (XDEPTH <= 2 ? PixColors[Color_fg]
2007 : PixColors[Color_Black]); 2041 : PixColors[Color_Black]);
2008 menubarGC = XCreateGC (display->display, menuBar.win, 2042 menubarGC = XCreateGC (display->display, menuBar.win,
2009 GCForeground | GCFont, &gcvalue); 2043 GCForeground, &gcvalue);
2010 2044
2011 } 2045 }
2012 /* make sure the font is correct */ 2046 /* make sure the font is correct */
2013 XSetFont (display->display, menubarGC, TermWin.font->fid);
2014 XSetFont (display->display, botShadowGC, TermWin.font->fid);
2015 XClearWindow (display->display, menuBar.win); 2047 XClearWindow (display->display, menuBar.win);
2016 2048
2017 menu_hide_all (); 2049 menu_hide_all ();
2018 2050
2019 x = 0; 2051 x = 0;
2031 2063
2032 if (x >= TermWin.ncol) 2064 if (x >= TermWin.ncol)
2033 len = (TermWin.ncol - (menu->x + HSPACE)); 2065 len = (TermWin.ncol - (menu->x + HSPACE));
2034 2066
2035 drawbox_menubar (menu->x, len, +1); 2067 drawbox_menubar (menu->x, len, +1);
2036 draw_string (display->display, menuBar.win, menubarGC, 2068 draw_string (*menuBar.drawable, menubarGC, TermWin.fontset,
2037 (Width2Pixel (menu->x) + Width2Pixel (HSPACE) / 2), 2069 (Width2Pixel (menu->x) + Width2Pixel (HSPACE) / 2),
2038 menuBar_height () - SHADOW, menu->name, len); 2070 SHADOW, menu->name, len);
2039 2071
2040 if (x >= TermWin.ncol) 2072 if (x >= TermWin.ncol)
2041 break; 2073 break;
2042 } 2074 }
2043 } 2075 }
2094 } 2126 }
2095 title[len] = '\0'; 2127 title[len] = '\0';
2096 2128
2097 ncol -= (x + len + HSPACE); 2129 ncol -= (x + len + HSPACE);
2098 if (len > 0 && ncol >= 0) 2130 if (len > 0 && ncol >= 0)
2099 draw_string (display->display, menuBar.win, menubarGC, 2131 draw_string (*menuBar.drawable, menubarGC, TermWin.fontset,
2100 Width2Pixel (x) + Width2Pixel (ncol + HSPACE) / 2, 2132 Width2Pixel (x) + Width2Pixel (ncol + HSPACE) / 2,
2101 menuBar_height () - SHADOW, title, len); 2133 SHADOW, title, len);
2102 } 2134 }
2103} 2135}
2104 2136
2105int 2137int
2106rxvt_term::menubar_mapping (int map) 2138rxvt_term::menubar_mapping (int map)
2129} 2161}
2130 2162
2131int 2163int
2132rxvt_term::menu_select (XButtonEvent &ev) 2164rxvt_term::menu_select (XButtonEvent &ev)
2133{ 2165{
2134 menuitem_t *thisitem, *item = NULL; 2166 menuitem_t *thisitem, *item = NULL;
2135 int this_y, y; 2167 int this_y, y;
2136 menu_t *ActiveMenu = ActiveMenu;
2137 2168
2138 Window unused_root, unused_child; 2169 Window unused_root, unused_child;
2139 int unused_root_x, unused_root_y; 2170 int unused_root_x, unused_root_y;
2140 unsigned int unused_mask; 2171 unsigned int unused_mask;
2141 2172
2142 if (ActiveMenu == NULL) 2173 if (ActiveMenu == NULL)
2143 return 0; 2174 return 0;
2144 2175
2145 XQueryPointer (display->display, ActiveMenu->win, 2176 XQueryPointer (display->display, ActiveMenu->win,
2146 &unused_root, &unused_child, 2177 &unused_root, &unused_child,
2147 &unused_root_x, &unused_root_y, 2178 &unused_root_x, &unused_root_y,
2148 &ev.x, &ev.y, &unused_mask); 2179 &ev.x, &ev.y, &unused_mask);
2149 2180
2150 if (ActiveMenu->parent != NULL && (ev.x < 0 || ev.y < 0)) 2181 if (ActiveMenu->parent != NULL && (ev.x < 0 || ev.y < 0))
2151 { 2182 {
2152 menu_hide (); 2183 menu_hide ();
2153 return 1; 2184 return 1;
2154 } 2185 }
2186
2155 /* determine the menu item corresponding to the Y index */ 2187 /* determine the menu item corresponding to the Y index */
2156 y = SHADOW; 2188 y = SHADOW;
2157 if (ev.x >= 0 && ev.x <= (ActiveMenu->w - SHADOW)) 2189 if (ev.x >= 0 && ev.x <= (ActiveMenu->w - SHADOW))
2158 { 2190 {
2159 for (item = ActiveMenu->head; item != NULL; item = item->next) 2191 for (item = ActiveMenu->head; item != NULL; item = item->next)
2160 { 2192 {
2161 int h = HEIGHT_TEXT + 2 * SHADOW; 2193 int h = HEIGHT_TEXT + 2 * SHADOW;
2162 2194
2163 if (isSeparator (item->name)) 2195 if (isSeparator (item->name))
2164 h = HEIGHT_SEPARATOR; 2196 h = HEIGHT_SEPARATOR;
2165 else if (ev.y >= y && ev.y < (y + h)) 2197 else if (ev.y >= y && ev.y < (y + h))
2166 break; 2198 break;
2199
2167 y += h; 2200 y += h;
2168 } 2201 }
2169 } 2202 }
2203
2170 if (item == NULL && ev.type == ButtonRelease) 2204 if (item == NULL && ev.type == ButtonRelease)
2171 { 2205 {
2172 menu_hide_all (); 2206 menu_hide_all ();
2173 return 0; 2207 return 0;
2174 } 2208 }
2209
2175 thisitem = item; 2210 thisitem = item;
2176 this_y = y - SHADOW; 2211 this_y = y - SHADOW;
2177 2212
2178 /* erase the last item */ 2213 /* erase the last item */
2179 if (ActiveMenu->item != NULL) 2214 if (ActiveMenu->item != NULL)
2180 { 2215 {
2181 if (ActiveMenu->item != thisitem) 2216 if (ActiveMenu->item != thisitem)
2182 { 2217 {
2183 for (y = 0, item = ActiveMenu->head; item != NULL; 2218 for (y = 0, item = ActiveMenu->head; item != NULL; item = item->next)
2184 item = item->next)
2185 { 2219 {
2186 int h; 2220 int h;
2187 2221
2188 if (isSeparator (item->name)) 2222 if (isSeparator (item->name))
2189 h = HEIGHT_SEPARATOR; 2223 h = HEIGHT_SEPARATOR;
2190 else if (item == ActiveMenu->item) 2224 else if (item == ActiveMenu->item)
2191 { 2225 {
2192 /* erase old menuitem */ 2226 /* erase old menuitem */
2193 drawbox_menuitem (y, 0); /* No Shadow */ 2227 drawbox_menuitem (y, 0); /* No Shadow */
2194 if (item->entry.type == MenuSubMenu) 2228 if (item->entry.type == MenuSubMenu)
2195 drawtriangle (ActiveMenu->w, y, +1); 2229 drawtriangle (ActiveMenu->w, y, +1);
2230
2196 break; 2231 break;
2197 } 2232 }
2198 else 2233 else
2199 h = HEIGHT_TEXT + 2 * SHADOW; 2234 h = HEIGHT_TEXT + 2 * SHADOW;
2235
2200 y += h; 2236 y += h;
2201 } 2237 }
2202 } 2238 }
2203 else 2239 else
2204 { 2240 {
2213 break; 2249 break;
2214 2250
2215 case MenuAction: 2251 case MenuAction:
2216 case MenuTerminalAction: 2252 case MenuTerminalAction:
2217 drawbox_menuitem (this_y, -1); 2253 drawbox_menuitem (this_y, -1);
2218 {
2219#ifdef HAVE_NANOSLEEP 2254#ifdef HAVE_NANOSLEEP
2220 struct timespec rqt; 2255 struct timespec rqt;
2221 2256
2222 rqt.tv_sec = 0; 2257 rqt.tv_sec = 0;
2223 rqt.tv_nsec = MENU_DELAY_USEC * 1000; 2258 rqt.tv_nsec = MENU_DELAY_USEC * 1000;
2224 nanosleep (&rqt, NULL); 2259 nanosleep (&rqt, NULL);
2225#else 2260#else
2226 /* use select for timing */ 2261 /* use select for timing */
2227 struct timeval tv; 2262 struct timeval tv;
2228 2263
2229 tv.tv_sec = 0; 2264 tv.tv_sec = 0;
2230 tv.tv_usec = MENU_DELAY_USEC; 2265 tv.tv_usec = MENU_DELAY_USEC;
2231 select (0, NULL, NULL, NULL, &tv); 2266 select (0, NULL, NULL, NULL, &tv);
2232#endif 2267#endif
2233
2234 }
2235 /* remove menu before sending keys to the application */ 2268 /* remove menu before sending keys to the application */
2236 menu_hide_all (); 2269 menu_hide_all ();
2237#ifndef DEBUG_MENU 2270#ifndef DEBUG_MENU
2238 action_dispatch (& (item->entry.action)); 2271 action_dispatch (& (item->entry.action));
2239#else /* DEBUG_MENU */ 2272#else /* DEBUG_MENU */
2250 break; 2283 break;
2251 } 2284 }
2252 return 0; 2285 return 0;
2253 } 2286 }
2254 } 2287 }
2288
2255DoMenu: 2289DoMenu:
2256 ActiveMenu->item = thisitem; 2290 ActiveMenu->item = thisitem;
2257 y = this_y; 2291 y = this_y;
2292
2258 if (item != NULL) 2293 if (thisitem != NULL)
2259 { 2294 {
2260 item = ActiveMenu->item; 2295 item = ActiveMenu->item;
2261 if (item->entry.type != MenuLabel) 2296 if (item->entry.type != MenuLabel)
2262 drawbox_menuitem (y, +1); 2297 drawbox_menuitem (y, +1);
2298
2263 if (item->entry.type == MenuSubMenu) 2299 if (item->entry.type == MenuSubMenu)
2264 { 2300 {
2265 int x; 2301 int x;
2266 2302
2267 drawtriangle (ActiveMenu->w, y, -1); 2303 drawtriangle (ActiveMenu->w, y, -1);
2268 2304
2269 x = ev.x + (ActiveMenu->parent 2305 x = ev.x + (ActiveMenu->parent
2270 ? ActiveMenu->x 2306 ? ActiveMenu->x
2282} 2318}
2283 2319
2284void 2320void
2285rxvt_term::menubar_select (XButtonEvent &ev) 2321rxvt_term::menubar_select (XButtonEvent &ev)
2286{ 2322{
2287 menu_t *menu = NULL; 2323 menu_t *menu = NULL;
2288 2324
2289 /* determine the pulldown menu corresponding to the X index */ 2325 /* determine the pulldown menu corresponding to the X index */
2290 if (ev.y >= 0 && ev.y <= menuBar_height () && CurrentBar != NULL) 2326 if (ev.y >= 0 && ev.y <= menuBar_height () && CurrentBar != NULL)
2291 { 2327 {
2292 for (menu = CurrentBar->head; menu != NULL; menu = menu->next) 2328 for (menu = CurrentBar->head; menu != NULL; menu = menu->next)
2293 { 2329 {
2294 int x = Width2Pixel (menu->x); 2330 int x = Width2Pixel (menu->x);
2295 int w = Width2Pixel (menu->len + HSPACE); 2331 int w = Width2Pixel (menu->len + HSPACE);
2296 2332
2297 if ((ev.x >= x && ev.x < x + w)) 2333 if ((ev.x >= x && ev.x < x + w))
2298 break; 2334 break;
2299 } 2335 }
2300 } 2336 }
2398 menu_select (ev); 2434 menu_select (ev);
2399 break; 2435 break;
2400 2436
2401 case MotionNotify: 2437 case MotionNotify:
2402 while (XCheckTypedWindowEvent (display->display, TermWin.parent[0], 2438 while (XCheckTypedWindowEvent (display->display, TermWin.parent[0],
2403 MotionNotify, (XEvent *)&ev)) ; 2439 MotionNotify, (XEvent *)&ev)) ;
2404 2440
2405 if (ActiveMenu) 2441 if (ActiveMenu)
2406 while (menu_select (ev)) ; 2442 while (menu_select (ev)) ;
2407 else 2443 else
2408 ev.y = -1; 2444 ev.y = -1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines