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, 675 Mass Ave, Cambridge, MA 02139, USA. */
20 /* X pop-up deck-of-cards menu facility for gnuemacs.
22 * Written by Jon Arnold and Roman Budzianowski
23 * Mods and rewrite by Robert Krawitz
27 /* Modified by Fred Pierresteguy on December 93
28 to make the popup menus and menubar use the Xt. */
30 /* Rewritten for clarity and GC protection by rms in Feb 94. */
32 /* On 4.3 this loses if it comes after xterm.h. */
38 #include "termhooks.h"
42 #include "blockinput.h"
51 /* This may include sys/types.h, and that somehow loses
52 if this is not done before the other system files. */
56 /* Load sys/types.h if not already loaded.
57 In some systems loading it twice is suicidal. */
59 #include <sys/types.h>
62 #include "dispextern.h"
67 #include <X11/IntrinsicP.h>
68 #include <X11/CoreP.h>
69 #include <X11/StringDefs.h>
70 #include <X11/Shell.h>
71 #include <X11/Xaw/Paned.h>
72 #include "../lwlib/lwlib.h"
73 #else /* not USE_X_TOOLKIT */
74 #include "../oldXMenu/XMenu.h"
75 #endif /* not USE_X_TOOLKIT */
76 #endif /* HAVE_X_WINDOWS */
78 #define min(x,y) (((x) < (y)) ? (x) : (y))
79 #define max(x,y) (((x) > (y)) ? (x) : (y))
86 Lisp_Object Qdebug_on_next_call
;
88 extern Lisp_Object Qmenu_enable
;
89 extern Lisp_Object Qmenu_bar
;
90 extern Lisp_Object Qmouse_click
, Qevent_kind
;
92 extern Lisp_Object Vdefine_key_rebound_commands
;
94 extern Lisp_Object Voverriding_local_map
;
95 extern Lisp_Object Voverriding_local_map_menu_flag
;
97 extern Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
99 extern Lisp_Object Qmenu_bar_update_hook
;
102 extern void set_frame_menubar ();
103 extern void process_expose_from_menu ();
104 extern XtAppContext Xt_app_con
;
106 static Lisp_Object
xdialog_show ();
107 void popup_get_selection ();
110 static Lisp_Object
xmenu_show ();
111 static void keymap_panes ();
112 static void single_keymap_panes ();
113 static void list_of_panes ();
114 static void list_of_items ();
116 /* This holds a Lisp vector that holds the results of decoding
117 the keymaps or alist-of-alists that specify a menu.
119 It describes the panes and items within the panes.
121 Each pane is described by 3 elements in the vector:
122 t, the pane name, the pane's prefix key.
123 Then follow the pane's items, with 5 elements per item:
124 the item string, the enable flag, the item's value,
125 the definition, and the equivalent keyboard key's description string.
127 In some cases, multiple levels of menus may be described.
128 A single vector slot containing nil indicates the start of a submenu.
129 A single vector slot containing lambda indicates the end of a submenu.
130 The submenu follows a menu item which is the way to reach the submenu.
132 A single vector slot containing quote indicates that the
133 following items should appear on the right of a dialog box.
135 Using a Lisp vector to hold this information while we decode it
136 takes care of protecting all the data from GC. */
138 #define MENU_ITEMS_PANE_NAME 1
139 #define MENU_ITEMS_PANE_PREFIX 2
140 #define MENU_ITEMS_PANE_LENGTH 3
142 #define MENU_ITEMS_ITEM_NAME 0
143 #define MENU_ITEMS_ITEM_ENABLE 1
144 #define MENU_ITEMS_ITEM_VALUE 2
145 #define MENU_ITEMS_ITEM_EQUIV_KEY 3
146 #define MENU_ITEMS_ITEM_DEFINITION 4
147 #define MENU_ITEMS_ITEM_LENGTH 5
149 static Lisp_Object menu_items
;
151 /* Number of slots currently allocated in menu_items. */
152 static int menu_items_allocated
;
154 /* This is the index in menu_items of the first empty slot. */
155 static int menu_items_used
;
157 /* The number of panes currently recorded in menu_items,
158 excluding those within submenus. */
159 static int menu_items_n_panes
;
161 /* Current depth within submenus. */
162 static int menu_items_submenu_depth
;
164 /* Flag which when set indicates a dialog or menu has been posted by
165 Xt on behalf of one of the widget sets. */
166 static int popup_activated_flag
;
168 static int next_menubar_widget_id
;
172 /* Return the frame whose ->output_data.x->id equals ID, or 0 if none. */
174 static struct frame
*
175 menubar_id_to_frame (id
)
178 Lisp_Object tail
, frame
;
181 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCONS (tail
)->cdr
)
183 frame
= XCONS (tail
)->car
;
184 if (!GC_FRAMEP (frame
))
187 if (f
->output_data
.nothing
== 1)
189 if (f
->output_data
.x
->id
== id
)
197 /* Initialize the menu_items structure if we haven't already done so.
198 Also mark it as currently empty. */
203 if (NILP (menu_items
))
205 menu_items_allocated
= 60;
206 menu_items
= Fmake_vector (make_number (menu_items_allocated
), Qnil
);
210 menu_items_n_panes
= 0;
211 menu_items_submenu_depth
= 0;
214 /* Call at the end of generating the data in menu_items.
215 This fills in the number of items in the last pane. */
222 /* Call when finished using the data for the current menu
226 discard_menu_items ()
228 /* Free the structure if it is especially large.
229 Otherwise, hold on to it, to save time. */
230 if (menu_items_allocated
> 200)
233 menu_items_allocated
= 0;
237 /* Make the menu_items vector twice as large. */
243 int old_size
= menu_items_allocated
;
246 menu_items_allocated
*= 2;
247 menu_items
= Fmake_vector (make_number (menu_items_allocated
), Qnil
);
248 bcopy (XVECTOR (old
)->contents
, XVECTOR (menu_items
)->contents
,
249 old_size
* sizeof (Lisp_Object
));
252 /* Begin a submenu. */
255 push_submenu_start ()
257 if (menu_items_used
+ 1 > menu_items_allocated
)
260 XVECTOR (menu_items
)->contents
[menu_items_used
++] = Qnil
;
261 menu_items_submenu_depth
++;
269 if (menu_items_used
+ 1 > menu_items_allocated
)
272 XVECTOR (menu_items
)->contents
[menu_items_used
++] = Qlambda
;
273 menu_items_submenu_depth
--;
276 /* Indicate boundary between left and right. */
279 push_left_right_boundary ()
281 if (menu_items_used
+ 1 > menu_items_allocated
)
284 XVECTOR (menu_items
)->contents
[menu_items_used
++] = Qquote
;
287 /* Start a new menu pane in menu_items..
288 NAME is the pane name. PREFIX_VEC is a prefix key for this pane. */
291 push_menu_pane (name
, prefix_vec
)
292 Lisp_Object name
, prefix_vec
;
294 if (menu_items_used
+ MENU_ITEMS_PANE_LENGTH
> menu_items_allocated
)
297 if (menu_items_submenu_depth
== 0)
298 menu_items_n_panes
++;
299 XVECTOR (menu_items
)->contents
[menu_items_used
++] = Qt
;
300 XVECTOR (menu_items
)->contents
[menu_items_used
++] = name
;
301 XVECTOR (menu_items
)->contents
[menu_items_used
++] = prefix_vec
;
304 /* Push one menu item into the current pane.
305 NAME is the string to display. ENABLE if non-nil means
306 this item can be selected. KEY is the key generated by
307 choosing this item, or nil if this item doesn't really have a definition.
308 DEF is the definition of this item.
309 EQUIV is the textual description of the keyboard equivalent for
310 this item (or nil if none). */
313 push_menu_item (name
, enable
, key
, def
, equiv
)
314 Lisp_Object name
, enable
, key
, def
, equiv
;
316 if (menu_items_used
+ MENU_ITEMS_ITEM_LENGTH
> menu_items_allocated
)
319 XVECTOR (menu_items
)->contents
[menu_items_used
++] = name
;
320 XVECTOR (menu_items
)->contents
[menu_items_used
++] = enable
;
321 XVECTOR (menu_items
)->contents
[menu_items_used
++] = key
;
322 XVECTOR (menu_items
)->contents
[menu_items_used
++] = equiv
;
323 XVECTOR (menu_items
)->contents
[menu_items_used
++] = def
;
326 /* Figure out the current keyboard equivalent of a menu item ITEM1.
327 The item string for menu display should be ITEM_STRING.
328 Store the equivalent keyboard key sequence's
329 textual description into *DESCRIP_PTR.
330 Also cache them in the item itself.
331 Return the real definition to execute. */
334 menu_item_equiv_key (item_string
, item1
, descrip_ptr
)
335 Lisp_Object item_string
;
337 Lisp_Object
*descrip_ptr
;
339 /* This is the real definition--the function to run. */
341 /* This is the sublist that records cached equiv key data
342 so we can save time. */
343 Lisp_Object cachelist
;
344 /* These are the saved equivalent keyboard key sequence
345 and its key-description. */
346 Lisp_Object savedkey
, descrip
;
349 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
351 /* If a help string follows the item string, skip it. */
352 if (CONSP (XCONS (item1
)->cdr
)
353 && STRINGP (XCONS (XCONS (item1
)->cdr
)->car
))
354 item1
= XCONS (item1
)->cdr
;
358 /* Get out the saved equivalent-keyboard-key info. */
359 cachelist
= savedkey
= descrip
= Qnil
;
360 if (CONSP (def
) && CONSP (XCONS (def
)->car
)
361 && (NILP (XCONS (XCONS (def
)->car
)->car
)
362 || VECTORP (XCONS (XCONS (def
)->car
)->car
)))
364 cachelist
= XCONS (def
)->car
;
365 def
= XCONS (def
)->cdr
;
366 savedkey
= XCONS (cachelist
)->car
;
367 descrip
= XCONS (cachelist
)->cdr
;
370 GCPRO4 (def
, def1
, savedkey
, descrip
);
372 /* Is it still valid? */
374 if (!NILP (savedkey
))
375 def1
= Fkey_binding (savedkey
, Qnil
);
376 /* If not, update it. */
378 /* If the command is an alias for another
379 (such as easymenu.el and lmenu.el set it up),
380 check if the original command matches the cached command. */
381 && !(SYMBOLP (def
) && SYMBOLP (XSYMBOL (def
)->function
)
382 && EQ (def1
, XSYMBOL (def
)->function
))
383 /* If something had no key binding before, don't recheck it
384 because that is too slow--except if we have a list of rebound
385 commands in Vdefine_key_rebound_commands, do recheck any command
386 that appears in that list. */
387 && (NILP (cachelist
) || !NILP (savedkey
)
388 || (! EQ (Qt
, Vdefine_key_rebound_commands
)
389 && !NILP (Fmemq (def
, Vdefine_key_rebound_commands
)))))
393 /* If the command is an alias for another
394 (such as easymenu.el and lmenu.el set it up),
395 see if the original command name has equivalent keys. */
396 if (SYMBOLP (def
) && SYMBOLP (XSYMBOL (def
)->function
))
397 savedkey
= Fwhere_is_internal (XSYMBOL (def
)->function
,
400 /* Otherwise look up the specified command itself.
401 We don't try both, because that makes easymenu menus slow. */
402 savedkey
= Fwhere_is_internal (def
, Qnil
, Qt
, Qnil
);
404 if (!NILP (savedkey
))
406 descrip
= Fkey_description (savedkey
);
407 descrip
= concat2 (make_string (" (", 3), descrip
);
408 descrip
= concat2 (descrip
, make_string (")", 1));
412 /* Cache the data we just got in a sublist of the menu binding. */
413 if (NILP (cachelist
))
415 CHECK_IMPURE (item1
);
416 XCONS (item1
)->cdr
= Fcons (Fcons (savedkey
, descrip
), def
);
420 XCONS (cachelist
)->car
= savedkey
;
421 XCONS (cachelist
)->cdr
= descrip
;
425 *descrip_ptr
= descrip
;
429 /* This is used as the handler when calling internal_condition_case_1. */
432 menu_item_enabled_p_1 (arg
)
435 /* If we got a quit from within the menu computation,
436 quit all the way out of it. This takes care of C-] in the debugger. */
437 if (CONSP (arg
) && EQ (XCONS (arg
)->car
, Qquit
))
438 Fsignal (Qquit
, Qnil
);
443 /* Return non-nil if the command DEF is enabled when used as a menu item.
444 This is based on looking for a menu-enable property.
445 If NOTREAL is set, don't bother really computing this. */
448 menu_item_enabled_p (def
, notreal
)
452 Lisp_Object enabled
, tem
;
459 /* No property, or nil, means enable.
460 Otherwise, enable if value is not nil. */
461 tem
= Fget (def
, Qmenu_enable
);
463 /* (condition-case nil (eval tem)
465 enabled
= internal_condition_case_1 (Feval
, tem
, Qerror
,
466 menu_item_enabled_p_1
);
471 /* Look through KEYMAPS, a vector of keymaps that is NMAPS long,
472 and generate menu panes for them in menu_items.
473 If NOTREAL is nonzero,
474 don't bother really computing whether an item is enabled. */
477 keymap_panes (keymaps
, nmaps
, notreal
)
478 Lisp_Object
*keymaps
;
486 /* Loop over the given keymaps, making a pane for each map.
487 But don't make a pane that is empty--ignore that map instead.
488 P is the number of panes we have made so far. */
489 for (mapno
= 0; mapno
< nmaps
; mapno
++)
490 single_keymap_panes (keymaps
[mapno
], Qnil
, Qnil
, notreal
);
492 finish_menu_items ();
495 /* This is a recursive subroutine of keymap_panes.
496 It handles one keymap, KEYMAP.
497 The other arguments are passed along
498 or point to local variables of the previous function.
499 If NOTREAL is nonzero,
500 don't bother really computing whether an item is enabled. */
503 single_keymap_panes (keymap
, pane_name
, prefix
, notreal
)
505 Lisp_Object pane_name
;
509 Lisp_Object pending_maps
;
510 Lisp_Object tail
, item
, item1
, item_string
, table
;
511 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
515 push_menu_pane (pane_name
, prefix
);
517 for (tail
= keymap
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
519 /* Look at each key binding, and if it has a menu string,
520 make a menu item from it. */
521 item
= XCONS (tail
)->car
;
524 item1
= XCONS (item
)->cdr
;
527 item_string
= XCONS (item1
)->car
;
528 if (STRINGP (item_string
))
530 /* This is the real definition--the function to run. */
532 /* These are the saved equivalent keyboard key sequence
533 and its key-description. */
535 Lisp_Object tem
, enabled
;
537 /* GCPRO because ...enabled_p will call eval
538 and ..._equiv_key may autoload something.
539 Protecting KEYMAP preserves everything we use;
540 aside from that, must protect whatever might be
541 a string. Since there's no GCPRO5, we refetch
542 item_string instead of protecting it. */
543 descrip
= def
= Qnil
;
544 GCPRO4 (keymap
, pending_maps
, def
, descrip
);
546 def
= menu_item_equiv_key (item_string
, item1
, &descrip
);
547 enabled
= menu_item_enabled_p (def
, notreal
);
551 item_string
= XCONS (item1
)->car
;
553 tem
= Fkeymapp (def
);
554 if (XSTRING (item_string
)->data
[0] == '@' && !NILP (tem
))
555 pending_maps
= Fcons (Fcons (def
, Fcons (item_string
, XCONS (item
)->car
)),
560 GCPRO4 (keymap
, pending_maps
, descrip
, item_string
);
561 submap
= get_keymap_1 (def
, 0, 1);
563 #ifndef USE_X_TOOLKIT
564 /* Indicate visually that this is a submenu. */
566 item_string
= concat2 (item_string
,
567 build_string (" >"));
569 /* If definition is nil, pass nil as the key. */
570 push_menu_item (item_string
, enabled
,
571 XCONS (item
)->car
, def
,
574 /* Display a submenu using the toolkit. */
577 push_submenu_start ();
578 single_keymap_panes (submap
, Qnil
,
579 XCONS (item
)->car
, notreal
);
587 else if (VECTORP (item
))
589 /* Loop over the char values represented in the vector. */
590 int len
= XVECTOR (item
)->size
;
592 for (c
= 0; c
< len
; c
++)
594 Lisp_Object character
;
595 XSETFASTINT (character
, c
);
596 item1
= XVECTOR (item
)->contents
[c
];
599 item_string
= XCONS (item1
)->car
;
600 if (STRINGP (item_string
))
604 /* These are the saved equivalent keyboard key sequence
605 and its key-description. */
607 Lisp_Object tem
, enabled
;
609 /* GCPRO because ...enabled_p will call eval
610 and ..._equiv_key may autoload something.
611 Protecting KEYMAP preserves everything we use;
612 aside from that, must protect whatever might be
613 a string. Since there's no GCPRO5, we refetch
614 item_string instead of protecting it. */
615 GCPRO4 (keymap
, pending_maps
, def
, descrip
);
616 descrip
= def
= Qnil
;
618 def
= menu_item_equiv_key (item_string
, item1
, &descrip
);
619 enabled
= menu_item_enabled_p (def
, notreal
);
623 item_string
= XCONS (item1
)->car
;
625 tem
= Fkeymapp (def
);
626 if (XSTRING (item_string
)->data
[0] == '@' && !NILP (tem
))
627 pending_maps
= Fcons (Fcons (def
, Fcons (item_string
, character
)),
632 GCPRO4 (keymap
, pending_maps
, descrip
, item_string
);
633 submap
= get_keymap_1 (def
, 0, 1);
635 #ifndef USE_X_TOOLKIT
637 item_string
= concat2 (item_string
,
638 build_string (" >"));
640 /* If definition is nil, pass nil as the key. */
641 push_menu_item (item_string
, enabled
, character
,
646 push_submenu_start ();
647 single_keymap_panes (submap
, Qnil
,
659 /* Process now any submenus which want to be panes at this level. */
660 while (!NILP (pending_maps
))
662 Lisp_Object elt
, eltcdr
, string
;
663 elt
= Fcar (pending_maps
);
664 eltcdr
= XCONS (elt
)->cdr
;
665 string
= XCONS (eltcdr
)->car
;
666 /* We no longer discard the @ from the beginning of the string here.
667 Instead, we do this in xmenu_show. */
668 single_keymap_panes (Fcar (elt
), string
,
669 XCONS (eltcdr
)->cdr
, notreal
);
670 pending_maps
= Fcdr (pending_maps
);
674 /* Push all the panes and items of a menu decsribed by the
675 alist-of-alists MENU.
676 This handles old-fashioned calls to x-popup-menu. */
686 for (tail
= menu
; !NILP (tail
); tail
= Fcdr (tail
))
688 Lisp_Object elt
, pane_name
, pane_data
;
690 pane_name
= Fcar (elt
);
691 CHECK_STRING (pane_name
, 0);
692 push_menu_pane (pane_name
, Qnil
);
693 pane_data
= Fcdr (elt
);
694 CHECK_CONS (pane_data
, 0);
695 list_of_items (pane_data
);
698 finish_menu_items ();
701 /* Push the items in a single pane defined by the alist PANE. */
707 Lisp_Object tail
, item
, item1
;
709 for (tail
= pane
; !NILP (tail
); tail
= Fcdr (tail
))
713 push_menu_item (item
, Qnil
, Qnil
, Qt
, Qnil
);
714 else if (NILP (item
))
715 push_left_right_boundary ();
718 CHECK_CONS (item
, 0);
720 CHECK_STRING (item1
, 1);
721 push_menu_item (item1
, Qt
, Fcdr (item
), Qt
, Qnil
);
726 DEFUN ("x-popup-menu", Fx_popup_menu
, Sx_popup_menu
, 2, 2, 0,
727 "Pop up a deck-of-cards menu and return user's selection.\n\
728 POSITION is a position specification. This is either a mouse button event\n\
729 or a list ((XOFFSET YOFFSET) WINDOW)\n\
730 where XOFFSET and YOFFSET are positions in pixels from the top left\n\
731 corner of WINDOW's frame. (WINDOW may be a frame object instead of a window.)\n\
732 This controls the position of the center of the first line\n\
733 in the first pane of the menu, not the top left of the menu as a whole.\n\
734 If POSITION is t, it means to use the current mouse position.\n\
736 MENU is a specifier for a menu. For the simplest case, MENU is a keymap.\n\
737 The menu items come from key bindings that have a menu string as well as\n\
738 a definition; actually, the \"definition\" in such a key binding looks like\n\
739 \(STRING . REAL-DEFINITION). To give the menu a title, put a string into\n\
740 the keymap as a top-level element.\n\n\
741 You can also use a list of keymaps as MENU.\n\
742 Then each keymap makes a separate pane.\n\
743 When MENU is a keymap or a list of keymaps, the return value\n\
744 is a list of events.\n\n\
745 Alternatively, you can specify a menu of multiple panes\n\
746 with a list of the form (TITLE PANE1 PANE2...),\n\
747 where each pane is a list of form (TITLE ITEM1 ITEM2...).\n\
748 Each ITEM is normally a cons cell (STRING . VALUE);\n\
749 but a string can appear as an item--that makes a nonselectable line\n\
751 With this form of menu, the return value is VALUE from the chosen item.\n\
753 If POSITION is nil, don't display the menu at all, just precalculate the\n\
754 cached information about equivalent key sequences.")
756 Lisp_Object position
, menu
;
758 int number_of_panes
, panes
;
759 Lisp_Object keymap
, tem
;
763 Lisp_Object selection
;
766 Lisp_Object x
, y
, window
;
771 if (! NILP (position
))
775 /* Decode the first argument: find the window and the coordinates. */
776 if (EQ (position
, Qt
)
777 || (CONSP (position
) && EQ (XCONS (position
)->car
, Qmenu_bar
)))
779 /* Use the mouse's current position. */
780 FRAME_PTR new_f
= selected_frame
;
781 Lisp_Object bar_window
;
785 if (mouse_position_hook
)
786 (*mouse_position_hook
) (&new_f
, 1, &bar_window
,
787 &part
, &x
, &y
, &time
);
789 XSETFRAME (window
, new_f
);
792 window
= selected_window
;
799 tem
= Fcar (position
);
802 window
= Fcar (Fcdr (position
));
804 y
= Fcar (Fcdr (tem
));
809 tem
= Fcar (Fcdr (position
)); /* EVENT_START (position) */
810 window
= Fcar (tem
); /* POSN_WINDOW (tem) */
811 tem
= Fcar (Fcdr (Fcdr (tem
))); /* POSN_WINDOW_POSN (tem) */
820 /* Decode where to put the menu. */
828 else if (WINDOWP (window
))
830 CHECK_LIVE_WINDOW (window
, 0);
831 f
= XFRAME (WINDOW_FRAME (XWINDOW (window
)));
833 xpos
= (FONT_WIDTH (f
->output_data
.x
->font
) * XWINDOW (window
)->left
);
834 ypos
= (f
->output_data
.x
->line_height
* XWINDOW (window
)->top
);
837 /* ??? Not really clean; should be CHECK_WINDOW_OR_FRAME,
838 but I don't want to make one now. */
839 CHECK_WINDOW (window
, 0);
848 /* Decode the menu items from what was specified. */
850 keymap
= Fkeymapp (menu
);
853 tem
= Fkeymapp (Fcar (menu
));
856 /* We were given a keymap. Extract menu info from the keymap. */
858 keymap
= get_keymap (menu
);
860 /* Extract the detailed info to make one pane. */
861 keymap_panes (&menu
, 1, NILP (position
));
863 /* Search for a string appearing directly as an element of the keymap.
864 That string is the title of the menu. */
865 prompt
= map_prompt (keymap
);
867 /* Make that be the pane title of the first pane. */
868 if (!NILP (prompt
) && menu_items_n_panes
>= 0)
869 XVECTOR (menu_items
)->contents
[MENU_ITEMS_PANE_NAME
] = prompt
;
873 else if (!NILP (tem
))
875 /* We were given a list of keymaps. */
876 int nmaps
= XFASTINT (Flength (menu
));
878 = (Lisp_Object
*) alloca (nmaps
* sizeof (Lisp_Object
));
883 /* The first keymap that has a prompt string
884 supplies the menu title. */
885 for (tem
= menu
, i
= 0; CONSP (tem
); tem
= Fcdr (tem
))
889 maps
[i
++] = keymap
= get_keymap (Fcar (tem
));
891 prompt
= map_prompt (keymap
);
892 if (NILP (title
) && !NILP (prompt
))
896 /* Extract the detailed info to make one pane. */
897 keymap_panes (maps
, nmaps
, NILP (position
));
899 /* Make the title be the pane title of the first pane. */
900 if (!NILP (title
) && menu_items_n_panes
>= 0)
901 XVECTOR (menu_items
)->contents
[MENU_ITEMS_PANE_NAME
] = title
;
907 /* We were given an old-fashioned menu. */
909 CHECK_STRING (title
, 1);
911 list_of_panes (Fcdr (menu
));
918 discard_menu_items ();
923 /* Display them in a menu. */
926 selection
= xmenu_show (f
, xpos
, ypos
, for_click
,
927 keymaps
, title
, &error_name
);
930 discard_menu_items ();
934 if (error_name
) error (error_name
);
938 DEFUN ("x-popup-dialog", Fx_popup_dialog
, Sx_popup_dialog
, 2, 2, 0,
939 "Pop up a dialog box and return user's selection.\n\
940 POSITION specifies which frame to use.\n\
941 This is normally a mouse button event or a window or frame.\n\
942 If POSITION is t, it means to use the frame the mouse is on.\n\
943 The dialog box appears in the middle of the specified frame.\n\
945 CONTENTS specifies the alternatives to display in the dialog box.\n\
946 It is a list of the form (TITLE ITEM1 ITEM2...).\n\
947 Each ITEM is a cons cell (STRING . VALUE).\n\
948 The return value is VALUE from the chosen item.\n\n\
949 An ITEM may also be just a string--that makes a nonselectable item.\n\
950 An ITEM may also be nil--that means to put all preceding items\n\
951 on the left of the dialog box and all following items on the right.\n\
952 \(By default, approximately half appear on each side.)")
954 Lisp_Object position
, contents
;
961 /* Decode the first argument: find the window or frame to use. */
962 if (EQ (position
, Qt
)
963 || (CONSP (position
) && EQ (XCONS (position
)->car
, Qmenu_bar
)))
965 #if 0 /* Using the frame the mouse is on may not be right. */
966 /* Use the mouse's current position. */
967 FRAME_PTR new_f
= selected_frame
;
968 Lisp_Object bar_window
;
973 (*mouse_position_hook
) (&new_f
, 1, &bar_window
, &part
, &x
, &y
, &time
);
976 XSETFRAME (window
, new_f
);
978 window
= selected_window
;
980 window
= selected_window
;
982 else if (CONSP (position
))
985 tem
= Fcar (position
);
987 window
= Fcar (Fcdr (position
));
990 tem
= Fcar (Fcdr (position
)); /* EVENT_START (position) */
991 window
= Fcar (tem
); /* POSN_WINDOW (tem) */
994 else if (WINDOWP (position
) || FRAMEP (position
))
997 /* Decode where to put the menu. */
1000 f
= XFRAME (window
);
1001 else if (WINDOWP (window
))
1003 CHECK_LIVE_WINDOW (window
, 0);
1004 f
= XFRAME (WINDOW_FRAME (XWINDOW (window
)));
1007 /* ??? Not really clean; should be CHECK_WINDOW_OR_FRAME,
1008 but I don't want to make one now. */
1009 CHECK_WINDOW (window
, 0);
1011 #ifndef USE_X_TOOLKIT
1012 /* Display a menu with these alternatives
1013 in the middle of frame F. */
1015 Lisp_Object x
, y
, frame
, newpos
;
1016 XSETFRAME (frame
, f
);
1017 XSETINT (x
, x_pixel_width (f
) / 2);
1018 XSETINT (y
, x_pixel_height (f
) / 2);
1019 newpos
= Fcons (Fcons (x
, Fcons (y
, Qnil
)), Fcons (frame
, Qnil
));
1021 return Fx_popup_menu (newpos
,
1022 Fcons (Fcar (contents
), Fcons (contents
, Qnil
)));
1028 Lisp_Object selection
;
1030 /* Decode the dialog items from what was specified. */
1031 title
= Fcar (contents
);
1032 CHECK_STRING (title
, 1);
1034 list_of_panes (Fcons (contents
, Qnil
));
1036 /* Display them in a dialog box. */
1038 selection
= xdialog_show (f
, 0, title
, &error_name
);
1041 discard_menu_items ();
1043 if (error_name
) error (error_name
);
1049 #ifdef USE_X_TOOLKIT
1051 /* Loop in Xt until the menu pulldown or dialog popup has been
1052 popped down (deactivated).
1054 NOTE: All calls to popup_get_selection should be protected
1055 with BLOCK_INPUT, UNBLOCK_INPUT wrappers. */
1058 popup_get_selection (initial_event
, dpyinfo
, id
)
1059 XEvent
*initial_event
;
1060 struct x_display_info
*dpyinfo
;
1065 /* Define a queue to save up for later unreading
1066 all X events that don't pertain to the menu. */
1070 struct event_queue
*next
;
1073 struct event_queue
*queue
= NULL
;
1074 struct event_queue
*queue_tmp
;
1077 event
= *initial_event
;
1079 XtAppNextEvent (Xt_app_con
, &event
);
1083 /* Handle expose events for editor frames right away. */
1084 if (event
.type
== Expose
)
1085 process_expose_from_menu (event
);
1086 /* Make sure we don't consider buttons grabbed after menu goes. */
1087 else if (event
.type
== ButtonRelease
1088 && dpyinfo
->display
== event
.xbutton
.display
)
1089 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
1090 /* If the user presses a key, deactivate the menu.
1091 The user is likely to do that if we get wedged. */
1092 else if (event
.type
== KeyPress
1093 && dpyinfo
->display
== event
.xbutton
.display
)
1095 popup_activated_flag
= 0;
1099 /* Queue all events not for this popup,
1100 except for Expose, which we've already handled.
1101 Note that the X window is associated with the frame if this
1102 is a menu bar popup, but not if it's a dialog box. So we use
1103 x_non_menubar_window_to_frame, not x_any_window_to_frame. */
1104 if (event
.type
!= Expose
1105 && (event
.xany
.display
!= dpyinfo
->display
1106 || x_non_menubar_window_to_frame (dpyinfo
, event
.xany
.window
)))
1108 queue_tmp
= (struct event_queue
*) malloc (sizeof (struct event_queue
));
1110 if (queue_tmp
!= NULL
)
1112 queue_tmp
->event
= event
;
1113 queue_tmp
->next
= queue
;
1118 XtDispatchEvent (&event
);
1120 if (!popup_activated ())
1122 XtAppNextEvent (Xt_app_con
, &event
);
1125 /* Unread any events that we got but did not handle. */
1126 while (queue
!= NULL
)
1129 XPutBackEvent (queue_tmp
->event
.xany
.display
, &queue_tmp
->event
);
1130 queue
= queue_tmp
->next
;
1131 free ((char *)queue_tmp
);
1132 /* Cause these events to get read as soon as we UNBLOCK_INPUT. */
1133 interrupt_input_pending
= 1;
1137 /* Activate the menu bar of frame F.
1138 This is called from keyboard.c when it gets the
1139 menu_bar_activate_event out of the Emacs event queue.
1141 To activate the menu bar, we use the X button-press event
1142 that was saved in saved_button_event.
1143 That makes the toolkit do its thing.
1145 But first we recompute the menu bar contents (the whole tree).
1147 The reason for saving the button event until here, instead of
1148 passing it to the toolkit right away, is that we can safely
1149 execute Lisp code. */
1151 x_activate_menubar (f
)
1154 if (f
->output_data
.x
->saved_button_event
->type
!= ButtonPress
)
1157 set_frame_menubar (f
, 0, 1);
1160 XtDispatchEvent ((XEvent
*) f
->output_data
.x
->saved_button_event
);
1163 /* Ignore this if we get it a second time. */
1164 f
->output_data
.x
->saved_button_event
->type
= 0;
1167 /* Detect if a dialog or menu has been posted. */
1172 return popup_activated_flag
;
1176 /* This callback is invoked when the user selects a menubar cascade
1177 pushbutton, but before the pulldown menu is posted. */
1180 popup_activate_callback (widget
, id
, client_data
)
1183 XtPointer client_data
;
1185 popup_activated_flag
= 1;
1188 /* This callback is called from the menu bar pulldown menu
1189 when the user makes a selection.
1190 Figure out what the user chose
1191 and put the appropriate events into the keyboard buffer. */
1194 menubar_selection_callback (widget
, id
, client_data
)
1197 XtPointer client_data
;
1199 Lisp_Object prefix
, entry
;
1200 FRAME_PTR f
= menubar_id_to_frame (id
);
1202 Lisp_Object
*subprefix_stack
;
1203 int submenu_depth
= 0;
1208 subprefix_stack
= (Lisp_Object
*) alloca (f
->menu_bar_items_used
* sizeof (Lisp_Object
));
1209 vector
= f
->menu_bar_vector
;
1212 while (i
< f
->menu_bar_items_used
)
1214 if (EQ (XVECTOR (vector
)->contents
[i
], Qnil
))
1216 subprefix_stack
[submenu_depth
++] = prefix
;
1220 else if (EQ (XVECTOR (vector
)->contents
[i
], Qlambda
))
1222 prefix
= subprefix_stack
[--submenu_depth
];
1225 else if (EQ (XVECTOR (vector
)->contents
[i
], Qt
))
1227 prefix
= XVECTOR (vector
)->contents
[i
+ MENU_ITEMS_PANE_PREFIX
];
1228 i
+= MENU_ITEMS_PANE_LENGTH
;
1232 entry
= XVECTOR (vector
)->contents
[i
+ MENU_ITEMS_ITEM_VALUE
];
1233 /* The EMACS_INT cast avoids a warning. There's no problem
1234 as long as pointers have enough bits to hold small integers. */
1235 if ((int) (EMACS_INT
) client_data
== i
)
1238 struct input_event buf
;
1241 XSETFRAME (frame
, f
);
1242 buf
.kind
= menu_bar_event
;
1243 buf
.frame_or_window
= Fcons (frame
, Fcons (Qmenu_bar
, Qnil
));
1244 kbd_buffer_store_event (&buf
);
1246 for (j
= 0; j
< submenu_depth
; j
++)
1247 if (!NILP (subprefix_stack
[j
]))
1249 buf
.kind
= menu_bar_event
;
1250 buf
.frame_or_window
= Fcons (frame
, subprefix_stack
[j
]);
1251 kbd_buffer_store_event (&buf
);
1256 buf
.kind
= menu_bar_event
;
1257 buf
.frame_or_window
= Fcons (frame
, prefix
);
1258 kbd_buffer_store_event (&buf
);
1261 buf
.kind
= menu_bar_event
;
1262 buf
.frame_or_window
= Fcons (frame
, entry
);
1263 kbd_buffer_store_event (&buf
);
1267 i
+= MENU_ITEMS_ITEM_LENGTH
;
1272 /* This callback is invoked when a dialog or menu is finished being
1273 used and has been unposted. */
1276 popup_deactivate_callback (widget
, id
, client_data
)
1279 XtPointer client_data
;
1281 popup_activated_flag
= 0;
1285 /* This recursively calls free_widget_value on the tree of widgets.
1286 It must free all data that was malloc'ed for these widget_values.
1287 In Emacs, many slots are pointers into the data of Lisp_Strings, and
1288 must be left alone. */
1291 free_menubar_widget_value_tree (wv
)
1296 wv
->name
= wv
->value
= wv
->key
= (char *) 0xDEADBEEF;
1298 if (wv
->contents
&& (wv
->contents
!= (widget_value
*)1))
1300 free_menubar_widget_value_tree (wv
->contents
);
1301 wv
->contents
= (widget_value
*) 0xDEADBEEF;
1305 free_menubar_widget_value_tree (wv
->next
);
1306 wv
->next
= (widget_value
*) 0xDEADBEEF;
1309 free_widget_value (wv
);
1313 /* Return a tree of widget_value structures for a menu bar item
1314 whose event type is ITEM_KEY (with string ITEM_NAME)
1315 and whose contents come from the list of keymaps MAPS. */
1317 static widget_value
*
1318 single_submenu (item_key
, item_name
, maps
)
1319 Lisp_Object item_key
, item_name
, maps
;
1321 widget_value
*wv
, *prev_wv
, *save_wv
, *first_wv
;
1323 int submenu_depth
= 0;
1326 Lisp_Object
*mapvec
;
1327 widget_value
**submenu_stack
;
1329 int previous_items
= menu_items_used
;
1330 int top_level_items
= 0;
1332 length
= Flength (maps
);
1333 len
= XINT (length
);
1335 /* Convert the list MAPS into a vector MAPVEC. */
1336 mapvec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
1337 for (i
= 0; i
< len
; i
++)
1339 mapvec
[i
] = Fcar (maps
);
1343 menu_items_n_panes
= 0;
1345 /* Loop over the given keymaps, making a pane for each map.
1346 But don't make a pane that is empty--ignore that map instead. */
1347 for (i
= 0; i
< len
; i
++)
1349 if (SYMBOLP (mapvec
[i
]))
1351 top_level_items
= 1;
1352 push_menu_pane (Qnil
, Qnil
);
1353 push_menu_item (item_name
, Qt
, item_key
, mapvec
[i
], Qnil
);
1356 single_keymap_panes (mapvec
[i
], item_name
, item_key
, 0);
1359 /* Create a tree of widget_value objects
1360 representing the panes and their items. */
1363 = (widget_value
**) alloca (menu_items_used
* sizeof (widget_value
*));
1364 wv
= malloc_widget_value ();
1372 /* Loop over all panes and items made during this call
1373 and construct a tree of widget_value objects.
1374 Ignore the panes and items made by previous calls to
1375 single_submenu, even though those are also in menu_items. */
1377 while (i
< menu_items_used
)
1379 if (EQ (XVECTOR (menu_items
)->contents
[i
], Qnil
))
1381 submenu_stack
[submenu_depth
++] = save_wv
;
1386 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qlambda
))
1389 save_wv
= submenu_stack
[--submenu_depth
];
1392 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qt
)
1393 && submenu_depth
!= 0)
1394 i
+= MENU_ITEMS_PANE_LENGTH
;
1395 /* Ignore a nil in the item list.
1396 It's meaningful only for dialog boxes. */
1397 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qquote
))
1399 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qt
))
1401 /* Create a new pane. */
1402 Lisp_Object pane_name
, prefix
;
1404 pane_name
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_PANE_NAME
];
1405 prefix
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_PANE_PREFIX
];
1406 pane_string
= (NILP (pane_name
)
1407 ? "" : (char *) XSTRING (pane_name
)->data
);
1408 /* If there is just one top-level pane, put all its items directly
1409 under the top-level menu. */
1410 if (menu_items_n_panes
== 1)
1413 /* If the pane has a meaningful name,
1414 make the pane a top-level menu item
1415 with its items as a submenu beneath it. */
1416 if (strcmp (pane_string
, ""))
1418 wv
= malloc_widget_value ();
1422 first_wv
->contents
= wv
;
1423 wv
->name
= pane_string
;
1424 /* Ignore the @ that means "separate pane".
1425 This is a kludge, but this isn't worth more time. */
1426 if (!NILP (prefix
) && wv
->name
[0] == '@')
1433 i
+= MENU_ITEMS_PANE_LENGTH
;
1437 /* Create a new item within current pane. */
1438 Lisp_Object item_name
, enable
, descrip
, def
;
1439 item_name
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_NAME
];
1440 enable
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_ENABLE
];
1442 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_EQUIV_KEY
];
1443 def
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_DEFINITION
];
1445 wv
= malloc_widget_value ();
1449 save_wv
->contents
= wv
;
1451 wv
->name
= (char *) XSTRING (item_name
)->data
;
1452 if (!NILP (descrip
))
1453 wv
->key
= (char *) XSTRING (descrip
)->data
;
1455 /* The EMACS_INT cast avoids a warning. There's no problem
1456 as long as pointers have enough bits to hold small integers. */
1457 wv
->call_data
= (!NILP (def
) ? (void *) (EMACS_INT
) i
: 0);
1458 wv
->enabled
= !NILP (enable
);
1461 i
+= MENU_ITEMS_ITEM_LENGTH
;
1465 /* If we have just one "menu item"
1466 that was originally a button, return it by itself. */
1467 if (top_level_items
&& first_wv
->contents
&& first_wv
->contents
->next
== 0)
1469 wv
= first_wv
->contents
;
1470 free_widget_value (first_wv
);
1477 extern void EmacsFrameSetCharSize ();
1479 /* Recompute all the widgets of frame F, when the menu bar
1480 has been changed. */
1483 update_frame_menubar (f
)
1486 struct x_output
*x
= f
->output_data
.x
;
1488 int menubar_changed
;
1490 Dimension shell_height
;
1492 /* We assume the menubar contents has changed if the global flag is set,
1493 or if the current buffer has changed, or if the menubar has never
1494 been updated before.
1496 menubar_changed
= (x
->menubar_widget
1497 && !XtIsManaged (x
->menubar_widget
));
1499 if (! (menubar_changed
))
1503 /* Save the size of the frame because the pane widget doesn't accept to
1504 resize itself. So force it. */
1508 /* Do the voodoo which means "I'm changing lots of things, don't try to
1509 refigure sizes until I'm done." */
1510 lw_refigure_widget (x
->column_widget
, False
);
1512 /* the order in which children are managed is the top to
1513 bottom order in which they are displayed in the paned window.
1514 First, remove the text-area widget.
1516 XtUnmanageChild (x
->edit_widget
);
1518 /* remove the menubar that is there now, and put up the menubar that
1521 if (menubar_changed
)
1523 XtManageChild (x
->menubar_widget
);
1524 XtMapWidget (x
->menubar_widget
);
1525 XtVaSetValues (x
->menubar_widget
, XtNmappedWhenManaged
, 1, 0);
1528 /* Re-manage the text-area widget, and then thrash the sizes. */
1529 XtManageChild (x
->edit_widget
);
1530 lw_refigure_widget (x
->column_widget
, True
);
1532 /* Force the pane widget to resize itself with the right values. */
1533 EmacsFrameSetCharSize (x
->edit_widget
, columns
, rows
);
1538 /* Set the contents of the menubar widgets of frame F.
1539 The argument FIRST_TIME is currently ignored;
1540 it is set the first time this is called, from initialize_frame_menubar. */
1543 set_frame_menubar (f
, first_time
, deep_p
)
1548 Widget menubar_widget
= f
->output_data
.x
->menubar_widget
;
1549 Lisp_Object tail
, items
, frame
;
1550 widget_value
*wv
, *first_wv
, *prev_wv
= 0;
1554 if (f
->output_data
.x
->id
== 0)
1555 f
->output_data
.x
->id
= next_menubar_widget_id
++;
1556 id
= f
->output_data
.x
->id
;
1558 if (! menubar_widget
)
1561 wv
= malloc_widget_value ();
1562 wv
->name
= "menubar";
1569 /* Make a widget-value tree representing the entire menu trees. */
1571 struct buffer
*prev
= current_buffer
;
1573 int specpdl_count
= specpdl_ptr
- specpdl
;
1574 int previous_menu_items_used
= f
->menu_bar_items_used
;
1575 Lisp_Object
*previous_items
1576 = (Lisp_Object
*) alloca (previous_menu_items_used
1577 * sizeof (Lisp_Object
));
1579 buffer
= XWINDOW (FRAME_SELECTED_WINDOW (f
))->buffer
;
1580 specbind (Qinhibit_quit
, Qt
);
1581 /* Don't let the debugger step into this code
1582 because it is not reentrant. */
1583 specbind (Qdebug_on_next_call
, Qnil
);
1585 record_unwind_protect (Fstore_match_data
, Fmatch_data ());
1586 if (NILP (Voverriding_local_map_menu_flag
))
1588 specbind (Qoverriding_terminal_local_map
, Qnil
);
1589 specbind (Qoverriding_local_map
, Qnil
);
1592 set_buffer_internal_1 (XBUFFER (buffer
));
1594 /* Run the Lucid hook. */
1595 call1 (Vrun_hooks
, Qactivate_menubar_hook
);
1596 /* If it has changed current-menubar from previous value,
1597 really recompute the menubar from the value. */
1598 if (! NILP (Vlucid_menu_bar_dirty_flag
))
1599 call0 (Qrecompute_lucid_menubar
);
1600 call1 (Vrun_hooks
, Qmenu_bar_update_hook
);
1601 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
1603 items
= FRAME_MENU_BAR_ITEMS (f
);
1605 inhibit_garbage_collection ();
1607 /* Save the frame's previous menu bar contents data. */
1608 bcopy (XVECTOR (f
->menu_bar_vector
)->contents
, previous_items
,
1609 previous_menu_items_used
* sizeof (Lisp_Object
));
1611 /* Fill in the current menu bar contents. */
1612 menu_items
= f
->menu_bar_vector
;
1613 menu_items_allocated
= XVECTOR (menu_items
)->size
;
1615 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 3)
1617 Lisp_Object key
, string
, maps
;
1619 key
= XVECTOR (items
)->contents
[i
];
1620 string
= XVECTOR (items
)->contents
[i
+ 1];
1621 maps
= XVECTOR (items
)->contents
[i
+ 2];
1625 wv
= single_submenu (key
, string
, maps
);
1629 first_wv
->contents
= wv
;
1630 /* Don't set wv->name here; GC during the loop might relocate it. */
1635 finish_menu_items ();
1637 set_buffer_internal_1 (prev
);
1638 unbind_to (specpdl_count
, Qnil
);
1640 /* If there has been no change in the Lisp-level contents
1641 of the menu bar, skip redisplaying it. Just exit. */
1643 for (i
= 0; i
< previous_menu_items_used
; i
++)
1644 if (menu_items_used
== i
1645 || (previous_items
[i
] != XVECTOR (menu_items
)->contents
[i
]))
1647 if (i
== menu_items_used
&& i
== previous_menu_items_used
)
1649 free_menubar_widget_value_tree (first_wv
);
1655 /* Now GC cannot happen during the lifetime of the widget_value,
1656 so it's safe to store data from a Lisp_String. */
1657 wv
= first_wv
->contents
;
1658 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 3)
1661 string
= XVECTOR (items
)->contents
[i
+ 1];
1664 wv
->name
= (char *) XSTRING (string
)->data
;
1668 f
->menu_bar_vector
= menu_items
;
1669 f
->menu_bar_items_used
= menu_items_used
;
1674 /* Make a widget-value tree containing
1675 just the top level menu bar strings. */
1677 items
= FRAME_MENU_BAR_ITEMS (f
);
1678 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 3)
1682 string
= XVECTOR (items
)->contents
[i
+ 1];
1686 wv
= malloc_widget_value ();
1687 wv
->name
= (char *) XSTRING (string
)->data
;
1694 first_wv
->contents
= wv
;
1699 /* Create or update the menu bar widget. */
1705 /* Disable resizing (done for Motif!) */
1706 lw_allow_resizing (f
->output_data
.x
->widget
, False
);
1708 /* The third arg is DEEP_P, which says to consider the entire
1709 menu trees we supply, rather than just the menu bar item names. */
1710 lw_modify_all_widgets (id
, first_wv
, deep_p
);
1712 /* Re-enable the edit widget to resize. */
1713 lw_allow_resizing (f
->output_data
.x
->widget
, True
);
1717 menubar_widget
= lw_create_widget ("menubar", "menubar", id
, first_wv
,
1718 f
->output_data
.x
->column_widget
,
1720 popup_activate_callback
,
1721 menubar_selection_callback
,
1722 popup_deactivate_callback
);
1723 f
->output_data
.x
->menubar_widget
= menubar_widget
;
1728 = (f
->output_data
.x
->menubar_widget
1729 ? (f
->output_data
.x
->menubar_widget
->core
.height
1730 + f
->output_data
.x
->menubar_widget
->core
.border_width
)
1733 if (FRAME_EXTERNAL_MENU_BAR (f
))
1736 XtVaGetValues (f
->output_data
.x
->column_widget
,
1737 XtNinternalBorderWidth
, &ibw
, NULL
);
1738 menubar_size
+= ibw
;
1741 f
->output_data
.x
->menubar_height
= menubar_size
;
1744 free_menubar_widget_value_tree (first_wv
);
1746 update_frame_menubar (f
);
1751 /* Called from Fx_create_frame to create the inital menubar of a frame
1752 before it is mapped, so that the window is mapped with the menubar already
1753 there instead of us tacking it on later and thrashing the window after it
1757 initialize_frame_menubar (f
)
1760 /* This function is called before the first chance to redisplay
1761 the frame. It has to be, so the frame will have the right size. */
1762 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
1763 set_frame_menubar (f
, 1, 1);
1766 /* Get rid of the menu bar of frame F, and free its storage.
1767 This is used when deleting a frame, and when turning off the menu bar. */
1770 free_frame_menubar (f
)
1773 Widget menubar_widget
;
1776 menubar_widget
= f
->output_data
.x
->menubar_widget
;
1781 lw_destroy_all_widgets ((LWLIB_ID
) f
->output_data
.x
->id
);
1786 #endif /* USE_X_TOOLKIT */
1788 /* xmenu_show actually displays a menu using the panes and items in menu_items
1789 and returns the value selected from it.
1790 There are two versions of xmenu_show, one for Xt and one for Xlib.
1791 Both assume input is blocked by the caller. */
1793 /* F is the frame the menu is for.
1794 X and Y are the frame-relative specified position,
1795 relative to the inside upper left corner of the frame F.
1796 FOR_CLICK if this menu was invoked for a mouse click.
1797 KEYMAPS is 1 if this menu was specified with keymaps;
1798 in that case, we return a list containing the chosen item's value
1799 and perhaps also the pane's prefix.
1800 TITLE is the specified menu title.
1801 ERROR is a place to store an error message string in case of failure.
1802 (We return nil on failure, but the value doesn't actually matter.) */
1804 #ifdef USE_X_TOOLKIT
1806 /* We need a unique id for each widget handled by the Lucid Widget
1809 For the main windows, and popup menus, we use this counter,
1810 which we increment each time after use. This starts from 1<<16.
1812 For menu bars, we use numbers starting at 0, counted in
1813 next_menubar_widget_id. */
1814 LWLIB_ID widget_id_tick
;
1817 static Lisp_Object
*volatile menu_item_selection
;
1819 static Lisp_Object
*menu_item_selection
;
1823 popup_selection_callback (widget
, id
, client_data
)
1826 XtPointer client_data
;
1828 menu_item_selection
= (Lisp_Object
*) client_data
;
1832 xmenu_show (f
, x
, y
, for_click
, keymaps
, title
, error
)
1846 widget_value
*wv
, *save_wv
= 0, *first_wv
= 0, *prev_wv
= 0;
1847 widget_value
**submenu_stack
1848 = (widget_value
**) alloca (menu_items_used
* sizeof (widget_value
*));
1849 Lisp_Object
*subprefix_stack
1850 = (Lisp_Object
*) alloca (menu_items_used
* sizeof (Lisp_Object
));
1851 int submenu_depth
= 0;
1852 XButtonPressedEvent dummy
;
1855 int next_release_must_exit
= 0;
1859 if (menu_items_used
<= MENU_ITEMS_PANE_LENGTH
)
1861 *error
= "Empty menu";
1865 /* Create a tree of widget_value objects
1866 representing the panes and their items. */
1867 wv
= malloc_widget_value ();
1874 /* Loop over all panes and items, filling in the tree. */
1876 while (i
< menu_items_used
)
1878 if (EQ (XVECTOR (menu_items
)->contents
[i
], Qnil
))
1880 submenu_stack
[submenu_depth
++] = save_wv
;
1886 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qlambda
))
1889 save_wv
= submenu_stack
[--submenu_depth
];
1893 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qt
)
1894 && submenu_depth
!= 0)
1895 i
+= MENU_ITEMS_PANE_LENGTH
;
1896 /* Ignore a nil in the item list.
1897 It's meaningful only for dialog boxes. */
1898 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qquote
))
1900 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qt
))
1902 /* Create a new pane. */
1903 Lisp_Object pane_name
, prefix
;
1905 pane_name
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_PANE_NAME
];
1906 prefix
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_PANE_PREFIX
];
1907 pane_string
= (NILP (pane_name
)
1908 ? "" : (char *) XSTRING (pane_name
)->data
);
1909 /* If there is just one top-level pane, put all its items directly
1910 under the top-level menu. */
1911 if (menu_items_n_panes
== 1)
1914 /* If the pane has a meaningful name,
1915 make the pane a top-level menu item
1916 with its items as a submenu beneath it. */
1917 if (!keymaps
&& strcmp (pane_string
, ""))
1919 wv
= malloc_widget_value ();
1923 first_wv
->contents
= wv
;
1924 wv
->name
= pane_string
;
1925 if (keymaps
&& !NILP (prefix
))
1932 else if (first_pane
)
1938 i
+= MENU_ITEMS_PANE_LENGTH
;
1942 /* Create a new item within current pane. */
1943 Lisp_Object item_name
, enable
, descrip
, def
;
1944 item_name
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_NAME
];
1945 enable
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_ENABLE
];
1947 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_EQUIV_KEY
];
1948 def
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_DEFINITION
];
1950 wv
= malloc_widget_value ();
1954 save_wv
->contents
= wv
;
1955 wv
->name
= (char *) XSTRING (item_name
)->data
;
1956 if (!NILP (descrip
))
1957 wv
->key
= (char *) XSTRING (descrip
)->data
;
1959 /* If this item has a null value,
1960 make the call_data null so that it won't display a box
1961 when the mouse is on it. */
1963 = (!NILP (def
) ? (void *) &XVECTOR (menu_items
)->contents
[i
] : 0);
1964 wv
->enabled
= !NILP (enable
);
1967 i
+= MENU_ITEMS_ITEM_LENGTH
;
1971 /* Deal with the title, if it is non-nil. */
1974 widget_value
*wv_title
= malloc_widget_value ();
1975 widget_value
*wv_sep1
= malloc_widget_value ();
1976 widget_value
*wv_sep2
= malloc_widget_value ();
1978 wv_sep2
->name
= "--";
1979 wv_sep2
->next
= first_wv
->contents
;
1981 wv_sep1
->name
= "--";
1982 wv_sep1
->next
= wv_sep2
;
1984 wv_title
->name
= (char *) XSTRING (title
)->data
;
1985 wv_title
->enabled
= True
;
1986 wv_title
->next
= wv_sep1
;
1987 first_wv
->contents
= wv_title
;
1990 /* Actually create the menu. */
1991 menu_id
= widget_id_tick
++;
1992 menu
= lw_create_widget ("popup", first_wv
->name
, menu_id
, first_wv
,
1993 f
->output_data
.x
->widget
, 1, 0,
1994 popup_selection_callback
,
1995 popup_deactivate_callback
);
1997 /* Adjust coordinates to relative to the outer (window manager) window. */
2000 int win_x
= 0, win_y
= 0;
2002 /* Find the position of the outside upper-left corner of
2003 the inner window, with respect to the outer window. */
2004 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
2007 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
2009 /* From-window, to-window. */
2010 f
->output_data
.x
->window_desc
,
2011 f
->output_data
.x
->parent_desc
,
2013 /* From-position, to-position. */
2014 0, 0, &win_x
, &win_y
,
2016 /* Child of window. */
2024 /* Adjust coordinates to be root-window-relative. */
2025 x
+= f
->output_data
.x
->left_pos
;
2026 y
+= f
->output_data
.x
->top_pos
;
2028 dummy
.type
= ButtonPress
;
2030 dummy
.send_event
= 0;
2031 dummy
.display
= FRAME_X_DISPLAY (f
);
2032 dummy
.time
= CurrentTime
;
2034 dummy
.root
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
2035 dummy
.window
= dummy
.root
;
2036 dummy
.subwindow
= dummy
.root
;
2042 /* Don't allow any geometry request from the user. */
2043 XtSetArg (av
[ac
], XtNgeometry
, 0); ac
++;
2044 XtSetValues (menu
, av
, ac
);
2046 /* Free the widget_value objects we used to specify the contents. */
2047 free_menubar_widget_value_tree (first_wv
);
2049 /* No selection has been chosen yet. */
2050 menu_item_selection
= 0;
2052 /* Display the menu. */
2053 lw_popup_menu (menu
, &dummy
);
2054 popup_activated_flag
= 1;
2056 /* Process events that apply to the menu. */
2057 popup_get_selection ((XEvent
*) 0, FRAME_X_DISPLAY_INFO (f
), menu_id
);
2059 /* fp turned off the following statement and wrote a comment
2060 that it is unnecessary--that the menu has already disappeared.
2061 Nowadays the menu disappears ok, all right, but
2062 we need to delete the widgets or multiple ones will pile up. */
2063 lw_destroy_all_widgets (menu_id
);
2065 /* Find the selected item, and its pane, to return
2066 the proper value. */
2067 if (menu_item_selection
!= 0)
2069 Lisp_Object prefix
, entry
;
2073 while (i
< menu_items_used
)
2075 if (EQ (XVECTOR (menu_items
)->contents
[i
], Qnil
))
2077 subprefix_stack
[submenu_depth
++] = prefix
;
2081 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qlambda
))
2083 prefix
= subprefix_stack
[--submenu_depth
];
2086 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qt
))
2089 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_PANE_PREFIX
];
2090 i
+= MENU_ITEMS_PANE_LENGTH
;
2095 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_VALUE
];
2096 if (menu_item_selection
== &XVECTOR (menu_items
)->contents
[i
])
2102 entry
= Fcons (entry
, Qnil
);
2104 entry
= Fcons (prefix
, entry
);
2105 for (j
= submenu_depth
- 1; j
>= 0; j
--)
2106 if (!NILP (subprefix_stack
[j
]))
2107 entry
= Fcons (subprefix_stack
[j
], entry
);
2111 i
+= MENU_ITEMS_ITEM_LENGTH
;
2120 dialog_selection_callback (widget
, id
, client_data
)
2123 XtPointer client_data
;
2125 /* The EMACS_INT cast avoids a warning. There's no problem
2126 as long as pointers have enough bits to hold small integers. */
2127 if ((int) (EMACS_INT
) client_data
!= -1)
2128 menu_item_selection
= (Lisp_Object
*) client_data
;
2130 lw_destroy_all_widgets (id
);
2132 popup_activated_flag
= 0;
2135 static char * button_names
[] = {
2136 "button1", "button2", "button3", "button4", "button5",
2137 "button6", "button7", "button8", "button9", "button10" };
2140 xdialog_show (f
, keymaps
, title
, error
)
2146 int i
, nb_buttons
=0;
2149 char dialog_name
[6];
2151 widget_value
*wv
, *save_wv
= 0, *first_wv
= 0, *prev_wv
= 0;
2153 /* Number of elements seen so far, before boundary. */
2155 /* 1 means we've seen the boundary between left-hand elts and right-hand. */
2156 int boundary_seen
= 0;
2160 if (menu_items_n_panes
> 1)
2162 *error
= "Multiple panes in dialog box";
2166 /* Create a tree of widget_value objects
2167 representing the text label and buttons. */
2169 Lisp_Object pane_name
, prefix
;
2171 pane_name
= XVECTOR (menu_items
)->contents
[MENU_ITEMS_PANE_NAME
];
2172 prefix
= XVECTOR (menu_items
)->contents
[MENU_ITEMS_PANE_PREFIX
];
2173 pane_string
= (NILP (pane_name
)
2174 ? "" : (char *) XSTRING (pane_name
)->data
);
2175 prev_wv
= malloc_widget_value ();
2176 prev_wv
->value
= pane_string
;
2177 if (keymaps
&& !NILP (prefix
))
2179 prev_wv
->enabled
= 1;
2180 prev_wv
->name
= "message";
2183 /* Loop over all panes and items, filling in the tree. */
2184 i
= MENU_ITEMS_PANE_LENGTH
;
2185 while (i
< menu_items_used
)
2188 /* Create a new item within current pane. */
2189 Lisp_Object item_name
, enable
, descrip
;
2190 item_name
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_NAME
];
2191 enable
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_ENABLE
];
2193 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_EQUIV_KEY
];
2195 if (NILP (item_name
))
2197 free_menubar_widget_value_tree (first_wv
);
2198 *error
= "Submenu in dialog items";
2201 if (EQ (item_name
, Qquote
))
2203 /* This is the boundary between left-side elts
2204 and right-side elts. Stop incrementing right_count. */
2209 if (nb_buttons
>= 10)
2211 free_menubar_widget_value_tree (first_wv
);
2212 *error
= "Too many dialog items";
2216 wv
= malloc_widget_value ();
2218 wv
->name
= (char *) button_names
[nb_buttons
];
2219 if (!NILP (descrip
))
2220 wv
->key
= (char *) XSTRING (descrip
)->data
;
2221 wv
->value
= (char *) XSTRING (item_name
)->data
;
2222 wv
->call_data
= (void *) &XVECTOR (menu_items
)->contents
[i
];
2223 wv
->enabled
= !NILP (enable
);
2226 if (! boundary_seen
)
2230 i
+= MENU_ITEMS_ITEM_LENGTH
;
2233 /* If the boundary was not specified,
2234 by default put half on the left and half on the right. */
2235 if (! boundary_seen
)
2236 left_count
= nb_buttons
- nb_buttons
/ 2;
2238 wv
= malloc_widget_value ();
2239 wv
->name
= dialog_name
;
2241 /* Dialog boxes use a really stupid name encoding
2242 which specifies how many buttons to use
2243 and how many buttons are on the right.
2244 The Q means something also. */
2245 dialog_name
[0] = 'Q';
2246 dialog_name
[1] = '0' + nb_buttons
;
2247 dialog_name
[2] = 'B';
2248 dialog_name
[3] = 'R';
2249 /* Number of buttons to put on the right. */
2250 dialog_name
[4] = '0' + nb_buttons
- left_count
;
2252 wv
->contents
= first_wv
;
2256 /* Actually create the dialog. */
2257 dialog_id
= widget_id_tick
++;
2258 menu
= lw_create_widget (first_wv
->name
, "dialog", dialog_id
, first_wv
,
2259 f
->output_data
.x
->widget
, 1, 0,
2260 dialog_selection_callback
, 0);
2261 lw_modify_all_widgets (dialog_id
, first_wv
->contents
, True
);
2262 /* Free the widget_value objects we used to specify the contents. */
2263 free_menubar_widget_value_tree (first_wv
);
2265 /* No selection has been chosen yet. */
2266 menu_item_selection
= 0;
2268 /* Display the menu. */
2269 lw_pop_up_all_widgets (dialog_id
);
2270 popup_activated_flag
= 1;
2272 /* Process events that apply to the menu. */
2273 popup_get_selection ((XEvent
*) 0, FRAME_X_DISPLAY_INFO (f
), dialog_id
);
2275 lw_destroy_all_widgets (dialog_id
);
2277 /* Find the selected item, and its pane, to return
2278 the proper value. */
2279 if (menu_item_selection
!= 0)
2285 while (i
< menu_items_used
)
2289 if (EQ (XVECTOR (menu_items
)->contents
[i
], Qt
))
2292 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_PANE_PREFIX
];
2293 i
+= MENU_ITEMS_PANE_LENGTH
;
2298 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_VALUE
];
2299 if (menu_item_selection
== &XVECTOR (menu_items
)->contents
[i
])
2303 entry
= Fcons (entry
, Qnil
);
2305 entry
= Fcons (prefix
, entry
);
2309 i
+= MENU_ITEMS_ITEM_LENGTH
;
2316 #else /* not USE_X_TOOLKIT */
2319 xmenu_show (f
, x
, y
, for_click
, keymaps
, title
, error
)
2329 int pane
, selidx
, lpane
, status
;
2330 Lisp_Object entry
, pane_prefix
;
2332 int ulx
, uly
, width
, height
;
2333 int dispwidth
, dispheight
;
2337 unsigned int dummy_uint
;
2340 if (menu_items_n_panes
== 0)
2343 if (menu_items_used
<= MENU_ITEMS_PANE_LENGTH
)
2345 *error
= "Empty menu";
2349 /* Figure out which root window F is on. */
2350 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &root
,
2351 &dummy_int
, &dummy_int
, &dummy_uint
, &dummy_uint
,
2352 &dummy_uint
, &dummy_uint
);
2354 /* Make the menu on that window. */
2355 menu
= XMenuCreate (FRAME_X_DISPLAY (f
), root
, "emacs");
2358 *error
= "Can't create menu";
2362 #ifdef HAVE_X_WINDOWS
2363 /* Adjust coordinates to relative to the outer (window manager) window. */
2366 int win_x
= 0, win_y
= 0;
2368 /* Find the position of the outside upper-left corner of
2369 the inner window, with respect to the outer window. */
2370 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
2373 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
2375 /* From-window, to-window. */
2376 f
->output_data
.x
->window_desc
,
2377 f
->output_data
.x
->parent_desc
,
2379 /* From-position, to-position. */
2380 0, 0, &win_x
, &win_y
,
2382 /* Child of window. */
2389 #endif /* HAVE_X_WINDOWS */
2391 /* Adjust coordinates to be root-window-relative. */
2392 x
+= f
->output_data
.x
->left_pos
;
2393 y
+= f
->output_data
.x
->top_pos
;
2395 /* Create all the necessary panes and their items. */
2397 while (i
< menu_items_used
)
2399 if (EQ (XVECTOR (menu_items
)->contents
[i
], Qt
))
2401 /* Create a new pane. */
2402 Lisp_Object pane_name
, prefix
;
2405 pane_name
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_PANE_NAME
];
2406 prefix
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_PANE_PREFIX
];
2407 pane_string
= (NILP (pane_name
)
2408 ? "" : (char *) XSTRING (pane_name
)->data
);
2409 if (keymaps
&& !NILP (prefix
))
2412 lpane
= XMenuAddPane (FRAME_X_DISPLAY (f
), menu
, pane_string
, TRUE
);
2413 if (lpane
== XM_FAILURE
)
2415 XMenuDestroy (FRAME_X_DISPLAY (f
), menu
);
2416 *error
= "Can't create pane";
2419 i
+= MENU_ITEMS_PANE_LENGTH
;
2421 /* Find the width of the widest item in this pane. */
2424 while (j
< menu_items_used
)
2427 item
= XVECTOR (menu_items
)->contents
[j
];
2435 width
= XSTRING (item
)->size
;
2436 if (width
> maxwidth
)
2439 j
+= MENU_ITEMS_ITEM_LENGTH
;
2442 /* Ignore a nil in the item list.
2443 It's meaningful only for dialog boxes. */
2444 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qquote
))
2448 /* Create a new item within current pane. */
2449 Lisp_Object item_name
, enable
, descrip
;
2450 unsigned char *item_data
;
2452 item_name
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_NAME
];
2453 enable
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_ENABLE
];
2455 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_EQUIV_KEY
];
2456 if (!NILP (descrip
))
2458 int gap
= maxwidth
- XSTRING (item_name
)->size
;
2461 spacer
= Fmake_string (make_number (gap
), make_number (' '));
2462 item_name
= concat2 (item_name
, spacer
);
2463 item_name
= concat2 (item_name
, descrip
);
2464 item_data
= XSTRING (item_name
)->data
;
2466 /* if alloca is fast, use that to make the space,
2467 to reduce gc needs. */
2469 = (unsigned char *) alloca (maxwidth
2470 + XSTRING (descrip
)->size
+ 1);
2471 bcopy (XSTRING (item_name
)->data
, item_data
,
2472 XSTRING (item_name
)->size
);
2473 for (j
= XSTRING (item_name
)->size
; j
< maxwidth
; j
++)
2475 bcopy (XSTRING (descrip
)->data
, item_data
+ j
,
2476 XSTRING (descrip
)->size
);
2477 item_data
[j
+ XSTRING (descrip
)->size
] = 0;
2481 item_data
= XSTRING (item_name
)->data
;
2483 if (XMenuAddSelection (FRAME_X_DISPLAY (f
),
2484 menu
, lpane
, 0, item_data
,
2488 XMenuDestroy (FRAME_X_DISPLAY (f
), menu
);
2489 *error
= "Can't add selection to menu";
2492 i
+= MENU_ITEMS_ITEM_LENGTH
;
2496 /* All set and ready to fly. */
2497 XMenuRecompute (FRAME_X_DISPLAY (f
), menu
);
2498 dispwidth
= DisplayWidth (FRAME_X_DISPLAY (f
),
2499 XScreenNumberOfScreen (FRAME_X_SCREEN (f
)));
2500 dispheight
= DisplayHeight (FRAME_X_DISPLAY (f
),
2501 XScreenNumberOfScreen (FRAME_X_SCREEN (f
)));
2502 x
= min (x
, dispwidth
);
2503 y
= min (y
, dispheight
);
2506 XMenuLocate (FRAME_X_DISPLAY (f
), menu
, 0, 0, x
, y
,
2507 &ulx
, &uly
, &width
, &height
);
2508 if (ulx
+width
> dispwidth
)
2510 x
-= (ulx
+ width
) - dispwidth
;
2511 ulx
= dispwidth
- width
;
2513 if (uly
+height
> dispheight
)
2515 y
-= (uly
+ height
) - dispheight
;
2516 uly
= dispheight
- height
;
2518 if (ulx
< 0) x
-= ulx
;
2519 if (uly
< 0) y
-= uly
;
2521 XMenuSetAEQ (menu
, TRUE
);
2522 XMenuSetFreeze (menu
, TRUE
);
2525 status
= XMenuActivate (FRAME_X_DISPLAY (f
), menu
, &pane
, &selidx
,
2526 x
, y
, ButtonReleaseMask
, &datap
);
2529 #ifdef HAVE_X_WINDOWS
2530 /* Assume the mouse has moved out of the X window.
2531 If it has actually moved in, we will get an EnterNotify. */
2532 x_mouse_leave (FRAME_X_DISPLAY_INFO (f
));
2539 fprintf (stderr
, "pane= %d line = %d\n", panes
, selidx
);
2542 /* Find the item number SELIDX in pane number PANE. */
2544 while (i
< menu_items_used
)
2546 if (EQ (XVECTOR (menu_items
)->contents
[i
], Qt
))
2550 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_PANE_PREFIX
];
2552 i
+= MENU_ITEMS_PANE_LENGTH
;
2561 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_VALUE
];
2564 entry
= Fcons (entry
, Qnil
);
2565 if (!NILP (pane_prefix
))
2566 entry
= Fcons (pane_prefix
, entry
);
2572 i
+= MENU_ITEMS_ITEM_LENGTH
;
2578 *error
= "Can't activate menu";
2584 XMenuDestroy (FRAME_X_DISPLAY (f
), menu
);
2586 #ifdef HAVE_X_WINDOWS
2587 /* State that no mouse buttons are now held.
2588 (The oldXMenu code doesn't track this info for us.)
2589 That is not necessarily true, but the fiction leads to reasonable
2590 results, and it is a pain to ask which are actually held now. */
2591 FRAME_X_DISPLAY_INFO (f
)->grabbed
= 0;
2597 #endif /* not USE_X_TOOLKIT */
2601 staticpro (&menu_items
);
2604 Qdebug_on_next_call
= intern ("debug-on-next-call");
2605 staticpro (&Qdebug_on_next_call
);
2607 #ifdef USE_X_TOOLKIT
2608 widget_id_tick
= (1<<16);
2609 next_menubar_widget_id
= 1;
2612 defsubr (&Sx_popup_menu
);
2613 defsubr (&Sx_popup_dialog
);