aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGerd Moellmann1999-07-21 21:43:52 +0000
committerGerd Moellmann1999-07-21 21:43:52 +0000
commit3427a3db9f0be08f7a31f6ebb8507d4ecde587e4 (patch)
tree63783e976ef6d8721ebbff364c829a46276cecfe /src
parent4da4f201337713562628123446e5f62185ea9fb5 (diff)
downloademacs-3427a3db9f0be08f7a31f6ebb8507d4ecde587e4.tar.gz
emacs-3427a3db9f0be08f7a31f6ebb8507d4ecde587e4.zip
Ditto.
(xmenu_show) [LESSTIF_VERSION]: Add workaround for remaining button grab under LessTif (HAVE_BOXES): Define if USE_X_TOOLKIT. (HAVE_BOXES): Define if using Lucid menus. (single_submenu): Set button_type of menu to BUTTON_TYPE_NONE. (single_submenu): Likewise for panes and menu items. (set_frame_menubar): Set button_type of menu bar to none. (xmenu_show): Likewise. (single_submenu): Set widget values selected slot. (xmenu_show): Likewise. (push_menu_item): Add parameters `type' and `selected'. Store it in menu_items. (MENU_ITEMS_ITEM_TYPE): New. (MENU_ITEMS_ITEM_SELECTED): New. (MENU_ITEMS_ITEM_LENGTH): Increase by two. (popup_get_selection): Use xmalloc/xfree instead of malloc/free.
Diffstat (limited to 'src')
-rw-r--r--src/xmenu.c120
1 files changed, 95 insertions, 25 deletions
diff --git a/src/xmenu.c b/src/xmenu.c
index 46fb604f5f3..173810bc035 100644
--- a/src/xmenu.c
+++ b/src/xmenu.c
@@ -78,6 +78,10 @@ Boston, MA 02111-1307, USA. */
78#endif /* not USE_X_TOOLKIT */ 78#endif /* not USE_X_TOOLKIT */
79#endif /* HAVE_X_WINDOWS */ 79#endif /* HAVE_X_WINDOWS */
80 80
81#ifdef USE_MOTIF
82#include <Xm/Xm.h> /* for LESSTIF_VERSION */
83#endif
84
81#define min(x,y) (((x) < (y)) ? (x) : (y)) 85#define min(x,y) (((x) < (y)) ? (x) : (y))
82#define max(x,y) (((x) > (y)) ? (x) : (y)) 86#define max(x,y) (((x) > (y)) ? (x) : (y))
83 87
@@ -111,6 +115,16 @@ static Lisp_Object xdialog_show ();
111void popup_get_selection (); 115void popup_get_selection ();
112#endif 116#endif
113 117
118#ifdef USE_X_TOOLKIT
119
120/* Define HAVE_BOXES if meus can handle radio and toggle buttons. */
121
122#define HAVE_BOXES 1
123#endif
124
125static void push_menu_item P_ ((Lisp_Object, Lisp_Object, Lisp_Object,
126 Lisp_Object, Lisp_Object, Lisp_Object,
127 Lisp_Object));
114static Lisp_Object xmenu_show (); 128static Lisp_Object xmenu_show ();
115static void keymap_panes (); 129static void keymap_panes ();
116static void single_keymap_panes (); 130static void single_keymap_panes ();
@@ -149,7 +163,9 @@ static void list_of_items ();
149#define MENU_ITEMS_ITEM_VALUE 2 163#define MENU_ITEMS_ITEM_VALUE 2
150#define MENU_ITEMS_ITEM_EQUIV_KEY 3 164#define MENU_ITEMS_ITEM_EQUIV_KEY 3
151#define MENU_ITEMS_ITEM_DEFINITION 4 165#define MENU_ITEMS_ITEM_DEFINITION 4
152#define MENU_ITEMS_ITEM_LENGTH 5 166#define MENU_ITEMS_ITEM_TYPE 5
167#define MENU_ITEMS_ITEM_SELECTED 6
168#define MENU_ITEMS_ITEM_LENGTH 7
153 169
154static Lisp_Object menu_items; 170static Lisp_Object menu_items;
155 171
@@ -315,17 +331,17 @@ push_menu_pane (name, prefix_vec)
315 XVECTOR (menu_items)->contents[menu_items_used++] = prefix_vec; 331 XVECTOR (menu_items)->contents[menu_items_used++] = prefix_vec;
316} 332}
317 333
318/* Push one menu item into the current pane. 334/* Push one menu item into the current pane. NAME is the string to
319 NAME is the string to display. ENABLE if non-nil means 335 display. ENABLE if non-nil means this item can be selected. KEY
320 this item can be selected. KEY is the key generated by 336 is the key generated by choosing this item, or nil if this item
321 choosing this item, or nil if this item doesn't really have a definition. 337 doesn't really have a definition. DEF is the definition of this
322 DEF is the definition of this item. 338 item. EQUIV is the textual description of the keyboard equivalent
323 EQUIV is the textual description of the keyboard equivalent for 339 for this item (or nil if none). TYPE is the type of this menu
324 this item (or nil if none). */ 340 item, one of nil, `toggle' or `radio'. */
325 341
326static void 342static void
327push_menu_item (name, enable, key, def, equiv) 343push_menu_item (name, enable, key, def, equiv, type, selected)
328 Lisp_Object name, enable, key, def, equiv; 344 Lisp_Object name, enable, key, def, equiv, type, selected;
329{ 345{
330 if (menu_items_used + MENU_ITEMS_ITEM_LENGTH > menu_items_allocated) 346 if (menu_items_used + MENU_ITEMS_ITEM_LENGTH > menu_items_allocated)
331 grow_menu_items (); 347 grow_menu_items ();
@@ -335,6 +351,8 @@ push_menu_item (name, enable, key, def, equiv)
335 XVECTOR (menu_items)->contents[menu_items_used++] = key; 351 XVECTOR (menu_items)->contents[menu_items_used++] = key;
336 XVECTOR (menu_items)->contents[menu_items_used++] = equiv; 352 XVECTOR (menu_items)->contents[menu_items_used++] = equiv;
337 XVECTOR (menu_items)->contents[menu_items_used++] = def; 353 XVECTOR (menu_items)->contents[menu_items_used++] = def;
354 XVECTOR (menu_items)->contents[menu_items_used++] = type;
355 XVECTOR (menu_items)->contents[menu_items_used++] = selected;
338} 356}
339 357
340/* Look through KEYMAPS, a vector of keymaps that is NMAPS long, 358/* Look through KEYMAPS, a vector of keymaps that is NMAPS long,
@@ -561,7 +579,9 @@ single_menu_item (key, item, pending_maps_ptr, notreal, maxdepth,
561 579
562 push_menu_item (item_string, enabled, key, 580 push_menu_item (item_string, enabled, key,
563 XVECTOR (item_properties)->contents[ITEM_PROPERTY_DEF], 581 XVECTOR (item_properties)->contents[ITEM_PROPERTY_DEF],
564 XVECTOR (item_properties)->contents[ITEM_PROPERTY_KEYEQ]); 582 XVECTOR (item_properties)->contents[ITEM_PROPERTY_KEYEQ],
583 XVECTOR (item_properties)->contents[ITEM_PROPERTY_TYPE],
584 XVECTOR (item_properties)->contents[ITEM_PROPERTY_SELECTED]);
565 585
566#ifdef USE_X_TOOLKIT 586#ifdef USE_X_TOOLKIT
567 /* Display a submenu using the toolkit. */ 587 /* Display a submenu using the toolkit. */
@@ -613,7 +633,7 @@ list_of_items (pane)
613 { 633 {
614 item = Fcar (tail); 634 item = Fcar (tail);
615 if (STRINGP (item)) 635 if (STRINGP (item))
616 push_menu_item (item, Qnil, Qnil, Qt, Qnil); 636 push_menu_item (item, Qnil, Qnil, Qt, Qnil, Qnil, Qnil);
617 else if (NILP (item)) 637 else if (NILP (item))
618 push_left_right_boundary (); 638 push_left_right_boundary ();
619 else 639 else
@@ -621,7 +641,7 @@ list_of_items (pane)
621 CHECK_CONS (item, 0); 641 CHECK_CONS (item, 0);
622 item1 = Fcar (item); 642 item1 = Fcar (item);
623 CHECK_STRING (item1, 1); 643 CHECK_STRING (item1, 1);
624 push_menu_item (item1, Qt, Fcdr (item), Qt, Qnil); 644 push_menu_item (item1, Qt, Fcdr (item), Qt, Qnil, Qnil, Qnil);
625 } 645 }
626 } 646 }
627} 647}
@@ -1319,7 +1339,7 @@ single_submenu (item_key, item_name, maps)
1319 as opposed to a submenu. */ 1339 as opposed to a submenu. */
1320 top_level_items = 1; 1340 top_level_items = 1;
1321 push_menu_pane (Qnil, Qnil); 1341 push_menu_pane (Qnil, Qnil);
1322 push_menu_item (item_name, Qt, item_key, mapvec[i], Qnil); 1342 push_menu_item (item_name, Qt, item_key, mapvec[i], Qnil, Qnil, Qnil);
1323 } 1343 }
1324 else 1344 else
1325 single_keymap_panes (mapvec[i], item_name, item_key, 0, 10); 1345 single_keymap_panes (mapvec[i], item_name, item_key, 0, 10);
@@ -1334,6 +1354,7 @@ single_submenu (item_key, item_name, maps)
1334 wv->name = "menu"; 1354 wv->name = "menu";
1335 wv->value = 0; 1355 wv->value = 0;
1336 wv->enabled = 1; 1356 wv->enabled = 1;
1357 wv->button_type = BUTTON_TYPE_NONE;
1337 first_wv = wv; 1358 first_wv = wv;
1338 save_wv = 0; 1359 save_wv = 0;
1339 prev_wv = 0; 1360 prev_wv = 0;
@@ -1400,6 +1421,7 @@ single_submenu (item_key, item_name, maps)
1400 wv->name++; 1421 wv->name++;
1401 wv->value = 0; 1422 wv->value = 0;
1402 wv->enabled = 1; 1423 wv->enabled = 1;
1424 wv->button_type = BUTTON_TYPE_NONE;
1403 } 1425 }
1404 save_wv = wv; 1426 save_wv = wv;
1405 prev_wv = 0; 1427 prev_wv = 0;
@@ -1408,18 +1430,22 @@ single_submenu (item_key, item_name, maps)
1408 else 1430 else
1409 { 1431 {
1410 /* Create a new item within current pane. */ 1432 /* Create a new item within current pane. */
1411 Lisp_Object item_name, enable, descrip, def; 1433 Lisp_Object item_name, enable, descrip, def, type, selected;
1412 item_name = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_NAME]; 1434 item_name = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_NAME];
1413 enable = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_ENABLE]; 1435 enable = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_ENABLE];
1414 descrip 1436 descrip
1415 = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_EQUIV_KEY]; 1437 = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_EQUIV_KEY];
1416 def = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_DEFINITION]; 1438 def = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_DEFINITION];
1439 type = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_TYPE];
1440 selected = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_SELECTED];
1441
1417#ifndef HAVE_MULTILINGUAL_MENU 1442#ifndef HAVE_MULTILINGUAL_MENU
1418 if (STRING_MULTIBYTE (item_name)) 1443 if (STRING_MULTIBYTE (item_name))
1419 item_name = string_make_unibyte (item_name); 1444 item_name = string_make_unibyte (item_name);
1420 if (STRINGP (descrip) && STRING_MULTIBYTE (descrip)) 1445 if (STRINGP (descrip) && STRING_MULTIBYTE (descrip))
1421 descrip = string_make_unibyte (descrip); 1446 descrip = string_make_unibyte (descrip);
1422#endif 1447#endif
1448
1423 wv = xmalloc_widget_value (); 1449 wv = xmalloc_widget_value ();
1424 if (prev_wv) 1450 if (prev_wv)
1425 prev_wv->next = wv; 1451 prev_wv->next = wv;
@@ -1434,6 +1460,18 @@ single_submenu (item_key, item_name, maps)
1434 as long as pointers have enough bits to hold small integers. */ 1460 as long as pointers have enough bits to hold small integers. */
1435 wv->call_data = (!NILP (def) ? (void *) (EMACS_INT) i : 0); 1461 wv->call_data = (!NILP (def) ? (void *) (EMACS_INT) i : 0);
1436 wv->enabled = !NILP (enable); 1462 wv->enabled = !NILP (enable);
1463
1464 if (NILP (type))
1465 wv->button_type = BUTTON_TYPE_NONE;
1466 else if (EQ (type, QCradio))
1467 wv->button_type = BUTTON_TYPE_RADIO;
1468 else if (EQ (type, QCtoggle))
1469 wv->button_type = BUTTON_TYPE_TOGGLE;
1470 else
1471 abort ();
1472
1473 wv->selected = !NILP (selected);
1474
1437 prev_wv = wv; 1475 prev_wv = wv;
1438 1476
1439 i += MENU_ITEMS_ITEM_LENGTH; 1477 i += MENU_ITEMS_ITEM_LENGTH;
@@ -1551,6 +1589,7 @@ set_frame_menubar (f, first_time, deep_p)
1551 wv->name = "menubar"; 1589 wv->name = "menubar";
1552 wv->value = 0; 1590 wv->value = 0;
1553 wv->enabled = 1; 1591 wv->enabled = 1;
1592 wv->button_type = BUTTON_TYPE_NONE;
1554 first_wv = wv; 1593 first_wv = wv;
1555 1594
1556 if (deep_p) 1595 if (deep_p)
@@ -1623,6 +1662,7 @@ set_frame_menubar (f, first_time, deep_p)
1623 first_wv->contents = wv; 1662 first_wv->contents = wv;
1624 /* Don't set wv->name here; GC during the loop might relocate it. */ 1663 /* Don't set wv->name here; GC during the loop might relocate it. */
1625 wv->enabled = 1; 1664 wv->enabled = 1;
1665 wv->button_type = BUTTON_TYPE_NONE;
1626 prev_wv = wv; 1666 prev_wv = wv;
1627 } 1667 }
1628 1668
@@ -1681,6 +1721,7 @@ set_frame_menubar (f, first_time, deep_p)
1681 wv->name = (char *) XSTRING (string)->data; 1721 wv->name = (char *) XSTRING (string)->data;
1682 wv->value = 0; 1722 wv->value = 0;
1683 wv->enabled = 1; 1723 wv->enabled = 1;
1724 wv->button_type = BUTTON_TYPE_NONE;
1684 /* This prevents lwlib from assuming this 1725 /* This prevents lwlib from assuming this
1685 menu item is really supposed to be empty. */ 1726 menu item is really supposed to be empty. */
1686 /* The EMACS_INT cast avoids a warning. 1727 /* The EMACS_INT cast avoids a warning.
@@ -1879,6 +1920,7 @@ xmenu_show (f, x, y, for_click, keymaps, title, error)
1879 wv->name = "menu"; 1920 wv->name = "menu";
1880 wv->value = 0; 1921 wv->value = 0;
1881 wv->enabled = 1; 1922 wv->enabled = 1;
1923 wv->button_type = BUTTON_TYPE_NONE;
1882 first_wv = wv; 1924 first_wv = wv;
1883 first_pane = 1; 1925 first_pane = 1;
1884 1926
@@ -1941,6 +1983,7 @@ xmenu_show (f, x, y, for_click, keymaps, title, error)
1941 wv->name++; 1983 wv->name++;
1942 wv->value = 0; 1984 wv->value = 0;
1943 wv->enabled = 1; 1985 wv->enabled = 1;
1986 wv->button_type = BUTTON_TYPE_NONE;
1944 save_wv = wv; 1987 save_wv = wv;
1945 prev_wv = 0; 1988 prev_wv = 0;
1946 } 1989 }
@@ -1955,19 +1998,22 @@ xmenu_show (f, x, y, for_click, keymaps, title, error)
1955 else 1998 else
1956 { 1999 {
1957 /* Create a new item within current pane. */ 2000 /* Create a new item within current pane. */
1958 Lisp_Object item_name, enable, descrip, def; 2001 Lisp_Object item_name, enable, descrip, def, type, selected;
1959 item_name = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_NAME]; 2002 item_name = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_NAME];
1960 enable = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_ENABLE]; 2003 enable = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_ENABLE];
1961 descrip 2004 descrip
1962 = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_EQUIV_KEY]; 2005 = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_EQUIV_KEY];
1963 def = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_DEFINITION]; 2006 def = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_DEFINITION];
2007 type = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_TYPE];
2008 selected = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_SELECTED];
2009
1964#ifndef HAVE_MULTILINGUAL_MENU 2010#ifndef HAVE_MULTILINGUAL_MENU
1965 if (STRINGP (item_name) && STRING_MULTIBYTE (item_name)) 2011 if (STRINGP (item_name) && STRING_MULTIBYTE (item_name))
1966 item_name = string_make_unibyte (item_name); 2012 item_name = string_make_unibyte (item_name);
1967 if (STRINGP (descrip) && STRING_MULTIBYTE (descrip)) 2013 if (STRINGP (descrip) && STRING_MULTIBYTE (descrip))
1968 item_name = string_make_unibyte (descrip); 2014 item_name = string_make_unibyte (descrip);
1969#endif 2015#endif
1970 2016
1971 wv = xmalloc_widget_value (); 2017 wv = xmalloc_widget_value ();
1972 if (prev_wv) 2018 if (prev_wv)
1973 prev_wv->next = wv; 2019 prev_wv->next = wv;
@@ -1983,6 +2029,18 @@ xmenu_show (f, x, y, for_click, keymaps, title, error)
1983 wv->call_data 2029 wv->call_data
1984 = (!NILP (def) ? (void *) &XVECTOR (menu_items)->contents[i] : 0); 2030 = (!NILP (def) ? (void *) &XVECTOR (menu_items)->contents[i] : 0);
1985 wv->enabled = !NILP (enable); 2031 wv->enabled = !NILP (enable);
2032
2033 if (NILP (type))
2034 wv->button_type = BUTTON_TYPE_NONE;
2035 else if (EQ (type, QCtoggle))
2036 wv->button_type = BUTTON_TYPE_TOGGLE;
2037 else if (EQ (type, QCradio))
2038 wv->button_type = BUTTON_TYPE_RADIO;
2039 else
2040 abort ();
2041
2042 wv->selected = !NILP (selected);
2043
1986 prev_wv = wv; 2044 prev_wv = wv;
1987 2045
1988 i += MENU_ITEMS_ITEM_LENGTH; 2046 i += MENU_ITEMS_ITEM_LENGTH;
@@ -2008,6 +2066,7 @@ xmenu_show (f, x, y, for_click, keymaps, title, error)
2008#endif 2066#endif
2009 wv_title->name = (char *) XSTRING (title)->data; 2067 wv_title->name = (char *) XSTRING (title)->data;
2010 wv_title->enabled = True; 2068 wv_title->enabled = True;
2069 wv_title->button_type = BUTTON_TYPE_NONE;
2011 wv_title->next = wv_sep1; 2070 wv_title->next = wv_sep1;
2012 first_wv->contents = wv_title; 2071 first_wv->contents = wv_title;
2013 } 2072 }
@@ -2085,6 +2144,17 @@ xmenu_show (f, x, y, for_click, keymaps, title, error)
2085 /* Process events that apply to the menu. */ 2144 /* Process events that apply to the menu. */
2086 popup_get_selection ((XEvent *) 0, FRAME_X_DISPLAY_INFO (f), menu_id); 2145 popup_get_selection ((XEvent *) 0, FRAME_X_DISPLAY_INFO (f), menu_id);
2087 2146
2147#ifdef LESSTIF_VERSION
2148 /* Nov 1998: For an unknown reason a button grab remains active
2149 after the popup menu has gone. */
2150 XUngrabButton (XtDisplay (f->output_data.x->widget),
2151 AnyButton, AnyModifier,
2152 XtWindow (f->output_data.x->widget));
2153 XUngrabButton (XtDisplay (f->output_data.x->edit_widget),
2154 AnyButton, AnyModifier,
2155 XtWindow (f->output_data.x->edit_widget));
2156#endif /* LESSTIF_VERSION */
2157
2088 /* fp turned off the following statement and wrote a comment 2158 /* fp turned off the following statement and wrote a comment
2089 that it is unnecessary--that the menu has already disappeared. 2159 that it is unnecessary--that the menu has already disappeared.
2090 Nowadays the menu disappears ok, all right, but 2160 Nowadays the menu disappears ok, all right, but