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.22 by root, Fri Feb 4 11:41:23 2005 UTC

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
35static const struct 38static const struct
36 { 39 {
37 const char name; /* (l)eft, (u)p, (d)own, (r)ight */ 40 const char name; /* (l)eft, (u)p, (d)own, (r)ight */
38 const unsigned char str[5]; /* str[0] = STRLEN (str+1) */ 41 const unsigned char str[5]; /* str[0] = strlen (str+1) */
39 } 42 }
40Arrows[NARROWS] = { 43Arrows[NARROWS] = {
41 { 'l', "\003\033[D" }, 44 { 'l', "\003\033[D" },
42 { 'u', "\003\033[A" }, 45 { 'u', "\003\033[A" },
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/*}}} */
48 51
52static void
53draw_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}
75
49/* 76/*
50 * find an item called NAME in MENU 77 * find an item called NAME in MENU
51 */ 78 */
52menuitem_t * 79menuitem_t *
53rxvt_menuitem_find (const menu_t *menu, const char *name) 80rxvt_menuitem_find (const menu_t *menu, const char *name)
62 /* find the last item in the menu, this is good for separators */ 89 /* find the last item in the menu, this is good for separators */
63 for (item = menu->tail; item != NULL; item = item->prev) 90 for (item = menu->tail; item != NULL; item = item->prev)
64 { 91 {
65 if (item->entry.type == MenuSubMenu) 92 if (item->entry.type == MenuSubMenu)
66 { 93 {
67 if (!STRCMP (name, (item->entry.submenu.menu)->name)) 94 if (!strcmp (name, (item->entry.submenu.menu)->name))
68 break; 95 break;
69 } 96 }
70 else if ((isSeparator (name) && isSeparator (item->name)) 97 else if ((isSeparator (name) && isSeparator (item->name))
71 || !STRCMP (name, item->name)) 98 || !strcmp (name, item->name))
72 break; 99 break;
73 } 100 }
74 return item; 101 return item;
75} 102}
76 103
125rxvt_action_type (action_t *action, unsigned char *str) 152rxvt_action_type (action_t *action, unsigned char *str)
126{ 153{
127 unsigned int len; 154 unsigned int len;
128 155
129#if defined (DEBUG_MENU) || defined (DEBUG_MENUARROWS) 156#if defined (DEBUG_MENU) || defined (DEBUG_MENUARROWS)
130 len = STRLEN (str); 157 len = strlen (str);
131 fprintf (stderr, " (len %d) = %s\n", len, str); 158 fprintf (stderr, " (len %d) = %s\n", len, str);
132#else 159#else
133 len = rxvt_Str_escaped ((char *)str); 160 len = rxvt_Str_escaped ((char *)str);
134#endif 161#endif
135 162
236 beg = { NULL, 0 }, 263 beg = { NULL, 0 },
237 end = { NULL, 0 }, 264 end = { NULL, 0 },
238 *cur, 265 *cur,
239 parse[NARROWS]; 266 parse[NARROWS];
240 267
241 MEMSET (parse, 0, sizeof (parse)); 268 memset (parse, 0, sizeof (parse));
242 269
243 /* fprintf (stderr, "add arrows = `%s'\n", string); */ 270 /* fprintf (stderr, "add arrows = `%s'\n", string); */
244 for (p = string; p != NULL && *p; string = p) 271 for (p = string; p != NULL && *p; string = p)
245 { 272 {
246 p = (string + 3); 273 p = (string + 3);
267 cur->str = string; 294 cur->str = string;
268 cur->len = 0; 295 cur->len = 0;
269 296
270 if (cur == &end) 297 if (cur == &end)
271 { 298 {
272 p = STRCHR (string, '\0'); 299 p = strchr (string, '\0');
273 } 300 }
274 else 301 else
275 { 302 {
276 char *next = string; 303 char *next = string;
277 304
278 while (1) 305 while (1)
279 { 306 {
280 p = STRCHR (next, '<'); 307 p = strchr (next, '<');
281 if (p != NULL) 308 if (p != NULL)
282 { 309 {
283 if (p[1] && p[2] == '>') 310 if (p[1] && p[2] == '>')
284 break; 311 break;
285 /* parsed */ 312 /* parsed */
286 } 313 }
287 else 314 else
288 { 315 {
289 if (beg.str == NULL) /* no end needed */ 316 if (beg.str == NULL) /* no end needed */
290 p = STRCHR (next, '\0'); 317 p = strchr (next, '\0');
291 break; 318 break;
292 } 319 }
293 next = (p + 1); 320 next = (p + 1);
294 } 321 }
295 } 322 }
333 str = (unsigned char *) 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);
339 len += beg.len; 366 len += beg.len;
340 } 367 }
341 STRNCPY (str + len, parse[i].str, parse[i].len); 368 strncpy (str + len, parse[i].str, parse[i].len);
342 len += parse[i].len; 369 len += parse[i].len;
343 370
344 if (end.len) 371 if (end.len)
345 { 372 {
346 STRNCPY (str + len, end.str, end.len); 373 strncpy (str + len, end.str, end.len);
347 len += end.len; 374 len += end.len;
348 } 375 }
349 str[len] = '\0'; 376 str[len] = '\0';
350 377
351#ifdef DEBUG_MENUARROWS 378#ifdef DEBUG_MENUARROWS
405 item = (menuitem_t *) rxvt_malloc (sizeof (menuitem_t)); 432 item = (menuitem_t *) rxvt_malloc (sizeof (menuitem_t));
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 = (char *)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
417 /* add to tail of list */ 444 /* add to tail of list */
429 * add action 456 * add action
430 */ 457 */
431Item_Found: 458Item_Found:
432 if (name2 != NULL && item->name2 == NULL) 459 if (name2 != NULL && item->name2 == NULL)
433 { 460 {
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 = (char *)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;
445 len = STRLEN (action); 472 len = strlen (action);
446 473
447 if (len == 0 && item->name2 != NULL) 474 if (len == 0 && item->name2 != NULL)
448 { 475 {
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 = (unsigned char *)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);
460 } 487 }
461 /* new item and a possible increase in width */ 488 /* new item and a possible increase in width */
481#endif 508#endif
482 509
483 if (path[0] == '\0') 510 if (path[0] == '\0')
484 return path; 511 return path;
485 512
486 if (STRCHR (path, '/') != NULL) 513 if (strchr (path, '/') != NULL)
487 { 514 {
488 char *p = path; 515 char *p = path;
489 516
490 while ((p = STRCHR (p, '/')) != NULL) 517 while ((p = strchr (p, '/')) != NULL)
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))
511 { 541 {
512 if (*menu != NULL) 542 if (*menu != NULL)
513 *menu = (*menu)->parent; 543 *menu = (*menu)->parent;
514 } 544 }
515 else 545 else
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)
548 { 578 {
549 if (item->entry.type == MenuSubMenu 579 if (item->entry.type == MenuSubMenu
550 && !STRCMP (path, (item->entry.submenu.menu)->name)) 580 && !strcmp (path, (item->entry.submenu.menu)->name))
551 { 581 {
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
568menu_t * 600menu_t *
569rxvt_term::menu_delete (menu_t *menu) 601rxvt_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
636menu_t * 666menu_t *
637rxvt_term::menu_add (menu_t *parent, char *path) 667rxvt_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++;
654 parent = NULL; 683 parent = NULL;
655 } 684 }
656 while ((p = STRCHR (path, '/')) != NULL) 685 while ((p = strchr (path, '/')) != NULL)
657 { 686 {
658 p[0] = '\0'; 687 p[0] = '\0';
659 if (path[0] == '\0') 688 if (path[0] == '\0')
660 return NULL; 689 return NULL;
661 690
662 parent = menu_add (parent, path); 691 parent = menu_add (parent, path);
663 path = (p + 1); 692 path = (p + 1);
664 } 693 }
665 } 694 }
666 if (!STRCMP (path, DOTS)) 695 if (!strcmp (path, DOTS))
667 return (parent != NULL ? parent->parent : parent); 696 return (parent != NULL ? parent->parent : parent);
668 697
669 if (!STRCMP (path, DOT) || path[0] == '\0') 698 if (!strcmp (path, DOT) || path[0] == '\0')
670 return parent; 699 return parent;
671 700
672 /* allocate a new menu */ 701 /* allocate a new menu */
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 = (char *)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
788void 817void
789rxvt_term::drawbox_menuitem (int y, int state) 818rxvt_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
850void 882void
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 */
895void 927void
896rxvt_term::menu_show () 928rxvt_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 pix_colors[Color_fg],
932 PixColors[Color_scroll]); 964 pix_colors[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,
954 SHADOW, y + SHADOW + 1, 988 SHADOW, y + SHADOW + 1,
955 ActiveMenu->w - 2 * SHADOW, 0); 989 ActiveMenu->w - 2 * SHADOW, 0);
956 h = HEIGHT_SEPARATOR; 990 h = HEIGHT_SEPARATOR;
957 } 991 }
958 else 992 else
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;
999 y1 = (TermWin_TotalHeight () - menu->h); 1031 y1 = (TermWin_TotalHeight () - menu->h);
1000 1032
1001 menu->x = (x1 < 0 ? 0 : x1); 1033 menu->x = (x1 < 0 ? 0 : x1);
1002 menu->y = (y1 < 0 ? 0 : y1); 1034 menu->y = (y1 < 0 ? 0 : y1);
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 draw_string (display->display, ActiveMenu->win, gc, xoff, 1040 draw_string (*ActiveMenu->drawable, gc, TermWin.fontset[0],
1009 2 * SHADOW + y + TermWin.font->ascent + 1,
1010 name, len); 1041 xoff, 2 * SHADOW + y, name, len);
1011 1042
1012 len = item->len2; 1043 len = item->len2;
1013 name = item->name2; 1044 name = item->name2;
1014 1045
1015 if (len && name) 1046 if (len && name)
1016 draw_string (display->display, ActiveMenu->win, gc, 1047 draw_string (*ActiveMenu->drawable, gc, TermWin.fontset[0],
1017 ActiveMenu->w - (xoff + Width2Pixel (xright)), 1048 ActiveMenu->w - (xoff + Width2Pixel (xright)), 2 * SHADOW + y, name, len);
1018 2 * SHADOW + y + TermWin.font->ascent + 1,
1019 name, len);
1020 1049
1021 h = HEIGHT_TEXT + 2 * SHADOW; 1050 h = HEIGHT_TEXT + 2 * SHADOW;
1022 } 1051 }
1023 y += h; 1052 y += h;
1024 } 1053 }
1025} 1054}
1026 1055
1027void 1056void
1028rxvt_term::menu_display (void (rxvt_term::*update) ()) 1057rxvt_term::menu_display (void (rxvt_term::*update) ())
1029{ 1058{
1030 menu_t *ActiveMenu = ActiveMenu;
1031
1032 if (ActiveMenu == NULL) 1059 if (ActiveMenu == NULL)
1033 return; 1060 return;
1061
1062 delete ActiveMenu->drawable;
1034 if (ActiveMenu->win != None) 1063 if (ActiveMenu->win != None)
1035 XDestroyWindow (display->display, ActiveMenu->win); 1064 XDestroyWindow (display->display, ActiveMenu->win);
1036 ActiveMenu->win = None; 1065 ActiveMenu->win = None;
1037 ActiveMenu->item = NULL; 1066 ActiveMenu->item = NULL;
1038 1067
1039 if (ActiveMenu->parent == NULL) 1068 if (ActiveMenu->parent == NULL)
1040 drawbox_menubar (ActiveMenu->x, ActiveMenu->len, +1); 1069 drawbox_menubar (ActiveMenu->x, ActiveMenu->len, +1);
1070
1041 ActiveMenu = ActiveMenu->parent; 1071 ActiveMenu = ActiveMenu->parent;
1042 (this->*update) (); 1072 (this->*update) ();
1043} 1073}
1044 1074
1045void 1075void
1057void 1087void
1058rxvt_term::menu_clear (menu_t *menu) 1088rxvt_term::menu_clear (menu_t *menu)
1059{ 1089{
1060 if (menu != NULL) 1090 if (menu != NULL)
1061 { 1091 {
1062 menuitem_t *item = menu->tail; 1092 menuitem_t *item = menu->tail;
1063 1093
1064 while (item != NULL) 1094 while (item != NULL)
1065 { 1095 {
1066 menuitem_free (menu, item); 1096 menuitem_free (menu, item);
1067 /* it didn't get freed ... why? */ 1097 /* it didn't get freed ... why? */
1074} 1104}
1075 1105
1076void 1106void
1077rxvt_term::menubar_clear () 1107rxvt_term::menubar_clear ()
1078{ 1108{
1079 bar_t *CurrentBar = CurrentBar;
1080
1081 if (CurrentBar != NULL) 1109 if (CurrentBar != NULL)
1082 { 1110 {
1083 menu_t *menu = CurrentBar->tail; 1111 menu_t *menu = CurrentBar->tail;
1084 1112
1085 while (menu != NULL) 1113 while (menu != NULL)
1086 { 1114 {
1087 menu_t *prev = menu->prev; 1115 menu_t *prev = menu->prev;
1088 1116
1089 menu_delete (menu); 1117 menu_delete (menu);
1090 menu = prev; 1118 menu = prev;
1091 } 1119 }
1092 CurrentBar->head = CurrentBar->tail = NULL; 1120 CurrentBar->head = CurrentBar->tail = NULL;
1094 if (CurrentBar->title) 1122 if (CurrentBar->title)
1095 { 1123 {
1096 free (CurrentBar->title); 1124 free (CurrentBar->title);
1097 CurrentBar->title = NULL; 1125 CurrentBar->title = NULL;
1098 } 1126 }
1127
1099 menuarrow_free (0); /* remove all arrow functions */ 1128 menuarrow_free (0); /* remove all arrow functions */
1100 } 1129 }
1130
1101 ActiveMenu = NULL; 1131 ActiveMenu = NULL;
1102} 1132}
1103 1133
1104#if (MENUBAR_MAX > 1) 1134#if (MENUBAR_MAX > 1)
1105/* find if menu already exists */ 1135/* find if menu already exists */
1106bar_t * 1136bar_t *
1107rxvt_term::menubar_find (const char *name) 1137rxvt_term::menubar_find (const char *name)
1108{ 1138{
1109 bar_t *bar = CurrentBar; 1139 bar_t *bar = CurrentBar;
1110 1140
1111#ifdef DEBUG_MENUBAR_STACKING 1141#ifdef DEBUG_MENUBAR_STACKING
1112 fprintf (stderr, "looking for [menu:%s] ...", name ? name : " (nil)"); 1142 fprintf (stderr, "looking for [menu:%s] ...", name ? name : " (nil)");
1113#endif 1143#endif
1114 if (bar == NULL || name == NULL) 1144 if (bar == NULL || name == NULL)
1115 return NULL; 1145 return NULL;
1116 1146
1117 if (STRLEN (name) && STRCMP (name, "*")) 1147 if (strlen (name) && strcmp (name, "*"))
1118 { 1148 {
1119 do 1149 do
1120 { 1150 {
1121 if (!STRCMP (bar->name, name)) 1151 if (!strcmp (bar->name, name))
1122 { 1152 {
1123#ifdef DEBUG_MENUBAR_STACKING 1153#ifdef DEBUG_MENUBAR_STACKING
1124 fprintf (stderr, " found!\n"); 1154 fprintf (stderr, " found!\n");
1125#endif 1155#endif
1126 return bar; 1156 return bar;
1138} 1168}
1139 1169
1140int 1170int
1141rxvt_term::menubar_push (const char *name) 1171rxvt_term::menubar_push (const char *name)
1142{ 1172{
1143 int ret = 1; 1173 int ret = 1;
1144 bar_t *bar; 1174 bar_t *bar;
1145 1175
1146 if (CurrentBar == NULL) 1176 if (CurrentBar == NULL)
1147 { 1177 {
1148 /* allocate first one */ 1178 /* allocate first one */
1149 bar = (bar_t *) rxvt_malloc (sizeof (bar_t)); 1179 bar = (bar_t *) rxvt_malloc (sizeof (bar_t));
1150 1180
1151 MEMSET (bar, 0, sizeof (bar_t)); 1181 memset (bar, 0, sizeof (bar_t));
1152 /* circular linked-list */ 1182 /* circular linked-list */
1153 bar->next = bar->prev = bar; 1183 bar->next = bar->prev = bar;
1154 bar->head = bar->tail = NULL; 1184 bar->head = bar->tail = NULL;
1155 bar->title = NULL; 1185 bar->title = NULL;
1156 CurrentBar = bar; 1186 CurrentBar = bar;
1197 Nbars++; 1227 Nbars++;
1198 } 1228 }
1199 CurrentBar = bar; 1229 CurrentBar = bar;
1200 1230
1201 } 1231 }
1232
1202 menubar_clear (); 1233 menubar_clear ();
1203 } 1234 }
1204 } 1235 }
1205 1236
1206 /* give menubar this name */ 1237 /* give menubar this name */
1207 STRNCPY (CurrentBar->name, name, MAXNAME); 1238 strncpy (CurrentBar->name, name, MAXNAME);
1208 CurrentBar->name[MAXNAME - 1] = '\0'; 1239 CurrentBar->name[MAXNAME - 1] = '\0';
1209 1240
1210 return ret; 1241 return ret;
1211} 1242}
1212 1243
1245 1276
1246 free (CurrentBar); 1277 free (CurrentBar);
1247 CurrentBar = prev; 1278 CurrentBar = prev;
1248 } 1279 }
1249 } 1280 }
1250 while (CurrentBar && !STRCMP (name, "*")); 1281 while (CurrentBar && !strcmp (name, "*"));
1251} 1282}
1252 1283
1253void 1284void
1254rxvt_action_decode (FILE *fp, action_t *act) 1285rxvt_action_decode (FILE *fp, action_t *act)
1255{ 1286{
1256 unsigned char *str; 1287 unsigned char *str;
1257 short len; 1288 short len;
1258 1289
1259 if (act == NULL || (len = act->len) == 0 || (str = act->str) == NULL) 1290 if (act == NULL || (len = act->len) == 0 || (str = act->str) == NULL)
1260 return; 1291 return;
1261 1292
1262 if (act->type == MenuTerminalAction) 1293 if (act->type == MenuTerminalAction)
1285 str++; 1316 str++;
1286 len--; 1317 len--;
1287 break; 1318 break;
1288 } 1319 }
1289 } 1320 }
1321
1290 /* 1322 /*
1291 * control character form is preferred, since backslash-escaping 1323 * control character form is preferred, since backslash-escaping
1292 * can be really ugly looking when the backslashes themselves also 1324 * can be really ugly looking when the backslashes themselves also
1293 * have to be escaped to avoid Shell (or whatever scripting 1325 * have to be escaped to avoid Shell (or whatever scripting
1294 * language) interpretation 1326 * language) interpretation
1320 fprintf (fp, "\\%o", ch); 1352 fprintf (fp, "\\%o", ch);
1321 else 1353 else
1322 fprintf (fp, "%c", ch); 1354 fprintf (fp, "%c", ch);
1323 break; 1355 break;
1324 } 1356 }
1357
1325 len--; 1358 len--;
1326 } 1359 }
1360
1327 fprintf (fp, "\n"); 1361 fprintf (fp, "\n");
1328} 1362}
1329 1363
1330void 1364void
1331rxvt_menu_dump (FILE *fp, menu_t *menu) 1365rxvt_menu_dump (FILE *fp, menu_t *menu)
1345 else 1379 else
1346 rxvt_menu_dump (fp, item->entry.submenu.menu); 1380 rxvt_menu_dump (fp, item->entry.submenu.menu);
1347 break; 1381 break;
1348 1382
1349 case MenuLabel: 1383 case MenuLabel:
1350 fprintf (fp, "{%s}\n", (STRLEN (item->name) ? item->name : "-")); 1384 fprintf (fp, "{%s}\n", (strlen (item->name) ? item->name : "-"));
1351 break; 1385 break;
1352 1386
1353 case MenuTerminalAction: 1387 case MenuTerminalAction:
1354 case MenuAction: 1388 case MenuAction:
1355 fprintf (fp, "{%s}", item->name); 1389 fprintf (fp, "{%s}", item->name);
1356 if (item->name2 != NULL && STRLEN (item->name2)) 1390 if (item->name2 != NULL && strlen (item->name2))
1357 fprintf (fp, "{%s}", item->name2); 1391 fprintf (fp, "{%s}", item->name2);
1358 fprintf (fp, "\t"); 1392 fprintf (fp, "\t");
1359 rxvt_action_decode (fp, & (item->entry.action)); 1393 rxvt_action_decode (fp, & (item->entry.action));
1360 break; 1394 break;
1361 } 1395 }
1373 if (bar == NULL || fp == NULL) 1407 if (bar == NULL || fp == NULL)
1374 return; 1408 return;
1375 time (&t); 1409 time (&t);
1376 1410
1377 fprintf (fp, 1411 fprintf (fp,
1378 "# " APL_SUBCLASS " (%s) Pid: %u\n# Date: %s\n\n", 1412 "# " RESCLASS " (%s) Pid: %u\n# Date: %s\n\n",
1379 rs[Rs_name], (unsigned int)getpid (), ctime (&t)); 1413 rs[Rs_name], (unsigned int)getpid (), ctime (&t));
1380 1414
1381 /* dump in reverse order */ 1415 /* dump in reverse order */
1382 bar = CurrentBar->prev; 1416 bar = CurrentBar->prev;
1383 do 1417 do
1437 char *p, *file, *tag = NULL; 1471 char *p, *file, *tag = NULL;
1438 1472
1439 file = (char *)rxvt_File_find (filename, ".menu", rs[Rs_path]); 1473 file = (char *)rxvt_File_find (filename, ".menu", rs[Rs_path]);
1440 if (file == NULL) 1474 if (file == NULL)
1441 return; 1475 return;
1476
1442 fp = fopen (file, "rb"); 1477 fp = fopen (file, "rb");
1443 free (file); 1478 free (file);
1444 if (fp == NULL) 1479 if (fp == NULL)
1445 return; 1480 return;
1446 1481
1447#if (MENUBAR_MAX > 1) 1482#if (MENUBAR_MAX > 1)
1448 /* semi-colon delimited */ 1483 /* semi-colon delimited */
1449 if ((tag = STRCHR (filename, ';')) != NULL) 1484 if ((tag = strchr (filename, ';')) != NULL)
1450 { 1485 {
1451 tag++; 1486 tag++;
1452 if (*tag == '\0') 1487 if (*tag == '\0')
1453 tag = NULL; 1488 tag = NULL;
1454 } 1489 }
1552 * user interface for building/deleting and otherwise managing menus 1587 * user interface for building/deleting and otherwise managing menus
1553 */ 1588 */
1554void 1589void
1555rxvt_term::menubar_dispatch (char *str) 1590rxvt_term::menubar_dispatch (char *str)
1556{ 1591{
1557 int n, cmd; 1592 int n, cmd;
1558 char *path, *name, *name2; 1593 char *path, *name, *name2;
1559 1594
1560 if (menubar_visible () && ActiveMenu != NULL) 1595 if (menubar_visible () && ActiveMenu != NULL)
1561 menubar_expose (); 1596 menubar_expose ();
1562 else 1597 else
1563 ActiveMenu = NULL; 1598 ActiveMenu = NULL;
1594 if (str[0] == ':') 1629 if (str[0] == ':')
1595 { /* [:command:] */ 1630 { /* [:command:] */
1596 do 1631 do
1597 { 1632 {
1598 next++; 1633 next++;
1599 if ((next = STRCHR (next, ':')) == NULL) 1634 if ((next = strchr (next, ':')) == NULL)
1600 return; /* parse error */ 1635 return; /* parse error */
1601 } 1636 }
1602 while (next[1] != ']'); 1637 while (next[1] != ']');
1603 /* remove and skip ':]' */ 1638 /* remove and skip ':]' */
1604 *next = '\0'; 1639 *next = '\0';
1605 next += 2; 1640 next += 2;
1606 } 1641 }
1607 else 1642 else
1608 { 1643 {
1609 if ((next = STRCHR (next, ']')) == NULL) 1644 if ((next = strchr (next, ']')) == NULL)
1610 return; /* parse error */ 1645 return; /* parse error */
1611 /* remove and skip ']' */ 1646 /* remove and skip ']' */
1612 *next = '\0'; 1647 *next = '\0';
1613 next++; 1648 next++;
1614 } 1649 }
1622 menu_readonly = 0; 1657 menu_readonly = 0;
1623 menubar_dispatch (str + 1); 1658 menubar_dispatch (str + 1);
1624 menu_readonly = saved; 1659 menu_readonly = saved;
1625 } 1660 }
1626 /* these ones don't require menu stacking */ 1661 /* these ones don't require menu stacking */
1627 else if (!STRCMP (str, "clear")) 1662 else if (!strcmp (str, "clear"))
1628 { 1663 {
1629 menubar_clear (); 1664 menubar_clear ();
1630 } 1665 }
1631 else if (!STRCMP (str, "done") || rxvt_Str_match (str, "done:")) 1666 else if (!strcmp (str, "done") || rxvt_Str_match (str, "done:"))
1632 { 1667 {
1633 menu_readonly = 1; 1668 menu_readonly = 1;
1634 } 1669 }
1635 else if (!STRCMP (str, "show")) 1670 else if (!strcmp (str, "show"))
1636 { 1671 {
1637 map_menuBar (1); 1672 map_menuBar (1);
1638 menu_readonly = 1; 1673 menu_readonly = 1;
1639 } 1674 }
1640 else if (!STRCMP (str, "hide")) 1675 else if (!strcmp (str, "hide"))
1641 { 1676 {
1642 map_menuBar (0); 1677 map_menuBar (0);
1643 menu_readonly = 1; 1678 menu_readonly = 1;
1644 } 1679 }
1645 else if ((n = rxvt_Str_match (str, "read:")) != 0) 1680 else if ((n = rxvt_Str_match (str, "read:")) != 0)
1653 str += n; 1688 str += n;
1654 if (CurrentBar != NULL && !menu_readonly) 1689 if (CurrentBar != NULL && !menu_readonly)
1655 { 1690 {
1656 if (*str) 1691 if (*str)
1657 { 1692 {
1658 name = (char *)rxvt_realloc (CurrentBar->title, STRLEN (str) + 1); 1693 name = (char *)rxvt_realloc (CurrentBar->title, strlen (str) + 1);
1659 if (name != NULL) 1694 if (name != NULL)
1660 { 1695 {
1661 STRCPY (name, str); 1696 strcpy (name, str);
1662 CurrentBar->title = name; 1697 CurrentBar->title = name;
1663 } 1698 }
1664 menubar_expose (); 1699 menubar_expose ();
1665 } 1700 }
1666 else 1701 else
1671 } 1706 }
1672 } 1707 }
1673 else if ((n = rxvt_Str_match (str, "pixmap:")) != 0) 1708 else if ((n = rxvt_Str_match (str, "pixmap:")) != 0)
1674 { 1709 {
1675 str += n; 1710 str += n;
1676 xterm_seq (XTerm_Pixmap, str, CHAR_ST); 1711 process_xterm_seq (XTerm_Pixmap, str, CHAR_ST);
1677 } 1712 }
1678#if (MENUBAR_MAX > 1) 1713#if (MENUBAR_MAX > 1)
1679 else if ((n = rxvt_Str_match (str, "rm")) != 0) 1714 else if ((n = rxvt_Str_match (str, "rm")) != 0)
1680 { 1715 {
1681 str += n; 1716 str += n;
1711 } 1746 }
1712 1747
1713 if (CurrentBar != NULL) 1748 if (CurrentBar != NULL)
1714 menu_readonly = 0; /* allow menu build commands */ 1749 menu_readonly = 0; /* allow menu build commands */
1715 } 1750 }
1716 else if (!STRCMP (str, "dump")) 1751 else if (!strcmp (str, "dump"))
1717 { 1752 {
1718 /* dump current menubars to a file */ 1753 /* dump current menubars to a file */
1719 FILE *fp; 1754 FILE *fp;
1720 1755
1721 /* enough space to hold the results */ 1756 /* enough space to hold the results */
1722 char buffer[32]; 1757 char buffer[32];
1723 1758
1724 sprintf (buffer, "/tmp/" APL_SUBCLASS "-%u", 1759 sprintf (buffer, "/tmp/" RESCLASS "-%u",
1725 (unsigned int)getpid ()); 1760 (unsigned int)getpid ());
1726 1761
1727 if ((fp = fopen (buffer, "wb")) != NULL) 1762 if ((fp = fopen (buffer, "wb")) != NULL)
1728 { 1763 {
1729 xterm_seq (XTerm_title, buffer, CHAR_ST); 1764 process_xterm_seq (XTerm_title, buffer, CHAR_ST);
1730 menubar_dump (fp); 1765 menubar_dump (fp);
1731 fclose (fp); 1766 fclose (fp);
1732 } 1767 }
1733 } 1768 }
1734 else if (!STRCMP (str, "next")) 1769 else if (!strcmp (str, "next"))
1735 { 1770 {
1736 if (CurrentBar) 1771 if (CurrentBar)
1737 { 1772 {
1738 CurrentBar = CurrentBar->next; 1773 CurrentBar = CurrentBar->next;
1739 menu_readonly = 1; 1774 menu_readonly = 1;
1740 } 1775 }
1741 } 1776 }
1742 else if (!STRCMP (str, "prev")) 1777 else if (!strcmp (str, "prev"))
1743 { 1778 {
1744 if (CurrentBar) 1779 if (CurrentBar)
1745 { 1780 {
1746 CurrentBar = CurrentBar->prev; 1781 CurrentBar = CurrentBar->prev;
1747 menu_readonly = 1; 1782 menu_readonly = 1;
1748 } 1783 }
1749 } 1784 }
1750 else if (!STRCMP (str, "swap")) 1785 else if (!strcmp (str, "swap"))
1751 { 1786 {
1752 /* swap the top 2 menus */ 1787 /* swap the top 2 menus */
1753 if (CurrentBar) 1788 if (CurrentBar)
1754 { 1789 {
1755 bar_t *cbprev = CurrentBar->prev; 1790 bar_t *cbprev = CurrentBar->prev;
1804 1839
1805 name2 = NULL; 1840 name2 = NULL;
1806 /* parse STR, allow spaces inside (name) */ 1841 /* parse STR, allow spaces inside (name) */
1807 if (path[0] != '\0') 1842 if (path[0] != '\0')
1808 { 1843 {
1809 name = STRCHR (path, MENUITEM_BEG); 1844 name = strchr (path, MENUITEM_BEG);
1810 str = STRCHR (path, MENUITEM_END); 1845 str = strchr (path, MENUITEM_END);
1811 if (name != NULL || str != NULL) 1846 if (name != NULL || str != NULL)
1812 { 1847 {
1813 if (name == NULL || str == NULL || str <= (name + 1) 1848 if (name == NULL || str == NULL || str <= (name + 1)
1814 || (name > path && name[-1] != '/')) 1849 || (name > path && name[-1] != '/'))
1815 { 1850 {
1816 rxvt_print_error ("menu error <%s>\n", path); 1851 rxvt_warn ("menu error A<%s>, continuing.\n", path);
1817 break; 1852 break;
1818 } 1853 }
1819 if (str[1] == MENUITEM_BEG) 1854 if (str[1] == MENUITEM_BEG)
1820 { 1855 {
1821 name2 = (str + 2); 1856 name2 = (str + 2);
1822 str = STRCHR (name2, MENUITEM_END); 1857 str = strchr (name2, MENUITEM_END);
1823 1858
1824 if (str == NULL) 1859 if (str == NULL)
1825 { 1860 {
1826 rxvt_print_error ("menu error <%s>\n", path); 1861 rxvt_warn ("menu error B<%s>, continuing.\n", path);
1827 break; 1862 break;
1828 } 1863 }
1829 name2[-2] = '\0'; /* remove prev MENUITEM_END */ 1864 name2[-2] = '\0'; /* remove prev MENUITEM_END */
1830 } 1865 }
1831 if (name > path && name[-1] == '/') 1866 if (name > path && name[-1] == '/')
1853 if (path[0] != '\0') 1888 if (path[0] != '\0')
1854 { 1889 {
1855 int len; 1890 int len;
1856 1891
1857 path = menu_find_base (& (BuildMenu), path); 1892 path = menu_find_base (& (BuildMenu), path);
1858 len = STRLEN (path); 1893 len = strlen (path);
1859 1894
1860 /* don't allow menus called `*' */ 1895 /* don't allow menus called `*' */
1861 if (path[0] == '*') 1896 if (path[0] == '*')
1862 { 1897 {
1863 menu_clear (BuildMenu); 1898 menu_clear (BuildMenu);
1864 break; 1899 break;
1865 } 1900 }
1866 else if (len >= 2 && !STRCMP ((path + len - 2), "/*")) 1901 else if (len >= 2 && !strcmp ((path + len - 2), "/*"))
1867 { 1902 {
1868 path[len - 2] = '\0'; 1903 path[len - 2] = '\0';
1869 } 1904 }
1870 if (path[0] != '\0') 1905 if (path[0] != '\0')
1871 BuildMenu = menu_add (BuildMenu, path); 1906 BuildMenu = menu_add (BuildMenu, path);
1872 } 1907 }
1873 if (name != NULL && name[0] != '\0') 1908 if (name != NULL && name[0] != '\0')
1874 rxvt_menuitem_add (BuildMenu, 1909 rxvt_menuitem_add (BuildMenu,
1875 (STRCMP (name, SEPARATOR_NAME) ? name : ""), 1910 (strcmp (name, SEPARATOR_NAME) ? name : ""),
1876 name2, str); 1911 name2, str);
1877 break; 1912 break;
1878 1913
1879 case '-': /* delete menu entry */ 1914 case '-': /* delete menu entry */
1880 if (!STRCMP (path, "/*") && (name == NULL || name[0] == '\0')) 1915 if (!strcmp (path, "/*") && (name == NULL || name[0] == '\0'))
1881 { 1916 {
1882 menubar_clear (); 1917 menubar_clear ();
1883 BuildMenu = NULL; 1918 BuildMenu = NULL;
1884 menubar_expose (); 1919 menubar_expose ();
1885 break; 1920 break;
1888 { 1923 {
1889 int len; 1924 int len;
1890 menu_t *menu = BuildMenu; 1925 menu_t *menu = BuildMenu;
1891 1926
1892 path = menu_find_base (&menu, path); 1927 path = menu_find_base (&menu, path);
1893 len = STRLEN (path); 1928 len = strlen (path);
1894 1929
1895 /* submenu called `*' clears all menu items */ 1930 /* submenu called `*' clears all menu items */
1896 if (path[0] == '*') 1931 if (path[0] == '*')
1897 { 1932 {
1898 menu_clear (menu); 1933 menu_clear (menu);
1899 break; /* done */ 1934 break; /* done */
1900 } 1935 }
1901 else if (len >= 2 && !STRCMP (&path[len - 2], "/*")) 1936 else if (len >= 2 && !strcmp (&path[len - 2], "/*"))
1902 { 1937 {
1903 /* done */ 1938 /* done */
1904 break; 1939 break;
1905 } 1940 }
1906 else if (path[0] != '\0') 1941 else if (path[0] != '\0')
1919 { 1954 {
1920 const char *n1; 1955 const char *n1;
1921 menuitem_t *item; 1956 menuitem_t *item;
1922 menu_t *BuildMenu = BuildMenu; 1957 menu_t *BuildMenu = BuildMenu;
1923 1958
1924 n1 = STRCMP (name, SEPARATOR_NAME) ? name : ""; 1959 n1 = strcmp (name, SEPARATOR_NAME) ? name : "";
1925 item = rxvt_menuitem_find (BuildMenu, n1); 1960 item = rxvt_menuitem_find (BuildMenu, n1);
1926 if (item != NULL && item->entry.type != MenuSubMenu) 1961 if (item != NULL && item->entry.type != MenuSubMenu)
1927 { 1962 {
1928 menuitem_free (BuildMenu, item); 1963 menuitem_free (BuildMenu, item);
1929 1964
1974 if (!Arrows_x) 2009 if (!Arrows_x)
1975 return; 2010 return;
1976 2011
1977 for (i = 0; i < NARROWS; i++) 2012 for (i = 0; i < NARROWS; i++)
1978 { 2013 {
1979 const int w = Width2Pixel (1); 2014 const int w = Width2Pixel (1);
1980 const int y = (menuBar_TotalHeight () - w) / 2; 2015 const int y = (menuBar_TotalHeight () - w) / 2;
1981 int x = Arrows_x + (5 * Width2Pixel (i)) / 4; 2016 int x = Arrows_x + (5 * Width2Pixel (i)) / 4;
1982 2017
1983 if (!name || name == Arrows[i].name) 2018 if (!name || name == Arrows[i].name)
1984 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,
1985 Arrows[i].name); 2020 Arrows[i].name);
1986 } 2021 }
1987 XFlush (display->display); 2022 XFlush (display->display);
1988} 2023}
1989 2024
1990void 2025void
1991rxvt_term::menubar_expose () 2026rxvt_term::menubar_expose ()
1992{ 2027{
1993 menu_t *menu; 2028 menu_t *menu;
1994 int x; 2029 int x;
1995 2030
1996 if (!menubar_visible () || menuBar.win == 0) 2031 if (!menubar_visible () || menuBar.win == 0)
1997 return; 2032 return;
1998 2033
1999 if (menubarGC == None) 2034 if (menubarGC == None)
2000 { 2035 {
2001 /* Create the graphics context */ 2036 /* Create the graphics context */
2002 XGCValues gcvalue; 2037 XGCValues gcvalue;
2003 2038
2004 gcvalue.font = TermWin.font->fid;
2005
2006 gcvalue.foreground = (XDEPTH <= 2 ? PixColors[Color_fg] 2039 gcvalue.foreground = (display->depth <= 2 ? pix_colors[Color_fg]
2007 : PixColors[Color_Black]); 2040 : pix_colors[Color_Black]);
2008 menubarGC = XCreateGC (display->display, menuBar.win, 2041 menubarGC = XCreateGC (display->display, menuBar.win,
2009 GCForeground | GCFont, &gcvalue); 2042 GCForeground, &gcvalue);
2010 2043
2011 } 2044 }
2012 /* make sure the font is correct */ 2045 /* 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); 2046 XClearWindow (display->display, menuBar.win);
2016 2047
2017 menu_hide_all (); 2048 menu_hide_all ();
2018 2049
2019 x = 0; 2050 x = 0;
2031 2062
2032 if (x >= TermWin.ncol) 2063 if (x >= TermWin.ncol)
2033 len = (TermWin.ncol - (menu->x + HSPACE)); 2064 len = (TermWin.ncol - (menu->x + HSPACE));
2034 2065
2035 drawbox_menubar (menu->x, len, +1); 2066 drawbox_menubar (menu->x, len, +1);
2036 draw_string (display->display, menuBar.win, menubarGC, 2067 draw_string (*menuBar.drawable, menubarGC, TermWin.fontset[0],
2037 (Width2Pixel (menu->x) + Width2Pixel (HSPACE) / 2), 2068 (Width2Pixel (menu->x) + Width2Pixel (HSPACE) / 2),
2038 menuBar_height () - SHADOW, menu->name, len); 2069 SHADOW, menu->name, len);
2039 2070
2040 if (x >= TermWin.ncol) 2071 if (x >= TermWin.ncol)
2041 break; 2072 break;
2042 } 2073 }
2043 } 2074 }
2094 } 2125 }
2095 title[len] = '\0'; 2126 title[len] = '\0';
2096 2127
2097 ncol -= (x + len + HSPACE); 2128 ncol -= (x + len + HSPACE);
2098 if (len > 0 && ncol >= 0) 2129 if (len > 0 && ncol >= 0)
2099 draw_string (display->display, menuBar.win, menubarGC, 2130 draw_string (*menuBar.drawable, menubarGC, TermWin.fontset[0],
2100 Width2Pixel (x) + Width2Pixel (ncol + HSPACE) / 2, 2131 Width2Pixel (x) + Width2Pixel (ncol + HSPACE) / 2,
2101 menuBar_height () - SHADOW, title, len); 2132 SHADOW, title, len);
2102 } 2133 }
2103} 2134}
2104 2135
2105int 2136int
2106rxvt_term::menubar_mapping (int map) 2137rxvt_term::menubar_mapping (int map)
2129} 2160}
2130 2161
2131int 2162int
2132rxvt_term::menu_select (XButtonEvent &ev) 2163rxvt_term::menu_select (XButtonEvent &ev)
2133{ 2164{
2134 menuitem_t *thisitem, *item = NULL; 2165 menuitem_t *thisitem, *item = NULL;
2135 int this_y, y; 2166 int this_y, y;
2136 menu_t *ActiveMenu = ActiveMenu;
2137 2167
2138 Window unused_root, unused_child; 2168 Window unused_root, unused_child;
2139 int unused_root_x, unused_root_y; 2169 int unused_root_x, unused_root_y;
2140 unsigned int unused_mask; 2170 unsigned int unused_mask;
2141 2171
2142 if (ActiveMenu == NULL) 2172 if (ActiveMenu == NULL)
2143 return 0; 2173 return 0;
2144 2174
2145 XQueryPointer (display->display, ActiveMenu->win, 2175 XQueryPointer (display->display, ActiveMenu->win,
2146 &unused_root, &unused_child, 2176 &unused_root, &unused_child,
2147 &unused_root_x, &unused_root_y, 2177 &unused_root_x, &unused_root_y,
2148 &ev.x, &ev.y, &unused_mask); 2178 &ev.x, &ev.y, &unused_mask);
2149 2179
2150 if (ActiveMenu->parent != NULL && (ev.x < 0 || ev.y < 0)) 2180 if (ActiveMenu->parent != NULL && (ev.x < 0 || ev.y < 0))
2151 { 2181 {
2152 menu_hide (); 2182 menu_hide ();
2153 return 1; 2183 return 1;
2154 } 2184 }
2185
2155 /* determine the menu item corresponding to the Y index */ 2186 /* determine the menu item corresponding to the Y index */
2156 y = SHADOW; 2187 y = SHADOW;
2157 if (ev.x >= 0 && ev.x <= (ActiveMenu->w - SHADOW)) 2188 if (ev.x >= 0 && ev.x <= (ActiveMenu->w - SHADOW))
2158 { 2189 {
2159 for (item = ActiveMenu->head; item != NULL; item = item->next) 2190 for (item = ActiveMenu->head; item != NULL; item = item->next)
2160 { 2191 {
2161 int h = HEIGHT_TEXT + 2 * SHADOW; 2192 int h = HEIGHT_TEXT + 2 * SHADOW;
2162 2193
2163 if (isSeparator (item->name)) 2194 if (isSeparator (item->name))
2164 h = HEIGHT_SEPARATOR; 2195 h = HEIGHT_SEPARATOR;
2165 else if (ev.y >= y && ev.y < (y + h)) 2196 else if (ev.y >= y && ev.y < (y + h))
2166 break; 2197 break;
2198
2167 y += h; 2199 y += h;
2168 } 2200 }
2169 } 2201 }
2202
2170 if (item == NULL && ev.type == ButtonRelease) 2203 if (item == NULL && ev.type == ButtonRelease)
2171 { 2204 {
2172 menu_hide_all (); 2205 menu_hide_all ();
2173 return 0; 2206 return 0;
2174 } 2207 }
2208
2175 thisitem = item; 2209 thisitem = item;
2176 this_y = y - SHADOW; 2210 this_y = y - SHADOW;
2177 2211
2178 /* erase the last item */ 2212 /* erase the last item */
2179 if (ActiveMenu->item != NULL) 2213 if (ActiveMenu->item != NULL)
2180 { 2214 {
2181 if (ActiveMenu->item != thisitem) 2215 if (ActiveMenu->item != thisitem)
2182 { 2216 {
2183 for (y = 0, item = ActiveMenu->head; item != NULL; 2217 for (y = 0, item = ActiveMenu->head; item != NULL; item = item->next)
2184 item = item->next)
2185 { 2218 {
2186 int h; 2219 int h;
2187 2220
2188 if (isSeparator (item->name)) 2221 if (isSeparator (item->name))
2189 h = HEIGHT_SEPARATOR; 2222 h = HEIGHT_SEPARATOR;
2190 else if (item == ActiveMenu->item) 2223 else if (item == ActiveMenu->item)
2191 { 2224 {
2192 /* erase old menuitem */ 2225 /* erase old menuitem */
2193 drawbox_menuitem (y, 0); /* No Shadow */ 2226 drawbox_menuitem (y, 0); /* No Shadow */
2194 if (item->entry.type == MenuSubMenu) 2227 if (item->entry.type == MenuSubMenu)
2195 drawtriangle (ActiveMenu->w, y, +1); 2228 drawtriangle (ActiveMenu->w, y, +1);
2229
2196 break; 2230 break;
2197 } 2231 }
2198 else 2232 else
2199 h = HEIGHT_TEXT + 2 * SHADOW; 2233 h = HEIGHT_TEXT + 2 * SHADOW;
2234
2200 y += h; 2235 y += h;
2201 } 2236 }
2202 } 2237 }
2203 else 2238 else
2204 { 2239 {
2213 break; 2248 break;
2214 2249
2215 case MenuAction: 2250 case MenuAction:
2216 case MenuTerminalAction: 2251 case MenuTerminalAction:
2217 drawbox_menuitem (this_y, -1); 2252 drawbox_menuitem (this_y, -1);
2218 {
2219#ifdef HAVE_NANOSLEEP 2253#ifdef HAVE_NANOSLEEP
2220 struct timespec rqt; 2254 struct timespec rqt;
2221 2255
2222 rqt.tv_sec = 0; 2256 rqt.tv_sec = 0;
2223 rqt.tv_nsec = MENU_DELAY_USEC * 1000; 2257 rqt.tv_nsec = MENU_DELAY_USEC * 1000;
2224 nanosleep (&rqt, NULL); 2258 nanosleep (&rqt, NULL);
2225#else 2259#else
2226 /* use select for timing */ 2260 /* use select for timing */
2227 struct timeval tv; 2261 struct timeval tv;
2228 2262
2229 tv.tv_sec = 0; 2263 tv.tv_sec = 0;
2230 tv.tv_usec = MENU_DELAY_USEC; 2264 tv.tv_usec = MENU_DELAY_USEC;
2231 select (0, NULL, NULL, NULL, &tv); 2265 select (0, NULL, NULL, NULL, &tv);
2232#endif 2266#endif
2233
2234 }
2235 /* remove menu before sending keys to the application */ 2267 /* remove menu before sending keys to the application */
2236 menu_hide_all (); 2268 menu_hide_all ();
2237#ifndef DEBUG_MENU 2269#ifndef DEBUG_MENU
2238 action_dispatch (& (item->entry.action)); 2270 action_dispatch (& (item->entry.action));
2239#else /* DEBUG_MENU */ 2271#else /* DEBUG_MENU */
2250 break; 2282 break;
2251 } 2283 }
2252 return 0; 2284 return 0;
2253 } 2285 }
2254 } 2286 }
2287
2255DoMenu: 2288DoMenu:
2256 ActiveMenu->item = thisitem; 2289 ActiveMenu->item = thisitem;
2257 y = this_y; 2290 y = this_y;
2291
2258 if (item != NULL) 2292 if (thisitem != NULL)
2259 { 2293 {
2260 item = ActiveMenu->item; 2294 item = ActiveMenu->item;
2261 if (item->entry.type != MenuLabel) 2295 if (item->entry.type != MenuLabel)
2262 drawbox_menuitem (y, +1); 2296 drawbox_menuitem (y, +1);
2297
2263 if (item->entry.type == MenuSubMenu) 2298 if (item->entry.type == MenuSubMenu)
2264 { 2299 {
2265 int x; 2300 int x;
2266 2301
2267 drawtriangle (ActiveMenu->w, y, -1); 2302 drawtriangle (ActiveMenu->w, y, -1);
2268 2303
2269 x = ev.x + (ActiveMenu->parent 2304 x = ev.x + (ActiveMenu->parent
2270 ? ActiveMenu->x 2305 ? ActiveMenu->x
2282} 2317}
2283 2318
2284void 2319void
2285rxvt_term::menubar_select (XButtonEvent &ev) 2320rxvt_term::menubar_select (XButtonEvent &ev)
2286{ 2321{
2287 menu_t *menu = NULL; 2322 menu_t *menu = NULL;
2288 2323
2289 /* determine the pulldown menu corresponding to the X index */ 2324 /* determine the pulldown menu corresponding to the X index */
2290 if (ev.y >= 0 && ev.y <= menuBar_height () && CurrentBar != NULL) 2325 if (ev.y >= 0 && ev.y <= menuBar_height () && CurrentBar != NULL)
2291 { 2326 {
2292 for (menu = CurrentBar->head; menu != NULL; menu = menu->next) 2327 for (menu = CurrentBar->head; menu != NULL; menu = menu->next)
2293 { 2328 {
2294 int x = Width2Pixel (menu->x); 2329 int x = Width2Pixel (menu->x);
2295 int w = Width2Pixel (menu->len + HSPACE); 2330 int w = Width2Pixel (menu->len + HSPACE);
2296 2331
2297 if ((ev.x >= x && ev.x < x + w)) 2332 if ((ev.x >= x && ev.x < x + w))
2298 break; 2333 break;
2299 } 2334 }
2300 } 2335 }
2398 menu_select (ev); 2433 menu_select (ev);
2399 break; 2434 break;
2400 2435
2401 case MotionNotify: 2436 case MotionNotify:
2402 while (XCheckTypedWindowEvent (display->display, TermWin.parent[0], 2437 while (XCheckTypedWindowEvent (display->display, TermWin.parent[0],
2403 MotionNotify, (XEvent *)&ev)) ; 2438 MotionNotify, (XEvent *)&ev)) ;
2404 2439
2405 if (ActiveMenu) 2440 if (ActiveMenu)
2406 while (menu_select (ev)) ; 2441 while (menu_select (ev)) ;
2407 else 2442 else
2408 ev.y = -1; 2443 ev.y = -1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines