1 /* X Communication module for terminals which understand the X protocol.
2 Copyright (C) 1986, 1988, 1993, 1994 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* X pop-up deck-of-cards menu facility for gnuemacs.
23 * Written by Jon Arnold and Roman Budzianowski
24 * Mods and rewrite by Robert Krawitz
28 /* Modified by Fred Pierresteguy on December 93
29 to make the popup menus and menubar use the Xt. */
31 /* Rewritten for clarity and GC protection by rms in Feb 94. */
33 /* On 4.3 this loses if it comes after xterm.h. */
39 #include "termhooks.h"
43 #include "blockinput.h"
52 /* This may include sys/types.h, and that somehow loses
53 if this is not done before the other system files. */
57 /* Load sys/types.h if not already loaded.
58 In some systems loading it twice is suicidal. */
60 #include <sys/types.h>
63 #include "dispextern.h"
68 #include <X11/IntrinsicP.h>
69 #include <X11/CoreP.h>
70 #include <X11/StringDefs.h>
71 #include <X11/Shell.h>
73 #include <X11/Xaw/Paned.h>
74 #endif /* USE_LUCID */
75 #include "../lwlib/lwlib.h"
76 #else /* not USE_X_TOOLKIT */
77 #include "../oldXMenu/XMenu.h"
78 #endif /* not USE_X_TOOLKIT */
79 #endif /* HAVE_X_WINDOWS */
81 #define min(x,y) (((x) < (y)) ? (x) : (y))
82 #define max(x,y) (((x) > (y)) ? (x) : (y))
89 Lisp_Object Qdebug_on_next_call
;
91 Lisp_Object Qmenu_alias
;
93 extern Lisp_Object Qmenu_enable
;
94 extern Lisp_Object Qmenu_bar
;
95 extern Lisp_Object Qmouse_click
, Qevent_kind
;
97 extern Lisp_Object Vdefine_key_rebound_commands
;
99 extern Lisp_Object Voverriding_local_map
;
100 extern Lisp_Object Voverriding_local_map_menu_flag
;
102 extern Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
104 extern Lisp_Object Qmenu_bar_update_hook
;
107 extern void set_frame_menubar ();
108 extern void process_expose_from_menu ();
109 extern XtAppContext Xt_app_con
;
111 static Lisp_Object
xdialog_show ();
112 void popup_get_selection ();
115 static Lisp_Object
xmenu_show ();
116 static void keymap_panes ();
117 static void single_keymap_panes ();
118 static void list_of_panes ();
119 static void list_of_items ();
121 /* This holds a Lisp vector that holds the results of decoding
122 the keymaps or alist-of-alists that specify a menu.
124 It describes the panes and items within the panes.
126 Each pane is described by 3 elements in the vector:
127 t, the pane name, the pane's prefix key.
128 Then follow the pane's items, with 5 elements per item:
129 the item string, the enable flag, the item's value,
130 the definition, and the equivalent keyboard key's description string.
132 In some cases, multiple levels of menus may be described.
133 A single vector slot containing nil indicates the start of a submenu.
134 A single vector slot containing lambda indicates the end of a submenu.
135 The submenu follows a menu item which is the way to reach the submenu.
137 A single vector slot containing quote indicates that the
138 following items should appear on the right of a dialog box.
140 Using a Lisp vector to hold this information while we decode it
141 takes care of protecting all the data from GC. */
143 #define MENU_ITEMS_PANE_NAME 1
144 #define MENU_ITEMS_PANE_PREFIX 2
145 #define MENU_ITEMS_PANE_LENGTH 3
147 #define MENU_ITEMS_ITEM_NAME 0
148 #define MENU_ITEMS_ITEM_ENABLE 1
149 #define MENU_ITEMS_ITEM_VALUE 2
150 #define MENU_ITEMS_ITEM_EQUIV_KEY 3
151 #define MENU_ITEMS_ITEM_DEFINITION 4
152 #define MENU_ITEMS_ITEM_LENGTH 5
154 static Lisp_Object menu_items
;
156 /* Number of slots currently allocated in menu_items. */
157 static int menu_items_allocated
;
159 /* This is the index in menu_items of the first empty slot. */
160 static int menu_items_used
;
162 /* The number of panes currently recorded in menu_items,
163 excluding those within submenus. */
164 static int menu_items_n_panes
;
166 /* Current depth within submenus. */
167 static int menu_items_submenu_depth
;
169 /* Flag which when set indicates a dialog or menu has been posted by
170 Xt on behalf of one of the widget sets. */
171 static int popup_activated_flag
;
173 static int next_menubar_widget_id
;
177 /* Return the frame whose ->output_data.x->id equals ID, or 0 if none. */
179 static struct frame
*
180 menubar_id_to_frame (id
)
183 Lisp_Object tail
, frame
;
186 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCONS (tail
)->cdr
)
188 frame
= XCONS (tail
)->car
;
189 if (!GC_FRAMEP (frame
))
192 if (f
->output_data
.nothing
== 1)
194 if (f
->output_data
.x
->id
== id
)
202 /* Initialize the menu_items structure if we haven't already done so.
203 Also mark it as currently empty. */
208 if (NILP (menu_items
))
210 menu_items_allocated
= 60;
211 menu_items
= Fmake_vector (make_number (menu_items_allocated
), Qnil
);
215 menu_items_n_panes
= 0;
216 menu_items_submenu_depth
= 0;
219 /* Call at the end of generating the data in menu_items.
220 This fills in the number of items in the last pane. */
227 /* Call when finished using the data for the current menu
231 discard_menu_items ()
233 /* Free the structure if it is especially large.
234 Otherwise, hold on to it, to save time. */
235 if (menu_items_allocated
> 200)
238 menu_items_allocated
= 0;
242 /* Make the menu_items vector twice as large. */
248 int old_size
= menu_items_allocated
;
251 menu_items_allocated
*= 2;
252 menu_items
= Fmake_vector (make_number (menu_items_allocated
), Qnil
);
253 bcopy (XVECTOR (old
)->contents
, XVECTOR (menu_items
)->contents
,
254 old_size
* sizeof (Lisp_Object
));
257 /* Begin a submenu. */
260 push_submenu_start ()
262 if (menu_items_used
+ 1 > menu_items_allocated
)
265 XVECTOR (menu_items
)->contents
[menu_items_used
++] = Qnil
;
266 menu_items_submenu_depth
++;
274 if (menu_items_used
+ 1 > menu_items_allocated
)
277 XVECTOR (menu_items
)->contents
[menu_items_used
++] = Qlambda
;
278 menu_items_submenu_depth
--;
281 /* Indicate boundary between left and right. */
284 push_left_right_boundary ()
286 if (menu_items_used
+ 1 > menu_items_allocated
)
289 XVECTOR (menu_items
)->contents
[menu_items_used
++] = Qquote
;
292 /* Start a new menu pane in menu_items..
293 NAME is the pane name. PREFIX_VEC is a prefix key for this pane. */
296 push_menu_pane (name
, prefix_vec
)
297 Lisp_Object name
, prefix_vec
;
299 if (menu_items_used
+ MENU_ITEMS_PANE_LENGTH
> menu_items_allocated
)
302 if (menu_items_submenu_depth
== 0)
303 menu_items_n_panes
++;
304 XVECTOR (menu_items
)->contents
[menu_items_used
++] = Qt
;
305 XVECTOR (menu_items
)->contents
[menu_items_used
++] = name
;
306 XVECTOR (menu_items
)->contents
[menu_items_used
++] = prefix_vec
;
309 /* Push one menu item into the current pane.
310 NAME is the string to display. ENABLE if non-nil means
311 this item can be selected. KEY is the key generated by
312 choosing this item, or nil if this item doesn't really have a definition.
313 DEF is the definition of this item.
314 EQUIV is the textual description of the keyboard equivalent for
315 this item (or nil if none). */
318 push_menu_item (name
, enable
, key
, def
, equiv
)
319 Lisp_Object name
, enable
, key
, def
, equiv
;
321 if (menu_items_used
+ MENU_ITEMS_ITEM_LENGTH
> menu_items_allocated
)
324 XVECTOR (menu_items
)->contents
[menu_items_used
++] = name
;
325 XVECTOR (menu_items
)->contents
[menu_items_used
++] = enable
;
326 XVECTOR (menu_items
)->contents
[menu_items_used
++] = key
;
327 XVECTOR (menu_items
)->contents
[menu_items_used
++] = equiv
;
328 XVECTOR (menu_items
)->contents
[menu_items_used
++] = def
;
331 /* Figure out the current keyboard equivalent of a menu item ITEM1.
332 The item string for menu display should be ITEM_STRING.
333 Store the equivalent keyboard key sequence's
334 textual description into *DESCRIP_PTR.
335 Also cache them in the item itself.
336 Return the real definition to execute. */
339 menu_item_equiv_key (item_string
, item1
, descrip_ptr
)
340 Lisp_Object item_string
;
342 Lisp_Object
*descrip_ptr
;
344 /* This is the real definition--the function to run. */
346 /* This is the sublist that records cached equiv key data
347 so we can save time. */
348 Lisp_Object cachelist
;
349 /* These are the saved equivalent keyboard key sequence
350 and its key-description. */
351 Lisp_Object savedkey
, descrip
;
354 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
356 /* If a help string follows the item string, skip it. */
357 if (CONSP (XCONS (item1
)->cdr
)
358 && STRINGP (XCONS (XCONS (item1
)->cdr
)->car
))
359 item1
= XCONS (item1
)->cdr
;
363 /* Get out the saved equivalent-keyboard-key info. */
364 cachelist
= savedkey
= descrip
= Qnil
;
365 if (CONSP (def
) && CONSP (XCONS (def
)->car
)
366 && (NILP (XCONS (XCONS (def
)->car
)->car
)
367 || VECTORP (XCONS (XCONS (def
)->car
)->car
)))
369 cachelist
= XCONS (def
)->car
;
370 def
= XCONS (def
)->cdr
;
371 savedkey
= XCONS (cachelist
)->car
;
372 descrip
= XCONS (cachelist
)->cdr
;
375 GCPRO4 (def
, def1
, savedkey
, descrip
);
377 /* Is it still valid? */
379 if (!NILP (savedkey
))
380 def1
= Fkey_binding (savedkey
, Qnil
);
381 /* If not, update it. */
383 /* If the command is an alias for another
384 (such as easymenu.el and lmenu.el set it up),
385 check if the original command matches the cached command. */
386 && !(SYMBOLP (def
) && SYMBOLP (XSYMBOL (def
)->function
)
387 && EQ (def1
, XSYMBOL (def
)->function
))
388 /* If something had no key binding before, don't recheck it
389 because that is too slow--except if we have a list of rebound
390 commands in Vdefine_key_rebound_commands, do recheck any command
391 that appears in that list. */
392 && (NILP (cachelist
) || !NILP (savedkey
)
393 || (! EQ (Qt
, Vdefine_key_rebound_commands
)
394 && !NILP (Fmemq (def
, Vdefine_key_rebound_commands
)))))
398 /* If the command is an alias for another
399 (such as easymenu.el and lmenu.el set it up),
400 see if the original command name has equivalent keys. */
401 if (SYMBOLP (def
) && SYMBOLP (XSYMBOL (def
)->function
)
402 && ! NILP (Fget (def
, Qmenu_alias
)))
403 savedkey
= Fwhere_is_internal (XSYMBOL (def
)->function
,
406 /* Otherwise look up the specified command itself.
407 We don't try both, because that makes easymenu menus slow. */
408 savedkey
= Fwhere_is_internal (def
, Qnil
, Qt
, Qnil
);
410 if (!NILP (savedkey
))
412 descrip
= Fkey_description (savedkey
);
413 descrip
= concat2 (make_string (" (", 3), descrip
);
414 descrip
= concat2 (descrip
, make_string (")", 1));
418 /* Cache the data we just got in a sublist of the menu binding. */
419 if (NILP (cachelist
))
421 CHECK_IMPURE (item1
);
422 XCONS (item1
)->cdr
= Fcons (Fcons (savedkey
, descrip
), def
);
426 XCONS (cachelist
)->car
= savedkey
;
427 XCONS (cachelist
)->cdr
= descrip
;
431 *descrip_ptr
= descrip
;
435 /* This is used as the handler when calling internal_condition_case_1. */
438 menu_item_enabled_p_1 (arg
)
441 /* If we got a quit from within the menu computation,
442 quit all the way out of it. This takes care of C-] in the debugger. */
443 if (CONSP (arg
) && EQ (XCONS (arg
)->car
, Qquit
))
444 Fsignal (Qquit
, Qnil
);
449 /* Return non-nil if the command DEF is enabled when used as a menu item.
450 This is based on looking for a menu-enable property.
451 If NOTREAL is set, don't bother really computing this. */
454 menu_item_enabled_p (def
, notreal
)
458 Lisp_Object enabled
, tem
;
465 /* No property, or nil, means enable.
466 Otherwise, enable if value is not nil. */
467 tem
= Fget (def
, Qmenu_enable
);
469 /* (condition-case nil (eval tem)
471 enabled
= internal_condition_case_1 (Feval
, tem
, Qerror
,
472 menu_item_enabled_p_1
);
477 /* Look through KEYMAPS, a vector of keymaps that is NMAPS long,
478 and generate menu panes for them in menu_items.
479 If NOTREAL is nonzero,
480 don't bother really computing whether an item is enabled. */
483 keymap_panes (keymaps
, nmaps
, notreal
)
484 Lisp_Object
*keymaps
;
492 /* Loop over the given keymaps, making a pane for each map.
493 But don't make a pane that is empty--ignore that map instead.
494 P is the number of panes we have made so far. */
495 for (mapno
= 0; mapno
< nmaps
; mapno
++)
496 single_keymap_panes (keymaps
[mapno
], Qnil
, Qnil
, notreal
);
498 finish_menu_items ();
501 /* This is a recursive subroutine of keymap_panes.
502 It handles one keymap, KEYMAP.
503 The other arguments are passed along
504 or point to local variables of the previous function.
505 If NOTREAL is nonzero,
506 don't bother really computing whether an item is enabled. */
509 single_keymap_panes (keymap
, pane_name
, prefix
, notreal
)
511 Lisp_Object pane_name
;
515 Lisp_Object pending_maps
;
516 Lisp_Object tail
, item
, item1
, item_string
, table
;
517 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
521 push_menu_pane (pane_name
, prefix
);
523 for (tail
= keymap
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
525 /* Look at each key binding, and if it has a menu string,
526 make a menu item from it. */
527 item
= XCONS (tail
)->car
;
530 item1
= XCONS (item
)->cdr
;
533 item_string
= XCONS (item1
)->car
;
534 if (STRINGP (item_string
))
536 /* This is the real definition--the function to run. */
538 /* These are the saved equivalent keyboard key sequence
539 and its key-description. */
541 Lisp_Object tem
, enabled
;
543 /* GCPRO because ...enabled_p will call eval
544 and ..._equiv_key may autoload something.
545 Protecting KEYMAP preserves everything we use;
546 aside from that, must protect whatever might be
547 a string. Since there's no GCPRO5, we refetch
548 item_string instead of protecting it. */
549 descrip
= def
= Qnil
;
550 GCPRO4 (keymap
, pending_maps
, def
, descrip
);
552 def
= menu_item_equiv_key (item_string
, item1
, &descrip
);
553 enabled
= menu_item_enabled_p (def
, notreal
);
557 item_string
= XCONS (item1
)->car
;
559 tem
= Fkeymapp (def
);
560 if (XSTRING (item_string
)->data
[0] == '@' && !NILP (tem
))
561 pending_maps
= Fcons (Fcons (def
, Fcons (item_string
, XCONS (item
)->car
)),
566 GCPRO4 (keymap
, pending_maps
, descrip
, item_string
);
567 submap
= get_keymap_1 (def
, 0, 1);
569 #ifndef USE_X_TOOLKIT
570 /* Indicate visually that this is a submenu. */
572 item_string
= concat2 (item_string
,
573 build_string (" >"));
575 /* If definition is nil, pass nil as the key. */
576 push_menu_item (item_string
, enabled
,
577 XCONS (item
)->car
, def
,
580 /* Display a submenu using the toolkit. */
583 push_submenu_start ();
584 single_keymap_panes (submap
, Qnil
,
585 XCONS (item
)->car
, notreal
);
593 else if (VECTORP (item
))
595 /* Loop over the char values represented in the vector. */
596 int len
= XVECTOR (item
)->size
;
598 for (c
= 0; c
< len
; c
++)
600 Lisp_Object character
;
601 XSETFASTINT (character
, c
);
602 item1
= XVECTOR (item
)->contents
[c
];
605 item_string
= XCONS (item1
)->car
;
606 if (STRINGP (item_string
))
610 /* These are the saved equivalent keyboard key sequence
611 and its key-description. */
613 Lisp_Object tem
, enabled
;
615 /* GCPRO because ...enabled_p will call eval
616 and ..._equiv_key may autoload something.
617 Protecting KEYMAP preserves everything we use;
618 aside from that, must protect whatever might be
619 a string. Since there's no GCPRO5, we refetch
620 item_string instead of protecting it. */
621 GCPRO4 (keymap
, pending_maps
, def
, descrip
);
622 descrip
= def
= Qnil
;
624 def
= menu_item_equiv_key (item_string
, item1
, &descrip
);
625 enabled
= menu_item_enabled_p (def
, notreal
);
629 item_string
= XCONS (item1
)->car
;
631 tem
= Fkeymapp (def
);
632 if (XSTRING (item_string
)->data
[0] == '@' && !NILP (tem
))
633 pending_maps
= Fcons (Fcons (def
, Fcons (item_string
, character
)),
638 GCPRO4 (keymap
, pending_maps
, descrip
, item_string
);
639 submap
= get_keymap_1 (def
, 0, 1);
641 #ifndef USE_X_TOOLKIT
643 item_string
= concat2 (item_string
,
644 build_string (" >"));
646 /* If definition is nil, pass nil as the key. */
647 push_menu_item (item_string
, enabled
, character
,
652 push_submenu_start ();
653 single_keymap_panes (submap
, Qnil
,
665 /* Process now any submenus which want to be panes at this level. */
666 while (!NILP (pending_maps
))
668 Lisp_Object elt
, eltcdr
, string
;
669 elt
= Fcar (pending_maps
);
670 eltcdr
= XCONS (elt
)->cdr
;
671 string
= XCONS (eltcdr
)->car
;
672 /* We no longer discard the @ from the beginning of the string here.
673 Instead, we do this in xmenu_show. */
674 single_keymap_panes (Fcar (elt
), string
,
675 XCONS (eltcdr
)->cdr
, notreal
);
676 pending_maps
= Fcdr (pending_maps
);
680 /* Push all the panes and items of a menu described by the
681 alist-of-alists MENU.
682 This handles old-fashioned calls to x-popup-menu. */
692 for (tail
= menu
; !NILP (tail
); tail
= Fcdr (tail
))
694 Lisp_Object elt
, pane_name
, pane_data
;
696 pane_name
= Fcar (elt
);
697 CHECK_STRING (pane_name
, 0);
698 push_menu_pane (pane_name
, Qnil
);
699 pane_data
= Fcdr (elt
);
700 CHECK_CONS (pane_data
, 0);
701 list_of_items (pane_data
);
704 finish_menu_items ();
707 /* Push the items in a single pane defined by the alist PANE. */
713 Lisp_Object tail
, item
, item1
;
715 for (tail
= pane
; !NILP (tail
); tail
= Fcdr (tail
))
719 push_menu_item (item
, Qnil
, Qnil
, Qt
, Qnil
);
720 else if (NILP (item
))
721 push_left_right_boundary ();
724 CHECK_CONS (item
, 0);
726 CHECK_STRING (item1
, 1);
727 push_menu_item (item1
, Qt
, Fcdr (item
), Qt
, Qnil
);
732 DEFUN ("x-popup-menu", Fx_popup_menu
, Sx_popup_menu
, 2, 2, 0,
733 "Pop up a deck-of-cards menu and return user's selection.\n\
734 POSITION is a position specification. This is either a mouse button event\n\
735 or a list ((XOFFSET YOFFSET) WINDOW)\n\
736 where XOFFSET and YOFFSET are positions in pixels from the top left\n\
737 corner of WINDOW's frame. (WINDOW may be a frame object instead of a window.)\n\
738 This controls the position of the center of the first line\n\
739 in the first pane of the menu, not the top left of the menu as a whole.\n\
740 If POSITION is t, it means to use the current mouse position.\n\
742 MENU is a specifier for a menu. For the simplest case, MENU is a keymap.\n\
743 The menu items come from key bindings that have a menu string as well as\n\
744 a definition; actually, the \"definition\" in such a key binding looks like\n\
745 \(STRING . REAL-DEFINITION). To give the menu a title, put a string into\n\
746 the keymap as a top-level element.\n\n\
747 You can also use a list of keymaps as MENU.\n\
748 Then each keymap makes a separate pane.\n\
749 When MENU is a keymap or a list of keymaps, the return value\n\
750 is a list of events.\n\n\
751 Alternatively, you can specify a menu of multiple panes\n\
752 with a list of the form (TITLE PANE1 PANE2...),\n\
753 where each pane is a list of form (TITLE ITEM1 ITEM2...).\n\
754 Each ITEM is normally a cons cell (STRING . VALUE);\n\
755 but a string can appear as an item--that makes a nonselectable line\n\
757 With this form of menu, the return value is VALUE from the chosen item.\n\
759 If POSITION is nil, don't display the menu at all, just precalculate the\n\
760 cached information about equivalent key sequences.")
762 Lisp_Object position
, menu
;
764 int number_of_panes
, panes
;
765 Lisp_Object keymap
, tem
;
769 Lisp_Object selection
;
772 Lisp_Object x
, y
, window
;
778 if (! NILP (position
))
782 /* Decode the first argument: find the window and the coordinates. */
783 if (EQ (position
, Qt
)
784 || (CONSP (position
) && EQ (XCONS (position
)->car
, Qmenu_bar
)))
786 /* Use the mouse's current position. */
787 FRAME_PTR new_f
= selected_frame
;
788 Lisp_Object bar_window
;
792 if (mouse_position_hook
)
793 (*mouse_position_hook
) (&new_f
, 1, &bar_window
,
794 &part
, &x
, &y
, &time
);
796 XSETFRAME (window
, new_f
);
799 window
= selected_window
;
806 tem
= Fcar (position
);
809 window
= Fcar (Fcdr (position
));
811 y
= Fcar (Fcdr (tem
));
816 tem
= Fcar (Fcdr (position
)); /* EVENT_START (position) */
817 window
= Fcar (tem
); /* POSN_WINDOW (tem) */
818 tem
= Fcar (Fcdr (Fcdr (tem
))); /* POSN_WINDOW_POSN (tem) */
827 /* Decode where to put the menu. */
835 else if (WINDOWP (window
))
837 CHECK_LIVE_WINDOW (window
, 0);
838 f
= XFRAME (WINDOW_FRAME (XWINDOW (window
)));
840 xpos
= (FONT_WIDTH (f
->output_data
.x
->font
) * XWINDOW (window
)->left
);
841 ypos
= (f
->output_data
.x
->line_height
* XWINDOW (window
)->top
);
844 /* ??? Not really clean; should be CHECK_WINDOW_OR_FRAME,
845 but I don't want to make one now. */
846 CHECK_WINDOW (window
, 0);
851 #endif /* HAVE_MENUS */
856 /* Decode the menu items from what was specified. */
858 keymap
= Fkeymapp (menu
);
861 tem
= Fkeymapp (Fcar (menu
));
864 /* We were given a keymap. Extract menu info from the keymap. */
866 keymap
= get_keymap (menu
);
868 /* Extract the detailed info to make one pane. */
869 keymap_panes (&menu
, 1, NILP (position
));
871 /* Search for a string appearing directly as an element of the keymap.
872 That string is the title of the menu. */
873 prompt
= map_prompt (keymap
);
875 /* Make that be the pane title of the first pane. */
876 if (!NILP (prompt
) && menu_items_n_panes
>= 0)
877 XVECTOR (menu_items
)->contents
[MENU_ITEMS_PANE_NAME
] = prompt
;
881 else if (!NILP (tem
))
883 /* We were given a list of keymaps. */
884 int nmaps
= XFASTINT (Flength (menu
));
886 = (Lisp_Object
*) alloca (nmaps
* sizeof (Lisp_Object
));
891 /* The first keymap that has a prompt string
892 supplies the menu title. */
893 for (tem
= menu
, i
= 0; CONSP (tem
); tem
= Fcdr (tem
))
897 maps
[i
++] = keymap
= get_keymap (Fcar (tem
));
899 prompt
= map_prompt (keymap
);
900 if (NILP (title
) && !NILP (prompt
))
904 /* Extract the detailed info to make one pane. */
905 keymap_panes (maps
, nmaps
, NILP (position
));
907 /* Make the title be the pane title of the first pane. */
908 if (!NILP (title
) && menu_items_n_panes
>= 0)
909 XVECTOR (menu_items
)->contents
[MENU_ITEMS_PANE_NAME
] = title
;
915 /* We were given an old-fashioned menu. */
917 CHECK_STRING (title
, 1);
919 list_of_panes (Fcdr (menu
));
926 discard_menu_items ();
932 /* Display them in a menu. */
935 selection
= xmenu_show (f
, xpos
, ypos
, for_click
,
936 keymaps
, title
, &error_name
);
939 discard_menu_items ();
942 #endif /* HAVE_MENUS */
944 if (error_name
) error (error_name
);
950 DEFUN ("x-popup-dialog", Fx_popup_dialog
, Sx_popup_dialog
, 2, 2, 0,
951 "Pop up a dialog box and return user's selection.\n\
952 POSITION specifies which frame to use.\n\
953 This is normally a mouse button event or a window or frame.\n\
954 If POSITION is t, it means to use the frame the mouse is on.\n\
955 The dialog box appears in the middle of the specified frame.\n\
957 CONTENTS specifies the alternatives to display in the dialog box.\n\
958 It is a list of the form (TITLE ITEM1 ITEM2...).\n\
959 Each ITEM is a cons cell (STRING . VALUE).\n\
960 The return value is VALUE from the chosen item.\n\n\
961 An ITEM may also be just a string--that makes a nonselectable item.\n\
962 An ITEM may also be nil--that means to put all preceding items\n\
963 on the left of the dialog box and all following items on the right.\n\
964 \(By default, approximately half appear on each side.)")
966 Lisp_Object position
, contents
;
973 /* Decode the first argument: find the window or frame to use. */
974 if (EQ (position
, Qt
)
975 || (CONSP (position
) && EQ (XCONS (position
)->car
, Qmenu_bar
)))
977 #if 0 /* Using the frame the mouse is on may not be right. */
978 /* Use the mouse's current position. */
979 FRAME_PTR new_f
= selected_frame
;
980 Lisp_Object bar_window
;
985 (*mouse_position_hook
) (&new_f
, 1, &bar_window
, &part
, &x
, &y
, &time
);
988 XSETFRAME (window
, new_f
);
990 window
= selected_window
;
992 window
= selected_window
;
994 else if (CONSP (position
))
997 tem
= Fcar (position
);
999 window
= Fcar (Fcdr (position
));
1002 tem
= Fcar (Fcdr (position
)); /* EVENT_START (position) */
1003 window
= Fcar (tem
); /* POSN_WINDOW (tem) */
1006 else if (WINDOWP (position
) || FRAMEP (position
))
1009 /* Decode where to put the menu. */
1011 if (FRAMEP (window
))
1012 f
= XFRAME (window
);
1013 else if (WINDOWP (window
))
1015 CHECK_LIVE_WINDOW (window
, 0);
1016 f
= XFRAME (WINDOW_FRAME (XWINDOW (window
)));
1019 /* ??? Not really clean; should be CHECK_WINDOW_OR_FRAME,
1020 but I don't want to make one now. */
1021 CHECK_WINDOW (window
, 0);
1023 #ifndef USE_X_TOOLKIT
1024 /* Display a menu with these alternatives
1025 in the middle of frame F. */
1027 Lisp_Object x
, y
, frame
, newpos
;
1028 XSETFRAME (frame
, f
);
1029 XSETINT (x
, x_pixel_width (f
) / 2);
1030 XSETINT (y
, x_pixel_height (f
) / 2);
1031 newpos
= Fcons (Fcons (x
, Fcons (y
, Qnil
)), Fcons (frame
, Qnil
));
1033 return Fx_popup_menu (newpos
,
1034 Fcons (Fcar (contents
), Fcons (contents
, Qnil
)));
1040 Lisp_Object selection
;
1042 /* Decode the dialog items from what was specified. */
1043 title
= Fcar (contents
);
1044 CHECK_STRING (title
, 1);
1046 list_of_panes (Fcons (contents
, Qnil
));
1048 /* Display them in a dialog box. */
1050 selection
= xdialog_show (f
, 0, title
, &error_name
);
1053 discard_menu_items ();
1055 if (error_name
) error (error_name
);
1061 #ifdef USE_X_TOOLKIT
1063 /* Loop in Xt until the menu pulldown or dialog popup has been
1064 popped down (deactivated). This is used for x-popup-menu
1065 and x-popup-dialog; it is not used for the menu bar any more.
1067 NOTE: All calls to popup_get_selection should be protected
1068 with BLOCK_INPUT, UNBLOCK_INPUT wrappers. */
1071 popup_get_selection (initial_event
, dpyinfo
, id
)
1072 XEvent
*initial_event
;
1073 struct x_display_info
*dpyinfo
;
1078 /* Define a queue to save up for later unreading
1079 all X events that don't pertain to the menu. */
1083 struct event_queue
*next
;
1086 struct event_queue
*queue
= NULL
;
1087 struct event_queue
*queue_tmp
;
1090 event
= *initial_event
;
1092 XtAppNextEvent (Xt_app_con
, &event
);
1096 /* Handle expose events for editor frames right away. */
1097 if (event
.type
== Expose
)
1098 process_expose_from_menu (event
);
1099 /* Make sure we don't consider buttons grabbed after menu goes.
1100 And make sure to deactivate for any ButtonRelease,
1101 even if XtDispatchEvent doesn't do that. */
1102 else if (event
.type
== ButtonRelease
1103 && dpyinfo
->display
== event
.xbutton
.display
)
1105 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
1106 popup_activated_flag
= 0;
1108 /* If the user presses a key, deactivate the menu.
1109 The user is likely to do that if we get wedged. */
1110 else if (event
.type
== KeyPress
1111 && dpyinfo
->display
== event
.xbutton
.display
)
1113 popup_activated_flag
= 0;
1116 /* Button presses outside the menu also pop it down. */
1117 else if (event
.type
== ButtonPress
1118 && event
.xany
.display
== dpyinfo
->display
1119 && x_any_window_to_frame (dpyinfo
, event
.xany
.window
))
1121 popup_activated_flag
= 0;
1125 /* Queue all events not for this popup,
1126 except for Expose, which we've already handled, and ButtonRelease.
1127 Note that the X window is associated with the frame if this
1128 is a menu bar popup, but not if it's a dialog box. So we use
1129 x_non_menubar_window_to_frame, not x_any_window_to_frame. */
1130 if (event
.type
!= Expose
1131 && !(event
.type
== ButtonRelease
1132 && dpyinfo
->display
== event
.xbutton
.display
)
1133 && (event
.xany
.display
!= dpyinfo
->display
1134 || x_non_menubar_window_to_frame (dpyinfo
, event
.xany
.window
)))
1136 queue_tmp
= (struct event_queue
*) malloc (sizeof (struct event_queue
));
1138 if (queue_tmp
!= NULL
)
1140 queue_tmp
->event
= event
;
1141 queue_tmp
->next
= queue
;
1146 XtDispatchEvent (&event
);
1148 if (!popup_activated ())
1150 XtAppNextEvent (Xt_app_con
, &event
);
1153 /* Unread any events that we got but did not handle. */
1154 while (queue
!= NULL
)
1157 XPutBackEvent (queue_tmp
->event
.xany
.display
, &queue_tmp
->event
);
1158 queue
= queue_tmp
->next
;
1159 free ((char *)queue_tmp
);
1160 /* Cause these events to get read as soon as we UNBLOCK_INPUT. */
1161 interrupt_input_pending
= 1;
1165 /* Activate the menu bar of frame F.
1166 This is called from keyboard.c when it gets the
1167 menu_bar_activate_event out of the Emacs event queue.
1169 To activate the menu bar, we use the X button-press event
1170 that was saved in saved_button_event.
1171 That makes the toolkit do its thing.
1173 But first we recompute the menu bar contents (the whole tree).
1175 The reason for saving the button event until here, instead of
1176 passing it to the toolkit right away, is that we can safely
1177 execute Lisp code. */
1179 x_activate_menubar (f
)
1182 if (f
->output_data
.x
->saved_button_event
->type
!= ButtonPress
)
1185 set_frame_menubar (f
, 0, 1);
1188 XtDispatchEvent ((XEvent
*) f
->output_data
.x
->saved_button_event
);
1191 /* Ignore this if we get it a second time. */
1192 f
->output_data
.x
->saved_button_event
->type
= 0;
1195 /* Detect if a dialog or menu has been posted. */
1200 return popup_activated_flag
;
1204 /* This callback is invoked when the user selects a menubar cascade
1205 pushbutton, but before the pulldown menu is posted. */
1208 popup_activate_callback (widget
, id
, client_data
)
1211 XtPointer client_data
;
1213 popup_activated_flag
= 1;
1216 /* This callback is called from the menu bar pulldown menu
1217 when the user makes a selection.
1218 Figure out what the user chose
1219 and put the appropriate events into the keyboard buffer. */
1222 menubar_selection_callback (widget
, id
, client_data
)
1225 XtPointer client_data
;
1227 Lisp_Object prefix
, entry
;
1228 FRAME_PTR f
= menubar_id_to_frame (id
);
1230 Lisp_Object
*subprefix_stack
;
1231 int submenu_depth
= 0;
1236 subprefix_stack
= (Lisp_Object
*) alloca (f
->menu_bar_items_used
* sizeof (Lisp_Object
));
1237 vector
= f
->menu_bar_vector
;
1240 while (i
< f
->menu_bar_items_used
)
1242 if (EQ (XVECTOR (vector
)->contents
[i
], Qnil
))
1244 subprefix_stack
[submenu_depth
++] = prefix
;
1248 else if (EQ (XVECTOR (vector
)->contents
[i
], Qlambda
))
1250 prefix
= subprefix_stack
[--submenu_depth
];
1253 else if (EQ (XVECTOR (vector
)->contents
[i
], Qt
))
1255 prefix
= XVECTOR (vector
)->contents
[i
+ MENU_ITEMS_PANE_PREFIX
];
1256 i
+= MENU_ITEMS_PANE_LENGTH
;
1260 entry
= XVECTOR (vector
)->contents
[i
+ MENU_ITEMS_ITEM_VALUE
];
1261 /* The EMACS_INT cast avoids a warning. There's no problem
1262 as long as pointers have enough bits to hold small integers. */
1263 if ((int) (EMACS_INT
) client_data
== i
)
1266 struct input_event buf
;
1269 XSETFRAME (frame
, f
);
1270 buf
.kind
= menu_bar_event
;
1271 buf
.frame_or_window
= Fcons (frame
, Fcons (Qmenu_bar
, Qnil
));
1272 kbd_buffer_store_event (&buf
);
1274 for (j
= 0; j
< submenu_depth
; j
++)
1275 if (!NILP (subprefix_stack
[j
]))
1277 buf
.kind
= menu_bar_event
;
1278 buf
.frame_or_window
= Fcons (frame
, subprefix_stack
[j
]);
1279 kbd_buffer_store_event (&buf
);
1284 buf
.kind
= menu_bar_event
;
1285 buf
.frame_or_window
= Fcons (frame
, prefix
);
1286 kbd_buffer_store_event (&buf
);
1289 buf
.kind
= menu_bar_event
;
1290 buf
.frame_or_window
= Fcons (frame
, entry
);
1291 kbd_buffer_store_event (&buf
);
1295 i
+= MENU_ITEMS_ITEM_LENGTH
;
1300 /* This callback is invoked when a dialog or menu is finished being
1301 used and has been unposted. */
1304 popup_deactivate_callback (widget
, id
, client_data
)
1307 XtPointer client_data
;
1309 popup_activated_flag
= 0;
1312 /* Allocate a widget_value, blocking input. */
1315 xmalloc_widget_value ()
1317 widget_value
*value
;
1320 value
= malloc_widget_value ();
1326 /* This recursively calls free_widget_value on the tree of widgets.
1327 It must free all data that was malloc'ed for these widget_values.
1328 In Emacs, many slots are pointers into the data of Lisp_Strings, and
1329 must be left alone. */
1332 free_menubar_widget_value_tree (wv
)
1337 wv
->name
= wv
->value
= wv
->key
= (char *) 0xDEADBEEF;
1339 if (wv
->contents
&& (wv
->contents
!= (widget_value
*)1))
1341 free_menubar_widget_value_tree (wv
->contents
);
1342 wv
->contents
= (widget_value
*) 0xDEADBEEF;
1346 free_menubar_widget_value_tree (wv
->next
);
1347 wv
->next
= (widget_value
*) 0xDEADBEEF;
1350 free_widget_value (wv
);
1354 /* Return a tree of widget_value structures for a menu bar item
1355 whose event type is ITEM_KEY (with string ITEM_NAME)
1356 and whose contents come from the list of keymaps MAPS. */
1358 static widget_value
*
1359 single_submenu (item_key
, item_name
, maps
)
1360 Lisp_Object item_key
, item_name
, maps
;
1362 widget_value
*wv
, *prev_wv
, *save_wv
, *first_wv
;
1364 int submenu_depth
= 0;
1367 Lisp_Object
*mapvec
;
1368 widget_value
**submenu_stack
;
1370 int previous_items
= menu_items_used
;
1371 int top_level_items
= 0;
1373 length
= Flength (maps
);
1374 len
= XINT (length
);
1376 /* Convert the list MAPS into a vector MAPVEC. */
1377 mapvec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
1378 for (i
= 0; i
< len
; i
++)
1380 mapvec
[i
] = Fcar (maps
);
1384 menu_items_n_panes
= 0;
1386 /* Loop over the given keymaps, making a pane for each map.
1387 But don't make a pane that is empty--ignore that map instead. */
1388 for (i
= 0; i
< len
; i
++)
1390 if (SYMBOLP (mapvec
[i
])
1391 || (CONSP (mapvec
[i
])
1392 && NILP (Fkeymapp (mapvec
[i
]))))
1394 /* Here we have a command at top level in the menu bar
1395 as opposed to a submenu. */
1396 top_level_items
= 1;
1397 push_menu_pane (Qnil
, Qnil
);
1398 push_menu_item (item_name
, Qt
, item_key
, mapvec
[i
], Qnil
);
1401 single_keymap_panes (mapvec
[i
], item_name
, item_key
, 0);
1404 /* Create a tree of widget_value objects
1405 representing the panes and their items. */
1408 = (widget_value
**) alloca (menu_items_used
* sizeof (widget_value
*));
1409 wv
= xmalloc_widget_value ();
1417 /* Loop over all panes and items made during this call
1418 and construct a tree of widget_value objects.
1419 Ignore the panes and items made by previous calls to
1420 single_submenu, even though those are also in menu_items. */
1422 while (i
< menu_items_used
)
1424 if (EQ (XVECTOR (menu_items
)->contents
[i
], Qnil
))
1426 submenu_stack
[submenu_depth
++] = save_wv
;
1431 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qlambda
))
1434 save_wv
= submenu_stack
[--submenu_depth
];
1437 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qt
)
1438 && submenu_depth
!= 0)
1439 i
+= MENU_ITEMS_PANE_LENGTH
;
1440 /* Ignore a nil in the item list.
1441 It's meaningful only for dialog boxes. */
1442 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qquote
))
1444 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qt
))
1446 /* Create a new pane. */
1447 Lisp_Object pane_name
, prefix
;
1449 pane_name
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_PANE_NAME
];
1450 prefix
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_PANE_PREFIX
];
1451 pane_string
= (NILP (pane_name
)
1452 ? "" : (char *) XSTRING (pane_name
)->data
);
1453 /* If there is just one top-level pane, put all its items directly
1454 under the top-level menu. */
1455 if (menu_items_n_panes
== 1)
1458 /* If the pane has a meaningful name,
1459 make the pane a top-level menu item
1460 with its items as a submenu beneath it. */
1461 if (strcmp (pane_string
, ""))
1463 wv
= xmalloc_widget_value ();
1467 first_wv
->contents
= wv
;
1468 wv
->name
= pane_string
;
1469 /* Ignore the @ that means "separate pane".
1470 This is a kludge, but this isn't worth more time. */
1471 if (!NILP (prefix
) && wv
->name
[0] == '@')
1478 i
+= MENU_ITEMS_PANE_LENGTH
;
1482 /* Create a new item within current pane. */
1483 Lisp_Object item_name
, enable
, descrip
, def
;
1484 item_name
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_NAME
];
1485 enable
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_ENABLE
];
1487 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_EQUIV_KEY
];
1488 def
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_DEFINITION
];
1490 wv
= xmalloc_widget_value ();
1494 save_wv
->contents
= wv
;
1496 wv
->name
= (char *) XSTRING (item_name
)->data
;
1497 if (!NILP (descrip
))
1498 wv
->key
= (char *) XSTRING (descrip
)->data
;
1500 /* The EMACS_INT cast avoids a warning. There's no problem
1501 as long as pointers have enough bits to hold small integers. */
1502 wv
->call_data
= (!NILP (def
) ? (void *) (EMACS_INT
) i
: 0);
1503 wv
->enabled
= !NILP (enable
);
1506 i
+= MENU_ITEMS_ITEM_LENGTH
;
1510 /* If we have just one "menu item"
1511 that was originally a button, return it by itself. */
1512 if (top_level_items
&& first_wv
->contents
&& first_wv
->contents
->next
== 0)
1514 wv
= first_wv
->contents
;
1515 free_widget_value (first_wv
);
1522 extern void EmacsFrameSetCharSize ();
1524 /* Recompute all the widgets of frame F, when the menu bar
1525 has been changed. */
1528 update_frame_menubar (f
)
1531 struct x_output
*x
= f
->output_data
.x
;
1533 int menubar_changed
;
1535 Dimension shell_height
;
1537 /* We assume the menubar contents has changed if the global flag is set,
1538 or if the current buffer has changed, or if the menubar has never
1539 been updated before.
1541 menubar_changed
= (x
->menubar_widget
1542 && !XtIsManaged (x
->menubar_widget
));
1544 if (! (menubar_changed
))
1548 /* Save the size of the frame because the pane widget doesn't accept to
1549 resize itself. So force it. */
1553 /* Do the voodoo which means "I'm changing lots of things, don't try to
1554 refigure sizes until I'm done." */
1555 lw_refigure_widget (x
->column_widget
, False
);
1557 /* the order in which children are managed is the top to
1558 bottom order in which they are displayed in the paned window.
1559 First, remove the text-area widget.
1561 XtUnmanageChild (x
->edit_widget
);
1563 /* remove the menubar that is there now, and put up the menubar that
1566 if (menubar_changed
)
1568 XtManageChild (x
->menubar_widget
);
1569 XtMapWidget (x
->menubar_widget
);
1570 XtVaSetValues (x
->menubar_widget
, XtNmappedWhenManaged
, 1, 0);
1573 /* Re-manage the text-area widget, and then thrash the sizes. */
1574 XtManageChild (x
->edit_widget
);
1575 lw_refigure_widget (x
->column_widget
, True
);
1577 /* Force the pane widget to resize itself with the right values. */
1578 EmacsFrameSetCharSize (x
->edit_widget
, columns
, rows
);
1583 /* Set the contents of the menubar widgets of frame F.
1584 The argument FIRST_TIME is currently ignored;
1585 it is set the first time this is called, from initialize_frame_menubar. */
1588 set_frame_menubar (f
, first_time
, deep_p
)
1593 Widget menubar_widget
= f
->output_data
.x
->menubar_widget
;
1594 Lisp_Object tail
, items
, frame
;
1595 widget_value
*wv
, *first_wv
, *prev_wv
= 0;
1599 if (f
->output_data
.x
->id
== 0)
1600 f
->output_data
.x
->id
= next_menubar_widget_id
++;
1601 id
= f
->output_data
.x
->id
;
1603 if (! menubar_widget
)
1606 wv
= xmalloc_widget_value ();
1607 wv
->name
= "menubar";
1614 /* Make a widget-value tree representing the entire menu trees. */
1616 struct buffer
*prev
= current_buffer
;
1618 int specpdl_count
= specpdl_ptr
- specpdl
;
1619 int previous_menu_items_used
= f
->menu_bar_items_used
;
1620 Lisp_Object
*previous_items
1621 = (Lisp_Object
*) alloca (previous_menu_items_used
1622 * sizeof (Lisp_Object
));
1624 buffer
= XWINDOW (FRAME_SELECTED_WINDOW (f
))->buffer
;
1625 specbind (Qinhibit_quit
, Qt
);
1626 /* Don't let the debugger step into this code
1627 because it is not reentrant. */
1628 specbind (Qdebug_on_next_call
, Qnil
);
1630 record_unwind_protect (Fstore_match_data
, Fmatch_data ());
1631 if (NILP (Voverriding_local_map_menu_flag
))
1633 specbind (Qoverriding_terminal_local_map
, Qnil
);
1634 specbind (Qoverriding_local_map
, Qnil
);
1637 set_buffer_internal_1 (XBUFFER (buffer
));
1639 /* Run the Lucid hook. */
1640 call1 (Vrun_hooks
, Qactivate_menubar_hook
);
1641 /* If it has changed current-menubar from previous value,
1642 really recompute the menubar from the value. */
1643 if (! NILP (Vlucid_menu_bar_dirty_flag
))
1644 call0 (Qrecompute_lucid_menubar
);
1645 safe_run_hooks (Qmenu_bar_update_hook
);
1646 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
1648 items
= FRAME_MENU_BAR_ITEMS (f
);
1650 inhibit_garbage_collection ();
1652 /* Save the frame's previous menu bar contents data. */
1653 bcopy (XVECTOR (f
->menu_bar_vector
)->contents
, previous_items
,
1654 previous_menu_items_used
* sizeof (Lisp_Object
));
1656 /* Fill in the current menu bar contents. */
1657 menu_items
= f
->menu_bar_vector
;
1658 menu_items_allocated
= XVECTOR (menu_items
)->size
;
1660 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
1662 Lisp_Object key
, string
, maps
;
1664 key
= XVECTOR (items
)->contents
[i
];
1665 string
= XVECTOR (items
)->contents
[i
+ 1];
1666 maps
= XVECTOR (items
)->contents
[i
+ 2];
1670 wv
= single_submenu (key
, string
, maps
);
1674 first_wv
->contents
= wv
;
1675 /* Don't set wv->name here; GC during the loop might relocate it. */
1680 finish_menu_items ();
1682 set_buffer_internal_1 (prev
);
1683 unbind_to (specpdl_count
, Qnil
);
1685 /* If there has been no change in the Lisp-level contents
1686 of the menu bar, skip redisplaying it. Just exit. */
1688 for (i
= 0; i
< previous_menu_items_used
; i
++)
1689 if (menu_items_used
== i
1690 || (previous_items
[i
] != XVECTOR (menu_items
)->contents
[i
]))
1692 if (i
== menu_items_used
&& i
== previous_menu_items_used
&& i
!= 0)
1694 free_menubar_widget_value_tree (first_wv
);
1700 /* Now GC cannot happen during the lifetime of the widget_value,
1701 so it's safe to store data from a Lisp_String. */
1702 wv
= first_wv
->contents
;
1703 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
1706 string
= XVECTOR (items
)->contents
[i
+ 1];
1709 wv
->name
= (char *) XSTRING (string
)->data
;
1713 f
->menu_bar_vector
= menu_items
;
1714 f
->menu_bar_items_used
= menu_items_used
;
1719 /* Make a widget-value tree containing
1720 just the top level menu bar strings. */
1722 items
= FRAME_MENU_BAR_ITEMS (f
);
1723 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
1727 string
= XVECTOR (items
)->contents
[i
+ 1];
1731 wv
= xmalloc_widget_value ();
1732 wv
->name
= (char *) XSTRING (string
)->data
;
1739 first_wv
->contents
= wv
;
1743 /* Forget what we thought we knew about what is in the
1744 detailed contents of the menu bar menus.
1745 Changing the top level always destroys the contents. */
1746 f
->menu_bar_items_used
= 0;
1749 /* Create or update the menu bar widget. */
1755 /* Disable resizing (done for Motif!) */
1756 lw_allow_resizing (f
->output_data
.x
->widget
, False
);
1758 /* The third arg is DEEP_P, which says to consider the entire
1759 menu trees we supply, rather than just the menu bar item names. */
1760 lw_modify_all_widgets (id
, first_wv
, deep_p
);
1762 /* Re-enable the edit widget to resize. */
1763 lw_allow_resizing (f
->output_data
.x
->widget
, True
);
1767 menubar_widget
= lw_create_widget ("menubar", "menubar", id
, first_wv
,
1768 f
->output_data
.x
->column_widget
,
1770 popup_activate_callback
,
1771 menubar_selection_callback
,
1772 popup_deactivate_callback
);
1773 f
->output_data
.x
->menubar_widget
= menubar_widget
;
1778 = (f
->output_data
.x
->menubar_widget
1779 ? (f
->output_data
.x
->menubar_widget
->core
.height
1780 + f
->output_data
.x
->menubar_widget
->core
.border_width
)
1784 if (FRAME_EXTERNAL_MENU_BAR (f
))
1787 XtVaGetValues (f
->output_data
.x
->column_widget
,
1788 XtNinternalBorderWidth
, &ibw
, NULL
);
1789 menubar_size
+= ibw
;
1791 #endif /* USE_LUCID */
1793 f
->output_data
.x
->menubar_height
= menubar_size
;
1796 free_menubar_widget_value_tree (first_wv
);
1798 update_frame_menubar (f
);
1803 /* Called from Fx_create_frame to create the initial menubar of a frame
1804 before it is mapped, so that the window is mapped with the menubar already
1805 there instead of us tacking it on later and thrashing the window after it
1809 initialize_frame_menubar (f
)
1812 /* This function is called before the first chance to redisplay
1813 the frame. It has to be, so the frame will have the right size. */
1814 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
1815 set_frame_menubar (f
, 1, 1);
1818 /* Get rid of the menu bar of frame F, and free its storage.
1819 This is used when deleting a frame, and when turning off the menu bar. */
1822 free_frame_menubar (f
)
1825 Widget menubar_widget
;
1828 menubar_widget
= f
->output_data
.x
->menubar_widget
;
1833 lw_destroy_all_widgets ((LWLIB_ID
) f
->output_data
.x
->id
);
1838 #endif /* USE_X_TOOLKIT */
1840 /* xmenu_show actually displays a menu using the panes and items in menu_items
1841 and returns the value selected from it.
1842 There are two versions of xmenu_show, one for Xt and one for Xlib.
1843 Both assume input is blocked by the caller. */
1845 /* F is the frame the menu is for.
1846 X and Y are the frame-relative specified position,
1847 relative to the inside upper left corner of the frame F.
1848 FOR_CLICK if this menu was invoked for a mouse click.
1849 KEYMAPS is 1 if this menu was specified with keymaps;
1850 in that case, we return a list containing the chosen item's value
1851 and perhaps also the pane's prefix.
1852 TITLE is the specified menu title.
1853 ERROR is a place to store an error message string in case of failure.
1854 (We return nil on failure, but the value doesn't actually matter.) */
1856 #ifdef USE_X_TOOLKIT
1858 /* We need a unique id for each widget handled by the Lucid Widget
1861 For the main windows, and popup menus, we use this counter,
1862 which we increment each time after use. This starts from 1<<16.
1864 For menu bars, we use numbers starting at 0, counted in
1865 next_menubar_widget_id. */
1866 LWLIB_ID widget_id_tick
;
1869 static Lisp_Object
*volatile menu_item_selection
;
1871 static Lisp_Object
*menu_item_selection
;
1875 popup_selection_callback (widget
, id
, client_data
)
1878 XtPointer client_data
;
1880 menu_item_selection
= (Lisp_Object
*) client_data
;
1884 xmenu_show (f
, x
, y
, for_click
, keymaps
, title
, error
)
1898 widget_value
*wv
, *save_wv
= 0, *first_wv
= 0, *prev_wv
= 0;
1899 widget_value
**submenu_stack
1900 = (widget_value
**) alloca (menu_items_used
* sizeof (widget_value
*));
1901 Lisp_Object
*subprefix_stack
1902 = (Lisp_Object
*) alloca (menu_items_used
* sizeof (Lisp_Object
));
1903 int submenu_depth
= 0;
1904 XButtonPressedEvent dummy
;
1907 int next_release_must_exit
= 0;
1911 if (menu_items_used
<= MENU_ITEMS_PANE_LENGTH
)
1913 *error
= "Empty menu";
1917 /* Create a tree of widget_value objects
1918 representing the panes and their items. */
1919 wv
= xmalloc_widget_value ();
1926 /* Loop over all panes and items, filling in the tree. */
1928 while (i
< menu_items_used
)
1930 if (EQ (XVECTOR (menu_items
)->contents
[i
], Qnil
))
1932 submenu_stack
[submenu_depth
++] = save_wv
;
1938 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qlambda
))
1941 save_wv
= submenu_stack
[--submenu_depth
];
1945 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qt
)
1946 && submenu_depth
!= 0)
1947 i
+= MENU_ITEMS_PANE_LENGTH
;
1948 /* Ignore a nil in the item list.
1949 It's meaningful only for dialog boxes. */
1950 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qquote
))
1952 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qt
))
1954 /* Create a new pane. */
1955 Lisp_Object pane_name
, prefix
;
1957 pane_name
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_PANE_NAME
];
1958 prefix
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_PANE_PREFIX
];
1959 pane_string
= (NILP (pane_name
)
1960 ? "" : (char *) XSTRING (pane_name
)->data
);
1961 /* If there is just one top-level pane, put all its items directly
1962 under the top-level menu. */
1963 if (menu_items_n_panes
== 1)
1966 /* If the pane has a meaningful name,
1967 make the pane a top-level menu item
1968 with its items as a submenu beneath it. */
1969 if (!keymaps
&& strcmp (pane_string
, ""))
1971 wv
= xmalloc_widget_value ();
1975 first_wv
->contents
= wv
;
1976 wv
->name
= pane_string
;
1977 if (keymaps
&& !NILP (prefix
))
1984 else if (first_pane
)
1990 i
+= MENU_ITEMS_PANE_LENGTH
;
1994 /* Create a new item within current pane. */
1995 Lisp_Object item_name
, enable
, descrip
, def
;
1996 item_name
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_NAME
];
1997 enable
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_ENABLE
];
1999 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_EQUIV_KEY
];
2000 def
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_DEFINITION
];
2002 wv
= xmalloc_widget_value ();
2006 save_wv
->contents
= wv
;
2007 wv
->name
= (char *) XSTRING (item_name
)->data
;
2008 if (!NILP (descrip
))
2009 wv
->key
= (char *) XSTRING (descrip
)->data
;
2011 /* If this item has a null value,
2012 make the call_data null so that it won't display a box
2013 when the mouse is on it. */
2015 = (!NILP (def
) ? (void *) &XVECTOR (menu_items
)->contents
[i
] : 0);
2016 wv
->enabled
= !NILP (enable
);
2019 i
+= MENU_ITEMS_ITEM_LENGTH
;
2023 /* Deal with the title, if it is non-nil. */
2026 widget_value
*wv_title
= xmalloc_widget_value ();
2027 widget_value
*wv_sep1
= xmalloc_widget_value ();
2028 widget_value
*wv_sep2
= xmalloc_widget_value ();
2030 wv_sep2
->name
= "--";
2031 wv_sep2
->next
= first_wv
->contents
;
2033 wv_sep1
->name
= "--";
2034 wv_sep1
->next
= wv_sep2
;
2036 wv_title
->name
= (char *) XSTRING (title
)->data
;
2037 wv_title
->enabled
= True
;
2038 wv_title
->next
= wv_sep1
;
2039 first_wv
->contents
= wv_title
;
2042 /* Actually create the menu. */
2043 menu_id
= widget_id_tick
++;
2044 menu
= lw_create_widget ("popup", first_wv
->name
, menu_id
, first_wv
,
2045 f
->output_data
.x
->widget
, 1, 0,
2046 popup_selection_callback
,
2047 popup_deactivate_callback
);
2049 /* Adjust coordinates to relative to the outer (window manager) window. */
2052 int win_x
= 0, win_y
= 0;
2054 /* Find the position of the outside upper-left corner of
2055 the inner window, with respect to the outer window. */
2056 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
2059 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
2061 /* From-window, to-window. */
2062 f
->output_data
.x
->window_desc
,
2063 f
->output_data
.x
->parent_desc
,
2065 /* From-position, to-position. */
2066 0, 0, &win_x
, &win_y
,
2068 /* Child of window. */
2076 /* Adjust coordinates to be root-window-relative. */
2077 x
+= f
->output_data
.x
->left_pos
;
2078 y
+= f
->output_data
.x
->top_pos
;
2080 dummy
.type
= ButtonPress
;
2082 dummy
.send_event
= 0;
2083 dummy
.display
= FRAME_X_DISPLAY (f
);
2084 dummy
.time
= CurrentTime
;
2086 dummy
.root
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
2087 dummy
.window
= dummy
.root
;
2088 dummy
.subwindow
= dummy
.root
;
2094 /* Don't allow any geometry request from the user. */
2095 XtSetArg (av
[ac
], XtNgeometry
, 0); ac
++;
2096 XtSetValues (menu
, av
, ac
);
2098 /* Free the widget_value objects we used to specify the contents. */
2099 free_menubar_widget_value_tree (first_wv
);
2101 /* No selection has been chosen yet. */
2102 menu_item_selection
= 0;
2104 /* Display the menu. */
2105 lw_popup_menu (menu
, &dummy
);
2106 popup_activated_flag
= 1;
2108 /* Process events that apply to the menu. */
2109 popup_get_selection ((XEvent
*) 0, FRAME_X_DISPLAY_INFO (f
), menu_id
);
2111 /* fp turned off the following statement and wrote a comment
2112 that it is unnecessary--that the menu has already disappeared.
2113 Nowadays the menu disappears ok, all right, but
2114 we need to delete the widgets or multiple ones will pile up. */
2115 lw_destroy_all_widgets (menu_id
);
2117 /* Find the selected item, and its pane, to return
2118 the proper value. */
2119 if (menu_item_selection
!= 0)
2121 Lisp_Object prefix
, entry
;
2125 while (i
< menu_items_used
)
2127 if (EQ (XVECTOR (menu_items
)->contents
[i
], Qnil
))
2129 subprefix_stack
[submenu_depth
++] = prefix
;
2133 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qlambda
))
2135 prefix
= subprefix_stack
[--submenu_depth
];
2138 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qt
))
2141 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_PANE_PREFIX
];
2142 i
+= MENU_ITEMS_PANE_LENGTH
;
2144 /* Ignore a nil in the item list.
2145 It's meaningful only for dialog boxes. */
2146 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qquote
))
2151 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_VALUE
];
2152 if (menu_item_selection
== &XVECTOR (menu_items
)->contents
[i
])
2158 entry
= Fcons (entry
, Qnil
);
2160 entry
= Fcons (prefix
, entry
);
2161 for (j
= submenu_depth
- 1; j
>= 0; j
--)
2162 if (!NILP (subprefix_stack
[j
]))
2163 entry
= Fcons (subprefix_stack
[j
], entry
);
2167 i
+= MENU_ITEMS_ITEM_LENGTH
;
2176 dialog_selection_callback (widget
, id
, client_data
)
2179 XtPointer client_data
;
2181 /* The EMACS_INT cast avoids a warning. There's no problem
2182 as long as pointers have enough bits to hold small integers. */
2183 if ((int) (EMACS_INT
) client_data
!= -1)
2184 menu_item_selection
= (Lisp_Object
*) client_data
;
2186 lw_destroy_all_widgets (id
);
2188 popup_activated_flag
= 0;
2191 static char * button_names
[] = {
2192 "button1", "button2", "button3", "button4", "button5",
2193 "button6", "button7", "button8", "button9", "button10" };
2196 xdialog_show (f
, keymaps
, title
, error
)
2202 int i
, nb_buttons
=0;
2205 char dialog_name
[6];
2207 widget_value
*wv
, *save_wv
= 0, *first_wv
= 0, *prev_wv
= 0;
2209 /* Number of elements seen so far, before boundary. */
2211 /* 1 means we've seen the boundary between left-hand elts and right-hand. */
2212 int boundary_seen
= 0;
2216 if (menu_items_n_panes
> 1)
2218 *error
= "Multiple panes in dialog box";
2222 /* Create a tree of widget_value objects
2223 representing the text label and buttons. */
2225 Lisp_Object pane_name
, prefix
;
2227 pane_name
= XVECTOR (menu_items
)->contents
[MENU_ITEMS_PANE_NAME
];
2228 prefix
= XVECTOR (menu_items
)->contents
[MENU_ITEMS_PANE_PREFIX
];
2229 pane_string
= (NILP (pane_name
)
2230 ? "" : (char *) XSTRING (pane_name
)->data
);
2231 prev_wv
= xmalloc_widget_value ();
2232 prev_wv
->value
= pane_string
;
2233 if (keymaps
&& !NILP (prefix
))
2235 prev_wv
->enabled
= 1;
2236 prev_wv
->name
= "message";
2239 /* Loop over all panes and items, filling in the tree. */
2240 i
= MENU_ITEMS_PANE_LENGTH
;
2241 while (i
< menu_items_used
)
2244 /* Create a new item within current pane. */
2245 Lisp_Object item_name
, enable
, descrip
;
2246 item_name
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_NAME
];
2247 enable
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_ENABLE
];
2249 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_EQUIV_KEY
];
2251 if (NILP (item_name
))
2253 free_menubar_widget_value_tree (first_wv
);
2254 *error
= "Submenu in dialog items";
2257 if (EQ (item_name
, Qquote
))
2259 /* This is the boundary between left-side elts
2260 and right-side elts. Stop incrementing right_count. */
2265 if (nb_buttons
>= 10)
2267 free_menubar_widget_value_tree (first_wv
);
2268 *error
= "Too many dialog items";
2272 wv
= xmalloc_widget_value ();
2274 wv
->name
= (char *) button_names
[nb_buttons
];
2275 if (!NILP (descrip
))
2276 wv
->key
= (char *) XSTRING (descrip
)->data
;
2277 wv
->value
= (char *) XSTRING (item_name
)->data
;
2278 wv
->call_data
= (void *) &XVECTOR (menu_items
)->contents
[i
];
2279 wv
->enabled
= !NILP (enable
);
2282 if (! boundary_seen
)
2286 i
+= MENU_ITEMS_ITEM_LENGTH
;
2289 /* If the boundary was not specified,
2290 by default put half on the left and half on the right. */
2291 if (! boundary_seen
)
2292 left_count
= nb_buttons
- nb_buttons
/ 2;
2294 wv
= xmalloc_widget_value ();
2295 wv
->name
= dialog_name
;
2297 /* Dialog boxes use a really stupid name encoding
2298 which specifies how many buttons to use
2299 and how many buttons are on the right.
2300 The Q means something also. */
2301 dialog_name
[0] = 'Q';
2302 dialog_name
[1] = '0' + nb_buttons
;
2303 dialog_name
[2] = 'B';
2304 dialog_name
[3] = 'R';
2305 /* Number of buttons to put on the right. */
2306 dialog_name
[4] = '0' + nb_buttons
- left_count
;
2308 wv
->contents
= first_wv
;
2312 /* Actually create the dialog. */
2313 dialog_id
= widget_id_tick
++;
2314 menu
= lw_create_widget (first_wv
->name
, "dialog", dialog_id
, first_wv
,
2315 f
->output_data
.x
->widget
, 1, 0,
2316 dialog_selection_callback
, 0);
2317 lw_modify_all_widgets (dialog_id
, first_wv
->contents
, True
);
2318 /* Free the widget_value objects we used to specify the contents. */
2319 free_menubar_widget_value_tree (first_wv
);
2321 /* No selection has been chosen yet. */
2322 menu_item_selection
= 0;
2324 /* Display the menu. */
2325 lw_pop_up_all_widgets (dialog_id
);
2326 popup_activated_flag
= 1;
2328 /* Process events that apply to the menu. */
2329 popup_get_selection ((XEvent
*) 0, FRAME_X_DISPLAY_INFO (f
), dialog_id
);
2331 lw_destroy_all_widgets (dialog_id
);
2333 /* Find the selected item, and its pane, to return
2334 the proper value. */
2335 if (menu_item_selection
!= 0)
2341 while (i
< menu_items_used
)
2345 if (EQ (XVECTOR (menu_items
)->contents
[i
], Qt
))
2348 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_PANE_PREFIX
];
2349 i
+= MENU_ITEMS_PANE_LENGTH
;
2354 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_VALUE
];
2355 if (menu_item_selection
== &XVECTOR (menu_items
)->contents
[i
])
2359 entry
= Fcons (entry
, Qnil
);
2361 entry
= Fcons (prefix
, entry
);
2365 i
+= MENU_ITEMS_ITEM_LENGTH
;
2372 #else /* not USE_X_TOOLKIT */
2375 xmenu_show (f
, x
, y
, for_click
, keymaps
, title
, error
)
2385 int pane
, selidx
, lpane
, status
;
2386 Lisp_Object entry
, pane_prefix
;
2388 int ulx
, uly
, width
, height
;
2389 int dispwidth
, dispheight
;
2393 unsigned int dummy_uint
;
2396 if (menu_items_n_panes
== 0)
2399 if (menu_items_used
<= MENU_ITEMS_PANE_LENGTH
)
2401 *error
= "Empty menu";
2405 /* Figure out which root window F is on. */
2406 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &root
,
2407 &dummy_int
, &dummy_int
, &dummy_uint
, &dummy_uint
,
2408 &dummy_uint
, &dummy_uint
);
2410 /* Make the menu on that window. */
2411 menu
= XMenuCreate (FRAME_X_DISPLAY (f
), root
, "emacs");
2414 *error
= "Can't create menu";
2418 #ifdef HAVE_X_WINDOWS
2419 /* Adjust coordinates to relative to the outer (window manager) window. */
2422 int win_x
= 0, win_y
= 0;
2424 /* Find the position of the outside upper-left corner of
2425 the inner window, with respect to the outer window. */
2426 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
2429 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
2431 /* From-window, to-window. */
2432 f
->output_data
.x
->window_desc
,
2433 f
->output_data
.x
->parent_desc
,
2435 /* From-position, to-position. */
2436 0, 0, &win_x
, &win_y
,
2438 /* Child of window. */
2445 #endif /* HAVE_X_WINDOWS */
2447 /* Adjust coordinates to be root-window-relative. */
2448 x
+= f
->output_data
.x
->left_pos
;
2449 y
+= f
->output_data
.x
->top_pos
;
2451 /* Create all the necessary panes and their items. */
2453 while (i
< menu_items_used
)
2455 if (EQ (XVECTOR (menu_items
)->contents
[i
], Qt
))
2457 /* Create a new pane. */
2458 Lisp_Object pane_name
, prefix
;
2461 pane_name
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_PANE_NAME
];
2462 prefix
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_PANE_PREFIX
];
2463 pane_string
= (NILP (pane_name
)
2464 ? "" : (char *) XSTRING (pane_name
)->data
);
2465 if (keymaps
&& !NILP (prefix
))
2468 lpane
= XMenuAddPane (FRAME_X_DISPLAY (f
), menu
, pane_string
, TRUE
);
2469 if (lpane
== XM_FAILURE
)
2471 XMenuDestroy (FRAME_X_DISPLAY (f
), menu
);
2472 *error
= "Can't create pane";
2475 i
+= MENU_ITEMS_PANE_LENGTH
;
2477 /* Find the width of the widest item in this pane. */
2480 while (j
< menu_items_used
)
2483 item
= XVECTOR (menu_items
)->contents
[j
];
2491 width
= XSTRING (item
)->size
;
2492 if (width
> maxwidth
)
2495 j
+= MENU_ITEMS_ITEM_LENGTH
;
2498 /* Ignore a nil in the item list.
2499 It's meaningful only for dialog boxes. */
2500 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qquote
))
2504 /* Create a new item within current pane. */
2505 Lisp_Object item_name
, enable
, descrip
;
2506 unsigned char *item_data
;
2508 item_name
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_NAME
];
2509 enable
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_ENABLE
];
2511 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_EQUIV_KEY
];
2512 if (!NILP (descrip
))
2514 int gap
= maxwidth
- XSTRING (item_name
)->size
;
2517 spacer
= Fmake_string (make_number (gap
), make_number (' '));
2518 item_name
= concat2 (item_name
, spacer
);
2519 item_name
= concat2 (item_name
, descrip
);
2520 item_data
= XSTRING (item_name
)->data
;
2522 /* if alloca is fast, use that to make the space,
2523 to reduce gc needs. */
2525 = (unsigned char *) alloca (maxwidth
2526 + XSTRING (descrip
)->size
+ 1);
2527 bcopy (XSTRING (item_name
)->data
, item_data
,
2528 XSTRING (item_name
)->size
);
2529 for (j
= XSTRING (item_name
)->size
; j
< maxwidth
; j
++)
2531 bcopy (XSTRING (descrip
)->data
, item_data
+ j
,
2532 XSTRING (descrip
)->size
);
2533 item_data
[j
+ XSTRING (descrip
)->size
] = 0;
2537 item_data
= XSTRING (item_name
)->data
;
2539 if (XMenuAddSelection (FRAME_X_DISPLAY (f
),
2540 menu
, lpane
, 0, item_data
,
2544 XMenuDestroy (FRAME_X_DISPLAY (f
), menu
);
2545 *error
= "Can't add selection to menu";
2548 i
+= MENU_ITEMS_ITEM_LENGTH
;
2552 /* All set and ready to fly. */
2553 XMenuRecompute (FRAME_X_DISPLAY (f
), menu
);
2554 dispwidth
= DisplayWidth (FRAME_X_DISPLAY (f
),
2555 XScreenNumberOfScreen (FRAME_X_SCREEN (f
)));
2556 dispheight
= DisplayHeight (FRAME_X_DISPLAY (f
),
2557 XScreenNumberOfScreen (FRAME_X_SCREEN (f
)));
2558 x
= min (x
, dispwidth
);
2559 y
= min (y
, dispheight
);
2562 XMenuLocate (FRAME_X_DISPLAY (f
), menu
, 0, 0, x
, y
,
2563 &ulx
, &uly
, &width
, &height
);
2564 if (ulx
+width
> dispwidth
)
2566 x
-= (ulx
+ width
) - dispwidth
;
2567 ulx
= dispwidth
- width
;
2569 if (uly
+height
> dispheight
)
2571 y
-= (uly
+ height
) - dispheight
;
2572 uly
= dispheight
- height
;
2574 if (ulx
< 0) x
-= ulx
;
2575 if (uly
< 0) y
-= uly
;
2577 XMenuSetAEQ (menu
, TRUE
);
2578 XMenuSetFreeze (menu
, TRUE
);
2581 status
= XMenuActivate (FRAME_X_DISPLAY (f
), menu
, &pane
, &selidx
,
2582 x
, y
, ButtonReleaseMask
, &datap
);
2585 #ifdef HAVE_X_WINDOWS
2586 /* Assume the mouse has moved out of the X window.
2587 If it has actually moved in, we will get an EnterNotify. */
2588 x_mouse_leave (FRAME_X_DISPLAY_INFO (f
));
2595 fprintf (stderr
, "pane= %d line = %d\n", panes
, selidx
);
2598 /* Find the item number SELIDX in pane number PANE. */
2600 while (i
< menu_items_used
)
2602 if (EQ (XVECTOR (menu_items
)->contents
[i
], Qt
))
2606 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_PANE_PREFIX
];
2608 i
+= MENU_ITEMS_PANE_LENGTH
;
2617 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_VALUE
];
2620 entry
= Fcons (entry
, Qnil
);
2621 if (!NILP (pane_prefix
))
2622 entry
= Fcons (pane_prefix
, entry
);
2628 i
+= MENU_ITEMS_ITEM_LENGTH
;
2634 *error
= "Can't activate menu";
2640 XMenuDestroy (FRAME_X_DISPLAY (f
), menu
);
2642 #ifdef HAVE_X_WINDOWS
2643 /* State that no mouse buttons are now held.
2644 (The oldXMenu code doesn't track this info for us.)
2645 That is not necessarily true, but the fiction leads to reasonable
2646 results, and it is a pain to ask which are actually held now. */
2647 FRAME_X_DISPLAY_INFO (f
)->grabbed
= 0;
2653 #endif /* not USE_X_TOOLKIT */
2655 #endif /* HAVE_MENUS */
2659 staticpro (&menu_items
);
2662 Qmenu_alias
= intern ("menu-alias");
2663 staticpro (&Qmenu_alias
);
2665 Qdebug_on_next_call
= intern ("debug-on-next-call");
2666 staticpro (&Qdebug_on_next_call
);
2668 #ifdef USE_X_TOOLKIT
2669 widget_id_tick
= (1<<16);
2670 next_menubar_widget_id
= 1;
2673 defsubr (&Sx_popup_menu
);
2675 defsubr (&Sx_popup_dialog
);