(ido-make-merged-file-list): Fix last change again.
[bpt/emacs.git] / src / xmenu.c
CommitLineData
dcfdbac7 1/* X Communication module for terminals which understand the X protocol.
950eaee7
GM
2 Copyright (C) 1986, 88, 93, 94, 96, 99, 2000, 2001
3 Free Software Foundation, Inc.
dcfdbac7
JB
4
5This file is part of GNU Emacs.
6
7GNU Emacs is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
774910eb 9the Free Software Foundation; either version 2, or (at your option)
dcfdbac7
JB
10any later version.
11
12GNU Emacs is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU Emacs; see the file COPYING. If not, write to
3b7ad313
EN
19the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, USA. */
dcfdbac7 21
c9e60620 22/* X pop-up deck-of-cards menu facility for GNU Emacs.
dcfdbac7
JB
23 *
24 * Written by Jon Arnold and Roman Budzianowski
25 * Mods and rewrite by Robert Krawitz
26 *
27 */
28
18686d47
RS
29/* Modified by Fred Pierresteguy on December 93
30 to make the popup menus and menubar use the Xt. */
31
78589e07
RS
32/* Rewritten for clarity and GC protection by rms in Feb 94. */
33
68c45bf0
PE
34#include <config.h>
35
dcfdbac7
JB
36/* On 4.3 this loses if it comes after xterm.h. */
37#include <signal.h>
565620a5
RS
38
39#include <stdio.h>
7ee72033 40
dcfdbac7 41#include "lisp.h"
18686d47 42#include "termhooks.h"
02067692 43#include "keyboard.h"
5ee707b8 44#include "keymap.h"
7708e9bd 45#include "frame.h"
dcfdbac7 46#include "window.h"
9ac0d9e0 47#include "blockinput.h"
88766961 48#include "buffer.h"
cc45fb40
SM
49#include "charset.h"
50#include "coding.h"
dcfdbac7 51
eeee3112
RS
52#ifdef MSDOS
53#include "msdos.h"
54#endif
55
87485d6f 56#ifdef HAVE_X_WINDOWS
dcfdbac7
JB
57/* This may include sys/types.h, and that somehow loses
58 if this is not done before the other system files. */
59#include "xterm.h"
87485d6f 60#endif
dcfdbac7
JB
61
62/* Load sys/types.h if not already loaded.
63 In some systems loading it twice is suicidal. */
64#ifndef makedev
65#include <sys/types.h>
66#endif
67
68#include "dispextern.h"
69
87485d6f 70#ifdef HAVE_X_WINDOWS
703dc2a8 71#undef HAVE_MULTILINGUAL_MENU
18686d47 72#ifdef USE_X_TOOLKIT
991786dd 73#include "widget.h"
18686d47
RS
74#include <X11/Xlib.h>
75#include <X11/IntrinsicP.h>
76#include <X11/CoreP.h>
77#include <X11/StringDefs.h>
60f312e2 78#include <X11/Shell.h>
5ee80bd3 79#ifdef USE_LUCID
1d1c1567 80#include <X11/Xaw/Paned.h>
5ee80bd3 81#endif /* USE_LUCID */
18686d47 82#include "../lwlib/lwlib.h"
a352a815
RS
83#else /* not USE_X_TOOLKIT */
84#include "../oldXMenu/XMenu.h"
85#endif /* not USE_X_TOOLKIT */
86#endif /* HAVE_X_WINDOWS */
18686d47 87
dcfdbac7
JB
88#ifndef TRUE
89#define TRUE 1
90#define FALSE 0
78589e07 91#endif /* no TRUE */
dcfdbac7 92
bfc524bc
RS
93Lisp_Object Vmenu_updating_frame;
94
0314aacb
RS
95Lisp_Object Qdebug_on_next_call;
96
18686d47 97extern Lisp_Object Qmenu_bar;
92280f67 98extern Lisp_Object Qmouse_click, Qevent_kind;
78589e07 99
de57a39c 100extern Lisp_Object QCtoggle, QCradio;
8fbc986d 101
88766961
RS
102extern Lisp_Object Voverriding_local_map;
103extern Lisp_Object Voverriding_local_map_menu_flag;
104
105extern Lisp_Object Qoverriding_local_map, Qoverriding_terminal_local_map;
106
107extern Lisp_Object Qmenu_bar_update_hook;
108
18686d47 109#ifdef USE_X_TOOLKIT
88766961 110extern void set_frame_menubar ();
78589e07
RS
111extern void process_expose_from_menu ();
112extern XtAppContext Xt_app_con;
113
165e1749 114static Lisp_Object xdialog_show ();
4dedbfe0 115void popup_get_selection ();
3427a3db 116
c9e60620 117/* Define HAVE_BOXES if menus can handle radio and toggle buttons. */
3427a3db
GM
118
119#define HAVE_BOXES 1
120#endif
121
122static void push_menu_item P_ ((Lisp_Object, Lisp_Object, Lisp_Object,
123 Lisp_Object, Lisp_Object, Lisp_Object,
850df50b 124 Lisp_Object, Lisp_Object));
f61a541b
GM
125static int update_frame_menubar P_ ((struct frame *));
126static Lisp_Object xmenu_show P_ ((struct frame *, int, int, int, int,
127 Lisp_Object, char **));
128static void keymap_panes P_ ((Lisp_Object *, int, int));
129static void single_keymap_panes P_ ((Lisp_Object, Lisp_Object, Lisp_Object,
130 int, int));
131static void single_menu_item P_ ((Lisp_Object, Lisp_Object, Lisp_Object *,
132 int, int, int *));
133static void list_of_panes P_ ((Lisp_Object));
134static void list_of_items P_ ((Lisp_Object));
78589e07
RS
135\f
136/* This holds a Lisp vector that holds the results of decoding
137 the keymaps or alist-of-alists that specify a menu.
dcfdbac7 138
78589e07 139 It describes the panes and items within the panes.
dcfdbac7 140
78589e07
RS
141 Each pane is described by 3 elements in the vector:
142 t, the pane name, the pane's prefix key.
a352a815 143 Then follow the pane's items, with 5 elements per item:
78589e07 144 the item string, the enable flag, the item's value,
a352a815 145 the definition, and the equivalent keyboard key's description string.
dcfdbac7 146
101bb4a5
RS
147 In some cases, multiple levels of menus may be described.
148 A single vector slot containing nil indicates the start of a submenu.
149 A single vector slot containing lambda indicates the end of a submenu.
150 The submenu follows a menu item which is the way to reach the submenu.
151
fcaa7665
RS
152 A single vector slot containing quote indicates that the
153 following items should appear on the right of a dialog box.
154
78589e07
RS
155 Using a Lisp vector to hold this information while we decode it
156 takes care of protecting all the data from GC. */
dcfdbac7 157
78589e07
RS
158#define MENU_ITEMS_PANE_NAME 1
159#define MENU_ITEMS_PANE_PREFIX 2
160#define MENU_ITEMS_PANE_LENGTH 3
088831f6 161
850df50b
GM
162enum menu_item_idx
163{
164 MENU_ITEMS_ITEM_NAME = 0,
165 MENU_ITEMS_ITEM_ENABLE,
166 MENU_ITEMS_ITEM_VALUE,
167 MENU_ITEMS_ITEM_EQUIV_KEY,
168 MENU_ITEMS_ITEM_DEFINITION,
169 MENU_ITEMS_ITEM_TYPE,
170 MENU_ITEMS_ITEM_SELECTED,
171 MENU_ITEMS_ITEM_HELP,
172 MENU_ITEMS_ITEM_LENGTH
173};
7da99777 174
78589e07 175static Lisp_Object menu_items;
18686d47 176
78589e07
RS
177/* Number of slots currently allocated in menu_items. */
178static int menu_items_allocated;
18686d47 179
78589e07
RS
180/* This is the index in menu_items of the first empty slot. */
181static int menu_items_used;
18686d47 182
101bb4a5
RS
183/* The number of panes currently recorded in menu_items,
184 excluding those within submenus. */
78589e07 185static int menu_items_n_panes;
18686d47 186
101bb4a5
RS
187/* Current depth within submenus. */
188static int menu_items_submenu_depth;
189
4dedbfe0 190/* Flag which when set indicates a dialog or menu has been posted by
c98fcf4b 191 Xt on behalf of one of the widget sets. */
7555d825 192int popup_activated_flag;
4dedbfe0 193
88766961 194static int next_menubar_widget_id;
745c34fb 195
a9be6839
RS
196/* This is set nonzero after the user activates the menu bar, and set
197 to zero again after the menu bars are redisplayed by prepare_menu_bar.
198 While it is nonzero, all calls to set_frame_menubar go deep.
199
200 I don't understand why this is needed, but it does seem to be
201 needed on Motif, according to Marcus Daniels <marcus@sysc.pdx.edu>. */
202
203int pending_menu_activation;
bd3a4da2 204\f
88766961 205#ifdef USE_X_TOOLKIT
bd3a4da2 206
7556890b 207/* Return the frame whose ->output_data.x->id equals ID, or 0 if none. */
bd3a4da2 208
88766961
RS
209static struct frame *
210menubar_id_to_frame (id)
211 LWLIB_ID id;
212{
213 Lisp_Object tail, frame;
214 FRAME_PTR f;
bd3a4da2 215
8e713be6 216 for (tail = Vframe_list; GC_CONSP (tail); tail = XCDR (tail))
bd3a4da2 217 {
8e713be6 218 frame = XCAR (tail);
88766961
RS
219 if (!GC_FRAMEP (frame))
220 continue;
221 f = XFRAME (frame);
2d764c78 222 if (!FRAME_WINDOW_P (f))
88766961 223 continue;
7556890b 224 if (f->output_data.x->id == id)
88766961 225 return f;
bd3a4da2 226 }
88766961 227 return 0;
bd3a4da2 228}
88766961
RS
229
230#endif
4dedbfe0 231\f
78589e07
RS
232/* Initialize the menu_items structure if we haven't already done so.
233 Also mark it as currently empty. */
234
235static void
236init_menu_items ()
237{
238 if (NILP (menu_items))
239 {
240 menu_items_allocated = 60;
241 menu_items = Fmake_vector (make_number (menu_items_allocated), Qnil);
18686d47
RS
242 }
243
78589e07
RS
244 menu_items_used = 0;
245 menu_items_n_panes = 0;
101bb4a5 246 menu_items_submenu_depth = 0;
78589e07 247}
18686d47 248
0b1f4572 249/* Call at the end of generating the data in menu_items. */
1658603c 250
78589e07
RS
251static void
252finish_menu_items ()
253{
254}
1658603c 255
78589e07
RS
256/* Call when finished using the data for the current menu
257 in menu_items. */
1658603c 258
78589e07
RS
259static void
260discard_menu_items ()
261{
262 /* Free the structure if it is especially large.
263 Otherwise, hold on to it, to save time. */
264 if (menu_items_allocated > 200)
265 {
266 menu_items = Qnil;
267 menu_items_allocated = 0;
268 }
269}
1658603c 270
101bb4a5
RS
271/* Make the menu_items vector twice as large. */
272
273static void
274grow_menu_items ()
275{
276 Lisp_Object old;
277 int old_size = menu_items_allocated;
278 old = menu_items;
279
280 menu_items_allocated *= 2;
281 menu_items = Fmake_vector (make_number (menu_items_allocated), Qnil);
282 bcopy (XVECTOR (old)->contents, XVECTOR (menu_items)->contents,
283 old_size * sizeof (Lisp_Object));
284}
285
286/* Begin a submenu. */
287
288static void
289push_submenu_start ()
290{
291 if (menu_items_used + 1 > menu_items_allocated)
292 grow_menu_items ();
293
294 XVECTOR (menu_items)->contents[menu_items_used++] = Qnil;
295 menu_items_submenu_depth++;
296}
297
298/* End a submenu. */
299
300static void
301push_submenu_end ()
302{
303 if (menu_items_used + 1 > menu_items_allocated)
304 grow_menu_items ();
305
306 XVECTOR (menu_items)->contents[menu_items_used++] = Qlambda;
307 menu_items_submenu_depth--;
308}
309
fcaa7665
RS
310/* Indicate boundary between left and right. */
311
312static void
313push_left_right_boundary ()
314{
315 if (menu_items_used + 1 > menu_items_allocated)
316 grow_menu_items ();
317
318 XVECTOR (menu_items)->contents[menu_items_used++] = Qquote;
319}
320
c9e60620 321/* Start a new menu pane in menu_items.
78589e07 322 NAME is the pane name. PREFIX_VEC is a prefix key for this pane. */
1658603c 323
78589e07
RS
324static void
325push_menu_pane (name, prefix_vec)
326 Lisp_Object name, prefix_vec;
327{
328 if (menu_items_used + MENU_ITEMS_PANE_LENGTH > menu_items_allocated)
101bb4a5 329 grow_menu_items ();
dcfdbac7 330
101bb4a5
RS
331 if (menu_items_submenu_depth == 0)
332 menu_items_n_panes++;
78589e07
RS
333 XVECTOR (menu_items)->contents[menu_items_used++] = Qt;
334 XVECTOR (menu_items)->contents[menu_items_used++] = name;
335 XVECTOR (menu_items)->contents[menu_items_used++] = prefix_vec;
336}
dcfdbac7 337
3427a3db
GM
338/* Push one menu item into the current pane. NAME is the string to
339 display. ENABLE if non-nil means this item can be selected. KEY
340 is the key generated by choosing this item, or nil if this item
341 doesn't really have a definition. DEF is the definition of this
342 item. EQUIV is the textual description of the keyboard equivalent
343 for this item (or nil if none). TYPE is the type of this menu
344 item, one of nil, `toggle' or `radio'. */
18686d47 345
78589e07 346static void
850df50b
GM
347push_menu_item (name, enable, key, def, equiv, type, selected, help)
348 Lisp_Object name, enable, key, def, equiv, type, selected, help;
78589e07
RS
349{
350 if (menu_items_used + MENU_ITEMS_ITEM_LENGTH > menu_items_allocated)
101bb4a5 351 grow_menu_items ();
088831f6 352
78589e07
RS
353 XVECTOR (menu_items)->contents[menu_items_used++] = name;
354 XVECTOR (menu_items)->contents[menu_items_used++] = enable;
355 XVECTOR (menu_items)->contents[menu_items_used++] = key;
356 XVECTOR (menu_items)->contents[menu_items_used++] = equiv;
a352a815 357 XVECTOR (menu_items)->contents[menu_items_used++] = def;
3427a3db
GM
358 XVECTOR (menu_items)->contents[menu_items_used++] = type;
359 XVECTOR (menu_items)->contents[menu_items_used++] = selected;
850df50b 360 XVECTOR (menu_items)->contents[menu_items_used++] = help;
78589e07
RS
361}
362\f
78589e07 363/* Look through KEYMAPS, a vector of keymaps that is NMAPS long,
101bb4a5
RS
364 and generate menu panes for them in menu_items.
365 If NOTREAL is nonzero,
366 don't bother really computing whether an item is enabled. */
18686d47 367
78589e07 368static void
101bb4a5 369keymap_panes (keymaps, nmaps, notreal)
78589e07
RS
370 Lisp_Object *keymaps;
371 int nmaps;
101bb4a5 372 int notreal;
18686d47 373{
78589e07 374 int mapno;
18686d47 375
78589e07 376 init_menu_items ();
18686d47 377
78589e07
RS
378 /* Loop over the given keymaps, making a pane for each map.
379 But don't make a pane that is empty--ignore that map instead.
380 P is the number of panes we have made so far. */
381 for (mapno = 0; mapno < nmaps; mapno++)
488205c0 382 single_keymap_panes (keymaps[mapno],
5ee707b8 383 Fkeymap_prompt (keymaps[mapno]), Qnil, notreal, 10);
78589e07
RS
384
385 finish_menu_items ();
386}
387
388/* This is a recursive subroutine of keymap_panes.
389 It handles one keymap, KEYMAP.
390 The other arguments are passed along
101bb4a5 391 or point to local variables of the previous function.
de57a39c
RS
392 If NOTREAL is nonzero, only check for equivalent key bindings, don't
393 evaluate expressions in menu items and don't make any menu.
98381e42
RS
394
395 If we encounter submenus deeper than MAXDEPTH levels, ignore them. */
78589e07
RS
396
397static void
98381e42 398single_keymap_panes (keymap, pane_name, prefix, notreal, maxdepth)
78589e07
RS
399 Lisp_Object keymap;
400 Lisp_Object pane_name;
401 Lisp_Object prefix;
101bb4a5 402 int notreal;
98381e42 403 int maxdepth;
78589e07 404{
de57a39c
RS
405 Lisp_Object pending_maps = Qnil;
406 Lisp_Object tail, item;
407 struct gcpro gcpro1, gcpro2;
408 int notbuttons = 0;
78589e07 409
98381e42
RS
410 if (maxdepth <= 0)
411 return;
412
78589e07
RS
413 push_menu_pane (pane_name, prefix);
414
de57a39c
RS
415#ifndef HAVE_BOXES
416 /* Remember index for first item in this pane so we can go back and
417 add a prefix when (if) we see the first button. After that, notbuttons
418 is set to 0, to mark that we have seen a button and all non button
419 items need a prefix. */
420 notbuttons = menu_items_used;
421#endif
422
8e713be6 423 for (tail = keymap; CONSP (tail); tail = XCDR (tail))
18686d47 424 {
de57a39c
RS
425 GCPRO2 (keymap, pending_maps);
426 /* Look at each key binding, and if it is a menu item add it
427 to this menu. */
8e713be6 428 item = XCAR (tail);
b5bb2705 429 if (CONSP (item))
8e713be6 430 single_menu_item (XCAR (item), XCDR (item),
de57a39c 431 &pending_maps, notreal, maxdepth, &notbuttons);
b5bb2705 432 else if (VECTORP (item))
78589e07
RS
433 {
434 /* Loop over the char values represented in the vector. */
435 int len = XVECTOR (item)->size;
436 int c;
437 for (c = 0; c < len; c++)
438 {
439 Lisp_Object character;
33b43fa6 440 XSETFASTINT (character, c);
de57a39c
RS
441 single_menu_item (character, XVECTOR (item)->contents[c],
442 &pending_maps, notreal, maxdepth, &notbuttons);
78589e07 443 }
18686d47 444 }
de57a39c 445 UNGCPRO;
18686d47 446 }
78589e07
RS
447
448 /* Process now any submenus which want to be panes at this level. */
449 while (!NILP (pending_maps))
450 {
101bb4a5 451 Lisp_Object elt, eltcdr, string;
78589e07 452 elt = Fcar (pending_maps);
8e713be6
KR
453 eltcdr = XCDR (elt);
454 string = XCAR (eltcdr);
101bb4a5
RS
455 /* We no longer discard the @ from the beginning of the string here.
456 Instead, we do this in xmenu_show. */
457 single_keymap_panes (Fcar (elt), string,
8e713be6 458 XCDR (eltcdr), notreal, maxdepth - 1);
78589e07
RS
459 pending_maps = Fcdr (pending_maps);
460 }
18686d47 461}
78589e07 462\f
de57a39c
RS
463/* This is a subroutine of single_keymap_panes that handles one
464 keymap entry.
465 KEY is a key in a keymap and ITEM is its binding.
466 PENDING_MAPS_PTR points to a list of keymaps waiting to be made into
467 separate panes.
468 If NOTREAL is nonzero, only check for equivalent key bindings, don't
469 evaluate expressions in menu items and don't make any menu.
470 If we encounter submenus deeper than MAXDEPTH levels, ignore them.
471 NOTBUTTONS_PTR is only used when simulating toggle boxes and radio
472 buttons. It points to variable notbuttons in single_keymap_panes,
473 which keeps track of if we have seen a button in this menu or not. */
474
475static void
476single_menu_item (key, item, pending_maps_ptr, notreal, maxdepth,
477 notbuttons_ptr)
478 Lisp_Object key, item;
479 Lisp_Object *pending_maps_ptr;
480 int maxdepth, notreal;
481 int *notbuttons_ptr;
482{
faa935b6 483 Lisp_Object map, item_string, enabled;
de57a39c
RS
484 struct gcpro gcpro1, gcpro2;
485 int res;
486
487 /* Parse the menu item and leave the result in item_properties. */
488 GCPRO2 (key, item);
489 res = parse_menu_item (item, notreal, 0);
490 UNGCPRO;
491 if (!res)
492 return; /* Not a menu item. */
493
494 map = XVECTOR (item_properties)->contents[ITEM_PROPERTY_MAP];
495
496 if (notreal)
497 {
498 /* We don't want to make a menu, just traverse the keymaps to
499 precompute equivalent key bindings. */
500 if (!NILP (map))
501 single_keymap_panes (map, Qnil, key, 1, maxdepth - 1);
502 return;
503 }
504
505 enabled = XVECTOR (item_properties)->contents[ITEM_PROPERTY_ENABLE];
506 item_string = XVECTOR (item_properties)->contents[ITEM_PROPERTY_NAME];
507
508 if (!NILP (map) && XSTRING (item_string)->data[0] == '@')
509 {
510 if (!NILP (enabled))
511 /* An enabled separate pane. Remember this to handle it later. */
512 *pending_maps_ptr = Fcons (Fcons (map, Fcons (item_string, key)),
513 *pending_maps_ptr);
514 return;
515 }
516
517#ifndef HAVE_BOXES
518 /* Simulate radio buttons and toggle boxes by putting a prefix in
519 front of them. */
520 {
521 Lisp_Object prefix = Qnil;
522 Lisp_Object type = XVECTOR (item_properties)->contents[ITEM_PROPERTY_TYPE];
523 if (!NILP (type))
524 {
525 Lisp_Object selected
526 = XVECTOR (item_properties)->contents[ITEM_PROPERTY_SELECTED];
527
528 if (*notbuttons_ptr)
529 /* The first button. Line up previous items in this menu. */
530 {
531 int index = *notbuttons_ptr; /* Index for first item this menu. */
532 int submenu = 0;
533 Lisp_Object tem;
534 while (index < menu_items_used)
535 {
536 tem
537 = XVECTOR (menu_items)->contents[index + MENU_ITEMS_ITEM_NAME];
538 if (NILP (tem))
539 {
540 index++;
541 submenu++; /* Skip sub menu. */
542 }
543 else if (EQ (tem, Qlambda))
544 {
545 index++;
546 submenu--; /* End sub menu. */
547 }
548 else if (EQ (tem, Qt))
549 index += 3; /* Skip new pane marker. */
550 else if (EQ (tem, Qquote))
551 index++; /* Skip a left, right divider. */
552 else
553 {
554 if (!submenu && XSTRING (tem)->data[0] != '\0'
555 && XSTRING (tem)->data[0] != '-')
556 XVECTOR (menu_items)->contents[index + MENU_ITEMS_ITEM_NAME]
557 = concat2 (build_string (" "), tem);
558 index += MENU_ITEMS_ITEM_LENGTH;
559 }
560 }
561 *notbuttons_ptr = 0;
562 }
563
564 /* Calculate prefix, if any, for this item. */
565 if (EQ (type, QCtoggle))
566 prefix = build_string (NILP (selected) ? "[ ] " : "[X] ");
567 else if (EQ (type, QCradio))
568 prefix = build_string (NILP (selected) ? "( ) " : "(*) ");
569 }
570 /* Not a button. If we have earlier buttons, then we need a prefix. */
571 else if (!*notbuttons_ptr && XSTRING (item_string)->data[0] != '\0'
572 && XSTRING (item_string)->data[0] != '-')
573 prefix = build_string (" ");
574
575 if (!NILP (prefix))
576 item_string = concat2 (prefix, item_string);
577 }
578#endif /* not HAVE_BOXES */
579
580#ifndef USE_X_TOOLKIT
581 if (!NILP(map))
582 /* Indicate visually that this is a submenu. */
583 item_string = concat2 (item_string, build_string (" >"));
584#endif
585
586 push_menu_item (item_string, enabled, key,
587 XVECTOR (item_properties)->contents[ITEM_PROPERTY_DEF],
3427a3db
GM
588 XVECTOR (item_properties)->contents[ITEM_PROPERTY_KEYEQ],
589 XVECTOR (item_properties)->contents[ITEM_PROPERTY_TYPE],
850df50b
GM
590 XVECTOR (item_properties)->contents[ITEM_PROPERTY_SELECTED],
591 XVECTOR (item_properties)->contents[ITEM_PROPERTY_HELP]);
de57a39c
RS
592
593#ifdef USE_X_TOOLKIT
594 /* Display a submenu using the toolkit. */
595 if (! (NILP (map) || NILP (enabled)))
596 {
597 push_submenu_start ();
598 single_keymap_panes (map, Qnil, key, 0, maxdepth - 1);
599 push_submenu_end ();
600 }
601#endif
602}
603\f
8e6208c5 604/* Push all the panes and items of a menu described by the
78589e07
RS
605 alist-of-alists MENU.
606 This handles old-fashioned calls to x-popup-menu. */
18686d47 607
78589e07
RS
608static void
609list_of_panes (menu)
18686d47 610 Lisp_Object menu;
18686d47 611{
78589e07
RS
612 Lisp_Object tail;
613
614 init_menu_items ();
615
616 for (tail = menu; !NILP (tail); tail = Fcdr (tail))
617 {
618 Lisp_Object elt, pane_name, pane_data;
619 elt = Fcar (tail);
620 pane_name = Fcar (elt);
b7826503 621 CHECK_STRING (pane_name);
78589e07
RS
622 push_menu_pane (pane_name, Qnil);
623 pane_data = Fcdr (elt);
b7826503 624 CHECK_CONS (pane_data);
78589e07
RS
625 list_of_items (pane_data);
626 }
627
628 finish_menu_items ();
629}
630
631/* Push the items in a single pane defined by the alist PANE. */
632
633static void
634list_of_items (pane)
635 Lisp_Object pane;
636{
637 Lisp_Object tail, item, item1;
638
639 for (tail = pane; !NILP (tail); tail = Fcdr (tail))
640 {
641 item = Fcar (tail);
642 if (STRINGP (item))
850df50b 643 push_menu_item (item, Qnil, Qnil, Qt, Qnil, Qnil, Qnil, Qnil);
fcaa7665
RS
644 else if (NILP (item))
645 push_left_right_boundary ();
78589e07
RS
646 else
647 {
b7826503 648 CHECK_CONS (item);
78589e07 649 item1 = Fcar (item);
b7826503 650 CHECK_STRING (item1);
850df50b 651 push_menu_item (item1, Qt, Fcdr (item), Qt, Qnil, Qnil, Qnil, Qnil);
78589e07
RS
652 }
653 }
654}
655\f
540e52d1 656DEFUN ("x-popup-menu", Fx_popup_menu, Sx_popup_menu, 2, 2, 0,
f6e34773 657 doc: /* Pop up a deck-of-cards menu and return user's selection.
228299fa
GM
658POSITION is a position specification. This is either a mouse button event
659or a list ((XOFFSET YOFFSET) WINDOW)
660where XOFFSET and YOFFSET are positions in pixels from the top left
661corner of WINDOW's frame. (WINDOW may be a frame object instead of a window.)
662This controls the position of the center of the first line
663in the first pane of the menu, not the top left of the menu as a whole.
664If POSITION is t, it means to use the current mouse position.
665
666MENU is a specifier for a menu. For the simplest case, MENU is a keymap.
667The menu items come from key bindings that have a menu string as well as
668a definition; actually, the "definition" in such a key binding looks like
669\(STRING . REAL-DEFINITION). To give the menu a title, put a string into
670the keymap as a top-level element.
671
672If REAL-DEFINITION is nil, that puts a nonselectable string in the menu.
673Otherwise, REAL-DEFINITION should be a valid key binding definition.
674
675You can also use a list of keymaps as MENU.
676 Then each keymap makes a separate pane.
677When MENU is a keymap or a list of keymaps, the return value
678is a list of events.
679
680Alternatively, you can specify a menu of multiple panes
681 with a list of the form (TITLE PANE1 PANE2...),
682where each pane is a list of form (TITLE ITEM1 ITEM2...).
683Each ITEM is normally a cons cell (STRING . VALUE);
684but a string can appear as an item--that makes a nonselectable line
685in the menu.
686With this form of menu, the return value is VALUE from the chosen item.
687
688If POSITION is nil, don't display the menu at all, just precalculate the
7ee72033
MB
689cached information about equivalent key sequences. */)
690 (position, menu)
78589e07
RS
691 Lisp_Object position, menu;
692{
18686d47 693 Lisp_Object keymap, tem;
6bbd7a29 694 int xpos = 0, ypos = 0;
78589e07
RS
695 Lisp_Object title;
696 char *error_name;
697 Lisp_Object selection;
cc45fb40 698 FRAME_PTR f = NULL;
78589e07
RS
699 Lisp_Object x, y, window;
700 int keymaps = 0;
9685a93f 701 int for_click = 0;
78589e07
RS
702 struct gcpro gcpro1;
703
1e659e4c 704#ifdef HAVE_MENUS
78589e07
RS
705 if (! NILP (position))
706 {
101bb4a5
RS
707 check_x ();
708
78589e07 709 /* Decode the first argument: find the window and the coordinates. */
9572375b 710 if (EQ (position, Qt)
2b06561a
DL
711 || (CONSP (position) && (EQ (XCAR (position), Qmenu_bar)
712 || EQ (XCAR (position), Qtool_bar))))
78589e07
RS
713 {
714 /* Use the mouse's current position. */
b404828f 715 FRAME_PTR new_f = SELECTED_FRAME ();
78589e07 716 Lisp_Object bar_window;
dfcf069d 717 enum scroll_bar_part part;
78589e07
RS
718 unsigned long time;
719
b137c582 720 if (mouse_position_hook)
46b657e2
RS
721 (*mouse_position_hook) (&new_f, 1, &bar_window,
722 &part, &x, &y, &time);
5ca2ef64 723 if (new_f != 0)
a39f0477 724 XSETFRAME (window, new_f);
5ca2ef64
RS
725 else
726 {
727 window = selected_window;
33b43fa6
KH
728 XSETFASTINT (x, 0);
729 XSETFASTINT (y, 0);
5ca2ef64 730 }
78589e07
RS
731 }
732 else
733 {
734 tem = Fcar (position);
b5bb2705 735 if (CONSP (tem))
78589e07
RS
736 {
737 window = Fcar (Fcdr (position));
738 x = Fcar (tem);
739 y = Fcar (Fcdr (tem));
740 }
741 else
742 {
9685a93f 743 for_click = 1;
78589e07
RS
744 tem = Fcar (Fcdr (position)); /* EVENT_START (position) */
745 window = Fcar (tem); /* POSN_WINDOW (tem) */
746 tem = Fcar (Fcdr (Fcdr (tem))); /* POSN_WINDOW_POSN (tem) */
747 x = Fcar (tem);
748 y = Fcdr (tem);
78589e07
RS
749 }
750 }
751
b7826503
PJ
752 CHECK_NUMBER (x);
753 CHECK_NUMBER (y);
78589e07
RS
754
755 /* Decode where to put the menu. */
756
b5bb2705 757 if (FRAMEP (window))
78589e07
RS
758 {
759 f = XFRAME (window);
78589e07
RS
760 xpos = 0;
761 ypos = 0;
762 }
b5bb2705 763 else if (WINDOWP (window))
78589e07 764 {
b7826503 765 CHECK_LIVE_WINDOW (window);
78589e07
RS
766 f = XFRAME (WINDOW_FRAME (XWINDOW (window)));
767
cc45fb40 768 xpos = (FONT_WIDTH (FRAME_FONT (f))
99d3fac7 769 * XFASTINT (XWINDOW (window)->left));
cc45fb40 770 ypos = (FRAME_LINE_HEIGHT (f)
99d3fac7 771 * XFASTINT (XWINDOW (window)->top));
78589e07
RS
772 }
773 else
774 /* ??? Not really clean; should be CHECK_WINDOW_OR_FRAME,
775 but I don't want to make one now. */
b7826503 776 CHECK_WINDOW (window);
78589e07
RS
777
778 xpos += XINT (x);
779 ypos += XINT (y);
bfc524bc
RS
780
781 XSETFRAME (Vmenu_updating_frame, f);
78589e07 782 }
bfc524bc 783 Vmenu_updating_frame = Qnil;
1e659e4c 784#endif /* HAVE_MENUS */
78589e07
RS
785
786 title = Qnil;
787 GCPRO1 (title);
788
789 /* Decode the menu items from what was specified. */
18686d47 790
02067692
SM
791 keymap = get_keymap (menu, 0, 0);
792 if (CONSP (keymap))
18686d47
RS
793 {
794 /* We were given a keymap. Extract menu info from the keymap. */
795 Lisp_Object prompt;
18686d47 796
78589e07 797 /* Extract the detailed info to make one pane. */
101bb4a5 798 keymap_panes (&menu, 1, NILP (position));
78589e07 799
18686d47
RS
800 /* Search for a string appearing directly as an element of the keymap.
801 That string is the title of the menu. */
5ee707b8 802 prompt = Fkeymap_prompt (keymap);
4f9ad016
RS
803 if (NILP (title) && !NILP (prompt))
804 title = prompt;
18686d47 805
78589e07
RS
806 /* Make that be the pane title of the first pane. */
807 if (!NILP (prompt) && menu_items_n_panes >= 0)
808 XVECTOR (menu_items)->contents[MENU_ITEMS_PANE_NAME] = prompt;
809
810 keymaps = 1;
18686d47 811 }
02067692 812 else if (CONSP (menu) && KEYMAPP (XCAR (menu)))
18686d47
RS
813 {
814 /* We were given a list of keymaps. */
18686d47
RS
815 int nmaps = XFASTINT (Flength (menu));
816 Lisp_Object *maps
817 = (Lisp_Object *) alloca (nmaps * sizeof (Lisp_Object));
818 int i;
78589e07
RS
819
820 title = Qnil;
18686d47
RS
821
822 /* The first keymap that has a prompt string
823 supplies the menu title. */
b5bb2705 824 for (tem = menu, i = 0; CONSP (tem); tem = Fcdr (tem))
18686d47 825 {
78589e07
RS
826 Lisp_Object prompt;
827
02067692 828 maps[i++] = keymap = get_keymap (Fcar (tem), 1, 0);
18686d47 829
5ee707b8 830 prompt = Fkeymap_prompt (keymap);
78589e07
RS
831 if (NILP (title) && !NILP (prompt))
832 title = prompt;
18686d47
RS
833 }
834
835 /* Extract the detailed info to make one pane. */
101bb4a5 836 keymap_panes (maps, nmaps, NILP (position));
78589e07
RS
837
838 /* Make the title be the pane title of the first pane. */
839 if (!NILP (title) && menu_items_n_panes >= 0)
840 XVECTOR (menu_items)->contents[MENU_ITEMS_PANE_NAME] = title;
841
842 keymaps = 1;
18686d47
RS
843 }
844 else
845 {
846 /* We were given an old-fashioned menu. */
78589e07 847 title = Fcar (menu);
b7826503 848 CHECK_STRING (title);
18686d47 849
78589e07 850 list_of_panes (Fcdr (menu));
18686d47 851
78589e07
RS
852 keymaps = 0;
853 }
18686d47 854
78589e07 855 if (NILP (position))
18686d47 856 {
78589e07
RS
857 discard_menu_items ();
858 UNGCPRO;
859 return Qnil;
18686d47
RS
860 }
861
1e659e4c 862#ifdef HAVE_MENUS
78589e07
RS
863 /* Display them in a menu. */
864 BLOCK_INPUT;
18686d47 865
673a6211 866 selection = xmenu_show (f, xpos, ypos, for_click,
78589e07
RS
867 keymaps, title, &error_name);
868 UNBLOCK_INPUT;
18686d47 869
78589e07 870 discard_menu_items ();
18686d47 871
78589e07 872 UNGCPRO;
1e659e4c 873#endif /* HAVE_MENUS */
18686d47 874
78589e07
RS
875 if (error_name) error (error_name);
876 return selection;
18686d47 877}
165e1749 878
1e659e4c
RS
879#ifdef HAVE_MENUS
880
540e52d1 881DEFUN ("x-popup-dialog", Fx_popup_dialog, Sx_popup_dialog, 2, 2, 0,
f6e34773 882 doc: /* Pop up a dialog box and return user's selection.
228299fa
GM
883POSITION specifies which frame to use.
884This is normally a mouse button event or a window or frame.
885If POSITION is t, it means to use the frame the mouse is on.
886The dialog box appears in the middle of the specified frame.
887
888CONTENTS specifies the alternatives to display in the dialog box.
889It is a list of the form (TITLE ITEM1 ITEM2...).
890Each ITEM is a cons cell (STRING . VALUE).
891The return value is VALUE from the chosen item.
892
893An ITEM may also be just a string--that makes a nonselectable item.
894An ITEM may also be nil--that means to put all preceding items
895on the left of the dialog box and all following items on the right.
7ee72033
MB
896\(By default, approximately half appear on each side.) */)
897 (position, contents)
99fe880d 898 Lisp_Object position, contents;
165e1749 899{
cc45fb40 900 FRAME_PTR f = NULL;
99fe880d 901 Lisp_Object window;
165e1749
FP
902
903 check_x ();
904
99fe880d 905 /* Decode the first argument: find the window or frame to use. */
88d4f6ec 906 if (EQ (position, Qt)
2b06561a
DL
907 || (CONSP (position) && (EQ (XCAR (position), Qmenu_bar)
908 || EQ (XCAR (position), Qtool_bar))))
165e1749 909 {
b14db4d7 910#if 0 /* Using the frame the mouse is on may not be right. */
99fe880d 911 /* Use the mouse's current position. */
b404828f 912 FRAME_PTR new_f = SELECTED_FRAME ();
99fe880d 913 Lisp_Object bar_window;
cc45fb40 914 enum scroll_bar_part part;
99fe880d
RS
915 unsigned long time;
916 Lisp_Object x, y;
165e1749 917
46b657e2 918 (*mouse_position_hook) (&new_f, 1, &bar_window, &part, &x, &y, &time);
5ca2ef64 919
99fe880d 920 if (new_f != 0)
a39f0477 921 XSETFRAME (window, new_f);
99fe880d
RS
922 else
923 window = selected_window;
b14db4d7 924#endif
88d4f6ec 925 window = selected_window;
99fe880d
RS
926 }
927 else if (CONSP (position))
928 {
929 Lisp_Object tem;
930 tem = Fcar (position);
b5bb2705 931 if (CONSP (tem))
99fe880d 932 window = Fcar (Fcdr (position));
80670155
RS
933 else
934 {
99fe880d
RS
935 tem = Fcar (Fcdr (position)); /* EVENT_START (position) */
936 window = Fcar (tem); /* POSN_WINDOW (tem) */
165e1749 937 }
165e1749 938 }
99fe880d
RS
939 else if (WINDOWP (position) || FRAMEP (position))
940 window = position;
a9be6839
RS
941 else
942 window = Qnil;
165e1749 943
99fe880d 944 /* Decode where to put the menu. */
165e1749 945
b5bb2705 946 if (FRAMEP (window))
99fe880d 947 f = XFRAME (window);
b5bb2705 948 else if (WINDOWP (window))
165e1749 949 {
b7826503 950 CHECK_LIVE_WINDOW (window);
99fe880d 951 f = XFRAME (WINDOW_FRAME (XWINDOW (window)));
165e1749 952 }
99fe880d
RS
953 else
954 /* ??? Not really clean; should be CHECK_WINDOW_OR_FRAME,
955 but I don't want to make one now. */
b7826503 956 CHECK_WINDOW (window);
165e1749 957
99fe880d
RS
958#ifndef USE_X_TOOLKIT
959 /* Display a menu with these alternatives
960 in the middle of frame F. */
961 {
962 Lisp_Object x, y, frame, newpos;
a39f0477
KH
963 XSETFRAME (frame, f);
964 XSETINT (x, x_pixel_width (f) / 2);
965 XSETINT (y, x_pixel_height (f) / 2);
99fe880d
RS
966 newpos = Fcons (Fcons (x, Fcons (y, Qnil)), Fcons (frame, Qnil));
967
968 return Fx_popup_menu (newpos,
969 Fcons (Fcar (contents), Fcons (contents, Qnil)));
970 }
971#else
972 {
973 Lisp_Object title;
974 char *error_name;
975 Lisp_Object selection;
165e1749 976
99fe880d
RS
977 /* Decode the dialog items from what was specified. */
978 title = Fcar (contents);
b7826503 979 CHECK_STRING (title);
165e1749 980
99fe880d 981 list_of_panes (Fcons (contents, Qnil));
165e1749 982
99fe880d
RS
983 /* Display them in a dialog box. */
984 BLOCK_INPUT;
f8c2630d 985 selection = xdialog_show (f, 0, title, &error_name);
99fe880d 986 UNBLOCK_INPUT;
165e1749 987
99fe880d
RS
988 discard_menu_items ();
989
990 if (error_name) error (error_name);
991 return selection;
992 }
7464b131 993#endif
392d3f4b 994}
78589e07
RS
995\f
996#ifdef USE_X_TOOLKIT
18686d47 997
4dedbfe0 998/* Loop in Xt until the menu pulldown or dialog popup has been
f56e7ad2
RS
999 popped down (deactivated). This is used for x-popup-menu
1000 and x-popup-dialog; it is not used for the menu bar any more.
c98fcf4b 1001
2e2b8e22 1002 NOTE: All calls to popup_get_selection should be protected
c98fcf4b 1003 with BLOCK_INPUT, UNBLOCK_INPUT wrappers. */
aa669def 1004
4dedbfe0 1005void
2e2b8e22 1006popup_get_selection (initial_event, dpyinfo, id)
4dedbfe0 1007 XEvent *initial_event;
aa669def 1008 struct x_display_info *dpyinfo;
2e2b8e22 1009 LWLIB_ID id;
78589e07 1010{
4dedbfe0 1011 XEvent event;
78589e07 1012
aa669def
RS
1013 /* Define a queue to save up for later unreading
1014 all X events that don't pertain to the menu. */
1015 struct event_queue
1016 {
1017 XEvent event;
1018 struct event_queue *next;
1019 };
1020
1021 struct event_queue *queue = NULL;
1022 struct event_queue *queue_tmp;
1023
4dedbfe0
PR
1024 if (initial_event)
1025 event = *initial_event;
1026 else
1027 XtAppNextEvent (Xt_app_con, &event);
78589e07 1028
4dedbfe0 1029 while (1)
78589e07 1030 {
aa669def
RS
1031 /* Handle expose events for editor frames right away. */
1032 if (event.type == Expose)
1033 process_expose_from_menu (event);
10624005
KH
1034 /* Make sure we don't consider buttons grabbed after menu goes.
1035 And make sure to deactivate for any ButtonRelease,
1036 even if XtDispatchEvent doesn't do that. */
aa669def
RS
1037 else if (event.type == ButtonRelease
1038 && dpyinfo->display == event.xbutton.display)
10624005
KH
1039 {
1040 dpyinfo->grabbed &= ~(1 << event.xbutton.button);
1041 popup_activated_flag = 0;
c8b5aa3d
RS
1042#ifdef USE_MOTIF /* Pretending that the event came from a
1043 Btn1Down seems the only way to convince Motif to
1044 activate its callbacks; setting the XmNmenuPost
1045 isn't working. --marcus@sysc.pdx.edu. */
1046 event.xbutton.button = 1;
1047#endif
10624005 1048 }
2e2b8e22
KH
1049 /* If the user presses a key, deactivate the menu.
1050 The user is likely to do that if we get wedged. */
1051 else if (event.type == KeyPress
1052 && dpyinfo->display == event.xbutton.display)
1053 {
09155689
AS
1054 KeySym keysym = XLookupKeysym (&event.xkey, 0);
1055 if (!IsModifierKey (keysym))
1056 {
1057 popup_activated_flag = 0;
1058 break;
1059 }
2e2b8e22 1060 }
d31d42cc
RS
1061 /* Button presses outside the menu also pop it down. */
1062 else if (event.type == ButtonPress
1063 && event.xany.display == dpyinfo->display
1064 && x_any_window_to_frame (dpyinfo, event.xany.window))
1065 {
1066 popup_activated_flag = 0;
1067 break;
1068 }
aa669def
RS
1069
1070 /* Queue all events not for this popup,
10624005 1071 except for Expose, which we've already handled, and ButtonRelease.
9572375b
KH
1072 Note that the X window is associated with the frame if this
1073 is a menu bar popup, but not if it's a dialog box. So we use
1074 x_non_menubar_window_to_frame, not x_any_window_to_frame. */
aa669def 1075 if (event.type != Expose
10624005
KH
1076 && !(event.type == ButtonRelease
1077 && dpyinfo->display == event.xbutton.display)
aa669def 1078 && (event.xany.display != dpyinfo->display
9572375b 1079 || x_non_menubar_window_to_frame (dpyinfo, event.xany.window)))
aa669def 1080 {
3e40ba92
GM
1081 queue_tmp = (struct event_queue *) xmalloc (sizeof *queue_tmp);
1082 queue_tmp->event = event;
1083 queue_tmp->next = queue;
1084 queue = queue_tmp;
aa669def 1085 }
9572375b
KH
1086 else
1087 XtDispatchEvent (&event);
aa669def
RS
1088
1089 if (!popup_activated ())
4dedbfe0
PR
1090 break;
1091 XtAppNextEvent (Xt_app_con, &event);
78589e07 1092 }
aa669def
RS
1093
1094 /* Unread any events that we got but did not handle. */
1095 while (queue != NULL)
1096 {
1097 queue_tmp = queue;
1098 XPutBackEvent (queue_tmp->event.xany.display, &queue_tmp->event);
1099 queue = queue_tmp->next;
36cc2d38 1100 xfree ((char *)queue_tmp);
aa669def
RS
1101 /* Cause these events to get read as soon as we UNBLOCK_INPUT. */
1102 interrupt_input_pending = 1;
1103 }
78589e07
RS
1104}
1105
88766961
RS
1106/* Activate the menu bar of frame F.
1107 This is called from keyboard.c when it gets the
3b8f9651 1108 MENU_BAR_ACTIVATE_EVENT out of the Emacs event queue.
88766961
RS
1109
1110 To activate the menu bar, we use the X button-press event
ac78b144 1111 that was saved in saved_menu_event.
88766961
RS
1112 That makes the toolkit do its thing.
1113
1114 But first we recompute the menu bar contents (the whole tree).
1115
1116 The reason for saving the button event until here, instead of
1117 passing it to the toolkit right away, is that we can safely
1118 execute Lisp code. */
1119
dfcf069d 1120void
88766961
RS
1121x_activate_menubar (f)
1122 FRAME_PTR f;
1123{
ac78b144 1124 if (!f->output_data.x->saved_menu_event->type)
88766961
RS
1125 return;
1126
a9be6839 1127 set_frame_menubar (f, 0, 1);
88766961 1128 BLOCK_INPUT;
ac78b144 1129 XtDispatchEvent ((XEvent *) f->output_data.x->saved_menu_event);
88766961 1130 UNBLOCK_INPUT;
a9be6839 1131#ifdef USE_MOTIF
745c34fb
RS
1132 if (f->output_data.x->saved_menu_event->type == ButtonRelease)
1133 pending_menu_activation = 1;
a9be6839 1134#endif
745c34fb 1135
88766961 1136 /* Ignore this if we get it a second time. */
ac78b144 1137 f->output_data.x->saved_menu_event->type = 0;
88766961
RS
1138}
1139
c98fcf4b 1140/* Detect if a dialog or menu has been posted. */
aa669def 1141
4dedbfe0
PR
1142int
1143popup_activated ()
1144{
1145 return popup_activated_flag;
1146}
1147
4dedbfe0
PR
1148/* This callback is invoked when the user selects a menubar cascade
1149 pushbutton, but before the pulldown menu is posted. */
78589e07
RS
1150
1151static void
4dedbfe0 1152popup_activate_callback (widget, id, client_data)
78589e07
RS
1153 Widget widget;
1154 LWLIB_ID id;
1155 XtPointer client_data;
1156{
4dedbfe0 1157 popup_activated_flag = 1;
7555d825
GM
1158}
1159
1160/* This callback is invoked when a dialog or menu is finished being
1161 used and has been unposted. */
1162
1163static void
1164popup_deactivate_callback (widget, id, client_data)
1165 Widget widget;
1166 LWLIB_ID id;
1167 XtPointer client_data;
1168{
7555d825 1169 popup_activated_flag = 0;
78589e07
RS
1170}
1171
850df50b
GM
1172/* Lwlib callback called when menu items are highlighted/unhighlighted
1173 while moving the mouse over them. WIDGET is the menu bar or menu
1174 popup widget. ID is its LWLIB_ID. CALL_DATA contains a pointer to
1175 the widget_value structure for the menu item, or null in case of
1176 unhighlighting. */
1177
1178void
1179menu_highlight_callback (widget, id, call_data)
1180 Widget widget;
1181 LWLIB_ID id;
1182 void *call_data;
1183{
1184 widget_value *wv = (widget_value *) call_data;
1185 struct frame *f;
1186 Lisp_Object frame, help;
850df50b 1187
0b1f4572 1188 help = wv ? wv->help : Qnil;
9cd50434 1189
850df50b
GM
1190 /* Determine the frame for the help event. */
1191 f = menubar_id_to_frame (id);
1192 if (f)
9cd50434
GM
1193 {
1194 XSETFRAME (frame, f);
1195 kbd_buffer_store_help_event (frame, help);
1196 }
850df50b
GM
1197 else
1198 {
1199 /* WIDGET is the popup menu. It's parent is the frame's
1200 widget. See which frame that is. */
1201 Widget frame_widget = XtParent (widget);
1202 Lisp_Object tail;
1203
1204 for (tail = Vframe_list; GC_CONSP (tail); tail = XCDR (tail))
1205 {
1206 frame = XCAR (tail);
1207 if (GC_FRAMEP (frame)
1208 && (f = XFRAME (frame),
1209 FRAME_X_P (f) && f->output_data.x->widget == frame_widget))
1210 break;
1211 }
850df50b 1212
9cd50434
GM
1213 show_help_echo (help, Qnil, Qnil, Qnil, 1);
1214 }
850df50b
GM
1215}
1216
4dedbfe0
PR
1217/* This callback is called from the menu bar pulldown menu
1218 when the user makes a selection.
1219 Figure out what the user chose
1220 and put the appropriate events into the keyboard buffer. */
1221
78589e07 1222static void
4dedbfe0 1223menubar_selection_callback (widget, id, client_data)
78589e07
RS
1224 Widget widget;
1225 LWLIB_ID id;
1226 XtPointer client_data;
1227{
c63f6952 1228 Lisp_Object prefix, entry;
88766961 1229 FRAME_PTR f = menubar_id_to_frame (id);
4dedbfe0
PR
1230 Lisp_Object vector;
1231 Lisp_Object *subprefix_stack;
1232 int submenu_depth = 0;
1233 int i;
1234
1235 if (!f)
1236 return;
6bbd7a29 1237 entry = Qnil;
4dedbfe0
PR
1238 subprefix_stack = (Lisp_Object *) alloca (f->menu_bar_items_used * sizeof (Lisp_Object));
1239 vector = f->menu_bar_vector;
1240 prefix = Qnil;
1241 i = 0;
1242 while (i < f->menu_bar_items_used)
1243 {
4dedbfe0
PR
1244 if (EQ (XVECTOR (vector)->contents[i], Qnil))
1245 {
1246 subprefix_stack[submenu_depth++] = prefix;
1247 prefix = entry;
1248 i++;
1249 }
1250 else if (EQ (XVECTOR (vector)->contents[i], Qlambda))
1251 {
1252 prefix = subprefix_stack[--submenu_depth];
1253 i++;
1254 }
1255 else if (EQ (XVECTOR (vector)->contents[i], Qt))
1256 {
4cb35c39 1257 prefix = XVECTOR (vector)->contents[i + MENU_ITEMS_PANE_PREFIX];
4dedbfe0
PR
1258 i += MENU_ITEMS_PANE_LENGTH;
1259 }
1260 else
1261 {
4cb35c39 1262 entry = XVECTOR (vector)->contents[i + MENU_ITEMS_ITEM_VALUE];
01d5e892
RS
1263 /* The EMACS_INT cast avoids a warning. There's no problem
1264 as long as pointers have enough bits to hold small integers. */
1265 if ((int) (EMACS_INT) client_data == i)
4dedbfe0
PR
1266 {
1267 int j;
1268 struct input_event buf;
4cb35c39 1269 Lisp_Object frame;
4dedbfe0 1270
4cb35c39 1271 XSETFRAME (frame, f);
9979315d
GM
1272 buf.kind = MENU_BAR_EVENT;
1273 buf.frame_or_window = frame;
1274 buf.arg = frame;
4dedbfe0
PR
1275 kbd_buffer_store_event (&buf);
1276
1277 for (j = 0; j < submenu_depth; j++)
1278 if (!NILP (subprefix_stack[j]))
1279 {
9979315d
GM
1280 buf.kind = MENU_BAR_EVENT;
1281 buf.frame_or_window = frame;
1282 buf.arg = subprefix_stack[j];
4dedbfe0
PR
1283 kbd_buffer_store_event (&buf);
1284 }
1285
1286 if (!NILP (prefix))
1287 {
9979315d
GM
1288 buf.kind = MENU_BAR_EVENT;
1289 buf.frame_or_window = frame;
1290 buf.arg = prefix;
4dedbfe0
PR
1291 kbd_buffer_store_event (&buf);
1292 }
1293
9979315d
GM
1294 buf.kind = MENU_BAR_EVENT;
1295 buf.frame_or_window = frame;
1296 buf.arg = entry;
4dedbfe0
PR
1297 kbd_buffer_store_event (&buf);
1298
1299 return;
1300 }
1301 i += MENU_ITEMS_ITEM_LENGTH;
1302 }
1303 }
18686d47
RS
1304}
1305
f9655c60
RS
1306/* Allocate a widget_value, blocking input. */
1307
1308widget_value *
1309xmalloc_widget_value ()
1310{
1311 widget_value *value;
1312
1313 BLOCK_INPUT;
1314 value = malloc_widget_value ();
1315 UNBLOCK_INPUT;
1316
1317 return value;
1318}
4dedbfe0
PR
1319
1320/* This recursively calls free_widget_value on the tree of widgets.
18686d47 1321 It must free all data that was malloc'ed for these widget_values.
78589e07
RS
1322 In Emacs, many slots are pointers into the data of Lisp_Strings, and
1323 must be left alone. */
1324
18686d47
RS
1325void
1326free_menubar_widget_value_tree (wv)
1327 widget_value *wv;
1328{
1329 if (! wv) return;
18686d47
RS
1330
1331 wv->name = wv->value = wv->key = (char *) 0xDEADBEEF;
1332
1333 if (wv->contents && (wv->contents != (widget_value*)1))
1334 {
1335 free_menubar_widget_value_tree (wv->contents);
1336 wv->contents = (widget_value *) 0xDEADBEEF;
1337 }
1338 if (wv->next)
1339 {
1340 free_menubar_widget_value_tree (wv->next);
1341 wv->next = (widget_value *) 0xDEADBEEF;
1342 }
1343 BLOCK_INPUT;
1344 free_widget_value (wv);
1345 UNBLOCK_INPUT;
1346}
4dedbfe0
PR
1347\f
1348/* Return a tree of widget_value structures for a menu bar item
1349 whose event type is ITEM_KEY (with string ITEM_NAME)
1350 and whose contents come from the list of keymaps MAPS. */
1351
1352static widget_value *
1353single_submenu (item_key, item_name, maps)
1354 Lisp_Object item_key, item_name, maps;
1355{
1356 widget_value *wv, *prev_wv, *save_wv, *first_wv;
1357 int i;
1358 int submenu_depth = 0;
1359 Lisp_Object length;
1360 int len;
1361 Lisp_Object *mapvec;
1362 widget_value **submenu_stack;
4dedbfe0 1363 int previous_items = menu_items_used;
71dca3e3 1364 int top_level_items = 0;
4dedbfe0
PR
1365
1366 length = Flength (maps);
1367 len = XINT (length);
1368
1369 /* Convert the list MAPS into a vector MAPVEC. */
1370 mapvec = (Lisp_Object *) alloca (len * sizeof (Lisp_Object));
1371 for (i = 0; i < len; i++)
1372 {
1373 mapvec[i] = Fcar (maps);
1374 maps = Fcdr (maps);
1375 }
1376
1377 menu_items_n_panes = 0;
1378
1379 /* Loop over the given keymaps, making a pane for each map.
1380 But don't make a pane that is empty--ignore that map instead. */
1381 for (i = 0; i < len; i++)
71dca3e3 1382 {
846e8c10 1383 if (SYMBOLP (mapvec[i])
02067692 1384 || (CONSP (mapvec[i]) && !KEYMAPP (mapvec[i])))
71dca3e3 1385 {
846e8c10
RS
1386 /* Here we have a command at top level in the menu bar
1387 as opposed to a submenu. */
71dca3e3
RS
1388 top_level_items = 1;
1389 push_menu_pane (Qnil, Qnil);
850df50b
GM
1390 push_menu_item (item_name, Qt, item_key, mapvec[i],
1391 Qnil, Qnil, Qnil, Qnil);
71dca3e3
RS
1392 }
1393 else
98381e42 1394 single_keymap_panes (mapvec[i], item_name, item_key, 0, 10);
71dca3e3 1395 }
4dedbfe0
PR
1396
1397 /* Create a tree of widget_value objects
1398 representing the panes and their items. */
1399
1400 submenu_stack
1401 = (widget_value **) alloca (menu_items_used * sizeof (widget_value *));
f7fab165 1402 wv = xmalloc_widget_value ();
4dedbfe0
PR
1403 wv->name = "menu";
1404 wv->value = 0;
1405 wv->enabled = 1;
3427a3db 1406 wv->button_type = BUTTON_TYPE_NONE;
0b1e6b54 1407 wv->help = Qnil;
4dedbfe0
PR
1408 first_wv = wv;
1409 save_wv = 0;
71dca3e3 1410 prev_wv = 0;
4dedbfe0
PR
1411
1412 /* Loop over all panes and items made during this call
1413 and construct a tree of widget_value objects.
1414 Ignore the panes and items made by previous calls to
1415 single_submenu, even though those are also in menu_items. */
1416 i = previous_items;
1417 while (i < menu_items_used)
1418 {
1419 if (EQ (XVECTOR (menu_items)->contents[i], Qnil))
1420 {
1421 submenu_stack[submenu_depth++] = save_wv;
1422 save_wv = prev_wv;
1423 prev_wv = 0;
1424 i++;
1425 }
1426 else if (EQ (XVECTOR (menu_items)->contents[i], Qlambda))
1427 {
1428 prev_wv = save_wv;
1429 save_wv = submenu_stack[--submenu_depth];
1430 i++;
1431 }
1432 else if (EQ (XVECTOR (menu_items)->contents[i], Qt)
1433 && submenu_depth != 0)
1434 i += MENU_ITEMS_PANE_LENGTH;
1435 /* Ignore a nil in the item list.
1436 It's meaningful only for dialog boxes. */
1437 else if (EQ (XVECTOR (menu_items)->contents[i], Qquote))
1438 i += 1;
1439 else if (EQ (XVECTOR (menu_items)->contents[i], Qt))
1440 {
1441 /* Create a new pane. */
1442 Lisp_Object pane_name, prefix;
1443 char *pane_string;
4c329aa8 1444
4dedbfe0
PR
1445 pane_name = XVECTOR (menu_items)->contents[i + MENU_ITEMS_PANE_NAME];
1446 prefix = XVECTOR (menu_items)->contents[i + MENU_ITEMS_PANE_PREFIX];
4c329aa8 1447
703dc2a8
KH
1448#ifndef HAVE_MULTILINGUAL_MENU
1449 if (STRINGP (pane_name) && STRING_MULTIBYTE (pane_name))
4c329aa8 1450 {
cc45fb40 1451 pane_name = ENCODE_SYSTEM (pane_name);
4c329aa8
GM
1452 AREF (menu_items, i + MENU_ITEMS_PANE_NAME) = pane_name;
1453 }
703dc2a8 1454#endif
4dedbfe0
PR
1455 pane_string = (NILP (pane_name)
1456 ? "" : (char *) XSTRING (pane_name)->data);
1457 /* If there is just one top-level pane, put all its items directly
1458 under the top-level menu. */
1459 if (menu_items_n_panes == 1)
1460 pane_string = "";
1461
1462 /* If the pane has a meaningful name,
1463 make the pane a top-level menu item
1464 with its items as a submenu beneath it. */
1465 if (strcmp (pane_string, ""))
1466 {
f7fab165 1467 wv = xmalloc_widget_value ();
4dedbfe0
PR
1468 if (save_wv)
1469 save_wv->next = wv;
1470 else
1471 first_wv->contents = wv;
1472 wv->name = pane_string;
ffcb5a51
RS
1473 /* Ignore the @ that means "separate pane".
1474 This is a kludge, but this isn't worth more time. */
1475 if (!NILP (prefix) && wv->name[0] == '@')
4dedbfe0
PR
1476 wv->name++;
1477 wv->value = 0;
1478 wv->enabled = 1;
3427a3db 1479 wv->button_type = BUTTON_TYPE_NONE;
0b1e6b54 1480 wv->help = Qnil;
4dedbfe0
PR
1481 }
1482 save_wv = wv;
1483 prev_wv = 0;
1484 i += MENU_ITEMS_PANE_LENGTH;
1485 }
1486 else
1487 {
1488 /* Create a new item within current pane. */
3427a3db 1489 Lisp_Object item_name, enable, descrip, def, type, selected;
850df50b
GM
1490 Lisp_Object help;
1491
4c329aa8
GM
1492 item_name = AREF (menu_items, i + MENU_ITEMS_ITEM_NAME);
1493 enable = AREF (menu_items, i + MENU_ITEMS_ITEM_ENABLE);
1494 descrip = AREF (menu_items, i + MENU_ITEMS_ITEM_EQUIV_KEY);
1495 def = AREF (menu_items, i + MENU_ITEMS_ITEM_DEFINITION);
1496 type = AREF (menu_items, i + MENU_ITEMS_ITEM_TYPE);
1497 selected = AREF (menu_items, i + MENU_ITEMS_ITEM_SELECTED);
1498 help = AREF (menu_items, i + MENU_ITEMS_ITEM_HELP);
3427a3db 1499
703dc2a8 1500#ifndef HAVE_MULTILINGUAL_MENU
3427a3db 1501 if (STRING_MULTIBYTE (item_name))
4c329aa8 1502 {
cc45fb40 1503 item_name = ENCODE_SYSTEM (item_name);
4c329aa8
GM
1504 AREF (menu_items, i + MENU_ITEMS_ITEM_NAME) = item_name;
1505 }
1506
3427a3db 1507 if (STRINGP (descrip) && STRING_MULTIBYTE (descrip))
4c329aa8 1508 {
cc45fb40 1509 descrip = ENCODE_SYSTEM (descrip);
4c329aa8
GM
1510 AREF (menu_items, i + MENU_ITEMS_ITEM_EQUIV_KEY) = descrip;
1511 }
1512#endif /* not HAVE_MULTILINGUAL_MENU */
3427a3db 1513
f7fab165 1514 wv = xmalloc_widget_value ();
4dedbfe0
PR
1515 if (prev_wv)
1516 prev_wv->next = wv;
71dca3e3 1517 else
4dedbfe0 1518 save_wv->contents = wv;
71dca3e3 1519
4dedbfe0
PR
1520 wv->name = (char *) XSTRING (item_name)->data;
1521 if (!NILP (descrip))
1522 wv->key = (char *) XSTRING (descrip)->data;
1523 wv->value = 0;
01d5e892
RS
1524 /* The EMACS_INT cast avoids a warning. There's no problem
1525 as long as pointers have enough bits to hold small integers. */
1526 wv->call_data = (!NILP (def) ? (void *) (EMACS_INT) i : 0);
4dedbfe0 1527 wv->enabled = !NILP (enable);
3427a3db
GM
1528
1529 if (NILP (type))
1530 wv->button_type = BUTTON_TYPE_NONE;
1531 else if (EQ (type, QCradio))
1532 wv->button_type = BUTTON_TYPE_RADIO;
1533 else if (EQ (type, QCtoggle))
1534 wv->button_type = BUTTON_TYPE_TOGGLE;
1535 else
1536 abort ();
1537
1538 wv->selected = !NILP (selected);
0b1f4572
RS
1539 if (! STRINGP (help))
1540 help = Qnil;
1541
1542 wv->help = help;
cc45fb40 1543
4dedbfe0
PR
1544 prev_wv = wv;
1545
1546 i += MENU_ITEMS_ITEM_LENGTH;
1547 }
1548 }
1549
71dca3e3
RS
1550 /* If we have just one "menu item"
1551 that was originally a button, return it by itself. */
1552 if (top_level_items && first_wv->contents && first_wv->contents->next == 0)
1553 {
1554 wv = first_wv->contents;
1555 free_widget_value (first_wv);
1556 return wv;
1557 }
1558
4dedbfe0
PR
1559 return first_wv;
1560}
cffa74ea 1561
4dedbfe0 1562
f61a541b
GM
1563\f
1564/* Recompute all the widgets of frame F, when the menu bar has been
1565 changed. Value is non-zero if widgets were updated. */
1566
1567static int
6af6cbb5 1568update_frame_menubar (f)
18686d47
RS
1569 FRAME_PTR f;
1570{
7556890b 1571 struct x_output *x = f->output_data.x;
cffa74ea 1572 int columns, rows;
18686d47 1573
f61a541b
GM
1574 if (!x->menubar_widget || XtIsManaged (x->menubar_widget))
1575 return 0;
18686d47
RS
1576
1577 BLOCK_INPUT;
f61a541b
GM
1578 /* Save the size of the frame because the pane widget doesn't accept
1579 to resize itself. So force it. */
cffa74ea
FP
1580 columns = f->width;
1581 rows = f->height;
1582
f61a541b
GM
1583 /* Do the voodoo which means "I'm changing lots of things, don't try
1584 to refigure sizes until I'm done." */
4dedbfe0 1585 lw_refigure_widget (x->column_widget, False);
cffa74ea 1586
f61a541b
GM
1587 /* The order in which children are managed is the top to bottom
1588 order in which they are displayed in the paned window. First,
1589 remove the text-area widget. */
18686d47
RS
1590 XtUnmanageChild (x->edit_widget);
1591
f61a541b
GM
1592 /* Remove the menubar that is there now, and put up the menubar that
1593 should be there. */
1594 XtManageChild (x->menubar_widget);
1595 XtMapWidget (x->menubar_widget);
1596 XtVaSetValues (x->menubar_widget, XtNmappedWhenManaged, 1, NULL);
18686d47 1597
c98fcf4b 1598 /* Re-manage the text-area widget, and then thrash the sizes. */
18686d47 1599 XtManageChild (x->edit_widget);
4dedbfe0 1600 lw_refigure_widget (x->column_widget, True);
cffa74ea
FP
1601
1602 /* Force the pane widget to resize itself with the right values. */
1603 EmacsFrameSetCharSize (x->edit_widget, columns, rows);
18686d47 1604 UNBLOCK_INPUT;
f61a541b 1605 return 1;
18686d47
RS
1606}
1607
4bcdbab1
KH
1608/* Set the contents of the menubar widgets of frame F.
1609 The argument FIRST_TIME is currently ignored;
1610 it is set the first time this is called, from initialize_frame_menubar. */
1611
18686d47 1612void
88766961 1613set_frame_menubar (f, first_time, deep_p)
18686d47 1614 FRAME_PTR f;
706aa2f2 1615 int first_time;
88766961 1616 int deep_p;
18686d47 1617{
7556890b 1618 Widget menubar_widget = f->output_data.x->menubar_widget;
faa935b6 1619 Lisp_Object items;
4d19cb8e 1620 widget_value *wv, *first_wv, *prev_wv = 0;
5b3557df 1621 int i;
cc45fb40 1622
88766961 1623 LWLIB_ID id;
18686d47 1624
bfc524bc
RS
1625 XSETFRAME (Vmenu_updating_frame, f);
1626
7556890b
RS
1627 if (f->output_data.x->id == 0)
1628 f->output_data.x->id = next_menubar_widget_id++;
1629 id = f->output_data.x->id;
37a98547 1630
88766961
RS
1631 if (! menubar_widget)
1632 deep_p = 1;
745c34fb 1633 else if (pending_menu_activation && !deep_p)
a9be6839
RS
1634 deep_p = 1;
1635 /* Make the first call for any given frame always go deep. */
1636 else if (!f->output_data.x->saved_menu_event && !deep_p)
745c34fb
RS
1637 {
1638 deep_p = 1;
a9be6839
RS
1639 f->output_data.x->saved_menu_event = (XEvent*)xmalloc (sizeof (XEvent));
1640 f->output_data.x->saved_menu_event->type = 0;
745c34fb 1641 }
18686d47 1642
f7fab165 1643 wv = xmalloc_widget_value ();
18686d47
RS
1644 wv->name = "menubar";
1645 wv->value = 0;
1646 wv->enabled = 1;
3427a3db 1647 wv->button_type = BUTTON_TYPE_NONE;
27ad7b52 1648 wv->help = Qnil;
4d19cb8e 1649 first_wv = wv;
8d8a3494 1650
88766961 1651 if (deep_p)
18686d47 1652 {
88766961
RS
1653 /* Make a widget-value tree representing the entire menu trees. */
1654
1655 struct buffer *prev = current_buffer;
1656 Lisp_Object buffer;
1657 int specpdl_count = specpdl_ptr - specpdl;
1658 int previous_menu_items_used = f->menu_bar_items_used;
1659 Lisp_Object *previous_items
1660 = (Lisp_Object *) alloca (previous_menu_items_used
1661 * sizeof (Lisp_Object));
1662
0b1cf399
RS
1663 /* If we are making a new widget, its contents are empty,
1664 do always reinitialize them. */
1665 if (! menubar_widget)
1666 previous_menu_items_used = 0;
1667
88766961
RS
1668 buffer = XWINDOW (FRAME_SELECTED_WINDOW (f))->buffer;
1669 specbind (Qinhibit_quit, Qt);
1670 /* Don't let the debugger step into this code
1671 because it is not reentrant. */
1672 specbind (Qdebug_on_next_call, Qnil);
1673
58226364 1674 record_unwind_protect (Fset_match_data, Fmatch_data (Qnil, Qnil));
88766961
RS
1675 if (NILP (Voverriding_local_map_menu_flag))
1676 {
1677 specbind (Qoverriding_terminal_local_map, Qnil);
1678 specbind (Qoverriding_local_map, Qnil);
1679 }
18686d47 1680
88766961 1681 set_buffer_internal_1 (XBUFFER (buffer));
18686d47 1682
88766961 1683 /* Run the Lucid hook. */
950eaee7
GM
1684 safe_run_hooks (Qactivate_menubar_hook);
1685
88766961
RS
1686 /* If it has changed current-menubar from previous value,
1687 really recompute the menubar from the value. */
1688 if (! NILP (Vlucid_menu_bar_dirty_flag))
1689 call0 (Qrecompute_lucid_menubar);
a57634d4 1690 safe_run_hooks (Qmenu_bar_update_hook);
88766961 1691 FRAME_MENU_BAR_ITEMS (f) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f));
18686d47 1692
88766961 1693 items = FRAME_MENU_BAR_ITEMS (f);
8d8a3494 1694
88766961 1695 inhibit_garbage_collection ();
8d8a3494 1696
88766961 1697 /* Save the frame's previous menu bar contents data. */
86c04183
GM
1698 if (previous_menu_items_used)
1699 bcopy (XVECTOR (f->menu_bar_vector)->contents, previous_items,
1700 previous_menu_items_used * sizeof (Lisp_Object));
8d8a3494 1701
88766961
RS
1702 /* Fill in the current menu bar contents. */
1703 menu_items = f->menu_bar_vector;
86c04183 1704 menu_items_allocated = VECTORP (menu_items) ? ASIZE (menu_items) : 0;
88766961 1705 init_menu_items ();
f04366cb 1706 for (i = 0; i < XVECTOR (items)->size; i += 4)
88766961
RS
1707 {
1708 Lisp_Object key, string, maps;
1709
1710 key = XVECTOR (items)->contents[i];
1711 string = XVECTOR (items)->contents[i + 1];
1712 maps = XVECTOR (items)->contents[i + 2];
1713 if (NILP (string))
1714 break;
1715
1716 wv = single_submenu (key, string, maps);
1717 if (prev_wv)
1718 prev_wv->next = wv;
1719 else
1720 first_wv->contents = wv;
1721 /* Don't set wv->name here; GC during the loop might relocate it. */
1722 wv->enabled = 1;
3427a3db 1723 wv->button_type = BUTTON_TYPE_NONE;
88766961
RS
1724 prev_wv = wv;
1725 }
1726
1727 finish_menu_items ();
1728
1729 set_buffer_internal_1 (prev);
8d8a3494 1730 unbind_to (specpdl_count, Qnil);
8d8a3494 1731
88766961
RS
1732 /* If there has been no change in the Lisp-level contents
1733 of the menu bar, skip redisplaying it. Just exit. */
1734
1735 for (i = 0; i < previous_menu_items_used; i++)
1736 if (menu_items_used == i
99d3fac7 1737 || (!EQ (previous_items[i], XVECTOR (menu_items)->contents[i])))
88766961 1738 break;
62555c22 1739 if (i == menu_items_used && i == previous_menu_items_used && i != 0)
88766961
RS
1740 {
1741 free_menubar_widget_value_tree (first_wv);
1742 menu_items = Qnil;
1743
1744 return;
1745 }
1746
1747 /* Now GC cannot happen during the lifetime of the widget_value,
1748 so it's safe to store data from a Lisp_String. */
1749 wv = first_wv->contents;
f04366cb 1750 for (i = 0; i < XVECTOR (items)->size; i += 4)
88766961
RS
1751 {
1752 Lisp_Object string;
1753 string = XVECTOR (items)->contents[i + 1];
1754 if (NILP (string))
1755 break;
1756 wv->name = (char *) XSTRING (string)->data;
1757 wv = wv->next;
1758 }
1759
1760 f->menu_bar_vector = menu_items;
1761 f->menu_bar_items_used = menu_items_used;
1762 menu_items = Qnil;
4d19cb8e 1763 }
88766961
RS
1764 else
1765 {
1766 /* Make a widget-value tree containing
1767 just the top level menu bar strings. */
4d19cb8e 1768
88766961 1769 items = FRAME_MENU_BAR_ITEMS (f);
f04366cb 1770 for (i = 0; i < XVECTOR (items)->size; i += 4)
88766961
RS
1771 {
1772 Lisp_Object string;
1773
1774 string = XVECTOR (items)->contents[i + 1];
1775 if (NILP (string))
1776 break;
1777
f7fab165 1778 wv = xmalloc_widget_value ();
88766961
RS
1779 wv->name = (char *) XSTRING (string)->data;
1780 wv->value = 0;
1781 wv->enabled = 1;
3427a3db 1782 wv->button_type = BUTTON_TYPE_NONE;
27ad7b52 1783 wv->help = Qnil;
fe8fa62f
RS
1784 /* This prevents lwlib from assuming this
1785 menu item is really supposed to be empty. */
1786 /* The EMACS_INT cast avoids a warning.
1787 This value just has to be different from small integers. */
1788 wv->call_data = (void *) (EMACS_INT) (-1);
88766961
RS
1789
1790 if (prev_wv)
1791 prev_wv->next = wv;
1792 else
1793 first_wv->contents = wv;
1794 prev_wv = wv;
1795 }
62555c22
RS
1796
1797 /* Forget what we thought we knew about what is in the
1798 detailed contents of the menu bar menus.
1799 Changing the top level always destroys the contents. */
1800 f->menu_bar_items_used = 0;
88766961 1801 }
4dedbfe0 1802
88766961 1803 /* Create or update the menu bar widget. */
aa669def
RS
1804
1805 BLOCK_INPUT;
1806
18686d47 1807 if (menubar_widget)
4dedbfe0
PR
1808 {
1809 /* Disable resizing (done for Motif!) */
7556890b 1810 lw_allow_resizing (f->output_data.x->widget, False);
4dedbfe0
PR
1811
1812 /* The third arg is DEEP_P, which says to consider the entire
1813 menu trees we supply, rather than just the menu bar item names. */
88766961 1814 lw_modify_all_widgets (id, first_wv, deep_p);
4dedbfe0 1815
c98fcf4b 1816 /* Re-enable the edit widget to resize. */
7556890b 1817 lw_allow_resizing (f->output_data.x->widget, True);
4dedbfe0 1818 }
18686d47
RS
1819 else
1820 {
88766961 1821 menubar_widget = lw_create_widget ("menubar", "menubar", id, first_wv,
7556890b 1822 f->output_data.x->column_widget,
4dedbfe0
PR
1823 0,
1824 popup_activate_callback,
1825 menubar_selection_callback,
850df50b
GM
1826 popup_deactivate_callback,
1827 menu_highlight_callback);
7556890b 1828 f->output_data.x->menubar_widget = menubar_widget;
18686d47 1829 }
1d1c1567
KH
1830
1831 {
1832 int menubar_size
7556890b
RS
1833 = (f->output_data.x->menubar_widget
1834 ? (f->output_data.x->menubar_widget->core.height
1835 + f->output_data.x->menubar_widget->core.border_width)
1d1c1567
KH
1836 : 0);
1837
f42aa681
RS
1838#if 0 /* Experimentally, we now get the right results
1839 for -geometry -0-0 without this. 24 Aug 96, rms. */
5ee80bd3 1840#ifdef USE_LUCID
1d1c1567
KH
1841 if (FRAME_EXTERNAL_MENU_BAR (f))
1842 {
1843 Dimension ibw = 0;
7556890b 1844 XtVaGetValues (f->output_data.x->column_widget,
1d1c1567
KH
1845 XtNinternalBorderWidth, &ibw, NULL);
1846 menubar_size += ibw;
1847 }
5ee80bd3 1848#endif /* USE_LUCID */
f42aa681 1849#endif /* 0 */
1d1c1567 1850
7556890b 1851 f->output_data.x->menubar_height = menubar_size;
1d1c1567 1852 }
18686d47
RS
1853
1854 free_menubar_widget_value_tree (first_wv);
364cd450 1855 update_frame_menubar (f);
18686d47
RS
1856
1857 UNBLOCK_INPUT;
1858}
85f487d1 1859
8e6208c5 1860/* Called from Fx_create_frame to create the initial menubar of a frame
4dedbfe0
PR
1861 before it is mapped, so that the window is mapped with the menubar already
1862 there instead of us tacking it on later and thrashing the window after it
1863 is visible. */
1864
1865void
1866initialize_frame_menubar (f)
1867 FRAME_PTR f;
1868{
1869 /* This function is called before the first chance to redisplay
1870 the frame. It has to be, so the frame will have the right size. */
1871 FRAME_MENU_BAR_ITEMS (f) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f));
88766961 1872 set_frame_menubar (f, 1, 1);
4dedbfe0
PR
1873}
1874
aba25348 1875
4dedbfe0
PR
1876/* Get rid of the menu bar of frame F, and free its storage.
1877 This is used when deleting a frame, and when turning off the menu bar. */
1878
85f487d1
FP
1879void
1880free_frame_menubar (f)
1881 FRAME_PTR f;
1882{
1883 Widget menubar_widget;
85f487d1 1884
7556890b 1885 menubar_widget = f->output_data.x->menubar_widget;
a45bad2a
RS
1886
1887 f->output_data.x->menubar_height = 0;
85f487d1
FP
1888
1889 if (menubar_widget)
1890 {
aba25348
GM
1891#ifdef USE_MOTIF
1892 /* Removing the menu bar magically changes the shell widget's x
1893 and y position of (0, 0) which, when the menu bar is turned
1894 on again, leads to pull-down menuss appearing in strange
1895 positions near the upper-left corner of the display. This
1896 happens only with some window managers like twm and ctwm,
1897 but not with other like Motif's mwm or kwm, because the
1898 latter generate ConfigureNotify events when the menu bar
1899 is switched off, which fixes the shell position. */
1900 Position x0, y0, x1, y1;
1901#endif
1902
85f487d1 1903 BLOCK_INPUT;
aba25348
GM
1904
1905#ifdef USE_MOTIF
ae556422
GM
1906 if (f->output_data.x->widget)
1907 XtVaGetValues (f->output_data.x->widget, XtNx, &x0, XtNy, &y0, NULL);
aba25348
GM
1908#endif
1909
7556890b 1910 lw_destroy_all_widgets ((LWLIB_ID) f->output_data.x->id);
0c05dcd3 1911 f->output_data.x->menubar_widget = NULL;
aba25348
GM
1912
1913#ifdef USE_MOTIF
ae556422
GM
1914 if (f->output_data.x->widget)
1915 {
1916 XtVaGetValues (f->output_data.x->widget, XtNx, &x1, XtNy, &y1, NULL);
1917 if (x1 == 0 && y1 == 0)
1918 XtVaSetValues (f->output_data.x->widget, XtNx, x0, XtNy, y0, NULL);
1919 }
aba25348
GM
1920#endif
1921
85f487d1
FP
1922 UNBLOCK_INPUT;
1923 }
1924}
78589e07 1925
78589e07
RS
1926#endif /* USE_X_TOOLKIT */
1927\f
1928/* xmenu_show actually displays a menu using the panes and items in menu_items
1929 and returns the value selected from it.
1930 There are two versions of xmenu_show, one for Xt and one for Xlib.
1931 Both assume input is blocked by the caller. */
1932
1933/* F is the frame the menu is for.
1934 X and Y are the frame-relative specified position,
1935 relative to the inside upper left corner of the frame F.
c8b5aa3d 1936 FOR_CLICK is nonzero if this menu was invoked for a mouse click.
78589e07
RS
1937 KEYMAPS is 1 if this menu was specified with keymaps;
1938 in that case, we return a list containing the chosen item's value
1939 and perhaps also the pane's prefix.
1940 TITLE is the specified menu title.
1941 ERROR is a place to store an error message string in case of failure.
1942 (We return nil on failure, but the value doesn't actually matter.) */
18686d47
RS
1943
1944#ifdef USE_X_TOOLKIT
18686d47 1945
8ed87156 1946/* We need a unique id for each widget handled by the Lucid Widget
cc17e9bf
KH
1947 library.
1948
1949 For the main windows, and popup menus, we use this counter,
88766961 1950 which we increment each time after use. This starts from 1<<16.
cc17e9bf 1951
88766961
RS
1952 For menu bars, we use numbers starting at 0, counted in
1953 next_menubar_widget_id. */
8ed87156 1954LWLIB_ID widget_id_tick;
165e1749 1955
4dedbfe0 1956static Lisp_Object *volatile menu_item_selection;
4dedbfe0
PR
1957
1958static void
1959popup_selection_callback (widget, id, client_data)
1960 Widget widget;
1961 LWLIB_ID id;
1962 XtPointer client_data;
1963{
1964 menu_item_selection = (Lisp_Object *) client_data;
1965}
1966
78589e07 1967static Lisp_Object
673a6211 1968xmenu_show (f, x, y, for_click, keymaps, title, error)
18686d47 1969 FRAME_PTR f;
18686d47
RS
1970 int x;
1971 int y;
9685a93f 1972 int for_click;
78589e07
RS
1973 int keymaps;
1974 Lisp_Object title;
1975 char **error;
18686d47 1976{
78589e07 1977 int i;
cc17e9bf 1978 LWLIB_ID menu_id;
18686d47 1979 Widget menu;
ffcb5a51 1980 Arg av[2];
60f312e2 1981 int ac = 0;
78589e07 1982 widget_value *wv, *save_wv = 0, *first_wv = 0, *prev_wv = 0;
101bb4a5
RS
1983 widget_value **submenu_stack
1984 = (widget_value **) alloca (menu_items_used * sizeof (widget_value *));
1985 Lisp_Object *subprefix_stack
1986 = (Lisp_Object *) alloca (menu_items_used * sizeof (Lisp_Object));
1987 int submenu_depth = 0;
ffcb5a51 1988 XButtonPressedEvent dummy;
4e8d3549 1989
78c8278d
RS
1990 int first_pane;
1991
78589e07
RS
1992 *error = NULL;
1993
742f715d
KH
1994 if (menu_items_used <= MENU_ITEMS_PANE_LENGTH)
1995 {
1996 *error = "Empty menu";
1997 return Qnil;
1998 }
63c414df 1999
78589e07
RS
2000 /* Create a tree of widget_value objects
2001 representing the panes and their items. */
f7fab165 2002 wv = xmalloc_widget_value ();
78589e07
RS
2003 wv->name = "menu";
2004 wv->value = 0;
2005 wv->enabled = 1;
3427a3db 2006 wv->button_type = BUTTON_TYPE_NONE;
27ad7b52 2007 wv->help =Qnil;
78589e07 2008 first_wv = wv;
78c8278d 2009 first_pane = 1;
78589e07
RS
2010
2011 /* Loop over all panes and items, filling in the tree. */
2012 i = 0;
2013 while (i < menu_items_used)
2014 {
101bb4a5
RS
2015 if (EQ (XVECTOR (menu_items)->contents[i], Qnil))
2016 {
2017 submenu_stack[submenu_depth++] = save_wv;
2018 save_wv = prev_wv;
2019 prev_wv = 0;
78c8278d 2020 first_pane = 1;
101bb4a5
RS
2021 i++;
2022 }
2023 else if (EQ (XVECTOR (menu_items)->contents[i], Qlambda))
2024 {
2025 prev_wv = save_wv;
2026 save_wv = submenu_stack[--submenu_depth];
78c8278d 2027 first_pane = 0;
101bb4a5
RS
2028 i++;
2029 }
2030 else if (EQ (XVECTOR (menu_items)->contents[i], Qt)
2031 && submenu_depth != 0)
2032 i += MENU_ITEMS_PANE_LENGTH;
fcaa7665
RS
2033 /* Ignore a nil in the item list.
2034 It's meaningful only for dialog boxes. */
2035 else if (EQ (XVECTOR (menu_items)->contents[i], Qquote))
2036 i += 1;
101bb4a5 2037 else if (EQ (XVECTOR (menu_items)->contents[i], Qt))
78589e07
RS
2038 {
2039 /* Create a new pane. */
2040 Lisp_Object pane_name, prefix;
2041 char *pane_string;
4c329aa8
GM
2042
2043 pane_name = AREF (menu_items, i + MENU_ITEMS_PANE_NAME);
2044 prefix = AREF (menu_items, i + MENU_ITEMS_PANE_PREFIX);
2045
703dc2a8 2046#ifndef HAVE_MULTILINGUAL_MENU
4c329aa8
GM
2047 if (STRINGP (pane_name) && STRING_MULTIBYTE (pane_name))
2048 {
cc45fb40 2049 pane_name = ENCODE_SYSTEM (pane_name);
4c329aa8
GM
2050 AREF (menu_items, i + MENU_ITEMS_PANE_NAME) = pane_name;
2051 }
703dc2a8 2052#endif
78589e07
RS
2053 pane_string = (NILP (pane_name)
2054 ? "" : (char *) XSTRING (pane_name)->data);
101bb4a5 2055 /* If there is just one top-level pane, put all its items directly
78589e07
RS
2056 under the top-level menu. */
2057 if (menu_items_n_panes == 1)
2058 pane_string = "";
2059
2060 /* If the pane has a meaningful name,
2061 make the pane a top-level menu item
2062 with its items as a submenu beneath it. */
78c8278d 2063 if (!keymaps && strcmp (pane_string, ""))
78589e07 2064 {
f7fab165 2065 wv = xmalloc_widget_value ();
78589e07
RS
2066 if (save_wv)
2067 save_wv->next = wv;
2068 else
2069 first_wv->contents = wv;
2070 wv->name = pane_string;
2071 if (keymaps && !NILP (prefix))
2072 wv->name++;
2073 wv->value = 0;
2074 wv->enabled = 1;
3427a3db 2075 wv->button_type = BUTTON_TYPE_NONE;
27ad7b52 2076 wv->help = Qnil;
78c8278d
RS
2077 save_wv = wv;
2078 prev_wv = 0;
78589e07 2079 }
78c8278d
RS
2080 else if (first_pane)
2081 {
2082 save_wv = wv;
2083 prev_wv = 0;
2084 }
2085 first_pane = 0;
78589e07
RS
2086 i += MENU_ITEMS_PANE_LENGTH;
2087 }
2088 else
2089 {
2090 /* Create a new item within current pane. */
9cd50434 2091 Lisp_Object item_name, enable, descrip, def, type, selected, help;
4c329aa8
GM
2092 item_name = AREF (menu_items, i + MENU_ITEMS_ITEM_NAME);
2093 enable = AREF (menu_items, i + MENU_ITEMS_ITEM_ENABLE);
2094 descrip = AREF (menu_items, i + MENU_ITEMS_ITEM_EQUIV_KEY);
2095 def = AREF (menu_items, i + MENU_ITEMS_ITEM_DEFINITION);
2096 type = AREF (menu_items, i + MENU_ITEMS_ITEM_TYPE);
2097 selected = AREF (menu_items, i + MENU_ITEMS_ITEM_SELECTED);
2098 help = AREF (menu_items, i + MENU_ITEMS_ITEM_HELP);
3427a3db 2099
703dc2a8 2100#ifndef HAVE_MULTILINGUAL_MENU
3427a3db 2101 if (STRINGP (item_name) && STRING_MULTIBYTE (item_name))
4c329aa8 2102 {
cc45fb40 2103 item_name = ENCODE_SYSTEM (item_name);
4c329aa8
GM
2104 AREF (menu_items, i + MENU_ITEMS_ITEM_NAME) = item_name;
2105 }
2106
3427a3db 2107 if (STRINGP (descrip) && STRING_MULTIBYTE (descrip))
4c329aa8 2108 {
cc45fb40 2109 descrip = ENCODE_SYSTEM (descrip);
4c329aa8
GM
2110 AREF (menu_items, i + MENU_ITEMS_ITEM_EQUIV_KEY) = descrip;
2111 }
2112#endif /* not HAVE_MULTILINGUAL_MENU */
3427a3db 2113
f7fab165 2114 wv = xmalloc_widget_value ();
78589e07
RS
2115 if (prev_wv)
2116 prev_wv->next = wv;
2117 else
2118 save_wv->contents = wv;
4e8d3549 2119 wv->name = (char *) XSTRING (item_name)->data;
78589e07 2120 if (!NILP (descrip))
4e8d3549 2121 wv->key = (char *) XSTRING (descrip)->data;
78589e07 2122 wv->value = 0;
a352a815
RS
2123 /* If this item has a null value,
2124 make the call_data null so that it won't display a box
2125 when the mouse is on it. */
2126 wv->call_data
2127 = (!NILP (def) ? (void *) &XVECTOR (menu_items)->contents[i] : 0);
78589e07 2128 wv->enabled = !NILP (enable);
3427a3db
GM
2129
2130 if (NILP (type))
2131 wv->button_type = BUTTON_TYPE_NONE;
2132 else if (EQ (type, QCtoggle))
2133 wv->button_type = BUTTON_TYPE_TOGGLE;
2134 else if (EQ (type, QCradio))
2135 wv->button_type = BUTTON_TYPE_RADIO;
2136 else
2137 abort ();
2138
2139 wv->selected = !NILP (selected);
cc45fb40 2140
0b1f4572
RS
2141 if (! STRINGP (help))
2142 help = Qnil;
2143
2144 wv->help = help;
cc45fb40 2145
78589e07
RS
2146 prev_wv = wv;
2147
2148 i += MENU_ITEMS_ITEM_LENGTH;
2149 }
2150 }
2151
c98fcf4b 2152 /* Deal with the title, if it is non-nil. */
4dedbfe0
PR
2153 if (!NILP (title))
2154 {
f7fab165
RS
2155 widget_value *wv_title = xmalloc_widget_value ();
2156 widget_value *wv_sep1 = xmalloc_widget_value ();
2157 widget_value *wv_sep2 = xmalloc_widget_value ();
4dedbfe0
PR
2158
2159 wv_sep2->name = "--";
2160 wv_sep2->next = first_wv->contents;
27ad7b52 2161 wv_sep2->help = Qnil;
4dedbfe0
PR
2162
2163 wv_sep1->name = "--";
2164 wv_sep1->next = wv_sep2;
27ad7b52 2165 wv_sep1->help = Qnil;
4dedbfe0 2166
703dc2a8
KH
2167#ifndef HAVE_MULTILINGUAL_MENU
2168 if (STRING_MULTIBYTE (title))
cc45fb40 2169 title = ENCODE_SYSTEM (title);
703dc2a8 2170#endif
4c329aa8 2171
4dedbfe0 2172 wv_title->name = (char *) XSTRING (title)->data;
cc45fb40 2173 wv_title->enabled = TRUE;
3427a3db 2174 wv_title->button_type = BUTTON_TYPE_NONE;
4dedbfe0 2175 wv_title->next = wv_sep1;
27ad7b52 2176 wv_title->help = Qnil;
4dedbfe0
PR
2177 first_wv->contents = wv_title;
2178 }
2179
78589e07 2180 /* Actually create the menu. */
cc17e9bf 2181 menu_id = widget_id_tick++;
78589e07 2182 menu = lw_create_widget ("popup", first_wv->name, menu_id, first_wv,
7556890b 2183 f->output_data.x->widget, 1, 0,
4dedbfe0 2184 popup_selection_callback,
850df50b
GM
2185 popup_deactivate_callback,
2186 menu_highlight_callback);
60f312e2 2187
ffcb5a51
RS
2188 /* Adjust coordinates to relative to the outer (window manager) window. */
2189 {
2190 Window child;
2191 int win_x = 0, win_y = 0;
2192
2193 /* Find the position of the outside upper-left corner of
2194 the inner window, with respect to the outer window. */
2195 if (f->output_data.x->parent_desc != FRAME_X_DISPLAY_INFO (f)->root_window)
2196 {
2197 BLOCK_INPUT;
2198 XTranslateCoordinates (FRAME_X_DISPLAY (f),
2199
2200 /* From-window, to-window. */
2201 f->output_data.x->window_desc,
2202 f->output_data.x->parent_desc,
2203
2204 /* From-position, to-position. */
2205 0, 0, &win_x, &win_y,
2206
2207 /* Child of window. */
2208 &child);
2209 UNBLOCK_INPUT;
2210 x += win_x;
2211 y += win_y;
2212 }
2213 }
2214
2215 /* Adjust coordinates to be root-window-relative. */
2216 x += f->output_data.x->left_pos;
2217 y += f->output_data.x->top_pos;
2218
2219 dummy.type = ButtonPress;
2220 dummy.serial = 0;
2221 dummy.send_event = 0;
2222 dummy.display = FRAME_X_DISPLAY (f);
2223 dummy.time = CurrentTime;
ffcb5a51
RS
2224 dummy.root = FRAME_X_DISPLAY_INFO (f)->root_window;
2225 dummy.window = dummy.root;
2226 dummy.subwindow = dummy.root;
2227 dummy.x_root = x;
2228 dummy.y_root = y;
2229 dummy.x = x;
2230 dummy.y = y;
c8b5aa3d
RS
2231 dummy.state = (FRAME_X_DISPLAY_INFO (f)->grabbed >> 1) * Button1Mask;
2232 dummy.button = 0;
2233 for (i = 0; i < 5; i++)
2234 if (FRAME_X_DISPLAY_INFO (f)->grabbed & (1 << i))
2235 dummy.button = i;
ffcb5a51 2236
60f312e2
RS
2237 /* Don't allow any geometry request from the user. */
2238 XtSetArg (av[ac], XtNgeometry, 0); ac++;
2239 XtSetValues (menu, av, ac);
2240
78589e07
RS
2241 /* Free the widget_value objects we used to specify the contents. */
2242 free_menubar_widget_value_tree (first_wv);
2243
2244 /* No selection has been chosen yet. */
2245 menu_item_selection = 0;
2246
78589e07 2247 /* Display the menu. */
a52445bd 2248 lw_popup_menu (menu, (XEvent *) &dummy);
4dedbfe0 2249 popup_activated_flag = 1;
18686d47 2250
78589e07 2251 /* Process events that apply to the menu. */
2e2b8e22 2252 popup_get_selection ((XEvent *) 0, FRAME_X_DISPLAY_INFO (f), menu_id);
78589e07 2253
a9c90b7c
RS
2254 /* fp turned off the following statement and wrote a comment
2255 that it is unnecessary--that the menu has already disappeared.
21af8a68
KH
2256 Nowadays the menu disappears ok, all right, but
2257 we need to delete the widgets or multiple ones will pile up. */
78589e07 2258 lw_destroy_all_widgets (menu_id);
18686d47 2259
78589e07
RS
2260 /* Find the selected item, and its pane, to return
2261 the proper value. */
2262 if (menu_item_selection != 0)
2263 {
c63f6952 2264 Lisp_Object prefix, entry;
78589e07 2265
6bbd7a29 2266 prefix = entry = Qnil;
78589e07
RS
2267 i = 0;
2268 while (i < menu_items_used)
2269 {
101bb4a5
RS
2270 if (EQ (XVECTOR (menu_items)->contents[i], Qnil))
2271 {
2272 subprefix_stack[submenu_depth++] = prefix;
2273 prefix = entry;
2274 i++;
2275 }
2276 else if (EQ (XVECTOR (menu_items)->contents[i], Qlambda))
2277 {
2278 prefix = subprefix_stack[--submenu_depth];
2279 i++;
2280 }
2281 else if (EQ (XVECTOR (menu_items)->contents[i], Qt))
78589e07
RS
2282 {
2283 prefix
2284 = XVECTOR (menu_items)->contents[i + MENU_ITEMS_PANE_PREFIX];
2285 i += MENU_ITEMS_PANE_LENGTH;
2286 }
d31d42cc
RS
2287 /* Ignore a nil in the item list.
2288 It's meaningful only for dialog boxes. */
2289 else if (EQ (XVECTOR (menu_items)->contents[i], Qquote))
2290 i += 1;
78589e07
RS
2291 else
2292 {
2293 entry
2294 = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_VALUE];
2295 if (menu_item_selection == &XVECTOR (menu_items)->contents[i])
2296 {
2297 if (keymaps != 0)
2298 {
101bb4a5
RS
2299 int j;
2300
78589e07
RS
2301 entry = Fcons (entry, Qnil);
2302 if (!NILP (prefix))
2303 entry = Fcons (prefix, entry);
101bb4a5 2304 for (j = submenu_depth - 1; j >= 0; j--)
e48087b7 2305 if (!NILP (subprefix_stack[j]))
5964e450 2306 entry = Fcons (subprefix_stack[j], entry);
78589e07
RS
2307 }
2308 return entry;
2309 }
2310 i += MENU_ITEMS_ITEM_LENGTH;
2311 }
2312 }
2313 }
2314
2315 return Qnil;
18686d47 2316}
4dedbfe0
PR
2317\f
2318static void
2319dialog_selection_callback (widget, id, client_data)
2320 Widget widget;
2321 LWLIB_ID id;
2322 XtPointer client_data;
2323{
01d5e892
RS
2324 /* The EMACS_INT cast avoids a warning. There's no problem
2325 as long as pointers have enough bits to hold small integers. */
2326 if ((int) (EMACS_INT) client_data != -1)
4dedbfe0
PR
2327 menu_item_selection = (Lisp_Object *) client_data;
2328 BLOCK_INPUT;
2329 lw_destroy_all_widgets (id);
2330 UNBLOCK_INPUT;
9572375b 2331 popup_activated_flag = 0;
4dedbfe0 2332}
18686d47 2333
165e1749
FP
2334static char * button_names [] = {
2335 "button1", "button2", "button3", "button4", "button5",
2336 "button6", "button7", "button8", "button9", "button10" };
2337
2338static Lisp_Object
673a6211 2339xdialog_show (f, keymaps, title, error)
165e1749 2340 FRAME_PTR f;
165e1749
FP
2341 int keymaps;
2342 Lisp_Object title;
2343 char **error;
2344{
2345 int i, nb_buttons=0;
cc17e9bf 2346 LWLIB_ID dialog_id;
165e1749 2347 Widget menu;
80670155 2348 char dialog_name[6];
165e1749 2349
faa935b6 2350 widget_value *wv, *first_wv = 0, *prev_wv = 0;
165e1749 2351
fcaa7665
RS
2352 /* Number of elements seen so far, before boundary. */
2353 int left_count = 0;
2354 /* 1 means we've seen the boundary between left-hand elts and right-hand. */
2355 int boundary_seen = 0;
2356
165e1749
FP
2357 *error = NULL;
2358
80670155
RS
2359 if (menu_items_n_panes > 1)
2360 {
2361 *error = "Multiple panes in dialog box";
2362 return Qnil;
2363 }
2364
165e1749
FP
2365 /* Create a tree of widget_value objects
2366 representing the text label and buttons. */
2367 {
2368 Lisp_Object pane_name, prefix;
2369 char *pane_string;
2370 pane_name = XVECTOR (menu_items)->contents[MENU_ITEMS_PANE_NAME];
2371 prefix = XVECTOR (menu_items)->contents[MENU_ITEMS_PANE_PREFIX];
2372 pane_string = (NILP (pane_name)
2373 ? "" : (char *) XSTRING (pane_name)->data);
f7fab165 2374 prev_wv = xmalloc_widget_value ();
165e1749
FP
2375 prev_wv->value = pane_string;
2376 if (keymaps && !NILP (prefix))
2377 prev_wv->name++;
2378 prev_wv->enabled = 1;
2379 prev_wv->name = "message";
27ad7b52 2380 prev_wv->help = Qnil;
165e1749
FP
2381 first_wv = prev_wv;
2382
2383 /* Loop over all panes and items, filling in the tree. */
2384 i = MENU_ITEMS_PANE_LENGTH;
2385 while (i < menu_items_used)
2386 {
2387
2388 /* Create a new item within current pane. */
2389 Lisp_Object item_name, enable, descrip;
2390 item_name = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_NAME];
2391 enable = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_ENABLE];
2392 descrip
2393 = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_EQUIV_KEY];
2394
80670155
RS
2395 if (NILP (item_name))
2396 {
2397 free_menubar_widget_value_tree (first_wv);
2398 *error = "Submenu in dialog items";
2399 return Qnil;
2400 }
fcaa7665
RS
2401 if (EQ (item_name, Qquote))
2402 {
2403 /* This is the boundary between left-side elts
2404 and right-side elts. Stop incrementing right_count. */
2405 boundary_seen = 1;
2406 i++;
2407 continue;
2408 }
86e71abf 2409 if (nb_buttons >= 9)
80670155
RS
2410 {
2411 free_menubar_widget_value_tree (first_wv);
2412 *error = "Too many dialog items";
2413 return Qnil;
2414 }
2415
f7fab165 2416 wv = xmalloc_widget_value ();
165e1749 2417 prev_wv->next = wv;
80670155 2418 wv->name = (char *) button_names[nb_buttons];
165e1749 2419 if (!NILP (descrip))
4e8d3549
RS
2420 wv->key = (char *) XSTRING (descrip)->data;
2421 wv->value = (char *) XSTRING (item_name)->data;
165e1749
FP
2422 wv->call_data = (void *) &XVECTOR (menu_items)->contents[i];
2423 wv->enabled = !NILP (enable);
27ad7b52 2424 wv->help = Qnil;
165e1749
FP
2425 prev_wv = wv;
2426
fcaa7665
RS
2427 if (! boundary_seen)
2428 left_count++;
2429
165e1749
FP
2430 nb_buttons++;
2431 i += MENU_ITEMS_ITEM_LENGTH;
2432 }
2433
fcaa7665
RS
2434 /* If the boundary was not specified,
2435 by default put half on the left and half on the right. */
2436 if (! boundary_seen)
2437 left_count = nb_buttons - nb_buttons / 2;
2438
f7fab165 2439 wv = xmalloc_widget_value ();
80670155 2440 wv->name = dialog_name;
27ad7b52 2441 wv->help = Qnil;
80670155
RS
2442 /* Dialog boxes use a really stupid name encoding
2443 which specifies how many buttons to use
2444 and how many buttons are on the right.
2445 The Q means something also. */
2446 dialog_name[0] = 'Q';
2447 dialog_name[1] = '0' + nb_buttons;
2448 dialog_name[2] = 'B';
2449 dialog_name[3] = 'R';
fcaa7665
RS
2450 /* Number of buttons to put on the right. */
2451 dialog_name[4] = '0' + nb_buttons - left_count;
80670155 2452 dialog_name[5] = 0;
165e1749
FP
2453 wv->contents = first_wv;
2454 first_wv = wv;
165e1749
FP
2455 }
2456
2457 /* Actually create the dialog. */
cc17e9bf 2458 dialog_id = widget_id_tick++;
165e1749 2459 menu = lw_create_widget (first_wv->name, "dialog", dialog_id, first_wv,
7556890b 2460 f->output_data.x->widget, 1, 0,
850df50b 2461 dialog_selection_callback, 0, 0);
b5587215 2462 lw_modify_all_widgets (dialog_id, first_wv->contents, True);
165e1749
FP
2463 /* Free the widget_value objects we used to specify the contents. */
2464 free_menubar_widget_value_tree (first_wv);
2465
2466 /* No selection has been chosen yet. */
2467 menu_item_selection = 0;
2468
165e1749
FP
2469 /* Display the menu. */
2470 lw_pop_up_all_widgets (dialog_id);
aa669def 2471 popup_activated_flag = 1;
165e1749
FP
2472
2473 /* Process events that apply to the menu. */
2e2b8e22 2474 popup_get_selection ((XEvent *) 0, FRAME_X_DISPLAY_INFO (f), dialog_id);
165e1749 2475
21af8a68
KH
2476 lw_destroy_all_widgets (dialog_id);
2477
165e1749
FP
2478 /* Find the selected item, and its pane, to return
2479 the proper value. */
2480 if (menu_item_selection != 0)
2481 {
2482 Lisp_Object prefix;
2483
2484 prefix = Qnil;
2485 i = 0;
2486 while (i < menu_items_used)
2487 {
2488 Lisp_Object entry;
2489
2490 if (EQ (XVECTOR (menu_items)->contents[i], Qt))
2491 {
2492 prefix
2493 = XVECTOR (menu_items)->contents[i + MENU_ITEMS_PANE_PREFIX];
2494 i += MENU_ITEMS_PANE_LENGTH;
2495 }
85996cfb
GM
2496 else if (EQ (XVECTOR (menu_items)->contents[i], Qquote))
2497 {
2498 /* This is the boundary between left-side elts and
2499 right-side elts. */
2500 ++i;
2501 }
165e1749
FP
2502 else
2503 {
2504 entry
2505 = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_VALUE];
2506 if (menu_item_selection == &XVECTOR (menu_items)->contents[i])
2507 {
2508 if (keymaps != 0)
2509 {
2510 entry = Fcons (entry, Qnil);
2511 if (!NILP (prefix))
2512 entry = Fcons (prefix, entry);
2513 }
2514 return entry;
2515 }
2516 i += MENU_ITEMS_ITEM_LENGTH;
2517 }
2518 }
2519 }
2520
2521 return Qnil;
2522}
ba461919 2523
18686d47 2524#else /* not USE_X_TOOLKIT */
78589e07 2525
3e703b25
GM
2526/* The frame of the last activated non-toolkit menu bar.
2527 Used to generate menu help events. */
2528
2529static struct frame *menu_help_frame;
2530
2531
62145073
GM
2532/* Show help HELP_STRING, or clear help if HELP_STRING is null.
2533
2534 PANE is the pane number, and ITEM is the menu item number in
2535 the menu (currently not used).
2536
2537 This cannot be done with generating a HELP_EVENT because
2538 XMenuActivate contains a loop that doesn't let Emacs process
2539 keyboard events. */
3e703b25
GM
2540
2541static void
62145073 2542menu_help_callback (help_string, pane, item)
3e703b25 2543 char *help_string;
62145073 2544 int pane, item;
3e703b25 2545{
62145073
GM
2546 extern Lisp_Object Qmenu_item;
2547 Lisp_Object *first_item;
2548 Lisp_Object pane_name;
2549 Lisp_Object menu_object;
2550
2551 first_item = XVECTOR (menu_items)->contents;
2552 if (EQ (first_item[0], Qt))
2553 pane_name = first_item[MENU_ITEMS_PANE_NAME];
2554 else if (EQ (first_item[0], Qquote))
2555 /* This shouldn't happen, see xmenu_show. */
cc45fb40 2556 pane_name = empty_string;
62145073
GM
2557 else
2558 pane_name = first_item[MENU_ITEMS_ITEM_NAME];
2559
2560 /* (menu-item MENU-NAME PANE-NUMBER) */
2561 menu_object = Fcons (Qmenu_item,
2562 Fcons (pane_name,
2563 Fcons (make_number (pane), Qnil)));
ba461919 2564 show_help_echo (help_string ? build_string (help_string) : Qnil,
62145073 2565 Qnil, menu_object, make_number (item), 1);
3e703b25 2566}
62145073 2567
3e703b25 2568
78589e07 2569static Lisp_Object
673a6211 2570xmenu_show (f, x, y, for_click, keymaps, title, error)
78589e07
RS
2571 FRAME_PTR f;
2572 int x, y;
9685a93f
RS
2573 int for_click;
2574 int keymaps;
78589e07
RS
2575 Lisp_Object title;
2576 char **error;
dcfdbac7 2577{
78589e07
RS
2578 Window root;
2579 XMenu *menu;
2580 int pane, selidx, lpane, status;
2581 Lisp_Object entry, pane_prefix;
dcfdbac7
JB
2582 char *datap;
2583 int ulx, uly, width, height;
2584 int dispwidth, dispheight;
4e8d3549
RS
2585 int i, j;
2586 int maxwidth;
78589e07
RS
2587 int dummy_int;
2588 unsigned int dummy_uint;
088831f6 2589
07a675b7 2590 *error = 0;
78589e07
RS
2591 if (menu_items_n_panes == 0)
2592 return Qnil;
088831f6 2593
742f715d
KH
2594 if (menu_items_used <= MENU_ITEMS_PANE_LENGTH)
2595 {
2596 *error = "Empty menu";
2597 return Qnil;
2598 }
2599
78589e07 2600 /* Figure out which root window F is on. */
92280f67 2601 XGetGeometry (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), &root,
78589e07
RS
2602 &dummy_int, &dummy_int, &dummy_uint, &dummy_uint,
2603 &dummy_uint, &dummy_uint);
18686d47 2604
78589e07 2605 /* Make the menu on that window. */
92280f67 2606 menu = XMenuCreate (FRAME_X_DISPLAY (f), root, "emacs");
78589e07 2607 if (menu == NULL)
dcfdbac7
JB
2608 {
2609 *error = "Can't create menu";
78589e07 2610 return Qnil;
dcfdbac7 2611 }
78589e07 2612
87485d6f 2613#ifdef HAVE_X_WINDOWS
78589e07 2614 /* Adjust coordinates to relative to the outer (window manager) window. */
78589e07
RS
2615 {
2616 Window child;
2617 int win_x = 0, win_y = 0;
2618
2619 /* Find the position of the outside upper-left corner of
2620 the inner window, with respect to the outer window. */
7556890b 2621 if (f->output_data.x->parent_desc != FRAME_X_DISPLAY_INFO (f)->root_window)
78589e07
RS
2622 {
2623 BLOCK_INPUT;
92280f67 2624 XTranslateCoordinates (FRAME_X_DISPLAY (f),
78589e07
RS
2625
2626 /* From-window, to-window. */
7556890b
RS
2627 f->output_data.x->window_desc,
2628 f->output_data.x->parent_desc,
78589e07
RS
2629
2630 /* From-position, to-position. */
2631 0, 0, &win_x, &win_y,
2632
2633 /* Child of window. */
2634 &child);
2635 UNBLOCK_INPUT;
2636 x += win_x;
2637 y += win_y;
2638 }
2639 }
87485d6f 2640#endif /* HAVE_X_WINDOWS */
78589e07
RS
2641
2642 /* Adjust coordinates to be root-window-relative. */
7556890b
RS
2643 x += f->output_data.x->left_pos;
2644 y += f->output_data.x->top_pos;
18686d47 2645
78589e07
RS
2646 /* Create all the necessary panes and their items. */
2647 i = 0;
2648 while (i < menu_items_used)
dcfdbac7 2649 {
78589e07 2650 if (EQ (XVECTOR (menu_items)->contents[i], Qt))
dcfdbac7 2651 {
78589e07
RS
2652 /* Create a new pane. */
2653 Lisp_Object pane_name, prefix;
2654 char *pane_string;
2655
2656 pane_name = XVECTOR (menu_items)->contents[i + MENU_ITEMS_PANE_NAME];
2657 prefix = XVECTOR (menu_items)->contents[i + MENU_ITEMS_PANE_PREFIX];
2658 pane_string = (NILP (pane_name)
2659 ? "" : (char *) XSTRING (pane_name)->data);
2660 if (keymaps && !NILP (prefix))
2661 pane_string++;
2662
92280f67 2663 lpane = XMenuAddPane (FRAME_X_DISPLAY (f), menu, pane_string, TRUE);
78589e07
RS
2664 if (lpane == XM_FAILURE)
2665 {
92280f67 2666 XMenuDestroy (FRAME_X_DISPLAY (f), menu);
78589e07
RS
2667 *error = "Can't create pane";
2668 return Qnil;
2669 }
2670 i += MENU_ITEMS_PANE_LENGTH;
4e8d3549
RS
2671
2672 /* Find the width of the widest item in this pane. */
2673 maxwidth = 0;
2674 j = i;
2675 while (j < menu_items_used)
2676 {
2677 Lisp_Object item;
2678 item = XVECTOR (menu_items)->contents[j];
2679 if (EQ (item, Qt))
2680 break;
2681 if (NILP (item))
2682 {
2683 j++;
2684 continue;
2685 }
fc932ac6 2686 width = STRING_BYTES (XSTRING (item));
4e8d3549
RS
2687 if (width > maxwidth)
2688 maxwidth = width;
2689
2690 j += MENU_ITEMS_ITEM_LENGTH;
2691 }
dcfdbac7 2692 }
fcaa7665
RS
2693 /* Ignore a nil in the item list.
2694 It's meaningful only for dialog boxes. */
2695 else if (EQ (XVECTOR (menu_items)->contents[i], Qquote))
2696 i += 1;
78589e07 2697 else
dcfdbac7 2698 {
78589e07 2699 /* Create a new item within current pane. */
3e703b25 2700 Lisp_Object item_name, enable, descrip, help;
4e8d3549 2701 unsigned char *item_data;
3e703b25 2702 char *help_string;
78589e07
RS
2703
2704 item_name = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_NAME];
2705 enable = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_ENABLE];
2706 descrip
2707 = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_EQUIV_KEY];
3e703b25
GM
2708 help = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_HELP];
2709 help_string = STRINGP (help) ? XSTRING (help)->data : NULL;
2710
78589e07 2711 if (!NILP (descrip))
4e8d3549 2712 {
fc932ac6 2713 int gap = maxwidth - STRING_BYTES (XSTRING (item_name));
4e8d3549
RS
2714#ifdef C_ALLOCA
2715 Lisp_Object spacer;
2716 spacer = Fmake_string (make_number (gap), make_number (' '));
2717 item_name = concat2 (item_name, spacer);
2718 item_name = concat2 (item_name, descrip);
2719 item_data = XSTRING (item_name)->data;
2720#else
2721 /* if alloca is fast, use that to make the space,
2722 to reduce gc needs. */
2723 item_data
2724 = (unsigned char *) alloca (maxwidth
fc932ac6 2725 + STRING_BYTES (XSTRING (descrip)) + 1);
4e8d3549 2726 bcopy (XSTRING (item_name)->data, item_data,
fc932ac6 2727 STRING_BYTES (XSTRING (item_name)));
4e8d3549
RS
2728 for (j = XSTRING (item_name)->size; j < maxwidth; j++)
2729 item_data[j] = ' ';
2730 bcopy (XSTRING (descrip)->data, item_data + j,
fc932ac6
RS
2731 STRING_BYTES (XSTRING (descrip)));
2732 item_data[j + STRING_BYTES (XSTRING (descrip))] = 0;
4e8d3549
RS
2733#endif
2734 }
2735 else
2736 item_data = XSTRING (item_name)->data;
78589e07 2737
92280f67
RS
2738 if (XMenuAddSelection (FRAME_X_DISPLAY (f),
2739 menu, lpane, 0, item_data,
3e703b25 2740 !NILP (enable), help_string)
dcfdbac7
JB
2741 == XM_FAILURE)
2742 {
92280f67 2743 XMenuDestroy (FRAME_X_DISPLAY (f), menu);
dcfdbac7 2744 *error = "Can't add selection to menu";
78589e07 2745 return Qnil;
dcfdbac7 2746 }
78589e07 2747 i += MENU_ITEMS_ITEM_LENGTH;
dcfdbac7
JB
2748 }
2749 }
4e8d3549 2750
78589e07 2751 /* All set and ready to fly. */
92280f67 2752 XMenuRecompute (FRAME_X_DISPLAY (f), menu);
63685b9d
GM
2753 dispwidth = DisplayWidth (FRAME_X_DISPLAY (f), FRAME_X_SCREEN_NUMBER (f));
2754 dispheight = DisplayHeight (FRAME_X_DISPLAY (f), FRAME_X_SCREEN_NUMBER (f));
78589e07
RS
2755 x = min (x, dispwidth);
2756 y = min (y, dispheight);
2757 x = max (x, 1);
2758 y = max (y, 1);
92280f67 2759 XMenuLocate (FRAME_X_DISPLAY (f), menu, 0, 0, x, y,
dcfdbac7
JB
2760 &ulx, &uly, &width, &height);
2761 if (ulx+width > dispwidth)
2762 {
78589e07 2763 x -= (ulx + width) - dispwidth;
dcfdbac7
JB
2764 ulx = dispwidth - width;
2765 }
2766 if (uly+height > dispheight)
2767 {
78589e07 2768 y -= (uly + height) - dispheight;
dcfdbac7
JB
2769 uly = dispheight - height;
2770 }
78589e07
RS
2771 if (ulx < 0) x -= ulx;
2772 if (uly < 0) y -= uly;
121e4555
KH
2773
2774 XMenuSetAEQ (menu, TRUE);
78589e07
RS
2775 XMenuSetFreeze (menu, TRUE);
2776 pane = selidx = 0;
3e703b25
GM
2777
2778 /* Help display under X won't work because XMenuActivate contains
2779 a loop that doesn't give Emacs a chance to process it. */
2780 menu_help_frame = f;
92280f67 2781 status = XMenuActivate (FRAME_X_DISPLAY (f), menu, &pane, &selidx,
3e703b25
GM
2782 x, y, ButtonReleaseMask, &datap,
2783 menu_help_callback);
a352a815
RS
2784
2785
f1df80a8 2786#ifdef HAVE_X_WINDOWS
a352a815
RS
2787 /* Assume the mouse has moved out of the X window.
2788 If it has actually moved in, we will get an EnterNotify. */
29e460bd 2789 x_mouse_leave (FRAME_X_DISPLAY_INFO (f));
f1df80a8 2790#endif
a352a815 2791
dcfdbac7
JB
2792 switch (status)
2793 {
2794 case XM_SUCCESS:
2795#ifdef XDEBUG
2796 fprintf (stderr, "pane= %d line = %d\n", panes, selidx);
2797#endif
fa6d54d9 2798
78589e07
RS
2799 /* Find the item number SELIDX in pane number PANE. */
2800 i = 0;
2801 while (i < menu_items_used)
fa6d54d9 2802 {
78589e07 2803 if (EQ (XVECTOR (menu_items)->contents[i], Qt))
088831f6 2804 {
78589e07
RS
2805 if (pane == 0)
2806 pane_prefix
2807 = XVECTOR (menu_items)->contents[i + MENU_ITEMS_PANE_PREFIX];
2808 pane--;
2809 i += MENU_ITEMS_PANE_LENGTH;
088831f6 2810 }
78589e07 2811 else
ab6ee1a0 2812 {
78589e07 2813 if (pane == -1)
ab6ee1a0 2814 {
78589e07 2815 if (selidx == 0)
ab6ee1a0 2816 {
78589e07
RS
2817 entry
2818 = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_VALUE];
2819 if (keymaps != 0)
ab6ee1a0 2820 {
78589e07
RS
2821 entry = Fcons (entry, Qnil);
2822 if (!NILP (pane_prefix))
2823 entry = Fcons (pane_prefix, entry);
ab6ee1a0 2824 }
78589e07 2825 break;
ab6ee1a0 2826 }
78589e07 2827 selidx--;
ab6ee1a0 2828 }
78589e07 2829 i += MENU_ITEMS_ITEM_LENGTH;
ab6ee1a0
RS
2830 }
2831 }
78589e07 2832 break;
dcfdbac7 2833
78589e07 2834 case XM_FAILURE:
78589e07
RS
2835 *error = "Can't activate menu";
2836 case XM_IA_SELECT:
2837 case XM_NO_SELECT:
2838 entry = Qnil;
2839 break;
dcfdbac7 2840 }
92280f67 2841 XMenuDestroy (FRAME_X_DISPLAY (f), menu);
a5285df3 2842
87485d6f 2843#ifdef HAVE_X_WINDOWS
a5285df3
RS
2844 /* State that no mouse buttons are now held.
2845 (The oldXMenu code doesn't track this info for us.)
2846 That is not necessarily true, but the fiction leads to reasonable
2847 results, and it is a pain to ask which are actually held now. */
e9a79fb2 2848 FRAME_X_DISPLAY_INFO (f)->grabbed = 0;
87485d6f 2849#endif
a5285df3 2850
78589e07 2851 return entry;
dcfdbac7 2852}
4dedbfe0 2853
78589e07 2854#endif /* not USE_X_TOOLKIT */
1e659e4c
RS
2855
2856#endif /* HAVE_MENUS */
088831f6 2857\f
dfcf069d 2858void
78589e07 2859syms_of_xmenu ()
dcfdbac7 2860{
78589e07
RS
2861 staticpro (&menu_items);
2862 menu_items = Qnil;
dcfdbac7 2863
0314aacb
RS
2864 Qdebug_on_next_call = intern ("debug-on-next-call");
2865 staticpro (&Qdebug_on_next_call);
2866
7ee72033
MB
2867 DEFVAR_LISP ("menu-updating-frame", &Vmenu_updating_frame,
2868 doc: /* Frame for which we are updating a menu.
228299fa 2869The enable predicate for a menu command should check this variable. */);
bfc524bc
RS
2870 Vmenu_updating_frame = Qnil;
2871
8ed87156 2872#ifdef USE_X_TOOLKIT
4dedbfe0 2873 widget_id_tick = (1<<16);
88766961 2874 next_menubar_widget_id = 1;
8ed87156
RS
2875#endif
2876
78589e07 2877 defsubr (&Sx_popup_menu);
1e659e4c 2878#ifdef HAVE_MENUS
165e1749 2879 defsubr (&Sx_popup_dialog);
1e659e4c 2880#endif
dcfdbac7 2881}