X-Git-Url: https://git.hcoop.net/bpt/emacs.git/blobdiff_plain/bf82bce457d7339e8468a52ae6f1687234a0c29b..0b1e6b549bf36860245f074737c05390c65b45bb:/src/xmenu.c diff --git a/src/xmenu.c b/src/xmenu.c index e5fffdaef5..06b0f9f77e 100644 --- a/src/xmenu.c +++ b/src/xmenu.c @@ -1,5 +1,6 @@ /* X Communication module for terminals which understand the X protocol. - Copyright (C) 1986, 1988, 1993, 1994, 1996 Free Software Foundation, Inc. + Copyright (C) 1986, 88, 93, 94, 96, 99, 2000, 2001 + Free Software Foundation, Inc. This file is part of GNU Emacs. @@ -18,7 +19,7 @@ along with GNU Emacs; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* X pop-up deck-of-cards menu facility for gnuemacs. +/* X pop-up deck-of-cards menu facility for GNU Emacs. * * Written by Jon Arnold and Roman Budzianowski * Mods and rewrite by Robert Krawitz @@ -30,21 +31,23 @@ Boston, MA 02111-1307, USA. */ /* Rewritten for clarity and GC protection by rms in Feb 94. */ +#include + /* On 4.3 this loses if it comes after xterm.h. */ #include -#include -#ifdef HAVE_STDLIB_H -#include -#endif #include + #include "lisp.h" #include "termhooks.h" +#include "keyboard.h" +#include "keymap.h" #include "frame.h" #include "window.h" -#include "keyboard.h" #include "blockinput.h" #include "buffer.h" +#include "charset.h" +#include "coding.h" #ifdef MSDOS #include "msdos.h" @@ -67,6 +70,7 @@ Boston, MA 02111-1307, USA. */ #ifdef HAVE_X_WINDOWS #undef HAVE_MULTILINGUAL_MENU #ifdef USE_X_TOOLKIT +#include "widget.h" #include #include #include @@ -81,13 +85,6 @@ Boston, MA 02111-1307, USA. */ #endif /* not USE_X_TOOLKIT */ #endif /* HAVE_X_WINDOWS */ -#ifdef USE_MOTIF -#include /* for LESSTIF_VERSION */ -#endif - -#define min(x,y) (((x) < (y)) ? (x) : (y)) -#define max(x,y) (((x) > (y)) ? (x) : (y)) - #ifndef TRUE #define TRUE 1 #define FALSE 0 @@ -116,24 +113,25 @@ extern XtAppContext Xt_app_con; static Lisp_Object xdialog_show (); void popup_get_selection (); -#endif -#ifdef USE_X_TOOLKIT - -/* Define HAVE_BOXES if meus can handle radio and toggle buttons. */ +/* Define HAVE_BOXES if menus can handle radio and toggle buttons. */ #define HAVE_BOXES 1 #endif static void push_menu_item P_ ((Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, - Lisp_Object)); -static Lisp_Object xmenu_show (); -static void keymap_panes (); -static void single_keymap_panes (); -static void single_menu_item (); -static void list_of_panes (); -static void list_of_items (); + Lisp_Object, Lisp_Object)); +static int update_frame_menubar P_ ((struct frame *)); +static Lisp_Object xmenu_show P_ ((struct frame *, int, int, int, int, + Lisp_Object, char **)); +static void keymap_panes P_ ((Lisp_Object *, int, int)); +static void single_keymap_panes P_ ((Lisp_Object, Lisp_Object, Lisp_Object, + int, int)); +static void single_menu_item P_ ((Lisp_Object, Lisp_Object, Lisp_Object *, + int, int, int *)); +static void list_of_panes P_ ((Lisp_Object)); +static void list_of_items P_ ((Lisp_Object)); /* This holds a Lisp vector that holds the results of decoding the keymaps or alist-of-alists that specify a menu. @@ -161,14 +159,18 @@ static void list_of_items (); #define MENU_ITEMS_PANE_PREFIX 2 #define MENU_ITEMS_PANE_LENGTH 3 -#define MENU_ITEMS_ITEM_NAME 0 -#define MENU_ITEMS_ITEM_ENABLE 1 -#define MENU_ITEMS_ITEM_VALUE 2 -#define MENU_ITEMS_ITEM_EQUIV_KEY 3 -#define MENU_ITEMS_ITEM_DEFINITION 4 -#define MENU_ITEMS_ITEM_TYPE 5 -#define MENU_ITEMS_ITEM_SELECTED 6 -#define MENU_ITEMS_ITEM_LENGTH 7 +enum menu_item_idx +{ + MENU_ITEMS_ITEM_NAME = 0, + MENU_ITEMS_ITEM_ENABLE, + MENU_ITEMS_ITEM_VALUE, + MENU_ITEMS_ITEM_EQUIV_KEY, + MENU_ITEMS_ITEM_DEFINITION, + MENU_ITEMS_ITEM_TYPE, + MENU_ITEMS_ITEM_SELECTED, + MENU_ITEMS_ITEM_HELP, + MENU_ITEMS_ITEM_LENGTH +}; static Lisp_Object menu_items; @@ -187,7 +189,7 @@ static int menu_items_submenu_depth; /* Flag which when set indicates a dialog or menu has been posted by Xt on behalf of one of the widget sets. */ -static int popup_activated_flag; +int popup_activated_flag; static int next_menubar_widget_id; @@ -217,7 +219,7 @@ menubar_id_to_frame (id) if (!GC_FRAMEP (frame)) continue; f = XFRAME (frame); - if (f->output_data.nothing == 1) + if (!FRAME_WINDOW_P (f)) continue; if (f->output_data.x->id == id) return f; @@ -244,8 +246,7 @@ init_menu_items () menu_items_submenu_depth = 0; } -/* Call at the end of generating the data in menu_items. - This fills in the number of items in the last pane. */ +/* Call at the end of generating the data in menu_items. */ static void finish_menu_items () @@ -317,7 +318,7 @@ push_left_right_boundary () XVECTOR (menu_items)->contents[menu_items_used++] = Qquote; } -/* Start a new menu pane in menu_items.. +/* Start a new menu pane in menu_items. NAME is the pane name. PREFIX_VEC is a prefix key for this pane. */ static void @@ -343,8 +344,8 @@ push_menu_pane (name, prefix_vec) item, one of nil, `toggle' or `radio'. */ static void -push_menu_item (name, enable, key, def, equiv, type, selected) - Lisp_Object name, enable, key, def, equiv, type, selected; +push_menu_item (name, enable, key, def, equiv, type, selected, help) + Lisp_Object name, enable, key, def, equiv, type, selected, help; { if (menu_items_used + MENU_ITEMS_ITEM_LENGTH > menu_items_allocated) grow_menu_items (); @@ -356,6 +357,7 @@ push_menu_item (name, enable, key, def, equiv, type, selected) XVECTOR (menu_items)->contents[menu_items_used++] = def; XVECTOR (menu_items)->contents[menu_items_used++] = type; XVECTOR (menu_items)->contents[menu_items_used++] = selected; + XVECTOR (menu_items)->contents[menu_items_used++] = help; } /* Look through KEYMAPS, a vector of keymaps that is NMAPS long, @@ -377,7 +379,8 @@ keymap_panes (keymaps, nmaps, notreal) But don't make a pane that is empty--ignore that map instead. P is the number of panes we have made so far. */ for (mapno = 0; mapno < nmaps; mapno++) - single_keymap_panes (keymaps[mapno], Qnil, Qnil, notreal, 10); + single_keymap_panes (keymaps[mapno], + Fkeymap_prompt (keymaps[mapno]), Qnil, notreal, 10); finish_menu_items (); } @@ -584,7 +587,8 @@ single_menu_item (key, item, pending_maps_ptr, notreal, maxdepth, XVECTOR (item_properties)->contents[ITEM_PROPERTY_DEF], XVECTOR (item_properties)->contents[ITEM_PROPERTY_KEYEQ], XVECTOR (item_properties)->contents[ITEM_PROPERTY_TYPE], - XVECTOR (item_properties)->contents[ITEM_PROPERTY_SELECTED]); + XVECTOR (item_properties)->contents[ITEM_PROPERTY_SELECTED], + XVECTOR (item_properties)->contents[ITEM_PROPERTY_HELP]); #ifdef USE_X_TOOLKIT /* Display a submenu using the toolkit. */ @@ -614,10 +618,10 @@ list_of_panes (menu) Lisp_Object elt, pane_name, pane_data; elt = Fcar (tail); pane_name = Fcar (elt); - CHECK_STRING (pane_name, 0); + CHECK_STRING (pane_name); push_menu_pane (pane_name, Qnil); pane_data = Fcdr (elt); - CHECK_CONS (pane_data, 0); + CHECK_CONS (pane_data); list_of_items (pane_data); } @@ -636,61 +640,62 @@ list_of_items (pane) { item = Fcar (tail); if (STRINGP (item)) - push_menu_item (item, Qnil, Qnil, Qt, Qnil, Qnil, Qnil); + push_menu_item (item, Qnil, Qnil, Qt, Qnil, Qnil, Qnil, Qnil); else if (NILP (item)) push_left_right_boundary (); else { - CHECK_CONS (item, 0); + CHECK_CONS (item); item1 = Fcar (item); - CHECK_STRING (item1, 1); - push_menu_item (item1, Qt, Fcdr (item), Qt, Qnil, Qnil, Qnil); + CHECK_STRING (item1); + push_menu_item (item1, Qt, Fcdr (item), Qt, Qnil, Qnil, Qnil, Qnil); } } } DEFUN ("x-popup-menu", Fx_popup_menu, Sx_popup_menu, 2, 2, 0, - "Pop up a deck-of-cards menu and return user's selection.\n\ -POSITION is a position specification. This is either a mouse button event\n\ -or a list ((XOFFSET YOFFSET) WINDOW)\n\ -where XOFFSET and YOFFSET are positions in pixels from the top left\n\ -corner of WINDOW's frame. (WINDOW may be a frame object instead of a window.)\n\ -This controls the position of the center of the first line\n\ -in the first pane of the menu, not the top left of the menu as a whole.\n\ -If POSITION is t, it means to use the current mouse position.\n\ -\n\ -MENU is a specifier for a menu. For the simplest case, MENU is a keymap.\n\ -The menu items come from key bindings that have a menu string as well as\n\ -a definition; actually, the \"definition\" in such a key binding looks like\n\ -\(STRING . REAL-DEFINITION). To give the menu a title, put a string into\n\ -the keymap as a top-level element.\n\n\ -If REAL-DEFINITION is nil, that puts a nonselectable string in the menu.\n\ -Otherwise, REAL-DEFINITION should be a valid key binding definition.\n\ -\n\ -You can also use a list of keymaps as MENU.\n\ - Then each keymap makes a separate pane.\n\ -When MENU is a keymap or a list of keymaps, the return value\n\ -is a list of events.\n\n\ -\n\ -Alternatively, you can specify a menu of multiple panes\n\ - with a list of the form (TITLE PANE1 PANE2...),\n\ -where each pane is a list of form (TITLE ITEM1 ITEM2...).\n\ -Each ITEM is normally a cons cell (STRING . VALUE);\n\ -but a string can appear as an item--that makes a nonselectable line\n\ -in the menu.\n\ -With this form of menu, the return value is VALUE from the chosen item.\n\ -\n\ -If POSITION is nil, don't display the menu at all, just precalculate the\n\ -cached information about equivalent key sequences.") - (position, menu) + doc: /* Pop up a deck-of-cards menu and return user's selection. +POSITION is a position specification. This is either a mouse button event +or a list ((XOFFSET YOFFSET) WINDOW) +where XOFFSET and YOFFSET are positions in pixels from the top left +corner of WINDOW's frame. (WINDOW may be a frame object instead of a window.) +This controls the position of the center of the first line +in the first pane of the menu, not the top left of the menu as a whole. +If POSITION is t, it means to use the current mouse position. + +MENU is a specifier for a menu. For the simplest case, MENU is a keymap. +The menu items come from key bindings that have a menu string as well as +a definition; actually, the "definition" in such a key binding looks like +\(STRING . REAL-DEFINITION). To give the menu a title, put a string into +the keymap as a top-level element. + +If REAL-DEFINITION is nil, that puts a nonselectable string in the menu. +Otherwise, REAL-DEFINITION should be a valid key binding definition. + +You can also use a list of keymaps as MENU. + Then each keymap makes a separate pane. +When MENU is a keymap or a list of keymaps, the return value +is a list of events. + +Alternatively, you can specify a menu of multiple panes + with a list of the form (TITLE PANE1 PANE2...), +where each pane is a list of form (TITLE ITEM1 ITEM2...). +Each ITEM is normally a cons cell (STRING . VALUE); +but a string can appear as an item--that makes a nonselectable line +in the menu. +With this form of menu, the return value is VALUE from the chosen item. + +If POSITION is nil, don't display the menu at all, just precalculate the +cached information about equivalent key sequences. */) + (position, menu) Lisp_Object position, menu; { Lisp_Object keymap, tem; - int xpos, ypos; + int xpos = 0, ypos = 0; Lisp_Object title; char *error_name; Lisp_Object selection; - FRAME_PTR f; + FRAME_PTR f = NULL; Lisp_Object x, y, window; int keymaps = 0; int for_click = 0; @@ -703,7 +708,8 @@ cached information about equivalent key sequences.") /* Decode the first argument: find the window and the coordinates. */ if (EQ (position, Qt) - || (CONSP (position) && EQ (XCAR (position), Qmenu_bar))) + || (CONSP (position) && (EQ (XCAR (position), Qmenu_bar) + || EQ (XCAR (position), Qtool_bar)))) { /* Use the mouse's current position. */ FRAME_PTR new_f = SELECTED_FRAME (); @@ -743,8 +749,8 @@ cached information about equivalent key sequences.") } } - CHECK_NUMBER (x, 0); - CHECK_NUMBER (y, 0); + CHECK_NUMBER (x); + CHECK_NUMBER (y); /* Decode where to put the menu. */ @@ -756,18 +762,18 @@ cached information about equivalent key sequences.") } else if (WINDOWP (window)) { - CHECK_LIVE_WINDOW (window, 0); + CHECK_LIVE_WINDOW (window); f = XFRAME (WINDOW_FRAME (XWINDOW (window))); - xpos = (FONT_WIDTH (f->output_data.x->font) + xpos = (FONT_WIDTH (FRAME_FONT (f)) * XFASTINT (XWINDOW (window)->left)); - ypos = (f->output_data.x->line_height + ypos = (FRAME_LINE_HEIGHT (f) * XFASTINT (XWINDOW (window)->top)); } else /* ??? Not really clean; should be CHECK_WINDOW_OR_FRAME, but I don't want to make one now. */ - CHECK_WINDOW (window, 0); + CHECK_WINDOW (window); xpos += XINT (x); ypos += XINT (y); @@ -782,22 +788,18 @@ cached information about equivalent key sequences.") /* Decode the menu items from what was specified. */ - keymap = Fkeymapp (menu); - tem = Qnil; - if (CONSP (menu)) - tem = Fkeymapp (Fcar (menu)); - if (!NILP (keymap)) + keymap = get_keymap (menu, 0, 0); + if (CONSP (keymap)) { /* We were given a keymap. Extract menu info from the keymap. */ Lisp_Object prompt; - keymap = get_keymap (menu); /* Extract the detailed info to make one pane. */ keymap_panes (&menu, 1, NILP (position)); /* Search for a string appearing directly as an element of the keymap. That string is the title of the menu. */ - prompt = map_prompt (keymap); + prompt = Fkeymap_prompt (keymap); if (NILP (title) && !NILP (prompt)) title = prompt; @@ -807,7 +809,7 @@ cached information about equivalent key sequences.") keymaps = 1; } - else if (!NILP (tem)) + else if (CONSP (menu) && KEYMAPP (XCAR (menu))) { /* We were given a list of keymaps. */ int nmaps = XFASTINT (Flength (menu)); @@ -823,9 +825,9 @@ cached information about equivalent key sequences.") { Lisp_Object prompt; - maps[i++] = keymap = get_keymap (Fcar (tem)); + maps[i++] = keymap = get_keymap (Fcar (tem), 1, 0); - prompt = map_prompt (keymap); + prompt = Fkeymap_prompt (keymap); if (NILP (title) && !NILP (prompt)) title = prompt; } @@ -843,7 +845,7 @@ cached information about equivalent key sequences.") { /* We were given an old-fashioned menu. */ title = Fcar (menu); - CHECK_STRING (title, 1); + CHECK_STRING (title); list_of_panes (Fcdr (menu)); @@ -877,37 +879,39 @@ cached information about equivalent key sequences.") #ifdef HAVE_MENUS DEFUN ("x-popup-dialog", Fx_popup_dialog, Sx_popup_dialog, 2, 2, 0, - "Pop up a dialog box and return user's selection.\n\ -POSITION specifies which frame to use.\n\ -This is normally a mouse button event or a window or frame.\n\ -If POSITION is t, it means to use the frame the mouse is on.\n\ -The dialog box appears in the middle of the specified frame.\n\ -\n\ -CONTENTS specifies the alternatives to display in the dialog box.\n\ -It is a list of the form (TITLE ITEM1 ITEM2...).\n\ -Each ITEM is a cons cell (STRING . VALUE).\n\ -The return value is VALUE from the chosen item.\n\n\ -An ITEM may also be just a string--that makes a nonselectable item.\n\ -An ITEM may also be nil--that means to put all preceding items\n\ -on the left of the dialog box and all following items on the right.\n\ -\(By default, approximately half appear on each side.)") - (position, contents) + doc: /* Pop up a dialog box and return user's selection. +POSITION specifies which frame to use. +This is normally a mouse button event or a window or frame. +If POSITION is t, it means to use the frame the mouse is on. +The dialog box appears in the middle of the specified frame. + +CONTENTS specifies the alternatives to display in the dialog box. +It is a list of the form (TITLE ITEM1 ITEM2...). +Each ITEM is a cons cell (STRING . VALUE). +The return value is VALUE from the chosen item. + +An ITEM may also be just a string--that makes a nonselectable item. +An ITEM may also be nil--that means to put all preceding items +on the left of the dialog box and all following items on the right. +\(By default, approximately half appear on each side.) */) + (position, contents) Lisp_Object position, contents; { - FRAME_PTR f; + FRAME_PTR f = NULL; Lisp_Object window; check_x (); /* Decode the first argument: find the window or frame to use. */ if (EQ (position, Qt) - || (CONSP (position) && EQ (XCAR (position), Qmenu_bar))) + || (CONSP (position) && (EQ (XCAR (position), Qmenu_bar) + || EQ (XCAR (position), Qtool_bar)))) { #if 0 /* Using the frame the mouse is on may not be right. */ /* Use the mouse's current position. */ FRAME_PTR new_f = SELECTED_FRAME (); Lisp_Object bar_window; - int part; + enum scroll_bar_part part; unsigned long time; Lisp_Object x, y; @@ -943,13 +947,13 @@ on the left of the dialog box and all following items on the right.\n\ f = XFRAME (window); else if (WINDOWP (window)) { - CHECK_LIVE_WINDOW (window, 0); + CHECK_LIVE_WINDOW (window); f = XFRAME (WINDOW_FRAME (XWINDOW (window))); } else /* ??? Not really clean; should be CHECK_WINDOW_OR_FRAME, but I don't want to make one now. */ - CHECK_WINDOW (window, 0); + CHECK_WINDOW (window); #ifndef USE_X_TOOLKIT /* Display a menu with these alternatives @@ -972,7 +976,7 @@ on the left of the dialog box and all following items on the right.\n\ /* Decode the dialog items from what was specified. */ title = Fcar (contents); - CHECK_STRING (title, 1); + CHECK_STRING (title); list_of_panes (Fcons (contents, Qnil)); @@ -1074,14 +1078,10 @@ popup_get_selection (initial_event, dpyinfo, id) && (event.xany.display != dpyinfo->display || x_non_menubar_window_to_frame (dpyinfo, event.xany.window))) { - queue_tmp = (struct event_queue *) malloc (sizeof (struct event_queue)); - - if (queue_tmp != NULL) - { - queue_tmp->event = event; - queue_tmp->next = queue; - queue = queue_tmp; - } + queue_tmp = (struct event_queue *) xmalloc (sizeof *queue_tmp); + queue_tmp->event = event; + queue_tmp->next = queue; + queue = queue_tmp; } else XtDispatchEvent (&event); @@ -1097,7 +1097,7 @@ popup_get_selection (initial_event, dpyinfo, id) queue_tmp = queue; XPutBackEvent (queue_tmp->event.xany.display, &queue_tmp->event); queue = queue_tmp->next; - free ((char *)queue_tmp); + xfree ((char *)queue_tmp); /* Cause these events to get read as soon as we UNBLOCK_INPUT. */ interrupt_input_pending = 1; } @@ -1145,7 +1145,6 @@ popup_activated () return popup_activated_flag; } - /* This callback is invoked when the user selects a menubar cascade pushbutton, but before the pulldown menu is posted. */ @@ -1158,6 +1157,63 @@ popup_activate_callback (widget, id, client_data) popup_activated_flag = 1; } +/* This callback is invoked when a dialog or menu is finished being + used and has been unposted. */ + +static void +popup_deactivate_callback (widget, id, client_data) + Widget widget; + LWLIB_ID id; + XtPointer client_data; +{ + popup_activated_flag = 0; +} + +/* Lwlib callback called when menu items are highlighted/unhighlighted + while moving the mouse over them. WIDGET is the menu bar or menu + popup widget. ID is its LWLIB_ID. CALL_DATA contains a pointer to + the widget_value structure for the menu item, or null in case of + unhighlighting. */ + +void +menu_highlight_callback (widget, id, call_data) + Widget widget; + LWLIB_ID id; + void *call_data; +{ + widget_value *wv = (widget_value *) call_data; + struct frame *f; + Lisp_Object frame, help; + + help = wv ? wv->help : Qnil; + + /* Determine the frame for the help event. */ + f = menubar_id_to_frame (id); + if (f) + { + XSETFRAME (frame, f); + kbd_buffer_store_help_event (frame, help); + } + else + { + /* WIDGET is the popup menu. It's parent is the frame's + widget. See which frame that is. */ + Widget frame_widget = XtParent (widget); + Lisp_Object tail; + + for (tail = Vframe_list; GC_CONSP (tail); tail = XCDR (tail)) + { + frame = XCAR (tail); + if (GC_FRAMEP (frame) + && (f = XFRAME (frame), + FRAME_X_P (f) && f->output_data.x->widget == frame_widget)) + break; + } + + show_help_echo (help, Qnil, Qnil, Qnil, 1); + } +} + /* This callback is called from the menu bar pulldown menu when the user makes a selection. Figure out what the user chose @@ -1178,6 +1234,7 @@ menubar_selection_callback (widget, id, client_data) if (!f) return; + entry = Qnil; subprefix_stack = (Lisp_Object *) alloca (f->menu_bar_items_used * sizeof (Lisp_Object)); vector = f->menu_bar_vector; prefix = Qnil; @@ -1212,27 +1269,31 @@ menubar_selection_callback (widget, id, client_data) Lisp_Object frame; XSETFRAME (frame, f); - buf.kind = menu_bar_event; - buf.frame_or_window = Fcons (frame, Fcons (Qmenu_bar, Qnil)); + buf.kind = MENU_BAR_EVENT; + buf.frame_or_window = frame; + buf.arg = frame; kbd_buffer_store_event (&buf); for (j = 0; j < submenu_depth; j++) if (!NILP (subprefix_stack[j])) { - buf.kind = menu_bar_event; - buf.frame_or_window = Fcons (frame, subprefix_stack[j]); + buf.kind = MENU_BAR_EVENT; + buf.frame_or_window = frame; + buf.arg = subprefix_stack[j]; kbd_buffer_store_event (&buf); } if (!NILP (prefix)) { - buf.kind = menu_bar_event; - buf.frame_or_window = Fcons (frame, prefix); + buf.kind = MENU_BAR_EVENT; + buf.frame_or_window = frame; + buf.arg = prefix; kbd_buffer_store_event (&buf); } - buf.kind = menu_bar_event; - buf.frame_or_window = Fcons (frame, entry); + buf.kind = MENU_BAR_EVENT; + buf.frame_or_window = frame; + buf.arg = entry; kbd_buffer_store_event (&buf); return; @@ -1242,18 +1303,6 @@ menubar_selection_callback (widget, id, client_data) } } -/* This callback is invoked when a dialog or menu is finished being - used and has been unposted. */ - -static void -popup_deactivate_callback (widget, id, client_data) - Widget widget; - LWLIB_ID id; - XtPointer client_data; -{ - popup_activated_flag = 0; -} - /* Allocate a widget_value, blocking input. */ widget_value * @@ -1332,14 +1381,14 @@ single_submenu (item_key, item_name, maps) for (i = 0; i < len; i++) { if (SYMBOLP (mapvec[i]) - || (CONSP (mapvec[i]) - && NILP (Fkeymapp (mapvec[i])))) + || (CONSP (mapvec[i]) && !KEYMAPP (mapvec[i]))) { /* Here we have a command at top level in the menu bar as opposed to a submenu. */ top_level_items = 1; push_menu_pane (Qnil, Qnil); - push_menu_item (item_name, Qt, item_key, mapvec[i], Qnil, Qnil, Qnil); + push_menu_item (item_name, Qt, item_key, mapvec[i], + Qnil, Qnil, Qnil, Qnil); } else single_keymap_panes (mapvec[i], item_name, item_key, 0, 10); @@ -1355,6 +1404,7 @@ single_submenu (item_key, item_name, maps) wv->value = 0; wv->enabled = 1; wv->button_type = BUTTON_TYPE_NONE; + wv->help = Qnil; first_wv = wv; save_wv = 0; prev_wv = 0; @@ -1391,11 +1441,16 @@ single_submenu (item_key, item_name, maps) /* Create a new pane. */ Lisp_Object pane_name, prefix; char *pane_string; + pane_name = XVECTOR (menu_items)->contents[i + MENU_ITEMS_PANE_NAME]; prefix = XVECTOR (menu_items)->contents[i + MENU_ITEMS_PANE_PREFIX]; + #ifndef HAVE_MULTILINGUAL_MENU if (STRINGP (pane_name) && STRING_MULTIBYTE (pane_name)) - pane_name = string_make_unibyte (pane_name); + { + pane_name = ENCODE_SYSTEM (pane_name); + AREF (menu_items, i + MENU_ITEMS_PANE_NAME) = pane_name; + } #endif pane_string = (NILP (pane_name) ? "" : (char *) XSTRING (pane_name)->data); @@ -1422,6 +1477,7 @@ single_submenu (item_key, item_name, maps) wv->value = 0; wv->enabled = 1; wv->button_type = BUTTON_TYPE_NONE; + wv->help = Qnil; } save_wv = wv; prev_wv = 0; @@ -1431,20 +1487,29 @@ single_submenu (item_key, item_name, maps) { /* Create a new item within current pane. */ Lisp_Object item_name, enable, descrip, def, type, selected; - item_name = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_NAME]; - enable = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_ENABLE]; - descrip - = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_EQUIV_KEY]; - def = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_DEFINITION]; - type = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_TYPE]; - selected = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_SELECTED]; + Lisp_Object help; + + item_name = AREF (menu_items, i + MENU_ITEMS_ITEM_NAME); + enable = AREF (menu_items, i + MENU_ITEMS_ITEM_ENABLE); + descrip = AREF (menu_items, i + MENU_ITEMS_ITEM_EQUIV_KEY); + def = AREF (menu_items, i + MENU_ITEMS_ITEM_DEFINITION); + type = AREF (menu_items, i + MENU_ITEMS_ITEM_TYPE); + selected = AREF (menu_items, i + MENU_ITEMS_ITEM_SELECTED); + help = AREF (menu_items, i + MENU_ITEMS_ITEM_HELP); #ifndef HAVE_MULTILINGUAL_MENU if (STRING_MULTIBYTE (item_name)) - item_name = string_make_unibyte (item_name); + { + item_name = ENCODE_SYSTEM (item_name); + AREF (menu_items, i + MENU_ITEMS_ITEM_NAME) = item_name; + } + if (STRINGP (descrip) && STRING_MULTIBYTE (descrip)) - descrip = string_make_unibyte (descrip); -#endif + { + descrip = ENCODE_SYSTEM (descrip); + AREF (menu_items, i + MENU_ITEMS_ITEM_EQUIV_KEY) = descrip; + } +#endif /* not HAVE_MULTILINGUAL_MENU */ wv = xmalloc_widget_value (); if (prev_wv) @@ -1471,7 +1536,11 @@ single_submenu (item_key, item_name, maps) abort (); wv->selected = !NILP (selected); - + if (! STRINGP (help)) + help = Qnil; + + wv->help = help; + prev_wv = wv; i += MENU_ITEMS_ITEM_LENGTH; @@ -1489,64 +1558,51 @@ single_submenu (item_key, item_name, maps) return first_wv; } - -extern void EmacsFrameSetCharSize (); -/* Recompute all the widgets of frame F, when the menu bar - has been changed. */ -static void + +/* Recompute all the widgets of frame F, when the menu bar has been + changed. Value is non-zero if widgets were updated. */ + +static int update_frame_menubar (f) FRAME_PTR f; { struct x_output *x = f->output_data.x; int columns, rows; - int menubar_changed; - /* We assume the menubar contents has changed if the global flag is set, - or if the current buffer has changed, or if the menubar has never - been updated before. - */ - menubar_changed = (x->menubar_widget - && !XtIsManaged (x->menubar_widget)); - - if (! (menubar_changed)) - return; + if (!x->menubar_widget || XtIsManaged (x->menubar_widget)) + return 0; BLOCK_INPUT; - /* Save the size of the frame because the pane widget doesn't accept to - resize itself. So force it. */ + /* Save the size of the frame because the pane widget doesn't accept + to resize itself. So force it. */ columns = f->width; rows = f->height; - /* Do the voodoo which means "I'm changing lots of things, don't try to - refigure sizes until I'm done." */ + /* Do the voodoo which means "I'm changing lots of things, don't try + to refigure sizes until I'm done." */ lw_refigure_widget (x->column_widget, False); - /* the order in which children are managed is the top to - bottom order in which they are displayed in the paned window. - First, remove the text-area widget. - */ + /* The order in which children are managed is the top to bottom + order in which they are displayed in the paned window. First, + remove the text-area widget. */ XtUnmanageChild (x->edit_widget); - /* remove the menubar that is there now, and put up the menubar that - should be there. - */ - if (menubar_changed) - { - XtManageChild (x->menubar_widget); - XtMapWidget (x->menubar_widget); - XtVaSetValues (x->menubar_widget, XtNmappedWhenManaged, 1, 0); - } + /* Remove the menubar that is there now, and put up the menubar that + should be there. */ + XtManageChild (x->menubar_widget); + XtMapWidget (x->menubar_widget); + XtVaSetValues (x->menubar_widget, XtNmappedWhenManaged, 1, NULL); /* Re-manage the text-area widget, and then thrash the sizes. */ XtManageChild (x->edit_widget); - x_set_menu_resources_from_menu_face (f, x->menubar_widget); lw_refigure_widget (x->column_widget, True); /* Force the pane widget to resize itself with the right values. */ EmacsFrameSetCharSize (x->edit_widget, columns, rows); UNBLOCK_INPUT; + return 1; } /* Set the contents of the menubar widgets of frame F. @@ -1563,6 +1619,7 @@ set_frame_menubar (f, first_time, deep_p) Lisp_Object items; widget_value *wv, *first_wv, *prev_wv = 0; int i; + LWLIB_ID id; XSETFRAME (Vmenu_updating_frame, f); @@ -1623,7 +1680,8 @@ set_frame_menubar (f, first_time, deep_p) set_buffer_internal_1 (XBUFFER (buffer)); /* Run the Lucid hook. */ - call1 (Vrun_hooks, Qactivate_menubar_hook); + safe_run_hooks (Qactivate_menubar_hook); + /* If it has changed current-menubar from previous value, really recompute the menubar from the value. */ if (! NILP (Vlucid_menu_bar_dirty_flag)) @@ -1636,12 +1694,13 @@ set_frame_menubar (f, first_time, deep_p) inhibit_garbage_collection (); /* Save the frame's previous menu bar contents data. */ - bcopy (XVECTOR (f->menu_bar_vector)->contents, previous_items, - previous_menu_items_used * sizeof (Lisp_Object)); + if (previous_menu_items_used) + bcopy (XVECTOR (f->menu_bar_vector)->contents, previous_items, + previous_menu_items_used * sizeof (Lisp_Object)); /* Fill in the current menu bar contents. */ menu_items = f->menu_bar_vector; - menu_items_allocated = XVECTOR (menu_items)->size; + menu_items_allocated = VECTORP (menu_items) ? ASIZE (menu_items) : 0; init_menu_items (); for (i = 0; i < XVECTOR (items)->size; i += 4) { @@ -1762,7 +1821,8 @@ set_frame_menubar (f, first_time, deep_p) 0, popup_activate_callback, menubar_selection_callback, - popup_deactivate_callback); + popup_deactivate_callback, + menu_highlight_callback); f->output_data.x->menubar_widget = menubar_widget; } @@ -1810,6 +1870,7 @@ initialize_frame_menubar (f) set_frame_menubar (f, 1, 1); } + /* Get rid of the menu bar of frame F, and free its storage. This is used when deleting a frame, and when turning off the menu bar. */ @@ -1825,8 +1886,37 @@ free_frame_menubar (f) if (menubar_widget) { +#ifdef USE_MOTIF + /* Removing the menu bar magically changes the shell widget's x + and y position of (0, 0) which, when the menu bar is turned + on again, leads to pull-down menuss appearing in strange + positions near the upper-left corner of the display. This + happens only with some window managers like twm and ctwm, + but not with other like Motif's mwm or kwm, because the + latter generate ConfigureNotify events when the menu bar + is switched off, which fixes the shell position. */ + Position x0, y0, x1, y1; +#endif + BLOCK_INPUT; + +#ifdef USE_MOTIF + if (f->output_data.x->widget) + XtVaGetValues (f->output_data.x->widget, XtNx, &x0, XtNy, &y0, NULL); +#endif + lw_destroy_all_widgets ((LWLIB_ID) f->output_data.x->id); + f->output_data.x->menubar_widget = NULL; + +#ifdef USE_MOTIF + if (f->output_data.x->widget) + { + XtVaGetValues (f->output_data.x->widget, XtNx, &x1, XtNy, &y1, NULL); + if (x1 == 0 && y1 == 0) + XtVaSetValues (f->output_data.x->widget, XtNx, x0, XtNy, y0, NULL); + } +#endif + UNBLOCK_INPUT; } } @@ -1861,11 +1951,7 @@ free_frame_menubar (f) next_menubar_widget_id. */ LWLIB_ID widget_id_tick; -#ifdef __STDC__ static Lisp_Object *volatile menu_item_selection; -#else -static Lisp_Object *menu_item_selection; -#endif static void popup_selection_callback (widget, id, client_data) @@ -1950,11 +2036,16 @@ xmenu_show (f, x, y, for_click, keymaps, title, error) /* Create a new pane. */ Lisp_Object pane_name, prefix; char *pane_string; - pane_name = XVECTOR (menu_items)->contents[i + MENU_ITEMS_PANE_NAME]; - prefix = XVECTOR (menu_items)->contents[i + MENU_ITEMS_PANE_PREFIX]; + + pane_name = AREF (menu_items, i + MENU_ITEMS_PANE_NAME); + prefix = AREF (menu_items, i + MENU_ITEMS_PANE_PREFIX); + #ifndef HAVE_MULTILINGUAL_MENU - if (!NILP (pane_name) && STRING_MULTIBYTE (pane_name)) - pane_name = string_make_unibyte (pane_name); + if (STRINGP (pane_name) && STRING_MULTIBYTE (pane_name)) + { + pane_name = ENCODE_SYSTEM (pane_name); + AREF (menu_items, i + MENU_ITEMS_PANE_NAME) = pane_name; + } #endif pane_string = (NILP (pane_name) ? "" : (char *) XSTRING (pane_name)->data); @@ -1993,21 +2084,28 @@ xmenu_show (f, x, y, for_click, keymaps, title, error) else { /* Create a new item within current pane. */ - Lisp_Object item_name, enable, descrip, def, type, selected; - item_name = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_NAME]; - enable = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_ENABLE]; - descrip - = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_EQUIV_KEY]; - def = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_DEFINITION]; - type = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_TYPE]; - selected = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_SELECTED]; + Lisp_Object item_name, enable, descrip, def, type, selected, help; + item_name = AREF (menu_items, i + MENU_ITEMS_ITEM_NAME); + enable = AREF (menu_items, i + MENU_ITEMS_ITEM_ENABLE); + descrip = AREF (menu_items, i + MENU_ITEMS_ITEM_EQUIV_KEY); + def = AREF (menu_items, i + MENU_ITEMS_ITEM_DEFINITION); + type = AREF (menu_items, i + MENU_ITEMS_ITEM_TYPE); + selected = AREF (menu_items, i + MENU_ITEMS_ITEM_SELECTED); + help = AREF (menu_items, i + MENU_ITEMS_ITEM_HELP); #ifndef HAVE_MULTILINGUAL_MENU if (STRINGP (item_name) && STRING_MULTIBYTE (item_name)) - item_name = string_make_unibyte (item_name); + { + item_name = ENCODE_SYSTEM (item_name); + AREF (menu_items, i + MENU_ITEMS_ITEM_NAME) = item_name; + } + if (STRINGP (descrip) && STRING_MULTIBYTE (descrip)) - item_name = string_make_unibyte (descrip); -#endif + { + descrip = ENCODE_SYSTEM (descrip); + AREF (menu_items, i + MENU_ITEMS_ITEM_EQUIV_KEY) = descrip; + } +#endif /* not HAVE_MULTILINGUAL_MENU */ wv = xmalloc_widget_value (); if (prev_wv) @@ -2035,7 +2133,12 @@ xmenu_show (f, x, y, for_click, keymaps, title, error) abort (); wv->selected = !NILP (selected); - + + if (! STRINGP (help)) + help = Qnil; + + wv->help = help; + prev_wv = wv; i += MENU_ITEMS_ITEM_LENGTH; @@ -2057,10 +2160,11 @@ xmenu_show (f, x, y, for_click, keymaps, title, error) #ifndef HAVE_MULTILINGUAL_MENU if (STRING_MULTIBYTE (title)) - title = string_make_unibyte (title); + title = ENCODE_SYSTEM (title); #endif + wv_title->name = (char *) XSTRING (title)->data; - wv_title->enabled = True; + wv_title->enabled = TRUE; wv_title->button_type = BUTTON_TYPE_NONE; wv_title->next = wv_sep1; first_wv->contents = wv_title; @@ -2071,7 +2175,8 @@ xmenu_show (f, x, y, for_click, keymaps, title, error) menu = lw_create_widget ("popup", first_wv->name, menu_id, first_wv, f->output_data.x->widget, 1, 0, popup_selection_callback, - popup_deactivate_callback); + popup_deactivate_callback, + menu_highlight_callback); /* Adjust coordinates to relative to the outer (window manager) window. */ { @@ -2133,24 +2238,12 @@ xmenu_show (f, x, y, for_click, keymaps, title, error) menu_item_selection = 0; /* Display the menu. */ - lw_popup_menu (menu, &dummy); - x_set_menu_resources_from_menu_face (f, menu); + lw_popup_menu (menu, (XEvent *) &dummy); popup_activated_flag = 1; /* Process events that apply to the menu. */ popup_get_selection ((XEvent *) 0, FRAME_X_DISPLAY_INFO (f), menu_id); -#ifdef LESSTIF_VERSION - /* Nov 1998: For an unknown reason a button grab remains active - after the popup menu has gone. */ - XUngrabButton (XtDisplay (f->output_data.x->widget), - AnyButton, AnyModifier, - XtWindow (f->output_data.x->widget)); - XUngrabButton (XtDisplay (f->output_data.x->edit_widget), - AnyButton, AnyModifier, - XtWindow (f->output_data.x->edit_widget)); -#endif /* LESSTIF_VERSION */ - /* fp turned off the following statement and wrote a comment that it is unnecessary--that the menu has already disappeared. Nowadays the menu disappears ok, all right, but @@ -2163,7 +2256,7 @@ xmenu_show (f, x, y, for_click, keymaps, title, error) { Lisp_Object prefix, entry; - prefix = Qnil; + prefix = entry = Qnil; i = 0; while (i < menu_items_used) { @@ -2356,7 +2449,7 @@ xdialog_show (f, keymaps, title, error) dialog_id = widget_id_tick++; menu = lw_create_widget (first_wv->name, "dialog", dialog_id, first_wv, f->output_data.x->widget, 1, 0, - dialog_selection_callback, 0); + dialog_selection_callback, 0, 0); lw_modify_all_widgets (dialog_id, first_wv->contents, True); /* Free the widget_value objects we used to specify the contents. */ free_menubar_widget_value_tree (first_wv); @@ -2391,6 +2484,12 @@ xdialog_show (f, keymaps, title, error) = XVECTOR (menu_items)->contents[i + MENU_ITEMS_PANE_PREFIX]; i += MENU_ITEMS_PANE_LENGTH; } + else if (EQ (XVECTOR (menu_items)->contents[i], Qquote)) + { + /* This is the boundary between left-side elts and + right-side elts. */ + ++i; + } else { entry @@ -2412,8 +2511,52 @@ xdialog_show (f, keymaps, title, error) return Qnil; } + #else /* not USE_X_TOOLKIT */ +/* The frame of the last activated non-toolkit menu bar. + Used to generate menu help events. */ + +static struct frame *menu_help_frame; + + +/* Show help HELP_STRING, or clear help if HELP_STRING is null. + + PANE is the pane number, and ITEM is the menu item number in + the menu (currently not used). + + This cannot be done with generating a HELP_EVENT because + XMenuActivate contains a loop that doesn't let Emacs process + keyboard events. */ + +static void +menu_help_callback (help_string, pane, item) + char *help_string; + int pane, item; +{ + extern Lisp_Object Qmenu_item; + Lisp_Object *first_item; + Lisp_Object pane_name; + Lisp_Object menu_object; + + first_item = XVECTOR (menu_items)->contents; + if (EQ (first_item[0], Qt)) + pane_name = first_item[MENU_ITEMS_PANE_NAME]; + else if (EQ (first_item[0], Qquote)) + /* This shouldn't happen, see xmenu_show. */ + pane_name = empty_string; + else + pane_name = first_item[MENU_ITEMS_ITEM_NAME]; + + /* (menu-item MENU-NAME PANE-NUMBER) */ + menu_object = Fcons (Qmenu_item, + Fcons (pane_name, + Fcons (make_number (pane), Qnil))); + show_help_echo (help_string ? build_string (help_string) : Qnil, + Qnil, menu_object, make_number (item), 1); +} + + static Lisp_Object xmenu_show (f, x, y, for_click, keymaps, title, error) FRAME_PTR f; @@ -2545,13 +2688,17 @@ xmenu_show (f, x, y, for_click, keymaps, title, error) else { /* Create a new item within current pane. */ - Lisp_Object item_name, enable, descrip; + Lisp_Object item_name, enable, descrip, help; unsigned char *item_data; + char *help_string; item_name = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_NAME]; enable = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_ENABLE]; descrip = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_EQUIV_KEY]; + help = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_HELP]; + help_string = STRINGP (help) ? XSTRING (help)->data : NULL; + if (!NILP (descrip)) { int gap = maxwidth - STRING_BYTES (XSTRING (item_name)); @@ -2581,7 +2728,7 @@ xmenu_show (f, x, y, for_click, keymaps, title, error) if (XMenuAddSelection (FRAME_X_DISPLAY (f), menu, lpane, 0, item_data, - !NILP (enable)) + !NILP (enable), help_string) == XM_FAILURE) { XMenuDestroy (FRAME_X_DISPLAY (f), menu); @@ -2594,10 +2741,8 @@ xmenu_show (f, x, y, for_click, keymaps, title, error) /* All set and ready to fly. */ XMenuRecompute (FRAME_X_DISPLAY (f), menu); - dispwidth = DisplayWidth (FRAME_X_DISPLAY (f), - XScreenNumberOfScreen (FRAME_X_SCREEN (f))); - dispheight = DisplayHeight (FRAME_X_DISPLAY (f), - XScreenNumberOfScreen (FRAME_X_SCREEN (f))); + dispwidth = DisplayWidth (FRAME_X_DISPLAY (f), FRAME_X_SCREEN_NUMBER (f)); + dispheight = DisplayHeight (FRAME_X_DISPLAY (f), FRAME_X_SCREEN_NUMBER (f)); x = min (x, dispwidth); y = min (y, dispheight); x = max (x, 1); @@ -2620,9 +2765,13 @@ xmenu_show (f, x, y, for_click, keymaps, title, error) XMenuSetAEQ (menu, TRUE); XMenuSetFreeze (menu, TRUE); pane = selidx = 0; - + + /* Help display under X won't work because XMenuActivate contains + a loop that doesn't give Emacs a chance to process it. */ + menu_help_frame = f; status = XMenuActivate (FRAME_X_DISPLAY (f), menu, &pane, &selidx, - x, y, ButtonReleaseMask, &datap); + x, y, ButtonReleaseMask, &datap, + menu_help_callback); #ifdef HAVE_X_WINDOWS @@ -2707,8 +2856,8 @@ syms_of_xmenu () staticpro (&Qdebug_on_next_call); DEFVAR_LISP ("menu-updating-frame", &Vmenu_updating_frame, - "Frame for which we are updating a menu.\n\ -The enable predicate for a menu command should check this variable."); + doc: /* Frame for which we are updating a menu. +The enable predicate for a menu command should check this variable. */); Vmenu_updating_frame = Qnil; #ifdef USE_X_TOOLKIT