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.27 by root, Wed Dec 21 14:19:19 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) */
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
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, vt, 959 ActiveMenu->win = XCreateSimpleWindow (display->display, vt,
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) >= width) 1027 if ((x1 + menu->w) >= width)
1028 x1 = (TermWin_TotalWidth () - menu->w); 1028 x1 = (TermWin_TotalWidth () - menu->w);
1029 1029
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, 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, 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
2065 len = (ncol - (menu->x + HSPACE)); 2065 len = (ncol - (menu->x + HSPACE));
2066 2066
2067 drawbox_menubar (menu->x, len, +1); 2067 drawbox_menubar (menu->x, len, +1);
2068 draw_string (*menuBar.drawable, menubarGC, fontset[0], 2068 draw_string (*menuBar.drawable, menubarGC, fontset[0],
2069 (Width2Pixel (menu->x) + Width2Pixel (HSPACE) / 2), 2069 (Width2Pixel (menu->x) + Width2Pixel (HSPACE) / 2),
2070 SHADOW, menu->name, len); 2070 MENU_SHADOW, menu->name, len);
2071 2071
2072 if (x >= ncol) 2072 if (x >= ncol)
2073 break; 2073 break;
2074 } 2074 }
2075 } 2075 }
2078 /* 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 */
2079 Arrows_x = 0; 2079 Arrows_x = 0;
2080 if (x < ncol) 2080 if (x < ncol)
2081 { 2081 {
2082 const char *str; 2082 const char *str;
2083 int ncol;
2084 unsigned int len; 2083 unsigned int len;
2085 char title[256]; 2084 char title[256];
2086 2085
2087 ncol = (int)ncol;
2088 if (x < (ncol - (NARROWS + 1))) 2086 if (x < (ncol - (NARROWS + 1)))
2089 { 2087 {
2090 ncol -= (NARROWS + 1); 2088 ncol -= (NARROWS + 1);
2091 Arrows_x = Width2Pixel (ncol); 2089 Arrows_x = Width2Pixel (ncol);
2092 } 2090 }
2091
2093 draw_Arrows (0, +1); 2092 draw_Arrows (0, +1);
2094 2093
2095 str = (CurrentBar 2094 str = (CurrentBar
2096 && CurrentBar->title) ? CurrentBar->title : "%n-%v"; 2095 && CurrentBar->title) ? CurrentBar->title : "%n-%v";
2097 for (len = 0; str[0] && len < sizeof (title) - 1; str++) 2096 for (len = 0; str[0] && len < sizeof (title) - 1; str++)
2128 2127
2129 ncol -= (x + len + HSPACE); 2128 ncol -= (x + len + HSPACE);
2130 if (len > 0 && ncol >= 0) 2129 if (len > 0 && ncol >= 0)
2131 draw_string (*menuBar.drawable, menubarGC, fontset[0], 2130 draw_string (*menuBar.drawable, menubarGC, fontset[0],
2132 Width2Pixel (x) + Width2Pixel (ncol + HSPACE) / 2, 2131 Width2Pixel (x) + Width2Pixel (ncol + HSPACE) / 2,
2133 SHADOW, title, len); 2132 MENU_SHADOW, title, len);
2134 } 2133 }
2135} 2134}
2136 2135
2137int 2136int
2138rxvt_term::menubar_mapping (int map) 2137rxvt_term::menubar_mapping (int map)
2183 menu_hide (); 2182 menu_hide ();
2184 return 1; 2183 return 1;
2185 } 2184 }
2186 2185
2187 /* determine the menu item corresponding to the Y index */ 2186 /* determine the menu item corresponding to the Y index */
2188 y = SHADOW; 2187 y = MENU_SHADOW;
2189 if (ev.x >= 0 && ev.x <= (ActiveMenu->w - SHADOW)) 2188 if (ev.x >= 0 && ev.x <= (ActiveMenu->w - MENU_SHADOW))
2190 { 2189 {
2191 for (item = ActiveMenu->head; item != NULL; item = item->next) 2190 for (item = ActiveMenu->head; item != NULL; item = item->next)
2192 { 2191 {
2193 int h = HEIGHT_TEXT + 2 * SHADOW; 2192 int h = HEIGHT_TEXT + 2 * MENU_SHADOW;
2194 2193
2195 if (isSeparator (item->name)) 2194 if (isSeparator (item->name))
2196 h = HEIGHT_SEPARATOR; 2195 h = HEIGHT_SEPARATOR;
2197 else if (ev.y >= y && ev.y < (y + h)) 2196 else if (ev.y >= y && ev.y < (y + h))
2198 break; 2197 break;
2206 menu_hide_all (); 2205 menu_hide_all ();
2207 return 0; 2206 return 0;
2208 } 2207 }
2209 2208
2210 thisitem = item; 2209 thisitem = item;
2211 this_y = y - SHADOW; 2210 this_y = y - MENU_SHADOW;
2212 2211
2213 /* erase the last item */ 2212 /* erase the last item */
2214 if (ActiveMenu->item != NULL) 2213 if (ActiveMenu->item != NULL)
2215 { 2214 {
2216 if (ActiveMenu->item != thisitem) 2215 if (ActiveMenu->item != thisitem)
2229 drawtriangle (ActiveMenu->w, y, +1); 2228 drawtriangle (ActiveMenu->w, y, +1);
2230 2229
2231 break; 2230 break;
2232 } 2231 }
2233 else 2232 else
2234 h = HEIGHT_TEXT + 2 * SHADOW; 2233 h = HEIGHT_TEXT + 2 * MENU_SHADOW;
2235 2234
2236 y += h; 2235 y += h;
2237 } 2236 }
2238 } 2237 }
2239 else 2238 else

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines