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.21 by root, Sat Aug 21 05:32:00 2004 UTC vs.
Revision 1.26 by root, Sun Dec 18 00:59:42 2005 UTC

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
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
954 ActiveMenu->h = h + 2 * SHADOW; 954 ActiveMenu->h = h + 2 * 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]);
965 ActiveMenu->drawable = new rxvt_drawable (display, ActiveMenu->win); 965 ActiveMenu->drawable = new rxvt_drawable (display, ActiveMenu->win);
966 XMapWindow (display->display, ActiveMenu->win); 966 XMapWindow (display->display, ActiveMenu->win);
967 } 967 }
968 968
969 rxvt_Draw_Shadow (display->display, ActiveMenu->win, 969 rxvt_Draw_Shadow (display->display, ActiveMenu->win,
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 SHADOW, y + SHADOW + 1,
989 ActiveMenu->w - 2 * SHADOW, 0); 989 ActiveMenu->w - 2 * 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;
1022 h += isSeparator (it->name) ? HEIGHT_SEPARATOR 1022 h += isSeparator (it->name) ? HEIGHT_SEPARATOR
1023 : HEIGHT_TEXT + 2 * SHADOW; 1023 : HEIGHT_TEXT + 2 * SHADOW;
1024 menu->h = h + 2 * SHADOW; 1024 menu->h = h + 2 * 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 * 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 * SHADOW + y, name, len);
1049 1049
1050 h = HEIGHT_TEXT + 2 * SHADOW; 1050 h = HEIGHT_TEXT + 2 * SHADOW;
1051 } 1051 }
1052 y += h; 1052 y += h;
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 {
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;
2015 const int y = (menuBar_TotalHeight () - w) / 2; 2016 const int y = (menuBar_TotalHeight () - w) / 2;
2016 int x = Arrows_x + (5 * Width2Pixel (i)) / 4; 2017 int x = Arrows_x + (5 * Width2Pixel (i)) / 4;
2017 2018
2018 if (!name || name == Arrows[i].name) 2019 if (!name || name == Arrows[i].name)
2019 rxvt_Draw_Triangle (display->display, menuBar.win, top, bot, x, y, w, 2020 rxvt_Draw_Triangle (display->display, menuBar.win, top, bot, x, y, w,
2020 Arrows[i].name); 2021 Arrows[i].name);
2021 } 2022 }
2022 XFlush (display->display); 2023 XFlush (display->display);
2023} 2024}
2024 2025
2025void 2026void
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 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 int ncol;
2083 unsigned int len; 2084 unsigned int len;
2084 char title[256]; 2085 char title[256];
2085 2086
2086 ncol = (int)TermWin.ncol; 2087 ncol = (int)ncol;
2087 if (x < (ncol - (NARROWS + 1))) 2088 if (x < (ncol - (NARROWS + 1)))
2088 { 2089 {
2089 ncol -= (NARROWS + 1); 2090 ncol -= (NARROWS + 1);
2090 Arrows_x = Width2Pixel (ncol); 2091 Arrows_x = Width2Pixel (ncol);
2091 } 2092 }
2125 } 2126 }
2126 title[len] = '\0'; 2127 title[len] = '\0';
2127 2128
2128 ncol -= (x + len + HSPACE); 2129 ncol -= (x + len + HSPACE);
2129 if (len > 0 && ncol >= 0) 2130 if (len > 0 && ncol >= 0)
2130 draw_string (*menuBar.drawable, menubarGC, TermWin.fontset[0], 2131 draw_string (*menuBar.drawable, menubarGC, fontset[0],
2131 Width2Pixel (x) + Width2Pixel (ncol + HSPACE) / 2, 2132 Width2Pixel (x) + Width2Pixel (ncol + HSPACE) / 2,
2132 SHADOW, title, len); 2133 SHADOW, title, len);
2133 } 2134 }
2134} 2135}
2135 2136
2248 break; 2249 break;
2249 2250
2250 case MenuAction: 2251 case MenuAction:
2251 case MenuTerminalAction: 2252 case MenuTerminalAction:
2252 drawbox_menuitem (this_y, -1); 2253 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; 2254 rxvt_usleep (MENU_DELAY_USEC);
2265 select (0, NULL, NULL, NULL, &tv);
2266#endif
2267 /* remove menu before sending keys to the application */ 2255 /* remove menu before sending keys to the application */
2268 menu_hide_all (); 2256 menu_hide_all ();
2269#ifndef DEBUG_MENU 2257#ifndef DEBUG_MENU
2270 action_dispatch (& (item->entry.action)); 2258 action_dispatch (& (item->entry.action));
2271#else /* DEBUG_MENU */ 2259#else /* DEBUG_MENU */
2349 if (ev.x >= (Arrows_x + (Width2Pixel (4 * i + i)) / 4) 2337 if (ev.x >= (Arrows_x + (Width2Pixel (4 * i + i)) / 4)
2350 && ev.x < (Arrows_x 2338 && ev.x < (Arrows_x
2351 + (Width2Pixel (4 * i + i + 4)) / 4)) 2339 + (Width2Pixel (4 * i + i + 4)) / 4))
2352 { 2340 {
2353 draw_Arrows (Arrows[i].name, -1); 2341 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; 2342 rxvt_usleep (MENU_DELAY_USEC);
2367 select (0, NULL, NULL, NULL, &tv);
2368#endif
2369
2370 }
2371 draw_Arrows (Arrows[i].name, +1); 2343 draw_Arrows (Arrows[i].name, +1);
2372#ifdef DEBUG_MENUARROWS 2344#ifdef DEBUG_MENUARROWS
2373 fprintf (stderr, "'%c': ", Arrows[i].name); 2345 fprintf (stderr, "'%c': ", Arrows[i].name);
2374 2346
2375 if (CurrentBar == NULL 2347 if (CurrentBar == NULL
2432 if (ev.button == Button1) 2404 if (ev.button == Button1)
2433 menu_select (ev); 2405 menu_select (ev);
2434 break; 2406 break;
2435 2407
2436 case MotionNotify: 2408 case MotionNotify:
2437 while (XCheckTypedWindowEvent (display->display, TermWin.parent[0], 2409 while (XCheckTypedWindowEvent (display->display, parent[0],
2438 MotionNotify, (XEvent *)&ev)) ; 2410 MotionNotify, (XEvent *)&ev));
2439 2411
2440 if (ActiveMenu) 2412 if (ActiveMenu)
2441 while (menu_select (ev)) ; 2413 while (menu_select (ev)) ;
2442 else 2414 else
2443 ev.y = -1; 2415 ev.y = -1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines