diff options
Diffstat (limited to 'src/menu.c')
-rw-r--r-- | src/menu.c | 176 |
1 files changed, 88 insertions, 88 deletions
diff --git a/src/menu.c b/src/menu.c index 2ec82a26cd8..e82c8570595 100644 --- a/src/menu.c +++ b/src/menu.c @@ -60,9 +60,9 @@ have_boxes (void) Lisp_Object menu_items; -/* If non-nil, means that the global vars defined here are already in use. +/* Whether the global vars defined here are already in use. Used to detect cases where we try to re-enter this non-reentrant code. */ -Lisp_Object menu_items_inuse; +bool menu_items_inuse; /* Number of slots currently allocated in menu_items. */ int menu_items_allocated; @@ -80,16 +80,16 @@ static int menu_items_submenu_depth; void init_menu_items (void) { - if (!NILP (menu_items_inuse)) + if (menu_items_inuse) error ("Trying to use a menu from within a menu-entry"); if (NILP (menu_items)) { menu_items_allocated = 60; - menu_items = Fmake_vector (make_number (menu_items_allocated), Qnil); + menu_items = make_nil_vector (menu_items_allocated); } - menu_items_inuse = Qt; + menu_items_inuse = true; menu_items_used = 0; menu_items_n_panes = 0; menu_items_submenu_depth = 0; @@ -105,7 +105,7 @@ finish_menu_items (void) void unuse_menu_items (void) { - menu_items_inuse = Qnil; + menu_items_inuse = false; } /* Call when finished using the data for the current menu @@ -121,7 +121,7 @@ discard_menu_items (void) menu_items = Qnil; menu_items_allocated = 0; } - eassert (NILP (menu_items_inuse)); + eassert (!menu_items_inuse); } /* This undoes save_menu_items, and it is called by the specpdl unwind @@ -131,14 +131,14 @@ static void restore_menu_items (Lisp_Object saved) { menu_items = XCAR (saved); - menu_items_inuse = (! NILP (menu_items) ? Qt : Qnil); + menu_items_inuse = ! NILP (menu_items); menu_items_allocated = (VECTORP (menu_items) ? ASIZE (menu_items) : 0); saved = XCDR (saved); - menu_items_used = XINT (XCAR (saved)); + menu_items_used = XFIXNUM (XCAR (saved)); saved = XCDR (saved); - menu_items_n_panes = XINT (XCAR (saved)); + menu_items_n_panes = XFIXNUM (XCAR (saved)); saved = XCDR (saved); - menu_items_submenu_depth = XINT (XCAR (saved)); + menu_items_submenu_depth = XFIXNUM (XCAR (saved)); } /* Push the whole state of menu_items processing onto the specpdl. @@ -147,12 +147,12 @@ restore_menu_items (Lisp_Object saved) void save_menu_items (void) { - Lisp_Object saved = list4 (!NILP (menu_items_inuse) ? menu_items : Qnil, - make_number (menu_items_used), - make_number (menu_items_n_panes), - make_number (menu_items_submenu_depth)); + Lisp_Object saved = list4 (menu_items_inuse ? menu_items : Qnil, + make_fixnum (menu_items_used), + make_fixnum (menu_items_n_panes), + make_fixnum (menu_items_submenu_depth)); record_unwind_protect (restore_menu_items, saved); - menu_items_inuse = Qnil; + menu_items_inuse = false; menu_items = Qnil; } @@ -170,8 +170,7 @@ ensure_menu_items (int items) } } -#if (defined USE_X_TOOLKIT || defined USE_GTK || defined HAVE_NS \ - || defined HAVE_NTGUI) +#ifdef HAVE_EXT_MENU_BAR /* Begin a submenu. */ @@ -195,7 +194,7 @@ push_submenu_end (void) menu_items_submenu_depth--; } -#endif /* USE_X_TOOLKIT || USE_GTK || HAVE_NS || defined HAVE_NTGUI */ +#endif /* HAVE_EXT_MENU_BAR */ /* Indicate boundary between left and right. */ @@ -524,19 +523,15 @@ bool parse_single_submenu (Lisp_Object item_key, Lisp_Object item_name, Lisp_Object maps) { - Lisp_Object length; - EMACS_INT len; Lisp_Object *mapvec; - ptrdiff_t i; bool top_level_items = 0; USE_SAFE_ALLOCA; - length = Flength (maps); - len = XINT (length); + ptrdiff_t len = list_length (maps); /* Convert the list MAPS into a vector MAPVEC. */ SAFE_ALLOCA_LISP (mapvec, len); - for (i = 0; i < len; i++) + for (ptrdiff_t i = 0; i < len; i++) { mapvec[i] = Fcar (maps); maps = Fcdr (maps); @@ -544,7 +539,7 @@ parse_single_submenu (Lisp_Object item_key, Lisp_Object item_name, /* Loop over the given keymaps, making a pane for each map. But don't make a pane that is empty--ignore that map instead. */ - for (i = 0; i < len; i++) + for (ptrdiff_t i = 0; i < len; i++) { if (!KEYMAPP (mapvec[i])) { @@ -647,7 +642,7 @@ digest_single_submenu (int start, int end, bool top_level_items) i = start; while (i < end) { - if (EQ (AREF (menu_items, i), Qnil)) + if (NILP (AREF (menu_items, i))) { submenu_stack[submenu_depth++] = save_wv; save_wv = prev_wv; @@ -692,7 +687,7 @@ digest_single_submenu (int start, int end, bool top_level_items) ASET (menu_items, i + MENU_ITEMS_PANE_NAME, pane_name); } -#elif defined (USE_LUCID) && defined (HAVE_XFT) +#elif defined (USE_LUCID) && (defined USE_CAIRO || defined HAVE_XFT) if (STRINGP (pane_name)) { pane_name = ENCODE_UTF_8 (pane_name); @@ -900,7 +895,7 @@ find_and_call_menu_selection (struct frame *f, int menu_bar_items_used, while (i < menu_bar_items_used) { - if (EQ (AREF (vector, i), Qnil)) + if (NILP (AREF (vector, i))) { subprefix_stack[submenu_depth++] = prefix; prefix = entry; @@ -985,7 +980,7 @@ find_and_return_menu_selection (struct frame *f, bool keymaps, void *client_data while (i < menu_items_used) { - if (EQ (AREF (menu_items, i), Qnil)) + if (NILP (AREF (menu_items, i))) { subprefix_stack[submenu_depth++] = prefix; prefix = entry; @@ -1079,7 +1074,7 @@ into menu items. */) if (!FRAME_LIVE_P (f)) return Qnil; - pixel_to_glyph_coords (f, XINT (x), XINT (y), &col, &row, NULL, 1); + pixel_to_glyph_coords (f, XFIXNUM (x), XFIXNUM (y), &col, &row, NULL, 1); if (0 <= row && row < FRAME_MENU_BAR_LINES (f)) { Lisp_Object items, item; @@ -1099,10 +1094,10 @@ into menu items. */) pos = AREF (items, i + 3); if (NILP (str)) return item; - if (XINT (pos) <= col + if (XFIXNUM (pos) <= col /* We use <= so the blank between 2 items on a TTY is considered part of the previous item. */ - && col <= XINT (pos) + menu_item_width (SDATA (str))) + && col <= XFIXNUM (pos) + menu_item_width (SDATA (str))) { item = AREF (items, i); return item; @@ -1112,51 +1107,8 @@ into menu items. */) return Qnil; } - -DEFUN ("x-popup-menu", Fx_popup_menu, Sx_popup_menu, 2, 2, 0, - 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. (WINDOW may be a window or a frame object.) -This controls the position of 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 the -list of events corresponding to the user's choice. Note that -`x-popup-menu' does not actually execute the command bound to that -sequence 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. - -If the user gets rid of the menu without making a valid choice, for -instance by clicking the mouse away from a valid choice or by typing -keyboard input, then this normally results in a quit and -`x-popup-menu' does not return. But if POSITION is a mouse button -event (indicating that the user invoked the menu with the mouse) then -no quit occurs and `x-popup-menu' returns nil. */) - (Lisp_Object position, Lisp_Object menu) +Lisp_Object +x_popup_menu_1 (Lisp_Object position, Lisp_Object menu) { Lisp_Object keymap, tem, tem2; int xpos = 0, ypos = 0; @@ -1195,7 +1147,7 @@ no quit occurs and `x-popup-menu' returns nil. */) else { menuflags |= MENU_FOR_CLICK; - tem = Fcar (Fcdr (position)); /* EVENT_START (position) */ + tem = Fcar (XCDR (position)); /* EVENT_START (position) */ window = Fcar (tem); /* POSN_WINDOW (tem) */ tem2 = Fcar (Fcdr (tem)); /* POSN_POSN (tem) */ /* The MENU_KBD_NAVIGATION field is set when the menu @@ -1211,7 +1163,7 @@ no quit occurs and `x-popup-menu' returns nil. */) event. */ if (!EQ (POSN_POSN (last_nonmenu_event), POSN_POSN (position)) - && CONSP (tem2) && EQ (Fcar (tem2), Qmenu_bar)) + && CONSP (tem2) && EQ (XCAR (tem2), Qmenu_bar)) menuflags |= MENU_KBD_NAVIGATION; tem = Fcar (Fcdr (Fcdr (tem))); /* POSN_WINDOW_POSN (tem) */ x = Fcar (tem); @@ -1245,9 +1197,9 @@ no quit occurs and `x-popup-menu' returns nil. */) int cur_x, cur_y; x_relative_mouse_position (new_f, &cur_x, &cur_y); - /* cur_x/y may be negative, so use make_number. */ - x = make_number (cur_x); - y = make_number (cur_y); + /* cur_x/y may be negative, so use make_fixnum. */ + x = make_fixnum (cur_x); + y = make_fixnum (cur_y); } } else @@ -1311,8 +1263,8 @@ no quit occurs and `x-popup-menu' returns nil. */) ? (EMACS_INT) INT_MIN - ypos : MOST_NEGATIVE_FIXNUM), INT_MAX - ypos); - xpos += XINT (x); - ypos += XINT (y); + xpos += XFIXNUM (x); + ypos += XFIXNUM (y); XSETFRAME (Vmenu_updating_frame, f); } @@ -1352,7 +1304,7 @@ no quit occurs and `x-popup-menu' returns nil. */) else if (CONSP (menu) && KEYMAPP (XCAR (menu))) { /* We were given a list of keymaps. */ - EMACS_INT nmaps = XFASTINT (Flength (menu)); + ptrdiff_t nmaps = list_length (menu); Lisp_Object *maps; ptrdiff_t i; USE_SAFE_ALLOCA; @@ -1443,6 +1395,55 @@ no quit occurs and `x-popup-menu' returns nil. */) return selection; } +DEFUN ("x-popup-menu", Fx_popup_menu, Sx_popup_menu, 2, 2, 0, + 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. (WINDOW may be a window or a frame object.) +This controls the position of 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 the +list of events corresponding to the user's choice. Note that +`x-popup-menu' does not actually execute the command bound to that +sequence 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. + +If the user gets rid of the menu without making a valid choice, for +instance by clicking the mouse away from a valid choice or by typing +keyboard input, then this normally results in a quit and +`x-popup-menu' does not return. But if POSITION is a mouse button +event (indicating that the user invoked the menu with the mouse) then +no quit occurs and `x-popup-menu' returns nil. */) + (Lisp_Object position, Lisp_Object menu) +{ + init_raw_keybuf_count (); + return x_popup_menu_1 (position, menu); +} + /* If F's terminal is not capable of displaying a popup dialog, emulate it with a menu. */ @@ -1574,9 +1575,8 @@ for instance using the window manager, then this produces a quit and void syms_of_menu (void) { - staticpro (&menu_items); menu_items = Qnil; - menu_items_inuse = Qnil; + staticpro (&menu_items); defsubr (&Sx_popup_menu); defsubr (&Sx_popup_dialog); |