aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRichard M. Stallman1994-04-14 17:14:57 +0000
committerRichard M. Stallman1994-04-14 17:14:57 +0000
commit4e8d35499af38afb69094586770d3710689061fa (patch)
treef561af02a5b22c2c72d0f7fec0c41e41548672a0 /src
parentd70c8f3052a06279cb7101fc1b521a7800f83efe (diff)
downloademacs-4e8d35499af38afb69094586770d3710689061fa.tar.gz
emacs-4e8d35499af38afb69094586770d3710689061fa.zip
(last_menu_bar_item_end): New variable.
(xmenu_show): Set that var. (other_menu_bar_item_p): Return 0 if mouse is not in any menu bar item. (xmenu_show, xdialog_show): Add casts in assignments to widget_value fields from string contents. (dispatch_dummy_expose): Cast arg to XtDispatchEvent. [!USE_X_TOOLKIT] (xmenu_show): Right-justify char equivalents. Use alloca for concatenated strings, if alloca is fast. [USE_X_TOOLKIT] (xmenu_show): Use XtTranslateCoords.
Diffstat (limited to 'src')
-rw-r--r--src/xmenu.c97
1 files changed, 76 insertions, 21 deletions
diff --git a/src/xmenu.c b/src/xmenu.c
index 18d51054934..9614e752430 100644
--- a/src/xmenu.c
+++ b/src/xmenu.c
@@ -981,7 +981,7 @@ dispatch_dummy_expose (w, x, y)
981 dummy.x = x; 981 dummy.x = x;
982 dummy.y = y; 982 dummy.y = y;
983 983
984 XtDispatchEvent (&dummy); 984 XtDispatchEvent ((XEvent *) &dummy);
985} 985}
986 986
987static int 987static int
@@ -1204,7 +1204,7 @@ set_frame_menubar (f, first_time)
1204 prev_wv->next = wv; 1204 prev_wv->next = wv;
1205 else 1205 else
1206 save_wv->contents = wv; 1206 save_wv->contents = wv;
1207 wv->name = XSTRING (string)->data; 1207 wv->name = (char *) XSTRING (string)->data;
1208 wv->value = 0; 1208 wv->value = 0;
1209 wv->enabled = 1; 1209 wv->enabled = 1;
1210 prev_wv = wv; 1210 prev_wv = wv;
@@ -1264,12 +1264,18 @@ initialize_frame_menubar (f)
1264 set_frame_menubar (f, 1); 1264 set_frame_menubar (f, 1);
1265} 1265}
1266 1266
1267/* Nonzero if position X, Y relative to inside of frame F 1267/* Horizontal bounds of the current menu bar item. */
1268 is in some other menu bar item. */
1269 1268
1270static int this_menu_bar_item_beg; 1269static int this_menu_bar_item_beg;
1271static int this_menu_bar_item_end; 1270static int this_menu_bar_item_end;
1272 1271
1272/* Horizontal position of the end of the last menu bar item. */
1273
1274static int last_menu_bar_item_end;
1275
1276/* Nonzero if position X, Y is in the menu bar and in some menu bar item
1277 but not in the current menu bar item. */
1278
1273static int 1279static int
1274other_menu_bar_item_p (f, x, y) 1280other_menu_bar_item_p (f, x, y)
1275 FRAME_PTR f; 1281 FRAME_PTR f;
@@ -1278,7 +1284,7 @@ other_menu_bar_item_p (f, x, y)
1278 return (y >= 0 1284 return (y >= 0
1279 && y < f->display.x->menubar_widget->core.height 1285 && y < f->display.x->menubar_widget->core.height
1280 && x >= 0 1286 && x >= 0
1281 && x < f->display.x->menubar_widget->core.width 1287 && x < last_menu_bar_item_end
1282 && (x >= this_menu_bar_item_end 1288 && (x >= this_menu_bar_item_end
1283 || x < this_menu_bar_item_beg)); 1289 || x < this_menu_bar_item_beg));
1284} 1290}
@@ -1387,10 +1393,13 @@ xmenu_show (f, x, y, menubarp, keymaps, title, error)
1387 struct event_queue *queue = NULL; 1393 struct event_queue *queue = NULL;
1388 struct event_queue *queue_tmp; 1394 struct event_queue *queue_tmp;
1389 1395
1396 Position root_x, root_y;
1397
1390 *error = NULL; 1398 *error = NULL;
1391 1399
1392 this_menu_bar_item_beg = -1; 1400 this_menu_bar_item_beg = -1;
1393 this_menu_bar_item_end = -1; 1401 this_menu_bar_item_end = -1;
1402 last_menu_bar_item_end = -1;
1394 1403
1395 /* Figure out which menu bar item, if any, this menu is for. */ 1404 /* Figure out which menu bar item, if any, this menu is for. */
1396 if (menubarp) 1405 if (menubarp)
@@ -1406,7 +1415,7 @@ xmenu_show (f, x, y, menubarp, keymaps, title, error)
1406 xend += (string_width (menubar, menubar_item->name) 1415 xend += (string_width (menubar, menubar_item->name)
1407 + 2 * (menubar->menu.horizontal_spacing 1416 + 2 * (menubar->menu.horizontal_spacing
1408 + menubar->menu.shadow_thickness)); 1417 + menubar->menu.shadow_thickness));
1409 if (x < xend) 1418 if (x >= xbeg && x < xend)
1410 { 1419 {
1411 x = xbeg + 4; 1420 x = xbeg + 4;
1412 y = 0; 1421 y = 0;
@@ -1414,19 +1423,19 @@ xmenu_show (f, x, y, menubarp, keymaps, title, error)
1414 to a different item. */ 1423 to a different item. */
1415 this_menu_bar_item_beg = xbeg; 1424 this_menu_bar_item_beg = xbeg;
1416 this_menu_bar_item_end = xend; 1425 this_menu_bar_item_end = xend;
1417 break;
1418 } 1426 }
1419 } 1427 }
1428 last_menu_bar_item_end = xend;
1420 } 1429 }
1421 if (menubar_item == 0) 1430 if (menubar_item == 0)
1422 menubarp = 0; 1431 menubarp = 0;
1423 1432
1424 /* Offset the coordinates to root-relative. */ 1433 /* Offset the coordinates to root-relative. */
1425 x += (f->display.x->widget->core.x 1434 XtTranslateCoords (f->display.x->widget,
1426 + f->display.x->widget->core.border_width); 1435 x, y + f->display.x->menubar_widget->core.height,
1427 y += (f->display.x->widget->core.y 1436 &root_x, &root_y);
1428 + f->display.x->widget->core.border_width 1437 x = root_x;
1429 + f->display.x->menubar_widget->core.height); 1438 y = root_y;
1430 1439
1431 /* Create a tree of widget_value objects 1440 /* Create a tree of widget_value objects
1432 representing the panes and their items. */ 1441 representing the panes and their items. */
@@ -1508,9 +1517,9 @@ xmenu_show (f, x, y, menubarp, keymaps, title, error)
1508 prev_wv->next = wv; 1517 prev_wv->next = wv;
1509 else 1518 else
1510 save_wv->contents = wv; 1519 save_wv->contents = wv;
1511 wv->name = XSTRING (item_name)->data; 1520 wv->name = (char *) XSTRING (item_name)->data;
1512 if (!NILP (descrip)) 1521 if (!NILP (descrip))
1513 wv->key = XSTRING (descrip)->data; 1522 wv->key = (char *) XSTRING (descrip)->data;
1514 wv->value = 0; 1523 wv->value = 0;
1515 wv->call_data = (void *) &XVECTOR (menu_items)->contents[i]; 1524 wv->call_data = (void *) &XVECTOR (menu_items)->contents[i];
1516 wv->enabled = !NILP (enable); 1525 wv->enabled = !NILP (enable);
@@ -1831,8 +1840,8 @@ xdialog_show (f, menubarp, keymaps, title, error)
1831 prev_wv->next = wv; 1840 prev_wv->next = wv;
1832 wv->name = (char *) button_names[nb_buttons]; 1841 wv->name = (char *) button_names[nb_buttons];
1833 if (!NILP (descrip)) 1842 if (!NILP (descrip))
1834 wv->key = XSTRING (descrip)->data; 1843 wv->key = (char *) XSTRING (descrip)->data;
1835 wv->value = XSTRING (item_name)->data; 1844 wv->value = (char *) XSTRING (item_name)->data;
1836 wv->call_data = (void *) &XVECTOR (menu_items)->contents[i]; 1845 wv->call_data = (void *) &XVECTOR (menu_items)->contents[i];
1837 wv->enabled = !NILP (enable); 1846 wv->enabled = !NILP (enable);
1838 prev_wv = wv; 1847 prev_wv = wv;
@@ -1979,7 +1988,8 @@ xmenu_show (f, x, y, menubarp, keymaps, title, error)
1979 char *datap; 1988 char *datap;
1980 int ulx, uly, width, height; 1989 int ulx, uly, width, height;
1981 int dispwidth, dispheight; 1990 int dispwidth, dispheight;
1982 int i; 1991 int i, j;
1992 int maxwidth;
1983 int dummy_int; 1993 int dummy_int;
1984 unsigned int dummy_uint; 1994 unsigned int dummy_uint;
1985 1995
@@ -2058,6 +2068,27 @@ xmenu_show (f, x, y, menubarp, keymaps, title, error)
2058 return Qnil; 2068 return Qnil;
2059 } 2069 }
2060 i += MENU_ITEMS_PANE_LENGTH; 2070 i += MENU_ITEMS_PANE_LENGTH;
2071
2072 /* Find the width of the widest item in this pane. */
2073 maxwidth = 0;
2074 j = i;
2075 while (j < menu_items_used)
2076 {
2077 Lisp_Object item;
2078 item = XVECTOR (menu_items)->contents[j];
2079 if (EQ (item, Qt))
2080 break;
2081 if (NILP (item))
2082 {
2083 j++;
2084 continue;
2085 }
2086 width = XSTRING (item)->size;
2087 if (width > maxwidth)
2088 maxwidth = width;
2089
2090 j += MENU_ITEMS_ITEM_LENGTH;
2091 }
2061 } 2092 }
2062 /* Ignore a nil in the item list. 2093 /* Ignore a nil in the item list.
2063 It's meaningful only for dialog boxes. */ 2094 It's meaningful only for dialog boxes. */
@@ -2067,16 +2098,40 @@ xmenu_show (f, x, y, menubarp, keymaps, title, error)
2067 { 2098 {
2068 /* Create a new item within current pane. */ 2099 /* Create a new item within current pane. */
2069 Lisp_Object item_name, enable, descrip; 2100 Lisp_Object item_name, enable, descrip;
2101 unsigned char *item_data;
2070 2102
2071 item_name = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_NAME]; 2103 item_name = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_NAME];
2072 enable = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_ENABLE]; 2104 enable = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_ENABLE];
2073 descrip 2105 descrip
2074 = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_EQUIV_KEY]; 2106 = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_EQUIV_KEY];
2075 if (!NILP (descrip)) 2107 if (!NILP (descrip))
2076 item_name = concat2 (item_name, descrip); 2108 {
2109 int gap = maxwidth - XSTRING (item_name)->size;
2110#ifdef C_ALLOCA
2111 Lisp_Object spacer;
2112 spacer = Fmake_string (make_number (gap), make_number (' '));
2113 item_name = concat2 (item_name, spacer);
2114 item_name = concat2 (item_name, descrip);
2115 item_data = XSTRING (item_name)->data;
2116#else
2117 /* if alloca is fast, use that to make the space,
2118 to reduce gc needs. */
2119 item_data
2120 = (unsigned char *) alloca (maxwidth
2121 + XSTRING (descrip)->size + 1);
2122 bcopy (XSTRING (item_name)->data, item_data,
2123 XSTRING (item_name)->size);
2124 for (j = XSTRING (item_name)->size; j < maxwidth; j++)
2125 item_data[j] = ' ';
2126 bcopy (XSTRING (descrip)->data, item_data + j,
2127 XSTRING (descrip)->size);
2128 item_data[j + XSTRING (descrip)->size] = 0;
2129#endif
2130 }
2131 else
2132 item_data = XSTRING (item_name)->data;
2077 2133
2078 if (XMenuAddSelection (XDISPLAY menu, lpane, 0, 2134 if (XMenuAddSelection (XDISPLAY menu, lpane, 0, item_data,
2079 XSTRING (item_name)->data,
2080 !NILP (enable)) 2135 !NILP (enable))
2081 == XM_FAILURE) 2136 == XM_FAILURE)
2082 { 2137 {
@@ -2087,7 +2142,7 @@ xmenu_show (f, x, y, menubarp, keymaps, title, error)
2087 i += MENU_ITEMS_ITEM_LENGTH; 2142 i += MENU_ITEMS_ITEM_LENGTH;
2088 } 2143 }
2089 } 2144 }
2090 2145
2091 /* All set and ready to fly. */ 2146 /* All set and ready to fly. */
2092 XMenuRecompute (XDISPLAY menu); 2147 XMenuRecompute (XDISPLAY menu);
2093 dispwidth = DisplayWidth (x_current_display, XDefaultScreen (x_current_display)); 2148 dispwidth = DisplayWidth (x_current_display, XDefaultScreen (x_current_display));