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.3 by pcg, Tue Nov 25 11:52:42 2003 UTC vs.
Revision 1.5 by pcg, Sat Jan 31 03:27:45 2004 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines