diff options
| author | Eli Zaretskii | 2013-10-05 18:42:17 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2013-10-05 18:42:17 +0300 |
| commit | 63dfbda7df0df5b054f8f95b79673672c267de54 (patch) | |
| tree | 47440f83d3d0d60714a5987cd30f715718e36a78 /src/menu.c | |
| parent | 6270e29ea3692882ce1ceee9be222b59b993c0e6 (diff) | |
| download | emacs-63dfbda7df0df5b054f8f95b79673672c267de54.tar.gz emacs-63dfbda7df0df5b054f8f95b79673672c267de54.zip | |
Fix menu drop by mouse click; new primitive menu-bar-menu-at-x-y.
Diffstat (limited to 'src/menu.c')
| -rw-r--r-- | src/menu.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/menu.c b/src/menu.c index 3f7aa0c33c3..690955ca0ad 100644 --- a/src/menu.c +++ b/src/menu.c | |||
| @@ -1035,6 +1035,59 @@ find_and_return_menu_selection (struct frame *f, bool keymaps, void *client_data | |||
| 1035 | } | 1035 | } |
| 1036 | #endif /* HAVE_NS */ | 1036 | #endif /* HAVE_NS */ |
| 1037 | 1037 | ||
| 1038 | DEFUN ("menu-bar-menu-at-x-y", Fmenu_bar_menu_at_x_y, Smenu_bar_menu_at_x_y, | ||
| 1039 | 2, 3, 0, | ||
| 1040 | doc: /* Return the menu-bar menu on FRAME at pixel coordinates X, Y. | ||
| 1041 | X and Y are frame-relative pixel coordinates, assumed to define | ||
| 1042 | a location within the menu bar. | ||
| 1043 | If FRAME is nil or omitted, it defaults to the selected frame. | ||
| 1044 | |||
| 1045 | Value is the symbol of the menu at X/Y, or nil if the specified | ||
| 1046 | coordinates are not within the FRAME's menu bar. The symbol can | ||
| 1047 | be used to look up the menu like this: | ||
| 1048 | |||
| 1049 | (lookup-key global-map [menu-bar SYMBOL]) | ||
| 1050 | |||
| 1051 | This function can return non-nil only on a text-terminal frame | ||
| 1052 | or on an X frame that doesn't use any GUI toolkit. Otherwise, | ||
| 1053 | Emacs does not manage the menu bar and cannot convert coordinates | ||
| 1054 | into menu items. */) | ||
| 1055 | (Lisp_Object x, Lisp_Object y, Lisp_Object frame) | ||
| 1056 | { | ||
| 1057 | int row, col; | ||
| 1058 | struct frame *f = decode_any_frame (frame); | ||
| 1059 | |||
| 1060 | if (!FRAME_LIVE_P (f)) | ||
| 1061 | return Qnil; | ||
| 1062 | |||
| 1063 | pixel_to_glyph_coords (f, XINT (x), XINT (y), &col, &row, NULL, 1); | ||
| 1064 | if (0 <= row && row < FRAME_MENU_BAR_LINES (f)) | ||
| 1065 | { | ||
| 1066 | Lisp_Object items, item; | ||
| 1067 | int i; | ||
| 1068 | |||
| 1069 | /* Find the menu bar item under `col'. */ | ||
| 1070 | item = Qnil; | ||
| 1071 | items = FRAME_MENU_BAR_ITEMS (f); | ||
| 1072 | for (i = 0; i < ASIZE (items); i += 4) | ||
| 1073 | { | ||
| 1074 | Lisp_Object pos, str; | ||
| 1075 | |||
| 1076 | str = AREF (items, i + 1); | ||
| 1077 | pos = AREF (items, i + 3); | ||
| 1078 | if (NILP (str)) | ||
| 1079 | return item; | ||
| 1080 | if (XINT (pos) <= col && col < XINT (pos) + SCHARS (str)) | ||
| 1081 | { | ||
| 1082 | item = AREF (items, i); | ||
| 1083 | return item; | ||
| 1084 | } | ||
| 1085 | } | ||
| 1086 | } | ||
| 1087 | return Qnil; | ||
| 1088 | } | ||
| 1089 | |||
| 1090 | |||
| 1038 | DEFUN ("x-popup-menu", Fx_popup_menu, Sx_popup_menu, 2, 2, 0, | 1091 | DEFUN ("x-popup-menu", Fx_popup_menu, Sx_popup_menu, 2, 2, 0, |
| 1039 | doc: /* Pop up a deck-of-cards menu and return user's selection. | 1092 | doc: /* Pop up a deck-of-cards menu and return user's selection. |
| 1040 | POSITION is a position specification. This is either a mouse button event | 1093 | POSITION is a position specification. This is either a mouse button event |
| @@ -1527,4 +1580,5 @@ syms_of_menu (void) | |||
| 1527 | #ifdef HAVE_MENUS | 1580 | #ifdef HAVE_MENUS |
| 1528 | defsubr (&Sx_popup_dialog); | 1581 | defsubr (&Sx_popup_dialog); |
| 1529 | #endif | 1582 | #endif |
| 1583 | defsubr (&Smenu_bar_menu_at_x_y); | ||
| 1530 | } | 1584 | } |