(xmenu_show): Do call lw_destroy_all_widgets.
[bpt/emacs.git] / src / xmenu.c
CommitLineData
dcfdbac7 1/* X Communication module for terminals which understand the X protocol.
b5b4d636 2 Copyright (C) 1986, 1988, 1993, 1994 Free Software Foundation, Inc.
dcfdbac7
JB
3
4This file is part of GNU Emacs.
5
6GNU Emacs is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
774910eb 8the Free Software Foundation; either version 2, or (at your option)
dcfdbac7
JB
9any later version.
10
11GNU Emacs is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Emacs; see the file COPYING. If not, write to
18the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20/* X pop-up deck-of-cards menu facility for gnuemacs.
21 *
22 * Written by Jon Arnold and Roman Budzianowski
23 * Mods and rewrite by Robert Krawitz
24 *
25 */
26
18686d47
RS
27/* Modified by Fred Pierresteguy on December 93
28 to make the popup menus and menubar use the Xt. */
29
78589e07
RS
30/* Rewritten for clarity and GC protection by rms in Feb 94. */
31
dcfdbac7
JB
32/* On 4.3 this loses if it comes after xterm.h. */
33#include <signal.h>
18160b98 34#include <config.h>
565620a5
RS
35
36#include <stdio.h>
dcfdbac7 37#include "lisp.h"
18686d47 38#include "termhooks.h"
7708e9bd 39#include "frame.h"
dcfdbac7 40#include "window.h"
031b0e31 41#include "keyboard.h"
9ac0d9e0 42#include "blockinput.h"
62010a73 43#include "puresize.h"
dcfdbac7 44
eeee3112
RS
45#ifdef MSDOS
46#include "msdos.h"
47#endif
48
87485d6f 49#ifdef HAVE_X_WINDOWS
dcfdbac7
JB
50/* This may include sys/types.h, and that somehow loses
51 if this is not done before the other system files. */
52#include "xterm.h"
87485d6f 53#endif
dcfdbac7
JB
54
55/* Load sys/types.h if not already loaded.
56 In some systems loading it twice is suicidal. */
57#ifndef makedev
58#include <sys/types.h>
59#endif
60
61#include "dispextern.h"
62
87485d6f 63#ifdef HAVE_X_WINDOWS
18686d47
RS
64#ifdef USE_X_TOOLKIT
65#include <X11/Xlib.h>
66#include <X11/IntrinsicP.h>
67#include <X11/CoreP.h>
68#include <X11/StringDefs.h>
60f312e2 69#include <X11/Shell.h>
1d1c1567 70#include <X11/Xaw/Paned.h>
18686d47 71#include "../lwlib/lwlib.h"
a352a815
RS
72#else /* not USE_X_TOOLKIT */
73#include "../oldXMenu/XMenu.h"
74#endif /* not USE_X_TOOLKIT */
75#endif /* HAVE_X_WINDOWS */
18686d47 76
dcfdbac7
JB
77#define min(x,y) (((x) < (y)) ? (x) : (y))
78#define max(x,y) (((x) > (y)) ? (x) : (y))
79
dcfdbac7
JB
80#ifndef TRUE
81#define TRUE 1
82#define FALSE 0
78589e07 83#endif /* no TRUE */
dcfdbac7 84
6904bdcd 85extern Lisp_Object Qmenu_enable;
18686d47 86extern Lisp_Object Qmenu_bar;
92280f67 87extern Lisp_Object Qmouse_click, Qevent_kind;
78589e07 88
18686d47 89#ifdef USE_X_TOOLKIT
78589e07
RS
90extern void process_expose_from_menu ();
91extern XtAppContext Xt_app_con;
92
165e1749 93static Lisp_Object xdialog_show ();
4dedbfe0 94void popup_get_selection ();
18686d47
RS
95#endif
96
78589e07
RS
97static Lisp_Object xmenu_show ();
98static void keymap_panes ();
99static void single_keymap_panes ();
100static void list_of_panes ();
101static void list_of_items ();
102\f
103/* This holds a Lisp vector that holds the results of decoding
104 the keymaps or alist-of-alists that specify a menu.
dcfdbac7 105
78589e07 106 It describes the panes and items within the panes.
dcfdbac7 107
78589e07
RS
108 Each pane is described by 3 elements in the vector:
109 t, the pane name, the pane's prefix key.
a352a815 110 Then follow the pane's items, with 5 elements per item:
78589e07 111 the item string, the enable flag, the item's value,
a352a815 112 the definition, and the equivalent keyboard key's description string.
dcfdbac7 113
101bb4a5
RS
114 In some cases, multiple levels of menus may be described.
115 A single vector slot containing nil indicates the start of a submenu.
116 A single vector slot containing lambda indicates the end of a submenu.
117 The submenu follows a menu item which is the way to reach the submenu.
118
fcaa7665
RS
119 A single vector slot containing quote indicates that the
120 following items should appear on the right of a dialog box.
121
78589e07
RS
122 Using a Lisp vector to hold this information while we decode it
123 takes care of protecting all the data from GC. */
dcfdbac7 124
78589e07
RS
125#define MENU_ITEMS_PANE_NAME 1
126#define MENU_ITEMS_PANE_PREFIX 2
127#define MENU_ITEMS_PANE_LENGTH 3
088831f6 128
78589e07
RS
129#define MENU_ITEMS_ITEM_NAME 0
130#define MENU_ITEMS_ITEM_ENABLE 1
131#define MENU_ITEMS_ITEM_VALUE 2
132#define MENU_ITEMS_ITEM_EQUIV_KEY 3
a352a815
RS
133#define MENU_ITEMS_ITEM_DEFINITION 4
134#define MENU_ITEMS_ITEM_LENGTH 5
7da99777 135
78589e07 136static Lisp_Object menu_items;
18686d47 137
78589e07
RS
138/* Number of slots currently allocated in menu_items. */
139static int menu_items_allocated;
18686d47 140
78589e07
RS
141/* This is the index in menu_items of the first empty slot. */
142static int menu_items_used;
18686d47 143
101bb4a5
RS
144/* The number of panes currently recorded in menu_items,
145 excluding those within submenus. */
78589e07 146static int menu_items_n_panes;
18686d47 147
101bb4a5
RS
148/* Current depth within submenus. */
149static int menu_items_submenu_depth;
150
4dedbfe0 151/* Flag which when set indicates a dialog or menu has been posted by
c98fcf4b 152 Xt on behalf of one of the widget sets. */
4dedbfe0
PR
153static int popup_activated_flag;
154
bd3a4da2
RS
155/* This holds a Lisp vector
156 which contains frames that have menu bars.
157 Each frame that has a menu bar is found at some index in this vector
158 and the menu bar widget refers to the frame through that index. */
159static Lisp_Object frame_vector;
160\f
161/* Return the index of FRAME in frame_vector.
162 If FRAME isn't in frame_vector yet, put it in,
163 lengthening the vector if necessary. */
164
165static int
166frame_vector_add_frame (f)
167 FRAME_PTR *f;
168{
169 int length = XVECTOR (frame_vector)->size;
170 int i, empty = -1;
171 Lisp_Object new, frame;
172
173 XSETFRAME (frame, f);
174
175 for (i = 0; i < length; i++)
176 {
177 if (EQ (frame, XVECTOR (frame_vector)->contents[i]))
178 return i;
179 if (NILP (XVECTOR (frame_vector)->contents[i]))
180 empty = i;
181 }
182
183 if (empty >= 0)
184 {
185 XVECTOR (frame_vector)->contents[empty] = frame;
186 return empty;
187 }
188
189 new = Fmake_vector (make_number (length * 2), Qnil);
190 bcopy (XVECTOR (frame_vector)->contents,
191 XVECTOR (new)->contents, sizeof (Lisp_Object) * length);
192
193 XVECTOR (frame_vector)->contents[length] = frame;
194 return length;
195}
4dedbfe0 196\f
78589e07
RS
197/* Initialize the menu_items structure if we haven't already done so.
198 Also mark it as currently empty. */
199
200static void
201init_menu_items ()
202{
203 if (NILP (menu_items))
204 {
205 menu_items_allocated = 60;
206 menu_items = Fmake_vector (make_number (menu_items_allocated), Qnil);
18686d47
RS
207 }
208
78589e07
RS
209 menu_items_used = 0;
210 menu_items_n_panes = 0;
101bb4a5 211 menu_items_submenu_depth = 0;
78589e07 212}
18686d47 213
78589e07
RS
214/* Call at the end of generating the data in menu_items.
215 This fills in the number of items in the last pane. */
1658603c 216
78589e07
RS
217static void
218finish_menu_items ()
219{
220}
1658603c 221
78589e07
RS
222/* Call when finished using the data for the current menu
223 in menu_items. */
1658603c 224
78589e07
RS
225static void
226discard_menu_items ()
227{
228 /* Free the structure if it is especially large.
229 Otherwise, hold on to it, to save time. */
230 if (menu_items_allocated > 200)
231 {
232 menu_items = Qnil;
233 menu_items_allocated = 0;
234 }
235}
1658603c 236
101bb4a5
RS
237/* Make the menu_items vector twice as large. */
238
239static void
240grow_menu_items ()
241{
242 Lisp_Object old;
243 int old_size = menu_items_allocated;
244 old = menu_items;
245
246 menu_items_allocated *= 2;
247 menu_items = Fmake_vector (make_number (menu_items_allocated), Qnil);
248 bcopy (XVECTOR (old)->contents, XVECTOR (menu_items)->contents,
249 old_size * sizeof (Lisp_Object));
250}
251
252/* Begin a submenu. */
253
254static void
255push_submenu_start ()
256{
257 if (menu_items_used + 1 > menu_items_allocated)
258 grow_menu_items ();
259
260 XVECTOR (menu_items)->contents[menu_items_used++] = Qnil;
261 menu_items_submenu_depth++;
262}
263
264/* End a submenu. */
265
266static void
267push_submenu_end ()
268{
269 if (menu_items_used + 1 > menu_items_allocated)
270 grow_menu_items ();
271
272 XVECTOR (menu_items)->contents[menu_items_used++] = Qlambda;
273 menu_items_submenu_depth--;
274}
275
fcaa7665
RS
276/* Indicate boundary between left and right. */
277
278static void
279push_left_right_boundary ()
280{
281 if (menu_items_used + 1 > menu_items_allocated)
282 grow_menu_items ();
283
284 XVECTOR (menu_items)->contents[menu_items_used++] = Qquote;
285}
286
78589e07
RS
287/* Start a new menu pane in menu_items..
288 NAME is the pane name. PREFIX_VEC is a prefix key for this pane. */
1658603c 289
78589e07
RS
290static void
291push_menu_pane (name, prefix_vec)
292 Lisp_Object name, prefix_vec;
293{
294 if (menu_items_used + MENU_ITEMS_PANE_LENGTH > menu_items_allocated)
101bb4a5 295 grow_menu_items ();
dcfdbac7 296
101bb4a5
RS
297 if (menu_items_submenu_depth == 0)
298 menu_items_n_panes++;
78589e07
RS
299 XVECTOR (menu_items)->contents[menu_items_used++] = Qt;
300 XVECTOR (menu_items)->contents[menu_items_used++] = name;
301 XVECTOR (menu_items)->contents[menu_items_used++] = prefix_vec;
302}
dcfdbac7 303
78589e07
RS
304/* Push one menu item into the current pane.
305 NAME is the string to display. ENABLE if non-nil means
306 this item can be selected. KEY is the key generated by
a352a815
RS
307 choosing this item, or nil if this item doesn't really have a definition.
308 DEF is the definition of this item.
309 EQUIV is the textual description of the keyboard equivalent for
310 this item (or nil if none). */
18686d47 311
78589e07 312static void
a352a815
RS
313push_menu_item (name, enable, key, def, equiv)
314 Lisp_Object name, enable, key, def, equiv;
78589e07
RS
315{
316 if (menu_items_used + MENU_ITEMS_ITEM_LENGTH > menu_items_allocated)
101bb4a5 317 grow_menu_items ();
088831f6 318
78589e07
RS
319 XVECTOR (menu_items)->contents[menu_items_used++] = name;
320 XVECTOR (menu_items)->contents[menu_items_used++] = enable;
321 XVECTOR (menu_items)->contents[menu_items_used++] = key;
322 XVECTOR (menu_items)->contents[menu_items_used++] = equiv;
a352a815 323 XVECTOR (menu_items)->contents[menu_items_used++] = def;
78589e07
RS
324}
325\f
326/* Figure out the current keyboard equivalent of a menu item ITEM1.
327 The item string for menu display should be ITEM_STRING.
328 Store the equivalent keyboard key sequence's
329 textual description into *DESCRIP_PTR.
330 Also cache them in the item itself.
331 Return the real definition to execute. */
088831f6 332
78589e07
RS
333static Lisp_Object
334menu_item_equiv_key (item_string, item1, descrip_ptr)
335 Lisp_Object item_string;
336 Lisp_Object item1;
337 Lisp_Object *descrip_ptr;
338{
339 /* This is the real definition--the function to run. */
340 Lisp_Object def;
341 /* This is the sublist that records cached equiv key data
342 so we can save time. */
343 Lisp_Object cachelist;
344 /* These are the saved equivalent keyboard key sequence
345 and its key-description. */
346 Lisp_Object savedkey, descrip;
347 Lisp_Object def1;
348 int changed = 0;
8c512fcb 349 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
088831f6 350
78589e07
RS
351 /* If a help string follows the item string, skip it. */
352 if (CONSP (XCONS (item1)->cdr)
353 && STRINGP (XCONS (XCONS (item1)->cdr)->car))
354 item1 = XCONS (item1)->cdr;
088831f6 355
78589e07 356 def = Fcdr (item1);
088831f6 357
78589e07
RS
358 /* Get out the saved equivalent-keyboard-key info. */
359 cachelist = savedkey = descrip = Qnil;
360 if (CONSP (def) && CONSP (XCONS (def)->car)
361 && (NILP (XCONS (XCONS (def)->car)->car)
362 || VECTORP (XCONS (XCONS (def)->car)->car)))
088831f6 363 {
78589e07
RS
364 cachelist = XCONS (def)->car;
365 def = XCONS (def)->cdr;
366 savedkey = XCONS (cachelist)->car;
367 descrip = XCONS (cachelist)->cdr;
088831f6 368 }
78589e07 369
8c512fcb
RS
370 GCPRO4 (def, def1, savedkey, descrip);
371
78589e07
RS
372 /* Is it still valid? */
373 def1 = Qnil;
374 if (!NILP (savedkey))
375 def1 = Fkey_binding (savedkey, Qnil);
376 /* If not, update it. */
377 if (! EQ (def1, def)
cc1032b3
RS
378 /* If the command is an alias for another
379 (such as easymenu.el and lmenu.el set it up),
c98fcf4b 380 check if the original command matches the cached command. */
cc1032b3
RS
381 && !(SYMBOLP (def) && SYMBOLP (XSYMBOL (def)->function)
382 && EQ (def1, XSYMBOL (def)->function))
78589e07
RS
383 /* If something had no key binding before, don't recheck it--
384 doing that takes too much time and makes menus too slow. */
385 && !(!NILP (cachelist) && NILP (savedkey)))
088831f6 386 {
78589e07
RS
387 changed = 1;
388 descrip = Qnil;
10bba266
RS
389 /* If the command is an alias for another
390 (such as easymenu.el and lmenu.el set it up),
391 see if the original command name has equivalent keys. */
392 if (SYMBOLP (def) && SYMBOLP (XSYMBOL (def)->function))
393 savedkey = Fwhere_is_internal (XSYMBOL (def)->function,
394 Qnil, Qt, Qnil);
86e00a8a
RS
395 else
396 /* Otherwise look up the specified command itself.
397 We don't try both, because that makes easymenu menus slow. */
398 savedkey = Fwhere_is_internal (def, Qnil, Qt, Qnil);
399
78589e07
RS
400 if (!NILP (savedkey))
401 {
402 descrip = Fkey_description (savedkey);
403 descrip = concat2 (make_string (" (", 3), descrip);
404 descrip = concat2 (descrip, make_string (")", 1));
405 }
dcfdbac7 406 }
18686d47 407
78589e07
RS
408 /* Cache the data we just got in a sublist of the menu binding. */
409 if (NILP (cachelist))
62010a73
RS
410 {
411 CHECK_IMPURE (item1);
412 XCONS (item1)->cdr = Fcons (Fcons (savedkey, descrip), def);
413 }
78589e07 414 else if (changed)
dcfdbac7 415 {
78589e07
RS
416 XCONS (cachelist)->car = savedkey;
417 XCONS (cachelist)->cdr = descrip;
dcfdbac7 418 }
18686d47 419
8c512fcb 420 UNGCPRO;
78589e07
RS
421 *descrip_ptr = descrip;
422 return def;
18686d47
RS
423}
424
78589e07
RS
425/* This is used as the handler when calling internal_condition_case_1. */
426
427static Lisp_Object
428menu_item_enabled_p_1 (arg)
429 Lisp_Object arg;
18686d47 430{
78589e07 431 return Qnil;
dcfdbac7
JB
432}
433
78589e07 434/* Return non-nil if the command DEF is enabled when used as a menu item.
101bb4a5
RS
435 This is based on looking for a menu-enable property.
436 If NOTREAL is set, don't bother really computing this. */
78589e07
RS
437
438static Lisp_Object
101bb4a5 439menu_item_enabled_p (def, notreal)
78589e07 440 Lisp_Object def;
0f5e911d 441 int notreal;
18686d47 442{
78589e07 443 Lisp_Object enabled, tem;
18686d47 444
78589e07 445 enabled = Qt;
101bb4a5
RS
446 if (notreal)
447 return enabled;
b5bb2705 448 if (SYMBOLP (def))
78589e07
RS
449 {
450 /* No property, or nil, means enable.
451 Otherwise, enable if value is not nil. */
452 tem = Fget (def, Qmenu_enable);
453 if (!NILP (tem))
454 /* (condition-case nil (eval tem)
455 (error nil)) */
456 enabled = internal_condition_case_1 (Feval, tem, Qerror,
457 menu_item_enabled_p_1);
458 }
459 return enabled;
460}
461\f
462/* Look through KEYMAPS, a vector of keymaps that is NMAPS long,
101bb4a5
RS
463 and generate menu panes for them in menu_items.
464 If NOTREAL is nonzero,
465 don't bother really computing whether an item is enabled. */
18686d47 466
78589e07 467static void
101bb4a5 468keymap_panes (keymaps, nmaps, notreal)
78589e07
RS
469 Lisp_Object *keymaps;
470 int nmaps;
101bb4a5 471 int notreal;
18686d47 472{
78589e07 473 int mapno;
18686d47 474
78589e07 475 init_menu_items ();
18686d47 476
78589e07
RS
477 /* Loop over the given keymaps, making a pane for each map.
478 But don't make a pane that is empty--ignore that map instead.
479 P is the number of panes we have made so far. */
480 for (mapno = 0; mapno < nmaps; mapno++)
101bb4a5 481 single_keymap_panes (keymaps[mapno], Qnil, Qnil, notreal);
78589e07
RS
482
483 finish_menu_items ();
484}
485
486/* This is a recursive subroutine of keymap_panes.
487 It handles one keymap, KEYMAP.
488 The other arguments are passed along
101bb4a5
RS
489 or point to local variables of the previous function.
490 If NOTREAL is nonzero,
491 don't bother really computing whether an item is enabled. */
78589e07
RS
492
493static void
101bb4a5 494single_keymap_panes (keymap, pane_name, prefix, notreal)
78589e07
RS
495 Lisp_Object keymap;
496 Lisp_Object pane_name;
497 Lisp_Object prefix;
101bb4a5 498 int notreal;
78589e07
RS
499{
500 Lisp_Object pending_maps;
501 Lisp_Object tail, item, item1, item_string, table;
502 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
503
504 pending_maps = Qnil;
505
506 push_menu_pane (pane_name, prefix);
507
b5bb2705 508 for (tail = keymap; CONSP (tail); tail = XCONS (tail)->cdr)
18686d47 509 {
78589e07
RS
510 /* Look at each key binding, and if it has a menu string,
511 make a menu item from it. */
512 item = XCONS (tail)->car;
b5bb2705 513 if (CONSP (item))
18686d47 514 {
78589e07 515 item1 = XCONS (item)->cdr;
b5bb2705 516 if (CONSP (item1))
78589e07
RS
517 {
518 item_string = XCONS (item1)->car;
b5bb2705 519 if (STRINGP (item_string))
78589e07
RS
520 {
521 /* This is the real definition--the function to run. */
522 Lisp_Object def;
523 /* These are the saved equivalent keyboard key sequence
524 and its key-description. */
525 Lisp_Object descrip;
526 Lisp_Object tem, enabled;
527
8c512fcb
RS
528 /* GCPRO because ...enabled_p will call eval
529 and ..._equiv_key may autoload something.
78589e07
RS
530 Protecting KEYMAP preserves everything we use;
531 aside from that, must protect whatever might be
532 a string. Since there's no GCPRO5, we refetch
533 item_string instead of protecting it. */
8c512fcb 534 descrip = def = Qnil;
78589e07 535 GCPRO4 (keymap, pending_maps, def, descrip);
8c512fcb
RS
536
537 def = menu_item_equiv_key (item_string, item1, &descrip);
101bb4a5
RS
538 enabled = menu_item_enabled_p (def, notreal);
539
78589e07
RS
540 UNGCPRO;
541
542 item_string = XCONS (item1)->car;
543
544 tem = Fkeymapp (def);
545 if (XSTRING (item_string)->data[0] == '@' && !NILP (tem))
546 pending_maps = Fcons (Fcons (def, Fcons (item_string, XCONS (item)->car)),
547 pending_maps);
548 else
101bb4a5
RS
549 {
550 Lisp_Object submap;
bc28c440 551 GCPRO4 (keymap, pending_maps, descrip, item_string);
101bb4a5 552 submap = get_keymap_1 (def, 0, 1);
bc28c440 553 UNGCPRO;
101bb4a5
RS
554#ifndef USE_X_TOOLKIT
555 /* Indicate visually that this is a submenu. */
556 if (!NILP (submap))
557 item_string = concat2 (item_string,
558 build_string (" >"));
559#endif
a352a815
RS
560 /* If definition is nil, pass nil as the key. */
561 push_menu_item (item_string, enabled,
562 XCONS (item)->car, def,
101bb4a5
RS
563 descrip);
564#ifdef USE_X_TOOLKIT
565 /* Display a submenu using the toolkit. */
566 if (! NILP (submap))
567 {
568 push_submenu_start ();
569 single_keymap_panes (submap, Qnil,
570 XCONS (item)->car, notreal);
571 push_submenu_end ();
572 }
573#endif
574 }
78589e07
RS
575 }
576 }
577 }
b5bb2705 578 else if (VECTORP (item))
78589e07
RS
579 {
580 /* Loop over the char values represented in the vector. */
581 int len = XVECTOR (item)->size;
582 int c;
583 for (c = 0; c < len; c++)
584 {
585 Lisp_Object character;
33b43fa6 586 XSETFASTINT (character, c);
78589e07 587 item1 = XVECTOR (item)->contents[c];
b5bb2705 588 if (CONSP (item1))
78589e07
RS
589 {
590 item_string = XCONS (item1)->car;
b5bb2705 591 if (STRINGP (item_string))
78589e07
RS
592 {
593 Lisp_Object def;
594
595 /* These are the saved equivalent keyboard key sequence
596 and its key-description. */
597 Lisp_Object descrip;
598 Lisp_Object tem, enabled;
599
8c512fcb
RS
600 /* GCPRO because ...enabled_p will call eval
601 and ..._equiv_key may autoload something.
78589e07
RS
602 Protecting KEYMAP preserves everything we use;
603 aside from that, must protect whatever might be
604 a string. Since there's no GCPRO5, we refetch
605 item_string instead of protecting it. */
606 GCPRO4 (keymap, pending_maps, def, descrip);
8c512fcb
RS
607 descrip = def = Qnil;
608
609 def = menu_item_equiv_key (item_string, item1, &descrip);
101bb4a5 610 enabled = menu_item_enabled_p (def, notreal);
8c512fcb 611
78589e07
RS
612 UNGCPRO;
613
614 item_string = XCONS (item1)->car;
615
616 tem = Fkeymapp (def);
617 if (XSTRING (item_string)->data[0] == '@' && !NILP (tem))
618 pending_maps = Fcons (Fcons (def, Fcons (item_string, character)),
619 pending_maps);
620 else
101bb4a5
RS
621 {
622 Lisp_Object submap;
bc28c440 623 GCPRO4 (keymap, pending_maps, descrip, item_string);
101bb4a5 624 submap = get_keymap_1 (def, 0, 1);
bc28c440 625 UNGCPRO;
101bb4a5
RS
626#ifndef USE_X_TOOLKIT
627 if (!NILP (submap))
628 item_string = concat2 (item_string,
629 build_string (" >"));
630#endif
a352a815 631 /* If definition is nil, pass nil as the key. */
101bb4a5 632 push_menu_item (item_string, enabled, character,
a352a815 633 def, descrip);
101bb4a5
RS
634#ifdef USE_X_TOOLKIT
635 if (! NILP (submap))
636 {
637 push_submenu_start ();
638 single_keymap_panes (submap, Qnil,
639 character, notreal);
640 push_submenu_end ();
641 }
642#endif
643 }
78589e07
RS
644 }
645 }
646 }
18686d47
RS
647 }
648 }
78589e07
RS
649
650 /* Process now any submenus which want to be panes at this level. */
651 while (!NILP (pending_maps))
652 {
101bb4a5 653 Lisp_Object elt, eltcdr, string;
78589e07
RS
654 elt = Fcar (pending_maps);
655 eltcdr = XCONS (elt)->cdr;
101bb4a5
RS
656 string = XCONS (eltcdr)->car;
657 /* We no longer discard the @ from the beginning of the string here.
658 Instead, we do this in xmenu_show. */
659 single_keymap_panes (Fcar (elt), string,
660 XCONS (eltcdr)->cdr, notreal);
78589e07
RS
661 pending_maps = Fcdr (pending_maps);
662 }
18686d47 663}
78589e07
RS
664\f
665/* Push all the panes and items of a menu decsribed by the
666 alist-of-alists MENU.
667 This handles old-fashioned calls to x-popup-menu. */
18686d47 668
78589e07
RS
669static void
670list_of_panes (menu)
18686d47 671 Lisp_Object menu;
18686d47 672{
78589e07
RS
673 Lisp_Object tail;
674
675 init_menu_items ();
676
677 for (tail = menu; !NILP (tail); tail = Fcdr (tail))
678 {
679 Lisp_Object elt, pane_name, pane_data;
680 elt = Fcar (tail);
681 pane_name = Fcar (elt);
682 CHECK_STRING (pane_name, 0);
683 push_menu_pane (pane_name, Qnil);
684 pane_data = Fcdr (elt);
685 CHECK_CONS (pane_data, 0);
686 list_of_items (pane_data);
687 }
688
689 finish_menu_items ();
690}
691
692/* Push the items in a single pane defined by the alist PANE. */
693
694static void
695list_of_items (pane)
696 Lisp_Object pane;
697{
698 Lisp_Object tail, item, item1;
699
700 for (tail = pane; !NILP (tail); tail = Fcdr (tail))
701 {
702 item = Fcar (tail);
703 if (STRINGP (item))
a352a815 704 push_menu_item (item, Qnil, Qnil, Qt, Qnil);
fcaa7665
RS
705 else if (NILP (item))
706 push_left_right_boundary ();
78589e07
RS
707 else
708 {
709 CHECK_CONS (item, 0);
710 item1 = Fcar (item);
711 CHECK_STRING (item1, 1);
a352a815 712 push_menu_item (item1, Qt, Fcdr (item), Qt, Qnil);
78589e07
RS
713 }
714 }
715}
716\f
540e52d1 717DEFUN ("x-popup-menu", Fx_popup_menu, Sx_popup_menu, 2, 2, 0,
78589e07
RS
718 "Pop up a deck-of-cards menu and return user's selection.\n\
719POSITION is a position specification. This is either a mouse button event\n\
720or a list ((XOFFSET YOFFSET) WINDOW)\n\
748a0e1f 721where XOFFSET and YOFFSET are positions in pixels from the top left\n\
78589e07
RS
722corner of WINDOW's frame. (WINDOW may be a frame object instead of a window.)\n\
723This controls the position of the center of the first line\n\
724in the first pane of the menu, not the top left of the menu as a whole.\n\
725If POSITION is t, it means to use the current mouse position.\n\
726\n\
727MENU is a specifier for a menu. For the simplest case, MENU is a keymap.\n\
728The menu items come from key bindings that have a menu string as well as\n\
729a definition; actually, the \"definition\" in such a key binding looks like\n\
730\(STRING . REAL-DEFINITION). To give the menu a title, put a string into\n\
731the keymap as a top-level element.\n\n\
732You can also use a list of keymaps as MENU.\n\
733 Then each keymap makes a separate pane.\n\
734When MENU is a keymap or a list of keymaps, the return value\n\
735is a list of events.\n\n\
736Alternatively, you can specify a menu of multiple panes\n\
737 with a list of the form (TITLE PANE1 PANE2...),\n\
738where each pane is a list of form (TITLE ITEM1 ITEM2...).\n\
739Each ITEM is normally a cons cell (STRING . VALUE);\n\
740but a string can appear as an item--that makes a nonselectable line\n\
741in the menu.\n\
742With this form of menu, the return value is VALUE from the chosen item.\n\
743\n\
744If POSITION is nil, don't display the menu at all, just precalculate the\n\
745cached information about equivalent key sequences.")
746 (position, menu)
747 Lisp_Object position, menu;
748{
749 int number_of_panes, panes;
18686d47 750 Lisp_Object keymap, tem;
78589e07
RS
751 int xpos, ypos;
752 Lisp_Object title;
753 char *error_name;
754 Lisp_Object selection;
18686d47 755 int i, j;
78589e07
RS
756 FRAME_PTR f;
757 Lisp_Object x, y, window;
758 int keymaps = 0;
9685a93f 759 int for_click = 0;
78589e07
RS
760 struct gcpro gcpro1;
761
78589e07
RS
762 if (! NILP (position))
763 {
101bb4a5
RS
764 check_x ();
765
78589e07 766 /* Decode the first argument: find the window and the coordinates. */
9572375b
KH
767 if (EQ (position, Qt)
768 || (CONSP (position) && EQ (XCONS (position)->car, Qmenu_bar)))
78589e07
RS
769 {
770 /* Use the mouse's current position. */
ac8f8f7d 771 FRAME_PTR new_f = selected_frame;
78589e07
RS
772 Lisp_Object bar_window;
773 int part;
774 unsigned long time;
775
b137c582 776 if (mouse_position_hook)
46b657e2
RS
777 (*mouse_position_hook) (&new_f, 1, &bar_window,
778 &part, &x, &y, &time);
5ca2ef64 779 if (new_f != 0)
a39f0477 780 XSETFRAME (window, new_f);
5ca2ef64
RS
781 else
782 {
783 window = selected_window;
33b43fa6
KH
784 XSETFASTINT (x, 0);
785 XSETFASTINT (y, 0);
5ca2ef64 786 }
78589e07
RS
787 }
788 else
789 {
790 tem = Fcar (position);
b5bb2705 791 if (CONSP (tem))
78589e07
RS
792 {
793 window = Fcar (Fcdr (position));
794 x = Fcar (tem);
795 y = Fcar (Fcdr (tem));
796 }
797 else
798 {
9685a93f 799 for_click = 1;
78589e07
RS
800 tem = Fcar (Fcdr (position)); /* EVENT_START (position) */
801 window = Fcar (tem); /* POSN_WINDOW (tem) */
802 tem = Fcar (Fcdr (Fcdr (tem))); /* POSN_WINDOW_POSN (tem) */
803 x = Fcar (tem);
804 y = Fcdr (tem);
78589e07
RS
805 }
806 }
807
808 CHECK_NUMBER (x, 0);
809 CHECK_NUMBER (y, 0);
810
811 /* Decode where to put the menu. */
812
b5bb2705 813 if (FRAMEP (window))
78589e07
RS
814 {
815 f = XFRAME (window);
78589e07
RS
816 xpos = 0;
817 ypos = 0;
818 }
b5bb2705 819 else if (WINDOWP (window))
78589e07
RS
820 {
821 CHECK_LIVE_WINDOW (window, 0);
822 f = XFRAME (WINDOW_FRAME (XWINDOW (window)));
823
824 xpos = (FONT_WIDTH (f->display.x->font) * XWINDOW (window)->left);
a8097b6c 825 ypos = (f->display.x->line_height * XWINDOW (window)->top);
78589e07
RS
826 }
827 else
828 /* ??? Not really clean; should be CHECK_WINDOW_OR_FRAME,
829 but I don't want to make one now. */
830 CHECK_WINDOW (window, 0);
831
832 xpos += XINT (x);
833 ypos += XINT (y);
834 }
835
836 title = Qnil;
837 GCPRO1 (title);
838
839 /* Decode the menu items from what was specified. */
18686d47
RS
840
841 keymap = Fkeymapp (menu);
842 tem = Qnil;
b5bb2705 843 if (CONSP (menu))
18686d47
RS
844 tem = Fkeymapp (Fcar (menu));
845 if (!NILP (keymap))
846 {
847 /* We were given a keymap. Extract menu info from the keymap. */
848 Lisp_Object prompt;
849 keymap = get_keymap (menu);
850
78589e07 851 /* Extract the detailed info to make one pane. */
101bb4a5 852 keymap_panes (&menu, 1, NILP (position));
78589e07 853
18686d47
RS
854 /* Search for a string appearing directly as an element of the keymap.
855 That string is the title of the menu. */
856 prompt = map_prompt (keymap);
18686d47 857
78589e07
RS
858 /* Make that be the pane title of the first pane. */
859 if (!NILP (prompt) && menu_items_n_panes >= 0)
860 XVECTOR (menu_items)->contents[MENU_ITEMS_PANE_NAME] = prompt;
861
862 keymaps = 1;
18686d47
RS
863 }
864 else if (!NILP (tem))
865 {
866 /* We were given a list of keymaps. */
18686d47
RS
867 int nmaps = XFASTINT (Flength (menu));
868 Lisp_Object *maps
869 = (Lisp_Object *) alloca (nmaps * sizeof (Lisp_Object));
870 int i;
78589e07
RS
871
872 title = Qnil;
18686d47
RS
873
874 /* The first keymap that has a prompt string
875 supplies the menu title. */
b5bb2705 876 for (tem = menu, i = 0; CONSP (tem); tem = Fcdr (tem))
18686d47 877 {
78589e07
RS
878 Lisp_Object prompt;
879
18686d47
RS
880 maps[i++] = keymap = get_keymap (Fcar (tem));
881
882 prompt = map_prompt (keymap);
78589e07
RS
883 if (NILP (title) && !NILP (prompt))
884 title = prompt;
18686d47
RS
885 }
886
887 /* Extract the detailed info to make one pane. */
101bb4a5 888 keymap_panes (maps, nmaps, NILP (position));
78589e07
RS
889
890 /* Make the title be the pane title of the first pane. */
891 if (!NILP (title) && menu_items_n_panes >= 0)
892 XVECTOR (menu_items)->contents[MENU_ITEMS_PANE_NAME] = title;
893
894 keymaps = 1;
18686d47
RS
895 }
896 else
897 {
898 /* We were given an old-fashioned menu. */
78589e07
RS
899 title = Fcar (menu);
900 CHECK_STRING (title, 1);
18686d47 901
78589e07 902 list_of_panes (Fcdr (menu));
18686d47 903
78589e07
RS
904 keymaps = 0;
905 }
18686d47 906
78589e07 907 if (NILP (position))
18686d47 908 {
78589e07
RS
909 discard_menu_items ();
910 UNGCPRO;
911 return Qnil;
18686d47
RS
912 }
913
78589e07
RS
914 /* Display them in a menu. */
915 BLOCK_INPUT;
18686d47 916
673a6211 917 selection = xmenu_show (f, xpos, ypos, for_click,
78589e07
RS
918 keymaps, title, &error_name);
919 UNBLOCK_INPUT;
18686d47 920
78589e07 921 discard_menu_items ();
18686d47 922
78589e07 923 UNGCPRO;
18686d47 924
78589e07
RS
925 if (error_name) error (error_name);
926 return selection;
18686d47 927}
165e1749 928
540e52d1 929DEFUN ("x-popup-dialog", Fx_popup_dialog, Sx_popup_dialog, 2, 2, 0,
165e1749 930 "Pop up a dialog box and return user's selection.\n\
99fe880d
RS
931POSITION specifies which frame to use.\n\
932This is normally a mouse button event or a window or frame.\n\
933If POSITION is t, it means to use the frame the mouse is on.\n\
934The dialog box appears in the middle of the specified frame.\n\
165e1749 935\n\
99fe880d
RS
936CONTENTS specifies the alternatives to display in the dialog box.\n\
937It is a list of the form (TITLE ITEM1 ITEM2...).\n\
938Each ITEM is a cons cell (STRING . VALUE).\n\
fcaa7665
RS
939The return value is VALUE from the chosen item.\n\n\
940An ITEM may also be just a string--that makes a nonselectable item.\n\
941An ITEM may also be nil--that means to put all preceding items\n\
942on the left of the dialog box and all following items on the right.\n\
943\(By default, approximately half appear on each side.)")
99fe880d
RS
944 (position, contents)
945 Lisp_Object position, contents;
165e1749 946{
165e1749 947 FRAME_PTR f;
99fe880d 948 Lisp_Object window;
165e1749
FP
949
950 check_x ();
951
99fe880d 952 /* Decode the first argument: find the window or frame to use. */
88d4f6ec
KH
953 if (EQ (position, Qt)
954 || (CONSP (position) && EQ (XCONS (position)->car, Qmenu_bar)))
165e1749 955 {
b14db4d7 956#if 0 /* Using the frame the mouse is on may not be right. */
99fe880d 957 /* Use the mouse's current position. */
ac8f8f7d 958 FRAME_PTR new_f = selected_frame;
99fe880d
RS
959 Lisp_Object bar_window;
960 int part;
961 unsigned long time;
962 Lisp_Object x, y;
165e1749 963
46b657e2 964 (*mouse_position_hook) (&new_f, 1, &bar_window, &part, &x, &y, &time);
5ca2ef64 965
99fe880d 966 if (new_f != 0)
a39f0477 967 XSETFRAME (window, new_f);
99fe880d
RS
968 else
969 window = selected_window;
b14db4d7 970#endif
88d4f6ec 971 window = selected_window;
99fe880d
RS
972 }
973 else if (CONSP (position))
974 {
975 Lisp_Object tem;
976 tem = Fcar (position);
b5bb2705 977 if (CONSP (tem))
99fe880d 978 window = Fcar (Fcdr (position));
80670155
RS
979 else
980 {
99fe880d
RS
981 tem = Fcar (Fcdr (position)); /* EVENT_START (position) */
982 window = Fcar (tem); /* POSN_WINDOW (tem) */
165e1749 983 }
165e1749 984 }
99fe880d
RS
985 else if (WINDOWP (position) || FRAMEP (position))
986 window = position;
165e1749 987
99fe880d 988 /* Decode where to put the menu. */
165e1749 989
b5bb2705 990 if (FRAMEP (window))
99fe880d 991 f = XFRAME (window);
b5bb2705 992 else if (WINDOWP (window))
165e1749 993 {
99fe880d
RS
994 CHECK_LIVE_WINDOW (window, 0);
995 f = XFRAME (WINDOW_FRAME (XWINDOW (window)));
165e1749 996 }
99fe880d
RS
997 else
998 /* ??? Not really clean; should be CHECK_WINDOW_OR_FRAME,
999 but I don't want to make one now. */
1000 CHECK_WINDOW (window, 0);
165e1749 1001
99fe880d
RS
1002#ifndef USE_X_TOOLKIT
1003 /* Display a menu with these alternatives
1004 in the middle of frame F. */
1005 {
1006 Lisp_Object x, y, frame, newpos;
a39f0477
KH
1007 XSETFRAME (frame, f);
1008 XSETINT (x, x_pixel_width (f) / 2);
1009 XSETINT (y, x_pixel_height (f) / 2);
99fe880d
RS
1010 newpos = Fcons (Fcons (x, Fcons (y, Qnil)), Fcons (frame, Qnil));
1011
1012 return Fx_popup_menu (newpos,
1013 Fcons (Fcar (contents), Fcons (contents, Qnil)));
1014 }
1015#else
1016 {
1017 Lisp_Object title;
1018 char *error_name;
1019 Lisp_Object selection;
165e1749 1020
99fe880d
RS
1021 /* Decode the dialog items from what was specified. */
1022 title = Fcar (contents);
1023 CHECK_STRING (title, 1);
165e1749 1024
99fe880d 1025 list_of_panes (Fcons (contents, Qnil));
165e1749 1026
99fe880d
RS
1027 /* Display them in a dialog box. */
1028 BLOCK_INPUT;
f8c2630d 1029 selection = xdialog_show (f, 0, title, &error_name);
99fe880d 1030 UNBLOCK_INPUT;
165e1749 1031
99fe880d
RS
1032 discard_menu_items ();
1033
1034 if (error_name) error (error_name);
1035 return selection;
1036 }
7464b131 1037#endif
392d3f4b 1038}
78589e07
RS
1039\f
1040#ifdef USE_X_TOOLKIT
18686d47 1041
4dedbfe0 1042/* Loop in Xt until the menu pulldown or dialog popup has been
c98fcf4b
PR
1043 popped down (deactivated).
1044
2e2b8e22 1045 NOTE: All calls to popup_get_selection should be protected
c98fcf4b 1046 with BLOCK_INPUT, UNBLOCK_INPUT wrappers. */
aa669def 1047
4dedbfe0 1048void
2e2b8e22 1049popup_get_selection (initial_event, dpyinfo, id)
4dedbfe0 1050 XEvent *initial_event;
aa669def 1051 struct x_display_info *dpyinfo;
2e2b8e22 1052 LWLIB_ID id;
78589e07 1053{
4dedbfe0 1054 XEvent event;
78589e07 1055
aa669def
RS
1056 /* Define a queue to save up for later unreading
1057 all X events that don't pertain to the menu. */
1058 struct event_queue
1059 {
1060 XEvent event;
1061 struct event_queue *next;
1062 };
1063
1064 struct event_queue *queue = NULL;
1065 struct event_queue *queue_tmp;
1066
4dedbfe0
PR
1067 if (initial_event)
1068 event = *initial_event;
1069 else
1070 XtAppNextEvent (Xt_app_con, &event);
78589e07 1071
4dedbfe0 1072 while (1)
78589e07 1073 {
aa669def
RS
1074 /* Handle expose events for editor frames right away. */
1075 if (event.type == Expose)
1076 process_expose_from_menu (event);
1077 /* Make sure we don't consider buttons grabbed after menu goes. */
1078 else if (event.type == ButtonRelease
1079 && dpyinfo->display == event.xbutton.display)
1080 dpyinfo->grabbed &= ~(1 << event.xbutton.button);
2e2b8e22
KH
1081 /* If the user presses a key, deactivate the menu.
1082 The user is likely to do that if we get wedged. */
1083 else if (event.type == KeyPress
1084 && dpyinfo->display == event.xbutton.display)
1085 {
2e2b8e22
KH
1086 popup_activated_flag = 0;
1087 break;
1088 }
aa669def
RS
1089
1090 /* Queue all events not for this popup,
9572375b
KH
1091 except for Expose, which we've already handled.
1092 Note that the X window is associated with the frame if this
1093 is a menu bar popup, but not if it's a dialog box. So we use
1094 x_non_menubar_window_to_frame, not x_any_window_to_frame. */
aa669def
RS
1095 if (event.type != Expose
1096 && (event.xany.display != dpyinfo->display
9572375b 1097 || x_non_menubar_window_to_frame (dpyinfo, event.xany.window)))
aa669def 1098 {
aa669def
RS
1099 queue_tmp = (struct event_queue *) malloc (sizeof (struct event_queue));
1100
1101 if (queue_tmp != NULL)
1102 {
1103 queue_tmp->event = event;
1104 queue_tmp->next = queue;
1105 queue = queue_tmp;
1106 }
1107 }
9572375b
KH
1108 else
1109 XtDispatchEvent (&event);
aa669def
RS
1110
1111 if (!popup_activated ())
4dedbfe0
PR
1112 break;
1113 XtAppNextEvent (Xt_app_con, &event);
78589e07 1114 }
aa669def
RS
1115
1116 /* Unread any events that we got but did not handle. */
1117 while (queue != NULL)
1118 {
1119 queue_tmp = queue;
1120 XPutBackEvent (queue_tmp->event.xany.display, &queue_tmp->event);
1121 queue = queue_tmp->next;
1122 free ((char *)queue_tmp);
1123 /* Cause these events to get read as soon as we UNBLOCK_INPUT. */
1124 interrupt_input_pending = 1;
1125 }
78589e07
RS
1126}
1127
c98fcf4b 1128/* Detect if a dialog or menu has been posted. */
aa669def 1129
4dedbfe0
PR
1130int
1131popup_activated ()
1132{
1133 return popup_activated_flag;
1134}
1135
1136
1137/* This callback is invoked when the user selects a menubar cascade
1138 pushbutton, but before the pulldown menu is posted. */
78589e07
RS
1139
1140static void
4dedbfe0 1141popup_activate_callback (widget, id, client_data)
78589e07
RS
1142 Widget widget;
1143 LWLIB_ID id;
1144 XtPointer client_data;
1145{
4dedbfe0 1146 popup_activated_flag = 1;
78589e07
RS
1147}
1148
4dedbfe0
PR
1149/* This callback is called from the menu bar pulldown menu
1150 when the user makes a selection.
1151 Figure out what the user chose
1152 and put the appropriate events into the keyboard buffer. */
1153
78589e07 1154static void
4dedbfe0 1155menubar_selection_callback (widget, id, client_data)
78589e07
RS
1156 Widget widget;
1157 LWLIB_ID id;
1158 XtPointer client_data;
1159{
c63f6952 1160 Lisp_Object prefix, entry;
bd3a4da2 1161 FRAME_PTR f = XFRAME (XVECTOR (frame_vector)->contents[id]);
4dedbfe0
PR
1162 Lisp_Object vector;
1163 Lisp_Object *subprefix_stack;
1164 int submenu_depth = 0;
1165 int i;
1166
1167 if (!f)
1168 return;
1169 subprefix_stack = (Lisp_Object *) alloca (f->menu_bar_items_used * sizeof (Lisp_Object));
1170 vector = f->menu_bar_vector;
1171 prefix = Qnil;
1172 i = 0;
1173 while (i < f->menu_bar_items_used)
1174 {
4dedbfe0
PR
1175 if (EQ (XVECTOR (vector)->contents[i], Qnil))
1176 {
1177 subprefix_stack[submenu_depth++] = prefix;
1178 prefix = entry;
1179 i++;
1180 }
1181 else if (EQ (XVECTOR (vector)->contents[i], Qlambda))
1182 {
1183 prefix = subprefix_stack[--submenu_depth];
1184 i++;
1185 }
1186 else if (EQ (XVECTOR (vector)->contents[i], Qt))
1187 {
4cb35c39 1188 prefix = XVECTOR (vector)->contents[i + MENU_ITEMS_PANE_PREFIX];
4dedbfe0
PR
1189 i += MENU_ITEMS_PANE_LENGTH;
1190 }
1191 else
1192 {
4cb35c39 1193 entry = XVECTOR (vector)->contents[i + MENU_ITEMS_ITEM_VALUE];
01d5e892
RS
1194 /* The EMACS_INT cast avoids a warning. There's no problem
1195 as long as pointers have enough bits to hold small integers. */
1196 if ((int) (EMACS_INT) client_data == i)
4dedbfe0
PR
1197 {
1198 int j;
1199 struct input_event buf;
4cb35c39 1200 Lisp_Object frame;
4dedbfe0 1201
4cb35c39 1202 XSETFRAME (frame, f);
4dedbfe0 1203 buf.kind = menu_bar_event;
9572375b 1204 buf.frame_or_window = Fcons (frame, Fcons (Qmenu_bar, Qnil));
4dedbfe0
PR
1205 kbd_buffer_store_event (&buf);
1206
1207 for (j = 0; j < submenu_depth; j++)
1208 if (!NILP (subprefix_stack[j]))
1209 {
1210 buf.kind = menu_bar_event;
4cb35c39 1211 buf.frame_or_window = Fcons (frame, subprefix_stack[j]);
4dedbfe0
PR
1212 kbd_buffer_store_event (&buf);
1213 }
1214
1215 if (!NILP (prefix))
1216 {
1217 buf.kind = menu_bar_event;
4cb35c39 1218 buf.frame_or_window = Fcons (frame, prefix);
4dedbfe0
PR
1219 kbd_buffer_store_event (&buf);
1220 }
1221
1222 buf.kind = menu_bar_event;
4cb35c39 1223 buf.frame_or_window = Fcons (frame, entry);
4dedbfe0
PR
1224 kbd_buffer_store_event (&buf);
1225
1226 return;
1227 }
1228 i += MENU_ITEMS_ITEM_LENGTH;
1229 }
1230 }
18686d47
RS
1231}
1232
4dedbfe0 1233/* This callback is invoked when a dialog or menu is finished being
c98fcf4b 1234 used and has been unposted. */
4dedbfe0 1235
165e1749 1236static void
4dedbfe0 1237popup_deactivate_callback (widget, id, client_data)
165e1749
FP
1238 Widget widget;
1239 LWLIB_ID id;
1240 XtPointer client_data;
1241{
4dedbfe0 1242 popup_activated_flag = 0;
165e1749
FP
1243}
1244
4dedbfe0
PR
1245
1246/* This recursively calls free_widget_value on the tree of widgets.
18686d47 1247 It must free all data that was malloc'ed for these widget_values.
78589e07
RS
1248 In Emacs, many slots are pointers into the data of Lisp_Strings, and
1249 must be left alone. */
1250
18686d47
RS
1251void
1252free_menubar_widget_value_tree (wv)
1253 widget_value *wv;
1254{
1255 if (! wv) return;
18686d47
RS
1256
1257 wv->name = wv->value = wv->key = (char *) 0xDEADBEEF;
1258
1259 if (wv->contents && (wv->contents != (widget_value*)1))
1260 {
1261 free_menubar_widget_value_tree (wv->contents);
1262 wv->contents = (widget_value *) 0xDEADBEEF;
1263 }
1264 if (wv->next)
1265 {
1266 free_menubar_widget_value_tree (wv->next);
1267 wv->next = (widget_value *) 0xDEADBEEF;
1268 }
1269 BLOCK_INPUT;
1270 free_widget_value (wv);
1271 UNBLOCK_INPUT;
1272}
4dedbfe0
PR
1273\f
1274/* Return a tree of widget_value structures for a menu bar item
1275 whose event type is ITEM_KEY (with string ITEM_NAME)
1276 and whose contents come from the list of keymaps MAPS. */
1277
1278static widget_value *
1279single_submenu (item_key, item_name, maps)
1280 Lisp_Object item_key, item_name, maps;
1281{
1282 widget_value *wv, *prev_wv, *save_wv, *first_wv;
1283 int i;
1284 int submenu_depth = 0;
1285 Lisp_Object length;
1286 int len;
1287 Lisp_Object *mapvec;
1288 widget_value **submenu_stack;
1289 int mapno;
1290 int previous_items = menu_items_used;
1291
1292 length = Flength (maps);
1293 len = XINT (length);
1294
1295 /* Convert the list MAPS into a vector MAPVEC. */
1296 mapvec = (Lisp_Object *) alloca (len * sizeof (Lisp_Object));
1297 for (i = 0; i < len; i++)
1298 {
1299 mapvec[i] = Fcar (maps);
1300 maps = Fcdr (maps);
1301 }
1302
1303 menu_items_n_panes = 0;
1304
1305 /* Loop over the given keymaps, making a pane for each map.
1306 But don't make a pane that is empty--ignore that map instead. */
1307 for (i = 0; i < len; i++)
1308 single_keymap_panes (mapvec[i], item_name, item_key, 0);
1309
1310 /* Create a tree of widget_value objects
1311 representing the panes and their items. */
1312
1313 submenu_stack
1314 = (widget_value **) alloca (menu_items_used * sizeof (widget_value *));
1315 wv = malloc_widget_value ();
1316 wv->name = "menu";
1317 wv->value = 0;
1318 wv->enabled = 1;
1319 first_wv = wv;
1320 save_wv = 0;
1321
1322 /* Loop over all panes and items made during this call
1323 and construct a tree of widget_value objects.
1324 Ignore the panes and items made by previous calls to
1325 single_submenu, even though those are also in menu_items. */
1326 i = previous_items;
1327 while (i < menu_items_used)
1328 {
1329 if (EQ (XVECTOR (menu_items)->contents[i], Qnil))
1330 {
1331 submenu_stack[submenu_depth++] = save_wv;
1332 save_wv = prev_wv;
1333 prev_wv = 0;
1334 i++;
1335 }
1336 else if (EQ (XVECTOR (menu_items)->contents[i], Qlambda))
1337 {
1338 prev_wv = save_wv;
1339 save_wv = submenu_stack[--submenu_depth];
1340 i++;
1341 }
1342 else if (EQ (XVECTOR (menu_items)->contents[i], Qt)
1343 && submenu_depth != 0)
1344 i += MENU_ITEMS_PANE_LENGTH;
1345 /* Ignore a nil in the item list.
1346 It's meaningful only for dialog boxes. */
1347 else if (EQ (XVECTOR (menu_items)->contents[i], Qquote))
1348 i += 1;
1349 else if (EQ (XVECTOR (menu_items)->contents[i], Qt))
1350 {
1351 /* Create a new pane. */
1352 Lisp_Object pane_name, prefix;
1353 char *pane_string;
1354 pane_name = XVECTOR (menu_items)->contents[i + MENU_ITEMS_PANE_NAME];
1355 prefix = XVECTOR (menu_items)->contents[i + MENU_ITEMS_PANE_PREFIX];
1356 pane_string = (NILP (pane_name)
1357 ? "" : (char *) XSTRING (pane_name)->data);
1358 /* If there is just one top-level pane, put all its items directly
1359 under the top-level menu. */
1360 if (menu_items_n_panes == 1)
1361 pane_string = "";
1362
1363 /* If the pane has a meaningful name,
1364 make the pane a top-level menu item
1365 with its items as a submenu beneath it. */
1366 if (strcmp (pane_string, ""))
1367 {
1368 wv = malloc_widget_value ();
1369 if (save_wv)
1370 save_wv->next = wv;
1371 else
1372 first_wv->contents = wv;
1373 wv->name = pane_string;
1374 if (!NILP (prefix))
1375 wv->name++;
1376 wv->value = 0;
1377 wv->enabled = 1;
1378 }
1379 save_wv = wv;
1380 prev_wv = 0;
1381 i += MENU_ITEMS_PANE_LENGTH;
1382 }
1383 else
1384 {
1385 /* Create a new item within current pane. */
a352a815 1386 Lisp_Object item_name, enable, descrip, def;
4dedbfe0
PR
1387 item_name = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_NAME];
1388 enable = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_ENABLE];
1389 descrip
1390 = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_EQUIV_KEY];
a352a815 1391 def = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_DEFINITION];
18686d47 1392
4dedbfe0
PR
1393 wv = malloc_widget_value ();
1394 if (prev_wv)
1395 prev_wv->next = wv;
1396 else
1397 save_wv->contents = wv;
1398 wv->name = (char *) XSTRING (item_name)->data;
1399 if (!NILP (descrip))
1400 wv->key = (char *) XSTRING (descrip)->data;
1401 wv->value = 0;
01d5e892
RS
1402 /* The EMACS_INT cast avoids a warning. There's no problem
1403 as long as pointers have enough bits to hold small integers. */
1404 wv->call_data = (!NILP (def) ? (void *) (EMACS_INT) i : 0);
4dedbfe0
PR
1405 wv->enabled = !NILP (enable);
1406 prev_wv = wv;
1407
1408 i += MENU_ITEMS_ITEM_LENGTH;
1409 }
1410 }
1411
1412 return first_wv;
1413}
1414\f
cffa74ea
FP
1415extern void EmacsFrameSetCharSize ();
1416
4bcdbab1
KH
1417/* Recompute all the widgets of frame F, when the menu bar
1418 has been changed. */
4dedbfe0 1419
18686d47 1420static void
6af6cbb5 1421update_frame_menubar (f)
18686d47
RS
1422 FRAME_PTR f;
1423{
1424 struct x_display *x = f->display.x;
cffa74ea 1425 int columns, rows;
18686d47
RS
1426 int menubar_changed;
1427
4dedbfe0
PR
1428 Dimension shell_height;
1429
1430 /* We assume the menubar contents has changed if the global flag is set,
1431 or if the current buffer has changed, or if the menubar has never
1432 been updated before.
1433 */
18686d47
RS
1434 menubar_changed = (x->menubar_widget
1435 && !XtIsManaged (x->menubar_widget));
1436
1437 if (! (menubar_changed))
1438 return;
1439
1440 BLOCK_INPUT;
cffa74ea
FP
1441 /* Save the size of the frame because the pane widget doesn't accept to
1442 resize itself. So force it. */
1443 columns = f->width;
1444 rows = f->height;
1445
4dedbfe0
PR
1446 /* Do the voodoo which means "I'm changing lots of things, don't try to
1447 refigure sizes until I'm done." */
1448 lw_refigure_widget (x->column_widget, False);
cffa74ea 1449
18686d47
RS
1450 /* the order in which children are managed is the top to
1451 bottom order in which they are displayed in the paned window.
1452 First, remove the text-area widget.
1453 */
1454 XtUnmanageChild (x->edit_widget);
1455
1456 /* remove the menubar that is there now, and put up the menubar that
1457 should be there.
1458 */
1459 if (menubar_changed)
1460 {
1461 XtManageChild (x->menubar_widget);
1462 XtMapWidget (x->menubar_widget);
1463 XtVaSetValues (x->menubar_widget, XtNmappedWhenManaged, 1, 0);
1464 }
1465
c98fcf4b 1466 /* Re-manage the text-area widget, and then thrash the sizes. */
18686d47 1467 XtManageChild (x->edit_widget);
4dedbfe0 1468 lw_refigure_widget (x->column_widget, True);
cffa74ea
FP
1469
1470 /* Force the pane widget to resize itself with the right values. */
1471 EmacsFrameSetCharSize (x->edit_widget, columns, rows);
1472
18686d47
RS
1473 UNBLOCK_INPUT;
1474}
1475
4bcdbab1
KH
1476/* Set the contents of the menubar widgets of frame F.
1477 The argument FIRST_TIME is currently ignored;
1478 it is set the first time this is called, from initialize_frame_menubar. */
1479
18686d47 1480void
706aa2f2 1481set_frame_menubar (f, first_time)
18686d47 1482 FRAME_PTR f;
706aa2f2 1483 int first_time;
18686d47
RS
1484{
1485 Widget menubar_widget = f->display.x->menubar_widget;
bd3a4da2 1486 Lisp_Object tail, items, frame;
4d19cb8e 1487 widget_value *wv, *first_wv, *prev_wv = 0;
5b3557df 1488 int i;
bd3a4da2 1489 int id;
aa669def 1490 int count;
bd3a4da2 1491
aa669def 1492 count = inhibit_garbage_collection ();
18686d47 1493
aa669def 1494 id = frame_vector_add_frame (f);
18686d47
RS
1495
1496 wv = malloc_widget_value ();
1497 wv->name = "menubar";
1498 wv->value = 0;
1499 wv->enabled = 1;
4d19cb8e 1500 first_wv = wv;
4dedbfe0
PR
1501 items = FRAME_MENU_BAR_ITEMS (f);
1502 menu_items = f->menu_bar_vector;
1503 menu_items_allocated = XVECTOR (menu_items)->size;
1504 init_menu_items ();
18686d47 1505
5b3557df 1506 for (i = 0; i < XVECTOR (items)->size; i += 3)
18686d47 1507 {
4dedbfe0 1508 Lisp_Object key, string, maps;
18686d47 1509
4dedbfe0 1510 key = XVECTOR (items)->contents[i];
5b3557df 1511 string = XVECTOR (items)->contents[i + 1];
4dedbfe0 1512 maps = XVECTOR (items)->contents[i + 2];
5b3557df
RS
1513 if (NILP (string))
1514 break;
18686d47 1515
4dedbfe0 1516 wv = single_submenu (key, string, maps);
18686d47
RS
1517 if (prev_wv)
1518 prev_wv->next = wv;
4d19cb8e
KH
1519 else
1520 first_wv->contents = wv;
1521 /* Don't set wv->name here; GC during the loop might relocate it. */
18686d47
RS
1522 wv->enabled = 1;
1523 prev_wv = wv;
1524 }
1525
4d19cb8e
KH
1526 /* Now GC cannot happen during the lifetime of the widget_value,
1527 so it's safe to store data from a Lisp_String. */
1528 wv = first_wv->contents;
1529 for (i = 0; i < XVECTOR (items)->size; i += 3)
1530 {
1531 Lisp_Object string;
1532 string = XVECTOR (items)->contents[i + 1];
1533 if (NILP (string))
1534 break;
1535 wv->name = (char *) XSTRING (string)->data;
1536 wv = wv->next;
1537 }
1538
4dedbfe0
PR
1539 finish_menu_items ();
1540
1541 f->menu_bar_vector = menu_items;
1542 f->menu_bar_items_used = menu_items_used;
1543 menu_items = Qnil;
1544
aa669def
RS
1545 unbind_to (count, Qnil);
1546
1547 BLOCK_INPUT;
1548
18686d47 1549 if (menubar_widget)
4dedbfe0
PR
1550 {
1551 /* Disable resizing (done for Motif!) */
1552 lw_allow_resizing (f->display.x->widget, False);
1553
1554 /* The third arg is DEEP_P, which says to consider the entire
1555 menu trees we supply, rather than just the menu bar item names. */
cc17e9bf 1556 lw_modify_all_widgets ((LWLIB_ID) id, first_wv, 1);
4dedbfe0 1557
c98fcf4b 1558 /* Re-enable the edit widget to resize. */
4dedbfe0
PR
1559 lw_allow_resizing (f->display.x->widget, True);
1560 }
18686d47
RS
1561 else
1562 {
1563 menubar_widget = lw_create_widget ("menubar", "menubar",
cc17e9bf 1564 (LWLIB_ID) id, first_wv,
4dedbfe0
PR
1565 f->display.x->column_widget,
1566 0,
1567 popup_activate_callback,
1568 menubar_selection_callback,
1569 popup_deactivate_callback);
18686d47 1570 f->display.x->menubar_widget = menubar_widget;
18686d47 1571 }
1d1c1567
KH
1572
1573 {
1574 int menubar_size
1575 = (f->display.x->menubar_widget
1576 ? (f->display.x->menubar_widget->core.height
1577 + f->display.x->menubar_widget->core.border_width)
1578 : 0);
1579
1580 if (FRAME_EXTERNAL_MENU_BAR (f))
1581 {
1582 Dimension ibw = 0;
1583 XtVaGetValues (f->display.x->column_widget,
1584 XtNinternalBorderWidth, &ibw, NULL);
1585 menubar_size += ibw;
1586 }
1587
1588 f->display.x->menubar_height = menubar_size;
1589 }
18686d47
RS
1590
1591 free_menubar_widget_value_tree (first_wv);
1592
4bcdbab1 1593 update_frame_menubar (f);
18686d47
RS
1594
1595 UNBLOCK_INPUT;
1596}
85f487d1 1597
4dedbfe0
PR
1598/* Called from Fx_create_frame to create the inital menubar of a frame
1599 before it is mapped, so that the window is mapped with the menubar already
1600 there instead of us tacking it on later and thrashing the window after it
1601 is visible. */
1602
1603void
1604initialize_frame_menubar (f)
1605 FRAME_PTR f;
1606{
1607 /* This function is called before the first chance to redisplay
1608 the frame. It has to be, so the frame will have the right size. */
1609 FRAME_MENU_BAR_ITEMS (f) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f));
1610 set_frame_menubar (f, 1);
1611}
1612
1613/* Get rid of the menu bar of frame F, and free its storage.
1614 This is used when deleting a frame, and when turning off the menu bar. */
1615
85f487d1
FP
1616void
1617free_frame_menubar (f)
1618 FRAME_PTR f;
1619{
1620 Widget menubar_widget;
1621 int id;
1622
1623 menubar_widget = f->display.x->menubar_widget;
85f487d1
FP
1624
1625 if (menubar_widget)
1626 {
bd3a4da2 1627 id = frame_vector_add_frame (f);
85f487d1 1628 BLOCK_INPUT;
cc17e9bf 1629 lw_destroy_all_widgets ((LWLIB_ID) id);
bd3a4da2 1630 XVECTOR (frame_vector)->contents[id] = Qnil;
85f487d1
FP
1631 UNBLOCK_INPUT;
1632 }
1633}
78589e07 1634
78589e07
RS
1635#endif /* USE_X_TOOLKIT */
1636\f
1637/* xmenu_show actually displays a menu using the panes and items in menu_items
1638 and returns the value selected from it.
1639 There are two versions of xmenu_show, one for Xt and one for Xlib.
1640 Both assume input is blocked by the caller. */
1641
1642/* F is the frame the menu is for.
1643 X and Y are the frame-relative specified position,
1644 relative to the inside upper left corner of the frame F.
9685a93f 1645 FOR_CLICK if this menu was invoked for a mouse click.
78589e07
RS
1646 KEYMAPS is 1 if this menu was specified with keymaps;
1647 in that case, we return a list containing the chosen item's value
1648 and perhaps also the pane's prefix.
1649 TITLE is the specified menu title.
1650 ERROR is a place to store an error message string in case of failure.
1651 (We return nil on failure, but the value doesn't actually matter.) */
18686d47
RS
1652
1653#ifdef USE_X_TOOLKIT
18686d47 1654
8ed87156 1655/* We need a unique id for each widget handled by the Lucid Widget
cc17e9bf
KH
1656 library.
1657
1658 For the main windows, and popup menus, we use this counter,
1659 which we increment each time after use.
1660
1661 For menu bars, we use the index of the frame in frame_vector
1662 as the id. */
8ed87156 1663LWLIB_ID widget_id_tick;
165e1749 1664
4dedbfe0
PR
1665#ifdef __STDC__
1666static Lisp_Object *volatile menu_item_selection;
1667#else
1668static Lisp_Object *menu_item_selection;
1669#endif
1670
1671static void
1672popup_selection_callback (widget, id, client_data)
1673 Widget widget;
1674 LWLIB_ID id;
1675 XtPointer client_data;
1676{
1677 menu_item_selection = (Lisp_Object *) client_data;
1678}
1679
78589e07 1680static Lisp_Object
673a6211 1681xmenu_show (f, x, y, for_click, keymaps, title, error)
18686d47 1682 FRAME_PTR f;
18686d47
RS
1683 int x;
1684 int y;
9685a93f 1685 int for_click;
78589e07
RS
1686 int keymaps;
1687 Lisp_Object title;
1688 char **error;
18686d47 1689{
78589e07 1690 int i;
cc17e9bf 1691 LWLIB_ID menu_id;
18686d47 1692 Widget menu;
60f312e2
RS
1693 Arg av [2];
1694 int ac = 0;
78589e07 1695 widget_value *wv, *save_wv = 0, *first_wv = 0, *prev_wv = 0;
101bb4a5
RS
1696 widget_value **submenu_stack
1697 = (widget_value **) alloca (menu_items_used * sizeof (widget_value *));
1698 Lisp_Object *subprefix_stack
1699 = (Lisp_Object *) alloca (menu_items_used * sizeof (Lisp_Object));
1700 int submenu_depth = 0;
78589e07 1701
4e8d3549
RS
1702 Position root_x, root_y;
1703
78c8278d 1704 int first_pane;
a51b963c 1705 int next_release_must_exit = 0;
78c8278d 1706
78589e07
RS
1707 *error = NULL;
1708
742f715d
KH
1709 if (menu_items_used <= MENU_ITEMS_PANE_LENGTH)
1710 {
1711 *error = "Empty menu";
1712 return Qnil;
1713 }
63c414df 1714
78589e07
RS
1715 /* Create a tree of widget_value objects
1716 representing the panes and their items. */
1717 wv = malloc_widget_value ();
1718 wv->name = "menu";
1719 wv->value = 0;
1720 wv->enabled = 1;
1721 first_wv = wv;
78c8278d 1722 first_pane = 1;
78589e07
RS
1723
1724 /* Loop over all panes and items, filling in the tree. */
1725 i = 0;
1726 while (i < menu_items_used)
1727 {
101bb4a5
RS
1728 if (EQ (XVECTOR (menu_items)->contents[i], Qnil))
1729 {
1730 submenu_stack[submenu_depth++] = save_wv;
1731 save_wv = prev_wv;
1732 prev_wv = 0;
78c8278d 1733 first_pane = 1;
101bb4a5
RS
1734 i++;
1735 }
1736 else if (EQ (XVECTOR (menu_items)->contents[i], Qlambda))
1737 {
1738 prev_wv = save_wv;
1739 save_wv = submenu_stack[--submenu_depth];
78c8278d 1740 first_pane = 0;
101bb4a5
RS
1741 i++;
1742 }
1743 else if (EQ (XVECTOR (menu_items)->contents[i], Qt)
1744 && submenu_depth != 0)
1745 i += MENU_ITEMS_PANE_LENGTH;
fcaa7665
RS
1746 /* Ignore a nil in the item list.
1747 It's meaningful only for dialog boxes. */
1748 else if (EQ (XVECTOR (menu_items)->contents[i], Qquote))
1749 i += 1;
101bb4a5 1750 else if (EQ (XVECTOR (menu_items)->contents[i], Qt))
78589e07
RS
1751 {
1752 /* Create a new pane. */
1753 Lisp_Object pane_name, prefix;
1754 char *pane_string;
1755 pane_name = XVECTOR (menu_items)->contents[i + MENU_ITEMS_PANE_NAME];
1756 prefix = XVECTOR (menu_items)->contents[i + MENU_ITEMS_PANE_PREFIX];
1757 pane_string = (NILP (pane_name)
1758 ? "" : (char *) XSTRING (pane_name)->data);
101bb4a5 1759 /* If there is just one top-level pane, put all its items directly
78589e07
RS
1760 under the top-level menu. */
1761 if (menu_items_n_panes == 1)
1762 pane_string = "";
1763
1764 /* If the pane has a meaningful name,
1765 make the pane a top-level menu item
1766 with its items as a submenu beneath it. */
78c8278d 1767 if (!keymaps && strcmp (pane_string, ""))
78589e07
RS
1768 {
1769 wv = malloc_widget_value ();
1770 if (save_wv)
1771 save_wv->next = wv;
1772 else
1773 first_wv->contents = wv;
1774 wv->name = pane_string;
1775 if (keymaps && !NILP (prefix))
1776 wv->name++;
1777 wv->value = 0;
1778 wv->enabled = 1;
78c8278d
RS
1779 save_wv = wv;
1780 prev_wv = 0;
78589e07 1781 }
78c8278d
RS
1782 else if (first_pane)
1783 {
1784 save_wv = wv;
1785 prev_wv = 0;
1786 }
1787 first_pane = 0;
78589e07
RS
1788 i += MENU_ITEMS_PANE_LENGTH;
1789 }
1790 else
1791 {
1792 /* Create a new item within current pane. */
a352a815 1793 Lisp_Object item_name, enable, descrip, def;
78589e07
RS
1794 item_name = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_NAME];
1795 enable = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_ENABLE];
1796 descrip
1797 = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_EQUIV_KEY];
a352a815 1798 def = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_DEFINITION];
78589e07
RS
1799
1800 wv = malloc_widget_value ();
1801 if (prev_wv)
1802 prev_wv->next = wv;
1803 else
1804 save_wv->contents = wv;
4e8d3549 1805 wv->name = (char *) XSTRING (item_name)->data;
78589e07 1806 if (!NILP (descrip))
4e8d3549 1807 wv->key = (char *) XSTRING (descrip)->data;
78589e07 1808 wv->value = 0;
a352a815
RS
1809 /* If this item has a null value,
1810 make the call_data null so that it won't display a box
1811 when the mouse is on it. */
1812 wv->call_data
1813 = (!NILP (def) ? (void *) &XVECTOR (menu_items)->contents[i] : 0);
78589e07
RS
1814 wv->enabled = !NILP (enable);
1815 prev_wv = wv;
1816
1817 i += MENU_ITEMS_ITEM_LENGTH;
1818 }
1819 }
1820
c98fcf4b 1821 /* Deal with the title, if it is non-nil. */
4dedbfe0
PR
1822 if (!NILP (title))
1823 {
1824 widget_value *wv_title = malloc_widget_value ();
1825 widget_value *wv_sep1 = malloc_widget_value ();
1826 widget_value *wv_sep2 = malloc_widget_value ();
1827
1828 wv_sep2->name = "--";
1829 wv_sep2->next = first_wv->contents;
1830
1831 wv_sep1->name = "--";
1832 wv_sep1->next = wv_sep2;
1833
1834 wv_title->name = (char *) XSTRING (title)->data;
1835 wv_title->enabled = True;
1836 wv_title->next = wv_sep1;
1837 first_wv->contents = wv_title;
1838 }
1839
78589e07 1840 /* Actually create the menu. */
cc17e9bf 1841 menu_id = widget_id_tick++;
78589e07 1842 menu = lw_create_widget ("popup", first_wv->name, menu_id, first_wv,
18686d47 1843 f->display.x->widget, 1, 0,
4dedbfe0
PR
1844 popup_selection_callback,
1845 popup_deactivate_callback);
60f312e2
RS
1846
1847 /* Don't allow any geometry request from the user. */
1848 XtSetArg (av[ac], XtNgeometry, 0); ac++;
1849 XtSetValues (menu, av, ac);
1850
78589e07
RS
1851 /* Free the widget_value objects we used to specify the contents. */
1852 free_menubar_widget_value_tree (first_wv);
1853
1854 /* No selection has been chosen yet. */
1855 menu_item_selection = 0;
1856
78589e07 1857 /* Display the menu. */
4dedbfe0
PR
1858 lw_popup_menu (menu);
1859 popup_activated_flag = 1;
18686d47 1860
78589e07 1861 /* Process events that apply to the menu. */
2e2b8e22 1862 popup_get_selection ((XEvent *) 0, FRAME_X_DISPLAY_INFO (f), menu_id);
78589e07 1863
a9c90b7c
RS
1864 /* fp turned off the following statement and wrote a comment
1865 that it is unnecessary--that the menu has already disappeared.
21af8a68
KH
1866 Nowadays the menu disappears ok, all right, but
1867 we need to delete the widgets or multiple ones will pile up. */
78589e07 1868 lw_destroy_all_widgets (menu_id);
18686d47 1869
78589e07
RS
1870 /* Find the selected item, and its pane, to return
1871 the proper value. */
1872 if (menu_item_selection != 0)
1873 {
c63f6952 1874 Lisp_Object prefix, entry;
78589e07
RS
1875
1876 prefix = Qnil;
1877 i = 0;
1878 while (i < menu_items_used)
1879 {
101bb4a5
RS
1880 if (EQ (XVECTOR (menu_items)->contents[i], Qnil))
1881 {
1882 subprefix_stack[submenu_depth++] = prefix;
1883 prefix = entry;
1884 i++;
1885 }
1886 else if (EQ (XVECTOR (menu_items)->contents[i], Qlambda))
1887 {
1888 prefix = subprefix_stack[--submenu_depth];
1889 i++;
1890 }
1891 else if (EQ (XVECTOR (menu_items)->contents[i], Qt))
78589e07
RS
1892 {
1893 prefix
1894 = XVECTOR (menu_items)->contents[i + MENU_ITEMS_PANE_PREFIX];
1895 i += MENU_ITEMS_PANE_LENGTH;
1896 }
1897 else
1898 {
1899 entry
1900 = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_VALUE];
1901 if (menu_item_selection == &XVECTOR (menu_items)->contents[i])
1902 {
1903 if (keymaps != 0)
1904 {
101bb4a5
RS
1905 int j;
1906
78589e07
RS
1907 entry = Fcons (entry, Qnil);
1908 if (!NILP (prefix))
1909 entry = Fcons (prefix, entry);
101bb4a5 1910 for (j = submenu_depth - 1; j >= 0; j--)
e48087b7 1911 if (!NILP (subprefix_stack[j]))
5964e450 1912 entry = Fcons (subprefix_stack[j], entry);
78589e07
RS
1913 }
1914 return entry;
1915 }
1916 i += MENU_ITEMS_ITEM_LENGTH;
1917 }
1918 }
1919 }
1920
1921 return Qnil;
18686d47 1922}
4dedbfe0
PR
1923\f
1924static void
1925dialog_selection_callback (widget, id, client_data)
1926 Widget widget;
1927 LWLIB_ID id;
1928 XtPointer client_data;
1929{
01d5e892
RS
1930 /* The EMACS_INT cast avoids a warning. There's no problem
1931 as long as pointers have enough bits to hold small integers. */
1932 if ((int) (EMACS_INT) client_data != -1)
4dedbfe0
PR
1933 menu_item_selection = (Lisp_Object *) client_data;
1934 BLOCK_INPUT;
1935 lw_destroy_all_widgets (id);
1936 UNBLOCK_INPUT;
9572375b 1937 popup_activated_flag = 0;
4dedbfe0 1938}
18686d47 1939
165e1749
FP
1940static char * button_names [] = {
1941 "button1", "button2", "button3", "button4", "button5",
1942 "button6", "button7", "button8", "button9", "button10" };
1943
1944static Lisp_Object
673a6211 1945xdialog_show (f, keymaps, title, error)
165e1749 1946 FRAME_PTR f;
165e1749
FP
1947 int keymaps;
1948 Lisp_Object title;
1949 char **error;
1950{
1951 int i, nb_buttons=0;
cc17e9bf 1952 LWLIB_ID dialog_id;
165e1749 1953 Widget menu;
80670155 1954 char dialog_name[6];
165e1749 1955
165e1749
FP
1956 widget_value *wv, *save_wv = 0, *first_wv = 0, *prev_wv = 0;
1957
fcaa7665
RS
1958 /* Number of elements seen so far, before boundary. */
1959 int left_count = 0;
1960 /* 1 means we've seen the boundary between left-hand elts and right-hand. */
1961 int boundary_seen = 0;
1962
165e1749
FP
1963 *error = NULL;
1964
80670155
RS
1965 if (menu_items_n_panes > 1)
1966 {
1967 *error = "Multiple panes in dialog box";
1968 return Qnil;
1969 }
1970
165e1749
FP
1971 /* Create a tree of widget_value objects
1972 representing the text label and buttons. */
1973 {
1974 Lisp_Object pane_name, prefix;
1975 char *pane_string;
1976 pane_name = XVECTOR (menu_items)->contents[MENU_ITEMS_PANE_NAME];
1977 prefix = XVECTOR (menu_items)->contents[MENU_ITEMS_PANE_PREFIX];
1978 pane_string = (NILP (pane_name)
1979 ? "" : (char *) XSTRING (pane_name)->data);
1980 prev_wv = malloc_widget_value ();
1981 prev_wv->value = pane_string;
1982 if (keymaps && !NILP (prefix))
1983 prev_wv->name++;
1984 prev_wv->enabled = 1;
1985 prev_wv->name = "message";
1986 first_wv = prev_wv;
1987
1988 /* Loop over all panes and items, filling in the tree. */
1989 i = MENU_ITEMS_PANE_LENGTH;
1990 while (i < menu_items_used)
1991 {
1992
1993 /* Create a new item within current pane. */
1994 Lisp_Object item_name, enable, descrip;
1995 item_name = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_NAME];
1996 enable = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_ENABLE];
1997 descrip
1998 = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_EQUIV_KEY];
1999
80670155
RS
2000 if (NILP (item_name))
2001 {
2002 free_menubar_widget_value_tree (first_wv);
2003 *error = "Submenu in dialog items";
2004 return Qnil;
2005 }
fcaa7665
RS
2006 if (EQ (item_name, Qquote))
2007 {
2008 /* This is the boundary between left-side elts
2009 and right-side elts. Stop incrementing right_count. */
2010 boundary_seen = 1;
2011 i++;
2012 continue;
2013 }
80670155
RS
2014 if (nb_buttons >= 10)
2015 {
2016 free_menubar_widget_value_tree (first_wv);
2017 *error = "Too many dialog items";
2018 return Qnil;
2019 }
2020
165e1749
FP
2021 wv = malloc_widget_value ();
2022 prev_wv->next = wv;
80670155 2023 wv->name = (char *) button_names[nb_buttons];
165e1749 2024 if (!NILP (descrip))
4e8d3549
RS
2025 wv->key = (char *) XSTRING (descrip)->data;
2026 wv->value = (char *) XSTRING (item_name)->data;
165e1749
FP
2027 wv->call_data = (void *) &XVECTOR (menu_items)->contents[i];
2028 wv->enabled = !NILP (enable);
2029 prev_wv = wv;
2030
fcaa7665
RS
2031 if (! boundary_seen)
2032 left_count++;
2033
165e1749
FP
2034 nb_buttons++;
2035 i += MENU_ITEMS_ITEM_LENGTH;
2036 }
2037
fcaa7665
RS
2038 /* If the boundary was not specified,
2039 by default put half on the left and half on the right. */
2040 if (! boundary_seen)
2041 left_count = nb_buttons - nb_buttons / 2;
2042
165e1749 2043 wv = malloc_widget_value ();
80670155
RS
2044 wv->name = dialog_name;
2045
2046 /* Dialog boxes use a really stupid name encoding
2047 which specifies how many buttons to use
2048 and how many buttons are on the right.
2049 The Q means something also. */
2050 dialog_name[0] = 'Q';
2051 dialog_name[1] = '0' + nb_buttons;
2052 dialog_name[2] = 'B';
2053 dialog_name[3] = 'R';
fcaa7665
RS
2054 /* Number of buttons to put on the right. */
2055 dialog_name[4] = '0' + nb_buttons - left_count;
80670155 2056 dialog_name[5] = 0;
165e1749
FP
2057 wv->contents = first_wv;
2058 first_wv = wv;
165e1749
FP
2059 }
2060
2061 /* Actually create the dialog. */
cc17e9bf 2062 dialog_id = widget_id_tick++;
165e1749
FP
2063 menu = lw_create_widget (first_wv->name, "dialog", dialog_id, first_wv,
2064 f->display.x->widget, 1, 0,
2065 dialog_selection_callback, 0);
b5587215 2066 lw_modify_all_widgets (dialog_id, first_wv->contents, True);
165e1749
FP
2067 /* Free the widget_value objects we used to specify the contents. */
2068 free_menubar_widget_value_tree (first_wv);
2069
2070 /* No selection has been chosen yet. */
2071 menu_item_selection = 0;
2072
165e1749
FP
2073 /* Display the menu. */
2074 lw_pop_up_all_widgets (dialog_id);
aa669def 2075 popup_activated_flag = 1;
165e1749
FP
2076
2077 /* Process events that apply to the menu. */
2e2b8e22 2078 popup_get_selection ((XEvent *) 0, FRAME_X_DISPLAY_INFO (f), dialog_id);
165e1749 2079
21af8a68
KH
2080 lw_destroy_all_widgets (dialog_id);
2081
165e1749
FP
2082 /* Find the selected item, and its pane, to return
2083 the proper value. */
2084 if (menu_item_selection != 0)
2085 {
2086 Lisp_Object prefix;
2087
2088 prefix = Qnil;
2089 i = 0;
2090 while (i < menu_items_used)
2091 {
2092 Lisp_Object entry;
2093
2094 if (EQ (XVECTOR (menu_items)->contents[i], Qt))
2095 {
2096 prefix
2097 = XVECTOR (menu_items)->contents[i + MENU_ITEMS_PANE_PREFIX];
2098 i += MENU_ITEMS_PANE_LENGTH;
2099 }
2100 else
2101 {
2102 entry
2103 = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_VALUE];
2104 if (menu_item_selection == &XVECTOR (menu_items)->contents[i])
2105 {
2106 if (keymaps != 0)
2107 {
2108 entry = Fcons (entry, Qnil);
2109 if (!NILP (prefix))
2110 entry = Fcons (prefix, entry);
2111 }
2112 return entry;
2113 }
2114 i += MENU_ITEMS_ITEM_LENGTH;
2115 }
2116 }
2117 }
2118
2119 return Qnil;
2120}
18686d47 2121#else /* not USE_X_TOOLKIT */
78589e07
RS
2122
2123static Lisp_Object
673a6211 2124xmenu_show (f, x, y, for_click, keymaps, title, error)
78589e07
RS
2125 FRAME_PTR f;
2126 int x, y;
9685a93f
RS
2127 int for_click;
2128 int keymaps;
78589e07
RS
2129 Lisp_Object title;
2130 char **error;
dcfdbac7 2131{
78589e07
RS
2132 Window root;
2133 XMenu *menu;
2134 int pane, selidx, lpane, status;
2135 Lisp_Object entry, pane_prefix;
dcfdbac7
JB
2136 char *datap;
2137 int ulx, uly, width, height;
2138 int dispwidth, dispheight;
4e8d3549
RS
2139 int i, j;
2140 int maxwidth;
78589e07
RS
2141 int dummy_int;
2142 unsigned int dummy_uint;
088831f6 2143
07a675b7 2144 *error = 0;
78589e07
RS
2145 if (menu_items_n_panes == 0)
2146 return Qnil;
088831f6 2147
742f715d
KH
2148 if (menu_items_used <= MENU_ITEMS_PANE_LENGTH)
2149 {
2150 *error = "Empty menu";
2151 return Qnil;
2152 }
2153
78589e07 2154 /* Figure out which root window F is on. */
92280f67 2155 XGetGeometry (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), &root,
78589e07
RS
2156 &dummy_int, &dummy_int, &dummy_uint, &dummy_uint,
2157 &dummy_uint, &dummy_uint);
18686d47 2158
78589e07 2159 /* Make the menu on that window. */
92280f67 2160 menu = XMenuCreate (FRAME_X_DISPLAY (f), root, "emacs");
78589e07 2161 if (menu == NULL)
dcfdbac7
JB
2162 {
2163 *error = "Can't create menu";
78589e07 2164 return Qnil;
dcfdbac7 2165 }
78589e07 2166
87485d6f 2167#ifdef HAVE_X_WINDOWS
78589e07 2168 /* Adjust coordinates to relative to the outer (window manager) window. */
78589e07
RS
2169 {
2170 Window child;
2171 int win_x = 0, win_y = 0;
2172
2173 /* Find the position of the outside upper-left corner of
2174 the inner window, with respect to the outer window. */
f1847de3 2175 if (f->display.x->parent_desc != FRAME_X_DISPLAY_INFO (f)->root_window)
78589e07
RS
2176 {
2177 BLOCK_INPUT;
92280f67 2178 XTranslateCoordinates (FRAME_X_DISPLAY (f),
78589e07
RS
2179
2180 /* From-window, to-window. */
2181 f->display.x->window_desc,
2182 f->display.x->parent_desc,
2183
2184 /* From-position, to-position. */
2185 0, 0, &win_x, &win_y,
2186
2187 /* Child of window. */
2188 &child);
2189 UNBLOCK_INPUT;
2190 x += win_x;
2191 y += win_y;
2192 }
2193 }
87485d6f 2194#endif /* HAVE_X_WINDOWS */
78589e07
RS
2195
2196 /* Adjust coordinates to be root-window-relative. */
2197 x += f->display.x->left_pos;
2198 y += f->display.x->top_pos;
18686d47 2199
78589e07
RS
2200 /* Create all the necessary panes and their items. */
2201 i = 0;
2202 while (i < menu_items_used)
dcfdbac7 2203 {
78589e07 2204 if (EQ (XVECTOR (menu_items)->contents[i], Qt))
dcfdbac7 2205 {
78589e07
RS
2206 /* Create a new pane. */
2207 Lisp_Object pane_name, prefix;
2208 char *pane_string;
2209
2210 pane_name = XVECTOR (menu_items)->contents[i + MENU_ITEMS_PANE_NAME];
2211 prefix = XVECTOR (menu_items)->contents[i + MENU_ITEMS_PANE_PREFIX];
2212 pane_string = (NILP (pane_name)
2213 ? "" : (char *) XSTRING (pane_name)->data);
2214 if (keymaps && !NILP (prefix))
2215 pane_string++;
2216
92280f67 2217 lpane = XMenuAddPane (FRAME_X_DISPLAY (f), menu, pane_string, TRUE);
78589e07
RS
2218 if (lpane == XM_FAILURE)
2219 {
92280f67 2220 XMenuDestroy (FRAME_X_DISPLAY (f), menu);
78589e07
RS
2221 *error = "Can't create pane";
2222 return Qnil;
2223 }
2224 i += MENU_ITEMS_PANE_LENGTH;
4e8d3549
RS
2225
2226 /* Find the width of the widest item in this pane. */
2227 maxwidth = 0;
2228 j = i;
2229 while (j < menu_items_used)
2230 {
2231 Lisp_Object item;
2232 item = XVECTOR (menu_items)->contents[j];
2233 if (EQ (item, Qt))
2234 break;
2235 if (NILP (item))
2236 {
2237 j++;
2238 continue;
2239 }
2240 width = XSTRING (item)->size;
2241 if (width > maxwidth)
2242 maxwidth = width;
2243
2244 j += MENU_ITEMS_ITEM_LENGTH;
2245 }
dcfdbac7 2246 }
fcaa7665
RS
2247 /* Ignore a nil in the item list.
2248 It's meaningful only for dialog boxes. */
2249 else if (EQ (XVECTOR (menu_items)->contents[i], Qquote))
2250 i += 1;
78589e07 2251 else
dcfdbac7 2252 {
78589e07
RS
2253 /* Create a new item within current pane. */
2254 Lisp_Object item_name, enable, descrip;
4e8d3549 2255 unsigned char *item_data;
78589e07
RS
2256
2257 item_name = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_NAME];
2258 enable = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_ENABLE];
2259 descrip
2260 = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_EQUIV_KEY];
2261 if (!NILP (descrip))
4e8d3549
RS
2262 {
2263 int gap = maxwidth - XSTRING (item_name)->size;
2264#ifdef C_ALLOCA
2265 Lisp_Object spacer;
2266 spacer = Fmake_string (make_number (gap), make_number (' '));
2267 item_name = concat2 (item_name, spacer);
2268 item_name = concat2 (item_name, descrip);
2269 item_data = XSTRING (item_name)->data;
2270#else
2271 /* if alloca is fast, use that to make the space,
2272 to reduce gc needs. */
2273 item_data
2274 = (unsigned char *) alloca (maxwidth
2275 + XSTRING (descrip)->size + 1);
2276 bcopy (XSTRING (item_name)->data, item_data,
2277 XSTRING (item_name)->size);
2278 for (j = XSTRING (item_name)->size; j < maxwidth; j++)
2279 item_data[j] = ' ';
2280 bcopy (XSTRING (descrip)->data, item_data + j,
2281 XSTRING (descrip)->size);
2282 item_data[j + XSTRING (descrip)->size] = 0;
2283#endif
2284 }
2285 else
2286 item_data = XSTRING (item_name)->data;
78589e07 2287
92280f67
RS
2288 if (XMenuAddSelection (FRAME_X_DISPLAY (f),
2289 menu, lpane, 0, item_data,
78589e07 2290 !NILP (enable))
dcfdbac7
JB
2291 == XM_FAILURE)
2292 {
92280f67 2293 XMenuDestroy (FRAME_X_DISPLAY (f), menu);
dcfdbac7 2294 *error = "Can't add selection to menu";
78589e07 2295 return Qnil;
dcfdbac7 2296 }
78589e07 2297 i += MENU_ITEMS_ITEM_LENGTH;
dcfdbac7
JB
2298 }
2299 }
4e8d3549 2300
78589e07 2301 /* All set and ready to fly. */
92280f67
RS
2302 XMenuRecompute (FRAME_X_DISPLAY (f), menu);
2303 dispwidth = DisplayWidth (FRAME_X_DISPLAY (f),
f1847de3 2304 XScreenNumberOfScreen (FRAME_X_SCREEN (f)));
92280f67 2305 dispheight = DisplayHeight (FRAME_X_DISPLAY (f),
f1847de3 2306 XScreenNumberOfScreen (FRAME_X_SCREEN (f)));
78589e07
RS
2307 x = min (x, dispwidth);
2308 y = min (y, dispheight);
2309 x = max (x, 1);
2310 y = max (y, 1);
92280f67 2311 XMenuLocate (FRAME_X_DISPLAY (f), menu, 0, 0, x, y,
dcfdbac7
JB
2312 &ulx, &uly, &width, &height);
2313 if (ulx+width > dispwidth)
2314 {
78589e07 2315 x -= (ulx + width) - dispwidth;
dcfdbac7
JB
2316 ulx = dispwidth - width;
2317 }
2318 if (uly+height > dispheight)
2319 {
78589e07 2320 y -= (uly + height) - dispheight;
dcfdbac7
JB
2321 uly = dispheight - height;
2322 }
78589e07
RS
2323 if (ulx < 0) x -= ulx;
2324 if (uly < 0) y -= uly;
121e4555
KH
2325
2326 XMenuSetAEQ (menu, TRUE);
78589e07
RS
2327 XMenuSetFreeze (menu, TRUE);
2328 pane = selidx = 0;
dcfdbac7 2329
92280f67 2330 status = XMenuActivate (FRAME_X_DISPLAY (f), menu, &pane, &selidx,
78589e07 2331 x, y, ButtonReleaseMask, &datap);
a352a815
RS
2332
2333
f1df80a8 2334#ifdef HAVE_X_WINDOWS
a352a815
RS
2335 /* Assume the mouse has moved out of the X window.
2336 If it has actually moved in, we will get an EnterNotify. */
29e460bd 2337 x_mouse_leave (FRAME_X_DISPLAY_INFO (f));
f1df80a8 2338#endif
a352a815 2339
dcfdbac7
JB
2340 switch (status)
2341 {
2342 case XM_SUCCESS:
2343#ifdef XDEBUG
2344 fprintf (stderr, "pane= %d line = %d\n", panes, selidx);
2345#endif
fa6d54d9 2346
78589e07
RS
2347 /* Find the item number SELIDX in pane number PANE. */
2348 i = 0;
2349 while (i < menu_items_used)
fa6d54d9 2350 {
78589e07 2351 if (EQ (XVECTOR (menu_items)->contents[i], Qt))
088831f6 2352 {
78589e07
RS
2353 if (pane == 0)
2354 pane_prefix
2355 = XVECTOR (menu_items)->contents[i + MENU_ITEMS_PANE_PREFIX];
2356 pane--;
2357 i += MENU_ITEMS_PANE_LENGTH;
088831f6 2358 }
78589e07 2359 else
ab6ee1a0 2360 {
78589e07 2361 if (pane == -1)
ab6ee1a0 2362 {
78589e07 2363 if (selidx == 0)
ab6ee1a0 2364 {
78589e07
RS
2365 entry
2366 = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_VALUE];
2367 if (keymaps != 0)
ab6ee1a0 2368 {
78589e07
RS
2369 entry = Fcons (entry, Qnil);
2370 if (!NILP (pane_prefix))
2371 entry = Fcons (pane_prefix, entry);
ab6ee1a0 2372 }
78589e07 2373 break;
ab6ee1a0 2374 }
78589e07 2375 selidx--;
ab6ee1a0 2376 }
78589e07 2377 i += MENU_ITEMS_ITEM_LENGTH;
ab6ee1a0
RS
2378 }
2379 }
78589e07 2380 break;
dcfdbac7 2381
78589e07 2382 case XM_FAILURE:
78589e07
RS
2383 *error = "Can't activate menu";
2384 case XM_IA_SELECT:
2385 case XM_NO_SELECT:
2386 entry = Qnil;
2387 break;
dcfdbac7 2388 }
92280f67 2389 XMenuDestroy (FRAME_X_DISPLAY (f), menu);
a5285df3 2390
87485d6f 2391#ifdef HAVE_X_WINDOWS
a5285df3
RS
2392 /* State that no mouse buttons are now held.
2393 (The oldXMenu code doesn't track this info for us.)
2394 That is not necessarily true, but the fiction leads to reasonable
2395 results, and it is a pain to ask which are actually held now. */
e9a79fb2 2396 FRAME_X_DISPLAY_INFO (f)->grabbed = 0;
87485d6f 2397#endif
a5285df3 2398
78589e07 2399 return entry;
dcfdbac7 2400}
4dedbfe0 2401
78589e07 2402#endif /* not USE_X_TOOLKIT */
088831f6 2403\f
78589e07 2404syms_of_xmenu ()
dcfdbac7 2405{
78589e07
RS
2406 staticpro (&menu_items);
2407 menu_items = Qnil;
dcfdbac7 2408
8ed87156 2409#ifdef USE_X_TOOLKIT
4dedbfe0 2410 widget_id_tick = (1<<16);
8ed87156
RS
2411#endif
2412
bd3a4da2
RS
2413 staticpro (&frame_vector);
2414 frame_vector = Fmake_vector (make_number (10), Qnil);
2415
78589e07 2416 defsubr (&Sx_popup_menu);
165e1749 2417 defsubr (&Sx_popup_dialog);
dcfdbac7 2418}