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>
72 #include <X11/Xaw/Paned.h>
73 #endif /* USE_LUCID */
74 #include "../lwlib/lwlib.h"
75 #else /* not USE_X_TOOLKIT */
76 #include "../oldXMenu/XMenu.h"
77 #endif /* not USE_X_TOOLKIT */
78 #endif /* HAVE_X_WINDOWS */
80 #define min(x,y) (((x) < (y)) ? (x) : (y))
81 #define max(x,y) (((x) > (y)) ? (x) : (y))
88 Lisp_Object Qdebug_on_next_call
;
90 extern Lisp_Object Qmenu_enable
;
91 extern Lisp_Object Qmenu_bar
;
92 extern Lisp_Object Qmouse_click
, Qevent_kind
;
94 extern Lisp_Object Vdefine_key_rebound_commands
;
96 extern Lisp_Object Voverriding_local_map
;
97 extern Lisp_Object Voverriding_local_map_menu_flag
;
99 extern Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
101 extern Lisp_Object Qmenu_bar_update_hook
;
104 extern void set_frame_menubar ();
105 extern void process_expose_from_menu ();
106 extern XtAppContext Xt_app_con
;
108 static Lisp_Object
xdialog_show ();
109 void popup_get_selection ();
112 static Lisp_Object
xmenu_show ();
113 static void keymap_panes ();
114 static void single_keymap_panes ();
115 static void list_of_panes ();
116 static void list_of_items ();
118 /* This holds a Lisp vector that holds the results of decoding
119 the keymaps or alist-of-alists that specify a menu.
121 It describes the panes and items within the panes.
123 Each pane is described by 3 elements in the vector:
124 t, the pane name, the pane's prefix key.
125 Then follow the pane's items, with 5 elements per item:
126 the item string, the enable flag, the item's value,
127 the definition, and the equivalent keyboard key's description string.
129 In some cases, multiple levels of menus may be described.
130 A single vector slot containing nil indicates the start of a submenu.
131 A single vector slot containing lambda indicates the end of a submenu.
132 The submenu follows a menu item which is the way to reach the submenu.
134 A single vector slot containing quote indicates that the
135 following items should appear on the right of a dialog box.
137 Using a Lisp vector to hold this information while we decode it
138 takes care of protecting all the data from GC. */
140 #define MENU_ITEMS_PANE_NAME 1
141 #define MENU_ITEMS_PANE_PREFIX 2
142 #define MENU_ITEMS_PANE_LENGTH 3
144 #define MENU_ITEMS_ITEM_NAME 0
145 #define MENU_ITEMS_ITEM_ENABLE 1
146 #define MENU_ITEMS_ITEM_VALUE 2
147 #define MENU_ITEMS_ITEM_EQUIV_KEY 3
148 #define MENU_ITEMS_ITEM_DEFINITION 4
149 #define MENU_ITEMS_ITEM_LENGTH 5
151 static Lisp_Object menu_items
;
153 /* Number of slots currently allocated in menu_items. */
154 static int menu_items_allocated
;
156 /* This is the index in menu_items of the first empty slot. */
157 static int menu_items_used
;
159 /* The number of panes currently recorded in menu_items,
160 excluding those within submenus. */
161 static int menu_items_n_panes
;
163 /* Current depth within submenus. */
164 static int menu_items_submenu_depth
;
166 /* Flag which when set indicates a dialog or menu has been posted by
167 Xt on behalf of one of the widget sets. */
168 static int popup_activated_flag
;
170 static int next_menubar_widget_id
;
174 /* Return the frame whose ->output_data.x->id equals ID, or 0 if none. */
176 static struct frame
*
177 menubar_id_to_frame (id
)
180 Lisp_Object tail
, frame
;
183 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCONS (tail
)->cdr
)
185 frame
= XCONS (tail
)->car
;
186 if (!GC_FRAMEP (frame
))
189 if (f
->output_data
.nothing
== 1)
191 if (f
->output_data
.x
->id
== id
)
199 /* Initialize the menu_items structure if we haven't already done so.
200 Also mark it as currently empty. */
205 if (NILP (menu_items
))
207 menu_items_allocated
= 60;
208 menu_items
= Fmake_vector (make_number (menu_items_allocated
), Qnil
);
212 menu_items_n_panes
= 0;
213 menu_items_submenu_depth
= 0;
216 /* Call at the end of generating the data in menu_items.
217 This fills in the number of items in the last pane. */
224 /* Call when finished using the data for the current menu
228 discard_menu_items ()
230 /* Free the structure if it is especially large.
231 Otherwise, hold on to it, to save time. */
232 if (menu_items_allocated
> 200)
235 menu_items_allocated
= 0;
239 /* Make the menu_items vector twice as large. */
245 int old_size
= menu_items_allocated
;
248 menu_items_allocated
*= 2;
249 menu_items
= Fmake_vector (make_number (menu_items_allocated
), Qnil
);
250 bcopy (XVECTOR (old
)->contents
, XVECTOR (menu_items
)->contents
,
251 old_size
* sizeof (Lisp_Object
));
254 /* Begin a submenu. */
257 push_submenu_start ()
259 if (menu_items_used
+ 1 > menu_items_allocated
)
262 XVECTOR (menu_items
)->contents
[menu_items_used
++] = Qnil
;
263 menu_items_submenu_depth
++;
271 if (menu_items_used
+ 1 > menu_items_allocated
)
274 XVECTOR (menu_items
)->contents
[menu_items_used
++] = Qlambda
;
275 menu_items_submenu_depth
--;
278 /* Indicate boundary between left and right. */
281 push_left_right_boundary ()
283 if (menu_items_used
+ 1 > menu_items_allocated
)
286 XVECTOR (menu_items
)->contents
[menu_items_used
++] = Qquote
;
289 /* Start a new menu pane in menu_items..
290 NAME is the pane name. PREFIX_VEC is a prefix key for this pane. */
293 push_menu_pane (name
, prefix_vec
)
294 Lisp_Object name
, prefix_vec
;
296 if (menu_items_used
+ MENU_ITEMS_PANE_LENGTH
> menu_items_allocated
)
299 if (menu_items_submenu_depth
== 0)
300 menu_items_n_panes
++;
301 XVECTOR (menu_items
)->contents
[menu_items_used
++] = Qt
;
302 XVECTOR (menu_items
)->contents
[menu_items_used
++] = name
;
303 XVECTOR (menu_items
)->contents
[menu_items_used
++] = prefix_vec
;
306 /* Push one menu item into the current pane.
307 NAME is the string to display. ENABLE if non-nil means
308 this item can be selected. KEY is the key generated by
309 choosing this item, or nil if this item doesn't really have a definition.
310 DEF is the definition of this item.
311 EQUIV is the textual description of the keyboard equivalent for
312 this item (or nil if none). */
315 push_menu_item (name
, enable
, key
, def
, equiv
)
316 Lisp_Object name
, enable
, key
, def
, equiv
;
318 if (menu_items_used
+ MENU_ITEMS_ITEM_LENGTH
> menu_items_allocated
)
321 XVECTOR (menu_items
)->contents
[menu_items_used
++] = name
;
322 XVECTOR (menu_items
)->contents
[menu_items_used
++] = enable
;
323 XVECTOR (menu_items
)->contents
[menu_items_used
++] = key
;
324 XVECTOR (menu_items
)->contents
[menu_items_used
++] = equiv
;
325 XVECTOR (menu_items
)->contents
[menu_items_used
++] = def
;
328 /* Figure out the current keyboard equivalent of a menu item ITEM1.
329 The item string for menu display should be ITEM_STRING.
330 Store the equivalent keyboard key sequence's
331 textual description into *DESCRIP_PTR.
332 Also cache them in the item itself.
333 Return the real definition to execute. */
336 menu_item_equiv_key (item_string
, item1
, descrip_ptr
)
337 Lisp_Object item_string
;
339 Lisp_Object
*descrip_ptr
;
341 /* This is the real definition--the function to run. */
343 /* This is the sublist that records cached equiv key data
344 so we can save time. */
345 Lisp_Object cachelist
;
346 /* These are the saved equivalent keyboard key sequence
347 and its key-description. */
348 Lisp_Object savedkey
, descrip
;
351 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
353 /* If a help string follows the item string, skip it. */
354 if (CONSP (XCONS (item1
)->cdr
)
355 && STRINGP (XCONS (XCONS (item1
)->cdr
)->car
))
356 item1
= XCONS (item1
)->cdr
;
360 /* Get out the saved equivalent-keyboard-key info. */
361 cachelist
= savedkey
= descrip
= Qnil
;
362 if (CONSP (def
) && CONSP (XCONS (def
)->car
)
363 && (NILP (XCONS (XCONS (def
)->car
)->car
)
364 || VECTORP (XCONS (XCONS (def
)->car
)->car
)))
366 cachelist
= XCONS (def
)->car
;
367 def
= XCONS (def
)->cdr
;
368 savedkey
= XCONS (cachelist
)->car
;
369 descrip
= XCONS (cachelist
)->cdr
;
372 GCPRO4 (def
, def1
, savedkey
, descrip
);
374 /* Is it still valid? */
376 if (!NILP (savedkey
))
377 def1
= Fkey_binding (savedkey
, Qnil
);
378 /* If not, update it. */
380 /* If the command is an alias for another
381 (such as easymenu.el and lmenu.el set it up),
382 check if the original command matches the cached command. */
383 && !(SYMBOLP (def
) && SYMBOLP (XSYMBOL (def
)->function
)
384 && EQ (def1
, XSYMBOL (def
)->function
))
385 /* If something had no key binding before, don't recheck it
386 because that is too slow--except if we have a list of rebound
387 commands in Vdefine_key_rebound_commands, do recheck any command
388 that appears in that list. */
389 && (NILP (cachelist
) || !NILP (savedkey
)
390 || (! EQ (Qt
, Vdefine_key_rebound_commands
)
391 && !NILP (Fmemq (def
, Vdefine_key_rebound_commands
)))))
395 /* If the command is an alias for another
396 (such as easymenu.el and lmenu.el set it up),
397 see if the original command name has equivalent keys. */
398 if (SYMBOLP (def
) && SYMBOLP (XSYMBOL (def
)->function
))
399 savedkey
= Fwhere_is_internal (XSYMBOL (def
)->function
,
402 /* Otherwise look up the specified command itself.
403 We don't try both, because that makes easymenu menus slow. */
404 savedkey
= Fwhere_is_internal (def
, Qnil
, Qt
, Qnil
);
406 if (!NILP (savedkey
))
408 descrip
= Fkey_description (savedkey
);
409 descrip
= concat2 (make_string (" (", 3), descrip
);
410 descrip
= concat2 (descrip
, make_string (")", 1));
414 /* Cache the data we just got in a sublist of the menu binding. */
415 if (NILP (cachelist
))
417 CHECK_IMPURE (item1
);
418 XCONS (item1
)->cdr
= Fcons (Fcons (savedkey
, descrip
), def
);
422 XCONS (cachelist
)->car
= savedkey
;
423 XCONS (cachelist
)->cdr
= descrip
;
427 *descrip_ptr
= descrip
;
431 /* This is used as the handler when calling internal_condition_case_1. */
434 menu_item_enabled_p_1 (arg
)
437 /* If we got a quit from within the menu computation,
438 quit all the way out of it. This takes care of C-] in the debugger. */
439 if (CONSP (arg
) && EQ (XCONS (arg
)->car
, Qquit
))
440 Fsignal (Qquit
, Qnil
);
445 /* Return non-nil if the command DEF is enabled when used as a menu item.
446 This is based on looking for a menu-enable property.
447 If NOTREAL is set, don't bother really computing this. */
450 menu_item_enabled_p (def
, notreal
)
454 Lisp_Object enabled
, tem
;
461 /* No property, or nil, means enable.
462 Otherwise, enable if value is not nil. */
463 tem
= Fget (def
, Qmenu_enable
);
465 /* (condition-case nil (eval tem)
467 enabled
= internal_condition_case_1 (Feval
, tem
, Qerror
,
468 menu_item_enabled_p_1
);
473 /* Look through KEYMAPS, a vector of keymaps that is NMAPS long,
474 and generate menu panes for them in menu_items.
475 If NOTREAL is nonzero,
476 don't bother really computing whether an item is enabled. */
479 keymap_panes (keymaps
, nmaps
, notreal
)
480 Lisp_Object
*keymaps
;
488 /* Loop over the given keymaps, making a pane for each map.
489 But don't make a pane that is empty--ignore that map instead.
490 P is the number of panes we have made so far. */
491 for (mapno
= 0; mapno
< nmaps
; mapno
++)
492 single_keymap_panes (keymaps
[mapno
], Qnil
, Qnil
, notreal
);
494 finish_menu_items ();
497 /* This is a recursive subroutine of keymap_panes.
498 It handles one keymap, KEYMAP.
499 The other arguments are passed along
500 or point to local variables of the previous function.
501 If NOTREAL is nonzero,
502 don't bother really computing whether an item is enabled. */
505 single_keymap_panes (keymap
, pane_name
, prefix
, notreal
)
507 Lisp_Object pane_name
;
511 Lisp_Object pending_maps
;
512 Lisp_Object tail
, item
, item1
, item_string
, table
;
513 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
517 push_menu_pane (pane_name
, prefix
);
519 for (tail
= keymap
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
521 /* Look at each key binding, and if it has a menu string,
522 make a menu item from it. */
523 item
= XCONS (tail
)->car
;
526 item1
= XCONS (item
)->cdr
;
529 item_string
= XCONS (item1
)->car
;
530 if (STRINGP (item_string
))
532 /* This is the real definition--the function to run. */
534 /* These are the saved equivalent keyboard key sequence
535 and its key-description. */
537 Lisp_Object tem
, enabled
;
539 /* GCPRO because ...enabled_p will call eval
540 and ..._equiv_key may autoload something.
541 Protecting KEYMAP preserves everything we use;
542 aside from that, must protect whatever might be
543 a string. Since there's no GCPRO5, we refetch
544 item_string instead of protecting it. */
545 descrip
= def
= Qnil
;
546 GCPRO4 (keymap
, pending_maps
, def
, descrip
);
548 def
= menu_item_equiv_key (item_string
, item1
, &descrip
);
549 enabled
= menu_item_enabled_p (def
, notreal
);
553 item_string
= XCONS (item1
)->car
;
555 tem
= Fkeymapp (def
);
556 if (XSTRING (item_string
)->data
[0] == '@' && !NILP (tem
))
557 pending_maps
= Fcons (Fcons (def
, Fcons (item_string
, XCONS (item
)->car
)),
562 GCPRO4 (keymap
, pending_maps
, descrip
, item_string
);
563 submap
= get_keymap_1 (def
, 0, 1);
565 #ifndef USE_X_TOOLKIT
566 /* Indicate visually that this is a submenu. */
568 item_string
= concat2 (item_string
,
569 build_string (" >"));
571 /* If definition is nil, pass nil as the key. */
572 push_menu_item (item_string
, enabled
,
573 XCONS (item
)->car
, def
,
576 /* Display a submenu using the toolkit. */
579 push_submenu_start ();
580 single_keymap_panes (submap
, Qnil
,
581 XCONS (item
)->car
, notreal
);
589 else if (VECTORP (item
))
591 /* Loop over the char values represented in the vector. */
592 int len
= XVECTOR (item
)->size
;
594 for (c
= 0; c
< len
; c
++)
596 Lisp_Object character
;
597 XSETFASTINT (character
, c
);
598 item1
= XVECTOR (item
)->contents
[c
];
601 item_string
= XCONS (item1
)->car
;
602 if (STRINGP (item_string
))
606 /* These are the saved equivalent keyboard key sequence
607 and its key-description. */
609 Lisp_Object tem
, enabled
;
611 /* GCPRO because ...enabled_p will call eval
612 and ..._equiv_key may autoload something.
613 Protecting KEYMAP preserves everything we use;
614 aside from that, must protect whatever might be
615 a string. Since there's no GCPRO5, we refetch
616 item_string instead of protecting it. */
617 GCPRO4 (keymap
, pending_maps
, def
, descrip
);
618 descrip
= def
= Qnil
;
620 def
= menu_item_equiv_key (item_string
, item1
, &descrip
);
621 enabled
= menu_item_enabled_p (def
, notreal
);
625 item_string
= XCONS (item1
)->car
;
627 tem
= Fkeymapp (def
);
628 if (XSTRING (item_string
)->data
[0] == '@' && !NILP (tem
))
629 pending_maps
= Fcons (Fcons (def
, Fcons (item_string
, character
)),
634 GCPRO4 (keymap
, pending_maps
, descrip
, item_string
);
635 submap
= get_keymap_1 (def
, 0, 1);
637 #ifndef USE_X_TOOLKIT
639 item_string
= concat2 (item_string
,
640 build_string (" >"));
642 /* If definition is nil, pass nil as the key. */
643 push_menu_item (item_string
, enabled
, character
,
648 push_submenu_start ();
649 single_keymap_panes (submap
, Qnil
,
661 /* Process now any submenus which want to be panes at this level. */
662 while (!NILP (pending_maps
))
664 Lisp_Object elt
, eltcdr
, string
;
665 elt
= Fcar (pending_maps
);
666 eltcdr
= XCONS (elt
)->cdr
;
667 string
= XCONS (eltcdr
)->car
;
668 /* We no longer discard the @ from the beginning of the string here.
669 Instead, we do this in xmenu_show. */
670 single_keymap_panes (Fcar (elt
), string
,
671 XCONS (eltcdr
)->cdr
, notreal
);
672 pending_maps
= Fcdr (pending_maps
);
676 /* Push all the panes and items of a menu decsribed by the
677 alist-of-alists MENU.
678 This handles old-fashioned calls to x-popup-menu. */
688 for (tail
= menu
; !NILP (tail
); tail
= Fcdr (tail
))
690 Lisp_Object elt
, pane_name
, pane_data
;
692 pane_name
= Fcar (elt
);
693 CHECK_STRING (pane_name
, 0);
694 push_menu_pane (pane_name
, Qnil
);
695 pane_data
= Fcdr (elt
);
696 CHECK_CONS (pane_data
, 0);
697 list_of_items (pane_data
);
700 finish_menu_items ();
703 /* Push the items in a single pane defined by the alist PANE. */
709 Lisp_Object tail
, item
, item1
;
711 for (tail
= pane
; !NILP (tail
); tail
= Fcdr (tail
))
715 push_menu_item (item
, Qnil
, Qnil
, Qt
, Qnil
);
716 else if (NILP (item
))
717 push_left_right_boundary ();
720 CHECK_CONS (item
, 0);
722 CHECK_STRING (item1
, 1);
723 push_menu_item (item1
, Qt
, Fcdr (item
), Qt
, Qnil
);
728 DEFUN ("x-popup-menu", Fx_popup_menu
, Sx_popup_menu
, 2, 2, 0,
729 "Pop up a deck-of-cards menu and return user's selection.\n\
730 POSITION is a position specification. This is either a mouse button event\n\
731 or a list ((XOFFSET YOFFSET) WINDOW)\n\
732 where XOFFSET and YOFFSET are positions in pixels from the top left\n\
733 corner of WINDOW's frame. (WINDOW may be a frame object instead of a window.)\n\
734 This controls the position of the center of the first line\n\
735 in the first pane of the menu, not the top left of the menu as a whole.\n\
736 If POSITION is t, it means to use the current mouse position.\n\
738 MENU is a specifier for a menu. For the simplest case, MENU is a keymap.\n\
739 The menu items come from key bindings that have a menu string as well as\n\
740 a definition; actually, the \"definition\" in such a key binding looks like\n\
741 \(STRING . REAL-DEFINITION). To give the menu a title, put a string into\n\
742 the keymap as a top-level element.\n\n\
743 You can also use a list of keymaps as MENU.\n\
744 Then each keymap makes a separate pane.\n\
745 When MENU is a keymap or a list of keymaps, the return value\n\
746 is a list of events.\n\n\
747 Alternatively, you can specify a menu of multiple panes\n\
748 with a list of the form (TITLE PANE1 PANE2...),\n\
749 where each pane is a list of form (TITLE ITEM1 ITEM2...).\n\
750 Each ITEM is normally a cons cell (STRING . VALUE);\n\
751 but a string can appear as an item--that makes a nonselectable line\n\
753 With this form of menu, the return value is VALUE from the chosen item.\n\
755 If POSITION is nil, don't display the menu at all, just precalculate the\n\
756 cached information about equivalent key sequences.")
758 Lisp_Object position
, menu
;
760 int number_of_panes
, panes
;
761 Lisp_Object keymap
, tem
;
765 Lisp_Object selection
;
768 Lisp_Object x
, y
, window
;
773 if (! NILP (position
))
777 /* Decode the first argument: find the window and the coordinates. */
778 if (EQ (position
, Qt
)
779 || (CONSP (position
) && EQ (XCONS (position
)->car
, Qmenu_bar
)))
781 /* Use the mouse's current position. */
782 FRAME_PTR new_f
= selected_frame
;
783 Lisp_Object bar_window
;
787 if (mouse_position_hook
)
788 (*mouse_position_hook
) (&new_f
, 1, &bar_window
,
789 &part
, &x
, &y
, &time
);
791 XSETFRAME (window
, new_f
);
794 window
= selected_window
;
801 tem
= Fcar (position
);
804 window
= Fcar (Fcdr (position
));
806 y
= Fcar (Fcdr (tem
));
811 tem
= Fcar (Fcdr (position
)); /* EVENT_START (position) */
812 window
= Fcar (tem
); /* POSN_WINDOW (tem) */
813 tem
= Fcar (Fcdr (Fcdr (tem
))); /* POSN_WINDOW_POSN (tem) */
822 /* Decode where to put the menu. */
830 else if (WINDOWP (window
))
832 CHECK_LIVE_WINDOW (window
, 0);
833 f
= XFRAME (WINDOW_FRAME (XWINDOW (window
)));
835 xpos
= (FONT_WIDTH (f
->output_data
.x
->font
) * XWINDOW (window
)->left
);
836 ypos
= (f
->output_data
.x
->line_height
* XWINDOW (window
)->top
);
839 /* ??? Not really clean; should be CHECK_WINDOW_OR_FRAME,
840 but I don't want to make one now. */
841 CHECK_WINDOW (window
, 0);
850 /* Decode the menu items from what was specified. */
852 keymap
= Fkeymapp (menu
);
855 tem
= Fkeymapp (Fcar (menu
));
858 /* We were given a keymap. Extract menu info from the keymap. */
860 keymap
= get_keymap (menu
);
862 /* Extract the detailed info to make one pane. */
863 keymap_panes (&menu
, 1, NILP (position
));
865 /* Search for a string appearing directly as an element of the keymap.
866 That string is the title of the menu. */
867 prompt
= map_prompt (keymap
);
869 /* Make that be the pane title of the first pane. */
870 if (!NILP (prompt
) && menu_items_n_panes
>= 0)
871 XVECTOR (menu_items
)->contents
[MENU_ITEMS_PANE_NAME
] = prompt
;
875 else if (!NILP (tem
))
877 /* We were given a list of keymaps. */
878 int nmaps
= XFASTINT (Flength (menu
));
880 = (Lisp_Object
*) alloca (nmaps
* sizeof (Lisp_Object
));
885 /* The first keymap that has a prompt string
886 supplies the menu title. */
887 for (tem
= menu
, i
= 0; CONSP (tem
); tem
= Fcdr (tem
))
891 maps
[i
++] = keymap
= get_keymap (Fcar (tem
));
893 prompt
= map_prompt (keymap
);
894 if (NILP (title
) && !NILP (prompt
))
898 /* Extract the detailed info to make one pane. */
899 keymap_panes (maps
, nmaps
, NILP (position
));
901 /* Make the title be the pane title of the first pane. */
902 if (!NILP (title
) && menu_items_n_panes
>= 0)
903 XVECTOR (menu_items
)->contents
[MENU_ITEMS_PANE_NAME
] = title
;
909 /* We were given an old-fashioned menu. */
911 CHECK_STRING (title
, 1);
913 list_of_panes (Fcdr (menu
));
920 discard_menu_items ();
925 /* Display them in a menu. */
928 selection
= xmenu_show (f
, xpos
, ypos
, for_click
,
929 keymaps
, title
, &error_name
);
932 discard_menu_items ();
936 if (error_name
) error (error_name
);
940 DEFUN ("x-popup-dialog", Fx_popup_dialog
, Sx_popup_dialog
, 2, 2, 0,
941 "Pop up a dialog box and return user's selection.\n\
942 POSITION specifies which frame to use.\n\
943 This is normally a mouse button event or a window or frame.\n\
944 If POSITION is t, it means to use the frame the mouse is on.\n\
945 The dialog box appears in the middle of the specified frame.\n\
947 CONTENTS specifies the alternatives to display in the dialog box.\n\
948 It is a list of the form (TITLE ITEM1 ITEM2...).\n\
949 Each ITEM is a cons cell (STRING . VALUE).\n\
950 The return value is VALUE from the chosen item.\n\n\
951 An ITEM may also be just a string--that makes a nonselectable item.\n\
952 An ITEM may also be nil--that means to put all preceding items\n\
953 on the left of the dialog box and all following items on the right.\n\
954 \(By default, approximately half appear on each side.)")
956 Lisp_Object position
, contents
;
963 /* Decode the first argument: find the window or frame to use. */
964 if (EQ (position
, Qt
)
965 || (CONSP (position
) && EQ (XCONS (position
)->car
, Qmenu_bar
)))
967 #if 0 /* Using the frame the mouse is on may not be right. */
968 /* Use the mouse's current position. */
969 FRAME_PTR new_f
= selected_frame
;
970 Lisp_Object bar_window
;
975 (*mouse_position_hook
) (&new_f
, 1, &bar_window
, &part
, &x
, &y
, &time
);
978 XSETFRAME (window
, new_f
);
980 window
= selected_window
;
982 window
= selected_window
;
984 else if (CONSP (position
))
987 tem
= Fcar (position
);
989 window
= Fcar (Fcdr (position
));
992 tem
= Fcar (Fcdr (position
)); /* EVENT_START (position) */
993 window
= Fcar (tem
); /* POSN_WINDOW (tem) */
996 else if (WINDOWP (position
) || FRAMEP (position
))
999 /* Decode where to put the menu. */
1001 if (FRAMEP (window
))
1002 f
= XFRAME (window
);
1003 else if (WINDOWP (window
))
1005 CHECK_LIVE_WINDOW (window
, 0);
1006 f
= XFRAME (WINDOW_FRAME (XWINDOW (window
)));
1009 /* ??? Not really clean; should be CHECK_WINDOW_OR_FRAME,
1010 but I don't want to make one now. */
1011 CHECK_WINDOW (window
, 0);
1013 #ifndef USE_X_TOOLKIT
1014 /* Display a menu with these alternatives
1015 in the middle of frame F. */
1017 Lisp_Object x
, y
, frame
, newpos
;
1018 XSETFRAME (frame
, f
);
1019 XSETINT (x
, x_pixel_width (f
) / 2);
1020 XSETINT (y
, x_pixel_height (f
) / 2);
1021 newpos
= Fcons (Fcons (x
, Fcons (y
, Qnil
)), Fcons (frame
, Qnil
));
1023 return Fx_popup_menu (newpos
,
1024 Fcons (Fcar (contents
), Fcons (contents
, Qnil
)));
1030 Lisp_Object selection
;
1032 /* Decode the dialog items from what was specified. */
1033 title
= Fcar (contents
);
1034 CHECK_STRING (title
, 1);
1036 list_of_panes (Fcons (contents
, Qnil
));
1038 /* Display them in a dialog box. */
1040 selection
= xdialog_show (f
, 0, title
, &error_name
);
1043 discard_menu_items ();
1045 if (error_name
) error (error_name
);
1051 #ifdef USE_X_TOOLKIT
1053 /* Loop in Xt until the menu pulldown or dialog popup has been
1054 popped down (deactivated).
1056 NOTE: All calls to popup_get_selection should be protected
1057 with BLOCK_INPUT, UNBLOCK_INPUT wrappers. */
1060 popup_get_selection (initial_event
, dpyinfo
, id
)
1061 XEvent
*initial_event
;
1062 struct x_display_info
*dpyinfo
;
1067 /* Define a queue to save up for later unreading
1068 all X events that don't pertain to the menu. */
1072 struct event_queue
*next
;
1075 struct event_queue
*queue
= NULL
;
1076 struct event_queue
*queue_tmp
;
1079 event
= *initial_event
;
1081 XtAppNextEvent (Xt_app_con
, &event
);
1085 /* Handle expose events for editor frames right away. */
1086 if (event
.type
== Expose
)
1087 process_expose_from_menu (event
);
1088 /* Make sure we don't consider buttons grabbed after menu goes. */
1089 else if (event
.type
== ButtonRelease
1090 && dpyinfo
->display
== event
.xbutton
.display
)
1091 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
1092 /* If the user presses a key, deactivate the menu.
1093 The user is likely to do that if we get wedged. */
1094 else if (event
.type
== KeyPress
1095 && dpyinfo
->display
== event
.xbutton
.display
)
1097 popup_activated_flag
= 0;
1100 /* Button presses outside the menu also pop it down. */
1101 else if (event
.type
== ButtonPress
1102 && event
.xany
.display
== dpyinfo
->display
1103 && x_any_window_to_frame (dpyinfo
, event
.xany
.window
))
1105 popup_activated_flag
= 0;
1109 /* Queue all events not for this popup,
1110 except for Expose, which we've already handled.
1111 Note that the X window is associated with the frame if this
1112 is a menu bar popup, but not if it's a dialog box. So we use
1113 x_non_menubar_window_to_frame, not x_any_window_to_frame. */
1114 if (event
.type
!= Expose
1115 && (event
.xany
.display
!= dpyinfo
->display
1116 || x_non_menubar_window_to_frame (dpyinfo
, event
.xany
.window
)))
1118 queue_tmp
= (struct event_queue
*) malloc (sizeof (struct event_queue
));
1120 if (queue_tmp
!= NULL
)
1122 queue_tmp
->event
= event
;
1123 queue_tmp
->next
= queue
;
1128 XtDispatchEvent (&event
);
1130 if (!popup_activated ())
1132 XtAppNextEvent (Xt_app_con
, &event
);
1135 /* Unread any events that we got but did not handle. */
1136 while (queue
!= NULL
)
1139 XPutBackEvent (queue_tmp
->event
.xany
.display
, &queue_tmp
->event
);
1140 queue
= queue_tmp
->next
;
1141 free ((char *)queue_tmp
);
1142 /* Cause these events to get read as soon as we UNBLOCK_INPUT. */
1143 interrupt_input_pending
= 1;
1147 /* Activate the menu bar of frame F.
1148 This is called from keyboard.c when it gets the
1149 menu_bar_activate_event out of the Emacs event queue.
1151 To activate the menu bar, we use the X button-press event
1152 that was saved in saved_button_event.
1153 That makes the toolkit do its thing.
1155 But first we recompute the menu bar contents (the whole tree).
1157 The reason for saving the button event until here, instead of
1158 passing it to the toolkit right away, is that we can safely
1159 execute Lisp code. */
1161 x_activate_menubar (f
)
1164 if (f
->output_data
.x
->saved_button_event
->type
!= ButtonPress
)
1167 set_frame_menubar (f
, 0, 1);
1170 XtDispatchEvent ((XEvent
*) f
->output_data
.x
->saved_button_event
);
1173 /* Ignore this if we get it a second time. */
1174 f
->output_data
.x
->saved_button_event
->type
= 0;
1177 /* Detect if a dialog or menu has been posted. */
1182 return popup_activated_flag
;
1186 /* This callback is invoked when the user selects a menubar cascade
1187 pushbutton, but before the pulldown menu is posted. */
1190 popup_activate_callback (widget
, id
, client_data
)
1193 XtPointer client_data
;
1195 popup_activated_flag
= 1;
1198 /* This callback is called from the menu bar pulldown menu
1199 when the user makes a selection.
1200 Figure out what the user chose
1201 and put the appropriate events into the keyboard buffer. */
1204 menubar_selection_callback (widget
, id
, client_data
)
1207 XtPointer client_data
;
1209 Lisp_Object prefix
, entry
;
1210 FRAME_PTR f
= menubar_id_to_frame (id
);
1212 Lisp_Object
*subprefix_stack
;
1213 int submenu_depth
= 0;
1218 subprefix_stack
= (Lisp_Object
*) alloca (f
->menu_bar_items_used
* sizeof (Lisp_Object
));
1219 vector
= f
->menu_bar_vector
;
1222 while (i
< f
->menu_bar_items_used
)
1224 if (EQ (XVECTOR (vector
)->contents
[i
], Qnil
))
1226 subprefix_stack
[submenu_depth
++] = prefix
;
1230 else if (EQ (XVECTOR (vector
)->contents
[i
], Qlambda
))
1232 prefix
= subprefix_stack
[--submenu_depth
];
1235 else if (EQ (XVECTOR (vector
)->contents
[i
], Qt
))
1237 prefix
= XVECTOR (vector
)->contents
[i
+ MENU_ITEMS_PANE_PREFIX
];
1238 i
+= MENU_ITEMS_PANE_LENGTH
;
1242 entry
= XVECTOR (vector
)->contents
[i
+ MENU_ITEMS_ITEM_VALUE
];
1243 /* The EMACS_INT cast avoids a warning. There's no problem
1244 as long as pointers have enough bits to hold small integers. */
1245 if ((int) (EMACS_INT
) client_data
== i
)
1248 struct input_event buf
;
1251 XSETFRAME (frame
, f
);
1252 buf
.kind
= menu_bar_event
;
1253 buf
.frame_or_window
= Fcons (frame
, Fcons (Qmenu_bar
, Qnil
));
1254 kbd_buffer_store_event (&buf
);
1256 for (j
= 0; j
< submenu_depth
; j
++)
1257 if (!NILP (subprefix_stack
[j
]))
1259 buf
.kind
= menu_bar_event
;
1260 buf
.frame_or_window
= Fcons (frame
, subprefix_stack
[j
]);
1261 kbd_buffer_store_event (&buf
);
1266 buf
.kind
= menu_bar_event
;
1267 buf
.frame_or_window
= Fcons (frame
, prefix
);
1268 kbd_buffer_store_event (&buf
);
1271 buf
.kind
= menu_bar_event
;
1272 buf
.frame_or_window
= Fcons (frame
, entry
);
1273 kbd_buffer_store_event (&buf
);
1277 i
+= MENU_ITEMS_ITEM_LENGTH
;
1282 /* This callback is invoked when a dialog or menu is finished being
1283 used and has been unposted. */
1286 popup_deactivate_callback (widget
, id
, client_data
)
1289 XtPointer client_data
;
1291 popup_activated_flag
= 0;
1295 /* This recursively calls free_widget_value on the tree of widgets.
1296 It must free all data that was malloc'ed for these widget_values.
1297 In Emacs, many slots are pointers into the data of Lisp_Strings, and
1298 must be left alone. */
1301 free_menubar_widget_value_tree (wv
)
1306 wv
->name
= wv
->value
= wv
->key
= (char *) 0xDEADBEEF;
1308 if (wv
->contents
&& (wv
->contents
!= (widget_value
*)1))
1310 free_menubar_widget_value_tree (wv
->contents
);
1311 wv
->contents
= (widget_value
*) 0xDEADBEEF;
1315 free_menubar_widget_value_tree (wv
->next
);
1316 wv
->next
= (widget_value
*) 0xDEADBEEF;
1319 free_widget_value (wv
);
1323 /* Return a tree of widget_value structures for a menu bar item
1324 whose event type is ITEM_KEY (with string ITEM_NAME)
1325 and whose contents come from the list of keymaps MAPS. */
1327 static widget_value
*
1328 single_submenu (item_key
, item_name
, maps
)
1329 Lisp_Object item_key
, item_name
, maps
;
1331 widget_value
*wv
, *prev_wv
, *save_wv
, *first_wv
;
1333 int submenu_depth
= 0;
1336 Lisp_Object
*mapvec
;
1337 widget_value
**submenu_stack
;
1339 int previous_items
= menu_items_used
;
1340 int top_level_items
= 0;
1342 length
= Flength (maps
);
1343 len
= XINT (length
);
1345 /* Convert the list MAPS into a vector MAPVEC. */
1346 mapvec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
1347 for (i
= 0; i
< len
; i
++)
1349 mapvec
[i
] = Fcar (maps
);
1353 menu_items_n_panes
= 0;
1355 /* Loop over the given keymaps, making a pane for each map.
1356 But don't make a pane that is empty--ignore that map instead. */
1357 for (i
= 0; i
< len
; i
++)
1359 if (SYMBOLP (mapvec
[i
]))
1361 top_level_items
= 1;
1362 push_menu_pane (Qnil
, Qnil
);
1363 push_menu_item (item_name
, Qt
, item_key
, mapvec
[i
], Qnil
);
1366 single_keymap_panes (mapvec
[i
], item_name
, item_key
, 0);
1369 /* Create a tree of widget_value objects
1370 representing the panes and their items. */
1373 = (widget_value
**) alloca (menu_items_used
* sizeof (widget_value
*));
1374 wv
= malloc_widget_value ();
1382 /* Loop over all panes and items made during this call
1383 and construct a tree of widget_value objects.
1384 Ignore the panes and items made by previous calls to
1385 single_submenu, even though those are also in menu_items. */
1387 while (i
< menu_items_used
)
1389 if (EQ (XVECTOR (menu_items
)->contents
[i
], Qnil
))
1391 submenu_stack
[submenu_depth
++] = save_wv
;
1396 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qlambda
))
1399 save_wv
= submenu_stack
[--submenu_depth
];
1402 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qt
)
1403 && submenu_depth
!= 0)
1404 i
+= MENU_ITEMS_PANE_LENGTH
;
1405 /* Ignore a nil in the item list.
1406 It's meaningful only for dialog boxes. */
1407 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qquote
))
1409 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qt
))
1411 /* Create a new pane. */
1412 Lisp_Object pane_name
, prefix
;
1414 pane_name
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_PANE_NAME
];
1415 prefix
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_PANE_PREFIX
];
1416 pane_string
= (NILP (pane_name
)
1417 ? "" : (char *) XSTRING (pane_name
)->data
);
1418 /* If there is just one top-level pane, put all its items directly
1419 under the top-level menu. */
1420 if (menu_items_n_panes
== 1)
1423 /* If the pane has a meaningful name,
1424 make the pane a top-level menu item
1425 with its items as a submenu beneath it. */
1426 if (strcmp (pane_string
, ""))
1428 wv
= malloc_widget_value ();
1432 first_wv
->contents
= wv
;
1433 wv
->name
= pane_string
;
1434 /* Ignore the @ that means "separate pane".
1435 This is a kludge, but this isn't worth more time. */
1436 if (!NILP (prefix
) && wv
->name
[0] == '@')
1443 i
+= MENU_ITEMS_PANE_LENGTH
;
1447 /* Create a new item within current pane. */
1448 Lisp_Object item_name
, enable
, descrip
, def
;
1449 item_name
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_NAME
];
1450 enable
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_ENABLE
];
1452 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_EQUIV_KEY
];
1453 def
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_DEFINITION
];
1455 wv
= malloc_widget_value ();
1459 save_wv
->contents
= wv
;
1461 wv
->name
= (char *) XSTRING (item_name
)->data
;
1462 if (!NILP (descrip
))
1463 wv
->key
= (char *) XSTRING (descrip
)->data
;
1465 /* The EMACS_INT cast avoids a warning. There's no problem
1466 as long as pointers have enough bits to hold small integers. */
1467 wv
->call_data
= (!NILP (def
) ? (void *) (EMACS_INT
) i
: 0);
1468 wv
->enabled
= !NILP (enable
);
1471 i
+= MENU_ITEMS_ITEM_LENGTH
;
1475 /* If we have just one "menu item"
1476 that was originally a button, return it by itself. */
1477 if (top_level_items
&& first_wv
->contents
&& first_wv
->contents
->next
== 0)
1479 wv
= first_wv
->contents
;
1480 free_widget_value (first_wv
);
1487 extern void EmacsFrameSetCharSize ();
1489 /* Recompute all the widgets of frame F, when the menu bar
1490 has been changed. */
1493 update_frame_menubar (f
)
1496 struct x_output
*x
= f
->output_data
.x
;
1498 int menubar_changed
;
1500 Dimension shell_height
;
1502 /* We assume the menubar contents has changed if the global flag is set,
1503 or if the current buffer has changed, or if the menubar has never
1504 been updated before.
1506 menubar_changed
= (x
->menubar_widget
1507 && !XtIsManaged (x
->menubar_widget
));
1509 if (! (menubar_changed
))
1513 /* Save the size of the frame because the pane widget doesn't accept to
1514 resize itself. So force it. */
1518 /* Do the voodoo which means "I'm changing lots of things, don't try to
1519 refigure sizes until I'm done." */
1520 lw_refigure_widget (x
->column_widget
, False
);
1522 /* the order in which children are managed is the top to
1523 bottom order in which they are displayed in the paned window.
1524 First, remove the text-area widget.
1526 XtUnmanageChild (x
->edit_widget
);
1528 /* remove the menubar that is there now, and put up the menubar that
1531 if (menubar_changed
)
1533 XtManageChild (x
->menubar_widget
);
1534 XtMapWidget (x
->menubar_widget
);
1535 XtVaSetValues (x
->menubar_widget
, XtNmappedWhenManaged
, 1, 0);
1538 /* Re-manage the text-area widget, and then thrash the sizes. */
1539 XtManageChild (x
->edit_widget
);
1540 lw_refigure_widget (x
->column_widget
, True
);
1542 /* Force the pane widget to resize itself with the right values. */
1543 EmacsFrameSetCharSize (x
->edit_widget
, columns
, rows
);
1548 /* Set the contents of the menubar widgets of frame F.
1549 The argument FIRST_TIME is currently ignored;
1550 it is set the first time this is called, from initialize_frame_menubar. */
1553 set_frame_menubar (f
, first_time
, deep_p
)
1558 Widget menubar_widget
= f
->output_data
.x
->menubar_widget
;
1559 Lisp_Object tail
, items
, frame
;
1560 widget_value
*wv
, *first_wv
, *prev_wv
= 0;
1564 if (f
->output_data
.x
->id
== 0)
1565 f
->output_data
.x
->id
= next_menubar_widget_id
++;
1566 id
= f
->output_data
.x
->id
;
1568 if (! menubar_widget
)
1571 wv
= malloc_widget_value ();
1572 wv
->name
= "menubar";
1579 /* Make a widget-value tree representing the entire menu trees. */
1581 struct buffer
*prev
= current_buffer
;
1583 int specpdl_count
= specpdl_ptr
- specpdl
;
1584 int previous_menu_items_used
= f
->menu_bar_items_used
;
1585 Lisp_Object
*previous_items
1586 = (Lisp_Object
*) alloca (previous_menu_items_used
1587 * sizeof (Lisp_Object
));
1589 buffer
= XWINDOW (FRAME_SELECTED_WINDOW (f
))->buffer
;
1590 specbind (Qinhibit_quit
, Qt
);
1591 /* Don't let the debugger step into this code
1592 because it is not reentrant. */
1593 specbind (Qdebug_on_next_call
, Qnil
);
1595 record_unwind_protect (Fstore_match_data
, Fmatch_data ());
1596 if (NILP (Voverriding_local_map_menu_flag
))
1598 specbind (Qoverriding_terminal_local_map
, Qnil
);
1599 specbind (Qoverriding_local_map
, Qnil
);
1602 set_buffer_internal_1 (XBUFFER (buffer
));
1604 /* Run the Lucid hook. */
1605 call1 (Vrun_hooks
, Qactivate_menubar_hook
);
1606 /* If it has changed current-menubar from previous value,
1607 really recompute the menubar from the value. */
1608 if (! NILP (Vlucid_menu_bar_dirty_flag
))
1609 call0 (Qrecompute_lucid_menubar
);
1610 call1 (Vrun_hooks
, Qmenu_bar_update_hook
);
1611 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
1613 items
= FRAME_MENU_BAR_ITEMS (f
);
1615 inhibit_garbage_collection ();
1617 /* Save the frame's previous menu bar contents data. */
1618 bcopy (XVECTOR (f
->menu_bar_vector
)->contents
, previous_items
,
1619 previous_menu_items_used
* sizeof (Lisp_Object
));
1621 /* Fill in the current menu bar contents. */
1622 menu_items
= f
->menu_bar_vector
;
1623 menu_items_allocated
= XVECTOR (menu_items
)->size
;
1625 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 3)
1627 Lisp_Object key
, string
, maps
;
1629 key
= XVECTOR (items
)->contents
[i
];
1630 string
= XVECTOR (items
)->contents
[i
+ 1];
1631 maps
= XVECTOR (items
)->contents
[i
+ 2];
1635 wv
= single_submenu (key
, string
, maps
);
1639 first_wv
->contents
= wv
;
1640 /* Don't set wv->name here; GC during the loop might relocate it. */
1645 finish_menu_items ();
1647 set_buffer_internal_1 (prev
);
1648 unbind_to (specpdl_count
, Qnil
);
1650 /* If there has been no change in the Lisp-level contents
1651 of the menu bar, skip redisplaying it. Just exit. */
1653 for (i
= 0; i
< previous_menu_items_used
; i
++)
1654 if (menu_items_used
== i
1655 || (previous_items
[i
] != XVECTOR (menu_items
)->contents
[i
]))
1657 if (i
== menu_items_used
&& i
== previous_menu_items_used
)
1659 free_menubar_widget_value_tree (first_wv
);
1665 /* Now GC cannot happen during the lifetime of the widget_value,
1666 so it's safe to store data from a Lisp_String. */
1667 wv
= first_wv
->contents
;
1668 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 3)
1671 string
= XVECTOR (items
)->contents
[i
+ 1];
1674 wv
->name
= (char *) XSTRING (string
)->data
;
1678 f
->menu_bar_vector
= menu_items
;
1679 f
->menu_bar_items_used
= menu_items_used
;
1684 /* Make a widget-value tree containing
1685 just the top level menu bar strings. */
1687 items
= FRAME_MENU_BAR_ITEMS (f
);
1688 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 3)
1692 string
= XVECTOR (items
)->contents
[i
+ 1];
1696 wv
= malloc_widget_value ();
1697 wv
->name
= (char *) XSTRING (string
)->data
;
1704 first_wv
->contents
= wv
;
1709 /* Create or update the menu bar widget. */
1715 /* Disable resizing (done for Motif!) */
1716 lw_allow_resizing (f
->output_data
.x
->widget
, False
);
1718 /* The third arg is DEEP_P, which says to consider the entire
1719 menu trees we supply, rather than just the menu bar item names. */
1720 lw_modify_all_widgets (id
, first_wv
, deep_p
);
1722 /* Re-enable the edit widget to resize. */
1723 lw_allow_resizing (f
->output_data
.x
->widget
, True
);
1727 menubar_widget
= lw_create_widget ("menubar", "menubar", id
, first_wv
,
1728 f
->output_data
.x
->column_widget
,
1730 popup_activate_callback
,
1731 menubar_selection_callback
,
1732 popup_deactivate_callback
);
1733 f
->output_data
.x
->menubar_widget
= menubar_widget
;
1738 = (f
->output_data
.x
->menubar_widget
1739 ? (f
->output_data
.x
->menubar_widget
->core
.height
1740 + f
->output_data
.x
->menubar_widget
->core
.border_width
)
1744 if (FRAME_EXTERNAL_MENU_BAR (f
))
1747 XtVaGetValues (f
->output_data
.x
->column_widget
,
1748 XtNinternalBorderWidth
, &ibw
, NULL
);
1749 menubar_size
+= ibw
;
1751 #endif /* USE_LUCID */
1753 f
->output_data
.x
->menubar_height
= menubar_size
;
1756 free_menubar_widget_value_tree (first_wv
);
1758 update_frame_menubar (f
);
1763 /* Called from Fx_create_frame to create the inital menubar of a frame
1764 before it is mapped, so that the window is mapped with the menubar already
1765 there instead of us tacking it on later and thrashing the window after it
1769 initialize_frame_menubar (f
)
1772 /* This function is called before the first chance to redisplay
1773 the frame. It has to be, so the frame will have the right size. */
1774 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
1775 set_frame_menubar (f
, 1, 1);
1778 /* Get rid of the menu bar of frame F, and free its storage.
1779 This is used when deleting a frame, and when turning off the menu bar. */
1782 free_frame_menubar (f
)
1785 Widget menubar_widget
;
1788 menubar_widget
= f
->output_data
.x
->menubar_widget
;
1793 lw_destroy_all_widgets ((LWLIB_ID
) f
->output_data
.x
->id
);
1798 #endif /* USE_X_TOOLKIT */
1800 /* xmenu_show actually displays a menu using the panes and items in menu_items
1801 and returns the value selected from it.
1802 There are two versions of xmenu_show, one for Xt and one for Xlib.
1803 Both assume input is blocked by the caller. */
1805 /* F is the frame the menu is for.
1806 X and Y are the frame-relative specified position,
1807 relative to the inside upper left corner of the frame F.
1808 FOR_CLICK if this menu was invoked for a mouse click.
1809 KEYMAPS is 1 if this menu was specified with keymaps;
1810 in that case, we return a list containing the chosen item's value
1811 and perhaps also the pane's prefix.
1812 TITLE is the specified menu title.
1813 ERROR is a place to store an error message string in case of failure.
1814 (We return nil on failure, but the value doesn't actually matter.) */
1816 #ifdef USE_X_TOOLKIT
1818 /* We need a unique id for each widget handled by the Lucid Widget
1821 For the main windows, and popup menus, we use this counter,
1822 which we increment each time after use. This starts from 1<<16.
1824 For menu bars, we use numbers starting at 0, counted in
1825 next_menubar_widget_id. */
1826 LWLIB_ID widget_id_tick
;
1829 static Lisp_Object
*volatile menu_item_selection
;
1831 static Lisp_Object
*menu_item_selection
;
1835 popup_selection_callback (widget
, id
, client_data
)
1838 XtPointer client_data
;
1840 menu_item_selection
= (Lisp_Object
*) client_data
;
1844 xmenu_show (f
, x
, y
, for_click
, keymaps
, title
, error
)
1858 widget_value
*wv
, *save_wv
= 0, *first_wv
= 0, *prev_wv
= 0;
1859 widget_value
**submenu_stack
1860 = (widget_value
**) alloca (menu_items_used
* sizeof (widget_value
*));
1861 Lisp_Object
*subprefix_stack
1862 = (Lisp_Object
*) alloca (menu_items_used
* sizeof (Lisp_Object
));
1863 int submenu_depth
= 0;
1864 XButtonPressedEvent dummy
;
1867 int next_release_must_exit
= 0;
1871 if (menu_items_used
<= MENU_ITEMS_PANE_LENGTH
)
1873 *error
= "Empty menu";
1877 /* Create a tree of widget_value objects
1878 representing the panes and their items. */
1879 wv
= malloc_widget_value ();
1886 /* Loop over all panes and items, filling in the tree. */
1888 while (i
< menu_items_used
)
1890 if (EQ (XVECTOR (menu_items
)->contents
[i
], Qnil
))
1892 submenu_stack
[submenu_depth
++] = save_wv
;
1898 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qlambda
))
1901 save_wv
= submenu_stack
[--submenu_depth
];
1905 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qt
)
1906 && submenu_depth
!= 0)
1907 i
+= MENU_ITEMS_PANE_LENGTH
;
1908 /* Ignore a nil in the item list.
1909 It's meaningful only for dialog boxes. */
1910 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qquote
))
1912 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qt
))
1914 /* Create a new pane. */
1915 Lisp_Object pane_name
, prefix
;
1917 pane_name
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_PANE_NAME
];
1918 prefix
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_PANE_PREFIX
];
1919 pane_string
= (NILP (pane_name
)
1920 ? "" : (char *) XSTRING (pane_name
)->data
);
1921 /* If there is just one top-level pane, put all its items directly
1922 under the top-level menu. */
1923 if (menu_items_n_panes
== 1)
1926 /* If the pane has a meaningful name,
1927 make the pane a top-level menu item
1928 with its items as a submenu beneath it. */
1929 if (!keymaps
&& strcmp (pane_string
, ""))
1931 wv
= malloc_widget_value ();
1935 first_wv
->contents
= wv
;
1936 wv
->name
= pane_string
;
1937 if (keymaps
&& !NILP (prefix
))
1944 else if (first_pane
)
1950 i
+= MENU_ITEMS_PANE_LENGTH
;
1954 /* Create a new item within current pane. */
1955 Lisp_Object item_name
, enable
, descrip
, def
;
1956 item_name
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_NAME
];
1957 enable
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_ENABLE
];
1959 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_EQUIV_KEY
];
1960 def
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_DEFINITION
];
1962 wv
= malloc_widget_value ();
1966 save_wv
->contents
= wv
;
1967 wv
->name
= (char *) XSTRING (item_name
)->data
;
1968 if (!NILP (descrip
))
1969 wv
->key
= (char *) XSTRING (descrip
)->data
;
1971 /* If this item has a null value,
1972 make the call_data null so that it won't display a box
1973 when the mouse is on it. */
1975 = (!NILP (def
) ? (void *) &XVECTOR (menu_items
)->contents
[i
] : 0);
1976 wv
->enabled
= !NILP (enable
);
1979 i
+= MENU_ITEMS_ITEM_LENGTH
;
1983 /* Deal with the title, if it is non-nil. */
1986 widget_value
*wv_title
= malloc_widget_value ();
1987 widget_value
*wv_sep1
= malloc_widget_value ();
1988 widget_value
*wv_sep2
= malloc_widget_value ();
1990 wv_sep2
->name
= "--";
1991 wv_sep2
->next
= first_wv
->contents
;
1993 wv_sep1
->name
= "--";
1994 wv_sep1
->next
= wv_sep2
;
1996 wv_title
->name
= (char *) XSTRING (title
)->data
;
1997 wv_title
->enabled
= True
;
1998 wv_title
->next
= wv_sep1
;
1999 first_wv
->contents
= wv_title
;
2002 /* Actually create the menu. */
2003 menu_id
= widget_id_tick
++;
2004 menu
= lw_create_widget ("popup", first_wv
->name
, menu_id
, first_wv
,
2005 f
->output_data
.x
->widget
, 1, 0,
2006 popup_selection_callback
,
2007 popup_deactivate_callback
);
2009 /* Adjust coordinates to relative to the outer (window manager) window. */
2012 int win_x
= 0, win_y
= 0;
2014 /* Find the position of the outside upper-left corner of
2015 the inner window, with respect to the outer window. */
2016 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
2019 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
2021 /* From-window, to-window. */
2022 f
->output_data
.x
->window_desc
,
2023 f
->output_data
.x
->parent_desc
,
2025 /* From-position, to-position. */
2026 0, 0, &win_x
, &win_y
,
2028 /* Child of window. */
2036 /* Adjust coordinates to be root-window-relative. */
2037 x
+= f
->output_data
.x
->left_pos
;
2038 y
+= f
->output_data
.x
->top_pos
;
2040 dummy
.type
= ButtonPress
;
2042 dummy
.send_event
= 0;
2043 dummy
.display
= FRAME_X_DISPLAY (f
);
2044 dummy
.time
= CurrentTime
;
2046 dummy
.root
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
2047 dummy
.window
= dummy
.root
;
2048 dummy
.subwindow
= dummy
.root
;
2054 /* Don't allow any geometry request from the user. */
2055 XtSetArg (av
[ac
], XtNgeometry
, 0); ac
++;
2056 XtSetValues (menu
, av
, ac
);
2058 /* Free the widget_value objects we used to specify the contents. */
2059 free_menubar_widget_value_tree (first_wv
);
2061 /* No selection has been chosen yet. */
2062 menu_item_selection
= 0;
2064 /* Display the menu. */
2065 lw_popup_menu (menu
, &dummy
);
2066 popup_activated_flag
= 1;
2068 /* Process events that apply to the menu. */
2069 popup_get_selection ((XEvent
*) 0, FRAME_X_DISPLAY_INFO (f
), menu_id
);
2071 /* fp turned off the following statement and wrote a comment
2072 that it is unnecessary--that the menu has already disappeared.
2073 Nowadays the menu disappears ok, all right, but
2074 we need to delete the widgets or multiple ones will pile up. */
2075 lw_destroy_all_widgets (menu_id
);
2077 /* Find the selected item, and its pane, to return
2078 the proper value. */
2079 if (menu_item_selection
!= 0)
2081 Lisp_Object prefix
, entry
;
2085 while (i
< menu_items_used
)
2087 if (EQ (XVECTOR (menu_items
)->contents
[i
], Qnil
))
2089 subprefix_stack
[submenu_depth
++] = prefix
;
2093 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qlambda
))
2095 prefix
= subprefix_stack
[--submenu_depth
];
2098 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qt
))
2101 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_PANE_PREFIX
];
2102 i
+= MENU_ITEMS_PANE_LENGTH
;
2104 /* Ignore a nil in the item list.
2105 It's meaningful only for dialog boxes. */
2106 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qquote
))
2111 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_VALUE
];
2112 if (menu_item_selection
== &XVECTOR (menu_items
)->contents
[i
])
2118 entry
= Fcons (entry
, Qnil
);
2120 entry
= Fcons (prefix
, entry
);
2121 for (j
= submenu_depth
- 1; j
>= 0; j
--)
2122 if (!NILP (subprefix_stack
[j
]))
2123 entry
= Fcons (subprefix_stack
[j
], entry
);
2127 i
+= MENU_ITEMS_ITEM_LENGTH
;
2136 dialog_selection_callback (widget
, id
, client_data
)
2139 XtPointer client_data
;
2141 /* The EMACS_INT cast avoids a warning. There's no problem
2142 as long as pointers have enough bits to hold small integers. */
2143 if ((int) (EMACS_INT
) client_data
!= -1)
2144 menu_item_selection
= (Lisp_Object
*) client_data
;
2146 lw_destroy_all_widgets (id
);
2148 popup_activated_flag
= 0;
2151 static char * button_names
[] = {
2152 "button1", "button2", "button3", "button4", "button5",
2153 "button6", "button7", "button8", "button9", "button10" };
2156 xdialog_show (f
, keymaps
, title
, error
)
2162 int i
, nb_buttons
=0;
2165 char dialog_name
[6];
2167 widget_value
*wv
, *save_wv
= 0, *first_wv
= 0, *prev_wv
= 0;
2169 /* Number of elements seen so far, before boundary. */
2171 /* 1 means we've seen the boundary between left-hand elts and right-hand. */
2172 int boundary_seen
= 0;
2176 if (menu_items_n_panes
> 1)
2178 *error
= "Multiple panes in dialog box";
2182 /* Create a tree of widget_value objects
2183 representing the text label and buttons. */
2185 Lisp_Object pane_name
, prefix
;
2187 pane_name
= XVECTOR (menu_items
)->contents
[MENU_ITEMS_PANE_NAME
];
2188 prefix
= XVECTOR (menu_items
)->contents
[MENU_ITEMS_PANE_PREFIX
];
2189 pane_string
= (NILP (pane_name
)
2190 ? "" : (char *) XSTRING (pane_name
)->data
);
2191 prev_wv
= malloc_widget_value ();
2192 prev_wv
->value
= pane_string
;
2193 if (keymaps
&& !NILP (prefix
))
2195 prev_wv
->enabled
= 1;
2196 prev_wv
->name
= "message";
2199 /* Loop over all panes and items, filling in the tree. */
2200 i
= MENU_ITEMS_PANE_LENGTH
;
2201 while (i
< menu_items_used
)
2204 /* Create a new item within current pane. */
2205 Lisp_Object item_name
, enable
, descrip
;
2206 item_name
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_NAME
];
2207 enable
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_ENABLE
];
2209 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_EQUIV_KEY
];
2211 if (NILP (item_name
))
2213 free_menubar_widget_value_tree (first_wv
);
2214 *error
= "Submenu in dialog items";
2217 if (EQ (item_name
, Qquote
))
2219 /* This is the boundary between left-side elts
2220 and right-side elts. Stop incrementing right_count. */
2225 if (nb_buttons
>= 10)
2227 free_menubar_widget_value_tree (first_wv
);
2228 *error
= "Too many dialog items";
2232 wv
= malloc_widget_value ();
2234 wv
->name
= (char *) button_names
[nb_buttons
];
2235 if (!NILP (descrip
))
2236 wv
->key
= (char *) XSTRING (descrip
)->data
;
2237 wv
->value
= (char *) XSTRING (item_name
)->data
;
2238 wv
->call_data
= (void *) &XVECTOR (menu_items
)->contents
[i
];
2239 wv
->enabled
= !NILP (enable
);
2242 if (! boundary_seen
)
2246 i
+= MENU_ITEMS_ITEM_LENGTH
;
2249 /* If the boundary was not specified,
2250 by default put half on the left and half on the right. */
2251 if (! boundary_seen
)
2252 left_count
= nb_buttons
- nb_buttons
/ 2;
2254 wv
= malloc_widget_value ();
2255 wv
->name
= dialog_name
;
2257 /* Dialog boxes use a really stupid name encoding
2258 which specifies how many buttons to use
2259 and how many buttons are on the right.
2260 The Q means something also. */
2261 dialog_name
[0] = 'Q';
2262 dialog_name
[1] = '0' + nb_buttons
;
2263 dialog_name
[2] = 'B';
2264 dialog_name
[3] = 'R';
2265 /* Number of buttons to put on the right. */
2266 dialog_name
[4] = '0' + nb_buttons
- left_count
;
2268 wv
->contents
= first_wv
;
2272 /* Actually create the dialog. */
2273 dialog_id
= widget_id_tick
++;
2274 menu
= lw_create_widget (first_wv
->name
, "dialog", dialog_id
, first_wv
,
2275 f
->output_data
.x
->widget
, 1, 0,
2276 dialog_selection_callback
, 0);
2277 lw_modify_all_widgets (dialog_id
, first_wv
->contents
, True
);
2278 /* Free the widget_value objects we used to specify the contents. */
2279 free_menubar_widget_value_tree (first_wv
);
2281 /* No selection has been chosen yet. */
2282 menu_item_selection
= 0;
2284 /* Display the menu. */
2285 lw_pop_up_all_widgets (dialog_id
);
2286 popup_activated_flag
= 1;
2288 /* Process events that apply to the menu. */
2289 popup_get_selection ((XEvent
*) 0, FRAME_X_DISPLAY_INFO (f
), dialog_id
);
2291 lw_destroy_all_widgets (dialog_id
);
2293 /* Find the selected item, and its pane, to return
2294 the proper value. */
2295 if (menu_item_selection
!= 0)
2301 while (i
< menu_items_used
)
2305 if (EQ (XVECTOR (menu_items
)->contents
[i
], Qt
))
2308 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_PANE_PREFIX
];
2309 i
+= MENU_ITEMS_PANE_LENGTH
;
2314 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_VALUE
];
2315 if (menu_item_selection
== &XVECTOR (menu_items
)->contents
[i
])
2319 entry
= Fcons (entry
, Qnil
);
2321 entry
= Fcons (prefix
, entry
);
2325 i
+= MENU_ITEMS_ITEM_LENGTH
;
2332 #else /* not USE_X_TOOLKIT */
2335 xmenu_show (f
, x
, y
, for_click
, keymaps
, title
, error
)
2345 int pane
, selidx
, lpane
, status
;
2346 Lisp_Object entry
, pane_prefix
;
2348 int ulx
, uly
, width
, height
;
2349 int dispwidth
, dispheight
;
2353 unsigned int dummy_uint
;
2356 if (menu_items_n_panes
== 0)
2359 if (menu_items_used
<= MENU_ITEMS_PANE_LENGTH
)
2361 *error
= "Empty menu";
2365 /* Figure out which root window F is on. */
2366 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &root
,
2367 &dummy_int
, &dummy_int
, &dummy_uint
, &dummy_uint
,
2368 &dummy_uint
, &dummy_uint
);
2370 /* Make the menu on that window. */
2371 menu
= XMenuCreate (FRAME_X_DISPLAY (f
), root
, "emacs");
2374 *error
= "Can't create menu";
2378 #ifdef HAVE_X_WINDOWS
2379 /* Adjust coordinates to relative to the outer (window manager) window. */
2382 int win_x
= 0, win_y
= 0;
2384 /* Find the position of the outside upper-left corner of
2385 the inner window, with respect to the outer window. */
2386 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
2389 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
2391 /* From-window, to-window. */
2392 f
->output_data
.x
->window_desc
,
2393 f
->output_data
.x
->parent_desc
,
2395 /* From-position, to-position. */
2396 0, 0, &win_x
, &win_y
,
2398 /* Child of window. */
2405 #endif /* HAVE_X_WINDOWS */
2407 /* Adjust coordinates to be root-window-relative. */
2408 x
+= f
->output_data
.x
->left_pos
;
2409 y
+= f
->output_data
.x
->top_pos
;
2411 /* Create all the necessary panes and their items. */
2413 while (i
< menu_items_used
)
2415 if (EQ (XVECTOR (menu_items
)->contents
[i
], Qt
))
2417 /* Create a new pane. */
2418 Lisp_Object pane_name
, prefix
;
2421 pane_name
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_PANE_NAME
];
2422 prefix
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_PANE_PREFIX
];
2423 pane_string
= (NILP (pane_name
)
2424 ? "" : (char *) XSTRING (pane_name
)->data
);
2425 if (keymaps
&& !NILP (prefix
))
2428 lpane
= XMenuAddPane (FRAME_X_DISPLAY (f
), menu
, pane_string
, TRUE
);
2429 if (lpane
== XM_FAILURE
)
2431 XMenuDestroy (FRAME_X_DISPLAY (f
), menu
);
2432 *error
= "Can't create pane";
2435 i
+= MENU_ITEMS_PANE_LENGTH
;
2437 /* Find the width of the widest item in this pane. */
2440 while (j
< menu_items_used
)
2443 item
= XVECTOR (menu_items
)->contents
[j
];
2451 width
= XSTRING (item
)->size
;
2452 if (width
> maxwidth
)
2455 j
+= MENU_ITEMS_ITEM_LENGTH
;
2458 /* Ignore a nil in the item list.
2459 It's meaningful only for dialog boxes. */
2460 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qquote
))
2464 /* Create a new item within current pane. */
2465 Lisp_Object item_name
, enable
, descrip
;
2466 unsigned char *item_data
;
2468 item_name
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_NAME
];
2469 enable
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_ENABLE
];
2471 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_EQUIV_KEY
];
2472 if (!NILP (descrip
))
2474 int gap
= maxwidth
- XSTRING (item_name
)->size
;
2477 spacer
= Fmake_string (make_number (gap
), make_number (' '));
2478 item_name
= concat2 (item_name
, spacer
);
2479 item_name
= concat2 (item_name
, descrip
);
2480 item_data
= XSTRING (item_name
)->data
;
2482 /* if alloca is fast, use that to make the space,
2483 to reduce gc needs. */
2485 = (unsigned char *) alloca (maxwidth
2486 + XSTRING (descrip
)->size
+ 1);
2487 bcopy (XSTRING (item_name
)->data
, item_data
,
2488 XSTRING (item_name
)->size
);
2489 for (j
= XSTRING (item_name
)->size
; j
< maxwidth
; j
++)
2491 bcopy (XSTRING (descrip
)->data
, item_data
+ j
,
2492 XSTRING (descrip
)->size
);
2493 item_data
[j
+ XSTRING (descrip
)->size
] = 0;
2497 item_data
= XSTRING (item_name
)->data
;
2499 if (XMenuAddSelection (FRAME_X_DISPLAY (f
),
2500 menu
, lpane
, 0, item_data
,
2504 XMenuDestroy (FRAME_X_DISPLAY (f
), menu
);
2505 *error
= "Can't add selection to menu";
2508 i
+= MENU_ITEMS_ITEM_LENGTH
;
2512 /* All set and ready to fly. */
2513 XMenuRecompute (FRAME_X_DISPLAY (f
), menu
);
2514 dispwidth
= DisplayWidth (FRAME_X_DISPLAY (f
),
2515 XScreenNumberOfScreen (FRAME_X_SCREEN (f
)));
2516 dispheight
= DisplayHeight (FRAME_X_DISPLAY (f
),
2517 XScreenNumberOfScreen (FRAME_X_SCREEN (f
)));
2518 x
= min (x
, dispwidth
);
2519 y
= min (y
, dispheight
);
2522 XMenuLocate (FRAME_X_DISPLAY (f
), menu
, 0, 0, x
, y
,
2523 &ulx
, &uly
, &width
, &height
);
2524 if (ulx
+width
> dispwidth
)
2526 x
-= (ulx
+ width
) - dispwidth
;
2527 ulx
= dispwidth
- width
;
2529 if (uly
+height
> dispheight
)
2531 y
-= (uly
+ height
) - dispheight
;
2532 uly
= dispheight
- height
;
2534 if (ulx
< 0) x
-= ulx
;
2535 if (uly
< 0) y
-= uly
;
2537 XMenuSetAEQ (menu
, TRUE
);
2538 XMenuSetFreeze (menu
, TRUE
);
2541 status
= XMenuActivate (FRAME_X_DISPLAY (f
), menu
, &pane
, &selidx
,
2542 x
, y
, ButtonReleaseMask
, &datap
);
2545 #ifdef HAVE_X_WINDOWS
2546 /* Assume the mouse has moved out of the X window.
2547 If it has actually moved in, we will get an EnterNotify. */
2548 x_mouse_leave (FRAME_X_DISPLAY_INFO (f
));
2555 fprintf (stderr
, "pane= %d line = %d\n", panes
, selidx
);
2558 /* Find the item number SELIDX in pane number PANE. */
2560 while (i
< menu_items_used
)
2562 if (EQ (XVECTOR (menu_items
)->contents
[i
], Qt
))
2566 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_PANE_PREFIX
];
2568 i
+= MENU_ITEMS_PANE_LENGTH
;
2577 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_VALUE
];
2580 entry
= Fcons (entry
, Qnil
);
2581 if (!NILP (pane_prefix
))
2582 entry
= Fcons (pane_prefix
, entry
);
2588 i
+= MENU_ITEMS_ITEM_LENGTH
;
2594 *error
= "Can't activate menu";
2600 XMenuDestroy (FRAME_X_DISPLAY (f
), menu
);
2602 #ifdef HAVE_X_WINDOWS
2603 /* State that no mouse buttons are now held.
2604 (The oldXMenu code doesn't track this info for us.)
2605 That is not necessarily true, but the fiction leads to reasonable
2606 results, and it is a pain to ask which are actually held now. */
2607 FRAME_X_DISPLAY_INFO (f
)->grabbed
= 0;
2613 #endif /* not USE_X_TOOLKIT */
2617 staticpro (&menu_items
);
2620 Qdebug_on_next_call
= intern ("debug-on-next-call");
2621 staticpro (&Qdebug_on_next_call
);
2623 #ifdef USE_X_TOOLKIT
2624 widget_id_tick
= (1<<16);
2625 next_menubar_widget_id
= 1;
2628 defsubr (&Sx_popup_menu
);
2629 defsubr (&Sx_popup_dialog
);