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 described 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). This is used for x-popup-menu
1055 and x-popup-dialog; it is not used for the menu bar any more.
1057 NOTE: All calls to popup_get_selection should be protected
1058 with BLOCK_INPUT, UNBLOCK_INPUT wrappers. */
1061 popup_get_selection (initial_event
, dpyinfo
, id
)
1062 XEvent
*initial_event
;
1063 struct x_display_info
*dpyinfo
;
1068 /* Define a queue to save up for later unreading
1069 all X events that don't pertain to the menu. */
1073 struct event_queue
*next
;
1076 struct event_queue
*queue
= NULL
;
1077 struct event_queue
*queue_tmp
;
1080 event
= *initial_event
;
1082 XtAppNextEvent (Xt_app_con
, &event
);
1086 /* Handle expose events for editor frames right away. */
1087 if (event
.type
== Expose
)
1088 process_expose_from_menu (event
);
1089 /* Make sure we don't consider buttons grabbed after menu goes. */
1090 else if (event
.type
== ButtonRelease
1091 && dpyinfo
->display
== event
.xbutton
.display
)
1092 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
1093 /* If the user presses a key, deactivate the menu.
1094 The user is likely to do that if we get wedged. */
1095 else if (event
.type
== KeyPress
1096 && dpyinfo
->display
== event
.xbutton
.display
)
1098 popup_activated_flag
= 0;
1101 /* Button presses outside the menu also pop it down. */
1102 else if (event
.type
== ButtonPress
1103 && event
.xany
.display
== dpyinfo
->display
1104 && x_any_window_to_frame (dpyinfo
, event
.xany
.window
))
1106 popup_activated_flag
= 0;
1110 /* Queue all events not for this popup,
1111 except for Expose, which we've already handled.
1112 Note that the X window is associated with the frame if this
1113 is a menu bar popup, but not if it's a dialog box. So we use
1114 x_non_menubar_window_to_frame, not x_any_window_to_frame. */
1115 if (event
.type
!= Expose
1116 && (event
.xany
.display
!= dpyinfo
->display
1117 || x_non_menubar_window_to_frame (dpyinfo
, event
.xany
.window
)))
1119 queue_tmp
= (struct event_queue
*) malloc (sizeof (struct event_queue
));
1121 if (queue_tmp
!= NULL
)
1123 queue_tmp
->event
= event
;
1124 queue_tmp
->next
= queue
;
1129 XtDispatchEvent (&event
);
1131 if (!popup_activated ())
1133 XtAppNextEvent (Xt_app_con
, &event
);
1136 /* Unread any events that we got but did not handle. */
1137 while (queue
!= NULL
)
1140 XPutBackEvent (queue_tmp
->event
.xany
.display
, &queue_tmp
->event
);
1141 queue
= queue_tmp
->next
;
1142 free ((char *)queue_tmp
);
1143 /* Cause these events to get read as soon as we UNBLOCK_INPUT. */
1144 interrupt_input_pending
= 1;
1148 /* Activate the menu bar of frame F.
1149 This is called from keyboard.c when it gets the
1150 menu_bar_activate_event out of the Emacs event queue.
1152 To activate the menu bar, we use the X button-press event
1153 that was saved in saved_button_event.
1154 That makes the toolkit do its thing.
1156 But first we recompute the menu bar contents (the whole tree).
1158 The reason for saving the button event until here, instead of
1159 passing it to the toolkit right away, is that we can safely
1160 execute Lisp code. */
1162 x_activate_menubar (f
)
1165 if (f
->output_data
.x
->saved_button_event
->type
!= ButtonPress
)
1168 set_frame_menubar (f
, 0, 1);
1171 XtDispatchEvent ((XEvent
*) f
->output_data
.x
->saved_button_event
);
1174 /* Ignore this if we get it a second time. */
1175 f
->output_data
.x
->saved_button_event
->type
= 0;
1178 /* Detect if a dialog or menu has been posted. */
1183 return popup_activated_flag
;
1187 /* This callback is invoked when the user selects a menubar cascade
1188 pushbutton, but before the pulldown menu is posted. */
1191 popup_activate_callback (widget
, id
, client_data
)
1194 XtPointer client_data
;
1196 popup_activated_flag
= 1;
1199 /* This callback is called from the menu bar pulldown menu
1200 when the user makes a selection.
1201 Figure out what the user chose
1202 and put the appropriate events into the keyboard buffer. */
1205 menubar_selection_callback (widget
, id
, client_data
)
1208 XtPointer client_data
;
1210 Lisp_Object prefix
, entry
;
1211 FRAME_PTR f
= menubar_id_to_frame (id
);
1213 Lisp_Object
*subprefix_stack
;
1214 int submenu_depth
= 0;
1219 subprefix_stack
= (Lisp_Object
*) alloca (f
->menu_bar_items_used
* sizeof (Lisp_Object
));
1220 vector
= f
->menu_bar_vector
;
1223 while (i
< f
->menu_bar_items_used
)
1225 if (EQ (XVECTOR (vector
)->contents
[i
], Qnil
))
1227 subprefix_stack
[submenu_depth
++] = prefix
;
1231 else if (EQ (XVECTOR (vector
)->contents
[i
], Qlambda
))
1233 prefix
= subprefix_stack
[--submenu_depth
];
1236 else if (EQ (XVECTOR (vector
)->contents
[i
], Qt
))
1238 prefix
= XVECTOR (vector
)->contents
[i
+ MENU_ITEMS_PANE_PREFIX
];
1239 i
+= MENU_ITEMS_PANE_LENGTH
;
1243 entry
= XVECTOR (vector
)->contents
[i
+ MENU_ITEMS_ITEM_VALUE
];
1244 /* The EMACS_INT cast avoids a warning. There's no problem
1245 as long as pointers have enough bits to hold small integers. */
1246 if ((int) (EMACS_INT
) client_data
== i
)
1249 struct input_event buf
;
1252 XSETFRAME (frame
, f
);
1253 buf
.kind
= menu_bar_event
;
1254 buf
.frame_or_window
= Fcons (frame
, Fcons (Qmenu_bar
, Qnil
));
1255 kbd_buffer_store_event (&buf
);
1257 for (j
= 0; j
< submenu_depth
; j
++)
1258 if (!NILP (subprefix_stack
[j
]))
1260 buf
.kind
= menu_bar_event
;
1261 buf
.frame_or_window
= Fcons (frame
, subprefix_stack
[j
]);
1262 kbd_buffer_store_event (&buf
);
1267 buf
.kind
= menu_bar_event
;
1268 buf
.frame_or_window
= Fcons (frame
, prefix
);
1269 kbd_buffer_store_event (&buf
);
1272 buf
.kind
= menu_bar_event
;
1273 buf
.frame_or_window
= Fcons (frame
, entry
);
1274 kbd_buffer_store_event (&buf
);
1278 i
+= MENU_ITEMS_ITEM_LENGTH
;
1283 /* This callback is invoked when a dialog or menu is finished being
1284 used and has been unposted. */
1287 popup_deactivate_callback (widget
, id
, client_data
)
1290 XtPointer client_data
;
1292 popup_activated_flag
= 0;
1296 /* This recursively calls free_widget_value on the tree of widgets.
1297 It must free all data that was malloc'ed for these widget_values.
1298 In Emacs, many slots are pointers into the data of Lisp_Strings, and
1299 must be left alone. */
1302 free_menubar_widget_value_tree (wv
)
1307 wv
->name
= wv
->value
= wv
->key
= (char *) 0xDEADBEEF;
1309 if (wv
->contents
&& (wv
->contents
!= (widget_value
*)1))
1311 free_menubar_widget_value_tree (wv
->contents
);
1312 wv
->contents
= (widget_value
*) 0xDEADBEEF;
1316 free_menubar_widget_value_tree (wv
->next
);
1317 wv
->next
= (widget_value
*) 0xDEADBEEF;
1320 free_widget_value (wv
);
1324 /* Return a tree of widget_value structures for a menu bar item
1325 whose event type is ITEM_KEY (with string ITEM_NAME)
1326 and whose contents come from the list of keymaps MAPS. */
1328 static widget_value
*
1329 single_submenu (item_key
, item_name
, maps
)
1330 Lisp_Object item_key
, item_name
, maps
;
1332 widget_value
*wv
, *prev_wv
, *save_wv
, *first_wv
;
1334 int submenu_depth
= 0;
1337 Lisp_Object
*mapvec
;
1338 widget_value
**submenu_stack
;
1340 int previous_items
= menu_items_used
;
1341 int top_level_items
= 0;
1343 length
= Flength (maps
);
1344 len
= XINT (length
);
1346 /* Convert the list MAPS into a vector MAPVEC. */
1347 mapvec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
1348 for (i
= 0; i
< len
; i
++)
1350 mapvec
[i
] = Fcar (maps
);
1354 menu_items_n_panes
= 0;
1356 /* Loop over the given keymaps, making a pane for each map.
1357 But don't make a pane that is empty--ignore that map instead. */
1358 for (i
= 0; i
< len
; i
++)
1360 if (SYMBOLP (mapvec
[i
]))
1362 top_level_items
= 1;
1363 push_menu_pane (Qnil
, Qnil
);
1364 push_menu_item (item_name
, Qt
, item_key
, mapvec
[i
], Qnil
);
1367 single_keymap_panes (mapvec
[i
], item_name
, item_key
, 0);
1370 /* Create a tree of widget_value objects
1371 representing the panes and their items. */
1374 = (widget_value
**) alloca (menu_items_used
* sizeof (widget_value
*));
1375 wv
= malloc_widget_value ();
1383 /* Loop over all panes and items made during this call
1384 and construct a tree of widget_value objects.
1385 Ignore the panes and items made by previous calls to
1386 single_submenu, even though those are also in menu_items. */
1388 while (i
< menu_items_used
)
1390 if (EQ (XVECTOR (menu_items
)->contents
[i
], Qnil
))
1392 submenu_stack
[submenu_depth
++] = save_wv
;
1397 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qlambda
))
1400 save_wv
= submenu_stack
[--submenu_depth
];
1403 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qt
)
1404 && submenu_depth
!= 0)
1405 i
+= MENU_ITEMS_PANE_LENGTH
;
1406 /* Ignore a nil in the item list.
1407 It's meaningful only for dialog boxes. */
1408 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qquote
))
1410 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qt
))
1412 /* Create a new pane. */
1413 Lisp_Object pane_name
, prefix
;
1415 pane_name
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_PANE_NAME
];
1416 prefix
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_PANE_PREFIX
];
1417 pane_string
= (NILP (pane_name
)
1418 ? "" : (char *) XSTRING (pane_name
)->data
);
1419 /* If there is just one top-level pane, put all its items directly
1420 under the top-level menu. */
1421 if (menu_items_n_panes
== 1)
1424 /* If the pane has a meaningful name,
1425 make the pane a top-level menu item
1426 with its items as a submenu beneath it. */
1427 if (strcmp (pane_string
, ""))
1429 wv
= malloc_widget_value ();
1433 first_wv
->contents
= wv
;
1434 wv
->name
= pane_string
;
1435 /* Ignore the @ that means "separate pane".
1436 This is a kludge, but this isn't worth more time. */
1437 if (!NILP (prefix
) && wv
->name
[0] == '@')
1444 i
+= MENU_ITEMS_PANE_LENGTH
;
1448 /* Create a new item within current pane. */
1449 Lisp_Object item_name
, enable
, descrip
, def
;
1450 item_name
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_NAME
];
1451 enable
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_ENABLE
];
1453 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_EQUIV_KEY
];
1454 def
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_DEFINITION
];
1456 wv
= malloc_widget_value ();
1460 save_wv
->contents
= wv
;
1462 wv
->name
= (char *) XSTRING (item_name
)->data
;
1463 if (!NILP (descrip
))
1464 wv
->key
= (char *) XSTRING (descrip
)->data
;
1466 /* The EMACS_INT cast avoids a warning. There's no problem
1467 as long as pointers have enough bits to hold small integers. */
1468 wv
->call_data
= (!NILP (def
) ? (void *) (EMACS_INT
) i
: 0);
1469 wv
->enabled
= !NILP (enable
);
1472 i
+= MENU_ITEMS_ITEM_LENGTH
;
1476 /* If we have just one "menu item"
1477 that was originally a button, return it by itself. */
1478 if (top_level_items
&& first_wv
->contents
&& first_wv
->contents
->next
== 0)
1480 wv
= first_wv
->contents
;
1481 free_widget_value (first_wv
);
1488 extern void EmacsFrameSetCharSize ();
1490 /* Recompute all the widgets of frame F, when the menu bar
1491 has been changed. */
1494 update_frame_menubar (f
)
1497 struct x_output
*x
= f
->output_data
.x
;
1499 int menubar_changed
;
1501 Dimension shell_height
;
1503 /* We assume the menubar contents has changed if the global flag is set,
1504 or if the current buffer has changed, or if the menubar has never
1505 been updated before.
1507 menubar_changed
= (x
->menubar_widget
1508 && !XtIsManaged (x
->menubar_widget
));
1510 if (! (menubar_changed
))
1514 /* Save the size of the frame because the pane widget doesn't accept to
1515 resize itself. So force it. */
1519 /* Do the voodoo which means "I'm changing lots of things, don't try to
1520 refigure sizes until I'm done." */
1521 lw_refigure_widget (x
->column_widget
, False
);
1523 /* the order in which children are managed is the top to
1524 bottom order in which they are displayed in the paned window.
1525 First, remove the text-area widget.
1527 XtUnmanageChild (x
->edit_widget
);
1529 /* remove the menubar that is there now, and put up the menubar that
1532 if (menubar_changed
)
1534 XtManageChild (x
->menubar_widget
);
1535 XtMapWidget (x
->menubar_widget
);
1536 XtVaSetValues (x
->menubar_widget
, XtNmappedWhenManaged
, 1, 0);
1539 /* Re-manage the text-area widget, and then thrash the sizes. */
1540 XtManageChild (x
->edit_widget
);
1541 lw_refigure_widget (x
->column_widget
, True
);
1543 /* Force the pane widget to resize itself with the right values. */
1544 EmacsFrameSetCharSize (x
->edit_widget
, columns
, rows
);
1549 /* Set the contents of the menubar widgets of frame F.
1550 The argument FIRST_TIME is currently ignored;
1551 it is set the first time this is called, from initialize_frame_menubar. */
1554 set_frame_menubar (f
, first_time
, deep_p
)
1559 Widget menubar_widget
= f
->output_data
.x
->menubar_widget
;
1560 Lisp_Object tail
, items
, frame
;
1561 widget_value
*wv
, *first_wv
, *prev_wv
= 0;
1565 if (f
->output_data
.x
->id
== 0)
1566 f
->output_data
.x
->id
= next_menubar_widget_id
++;
1567 id
= f
->output_data
.x
->id
;
1569 if (! menubar_widget
)
1572 wv
= malloc_widget_value ();
1573 wv
->name
= "menubar";
1580 /* Make a widget-value tree representing the entire menu trees. */
1582 struct buffer
*prev
= current_buffer
;
1584 int specpdl_count
= specpdl_ptr
- specpdl
;
1585 int previous_menu_items_used
= f
->menu_bar_items_used
;
1586 Lisp_Object
*previous_items
1587 = (Lisp_Object
*) alloca (previous_menu_items_used
1588 * sizeof (Lisp_Object
));
1590 buffer
= XWINDOW (FRAME_SELECTED_WINDOW (f
))->buffer
;
1591 specbind (Qinhibit_quit
, Qt
);
1592 /* Don't let the debugger step into this code
1593 because it is not reentrant. */
1594 specbind (Qdebug_on_next_call
, Qnil
);
1596 record_unwind_protect (Fstore_match_data
, Fmatch_data ());
1597 if (NILP (Voverriding_local_map_menu_flag
))
1599 specbind (Qoverriding_terminal_local_map
, Qnil
);
1600 specbind (Qoverriding_local_map
, Qnil
);
1603 set_buffer_internal_1 (XBUFFER (buffer
));
1605 /* Run the Lucid hook. */
1606 call1 (Vrun_hooks
, Qactivate_menubar_hook
);
1607 /* If it has changed current-menubar from previous value,
1608 really recompute the menubar from the value. */
1609 if (! NILP (Vlucid_menu_bar_dirty_flag
))
1610 call0 (Qrecompute_lucid_menubar
);
1611 call1 (Vrun_hooks
, Qmenu_bar_update_hook
);
1612 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
1614 items
= FRAME_MENU_BAR_ITEMS (f
);
1616 inhibit_garbage_collection ();
1618 /* Save the frame's previous menu bar contents data. */
1619 bcopy (XVECTOR (f
->menu_bar_vector
)->contents
, previous_items
,
1620 previous_menu_items_used
* sizeof (Lisp_Object
));
1622 /* Fill in the current menu bar contents. */
1623 menu_items
= f
->menu_bar_vector
;
1624 menu_items_allocated
= XVECTOR (menu_items
)->size
;
1626 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 3)
1628 Lisp_Object key
, string
, maps
;
1630 key
= XVECTOR (items
)->contents
[i
];
1631 string
= XVECTOR (items
)->contents
[i
+ 1];
1632 maps
= XVECTOR (items
)->contents
[i
+ 2];
1636 wv
= single_submenu (key
, string
, maps
);
1640 first_wv
->contents
= wv
;
1641 /* Don't set wv->name here; GC during the loop might relocate it. */
1646 finish_menu_items ();
1648 set_buffer_internal_1 (prev
);
1649 unbind_to (specpdl_count
, Qnil
);
1651 /* If there has been no change in the Lisp-level contents
1652 of the menu bar, skip redisplaying it. Just exit. */
1654 for (i
= 0; i
< previous_menu_items_used
; i
++)
1655 if (menu_items_used
== i
1656 || (previous_items
[i
] != XVECTOR (menu_items
)->contents
[i
]))
1658 if (i
== menu_items_used
&& i
== previous_menu_items_used
&& i
!= 0)
1660 free_menubar_widget_value_tree (first_wv
);
1666 /* Now GC cannot happen during the lifetime of the widget_value,
1667 so it's safe to store data from a Lisp_String. */
1668 wv
= first_wv
->contents
;
1669 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 3)
1672 string
= XVECTOR (items
)->contents
[i
+ 1];
1675 wv
->name
= (char *) XSTRING (string
)->data
;
1679 f
->menu_bar_vector
= menu_items
;
1680 f
->menu_bar_items_used
= menu_items_used
;
1685 /* Make a widget-value tree containing
1686 just the top level menu bar strings. */
1688 items
= FRAME_MENU_BAR_ITEMS (f
);
1689 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 3)
1693 string
= XVECTOR (items
)->contents
[i
+ 1];
1697 wv
= malloc_widget_value ();
1698 wv
->name
= (char *) XSTRING (string
)->data
;
1705 first_wv
->contents
= wv
;
1709 /* Forget what we thought we knew about what is in the
1710 detailed contents of the menu bar menus.
1711 Changing the top level always destroys the contents. */
1712 f
->menu_bar_items_used
= 0;
1715 /* Create or update the menu bar widget. */
1721 /* Disable resizing (done for Motif!) */
1722 lw_allow_resizing (f
->output_data
.x
->widget
, False
);
1724 /* The third arg is DEEP_P, which says to consider the entire
1725 menu trees we supply, rather than just the menu bar item names. */
1726 lw_modify_all_widgets (id
, first_wv
, deep_p
);
1728 /* Re-enable the edit widget to resize. */
1729 lw_allow_resizing (f
->output_data
.x
->widget
, True
);
1733 menubar_widget
= lw_create_widget ("menubar", "menubar", id
, first_wv
,
1734 f
->output_data
.x
->column_widget
,
1736 popup_activate_callback
,
1737 menubar_selection_callback
,
1738 popup_deactivate_callback
);
1739 f
->output_data
.x
->menubar_widget
= menubar_widget
;
1744 = (f
->output_data
.x
->menubar_widget
1745 ? (f
->output_data
.x
->menubar_widget
->core
.height
1746 + f
->output_data
.x
->menubar_widget
->core
.border_width
)
1750 if (FRAME_EXTERNAL_MENU_BAR (f
))
1753 XtVaGetValues (f
->output_data
.x
->column_widget
,
1754 XtNinternalBorderWidth
, &ibw
, NULL
);
1755 menubar_size
+= ibw
;
1757 #endif /* USE_LUCID */
1759 f
->output_data
.x
->menubar_height
= menubar_size
;
1762 free_menubar_widget_value_tree (first_wv
);
1764 update_frame_menubar (f
);
1769 /* Called from Fx_create_frame to create the initial menubar of a frame
1770 before it is mapped, so that the window is mapped with the menubar already
1771 there instead of us tacking it on later and thrashing the window after it
1775 initialize_frame_menubar (f
)
1778 /* This function is called before the first chance to redisplay
1779 the frame. It has to be, so the frame will have the right size. */
1780 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
1781 set_frame_menubar (f
, 1, 1);
1784 /* Get rid of the menu bar of frame F, and free its storage.
1785 This is used when deleting a frame, and when turning off the menu bar. */
1788 free_frame_menubar (f
)
1791 Widget menubar_widget
;
1794 menubar_widget
= f
->output_data
.x
->menubar_widget
;
1799 lw_destroy_all_widgets ((LWLIB_ID
) f
->output_data
.x
->id
);
1804 #endif /* USE_X_TOOLKIT */
1806 /* xmenu_show actually displays a menu using the panes and items in menu_items
1807 and returns the value selected from it.
1808 There are two versions of xmenu_show, one for Xt and one for Xlib.
1809 Both assume input is blocked by the caller. */
1811 /* F is the frame the menu is for.
1812 X and Y are the frame-relative specified position,
1813 relative to the inside upper left corner of the frame F.
1814 FOR_CLICK if this menu was invoked for a mouse click.
1815 KEYMAPS is 1 if this menu was specified with keymaps;
1816 in that case, we return a list containing the chosen item's value
1817 and perhaps also the pane's prefix.
1818 TITLE is the specified menu title.
1819 ERROR is a place to store an error message string in case of failure.
1820 (We return nil on failure, but the value doesn't actually matter.) */
1822 #ifdef USE_X_TOOLKIT
1824 /* We need a unique id for each widget handled by the Lucid Widget
1827 For the main windows, and popup menus, we use this counter,
1828 which we increment each time after use. This starts from 1<<16.
1830 For menu bars, we use numbers starting at 0, counted in
1831 next_menubar_widget_id. */
1832 LWLIB_ID widget_id_tick
;
1835 static Lisp_Object
*volatile menu_item_selection
;
1837 static Lisp_Object
*menu_item_selection
;
1841 popup_selection_callback (widget
, id
, client_data
)
1844 XtPointer client_data
;
1846 menu_item_selection
= (Lisp_Object
*) client_data
;
1850 xmenu_show (f
, x
, y
, for_click
, keymaps
, title
, error
)
1864 widget_value
*wv
, *save_wv
= 0, *first_wv
= 0, *prev_wv
= 0;
1865 widget_value
**submenu_stack
1866 = (widget_value
**) alloca (menu_items_used
* sizeof (widget_value
*));
1867 Lisp_Object
*subprefix_stack
1868 = (Lisp_Object
*) alloca (menu_items_used
* sizeof (Lisp_Object
));
1869 int submenu_depth
= 0;
1870 XButtonPressedEvent dummy
;
1873 int next_release_must_exit
= 0;
1877 if (menu_items_used
<= MENU_ITEMS_PANE_LENGTH
)
1879 *error
= "Empty menu";
1883 /* Create a tree of widget_value objects
1884 representing the panes and their items. */
1885 wv
= malloc_widget_value ();
1892 /* Loop over all panes and items, filling in the tree. */
1894 while (i
< menu_items_used
)
1896 if (EQ (XVECTOR (menu_items
)->contents
[i
], Qnil
))
1898 submenu_stack
[submenu_depth
++] = save_wv
;
1904 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qlambda
))
1907 save_wv
= submenu_stack
[--submenu_depth
];
1911 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qt
)
1912 && submenu_depth
!= 0)
1913 i
+= MENU_ITEMS_PANE_LENGTH
;
1914 /* Ignore a nil in the item list.
1915 It's meaningful only for dialog boxes. */
1916 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qquote
))
1918 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qt
))
1920 /* Create a new pane. */
1921 Lisp_Object pane_name
, prefix
;
1923 pane_name
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_PANE_NAME
];
1924 prefix
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_PANE_PREFIX
];
1925 pane_string
= (NILP (pane_name
)
1926 ? "" : (char *) XSTRING (pane_name
)->data
);
1927 /* If there is just one top-level pane, put all its items directly
1928 under the top-level menu. */
1929 if (menu_items_n_panes
== 1)
1932 /* If the pane has a meaningful name,
1933 make the pane a top-level menu item
1934 with its items as a submenu beneath it. */
1935 if (!keymaps
&& strcmp (pane_string
, ""))
1937 wv
= malloc_widget_value ();
1941 first_wv
->contents
= wv
;
1942 wv
->name
= pane_string
;
1943 if (keymaps
&& !NILP (prefix
))
1950 else if (first_pane
)
1956 i
+= MENU_ITEMS_PANE_LENGTH
;
1960 /* Create a new item within current pane. */
1961 Lisp_Object item_name
, enable
, descrip
, def
;
1962 item_name
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_NAME
];
1963 enable
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_ENABLE
];
1965 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_EQUIV_KEY
];
1966 def
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_DEFINITION
];
1968 wv
= malloc_widget_value ();
1972 save_wv
->contents
= wv
;
1973 wv
->name
= (char *) XSTRING (item_name
)->data
;
1974 if (!NILP (descrip
))
1975 wv
->key
= (char *) XSTRING (descrip
)->data
;
1977 /* If this item has a null value,
1978 make the call_data null so that it won't display a box
1979 when the mouse is on it. */
1981 = (!NILP (def
) ? (void *) &XVECTOR (menu_items
)->contents
[i
] : 0);
1982 wv
->enabled
= !NILP (enable
);
1985 i
+= MENU_ITEMS_ITEM_LENGTH
;
1989 /* Deal with the title, if it is non-nil. */
1992 widget_value
*wv_title
= malloc_widget_value ();
1993 widget_value
*wv_sep1
= malloc_widget_value ();
1994 widget_value
*wv_sep2
= malloc_widget_value ();
1996 wv_sep2
->name
= "--";
1997 wv_sep2
->next
= first_wv
->contents
;
1999 wv_sep1
->name
= "--";
2000 wv_sep1
->next
= wv_sep2
;
2002 wv_title
->name
= (char *) XSTRING (title
)->data
;
2003 wv_title
->enabled
= True
;
2004 wv_title
->next
= wv_sep1
;
2005 first_wv
->contents
= wv_title
;
2008 /* Actually create the menu. */
2009 menu_id
= widget_id_tick
++;
2010 menu
= lw_create_widget ("popup", first_wv
->name
, menu_id
, first_wv
,
2011 f
->output_data
.x
->widget
, 1, 0,
2012 popup_selection_callback
,
2013 popup_deactivate_callback
);
2015 /* Adjust coordinates to relative to the outer (window manager) window. */
2018 int win_x
= 0, win_y
= 0;
2020 /* Find the position of the outside upper-left corner of
2021 the inner window, with respect to the outer window. */
2022 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
2025 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
2027 /* From-window, to-window. */
2028 f
->output_data
.x
->window_desc
,
2029 f
->output_data
.x
->parent_desc
,
2031 /* From-position, to-position. */
2032 0, 0, &win_x
, &win_y
,
2034 /* Child of window. */
2042 /* Adjust coordinates to be root-window-relative. */
2043 x
+= f
->output_data
.x
->left_pos
;
2044 y
+= f
->output_data
.x
->top_pos
;
2046 dummy
.type
= ButtonPress
;
2048 dummy
.send_event
= 0;
2049 dummy
.display
= FRAME_X_DISPLAY (f
);
2050 dummy
.time
= CurrentTime
;
2052 dummy
.root
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
2053 dummy
.window
= dummy
.root
;
2054 dummy
.subwindow
= dummy
.root
;
2060 /* Don't allow any geometry request from the user. */
2061 XtSetArg (av
[ac
], XtNgeometry
, 0); ac
++;
2062 XtSetValues (menu
, av
, ac
);
2064 /* Free the widget_value objects we used to specify the contents. */
2065 free_menubar_widget_value_tree (first_wv
);
2067 /* No selection has been chosen yet. */
2068 menu_item_selection
= 0;
2070 /* Display the menu. */
2071 lw_popup_menu (menu
, &dummy
);
2072 popup_activated_flag
= 1;
2074 /* Process events that apply to the menu. */
2075 popup_get_selection ((XEvent
*) 0, FRAME_X_DISPLAY_INFO (f
), menu_id
);
2077 /* fp turned off the following statement and wrote a comment
2078 that it is unnecessary--that the menu has already disappeared.
2079 Nowadays the menu disappears ok, all right, but
2080 we need to delete the widgets or multiple ones will pile up. */
2081 lw_destroy_all_widgets (menu_id
);
2083 /* Find the selected item, and its pane, to return
2084 the proper value. */
2085 if (menu_item_selection
!= 0)
2087 Lisp_Object prefix
, entry
;
2091 while (i
< menu_items_used
)
2093 if (EQ (XVECTOR (menu_items
)->contents
[i
], Qnil
))
2095 subprefix_stack
[submenu_depth
++] = prefix
;
2099 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qlambda
))
2101 prefix
= subprefix_stack
[--submenu_depth
];
2104 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qt
))
2107 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_PANE_PREFIX
];
2108 i
+= MENU_ITEMS_PANE_LENGTH
;
2110 /* Ignore a nil in the item list.
2111 It's meaningful only for dialog boxes. */
2112 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qquote
))
2117 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_VALUE
];
2118 if (menu_item_selection
== &XVECTOR (menu_items
)->contents
[i
])
2124 entry
= Fcons (entry
, Qnil
);
2126 entry
= Fcons (prefix
, entry
);
2127 for (j
= submenu_depth
- 1; j
>= 0; j
--)
2128 if (!NILP (subprefix_stack
[j
]))
2129 entry
= Fcons (subprefix_stack
[j
], entry
);
2133 i
+= MENU_ITEMS_ITEM_LENGTH
;
2142 dialog_selection_callback (widget
, id
, client_data
)
2145 XtPointer client_data
;
2147 /* The EMACS_INT cast avoids a warning. There's no problem
2148 as long as pointers have enough bits to hold small integers. */
2149 if ((int) (EMACS_INT
) client_data
!= -1)
2150 menu_item_selection
= (Lisp_Object
*) client_data
;
2152 lw_destroy_all_widgets (id
);
2154 popup_activated_flag
= 0;
2157 static char * button_names
[] = {
2158 "button1", "button2", "button3", "button4", "button5",
2159 "button6", "button7", "button8", "button9", "button10" };
2162 xdialog_show (f
, keymaps
, title
, error
)
2168 int i
, nb_buttons
=0;
2171 char dialog_name
[6];
2173 widget_value
*wv
, *save_wv
= 0, *first_wv
= 0, *prev_wv
= 0;
2175 /* Number of elements seen so far, before boundary. */
2177 /* 1 means we've seen the boundary between left-hand elts and right-hand. */
2178 int boundary_seen
= 0;
2182 if (menu_items_n_panes
> 1)
2184 *error
= "Multiple panes in dialog box";
2188 /* Create a tree of widget_value objects
2189 representing the text label and buttons. */
2191 Lisp_Object pane_name
, prefix
;
2193 pane_name
= XVECTOR (menu_items
)->contents
[MENU_ITEMS_PANE_NAME
];
2194 prefix
= XVECTOR (menu_items
)->contents
[MENU_ITEMS_PANE_PREFIX
];
2195 pane_string
= (NILP (pane_name
)
2196 ? "" : (char *) XSTRING (pane_name
)->data
);
2197 prev_wv
= malloc_widget_value ();
2198 prev_wv
->value
= pane_string
;
2199 if (keymaps
&& !NILP (prefix
))
2201 prev_wv
->enabled
= 1;
2202 prev_wv
->name
= "message";
2205 /* Loop over all panes and items, filling in the tree. */
2206 i
= MENU_ITEMS_PANE_LENGTH
;
2207 while (i
< menu_items_used
)
2210 /* Create a new item within current pane. */
2211 Lisp_Object item_name
, enable
, descrip
;
2212 item_name
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_NAME
];
2213 enable
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_ENABLE
];
2215 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_EQUIV_KEY
];
2217 if (NILP (item_name
))
2219 free_menubar_widget_value_tree (first_wv
);
2220 *error
= "Submenu in dialog items";
2223 if (EQ (item_name
, Qquote
))
2225 /* This is the boundary between left-side elts
2226 and right-side elts. Stop incrementing right_count. */
2231 if (nb_buttons
>= 10)
2233 free_menubar_widget_value_tree (first_wv
);
2234 *error
= "Too many dialog items";
2238 wv
= malloc_widget_value ();
2240 wv
->name
= (char *) button_names
[nb_buttons
];
2241 if (!NILP (descrip
))
2242 wv
->key
= (char *) XSTRING (descrip
)->data
;
2243 wv
->value
= (char *) XSTRING (item_name
)->data
;
2244 wv
->call_data
= (void *) &XVECTOR (menu_items
)->contents
[i
];
2245 wv
->enabled
= !NILP (enable
);
2248 if (! boundary_seen
)
2252 i
+= MENU_ITEMS_ITEM_LENGTH
;
2255 /* If the boundary was not specified,
2256 by default put half on the left and half on the right. */
2257 if (! boundary_seen
)
2258 left_count
= nb_buttons
- nb_buttons
/ 2;
2260 wv
= malloc_widget_value ();
2261 wv
->name
= dialog_name
;
2263 /* Dialog boxes use a really stupid name encoding
2264 which specifies how many buttons to use
2265 and how many buttons are on the right.
2266 The Q means something also. */
2267 dialog_name
[0] = 'Q';
2268 dialog_name
[1] = '0' + nb_buttons
;
2269 dialog_name
[2] = 'B';
2270 dialog_name
[3] = 'R';
2271 /* Number of buttons to put on the right. */
2272 dialog_name
[4] = '0' + nb_buttons
- left_count
;
2274 wv
->contents
= first_wv
;
2278 /* Actually create the dialog. */
2279 dialog_id
= widget_id_tick
++;
2280 menu
= lw_create_widget (first_wv
->name
, "dialog", dialog_id
, first_wv
,
2281 f
->output_data
.x
->widget
, 1, 0,
2282 dialog_selection_callback
, 0);
2283 lw_modify_all_widgets (dialog_id
, first_wv
->contents
, True
);
2284 /* Free the widget_value objects we used to specify the contents. */
2285 free_menubar_widget_value_tree (first_wv
);
2287 /* No selection has been chosen yet. */
2288 menu_item_selection
= 0;
2290 /* Display the menu. */
2291 lw_pop_up_all_widgets (dialog_id
);
2292 popup_activated_flag
= 1;
2294 /* Process events that apply to the menu. */
2295 popup_get_selection ((XEvent
*) 0, FRAME_X_DISPLAY_INFO (f
), dialog_id
);
2297 lw_destroy_all_widgets (dialog_id
);
2299 /* Find the selected item, and its pane, to return
2300 the proper value. */
2301 if (menu_item_selection
!= 0)
2307 while (i
< menu_items_used
)
2311 if (EQ (XVECTOR (menu_items
)->contents
[i
], Qt
))
2314 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_PANE_PREFIX
];
2315 i
+= MENU_ITEMS_PANE_LENGTH
;
2320 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_VALUE
];
2321 if (menu_item_selection
== &XVECTOR (menu_items
)->contents
[i
])
2325 entry
= Fcons (entry
, Qnil
);
2327 entry
= Fcons (prefix
, entry
);
2331 i
+= MENU_ITEMS_ITEM_LENGTH
;
2338 #else /* not USE_X_TOOLKIT */
2341 xmenu_show (f
, x
, y
, for_click
, keymaps
, title
, error
)
2351 int pane
, selidx
, lpane
, status
;
2352 Lisp_Object entry
, pane_prefix
;
2354 int ulx
, uly
, width
, height
;
2355 int dispwidth
, dispheight
;
2359 unsigned int dummy_uint
;
2362 if (menu_items_n_panes
== 0)
2365 if (menu_items_used
<= MENU_ITEMS_PANE_LENGTH
)
2367 *error
= "Empty menu";
2371 /* Figure out which root window F is on. */
2372 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &root
,
2373 &dummy_int
, &dummy_int
, &dummy_uint
, &dummy_uint
,
2374 &dummy_uint
, &dummy_uint
);
2376 /* Make the menu on that window. */
2377 menu
= XMenuCreate (FRAME_X_DISPLAY (f
), root
, "emacs");
2380 *error
= "Can't create menu";
2384 #ifdef HAVE_X_WINDOWS
2385 /* Adjust coordinates to relative to the outer (window manager) window. */
2388 int win_x
= 0, win_y
= 0;
2390 /* Find the position of the outside upper-left corner of
2391 the inner window, with respect to the outer window. */
2392 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
2395 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
2397 /* From-window, to-window. */
2398 f
->output_data
.x
->window_desc
,
2399 f
->output_data
.x
->parent_desc
,
2401 /* From-position, to-position. */
2402 0, 0, &win_x
, &win_y
,
2404 /* Child of window. */
2411 #endif /* HAVE_X_WINDOWS */
2413 /* Adjust coordinates to be root-window-relative. */
2414 x
+= f
->output_data
.x
->left_pos
;
2415 y
+= f
->output_data
.x
->top_pos
;
2417 /* Create all the necessary panes and their items. */
2419 while (i
< menu_items_used
)
2421 if (EQ (XVECTOR (menu_items
)->contents
[i
], Qt
))
2423 /* Create a new pane. */
2424 Lisp_Object pane_name
, prefix
;
2427 pane_name
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_PANE_NAME
];
2428 prefix
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_PANE_PREFIX
];
2429 pane_string
= (NILP (pane_name
)
2430 ? "" : (char *) XSTRING (pane_name
)->data
);
2431 if (keymaps
&& !NILP (prefix
))
2434 lpane
= XMenuAddPane (FRAME_X_DISPLAY (f
), menu
, pane_string
, TRUE
);
2435 if (lpane
== XM_FAILURE
)
2437 XMenuDestroy (FRAME_X_DISPLAY (f
), menu
);
2438 *error
= "Can't create pane";
2441 i
+= MENU_ITEMS_PANE_LENGTH
;
2443 /* Find the width of the widest item in this pane. */
2446 while (j
< menu_items_used
)
2449 item
= XVECTOR (menu_items
)->contents
[j
];
2457 width
= XSTRING (item
)->size
;
2458 if (width
> maxwidth
)
2461 j
+= MENU_ITEMS_ITEM_LENGTH
;
2464 /* Ignore a nil in the item list.
2465 It's meaningful only for dialog boxes. */
2466 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qquote
))
2470 /* Create a new item within current pane. */
2471 Lisp_Object item_name
, enable
, descrip
;
2472 unsigned char *item_data
;
2474 item_name
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_NAME
];
2475 enable
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_ENABLE
];
2477 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_EQUIV_KEY
];
2478 if (!NILP (descrip
))
2480 int gap
= maxwidth
- XSTRING (item_name
)->size
;
2483 spacer
= Fmake_string (make_number (gap
), make_number (' '));
2484 item_name
= concat2 (item_name
, spacer
);
2485 item_name
= concat2 (item_name
, descrip
);
2486 item_data
= XSTRING (item_name
)->data
;
2488 /* if alloca is fast, use that to make the space,
2489 to reduce gc needs. */
2491 = (unsigned char *) alloca (maxwidth
2492 + XSTRING (descrip
)->size
+ 1);
2493 bcopy (XSTRING (item_name
)->data
, item_data
,
2494 XSTRING (item_name
)->size
);
2495 for (j
= XSTRING (item_name
)->size
; j
< maxwidth
; j
++)
2497 bcopy (XSTRING (descrip
)->data
, item_data
+ j
,
2498 XSTRING (descrip
)->size
);
2499 item_data
[j
+ XSTRING (descrip
)->size
] = 0;
2503 item_data
= XSTRING (item_name
)->data
;
2505 if (XMenuAddSelection (FRAME_X_DISPLAY (f
),
2506 menu
, lpane
, 0, item_data
,
2510 XMenuDestroy (FRAME_X_DISPLAY (f
), menu
);
2511 *error
= "Can't add selection to menu";
2514 i
+= MENU_ITEMS_ITEM_LENGTH
;
2518 /* All set and ready to fly. */
2519 XMenuRecompute (FRAME_X_DISPLAY (f
), menu
);
2520 dispwidth
= DisplayWidth (FRAME_X_DISPLAY (f
),
2521 XScreenNumberOfScreen (FRAME_X_SCREEN (f
)));
2522 dispheight
= DisplayHeight (FRAME_X_DISPLAY (f
),
2523 XScreenNumberOfScreen (FRAME_X_SCREEN (f
)));
2524 x
= min (x
, dispwidth
);
2525 y
= min (y
, dispheight
);
2528 XMenuLocate (FRAME_X_DISPLAY (f
), menu
, 0, 0, x
, y
,
2529 &ulx
, &uly
, &width
, &height
);
2530 if (ulx
+width
> dispwidth
)
2532 x
-= (ulx
+ width
) - dispwidth
;
2533 ulx
= dispwidth
- width
;
2535 if (uly
+height
> dispheight
)
2537 y
-= (uly
+ height
) - dispheight
;
2538 uly
= dispheight
- height
;
2540 if (ulx
< 0) x
-= ulx
;
2541 if (uly
< 0) y
-= uly
;
2543 XMenuSetAEQ (menu
, TRUE
);
2544 XMenuSetFreeze (menu
, TRUE
);
2547 status
= XMenuActivate (FRAME_X_DISPLAY (f
), menu
, &pane
, &selidx
,
2548 x
, y
, ButtonReleaseMask
, &datap
);
2551 #ifdef HAVE_X_WINDOWS
2552 /* Assume the mouse has moved out of the X window.
2553 If it has actually moved in, we will get an EnterNotify. */
2554 x_mouse_leave (FRAME_X_DISPLAY_INFO (f
));
2561 fprintf (stderr
, "pane= %d line = %d\n", panes
, selidx
);
2564 /* Find the item number SELIDX in pane number PANE. */
2566 while (i
< menu_items_used
)
2568 if (EQ (XVECTOR (menu_items
)->contents
[i
], Qt
))
2572 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_PANE_PREFIX
];
2574 i
+= MENU_ITEMS_PANE_LENGTH
;
2583 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_VALUE
];
2586 entry
= Fcons (entry
, Qnil
);
2587 if (!NILP (pane_prefix
))
2588 entry
= Fcons (pane_prefix
, entry
);
2594 i
+= MENU_ITEMS_ITEM_LENGTH
;
2600 *error
= "Can't activate menu";
2606 XMenuDestroy (FRAME_X_DISPLAY (f
), menu
);
2608 #ifdef HAVE_X_WINDOWS
2609 /* State that no mouse buttons are now held.
2610 (The oldXMenu code doesn't track this info for us.)
2611 That is not necessarily true, but the fiction leads to reasonable
2612 results, and it is a pain to ask which are actually held now. */
2613 FRAME_X_DISPLAY_INFO (f
)->grabbed
= 0;
2619 #endif /* not USE_X_TOOLKIT */
2623 staticpro (&menu_items
);
2626 Qdebug_on_next_call
= intern ("debug-on-next-call");
2627 staticpro (&Qdebug_on_next_call
);
2629 #ifdef USE_X_TOOLKIT
2630 widget_id_tick
= (1<<16);
2631 next_menubar_widget_id
= 1;
2634 defsubr (&Sx_popup_menu
);
2635 defsubr (&Sx_popup_dialog
);