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.22 by root, Fri Feb 4 11:41:23 2005 UTC vs.
Revision 1.29 by root, Tue Jan 3 02:43:33 2006 UTC

31#ifdef MENUBAR 31#ifdef MENUBAR
32#include "version.h" 32#include "version.h"
33#include "menubar.h" 33#include "menubar.h"
34 34
35#define Menu_PixelWidth(menu) \ 35#define Menu_PixelWidth(menu) \
36 (2 * SHADOW + Width2Pixel ((menu)->width + 3 * HSPACE)) 36 (2 * MENU_SHADOW + Width2Pixel ((menu)->width + 3 * HSPACE))
37 37
38static const struct 38static const struct
39 { 39 {
40 const char name; /* (l)eft, (u)p, (d)own, (r)ight */ 40 const char name; /* (l)eft, (u)p, (d)own, (r)ight */
41 const unsigned char str[5]; /* str[0] = strlen (str+1) */ 41 const unsigned char str[5]; /* str[0] = strlen (str+1) */
753{ 753{
754 GC top, bot; 754 GC top, bot;
755 755
756 x = Width2Pixel (x); 756 x = Width2Pixel (x);
757 len = Width2Pixel (len + HSPACE); 757 len = Width2Pixel (len + HSPACE);
758 if (x >= TermWin.width) 758 if (x >= width)
759 return; 759 return;
760 else if (x + len >= TermWin.width) 760 else if (x + len >= width)
761 len = (TermWin_TotalWidth () - x); 761 len = (TermWin_TotalWidth () - x);
762 762
763#ifdef MENUBAR_SHADOW_IN 763#ifdef MENUBAR_SHADOW_IN
764 state = -state; 764 state = -state;
765#endif 765#endif
804 default: 804 default:
805 top = bot = scrollbarGC; 805 top = bot = scrollbarGC;
806 break; /* neutral */ 806 break; /* neutral */
807 } 807 }
808 808
809 w = Height2Pixel (1) - 2 * SHADOW; 809 w = Height2Pixel (1) - 2 * MENU_SHADOW;
810 810
811 x -= SHADOW + (3 * w / 2); 811 x -= MENU_SHADOW + (3 * w / 2);
812 y += SHADOW * 3; 812 y += MENU_SHADOW * 3;
813 813
814 rxvt_Draw_Triangle (display->display, ActiveMenu->win, top, bot, x, y, w, 'r'); 814 rxvt_Draw_Triangle (display->display, ActiveMenu->win, top, bot, x, y, w, 'r');
815} 815}
816 816
817void 817void
836 top = bot = scrollbarGC; 836 top = bot = scrollbarGC;
837 break; /* neutral */ 837 break; /* neutral */
838 } 838 }
839 839
840 rxvt_Draw_Shadow (display->display, ActiveMenu->win, top, bot, 840 rxvt_Draw_Shadow (display->display, ActiveMenu->win, top, bot,
841 SHADOW + 0, SHADOW + y, 841 MENU_SHADOW + 0, MENU_SHADOW + y,
842 ActiveMenu->w - 2 * (SHADOW), 842 ActiveMenu->w - 2 * (MENU_SHADOW),
843 HEIGHT_TEXT + 2 * SHADOW); 843 HEIGHT_TEXT + 2 * MENU_SHADOW);
844 XFlush (display->display); 844 XFlush (display->display);
845} 845}
846 846
847#ifdef DEBUG_MENU_LAYOUT 847#ifdef DEBUG_MENU_LAYOUT
848void 848void
942 x = Width2Pixel (x); 942 x = Width2Pixel (x);
943 943
944 ActiveMenu->y = 1; 944 ActiveMenu->y = 1;
945 ActiveMenu->w = Menu_PixelWidth (ActiveMenu); 945 ActiveMenu->w = Menu_PixelWidth (ActiveMenu);
946 946
947 if ((x + ActiveMenu->w) >= TermWin.width) 947 if ((x + ActiveMenu->w) >= width)
948 x = (TermWin_TotalWidth () - ActiveMenu->w); 948 x = (TermWin_TotalWidth () - ActiveMenu->w);
949 949
950 /* find the height */ 950 /* find the height */
951 for (h = 0, item = ActiveMenu->head; item != NULL; item = item->next) 951 for (h = 0, item = ActiveMenu->head; item != NULL; item = item->next)
952 h += isSeparator (item->name) ? HEIGHT_SEPARATOR 952 h += isSeparator (item->name) ? HEIGHT_SEPARATOR
953 : HEIGHT_TEXT + 2 * SHADOW; 953 : HEIGHT_TEXT + 2 * MENU_SHADOW;
954 ActiveMenu->h = h + 2 * SHADOW; 954 ActiveMenu->h = h + 2 * MENU_SHADOW;
955 } 955 }
956 956
957 if (ActiveMenu->win == None) 957 if (ActiveMenu->win == None)
958 { 958 {
959 ActiveMenu->win = XCreateSimpleWindow (display->display, TermWin.vt, 959 ActiveMenu->win = XCreateSimpleWindow (display->display, vt,
960 x, ActiveMenu->y, 960 x, ActiveMenu->y,
961 ActiveMenu->w, ActiveMenu->h, 961 ActiveMenu->w, ActiveMenu->h,
962 0, 962 0,
963 pix_colors[Color_fg], 963 pix_colors[Color_fg],
964 pix_colors[Color_scroll]); 964 pix_colors[Color_scroll]);
975 if (item->len2 > xright) 975 if (item->len2 > xright)
976 xright = item->len2; 976 xright = item->len2;
977 977
978 for (y = 0, item = ActiveMenu->head; item != NULL; item = item->next) 978 for (y = 0, item = ActiveMenu->head; item != NULL; item = item->next)
979 { 979 {
980 const int xoff = (SHADOW + Width2Pixel (HSPACE) / 2); 980 const int xoff = (MENU_SHADOW + Width2Pixel (HSPACE) / 2);
981 register int h; 981 register int h;
982 GC gc = menubarGC; 982 GC gc = menubarGC;
983 983
984 if (isSeparator (item->name)) 984 if (isSeparator (item->name))
985 { 985 {
986 rxvt_Draw_Shadow (display->display, ActiveMenu->win, 986 rxvt_Draw_Shadow (display->display, ActiveMenu->win,
987 topShadowGC, botShadowGC, 987 topShadowGC, botShadowGC,
988 SHADOW, y + SHADOW + 1, 988 MENU_SHADOW, y + MENU_SHADOW + 1,
989 ActiveMenu->w - 2 * SHADOW, 0); 989 ActiveMenu->w - 2 * MENU_SHADOW, 0);
990 h = HEIGHT_SEPARATOR; 990 h = HEIGHT_SEPARATOR;
991 } 991 }
992 else 992 else
993 { 993 {
994 char *name = item->name; 994 char *name = item->name;
1018 x1 += x; 1018 x1 += x;
1019 1019
1020 /* find the height of this submenu */ 1020 /* find the height of this submenu */
1021 for (h = 0, it = menu->head; it != NULL; it = it->next) 1021 for (h = 0, it = menu->head; it != NULL; it = it->next)
1022 h += isSeparator (it->name) ? HEIGHT_SEPARATOR 1022 h += isSeparator (it->name) ? HEIGHT_SEPARATOR
1023 : HEIGHT_TEXT + 2 * SHADOW; 1023 : HEIGHT_TEXT + 2 * MENU_SHADOW;
1024 menu->h = h + 2 * SHADOW; 1024 menu->h = h + 2 * MENU_SHADOW;
1025 1025
1026 /* ensure menu is in window limits */ 1026 /* ensure menu is in window limits */
1027 if ((x1 + menu->w) >= TermWin.width) 1027 if ((x1 + menu->w) >= width)
1028 x1 = (TermWin_TotalWidth () - menu->w); 1028 x1 = (TermWin_TotalWidth () - menu->w);
1029 1029
1030 if ((y1 + menu->h) >= TermWin.height) 1030 if ((y1 + menu->h) >= height)
1031 y1 = (TermWin_TotalHeight () - menu->h); 1031 y1 = (TermWin_TotalHeight () - menu->h);
1032 1032
1033 menu->x = (x1 < 0 ? 0 : x1); 1033 menu->x = (x1 < 0 ? 0 : x1);
1034 menu->y = (y1 < 0 ? 0 : y1); 1034 menu->y = (y1 < 0 ? 0 : y1);
1035 } 1035 }
1036 else if (item->name2 && !strcmp (name, item->name2)) 1036 else if (item->name2 && !strcmp (name, item->name2))
1037 name = NULL; 1037 name = NULL;
1038 1038
1039 if (len && name) 1039 if (len && name)
1040 draw_string (*ActiveMenu->drawable, gc, TermWin.fontset[0], 1040 draw_string (*ActiveMenu->drawable, gc, fontset[0],
1041 xoff, 2 * SHADOW + y, name, len); 1041 xoff, 2 * MENU_SHADOW + y, name, len);
1042 1042
1043 len = item->len2; 1043 len = item->len2;
1044 name = item->name2; 1044 name = item->name2;
1045 1045
1046 if (len && name) 1046 if (len && name)
1047 draw_string (*ActiveMenu->drawable, gc, TermWin.fontset[0], 1047 draw_string (*ActiveMenu->drawable, gc, fontset[0],
1048 ActiveMenu->w - (xoff + Width2Pixel (xright)), 2 * SHADOW + y, name, len); 1048 ActiveMenu->w - (xoff + Width2Pixel (xright)), 2 * MENU_SHADOW + y, name, len);
1049 1049
1050 h = HEIGHT_TEXT + 2 * SHADOW; 1050 h = HEIGHT_TEXT + 2 * MENU_SHADOW;
1051 } 1051 }
1052 y += h; 1052 y += h;
1053 } 1053 }
1054} 1054}
1055 1055
1563 /* what? ... skip this line */ 1563 /* what? ... skip this line */
1564 p[0] = COMMENT_CHAR; 1564 p[0] = COMMENT_CHAR;
1565 } 1565 }
1566 } 1566 }
1567 } 1567 }
1568
1568 /* 1569 /*
1569 * remove leading/trailing space 1570 * remove leading/trailing space
1570 * and strip-off leading/trailing quotes
1571 * skip blank or comment lines 1571 * skip blank or comment lines
1572 */ 1572 */
1573 rxvt_Str_trim (p); 1573 rxvt_Str_trim (p);
1574 if (*p && *p != '#') 1574 if (*p && *p != '#')
1575 { 1575 {
1944 break; 1944 break;
1945 } 1945 }
1946 else 1946 else
1947 BuildMenu = menu; 1947 BuildMenu = menu;
1948 } 1948 }
1949
1949 if (BuildMenu != NULL) 1950 if (BuildMenu != NULL)
1950 { 1951 {
1951 if (name == NULL || name[0] == '\0') 1952 if (name == NULL || name[0] == '\0')
1952 BuildMenu = menu_delete (BuildMenu); 1953 BuildMenu = menu_delete (BuildMenu);
1953 else 1954 else
1954 { 1955 {
1955 const char *n1; 1956 const char *n1;
1956 menuitem_t *item; 1957 menuitem_t *item;
1957 menu_t *BuildMenu = BuildMenu;
1958 1958
1959 n1 = strcmp (name, SEPARATOR_NAME) ? name : ""; 1959 n1 = strcmp (name, SEPARATOR_NAME) ? name : "";
1960 item = rxvt_menuitem_find (BuildMenu, n1); 1960 item = rxvt_menuitem_find (BuildMenu, n1);
1961 if (item != NULL && item->entry.type != MenuSubMenu) 1961 if (item != NULL && item->entry.type != MenuSubMenu)
1962 { 1962 {
1967 for (item = BuildMenu->head; item != NULL; 1967 for (item = BuildMenu->head; item != NULL;
1968 item = item->next) 1968 item = item->next)
1969 { 1969 {
1970 short l = item->len + item->len2; 1970 short l = item->len + item->len2;
1971 1971
1972 MAX_IT (BuildMenu->width, l); 1972 max_it (BuildMenu->width, l);
1973 } 1973 }
1974 } 1974 }
1975 } 1975 }
1976
1976 menubar_expose (); 1977 menubar_expose ();
1977 } 1978 }
1978 break; 1979 break;
1979 } 1980 }
1980 break; 1981 break;
2058 2059
2059#ifdef DEBUG_MENU_LAYOUT 2060#ifdef DEBUG_MENU_LAYOUT
2060 rxvt_print_menu_descendants (menu); 2061 rxvt_print_menu_descendants (menu);
2061#endif 2062#endif
2062 2063
2063 if (x >= TermWin.ncol) 2064 if (x >= ncol)
2064 len = (TermWin.ncol - (menu->x + HSPACE)); 2065 len = (ncol - (menu->x + HSPACE));
2065 2066
2066 drawbox_menubar (menu->x, len, +1); 2067 drawbox_menubar (menu->x, len, +1);
2067 draw_string (*menuBar.drawable, menubarGC, TermWin.fontset[0], 2068 draw_string (*menuBar.drawable, menubarGC, fontset[0],
2068 (Width2Pixel (menu->x) + Width2Pixel (HSPACE) / 2), 2069 (Width2Pixel (menu->x) + Width2Pixel (HSPACE) / 2),
2069 SHADOW, menu->name, len); 2070 MENU_SHADOW, menu->name, len);
2070 2071
2071 if (x >= TermWin.ncol) 2072 if (x >= ncol)
2072 break; 2073 break;
2073 } 2074 }
2074 } 2075 }
2075 drawbox_menubar (x, TermWin.ncol, (CurrentBar ? +1 : -1)); 2076 drawbox_menubar (x, ncol, (CurrentBar ? +1 : -1));
2076 2077
2077 /* add the menuBar title, if it exists and there's plenty of room */ 2078 /* add the menuBar title, if it exists and there's plenty of room */
2078 Arrows_x = 0; 2079 Arrows_x = 0;
2079 if (x < TermWin.ncol) 2080 if (x < ncol)
2080 { 2081 {
2081 const char *str; 2082 const char *str;
2082 int ncol;
2083 unsigned int len; 2083 unsigned int len;
2084 char title[256]; 2084 char title[256];
2085 2085
2086 ncol = (int)TermWin.ncol;
2087 if (x < (ncol - (NARROWS + 1))) 2086 if (x < (ncol - (NARROWS + 1)))
2088 { 2087 {
2089 ncol -= (NARROWS + 1); 2088 ncol -= (NARROWS + 1);
2090 Arrows_x = Width2Pixel (ncol); 2089 Arrows_x = Width2Pixel (ncol);
2091 } 2090 }
2091
2092 draw_Arrows (0, +1); 2092 draw_Arrows (0, +1);
2093 2093
2094 str = (CurrentBar 2094 str = (CurrentBar
2095 && CurrentBar->title) ? CurrentBar->title : "%n-%v"; 2095 && CurrentBar->title) ? CurrentBar->title : "%n-%v";
2096 for (len = 0; str[0] && len < sizeof (title) - 1; str++) 2096 for (len = 0; str[0] && len < sizeof (title) - 1; str++)
2125 } 2125 }
2126 title[len] = '\0'; 2126 title[len] = '\0';
2127 2127
2128 ncol -= (x + len + HSPACE); 2128 ncol -= (x + len + HSPACE);
2129 if (len > 0 && ncol >= 0) 2129 if (len > 0 && ncol >= 0)
2130 draw_string (*menuBar.drawable, menubarGC, TermWin.fontset[0], 2130 draw_string (*menuBar.drawable, menubarGC, fontset[0],
2131 Width2Pixel (x) + Width2Pixel (ncol + HSPACE) / 2, 2131 Width2Pixel (x) + Width2Pixel (ncol + HSPACE) / 2,
2132 SHADOW, title, len); 2132 MENU_SHADOW, title, len);
2133 } 2133 }
2134} 2134}
2135 2135
2136int 2136int
2137rxvt_term::menubar_mapping (int map) 2137rxvt_term::menubar_mapping (int map)
2182 menu_hide (); 2182 menu_hide ();
2183 return 1; 2183 return 1;
2184 } 2184 }
2185 2185
2186 /* determine the menu item corresponding to the Y index */ 2186 /* determine the menu item corresponding to the Y index */
2187 y = SHADOW; 2187 y = MENU_SHADOW;
2188 if (ev.x >= 0 && ev.x <= (ActiveMenu->w - SHADOW)) 2188 if (ev.x >= 0 && ev.x <= (ActiveMenu->w - MENU_SHADOW))
2189 { 2189 {
2190 for (item = ActiveMenu->head; item != NULL; item = item->next) 2190 for (item = ActiveMenu->head; item != NULL; item = item->next)
2191 { 2191 {
2192 int h = HEIGHT_TEXT + 2 * SHADOW; 2192 int h = HEIGHT_TEXT + 2 * MENU_SHADOW;
2193 2193
2194 if (isSeparator (item->name)) 2194 if (isSeparator (item->name))
2195 h = HEIGHT_SEPARATOR; 2195 h = HEIGHT_SEPARATOR;
2196 else if (ev.y >= y && ev.y < (y + h)) 2196 else if (ev.y >= y && ev.y < (y + h))
2197 break; 2197 break;
2205 menu_hide_all (); 2205 menu_hide_all ();
2206 return 0; 2206 return 0;
2207 } 2207 }
2208 2208
2209 thisitem = item; 2209 thisitem = item;
2210 this_y = y - SHADOW; 2210 this_y = y - MENU_SHADOW;
2211 2211
2212 /* erase the last item */ 2212 /* erase the last item */
2213 if (ActiveMenu->item != NULL) 2213 if (ActiveMenu->item != NULL)
2214 { 2214 {
2215 if (ActiveMenu->item != thisitem) 2215 if (ActiveMenu->item != thisitem)
2228 drawtriangle (ActiveMenu->w, y, +1); 2228 drawtriangle (ActiveMenu->w, y, +1);
2229 2229
2230 break; 2230 break;
2231 } 2231 }
2232 else 2232 else
2233 h = HEIGHT_TEXT + 2 * SHADOW; 2233 h = HEIGHT_TEXT + 2 * MENU_SHADOW;
2234 2234
2235 y += h; 2235 y += h;
2236 } 2236 }
2237 } 2237 }
2238 else 2238 else
2248 break; 2248 break;
2249 2249
2250 case MenuAction: 2250 case MenuAction:
2251 case MenuTerminalAction: 2251 case MenuTerminalAction:
2252 drawbox_menuitem (this_y, -1); 2252 drawbox_menuitem (this_y, -1);
2253#ifdef HAVE_NANOSLEEP
2254 struct timespec rqt;
2255
2256 rqt.tv_sec = 0;
2257 rqt.tv_nsec = MENU_DELAY_USEC * 1000;
2258 nanosleep (&rqt, NULL);
2259#else
2260 /* use select for timing */
2261 struct timeval tv;
2262
2263 tv.tv_sec = 0;
2264 tv.tv_usec = MENU_DELAY_USEC; 2253 rxvt_usleep (MENU_DELAY_USEC);
2265 select (0, NULL, NULL, NULL, &tv);
2266#endif
2267 /* remove menu before sending keys to the application */ 2254 /* remove menu before sending keys to the application */
2268 menu_hide_all (); 2255 menu_hide_all ();
2269#ifndef DEBUG_MENU 2256#ifndef DEBUG_MENU
2270 action_dispatch (& (item->entry.action)); 2257 action_dispatch (& (item->entry.action));
2271#else /* DEBUG_MENU */ 2258#else /* DEBUG_MENU */
2349 if (ev.x >= (Arrows_x + (Width2Pixel (4 * i + i)) / 4) 2336 if (ev.x >= (Arrows_x + (Width2Pixel (4 * i + i)) / 4)
2350 && ev.x < (Arrows_x 2337 && ev.x < (Arrows_x
2351 + (Width2Pixel (4 * i + i + 4)) / 4)) 2338 + (Width2Pixel (4 * i + i + 4)) / 4))
2352 { 2339 {
2353 draw_Arrows (Arrows[i].name, -1); 2340 draw_Arrows (Arrows[i].name, -1);
2354 {
2355#ifdef HAVE_NANOSLEEP
2356 struct timespec rqt;
2357
2358 rqt.tv_sec = 0;
2359 rqt.tv_nsec = MENU_DELAY_USEC * 1000;
2360 nanosleep (&rqt, NULL);
2361#else
2362 /* use select for timing */
2363 struct timeval tv;
2364
2365 tv.tv_sec = 0;
2366 tv.tv_usec = MENU_DELAY_USEC; 2341 rxvt_usleep (MENU_DELAY_USEC);
2367 select (0, NULL, NULL, NULL, &tv);
2368#endif
2369
2370 }
2371 draw_Arrows (Arrows[i].name, +1); 2342 draw_Arrows (Arrows[i].name, +1);
2372#ifdef DEBUG_MENUARROWS 2343#ifdef DEBUG_MENUARROWS
2373 fprintf (stderr, "'%c': ", Arrows[i].name); 2344 fprintf (stderr, "'%c': ", Arrows[i].name);
2374 2345
2375 if (CurrentBar == NULL 2346 if (CurrentBar == NULL
2432 if (ev.button == Button1) 2403 if (ev.button == Button1)
2433 menu_select (ev); 2404 menu_select (ev);
2434 break; 2405 break;
2435 2406
2436 case MotionNotify: 2407 case MotionNotify:
2437 while (XCheckTypedWindowEvent (display->display, TermWin.parent[0], 2408 while (XCheckTypedWindowEvent (display->display, parent[0],
2438 MotionNotify, (XEvent *)&ev)) ; 2409 MotionNotify, (XEvent *)&ev));
2439 2410
2440 if (ActiveMenu) 2411 if (ActiveMenu)
2441 while (menu_select (ev)) ; 2412 while (menu_select (ev)) ;
2442 else 2413 else
2443 ev.y = -1; 2414 ev.y = -1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines