1 /* X Communication module for terminals which understand the X protocol.
2 Copyright (C) 1986, 1988, 1993, 1994 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* X pop-up deck-of-cards menu facility for gnuemacs.
23 * Written by Jon Arnold and Roman Budzianowski
24 * Mods and rewrite by Robert Krawitz
28 /* Modified by Fred Pierresteguy on December 93
29 to make the popup menus and menubar use the Xt. */
31 /* Rewritten for clarity and GC protection by rms in Feb 94. */
33 /* On 4.3 this loses if it comes after xterm.h. */
39 #include "termhooks.h"
43 #include "blockinput.h"
52 /* This may include sys/types.h, and that somehow loses
53 if this is not done before the other system files. */
57 /* Load sys/types.h if not already loaded.
58 In some systems loading it twice is suicidal. */
60 #include <sys/types.h>
63 #include "dispextern.h"
68 #include <X11/IntrinsicP.h>
69 #include <X11/CoreP.h>
70 #include <X11/StringDefs.h>
71 #include <X11/Shell.h>
73 #include <X11/Xaw/Paned.h>
74 #endif /* USE_LUCID */
75 #include "../lwlib/lwlib.h"
76 #else /* not USE_X_TOOLKIT */
77 #include "../oldXMenu/XMenu.h"
78 #endif /* not USE_X_TOOLKIT */
79 #endif /* HAVE_X_WINDOWS */
81 #define min(x,y) (((x) < (y)) ? (x) : (y))
82 #define max(x,y) (((x) > (y)) ? (x) : (y))
89 Lisp_Object Qdebug_on_next_call
;
91 extern Lisp_Object Qmenu_enable
;
92 extern Lisp_Object Qmenu_bar
;
93 extern Lisp_Object Qmouse_click
, Qevent_kind
;
95 extern Lisp_Object Vdefine_key_rebound_commands
;
97 extern Lisp_Object Voverriding_local_map
;
98 extern Lisp_Object Voverriding_local_map_menu_flag
;
100 extern Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
102 extern Lisp_Object Qmenu_bar_update_hook
;
105 extern void set_frame_menubar ();
106 extern void process_expose_from_menu ();
107 extern XtAppContext Xt_app_con
;
109 static Lisp_Object
xdialog_show ();
110 void popup_get_selection ();
113 static Lisp_Object
xmenu_show ();
114 static void keymap_panes ();
115 static void single_keymap_panes ();
116 static void list_of_panes ();
117 static void list_of_items ();
119 /* This holds a Lisp vector that holds the results of decoding
120 the keymaps or alist-of-alists that specify a menu.
122 It describes the panes and items within the panes.
124 Each pane is described by 3 elements in the vector:
125 t, the pane name, the pane's prefix key.
126 Then follow the pane's items, with 5 elements per item:
127 the item string, the enable flag, the item's value,
128 the definition, and the equivalent keyboard key's description string.
130 In some cases, multiple levels of menus may be described.
131 A single vector slot containing nil indicates the start of a submenu.
132 A single vector slot containing lambda indicates the end of a submenu.
133 The submenu follows a menu item which is the way to reach the submenu.
135 A single vector slot containing quote indicates that the
136 following items should appear on the right of a dialog box.
138 Using a Lisp vector to hold this information while we decode it
139 takes care of protecting all the data from GC. */
141 #define MENU_ITEMS_PANE_NAME 1
142 #define MENU_ITEMS_PANE_PREFIX 2
143 #define MENU_ITEMS_PANE_LENGTH 3
145 #define MENU_ITEMS_ITEM_NAME 0
146 #define MENU_ITEMS_ITEM_ENABLE 1
147 #define MENU_ITEMS_ITEM_VALUE 2
148 #define MENU_ITEMS_ITEM_EQUIV_KEY 3
149 #define MENU_ITEMS_ITEM_DEFINITION 4
150 #define MENU_ITEMS_ITEM_LENGTH 5
152 static Lisp_Object menu_items
;
154 /* Number of slots currently allocated in menu_items. */
155 static int menu_items_allocated
;
157 /* This is the index in menu_items of the first empty slot. */
158 static int menu_items_used
;
160 /* The number of panes currently recorded in menu_items,
161 excluding those within submenus. */
162 static int menu_items_n_panes
;
164 /* Current depth within submenus. */
165 static int menu_items_submenu_depth
;
167 /* Flag which when set indicates a dialog or menu has been posted by
168 Xt on behalf of one of the widget sets. */
169 static int popup_activated_flag
;
171 static int next_menubar_widget_id
;
175 /* Return the frame whose ->output_data.x->id equals ID, or 0 if none. */
177 static struct frame
*
178 menubar_id_to_frame (id
)
181 Lisp_Object tail
, frame
;
184 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCONS (tail
)->cdr
)
186 frame
= XCONS (tail
)->car
;
187 if (!GC_FRAMEP (frame
))
190 if (f
->output_data
.nothing
== 1)
192 if (f
->output_data
.x
->id
== id
)
200 /* Initialize the menu_items structure if we haven't already done so.
201 Also mark it as currently empty. */
206 if (NILP (menu_items
))
208 menu_items_allocated
= 60;
209 menu_items
= Fmake_vector (make_number (menu_items_allocated
), Qnil
);
213 menu_items_n_panes
= 0;
214 menu_items_submenu_depth
= 0;
217 /* Call at the end of generating the data in menu_items.
218 This fills in the number of items in the last pane. */
225 /* Call when finished using the data for the current menu
229 discard_menu_items ()
231 /* Free the structure if it is especially large.
232 Otherwise, hold on to it, to save time. */
233 if (menu_items_allocated
> 200)
236 menu_items_allocated
= 0;
240 /* Make the menu_items vector twice as large. */
246 int old_size
= menu_items_allocated
;
249 menu_items_allocated
*= 2;
250 menu_items
= Fmake_vector (make_number (menu_items_allocated
), Qnil
);
251 bcopy (XVECTOR (old
)->contents
, XVECTOR (menu_items
)->contents
,
252 old_size
* sizeof (Lisp_Object
));
255 /* Begin a submenu. */
258 push_submenu_start ()
260 if (menu_items_used
+ 1 > menu_items_allocated
)
263 XVECTOR (menu_items
)->contents
[menu_items_used
++] = Qnil
;
264 menu_items_submenu_depth
++;
272 if (menu_items_used
+ 1 > menu_items_allocated
)
275 XVECTOR (menu_items
)->contents
[menu_items_used
++] = Qlambda
;
276 menu_items_submenu_depth
--;
279 /* Indicate boundary between left and right. */
282 push_left_right_boundary ()
284 if (menu_items_used
+ 1 > menu_items_allocated
)
287 XVECTOR (menu_items
)->contents
[menu_items_used
++] = Qquote
;
290 /* Start a new menu pane in menu_items..
291 NAME is the pane name. PREFIX_VEC is a prefix key for this pane. */
294 push_menu_pane (name
, prefix_vec
)
295 Lisp_Object name
, prefix_vec
;
297 if (menu_items_used
+ MENU_ITEMS_PANE_LENGTH
> menu_items_allocated
)
300 if (menu_items_submenu_depth
== 0)
301 menu_items_n_panes
++;
302 XVECTOR (menu_items
)->contents
[menu_items_used
++] = Qt
;
303 XVECTOR (menu_items
)->contents
[menu_items_used
++] = name
;
304 XVECTOR (menu_items
)->contents
[menu_items_used
++] = prefix_vec
;
307 /* Push one menu item into the current pane.
308 NAME is the string to display. ENABLE if non-nil means
309 this item can be selected. KEY is the key generated by
310 choosing this item, or nil if this item doesn't really have a definition.
311 DEF is the definition of this item.
312 EQUIV is the textual description of the keyboard equivalent for
313 this item (or nil if none). */
316 push_menu_item (name
, enable
, key
, def
, equiv
)
317 Lisp_Object name
, enable
, key
, def
, equiv
;
319 if (menu_items_used
+ MENU_ITEMS_ITEM_LENGTH
> menu_items_allocated
)
322 XVECTOR (menu_items
)->contents
[menu_items_used
++] = name
;
323 XVECTOR (menu_items
)->contents
[menu_items_used
++] = enable
;
324 XVECTOR (menu_items
)->contents
[menu_items_used
++] = key
;
325 XVECTOR (menu_items
)->contents
[menu_items_used
++] = equiv
;
326 XVECTOR (menu_items
)->contents
[menu_items_used
++] = def
;
329 /* Figure out the current keyboard equivalent of a menu item ITEM1.
330 The item string for menu display should be ITEM_STRING.
331 Store the equivalent keyboard key sequence's
332 textual description into *DESCRIP_PTR.
333 Also cache them in the item itself.
334 Return the real definition to execute. */
337 menu_item_equiv_key (item_string
, item1
, descrip_ptr
)
338 Lisp_Object item_string
;
340 Lisp_Object
*descrip_ptr
;
342 /* This is the real definition--the function to run. */
344 /* This is the sublist that records cached equiv key data
345 so we can save time. */
346 Lisp_Object cachelist
;
347 /* These are the saved equivalent keyboard key sequence
348 and its key-description. */
349 Lisp_Object savedkey
, descrip
;
352 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
354 /* If a help string follows the item string, skip it. */
355 if (CONSP (XCONS (item1
)->cdr
)
356 && STRINGP (XCONS (XCONS (item1
)->cdr
)->car
))
357 item1
= XCONS (item1
)->cdr
;
361 /* Get out the saved equivalent-keyboard-key info. */
362 cachelist
= savedkey
= descrip
= Qnil
;
363 if (CONSP (def
) && CONSP (XCONS (def
)->car
)
364 && (NILP (XCONS (XCONS (def
)->car
)->car
)
365 || VECTORP (XCONS (XCONS (def
)->car
)->car
)))
367 cachelist
= XCONS (def
)->car
;
368 def
= XCONS (def
)->cdr
;
369 savedkey
= XCONS (cachelist
)->car
;
370 descrip
= XCONS (cachelist
)->cdr
;
373 GCPRO4 (def
, def1
, savedkey
, descrip
);
375 /* Is it still valid? */
377 if (!NILP (savedkey
))
378 def1
= Fkey_binding (savedkey
, Qnil
);
379 /* If not, update it. */
381 /* If the command is an alias for another
382 (such as easymenu.el and lmenu.el set it up),
383 check if the original command matches the cached command. */
384 && !(SYMBOLP (def
) && SYMBOLP (XSYMBOL (def
)->function
)
385 && EQ (def1
, XSYMBOL (def
)->function
))
386 /* If something had no key binding before, don't recheck it
387 because that is too slow--except if we have a list of rebound
388 commands in Vdefine_key_rebound_commands, do recheck any command
389 that appears in that list. */
390 && (NILP (cachelist
) || !NILP (savedkey
)
391 || (! EQ (Qt
, Vdefine_key_rebound_commands
)
392 && !NILP (Fmemq (def
, Vdefine_key_rebound_commands
)))))
396 /* If the command is an alias for another
397 (such as easymenu.el and lmenu.el set it up),
398 see if the original command name has equivalent keys. */
399 if (SYMBOLP (def
) && SYMBOLP (XSYMBOL (def
)->function
))
400 savedkey
= Fwhere_is_internal (XSYMBOL (def
)->function
,
403 /* Otherwise look up the specified command itself.
404 We don't try both, because that makes easymenu menus slow. */
405 savedkey
= Fwhere_is_internal (def
, Qnil
, Qt
, Qnil
);
407 if (!NILP (savedkey
))
409 descrip
= Fkey_description (savedkey
);
410 descrip
= concat2 (make_string (" (", 3), descrip
);
411 descrip
= concat2 (descrip
, make_string (")", 1));
415 /* Cache the data we just got in a sublist of the menu binding. */
416 if (NILP (cachelist
))
418 CHECK_IMPURE (item1
);
419 XCONS (item1
)->cdr
= Fcons (Fcons (savedkey
, descrip
), def
);
423 XCONS (cachelist
)->car
= savedkey
;
424 XCONS (cachelist
)->cdr
= descrip
;
428 *descrip_ptr
= descrip
;
432 /* This is used as the handler when calling internal_condition_case_1. */
435 menu_item_enabled_p_1 (arg
)
438 /* If we got a quit from within the menu computation,
439 quit all the way out of it. This takes care of C-] in the debugger. */
440 if (CONSP (arg
) && EQ (XCONS (arg
)->car
, Qquit
))
441 Fsignal (Qquit
, Qnil
);
446 /* Return non-nil if the command DEF is enabled when used as a menu item.
447 This is based on looking for a menu-enable property.
448 If NOTREAL is set, don't bother really computing this. */
451 menu_item_enabled_p (def
, notreal
)
455 Lisp_Object enabled
, tem
;
462 /* No property, or nil, means enable.
463 Otherwise, enable if value is not nil. */
464 tem
= Fget (def
, Qmenu_enable
);
466 /* (condition-case nil (eval tem)
468 enabled
= internal_condition_case_1 (Feval
, tem
, Qerror
,
469 menu_item_enabled_p_1
);
474 /* Look through KEYMAPS, a vector of keymaps that is NMAPS long,
475 and generate menu panes for them in menu_items.
476 If NOTREAL is nonzero,
477 don't bother really computing whether an item is enabled. */
480 keymap_panes (keymaps
, nmaps
, notreal
)
481 Lisp_Object
*keymaps
;
489 /* Loop over the given keymaps, making a pane for each map.
490 But don't make a pane that is empty--ignore that map instead.
491 P is the number of panes we have made so far. */
492 for (mapno
= 0; mapno
< nmaps
; mapno
++)
493 single_keymap_panes (keymaps
[mapno
], Qnil
, Qnil
, notreal
);
495 finish_menu_items ();
498 /* This is a recursive subroutine of keymap_panes.
499 It handles one keymap, KEYMAP.
500 The other arguments are passed along
501 or point to local variables of the previous function.
502 If NOTREAL is nonzero,
503 don't bother really computing whether an item is enabled. */
506 single_keymap_panes (keymap
, pane_name
, prefix
, notreal
)
508 Lisp_Object pane_name
;
512 Lisp_Object pending_maps
;
513 Lisp_Object tail
, item
, item1
, item_string
, table
;
514 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
518 push_menu_pane (pane_name
, prefix
);
520 for (tail
= keymap
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
522 /* Look at each key binding, and if it has a menu string,
523 make a menu item from it. */
524 item
= XCONS (tail
)->car
;
527 item1
= XCONS (item
)->cdr
;
530 item_string
= XCONS (item1
)->car
;
531 if (STRINGP (item_string
))
533 /* This is the real definition--the function to run. */
535 /* These are the saved equivalent keyboard key sequence
536 and its key-description. */
538 Lisp_Object tem
, enabled
;
540 /* GCPRO because ...enabled_p will call eval
541 and ..._equiv_key may autoload something.
542 Protecting KEYMAP preserves everything we use;
543 aside from that, must protect whatever might be
544 a string. Since there's no GCPRO5, we refetch
545 item_string instead of protecting it. */
546 descrip
= def
= Qnil
;
547 GCPRO4 (keymap
, pending_maps
, def
, descrip
);
549 def
= menu_item_equiv_key (item_string
, item1
, &descrip
);
550 enabled
= menu_item_enabled_p (def
, notreal
);
554 item_string
= XCONS (item1
)->car
;
556 tem
= Fkeymapp (def
);
557 if (XSTRING (item_string
)->data
[0] == '@' && !NILP (tem
))
558 pending_maps
= Fcons (Fcons (def
, Fcons (item_string
, XCONS (item
)->car
)),
563 GCPRO4 (keymap
, pending_maps
, descrip
, item_string
);
564 submap
= get_keymap_1 (def
, 0, 1);
566 #ifndef USE_X_TOOLKIT
567 /* Indicate visually that this is a submenu. */
569 item_string
= concat2 (item_string
,
570 build_string (" >"));
572 /* If definition is nil, pass nil as the key. */
573 push_menu_item (item_string
, enabled
,
574 XCONS (item
)->car
, def
,
577 /* Display a submenu using the toolkit. */
580 push_submenu_start ();
581 single_keymap_panes (submap
, Qnil
,
582 XCONS (item
)->car
, notreal
);
590 else if (VECTORP (item
))
592 /* Loop over the char values represented in the vector. */
593 int len
= XVECTOR (item
)->size
;
595 for (c
= 0; c
< len
; c
++)
597 Lisp_Object character
;
598 XSETFASTINT (character
, c
);
599 item1
= XVECTOR (item
)->contents
[c
];
602 item_string
= XCONS (item1
)->car
;
603 if (STRINGP (item_string
))
607 /* These are the saved equivalent keyboard key sequence
608 and its key-description. */
610 Lisp_Object tem
, enabled
;
612 /* GCPRO because ...enabled_p will call eval
613 and ..._equiv_key may autoload something.
614 Protecting KEYMAP preserves everything we use;
615 aside from that, must protect whatever might be
616 a string. Since there's no GCPRO5, we refetch
617 item_string instead of protecting it. */
618 GCPRO4 (keymap
, pending_maps
, def
, descrip
);
619 descrip
= def
= Qnil
;
621 def
= menu_item_equiv_key (item_string
, item1
, &descrip
);
622 enabled
= menu_item_enabled_p (def
, notreal
);
626 item_string
= XCONS (item1
)->car
;
628 tem
= Fkeymapp (def
);
629 if (XSTRING (item_string
)->data
[0] == '@' && !NILP (tem
))
630 pending_maps
= Fcons (Fcons (def
, Fcons (item_string
, character
)),
635 GCPRO4 (keymap
, pending_maps
, descrip
, item_string
);
636 submap
= get_keymap_1 (def
, 0, 1);
638 #ifndef USE_X_TOOLKIT
640 item_string
= concat2 (item_string
,
641 build_string (" >"));
643 /* If definition is nil, pass nil as the key. */
644 push_menu_item (item_string
, enabled
, character
,
649 push_submenu_start ();
650 single_keymap_panes (submap
, Qnil
,
662 /* Process now any submenus which want to be panes at this level. */
663 while (!NILP (pending_maps
))
665 Lisp_Object elt
, eltcdr
, string
;
666 elt
= Fcar (pending_maps
);
667 eltcdr
= XCONS (elt
)->cdr
;
668 string
= XCONS (eltcdr
)->car
;
669 /* We no longer discard the @ from the beginning of the string here.
670 Instead, we do this in xmenu_show. */
671 single_keymap_panes (Fcar (elt
), string
,
672 XCONS (eltcdr
)->cdr
, notreal
);
673 pending_maps
= Fcdr (pending_maps
);
677 /* Push all the panes and items of a menu described by the
678 alist-of-alists MENU.
679 This handles old-fashioned calls to x-popup-menu. */
689 for (tail
= menu
; !NILP (tail
); tail
= Fcdr (tail
))
691 Lisp_Object elt
, pane_name
, pane_data
;
693 pane_name
= Fcar (elt
);
694 CHECK_STRING (pane_name
, 0);
695 push_menu_pane (pane_name
, Qnil
);
696 pane_data
= Fcdr (elt
);
697 CHECK_CONS (pane_data
, 0);
698 list_of_items (pane_data
);
701 finish_menu_items ();
704 /* Push the items in a single pane defined by the alist PANE. */
710 Lisp_Object tail
, item
, item1
;
712 for (tail
= pane
; !NILP (tail
); tail
= Fcdr (tail
))
716 push_menu_item (item
, Qnil
, Qnil
, Qt
, Qnil
);
717 else if (NILP (item
))
718 push_left_right_boundary ();
721 CHECK_CONS (item
, 0);
723 CHECK_STRING (item1
, 1);
724 push_menu_item (item1
, Qt
, Fcdr (item
), Qt
, Qnil
);
729 DEFUN ("x-popup-menu", Fx_popup_menu
, Sx_popup_menu
, 2, 2, 0,
730 "Pop up a deck-of-cards menu and return user's selection.\n\
731 POSITION is a position specification. This is either a mouse button event\n\
732 or a list ((XOFFSET YOFFSET) WINDOW)\n\
733 where XOFFSET and YOFFSET are positions in pixels from the top left\n\
734 corner of WINDOW's frame. (WINDOW may be a frame object instead of a window.)\n\
735 This controls the position of the center of the first line\n\
736 in the first pane of the menu, not the top left of the menu as a whole.\n\
737 If POSITION is t, it means to use the current mouse position.\n\
739 MENU is a specifier for a menu. For the simplest case, MENU is a keymap.\n\
740 The menu items come from key bindings that have a menu string as well as\n\
741 a definition; actually, the \"definition\" in such a key binding looks like\n\
742 \(STRING . REAL-DEFINITION). To give the menu a title, put a string into\n\
743 the keymap as a top-level element.\n\n\
744 You can also use a list of keymaps as MENU.\n\
745 Then each keymap makes a separate pane.\n\
746 When MENU is a keymap or a list of keymaps, the return value\n\
747 is a list of events.\n\n\
748 Alternatively, you can specify a menu of multiple panes\n\
749 with a list of the form (TITLE PANE1 PANE2...),\n\
750 where each pane is a list of form (TITLE ITEM1 ITEM2...).\n\
751 Each ITEM is normally a cons cell (STRING . VALUE);\n\
752 but a string can appear as an item--that makes a nonselectable line\n\
754 With this form of menu, the return value is VALUE from the chosen item.\n\
756 If POSITION is nil, don't display the menu at all, just precalculate the\n\
757 cached information about equivalent key sequences.")
759 Lisp_Object position
, menu
;
761 int number_of_panes
, panes
;
762 Lisp_Object keymap
, tem
;
766 Lisp_Object selection
;
769 Lisp_Object x
, y
, window
;
775 if (! NILP (position
))
779 /* Decode the first argument: find the window and the coordinates. */
780 if (EQ (position
, Qt
)
781 || (CONSP (position
) && EQ (XCONS (position
)->car
, Qmenu_bar
)))
783 /* Use the mouse's current position. */
784 FRAME_PTR new_f
= selected_frame
;
785 Lisp_Object bar_window
;
789 if (mouse_position_hook
)
790 (*mouse_position_hook
) (&new_f
, 1, &bar_window
,
791 &part
, &x
, &y
, &time
);
793 XSETFRAME (window
, new_f
);
796 window
= selected_window
;
803 tem
= Fcar (position
);
806 window
= Fcar (Fcdr (position
));
808 y
= Fcar (Fcdr (tem
));
813 tem
= Fcar (Fcdr (position
)); /* EVENT_START (position) */
814 window
= Fcar (tem
); /* POSN_WINDOW (tem) */
815 tem
= Fcar (Fcdr (Fcdr (tem
))); /* POSN_WINDOW_POSN (tem) */
824 /* Decode where to put the menu. */
832 else if (WINDOWP (window
))
834 CHECK_LIVE_WINDOW (window
, 0);
835 f
= XFRAME (WINDOW_FRAME (XWINDOW (window
)));
837 xpos
= (FONT_WIDTH (f
->output_data
.x
->font
) * XWINDOW (window
)->left
);
838 ypos
= (f
->output_data
.x
->line_height
* XWINDOW (window
)->top
);
841 /* ??? Not really clean; should be CHECK_WINDOW_OR_FRAME,
842 but I don't want to make one now. */
843 CHECK_WINDOW (window
, 0);
848 #endif /* HAVE_MENUS */
853 /* Decode the menu items from what was specified. */
855 keymap
= Fkeymapp (menu
);
858 tem
= Fkeymapp (Fcar (menu
));
861 /* We were given a keymap. Extract menu info from the keymap. */
863 keymap
= get_keymap (menu
);
865 /* Extract the detailed info to make one pane. */
866 keymap_panes (&menu
, 1, NILP (position
));
868 /* Search for a string appearing directly as an element of the keymap.
869 That string is the title of the menu. */
870 prompt
= map_prompt (keymap
);
872 /* Make that be the pane title of the first pane. */
873 if (!NILP (prompt
) && menu_items_n_panes
>= 0)
874 XVECTOR (menu_items
)->contents
[MENU_ITEMS_PANE_NAME
] = prompt
;
878 else if (!NILP (tem
))
880 /* We were given a list of keymaps. */
881 int nmaps
= XFASTINT (Flength (menu
));
883 = (Lisp_Object
*) alloca (nmaps
* sizeof (Lisp_Object
));
888 /* The first keymap that has a prompt string
889 supplies the menu title. */
890 for (tem
= menu
, i
= 0; CONSP (tem
); tem
= Fcdr (tem
))
894 maps
[i
++] = keymap
= get_keymap (Fcar (tem
));
896 prompt
= map_prompt (keymap
);
897 if (NILP (title
) && !NILP (prompt
))
901 /* Extract the detailed info to make one pane. */
902 keymap_panes (maps
, nmaps
, NILP (position
));
904 /* Make the title be the pane title of the first pane. */
905 if (!NILP (title
) && menu_items_n_panes
>= 0)
906 XVECTOR (menu_items
)->contents
[MENU_ITEMS_PANE_NAME
] = title
;
912 /* We were given an old-fashioned menu. */
914 CHECK_STRING (title
, 1);
916 list_of_panes (Fcdr (menu
));
923 discard_menu_items ();
929 /* Display them in a menu. */
932 selection
= xmenu_show (f
, xpos
, ypos
, for_click
,
933 keymaps
, title
, &error_name
);
936 discard_menu_items ();
939 #endif /* HAVE_MENUS */
941 if (error_name
) error (error_name
);
947 DEFUN ("x-popup-dialog", Fx_popup_dialog
, Sx_popup_dialog
, 2, 2, 0,
948 "Pop up a dialog box and return user's selection.\n\
949 POSITION specifies which frame to use.\n\
950 This is normally a mouse button event or a window or frame.\n\
951 If POSITION is t, it means to use the frame the mouse is on.\n\
952 The dialog box appears in the middle of the specified frame.\n\
954 CONTENTS specifies the alternatives to display in the dialog box.\n\
955 It is a list of the form (TITLE ITEM1 ITEM2...).\n\
956 Each ITEM is a cons cell (STRING . VALUE).\n\
957 The return value is VALUE from the chosen item.\n\n\
958 An ITEM may also be just a string--that makes a nonselectable item.\n\
959 An ITEM may also be nil--that means to put all preceding items\n\
960 on the left of the dialog box and all following items on the right.\n\
961 \(By default, approximately half appear on each side.)")
963 Lisp_Object position
, contents
;
970 /* Decode the first argument: find the window or frame to use. */
971 if (EQ (position
, Qt
)
972 || (CONSP (position
) && EQ (XCONS (position
)->car
, Qmenu_bar
)))
974 #if 0 /* Using the frame the mouse is on may not be right. */
975 /* Use the mouse's current position. */
976 FRAME_PTR new_f
= selected_frame
;
977 Lisp_Object bar_window
;
982 (*mouse_position_hook
) (&new_f
, 1, &bar_window
, &part
, &x
, &y
, &time
);
985 XSETFRAME (window
, new_f
);
987 window
= selected_window
;
989 window
= selected_window
;
991 else if (CONSP (position
))
994 tem
= Fcar (position
);
996 window
= Fcar (Fcdr (position
));
999 tem
= Fcar (Fcdr (position
)); /* EVENT_START (position) */
1000 window
= Fcar (tem
); /* POSN_WINDOW (tem) */
1003 else if (WINDOWP (position
) || FRAMEP (position
))
1006 /* Decode where to put the menu. */
1008 if (FRAMEP (window
))
1009 f
= XFRAME (window
);
1010 else if (WINDOWP (window
))
1012 CHECK_LIVE_WINDOW (window
, 0);
1013 f
= XFRAME (WINDOW_FRAME (XWINDOW (window
)));
1016 /* ??? Not really clean; should be CHECK_WINDOW_OR_FRAME,
1017 but I don't want to make one now. */
1018 CHECK_WINDOW (window
, 0);
1020 #ifndef USE_X_TOOLKIT
1021 /* Display a menu with these alternatives
1022 in the middle of frame F. */
1024 Lisp_Object x
, y
, frame
, newpos
;
1025 XSETFRAME (frame
, f
);
1026 XSETINT (x
, x_pixel_width (f
) / 2);
1027 XSETINT (y
, x_pixel_height (f
) / 2);
1028 newpos
= Fcons (Fcons (x
, Fcons (y
, Qnil
)), Fcons (frame
, Qnil
));
1030 return Fx_popup_menu (newpos
,
1031 Fcons (Fcar (contents
), Fcons (contents
, Qnil
)));
1037 Lisp_Object selection
;
1039 /* Decode the dialog items from what was specified. */
1040 title
= Fcar (contents
);
1041 CHECK_STRING (title
, 1);
1043 list_of_panes (Fcons (contents
, Qnil
));
1045 /* Display them in a dialog box. */
1047 selection
= xdialog_show (f
, 0, title
, &error_name
);
1050 discard_menu_items ();
1052 if (error_name
) error (error_name
);
1058 #ifdef USE_X_TOOLKIT
1060 /* Loop in Xt until the menu pulldown or dialog popup has been
1061 popped down (deactivated). This is used for x-popup-menu
1062 and x-popup-dialog; it is not used for the menu bar any more.
1064 NOTE: All calls to popup_get_selection should be protected
1065 with BLOCK_INPUT, UNBLOCK_INPUT wrappers. */
1068 popup_get_selection (initial_event
, dpyinfo
, id
)
1069 XEvent
*initial_event
;
1070 struct x_display_info
*dpyinfo
;
1075 /* Define a queue to save up for later unreading
1076 all X events that don't pertain to the menu. */
1080 struct event_queue
*next
;
1083 struct event_queue
*queue
= NULL
;
1084 struct event_queue
*queue_tmp
;
1087 event
= *initial_event
;
1089 XtAppNextEvent (Xt_app_con
, &event
);
1093 /* Handle expose events for editor frames right away. */
1094 if (event
.type
== Expose
)
1095 process_expose_from_menu (event
);
1096 /* Make sure we don't consider buttons grabbed after menu goes. */
1097 else if (event
.type
== ButtonRelease
1098 && dpyinfo
->display
== event
.xbutton
.display
)
1099 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
1100 /* If the user presses a key, deactivate the menu.
1101 The user is likely to do that if we get wedged. */
1102 else if (event
.type
== KeyPress
1103 && dpyinfo
->display
== event
.xbutton
.display
)
1105 popup_activated_flag
= 0;
1108 /* Button presses outside the menu also pop it down. */
1109 else if (event
.type
== ButtonPress
1110 && event
.xany
.display
== dpyinfo
->display
1111 && x_any_window_to_frame (dpyinfo
, event
.xany
.window
))
1113 popup_activated_flag
= 0;
1117 /* Queue all events not for this popup,
1118 except for Expose, which we've already handled.
1119 Note that the X window is associated with the frame if this
1120 is a menu bar popup, but not if it's a dialog box. So we use
1121 x_non_menubar_window_to_frame, not x_any_window_to_frame. */
1122 if (event
.type
!= Expose
1123 && (event
.xany
.display
!= dpyinfo
->display
1124 || x_non_menubar_window_to_frame (dpyinfo
, event
.xany
.window
)))
1126 queue_tmp
= (struct event_queue
*) malloc (sizeof (struct event_queue
));
1128 if (queue_tmp
!= NULL
)
1130 queue_tmp
->event
= event
;
1131 queue_tmp
->next
= queue
;
1136 XtDispatchEvent (&event
);
1138 if (!popup_activated ())
1140 XtAppNextEvent (Xt_app_con
, &event
);
1143 /* Unread any events that we got but did not handle. */
1144 while (queue
!= NULL
)
1147 XPutBackEvent (queue_tmp
->event
.xany
.display
, &queue_tmp
->event
);
1148 queue
= queue_tmp
->next
;
1149 free ((char *)queue_tmp
);
1150 /* Cause these events to get read as soon as we UNBLOCK_INPUT. */
1151 interrupt_input_pending
= 1;
1155 /* Activate the menu bar of frame F.
1156 This is called from keyboard.c when it gets the
1157 menu_bar_activate_event out of the Emacs event queue.
1159 To activate the menu bar, we use the X button-press event
1160 that was saved in saved_button_event.
1161 That makes the toolkit do its thing.
1163 But first we recompute the menu bar contents (the whole tree).
1165 The reason for saving the button event until here, instead of
1166 passing it to the toolkit right away, is that we can safely
1167 execute Lisp code. */
1169 x_activate_menubar (f
)
1172 if (f
->output_data
.x
->saved_button_event
->type
!= ButtonPress
)
1175 set_frame_menubar (f
, 0, 1);
1178 XtDispatchEvent ((XEvent
*) f
->output_data
.x
->saved_button_event
);
1181 /* Ignore this if we get it a second time. */
1182 f
->output_data
.x
->saved_button_event
->type
= 0;
1185 /* Detect if a dialog or menu has been posted. */
1190 return popup_activated_flag
;
1194 /* This callback is invoked when the user selects a menubar cascade
1195 pushbutton, but before the pulldown menu is posted. */
1198 popup_activate_callback (widget
, id
, client_data
)
1201 XtPointer client_data
;
1203 popup_activated_flag
= 1;
1206 /* This callback is called from the menu bar pulldown menu
1207 when the user makes a selection.
1208 Figure out what the user chose
1209 and put the appropriate events into the keyboard buffer. */
1212 menubar_selection_callback (widget
, id
, client_data
)
1215 XtPointer client_data
;
1217 Lisp_Object prefix
, entry
;
1218 FRAME_PTR f
= menubar_id_to_frame (id
);
1220 Lisp_Object
*subprefix_stack
;
1221 int submenu_depth
= 0;
1226 subprefix_stack
= (Lisp_Object
*) alloca (f
->menu_bar_items_used
* sizeof (Lisp_Object
));
1227 vector
= f
->menu_bar_vector
;
1230 while (i
< f
->menu_bar_items_used
)
1232 if (EQ (XVECTOR (vector
)->contents
[i
], Qnil
))
1234 subprefix_stack
[submenu_depth
++] = prefix
;
1238 else if (EQ (XVECTOR (vector
)->contents
[i
], Qlambda
))
1240 prefix
= subprefix_stack
[--submenu_depth
];
1243 else if (EQ (XVECTOR (vector
)->contents
[i
], Qt
))
1245 prefix
= XVECTOR (vector
)->contents
[i
+ MENU_ITEMS_PANE_PREFIX
];
1246 i
+= MENU_ITEMS_PANE_LENGTH
;
1250 entry
= XVECTOR (vector
)->contents
[i
+ MENU_ITEMS_ITEM_VALUE
];
1251 /* The EMACS_INT cast avoids a warning. There's no problem
1252 as long as pointers have enough bits to hold small integers. */
1253 if ((int) (EMACS_INT
) client_data
== i
)
1256 struct input_event buf
;
1259 XSETFRAME (frame
, f
);
1260 buf
.kind
= menu_bar_event
;
1261 buf
.frame_or_window
= Fcons (frame
, Fcons (Qmenu_bar
, Qnil
));
1262 kbd_buffer_store_event (&buf
);
1264 for (j
= 0; j
< submenu_depth
; j
++)
1265 if (!NILP (subprefix_stack
[j
]))
1267 buf
.kind
= menu_bar_event
;
1268 buf
.frame_or_window
= Fcons (frame
, subprefix_stack
[j
]);
1269 kbd_buffer_store_event (&buf
);
1274 buf
.kind
= menu_bar_event
;
1275 buf
.frame_or_window
= Fcons (frame
, prefix
);
1276 kbd_buffer_store_event (&buf
);
1279 buf
.kind
= menu_bar_event
;
1280 buf
.frame_or_window
= Fcons (frame
, entry
);
1281 kbd_buffer_store_event (&buf
);
1285 i
+= MENU_ITEMS_ITEM_LENGTH
;
1290 /* This callback is invoked when a dialog or menu is finished being
1291 used and has been unposted. */
1294 popup_deactivate_callback (widget
, id
, client_data
)
1297 XtPointer client_data
;
1299 popup_activated_flag
= 0;
1302 /* Allocate a widget_value, blocking input. */
1305 xmalloc_widget_value ()
1307 widget_value
*value
;
1310 value
= malloc_widget_value ();
1316 /* This recursively calls free_widget_value on the tree of widgets.
1317 It must free all data that was malloc'ed for these widget_values.
1318 In Emacs, many slots are pointers into the data of Lisp_Strings, and
1319 must be left alone. */
1322 free_menubar_widget_value_tree (wv
)
1327 wv
->name
= wv
->value
= wv
->key
= (char *) 0xDEADBEEF;
1329 if (wv
->contents
&& (wv
->contents
!= (widget_value
*)1))
1331 free_menubar_widget_value_tree (wv
->contents
);
1332 wv
->contents
= (widget_value
*) 0xDEADBEEF;
1336 free_menubar_widget_value_tree (wv
->next
);
1337 wv
->next
= (widget_value
*) 0xDEADBEEF;
1340 free_widget_value (wv
);
1344 /* Return a tree of widget_value structures for a menu bar item
1345 whose event type is ITEM_KEY (with string ITEM_NAME)
1346 and whose contents come from the list of keymaps MAPS. */
1348 static widget_value
*
1349 single_submenu (item_key
, item_name
, maps
)
1350 Lisp_Object item_key
, item_name
, maps
;
1352 widget_value
*wv
, *prev_wv
, *save_wv
, *first_wv
;
1354 int submenu_depth
= 0;
1357 Lisp_Object
*mapvec
;
1358 widget_value
**submenu_stack
;
1360 int previous_items
= menu_items_used
;
1361 int top_level_items
= 0;
1363 length
= Flength (maps
);
1364 len
= XINT (length
);
1366 /* Convert the list MAPS into a vector MAPVEC. */
1367 mapvec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
1368 for (i
= 0; i
< len
; i
++)
1370 mapvec
[i
] = Fcar (maps
);
1374 menu_items_n_panes
= 0;
1376 /* Loop over the given keymaps, making a pane for each map.
1377 But don't make a pane that is empty--ignore that map instead. */
1378 for (i
= 0; i
< len
; i
++)
1380 if (SYMBOLP (mapvec
[i
]))
1382 top_level_items
= 1;
1383 push_menu_pane (Qnil
, Qnil
);
1384 push_menu_item (item_name
, Qt
, item_key
, mapvec
[i
], Qnil
);
1387 single_keymap_panes (mapvec
[i
], item_name
, item_key
, 0);
1390 /* Create a tree of widget_value objects
1391 representing the panes and their items. */
1394 = (widget_value
**) alloca (menu_items_used
* sizeof (widget_value
*));
1395 wv
= xmalloc_widget_value ();
1403 /* Loop over all panes and items made during this call
1404 and construct a tree of widget_value objects.
1405 Ignore the panes and items made by previous calls to
1406 single_submenu, even though those are also in menu_items. */
1408 while (i
< menu_items_used
)
1410 if (EQ (XVECTOR (menu_items
)->contents
[i
], Qnil
))
1412 submenu_stack
[submenu_depth
++] = save_wv
;
1417 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qlambda
))
1420 save_wv
= submenu_stack
[--submenu_depth
];
1423 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qt
)
1424 && submenu_depth
!= 0)
1425 i
+= MENU_ITEMS_PANE_LENGTH
;
1426 /* Ignore a nil in the item list.
1427 It's meaningful only for dialog boxes. */
1428 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qquote
))
1430 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qt
))
1432 /* Create a new pane. */
1433 Lisp_Object pane_name
, prefix
;
1435 pane_name
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_PANE_NAME
];
1436 prefix
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_PANE_PREFIX
];
1437 pane_string
= (NILP (pane_name
)
1438 ? "" : (char *) XSTRING (pane_name
)->data
);
1439 /* If there is just one top-level pane, put all its items directly
1440 under the top-level menu. */
1441 if (menu_items_n_panes
== 1)
1444 /* If the pane has a meaningful name,
1445 make the pane a top-level menu item
1446 with its items as a submenu beneath it. */
1447 if (strcmp (pane_string
, ""))
1449 wv
= xmalloc_widget_value ();
1453 first_wv
->contents
= wv
;
1454 wv
->name
= pane_string
;
1455 /* Ignore the @ that means "separate pane".
1456 This is a kludge, but this isn't worth more time. */
1457 if (!NILP (prefix
) && wv
->name
[0] == '@')
1464 i
+= MENU_ITEMS_PANE_LENGTH
;
1468 /* Create a new item within current pane. */
1469 Lisp_Object item_name
, enable
, descrip
, def
;
1470 item_name
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_NAME
];
1471 enable
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_ENABLE
];
1473 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_EQUIV_KEY
];
1474 def
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_DEFINITION
];
1476 wv
= xmalloc_widget_value ();
1480 save_wv
->contents
= wv
;
1482 wv
->name
= (char *) XSTRING (item_name
)->data
;
1483 if (!NILP (descrip
))
1484 wv
->key
= (char *) XSTRING (descrip
)->data
;
1486 /* The EMACS_INT cast avoids a warning. There's no problem
1487 as long as pointers have enough bits to hold small integers. */
1488 wv
->call_data
= (!NILP (def
) ? (void *) (EMACS_INT
) i
: 0);
1489 wv
->enabled
= !NILP (enable
);
1492 i
+= MENU_ITEMS_ITEM_LENGTH
;
1496 /* If we have just one "menu item"
1497 that was originally a button, return it by itself. */
1498 if (top_level_items
&& first_wv
->contents
&& first_wv
->contents
->next
== 0)
1500 wv
= first_wv
->contents
;
1501 free_widget_value (first_wv
);
1508 extern void EmacsFrameSetCharSize ();
1510 /* Recompute all the widgets of frame F, when the menu bar
1511 has been changed. */
1514 update_frame_menubar (f
)
1517 struct x_output
*x
= f
->output_data
.x
;
1519 int menubar_changed
;
1521 Dimension shell_height
;
1523 /* We assume the menubar contents has changed if the global flag is set,
1524 or if the current buffer has changed, or if the menubar has never
1525 been updated before.
1527 menubar_changed
= (x
->menubar_widget
1528 && !XtIsManaged (x
->menubar_widget
));
1530 if (! (menubar_changed
))
1534 /* Save the size of the frame because the pane widget doesn't accept to
1535 resize itself. So force it. */
1539 /* Do the voodoo which means "I'm changing lots of things, don't try to
1540 refigure sizes until I'm done." */
1541 lw_refigure_widget (x
->column_widget
, False
);
1543 /* the order in which children are managed is the top to
1544 bottom order in which they are displayed in the paned window.
1545 First, remove the text-area widget.
1547 XtUnmanageChild (x
->edit_widget
);
1549 /* remove the menubar that is there now, and put up the menubar that
1552 if (menubar_changed
)
1554 XtManageChild (x
->menubar_widget
);
1555 XtMapWidget (x
->menubar_widget
);
1556 XtVaSetValues (x
->menubar_widget
, XtNmappedWhenManaged
, 1, 0);
1559 /* Re-manage the text-area widget, and then thrash the sizes. */
1560 XtManageChild (x
->edit_widget
);
1561 lw_refigure_widget (x
->column_widget
, True
);
1563 /* Force the pane widget to resize itself with the right values. */
1564 EmacsFrameSetCharSize (x
->edit_widget
, columns
, rows
);
1569 /* Set the contents of the menubar widgets of frame F.
1570 The argument FIRST_TIME is currently ignored;
1571 it is set the first time this is called, from initialize_frame_menubar. */
1574 set_frame_menubar (f
, first_time
, deep_p
)
1579 Widget menubar_widget
= f
->output_data
.x
->menubar_widget
;
1580 Lisp_Object tail
, items
, frame
;
1581 widget_value
*wv
, *first_wv
, *prev_wv
= 0;
1585 if (f
->output_data
.x
->id
== 0)
1586 f
->output_data
.x
->id
= next_menubar_widget_id
++;
1587 id
= f
->output_data
.x
->id
;
1589 if (! menubar_widget
)
1592 wv
= xmalloc_widget_value ();
1593 wv
->name
= "menubar";
1600 /* Make a widget-value tree representing the entire menu trees. */
1602 struct buffer
*prev
= current_buffer
;
1604 int specpdl_count
= specpdl_ptr
- specpdl
;
1605 int previous_menu_items_used
= f
->menu_bar_items_used
;
1606 Lisp_Object
*previous_items
1607 = (Lisp_Object
*) alloca (previous_menu_items_used
1608 * sizeof (Lisp_Object
));
1610 buffer
= XWINDOW (FRAME_SELECTED_WINDOW (f
))->buffer
;
1611 specbind (Qinhibit_quit
, Qt
);
1612 /* Don't let the debugger step into this code
1613 because it is not reentrant. */
1614 specbind (Qdebug_on_next_call
, Qnil
);
1616 record_unwind_protect (Fstore_match_data
, Fmatch_data ());
1617 if (NILP (Voverriding_local_map_menu_flag
))
1619 specbind (Qoverriding_terminal_local_map
, Qnil
);
1620 specbind (Qoverriding_local_map
, Qnil
);
1623 set_buffer_internal_1 (XBUFFER (buffer
));
1625 /* Run the Lucid hook. */
1626 call1 (Vrun_hooks
, Qactivate_menubar_hook
);
1627 /* If it has changed current-menubar from previous value,
1628 really recompute the menubar from the value. */
1629 if (! NILP (Vlucid_menu_bar_dirty_flag
))
1630 call0 (Qrecompute_lucid_menubar
);
1631 safe_run_hooks (Qmenu_bar_update_hook
);
1632 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
1634 items
= FRAME_MENU_BAR_ITEMS (f
);
1636 inhibit_garbage_collection ();
1638 /* Save the frame's previous menu bar contents data. */
1639 bcopy (XVECTOR (f
->menu_bar_vector
)->contents
, previous_items
,
1640 previous_menu_items_used
* sizeof (Lisp_Object
));
1642 /* Fill in the current menu bar contents. */
1643 menu_items
= f
->menu_bar_vector
;
1644 menu_items_allocated
= XVECTOR (menu_items
)->size
;
1646 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
1648 Lisp_Object key
, string
, maps
;
1650 key
= XVECTOR (items
)->contents
[i
];
1651 string
= XVECTOR (items
)->contents
[i
+ 1];
1652 maps
= XVECTOR (items
)->contents
[i
+ 2];
1656 wv
= single_submenu (key
, string
, maps
);
1660 first_wv
->contents
= wv
;
1661 /* Don't set wv->name here; GC during the loop might relocate it. */
1666 finish_menu_items ();
1668 set_buffer_internal_1 (prev
);
1669 unbind_to (specpdl_count
, Qnil
);
1671 /* If there has been no change in the Lisp-level contents
1672 of the menu bar, skip redisplaying it. Just exit. */
1674 for (i
= 0; i
< previous_menu_items_used
; i
++)
1675 if (menu_items_used
== i
1676 || (previous_items
[i
] != XVECTOR (menu_items
)->contents
[i
]))
1678 if (i
== menu_items_used
&& i
== previous_menu_items_used
&& i
!= 0)
1680 free_menubar_widget_value_tree (first_wv
);
1686 /* Now GC cannot happen during the lifetime of the widget_value,
1687 so it's safe to store data from a Lisp_String. */
1688 wv
= first_wv
->contents
;
1689 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
1692 string
= XVECTOR (items
)->contents
[i
+ 1];
1695 wv
->name
= (char *) XSTRING (string
)->data
;
1699 f
->menu_bar_vector
= menu_items
;
1700 f
->menu_bar_items_used
= menu_items_used
;
1705 /* Make a widget-value tree containing
1706 just the top level menu bar strings. */
1708 items
= FRAME_MENU_BAR_ITEMS (f
);
1709 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
1713 string
= XVECTOR (items
)->contents
[i
+ 1];
1717 wv
= xmalloc_widget_value ();
1718 wv
->name
= (char *) XSTRING (string
)->data
;
1725 first_wv
->contents
= wv
;
1729 /* Forget what we thought we knew about what is in the
1730 detailed contents of the menu bar menus.
1731 Changing the top level always destroys the contents. */
1732 f
->menu_bar_items_used
= 0;
1735 /* Create or update the menu bar widget. */
1741 /* Disable resizing (done for Motif!) */
1742 lw_allow_resizing (f
->output_data
.x
->widget
, False
);
1744 /* The third arg is DEEP_P, which says to consider the entire
1745 menu trees we supply, rather than just the menu bar item names. */
1746 lw_modify_all_widgets (id
, first_wv
, deep_p
);
1748 /* Re-enable the edit widget to resize. */
1749 lw_allow_resizing (f
->output_data
.x
->widget
, True
);
1753 menubar_widget
= lw_create_widget ("menubar", "menubar", id
, first_wv
,
1754 f
->output_data
.x
->column_widget
,
1756 popup_activate_callback
,
1757 menubar_selection_callback
,
1758 popup_deactivate_callback
);
1759 f
->output_data
.x
->menubar_widget
= menubar_widget
;
1764 = (f
->output_data
.x
->menubar_widget
1765 ? (f
->output_data
.x
->menubar_widget
->core
.height
1766 + f
->output_data
.x
->menubar_widget
->core
.border_width
)
1770 if (FRAME_EXTERNAL_MENU_BAR (f
))
1773 XtVaGetValues (f
->output_data
.x
->column_widget
,
1774 XtNinternalBorderWidth
, &ibw
, NULL
);
1775 menubar_size
+= ibw
;
1777 #endif /* USE_LUCID */
1779 f
->output_data
.x
->menubar_height
= menubar_size
;
1782 free_menubar_widget_value_tree (first_wv
);
1784 update_frame_menubar (f
);
1789 /* Called from Fx_create_frame to create the initial menubar of a frame
1790 before it is mapped, so that the window is mapped with the menubar already
1791 there instead of us tacking it on later and thrashing the window after it
1795 initialize_frame_menubar (f
)
1798 /* This function is called before the first chance to redisplay
1799 the frame. It has to be, so the frame will have the right size. */
1800 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
1801 set_frame_menubar (f
, 1, 1);
1804 /* Get rid of the menu bar of frame F, and free its storage.
1805 This is used when deleting a frame, and when turning off the menu bar. */
1808 free_frame_menubar (f
)
1811 Widget menubar_widget
;
1814 menubar_widget
= f
->output_data
.x
->menubar_widget
;
1819 lw_destroy_all_widgets ((LWLIB_ID
) f
->output_data
.x
->id
);
1824 #endif /* USE_X_TOOLKIT */
1826 /* xmenu_show actually displays a menu using the panes and items in menu_items
1827 and returns the value selected from it.
1828 There are two versions of xmenu_show, one for Xt and one for Xlib.
1829 Both assume input is blocked by the caller. */
1831 /* F is the frame the menu is for.
1832 X and Y are the frame-relative specified position,
1833 relative to the inside upper left corner of the frame F.
1834 FOR_CLICK if this menu was invoked for a mouse click.
1835 KEYMAPS is 1 if this menu was specified with keymaps;
1836 in that case, we return a list containing the chosen item's value
1837 and perhaps also the pane's prefix.
1838 TITLE is the specified menu title.
1839 ERROR is a place to store an error message string in case of failure.
1840 (We return nil on failure, but the value doesn't actually matter.) */
1842 #ifdef USE_X_TOOLKIT
1844 /* We need a unique id for each widget handled by the Lucid Widget
1847 For the main windows, and popup menus, we use this counter,
1848 which we increment each time after use. This starts from 1<<16.
1850 For menu bars, we use numbers starting at 0, counted in
1851 next_menubar_widget_id. */
1852 LWLIB_ID widget_id_tick
;
1855 static Lisp_Object
*volatile menu_item_selection
;
1857 static Lisp_Object
*menu_item_selection
;
1861 popup_selection_callback (widget
, id
, client_data
)
1864 XtPointer client_data
;
1866 menu_item_selection
= (Lisp_Object
*) client_data
;
1870 xmenu_show (f
, x
, y
, for_click
, keymaps
, title
, error
)
1884 widget_value
*wv
, *save_wv
= 0, *first_wv
= 0, *prev_wv
= 0;
1885 widget_value
**submenu_stack
1886 = (widget_value
**) alloca (menu_items_used
* sizeof (widget_value
*));
1887 Lisp_Object
*subprefix_stack
1888 = (Lisp_Object
*) alloca (menu_items_used
* sizeof (Lisp_Object
));
1889 int submenu_depth
= 0;
1890 XButtonPressedEvent dummy
;
1893 int next_release_must_exit
= 0;
1897 if (menu_items_used
<= MENU_ITEMS_PANE_LENGTH
)
1899 *error
= "Empty menu";
1903 /* Create a tree of widget_value objects
1904 representing the panes and their items. */
1905 wv
= xmalloc_widget_value ();
1912 /* Loop over all panes and items, filling in the tree. */
1914 while (i
< menu_items_used
)
1916 if (EQ (XVECTOR (menu_items
)->contents
[i
], Qnil
))
1918 submenu_stack
[submenu_depth
++] = save_wv
;
1924 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qlambda
))
1927 save_wv
= submenu_stack
[--submenu_depth
];
1931 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qt
)
1932 && submenu_depth
!= 0)
1933 i
+= MENU_ITEMS_PANE_LENGTH
;
1934 /* Ignore a nil in the item list.
1935 It's meaningful only for dialog boxes. */
1936 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qquote
))
1938 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qt
))
1940 /* Create a new pane. */
1941 Lisp_Object pane_name
, prefix
;
1943 pane_name
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_PANE_NAME
];
1944 prefix
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_PANE_PREFIX
];
1945 pane_string
= (NILP (pane_name
)
1946 ? "" : (char *) XSTRING (pane_name
)->data
);
1947 /* If there is just one top-level pane, put all its items directly
1948 under the top-level menu. */
1949 if (menu_items_n_panes
== 1)
1952 /* If the pane has a meaningful name,
1953 make the pane a top-level menu item
1954 with its items as a submenu beneath it. */
1955 if (!keymaps
&& strcmp (pane_string
, ""))
1957 wv
= xmalloc_widget_value ();
1961 first_wv
->contents
= wv
;
1962 wv
->name
= pane_string
;
1963 if (keymaps
&& !NILP (prefix
))
1970 else if (first_pane
)
1976 i
+= MENU_ITEMS_PANE_LENGTH
;
1980 /* Create a new item within current pane. */
1981 Lisp_Object item_name
, enable
, descrip
, def
;
1982 item_name
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_NAME
];
1983 enable
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_ENABLE
];
1985 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_EQUIV_KEY
];
1986 def
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_DEFINITION
];
1988 wv
= xmalloc_widget_value ();
1992 save_wv
->contents
= wv
;
1993 wv
->name
= (char *) XSTRING (item_name
)->data
;
1994 if (!NILP (descrip
))
1995 wv
->key
= (char *) XSTRING (descrip
)->data
;
1997 /* If this item has a null value,
1998 make the call_data null so that it won't display a box
1999 when the mouse is on it. */
2001 = (!NILP (def
) ? (void *) &XVECTOR (menu_items
)->contents
[i
] : 0);
2002 wv
->enabled
= !NILP (enable
);
2005 i
+= MENU_ITEMS_ITEM_LENGTH
;
2009 /* Deal with the title, if it is non-nil. */
2012 widget_value
*wv_title
= xmalloc_widget_value ();
2013 widget_value
*wv_sep1
= xmalloc_widget_value ();
2014 widget_value
*wv_sep2
= xmalloc_widget_value ();
2016 wv_sep2
->name
= "--";
2017 wv_sep2
->next
= first_wv
->contents
;
2019 wv_sep1
->name
= "--";
2020 wv_sep1
->next
= wv_sep2
;
2022 wv_title
->name
= (char *) XSTRING (title
)->data
;
2023 wv_title
->enabled
= True
;
2024 wv_title
->next
= wv_sep1
;
2025 first_wv
->contents
= wv_title
;
2028 /* Actually create the menu. */
2029 menu_id
= widget_id_tick
++;
2030 menu
= lw_create_widget ("popup", first_wv
->name
, menu_id
, first_wv
,
2031 f
->output_data
.x
->widget
, 1, 0,
2032 popup_selection_callback
,
2033 popup_deactivate_callback
);
2035 /* Adjust coordinates to relative to the outer (window manager) window. */
2038 int win_x
= 0, win_y
= 0;
2040 /* Find the position of the outside upper-left corner of
2041 the inner window, with respect to the outer window. */
2042 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
2045 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
2047 /* From-window, to-window. */
2048 f
->output_data
.x
->window_desc
,
2049 f
->output_data
.x
->parent_desc
,
2051 /* From-position, to-position. */
2052 0, 0, &win_x
, &win_y
,
2054 /* Child of window. */
2062 /* Adjust coordinates to be root-window-relative. */
2063 x
+= f
->output_data
.x
->left_pos
;
2064 y
+= f
->output_data
.x
->top_pos
;
2066 dummy
.type
= ButtonPress
;
2068 dummy
.send_event
= 0;
2069 dummy
.display
= FRAME_X_DISPLAY (f
);
2070 dummy
.time
= CurrentTime
;
2072 dummy
.root
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
2073 dummy
.window
= dummy
.root
;
2074 dummy
.subwindow
= dummy
.root
;
2080 /* Don't allow any geometry request from the user. */
2081 XtSetArg (av
[ac
], XtNgeometry
, 0); ac
++;
2082 XtSetValues (menu
, av
, ac
);
2084 /* Free the widget_value objects we used to specify the contents. */
2085 free_menubar_widget_value_tree (first_wv
);
2087 /* No selection has been chosen yet. */
2088 menu_item_selection
= 0;
2090 /* Display the menu. */
2091 lw_popup_menu (menu
, &dummy
);
2092 popup_activated_flag
= 1;
2094 /* Process events that apply to the menu. */
2095 popup_get_selection ((XEvent
*) 0, FRAME_X_DISPLAY_INFO (f
), menu_id
);
2097 /* fp turned off the following statement and wrote a comment
2098 that it is unnecessary--that the menu has already disappeared.
2099 Nowadays the menu disappears ok, all right, but
2100 we need to delete the widgets or multiple ones will pile up. */
2101 lw_destroy_all_widgets (menu_id
);
2103 /* Find the selected item, and its pane, to return
2104 the proper value. */
2105 if (menu_item_selection
!= 0)
2107 Lisp_Object prefix
, entry
;
2111 while (i
< menu_items_used
)
2113 if (EQ (XVECTOR (menu_items
)->contents
[i
], Qnil
))
2115 subprefix_stack
[submenu_depth
++] = prefix
;
2119 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qlambda
))
2121 prefix
= subprefix_stack
[--submenu_depth
];
2124 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qt
))
2127 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_PANE_PREFIX
];
2128 i
+= MENU_ITEMS_PANE_LENGTH
;
2130 /* Ignore a nil in the item list.
2131 It's meaningful only for dialog boxes. */
2132 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qquote
))
2137 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_VALUE
];
2138 if (menu_item_selection
== &XVECTOR (menu_items
)->contents
[i
])
2144 entry
= Fcons (entry
, Qnil
);
2146 entry
= Fcons (prefix
, entry
);
2147 for (j
= submenu_depth
- 1; j
>= 0; j
--)
2148 if (!NILP (subprefix_stack
[j
]))
2149 entry
= Fcons (subprefix_stack
[j
], entry
);
2153 i
+= MENU_ITEMS_ITEM_LENGTH
;
2162 dialog_selection_callback (widget
, id
, client_data
)
2165 XtPointer client_data
;
2167 /* The EMACS_INT cast avoids a warning. There's no problem
2168 as long as pointers have enough bits to hold small integers. */
2169 if ((int) (EMACS_INT
) client_data
!= -1)
2170 menu_item_selection
= (Lisp_Object
*) client_data
;
2172 lw_destroy_all_widgets (id
);
2174 popup_activated_flag
= 0;
2177 static char * button_names
[] = {
2178 "button1", "button2", "button3", "button4", "button5",
2179 "button6", "button7", "button8", "button9", "button10" };
2182 xdialog_show (f
, keymaps
, title
, error
)
2188 int i
, nb_buttons
=0;
2191 char dialog_name
[6];
2193 widget_value
*wv
, *save_wv
= 0, *first_wv
= 0, *prev_wv
= 0;
2195 /* Number of elements seen so far, before boundary. */
2197 /* 1 means we've seen the boundary between left-hand elts and right-hand. */
2198 int boundary_seen
= 0;
2202 if (menu_items_n_panes
> 1)
2204 *error
= "Multiple panes in dialog box";
2208 /* Create a tree of widget_value objects
2209 representing the text label and buttons. */
2211 Lisp_Object pane_name
, prefix
;
2213 pane_name
= XVECTOR (menu_items
)->contents
[MENU_ITEMS_PANE_NAME
];
2214 prefix
= XVECTOR (menu_items
)->contents
[MENU_ITEMS_PANE_PREFIX
];
2215 pane_string
= (NILP (pane_name
)
2216 ? "" : (char *) XSTRING (pane_name
)->data
);
2217 prev_wv
= xmalloc_widget_value ();
2218 prev_wv
->value
= pane_string
;
2219 if (keymaps
&& !NILP (prefix
))
2221 prev_wv
->enabled
= 1;
2222 prev_wv
->name
= "message";
2225 /* Loop over all panes and items, filling in the tree. */
2226 i
= MENU_ITEMS_PANE_LENGTH
;
2227 while (i
< menu_items_used
)
2230 /* Create a new item within current pane. */
2231 Lisp_Object item_name
, enable
, descrip
;
2232 item_name
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_NAME
];
2233 enable
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_ENABLE
];
2235 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_EQUIV_KEY
];
2237 if (NILP (item_name
))
2239 free_menubar_widget_value_tree (first_wv
);
2240 *error
= "Submenu in dialog items";
2243 if (EQ (item_name
, Qquote
))
2245 /* This is the boundary between left-side elts
2246 and right-side elts. Stop incrementing right_count. */
2251 if (nb_buttons
>= 10)
2253 free_menubar_widget_value_tree (first_wv
);
2254 *error
= "Too many dialog items";
2258 wv
= xmalloc_widget_value ();
2260 wv
->name
= (char *) button_names
[nb_buttons
];
2261 if (!NILP (descrip
))
2262 wv
->key
= (char *) XSTRING (descrip
)->data
;
2263 wv
->value
= (char *) XSTRING (item_name
)->data
;
2264 wv
->call_data
= (void *) &XVECTOR (menu_items
)->contents
[i
];
2265 wv
->enabled
= !NILP (enable
);
2268 if (! boundary_seen
)
2272 i
+= MENU_ITEMS_ITEM_LENGTH
;
2275 /* If the boundary was not specified,
2276 by default put half on the left and half on the right. */
2277 if (! boundary_seen
)
2278 left_count
= nb_buttons
- nb_buttons
/ 2;
2280 wv
= xmalloc_widget_value ();
2281 wv
->name
= dialog_name
;
2283 /* Dialog boxes use a really stupid name encoding
2284 which specifies how many buttons to use
2285 and how many buttons are on the right.
2286 The Q means something also. */
2287 dialog_name
[0] = 'Q';
2288 dialog_name
[1] = '0' + nb_buttons
;
2289 dialog_name
[2] = 'B';
2290 dialog_name
[3] = 'R';
2291 /* Number of buttons to put on the right. */
2292 dialog_name
[4] = '0' + nb_buttons
- left_count
;
2294 wv
->contents
= first_wv
;
2298 /* Actually create the dialog. */
2299 dialog_id
= widget_id_tick
++;
2300 menu
= lw_create_widget (first_wv
->name
, "dialog", dialog_id
, first_wv
,
2301 f
->output_data
.x
->widget
, 1, 0,
2302 dialog_selection_callback
, 0);
2303 lw_modify_all_widgets (dialog_id
, first_wv
->contents
, True
);
2304 /* Free the widget_value objects we used to specify the contents. */
2305 free_menubar_widget_value_tree (first_wv
);
2307 /* No selection has been chosen yet. */
2308 menu_item_selection
= 0;
2310 /* Display the menu. */
2311 lw_pop_up_all_widgets (dialog_id
);
2312 popup_activated_flag
= 1;
2314 /* Process events that apply to the menu. */
2315 popup_get_selection ((XEvent
*) 0, FRAME_X_DISPLAY_INFO (f
), dialog_id
);
2317 lw_destroy_all_widgets (dialog_id
);
2319 /* Find the selected item, and its pane, to return
2320 the proper value. */
2321 if (menu_item_selection
!= 0)
2327 while (i
< menu_items_used
)
2331 if (EQ (XVECTOR (menu_items
)->contents
[i
], Qt
))
2334 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_PANE_PREFIX
];
2335 i
+= MENU_ITEMS_PANE_LENGTH
;
2340 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_VALUE
];
2341 if (menu_item_selection
== &XVECTOR (menu_items
)->contents
[i
])
2345 entry
= Fcons (entry
, Qnil
);
2347 entry
= Fcons (prefix
, entry
);
2351 i
+= MENU_ITEMS_ITEM_LENGTH
;
2358 #else /* not USE_X_TOOLKIT */
2361 xmenu_show (f
, x
, y
, for_click
, keymaps
, title
, error
)
2371 int pane
, selidx
, lpane
, status
;
2372 Lisp_Object entry
, pane_prefix
;
2374 int ulx
, uly
, width
, height
;
2375 int dispwidth
, dispheight
;
2379 unsigned int dummy_uint
;
2382 if (menu_items_n_panes
== 0)
2385 if (menu_items_used
<= MENU_ITEMS_PANE_LENGTH
)
2387 *error
= "Empty menu";
2391 /* Figure out which root window F is on. */
2392 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &root
,
2393 &dummy_int
, &dummy_int
, &dummy_uint
, &dummy_uint
,
2394 &dummy_uint
, &dummy_uint
);
2396 /* Make the menu on that window. */
2397 menu
= XMenuCreate (FRAME_X_DISPLAY (f
), root
, "emacs");
2400 *error
= "Can't create menu";
2404 #ifdef HAVE_X_WINDOWS
2405 /* Adjust coordinates to relative to the outer (window manager) window. */
2408 int win_x
= 0, win_y
= 0;
2410 /* Find the position of the outside upper-left corner of
2411 the inner window, with respect to the outer window. */
2412 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
2415 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
2417 /* From-window, to-window. */
2418 f
->output_data
.x
->window_desc
,
2419 f
->output_data
.x
->parent_desc
,
2421 /* From-position, to-position. */
2422 0, 0, &win_x
, &win_y
,
2424 /* Child of window. */
2431 #endif /* HAVE_X_WINDOWS */
2433 /* Adjust coordinates to be root-window-relative. */
2434 x
+= f
->output_data
.x
->left_pos
;
2435 y
+= f
->output_data
.x
->top_pos
;
2437 /* Create all the necessary panes and their items. */
2439 while (i
< menu_items_used
)
2441 if (EQ (XVECTOR (menu_items
)->contents
[i
], Qt
))
2443 /* Create a new pane. */
2444 Lisp_Object pane_name
, prefix
;
2447 pane_name
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_PANE_NAME
];
2448 prefix
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_PANE_PREFIX
];
2449 pane_string
= (NILP (pane_name
)
2450 ? "" : (char *) XSTRING (pane_name
)->data
);
2451 if (keymaps
&& !NILP (prefix
))
2454 lpane
= XMenuAddPane (FRAME_X_DISPLAY (f
), menu
, pane_string
, TRUE
);
2455 if (lpane
== XM_FAILURE
)
2457 XMenuDestroy (FRAME_X_DISPLAY (f
), menu
);
2458 *error
= "Can't create pane";
2461 i
+= MENU_ITEMS_PANE_LENGTH
;
2463 /* Find the width of the widest item in this pane. */
2466 while (j
< menu_items_used
)
2469 item
= XVECTOR (menu_items
)->contents
[j
];
2477 width
= XSTRING (item
)->size
;
2478 if (width
> maxwidth
)
2481 j
+= MENU_ITEMS_ITEM_LENGTH
;
2484 /* Ignore a nil in the item list.
2485 It's meaningful only for dialog boxes. */
2486 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qquote
))
2490 /* Create a new item within current pane. */
2491 Lisp_Object item_name
, enable
, descrip
;
2492 unsigned char *item_data
;
2494 item_name
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_NAME
];
2495 enable
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_ENABLE
];
2497 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_EQUIV_KEY
];
2498 if (!NILP (descrip
))
2500 int gap
= maxwidth
- XSTRING (item_name
)->size
;
2503 spacer
= Fmake_string (make_number (gap
), make_number (' '));
2504 item_name
= concat2 (item_name
, spacer
);
2505 item_name
= concat2 (item_name
, descrip
);
2506 item_data
= XSTRING (item_name
)->data
;
2508 /* if alloca is fast, use that to make the space,
2509 to reduce gc needs. */
2511 = (unsigned char *) alloca (maxwidth
2512 + XSTRING (descrip
)->size
+ 1);
2513 bcopy (XSTRING (item_name
)->data
, item_data
,
2514 XSTRING (item_name
)->size
);
2515 for (j
= XSTRING (item_name
)->size
; j
< maxwidth
; j
++)
2517 bcopy (XSTRING (descrip
)->data
, item_data
+ j
,
2518 XSTRING (descrip
)->size
);
2519 item_data
[j
+ XSTRING (descrip
)->size
] = 0;
2523 item_data
= XSTRING (item_name
)->data
;
2525 if (XMenuAddSelection (FRAME_X_DISPLAY (f
),
2526 menu
, lpane
, 0, item_data
,
2530 XMenuDestroy (FRAME_X_DISPLAY (f
), menu
);
2531 *error
= "Can't add selection to menu";
2534 i
+= MENU_ITEMS_ITEM_LENGTH
;
2538 /* All set and ready to fly. */
2539 XMenuRecompute (FRAME_X_DISPLAY (f
), menu
);
2540 dispwidth
= DisplayWidth (FRAME_X_DISPLAY (f
),
2541 XScreenNumberOfScreen (FRAME_X_SCREEN (f
)));
2542 dispheight
= DisplayHeight (FRAME_X_DISPLAY (f
),
2543 XScreenNumberOfScreen (FRAME_X_SCREEN (f
)));
2544 x
= min (x
, dispwidth
);
2545 y
= min (y
, dispheight
);
2548 XMenuLocate (FRAME_X_DISPLAY (f
), menu
, 0, 0, x
, y
,
2549 &ulx
, &uly
, &width
, &height
);
2550 if (ulx
+width
> dispwidth
)
2552 x
-= (ulx
+ width
) - dispwidth
;
2553 ulx
= dispwidth
- width
;
2555 if (uly
+height
> dispheight
)
2557 y
-= (uly
+ height
) - dispheight
;
2558 uly
= dispheight
- height
;
2560 if (ulx
< 0) x
-= ulx
;
2561 if (uly
< 0) y
-= uly
;
2563 XMenuSetAEQ (menu
, TRUE
);
2564 XMenuSetFreeze (menu
, TRUE
);
2567 status
= XMenuActivate (FRAME_X_DISPLAY (f
), menu
, &pane
, &selidx
,
2568 x
, y
, ButtonReleaseMask
, &datap
);
2571 #ifdef HAVE_X_WINDOWS
2572 /* Assume the mouse has moved out of the X window.
2573 If it has actually moved in, we will get an EnterNotify. */
2574 x_mouse_leave (FRAME_X_DISPLAY_INFO (f
));
2581 fprintf (stderr
, "pane= %d line = %d\n", panes
, selidx
);
2584 /* Find the item number SELIDX in pane number PANE. */
2586 while (i
< menu_items_used
)
2588 if (EQ (XVECTOR (menu_items
)->contents
[i
], Qt
))
2592 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_PANE_PREFIX
];
2594 i
+= MENU_ITEMS_PANE_LENGTH
;
2603 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_VALUE
];
2606 entry
= Fcons (entry
, Qnil
);
2607 if (!NILP (pane_prefix
))
2608 entry
= Fcons (pane_prefix
, entry
);
2614 i
+= MENU_ITEMS_ITEM_LENGTH
;
2620 *error
= "Can't activate menu";
2626 XMenuDestroy (FRAME_X_DISPLAY (f
), menu
);
2628 #ifdef HAVE_X_WINDOWS
2629 /* State that no mouse buttons are now held.
2630 (The oldXMenu code doesn't track this info for us.)
2631 That is not necessarily true, but the fiction leads to reasonable
2632 results, and it is a pain to ask which are actually held now. */
2633 FRAME_X_DISPLAY_INFO (f
)->grabbed
= 0;
2639 #endif /* not USE_X_TOOLKIT */
2641 #endif /* HAVE_MENUS */
2645 staticpro (&menu_items
);
2648 Qdebug_on_next_call
= intern ("debug-on-next-call");
2649 staticpro (&Qdebug_on_next_call
);
2651 #ifdef USE_X_TOOLKIT
2652 widget_id_tick
= (1<<16);
2653 next_menubar_widget_id
= 1;
2656 defsubr (&Sx_popup_menu
);
2658 defsubr (&Sx_popup_dialog
);