1 /* Platform-independent code for terminal communications.
2 Copyright (C) 1986, 1988, 1993, 1994, 1996, 1999, 2000, 2001, 2002, 2003,
3 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
27 #include "termhooks.h"
28 #include "blockinput.h"
29 #include "dispextern.h"
32 #include "../lwlib/lwlib.h"
50 extern AppendMenuW_Proc unicode_append_menu
;
52 #endif /* HAVE_NTGUI */
56 /* Define HAVE_BOXES if menus can handle radio and toggle buttons. */
57 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NTGUI)
61 extern Lisp_Object QCtoggle
, QCradio
;
63 Lisp_Object menu_items
;
65 /* If non-nil, means that the global vars defined here are already in use.
66 Used to detect cases where we try to re-enter this non-reentrant code. */
67 Lisp_Object menu_items_inuse
;
69 /* Number of slots currently allocated in menu_items. */
70 int menu_items_allocated
;
72 /* This is the index in menu_items of the first empty slot. */
75 /* The number of panes currently recorded in menu_items,
76 excluding those within submenus. */
77 int menu_items_n_panes
;
79 /* Current depth within submenus. */
80 static int menu_items_submenu_depth
;
85 if (!NILP (menu_items_inuse
))
86 error ("Trying to use a menu from within a menu-entry");
88 if (NILP (menu_items
))
90 menu_items_allocated
= 60;
91 menu_items
= Fmake_vector (make_number (menu_items_allocated
), Qnil
);
94 menu_items_inuse
= Qt
;
96 menu_items_n_panes
= 0;
97 menu_items_submenu_depth
= 0;
100 /* Call at the end of generating the data in menu_items. */
108 unuse_menu_items (dummy
)
111 return menu_items_inuse
= Qnil
;
114 /* Call when finished using the data for the current menu
118 discard_menu_items ()
120 /* Free the structure if it is especially large.
121 Otherwise, hold on to it, to save time. */
122 if (menu_items_allocated
> 200)
125 menu_items_allocated
= 0;
127 xassert (NILP (menu_items_inuse
));
130 /* This undoes save_menu_items, and it is called by the specpdl unwind
134 restore_menu_items (saved
)
137 menu_items
= XCAR (saved
);
138 menu_items_inuse
= (! NILP (menu_items
) ? Qt
: Qnil
);
139 menu_items_allocated
= (VECTORP (menu_items
) ? ASIZE (menu_items
) : 0);
140 saved
= XCDR (saved
);
141 menu_items_used
= XINT (XCAR (saved
));
142 saved
= XCDR (saved
);
143 menu_items_n_panes
= XINT (XCAR (saved
));
144 saved
= XCDR (saved
);
145 menu_items_submenu_depth
= XINT (XCAR (saved
));
149 /* Push the whole state of menu_items processing onto the specpdl.
150 It will be restored when the specpdl is unwound. */
155 Lisp_Object saved
= list4 (!NILP (menu_items_inuse
) ? menu_items
: Qnil
,
156 make_number (menu_items_used
),
157 make_number (menu_items_n_panes
),
158 make_number (menu_items_submenu_depth
));
159 record_unwind_protect (restore_menu_items
, saved
);
160 menu_items_inuse
= Qnil
;
165 /* Make the menu_items vector twice as large. */
170 menu_items_allocated
*= 2;
171 menu_items
= larger_vector (menu_items
, menu_items_allocated
, Qnil
);
174 /* Begin a submenu. */
177 push_submenu_start ()
179 if (menu_items_used
+ 1 > menu_items_allocated
)
182 XVECTOR (menu_items
)->contents
[menu_items_used
++] = Qnil
;
183 menu_items_submenu_depth
++;
191 if (menu_items_used
+ 1 > menu_items_allocated
)
194 XVECTOR (menu_items
)->contents
[menu_items_used
++] = Qlambda
;
195 menu_items_submenu_depth
--;
198 /* Indicate boundary between left and right. */
201 push_left_right_boundary ()
203 if (menu_items_used
+ 1 > menu_items_allocated
)
206 XVECTOR (menu_items
)->contents
[menu_items_used
++] = Qquote
;
209 /* Start a new menu pane in menu_items.
210 NAME is the pane name. PREFIX_VEC is a prefix key for this pane. */
213 push_menu_pane (name
, prefix_vec
)
214 Lisp_Object name
, prefix_vec
;
216 if (menu_items_used
+ MENU_ITEMS_PANE_LENGTH
> menu_items_allocated
)
219 if (menu_items_submenu_depth
== 0)
220 menu_items_n_panes
++;
221 XVECTOR (menu_items
)->contents
[menu_items_used
++] = Qt
;
222 XVECTOR (menu_items
)->contents
[menu_items_used
++] = name
;
223 XVECTOR (menu_items
)->contents
[menu_items_used
++] = prefix_vec
;
226 /* Push one menu item into the current pane. NAME is the string to
227 display. ENABLE if non-nil means this item can be selected. KEY
228 is the key generated by choosing this item, or nil if this item
229 doesn't really have a definition. DEF is the definition of this
230 item. EQUIV is the textual description of the keyboard equivalent
231 for this item (or nil if none). TYPE is the type of this menu
232 item, one of nil, `toggle' or `radio'. */
235 push_menu_item (name
, enable
, key
, def
, equiv
, type
, selected
, help
)
236 Lisp_Object name
, enable
, key
, def
, equiv
, type
, selected
, help
;
238 if (menu_items_used
+ MENU_ITEMS_ITEM_LENGTH
> menu_items_allocated
)
241 XVECTOR (menu_items
)->contents
[menu_items_used
++] = name
;
242 XVECTOR (menu_items
)->contents
[menu_items_used
++] = enable
;
243 XVECTOR (menu_items
)->contents
[menu_items_used
++] = key
;
244 XVECTOR (menu_items
)->contents
[menu_items_used
++] = equiv
;
245 XVECTOR (menu_items
)->contents
[menu_items_used
++] = def
;
246 XVECTOR (menu_items
)->contents
[menu_items_used
++] = type
;
247 XVECTOR (menu_items
)->contents
[menu_items_used
++] = selected
;
248 XVECTOR (menu_items
)->contents
[menu_items_used
++] = help
;
251 /* Args passed between single_keymap_panes and single_menu_item. */
254 Lisp_Object pending_maps
;
255 int maxdepth
, notreal
;
259 static void single_menu_item
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
,
262 /* This is a recursive subroutine of keymap_panes.
263 It handles one keymap, KEYMAP.
264 The other arguments are passed along
265 or point to local variables of the previous function.
266 If NOTREAL is nonzero, only check for equivalent key bindings, don't
267 evaluate expressions in menu items and don't make any menu.
269 If we encounter submenus deeper than MAXDEPTH levels, ignore them. */
272 single_keymap_panes (keymap
, pane_name
, prefix
, notreal
, maxdepth
)
274 Lisp_Object pane_name
;
282 skp
.pending_maps
= Qnil
;
283 skp
.maxdepth
= maxdepth
;
284 skp
.notreal
= notreal
;
290 push_menu_pane (pane_name
, prefix
);
293 /* Remember index for first item in this pane so we can go back and
294 add a prefix when (if) we see the first button. After that, notbuttons
295 is set to 0, to mark that we have seen a button and all non button
296 items need a prefix. */
297 skp
.notbuttons
= menu_items_used
;
300 GCPRO1 (skp
.pending_maps
);
301 map_keymap_canonical (keymap
, single_menu_item
, Qnil
, &skp
);
304 /* Process now any submenus which want to be panes at this level. */
305 while (CONSP (skp
.pending_maps
))
307 Lisp_Object elt
, eltcdr
, string
;
308 elt
= XCAR (skp
.pending_maps
);
310 string
= XCAR (eltcdr
);
311 /* We no longer discard the @ from the beginning of the string here.
312 Instead, we do this in *menu_show. */
313 single_keymap_panes (Fcar (elt
), string
,
314 XCDR (eltcdr
), notreal
, maxdepth
- 1);
315 skp
.pending_maps
= XCDR (skp
.pending_maps
);
319 /* This is a subroutine of single_keymap_panes that handles one
321 KEY is a key in a keymap and ITEM is its binding.
322 SKP->PENDING_MAPS_PTR is a list of keymaps waiting to be made into
324 If SKP->NOTREAL is nonzero, only check for equivalent key bindings, don't
325 evaluate expressions in menu items and don't make any menu.
326 If we encounter submenus deeper than SKP->MAXDEPTH levels, ignore them. */
329 single_menu_item (key
, item
, dummy
, skp_v
)
330 Lisp_Object key
, item
, dummy
;
333 Lisp_Object map
, item_string
, enabled
;
334 struct gcpro gcpro1
, gcpro2
;
336 struct skp
*skp
= skp_v
;
338 /* Parse the menu item and leave the result in item_properties. */
340 res
= parse_menu_item (item
, skp
->notreal
, 0);
343 return; /* Not a menu item. */
345 map
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_MAP
];
349 /* We don't want to make a menu, just traverse the keymaps to
350 precompute equivalent key bindings. */
352 single_keymap_panes (map
, Qnil
, key
, 1, skp
->maxdepth
- 1);
356 enabled
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ENABLE
];
357 item_string
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
];
359 if (!NILP (map
) && SREF (item_string
, 0) == '@')
362 /* An enabled separate pane. Remember this to handle it later. */
363 skp
->pending_maps
= Fcons (Fcons (map
, Fcons (item_string
, key
)),
368 #if defined(HAVE_X_WINDOWS) || defined(MSDOS)
370 /* Simulate radio buttons and toggle boxes by putting a prefix in
373 Lisp_Object prefix
= Qnil
;
374 Lisp_Object type
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_TYPE
];
378 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_SELECTED
];
381 /* The first button. Line up previous items in this menu. */
383 int index
= skp
->notbuttons
; /* Index for first item this menu. */
386 while (index
< menu_items_used
)
389 = XVECTOR (menu_items
)->contents
[index
+ MENU_ITEMS_ITEM_NAME
];
393 submenu
++; /* Skip sub menu. */
395 else if (EQ (tem
, Qlambda
))
398 submenu
--; /* End sub menu. */
400 else if (EQ (tem
, Qt
))
401 index
+= 3; /* Skip new pane marker. */
402 else if (EQ (tem
, Qquote
))
403 index
++; /* Skip a left, right divider. */
406 if (!submenu
&& SREF (tem
, 0) != '\0'
407 && SREF (tem
, 0) != '-')
408 XVECTOR (menu_items
)->contents
[index
+ MENU_ITEMS_ITEM_NAME
]
409 = concat2 (build_string (" "), tem
);
410 index
+= MENU_ITEMS_ITEM_LENGTH
;
416 /* Calculate prefix, if any, for this item. */
417 if (EQ (type
, QCtoggle
))
418 prefix
= build_string (NILP (selected
) ? "[ ] " : "[X] ");
419 else if (EQ (type
, QCradio
))
420 prefix
= build_string (NILP (selected
) ? "( ) " : "(*) ");
422 /* Not a button. If we have earlier buttons, then we need a prefix. */
423 else if (!skp
->notbuttons
&& SREF (item_string
, 0) != '\0'
424 && SREF (item_string
, 0) != '-')
425 prefix
= build_string (" ");
428 item_string
= concat2 (prefix
, item_string
);
430 #endif /* not HAVE_BOXES */
432 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
434 /* Indicate visually that this is a submenu. */
435 item_string
= concat2 (item_string
, build_string (" >"));
438 #endif /* HAVE_X_WINDOWS || MSDOS */
440 push_menu_item (item_string
, enabled
, key
,
441 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
],
442 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_KEYEQ
],
443 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_TYPE
],
444 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_SELECTED
],
445 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_HELP
]);
447 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (HAVE_NTGUI)
448 /* Display a submenu using the toolkit. */
449 if (! (NILP (map
) || NILP (enabled
)))
451 push_submenu_start ();
452 single_keymap_panes (map
, Qnil
, key
, 0, skp
->maxdepth
- 1);
458 /* Look through KEYMAPS, a vector of keymaps that is NMAPS long,
459 and generate menu panes for them in menu_items.
460 If NOTREAL is nonzero,
461 don't bother really computing whether an item is enabled. */
464 keymap_panes (keymaps
, nmaps
, notreal
)
465 Lisp_Object
*keymaps
;
473 /* Loop over the given keymaps, making a pane for each map.
474 But don't make a pane that is empty--ignore that map instead.
475 P is the number of panes we have made so far. */
476 for (mapno
= 0; mapno
< nmaps
; mapno
++)
477 single_keymap_panes (keymaps
[mapno
],
478 Fkeymap_prompt (keymaps
[mapno
]), Qnil
, notreal
, 10);
480 finish_menu_items ();
484 /* Push the items in a single pane defined by the alist PANE. */
489 Lisp_Object tail
, item
, item1
;
491 for (tail
= pane
; CONSP (tail
); tail
= XCDR (tail
))
495 push_menu_item (ENCODE_MENU_STRING (item
), Qnil
, Qnil
, Qt
,
496 Qnil
, Qnil
, Qnil
, Qnil
);
497 else if (CONSP (item
))
500 CHECK_STRING (item1
);
501 push_menu_item (ENCODE_MENU_STRING (item1
), Qt
, XCDR (item
),
502 Qt
, Qnil
, Qnil
, Qnil
, Qnil
);
505 push_left_right_boundary ();
510 /* Push all the panes and items of a menu described by the
511 alist-of-alists MENU.
512 This handles old-fashioned calls to x-popup-menu. */
521 for (tail
= menu
; CONSP (tail
); tail
= XCDR (tail
))
523 Lisp_Object elt
, pane_name
, pane_data
;
525 pane_name
= Fcar (elt
);
526 CHECK_STRING (pane_name
);
527 push_menu_pane (ENCODE_MENU_STRING (pane_name
), Qnil
);
528 pane_data
= Fcdr (elt
);
529 CHECK_CONS (pane_data
);
530 list_of_items (pane_data
);
533 finish_menu_items ();
536 /* Set up data in menu_items for a menu bar item
537 whose event type is ITEM_KEY (with string ITEM_NAME)
538 and whose contents come from the list of keymaps MAPS. */
540 parse_single_submenu (item_key
, item_name
, maps
)
541 Lisp_Object item_key
, item_name
, maps
;
547 int top_level_items
= 0;
549 length
= Flength (maps
);
552 /* Convert the list MAPS into a vector MAPVEC. */
553 mapvec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
554 for (i
= 0; i
< len
; i
++)
556 mapvec
[i
] = Fcar (maps
);
560 /* Loop over the given keymaps, making a pane for each map.
561 But don't make a pane that is empty--ignore that map instead. */
562 for (i
= 0; i
< len
; i
++)
564 if (!KEYMAPP (mapvec
[i
]))
566 /* Here we have a command at top level in the menu bar
567 as opposed to a submenu. */
569 push_menu_pane (Qnil
, Qnil
);
570 push_menu_item (item_name
, Qt
, item_key
, mapvec
[i
],
571 Qnil
, Qnil
, Qnil
, Qnil
);
576 prompt
= Fkeymap_prompt (mapvec
[i
]);
577 single_keymap_panes (mapvec
[i
],
578 !NILP (prompt
) ? prompt
: item_name
,
583 return top_level_items
;
587 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (HAVE_NTGUI)
589 /* Allocate a widget_value, blocking input. */
592 xmalloc_widget_value ()
597 value
= malloc_widget_value ();
603 /* This recursively calls free_widget_value on the tree of widgets.
604 It must free all data that was malloc'ed for these widget_values.
605 In Emacs, many slots are pointers into the data of Lisp_Strings, and
606 must be left alone. */
609 free_menubar_widget_value_tree (wv
)
614 wv
->name
= wv
->value
= wv
->key
= (char *) 0xDEADBEEF;
616 if (wv
->contents
&& (wv
->contents
!= (widget_value
*)1))
618 free_menubar_widget_value_tree (wv
->contents
);
619 wv
->contents
= (widget_value
*) 0xDEADBEEF;
623 free_menubar_widget_value_tree (wv
->next
);
624 wv
->next
= (widget_value
*) 0xDEADBEEF;
627 free_widget_value (wv
);
631 /* Create a tree of widget_value objects
632 representing the panes and items
633 in menu_items starting at index START, up to index END. */
636 digest_single_submenu (start
, end
, top_level_items
)
637 int start
, end
, top_level_items
;
639 widget_value
*wv
, *prev_wv
, *save_wv
, *first_wv
;
641 int submenu_depth
= 0;
642 widget_value
**submenu_stack
;
646 = (widget_value
**) alloca (menu_items_used
* sizeof (widget_value
*));
647 wv
= xmalloc_widget_value ();
651 wv
->button_type
= BUTTON_TYPE_NONE
;
657 /* Loop over all panes and items made by the preceding call
658 to parse_single_submenu and construct a tree of widget_value objects.
659 Ignore the panes and items used by previous calls to
660 digest_single_submenu, even though those are also in menu_items. */
664 if (EQ (XVECTOR (menu_items
)->contents
[i
], Qnil
))
666 submenu_stack
[submenu_depth
++] = save_wv
;
671 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qlambda
))
674 save_wv
= submenu_stack
[--submenu_depth
];
677 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qt
)
678 && submenu_depth
!= 0)
679 i
+= MENU_ITEMS_PANE_LENGTH
;
680 /* Ignore a nil in the item list.
681 It's meaningful only for dialog boxes. */
682 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qquote
))
684 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qt
))
686 /* Create a new pane. */
687 Lisp_Object pane_name
, prefix
;
692 pane_name
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_PANE_NAME
];
693 prefix
= XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_PANE_PREFIX
];
696 if (STRINGP (pane_name
))
698 if (unicode_append_menu
)
699 /* Encode as UTF-8 for now. */
700 pane_name
= ENCODE_UTF_8 (pane_name
);
701 else if (STRING_MULTIBYTE (pane_name
))
702 pane_name
= ENCODE_SYSTEM (pane_name
);
704 ASET (menu_items
, i
+ MENU_ITEMS_PANE_NAME
, pane_name
);
706 #elif !defined (HAVE_MULTILINGUAL_MENU)
707 if (STRINGP (pane_name
) && STRING_MULTIBYTE (pane_name
))
709 pane_name
= ENCODE_MENU_STRING (pane_name
);
710 ASET (menu_items
, i
+ MENU_ITEMS_PANE_NAME
, pane_name
);
714 pane_string
= (NILP (pane_name
)
715 ? "" : (char *) SDATA (pane_name
));
716 /* If there is just one top-level pane, put all its items directly
717 under the top-level menu. */
718 if (menu_items_n_panes
== 1)
721 /* If the pane has a meaningful name,
722 make the pane a top-level menu item
723 with its items as a submenu beneath it. */
724 if (strcmp (pane_string
, ""))
726 wv
= xmalloc_widget_value ();
730 first_wv
->contents
= wv
;
731 wv
->lname
= pane_name
;
732 /* Set value to 1 so update_submenu_strings can handle '@' */
733 wv
->value
= (char *)1;
735 wv
->button_type
= BUTTON_TYPE_NONE
;
743 i
+= MENU_ITEMS_PANE_LENGTH
;
747 /* Create a new item within current pane. */
748 Lisp_Object item_name
, enable
, descrip
, def
, type
, selected
;
751 /* All items should be contained in panes. */
755 item_name
= AREF (menu_items
, i
+ MENU_ITEMS_ITEM_NAME
);
756 enable
= AREF (menu_items
, i
+ MENU_ITEMS_ITEM_ENABLE
);
757 descrip
= AREF (menu_items
, i
+ MENU_ITEMS_ITEM_EQUIV_KEY
);
758 def
= AREF (menu_items
, i
+ MENU_ITEMS_ITEM_DEFINITION
);
759 type
= AREF (menu_items
, i
+ MENU_ITEMS_ITEM_TYPE
);
760 selected
= AREF (menu_items
, i
+ MENU_ITEMS_ITEM_SELECTED
);
761 help
= AREF (menu_items
, i
+ MENU_ITEMS_ITEM_HELP
);
764 if (STRINGP (item_name
))
766 if (unicode_append_menu
)
767 item_name
= ENCODE_UTF_8 (item_name
);
768 else if (STRING_MULTIBYTE (item_name
))
769 item_name
= ENCODE_SYSTEM (item_name
);
771 ASET (menu_items
, i
+ MENU_ITEMS_ITEM_NAME
, item_name
);
774 if (STRINGP (descrip
) && STRING_MULTIBYTE (descrip
))
776 descrip
= ENCODE_SYSTEM (descrip
);
777 ASET (menu_items
, i
+ MENU_ITEMS_ITEM_EQUIV_KEY
, descrip
);
779 #elif !defined (HAVE_MULTILINGUAL_MENU)
780 if (STRING_MULTIBYTE (item_name
))
782 item_name
= ENCODE_MENU_STRING (item_name
);
783 ASET (menu_items
, i
+ MENU_ITEMS_ITEM_NAME
, item_name
);
786 if (STRINGP (descrip
) && STRING_MULTIBYTE (descrip
))
788 descrip
= ENCODE_MENU_STRING (descrip
);
789 ASET (menu_items
, i
+ MENU_ITEMS_ITEM_EQUIV_KEY
, descrip
);
793 wv
= xmalloc_widget_value ();
797 save_wv
->contents
= wv
;
799 wv
->lname
= item_name
;
803 /* The EMACS_INT cast avoids a warning. There's no problem
804 as long as pointers have enough bits to hold small integers. */
805 wv
->call_data
= (!NILP (def
) ? (void *) (EMACS_INT
) i
: 0);
806 wv
->enabled
= !NILP (enable
);
809 wv
->button_type
= BUTTON_TYPE_NONE
;
810 else if (EQ (type
, QCradio
))
811 wv
->button_type
= BUTTON_TYPE_RADIO
;
812 else if (EQ (type
, QCtoggle
))
813 wv
->button_type
= BUTTON_TYPE_TOGGLE
;
817 wv
->selected
= !NILP (selected
);
818 if (! STRINGP (help
))
825 i
+= MENU_ITEMS_ITEM_LENGTH
;
829 /* If we have just one "menu item"
830 that was originally a button, return it by itself. */
831 if (top_level_items
&& first_wv
->contents
&& first_wv
->contents
->next
== 0)
833 wv
= first_wv
->contents
;
834 free_widget_value (first_wv
);
841 /* Walk through the widget_value tree starting at FIRST_WV and update
842 the char * pointers from the corresponding lisp values.
843 We do this after building the whole tree, since GC may happen while the
844 tree is constructed, and small strings are relocated. So we must wait
845 until no GC can happen before storing pointers into lisp values. */
847 update_submenu_strings (first_wv
)
848 widget_value
*first_wv
;
852 for (wv
= first_wv
; wv
; wv
= wv
->next
)
854 if (STRINGP (wv
->lname
))
856 wv
->name
= (char *) SDATA (wv
->lname
);
858 /* Ignore the @ that means "separate pane".
859 This is a kludge, but this isn't worth more time. */
860 if (wv
->value
== (char *)1)
862 if (wv
->name
[0] == '@')
868 if (STRINGP (wv
->lkey
))
869 wv
->key
= (char *) SDATA (wv
->lkey
);
872 update_submenu_strings (wv
->contents
);
876 /* Find the menu selection and store it in the keyboard buffer.
877 F is the frame the menu is on.
878 MENU_BAR_ITEMS_USED is the length of VECTOR.
879 VECTOR is an array of menu events for the whole menu. */
882 find_and_call_menu_selection (f
, menu_bar_items_used
, vector
, client_data
)
884 int menu_bar_items_used
;
888 Lisp_Object prefix
, entry
;
889 Lisp_Object
*subprefix_stack
;
890 int submenu_depth
= 0;
894 subprefix_stack
= (Lisp_Object
*) alloca (menu_bar_items_used
* sizeof (Lisp_Object
));
898 while (i
< menu_bar_items_used
)
900 if (EQ (XVECTOR (vector
)->contents
[i
], Qnil
))
902 subprefix_stack
[submenu_depth
++] = prefix
;
906 else if (EQ (XVECTOR (vector
)->contents
[i
], Qlambda
))
908 prefix
= subprefix_stack
[--submenu_depth
];
911 else if (EQ (XVECTOR (vector
)->contents
[i
], Qt
))
913 prefix
= XVECTOR (vector
)->contents
[i
+ MENU_ITEMS_PANE_PREFIX
];
914 i
+= MENU_ITEMS_PANE_LENGTH
;
918 entry
= XVECTOR (vector
)->contents
[i
+ MENU_ITEMS_ITEM_VALUE
];
919 /* The EMACS_INT cast avoids a warning. There's no problem
920 as long as pointers have enough bits to hold small integers. */
921 if ((int) (EMACS_INT
) client_data
== i
)
924 struct input_event buf
;
928 XSETFRAME (frame
, f
);
929 buf
.kind
= MENU_BAR_EVENT
;
930 buf
.frame_or_window
= frame
;
932 kbd_buffer_store_event (&buf
);
934 for (j
= 0; j
< submenu_depth
; j
++)
935 if (!NILP (subprefix_stack
[j
]))
937 buf
.kind
= MENU_BAR_EVENT
;
938 buf
.frame_or_window
= frame
;
939 buf
.arg
= subprefix_stack
[j
];
940 kbd_buffer_store_event (&buf
);
945 buf
.kind
= MENU_BAR_EVENT
;
946 buf
.frame_or_window
= frame
;
948 kbd_buffer_store_event (&buf
);
951 buf
.kind
= MENU_BAR_EVENT
;
952 buf
.frame_or_window
= frame
;
954 kbd_buffer_store_event (&buf
);
958 i
+= MENU_ITEMS_ITEM_LENGTH
;
963 #endif /* USE_X_TOOLKIT || USE_GTK || HAVE_NS || HAVE_NTGUI */
966 /* As above, but return the menu selection instead of storing in kb buffer.
967 If keymaps==1, return full prefixes to selection. */
969 find_and_return_menu_selection (FRAME_PTR f
, int keymaps
, void *client_data
)
971 Lisp_Object prefix
, entry
;
973 Lisp_Object
*subprefix_stack
;
974 int submenu_depth
= 0;
976 prefix
= entry
= Qnil
;
979 (Lisp_Object
*)alloca(menu_items_used
* sizeof (Lisp_Object
));
981 while (i
< menu_items_used
)
983 if (EQ (XVECTOR (menu_items
)->contents
[i
], Qnil
))
985 subprefix_stack
[submenu_depth
++] = prefix
;
989 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qlambda
))
991 prefix
= subprefix_stack
[--submenu_depth
];
994 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qt
))
997 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_PANE_PREFIX
];
998 i
+= MENU_ITEMS_PANE_LENGTH
;
1000 /* Ignore a nil in the item list.
1001 It's meaningful only for dialog boxes. */
1002 else if (EQ (XVECTOR (menu_items
)->contents
[i
], Qquote
))
1007 = XVECTOR (menu_items
)->contents
[i
+ MENU_ITEMS_ITEM_VALUE
];
1008 if ((int) (EMACS_INT
)client_data
== (int)(&XVECTOR (menu_items
)->contents
[i
]))
1014 entry
= Fcons (entry
, Qnil
);
1016 entry
= Fcons (prefix
, entry
);
1017 for (j
= submenu_depth
- 1; j
>= 0; j
--)
1018 if (!NILP (subprefix_stack
[j
]))
1019 entry
= Fcons (subprefix_stack
[j
], entry
);
1023 i
+= MENU_ITEMS_ITEM_LENGTH
;
1033 staticpro (&menu_items
);
1035 menu_items_inuse
= Qnil
;
1038 /* arch-tag: 78bbc7cf-8025-4156-aa8a-6c7fd99bf51d
1039 (do not change this comment) */