428
|
1 /* Implements an elisp-programmable menubar.
|
|
2 Copyright (C) 1993, 1994 Free Software Foundation, Inc.
|
|
3 Copyright (C) 1995 Tinker Systems and INS Engineering Corp.
|
826
|
4 Copyright (C) 2001, 2002 Ben Wing.
|
428
|
5
|
|
6 This file is part of XEmacs.
|
|
7
|
|
8 XEmacs is free software; you can redistribute it and/or modify it
|
|
9 under the terms of the GNU General Public License as published by the
|
|
10 Free Software Foundation; either version 2, or (at your option) any
|
|
11 later version.
|
|
12
|
|
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
16 for more details.
|
|
17
|
|
18 You should have received a copy of the GNU General Public License
|
|
19 along with XEmacs; see the file COPYING. If not, write to
|
|
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
21 Boston, MA 02111-1307, USA. */
|
|
22
|
|
23 /* Synched up with: Not in FSF. */
|
|
24
|
442
|
25 /* Authorship:
|
|
26
|
|
27 Created by Ben Wing as part of device-abstraction work for 19.12.
|
|
28 Menu filters and many other keywords added by Stig for 19.12.
|
|
29 Menu accelerators c. 1997? by ??. Moved here from event-stream.c.
|
|
30 Much other work post-1996 by ??.
|
|
31 */
|
428
|
32
|
|
33 #include <config.h>
|
|
34 #include "lisp.h"
|
|
35
|
|
36 #include "buffer.h"
|
872
|
37 #include "device-impl.h"
|
|
38 #include "frame-impl.h"
|
428
|
39 #include "gui.h"
|
442
|
40 #include "keymap.h"
|
428
|
41 #include "menubar.h"
|
|
42 #include "redisplay.h"
|
800
|
43 #include "specifier.h"
|
872
|
44 #include "window-impl.h"
|
428
|
45
|
|
46 int menubar_show_keybindings;
|
|
47 Lisp_Object Vmenubar_configuration;
|
|
48
|
|
49 Lisp_Object Qcurrent_menubar;
|
|
50
|
|
51 Lisp_Object Qactivate_menubar_hook, Vactivate_menubar_hook;
|
|
52
|
|
53 Lisp_Object Vmenubar_visible_p;
|
|
54
|
|
55 static Lisp_Object Vcurrent_menubar; /* DO NOT ever reference this.
|
|
56 Always go through Qcurrent_menubar.
|
|
57 See below. */
|
|
58
|
|
59 Lisp_Object Vblank_menubar;
|
|
60
|
|
61 int popup_menu_titles;
|
1279
|
62 int in_menu_callback;
|
428
|
63
|
|
64 Lisp_Object Vmenubar_pointer_glyph;
|
|
65
|
442
|
66 /* prefix key(s) that must match in order to activate menu.
|
|
67 This is ugly. fix me.
|
|
68 */
|
|
69 Lisp_Object Vmenu_accelerator_prefix;
|
|
70
|
|
71 /* list of modifier keys to match accelerator for top level menus */
|
|
72 Lisp_Object Vmenu_accelerator_modifiers;
|
|
73
|
|
74 /* whether menu accelerators are enabled */
|
|
75 Lisp_Object Vmenu_accelerator_enabled;
|
|
76
|
|
77 /* keymap for auxiliary menu accelerator functions */
|
|
78 Lisp_Object Vmenu_accelerator_map;
|
|
79
|
|
80 Lisp_Object Qmenu_force;
|
|
81 Lisp_Object Qmenu_fallback;
|
|
82 Lisp_Object Qmenu_quit;
|
|
83 Lisp_Object Qmenu_up;
|
|
84 Lisp_Object Qmenu_down;
|
|
85 Lisp_Object Qmenu_left;
|
|
86 Lisp_Object Qmenu_right;
|
|
87 Lisp_Object Qmenu_select;
|
|
88 Lisp_Object Qmenu_escape;
|
|
89
|
428
|
90 static int
|
2286
|
91 menubar_variable_changed (Lisp_Object UNUSED (sym), Lisp_Object *UNUSED (val),
|
|
92 Lisp_Object UNUSED (in_object), int UNUSED (flags))
|
428
|
93 {
|
|
94 MARK_MENUBAR_CHANGED;
|
|
95 return 0;
|
|
96 }
|
|
97
|
|
98 void
|
|
99 update_frame_menubars (struct frame *f)
|
|
100 {
|
|
101 if (f->menubar_changed || f->windows_changed)
|
|
102 MAYBE_FRAMEMETH (f, update_frame_menubars, (f));
|
|
103
|
|
104 f->menubar_changed = 0;
|
|
105 }
|
|
106
|
|
107 void
|
|
108 free_frame_menubars (struct frame *f)
|
|
109 {
|
|
110 /* If we had directly allocated any memory for the menubars instead
|
|
111 of using all Lisp_Objects this is where we would now free it. */
|
|
112
|
|
113 MAYBE_FRAMEMETH (f, free_frame_menubars, (f));
|
|
114 }
|
|
115
|
|
116 static void
|
2286
|
117 menubar_visible_p_changed (Lisp_Object UNUSED (specifier),
|
|
118 struct window *UNUSED (w),
|
|
119 Lisp_Object UNUSED (oldval))
|
428
|
120 {
|
|
121 MARK_MENUBAR_CHANGED;
|
|
122 }
|
|
123
|
|
124 static void
|
2286
|
125 menubar_visible_p_changed_in_frame (Lisp_Object UNUSED (specifier),
|
|
126 struct frame *f,
|
|
127 Lisp_Object UNUSED (oldval))
|
428
|
128 {
|
|
129 update_frame_menubars (f);
|
|
130 }
|
|
131
|
|
132 Lisp_Object
|
442
|
133 current_frame_menubar (const struct frame* f)
|
428
|
134 {
|
|
135 struct window *w = XWINDOW (FRAME_LAST_NONMINIBUF_WINDOW (f));
|
|
136 return symbol_value_in_buffer (Qcurrent_menubar, w->buffer);
|
|
137 }
|
|
138
|
|
139 Lisp_Object
|
|
140 menu_parse_submenu_keywords (Lisp_Object desc, Lisp_Object gui_item)
|
|
141 {
|
442
|
142 Lisp_Gui_Item *pgui_item = XGUI_ITEM (gui_item);
|
428
|
143
|
|
144 /* Menu descriptor should be a list */
|
|
145 CHECK_CONS (desc);
|
|
146
|
|
147 /* First element may be menu name, although can be omitted.
|
|
148 Let's think that if stuff begins with anything than a keyword
|
|
149 or a list (submenu), this is a menu name, expected to be a string */
|
|
150 if (!KEYWORDP (XCAR (desc)) && !CONSP (XCAR (desc)))
|
|
151 {
|
|
152 CHECK_STRING (XCAR (desc));
|
|
153 pgui_item->name = XCAR (desc);
|
|
154 desc = XCDR (desc);
|
|
155 if (!NILP (desc))
|
|
156 CHECK_CONS (desc);
|
|
157 }
|
|
158
|
|
159 /* Walk along all key-value pairs */
|
|
160 while (!NILP(desc) && KEYWORDP (XCAR (desc)))
|
|
161 {
|
|
162 Lisp_Object key, val;
|
|
163 key = XCAR (desc);
|
|
164 desc = XCDR (desc);
|
|
165 CHECK_CONS (desc);
|
|
166 val = XCAR (desc);
|
|
167 desc = XCDR (desc);
|
|
168 if (!NILP (desc))
|
|
169 CHECK_CONS (desc);
|
|
170 gui_item_add_keyval_pair (gui_item, key, val, ERROR_ME);
|
|
171 }
|
|
172
|
|
173 /* Return the rest - supposed to be a list of items */
|
|
174 return desc;
|
|
175 }
|
|
176
|
|
177 DEFUN ("menu-find-real-submenu", Fmenu_find_real_submenu, 2, 2, 0, /*
|
|
178 Find a submenu descriptor within DESC by following PATH.
|
|
179 This function finds a submenu descriptor, either from the description
|
|
180 DESC or generated by a filter within DESC. The function regards :config
|
|
181 and :included keywords in the DESC, and expands submenus along the
|
|
182 PATH using :filter functions. Return value is a descriptor for the
|
|
183 submenu, NOT expanded and NOT checked against :config and :included.
|
|
184 Also, individual menu items are not looked for, only submenus.
|
|
185
|
|
186 See also 'find-menu-item'.
|
|
187 */
|
|
188 (desc, path))
|
|
189 {
|
|
190 Lisp_Object path_entry, submenu_desc, submenu;
|
442
|
191 struct gcpro gcpro1, gcpro2;
|
428
|
192 Lisp_Object gui_item = allocate_gui_item ();
|
440
|
193 Lisp_Gui_Item* pgui_item = XGUI_ITEM (gui_item);
|
428
|
194
|
442
|
195 GCPRO2 (gui_item, desc);
|
428
|
196
|
|
197 EXTERNAL_LIST_LOOP (path_entry, path)
|
|
198 {
|
|
199 /* Verify that DESC describes a menu, not single item */
|
|
200 if (!CONSP (desc))
|
|
201 RETURN_UNGCPRO (Qnil);
|
|
202
|
|
203 /* Parse this menu */
|
|
204 desc = menu_parse_submenu_keywords (desc, gui_item);
|
|
205
|
|
206 /* Check that this (sub)menu is active */
|
1913
|
207 if (!gui_item_active_p (gui_item))
|
428
|
208 RETURN_UNGCPRO (Qnil);
|
|
209
|
|
210 /* Apply :filter */
|
|
211 if (!NILP (pgui_item->filter))
|
|
212 desc = call1 (pgui_item->filter, desc);
|
|
213
|
|
214 /* Find the next menu on the path inside this one */
|
|
215 EXTERNAL_LIST_LOOP (submenu_desc, desc)
|
|
216 {
|
|
217 submenu = XCAR (submenu_desc);
|
|
218 if (CONSP (submenu)
|
|
219 && STRINGP (XCAR (submenu))
|
|
220 && !NILP (Fstring_equal (XCAR (submenu), XCAR (path_entry))))
|
|
221 {
|
|
222 desc = submenu;
|
|
223 goto descend;
|
|
224 }
|
|
225 }
|
|
226 /* Submenu not found */
|
|
227 RETURN_UNGCPRO (Qnil);
|
|
228
|
|
229 descend:
|
|
230 /* Prepare for the next iteration */
|
|
231 gui_item_init (gui_item);
|
|
232 }
|
|
233
|
|
234 /* We have successfully descended down the end of the path */
|
|
235 UNGCPRO;
|
|
236 return desc;
|
|
237 }
|
|
238
|
|
239 DEFUN ("popup-menu", Fpopup_menu, 1, 2, 0, /*
|
444
|
240 Pop up the menu described by MENU-DESCRIPTION.
|
428
|
241 A menu description is a list of menu items, strings, and submenus.
|
|
242
|
|
243 The first element of a menu must be a string, which is the name of the menu.
|
|
244 This is the string that will be displayed in the parent menu, if any. For
|
|
245 toplevel menus, it is ignored. This string is not displayed in the menu
|
|
246 itself.
|
|
247
|
|
248 If an element of a menu is a string, then that string will be presented in
|
|
249 the menu as unselectable text.
|
|
250
|
|
251 If an element of a menu is a string consisting solely of hyphens, then that
|
|
252 item will be presented as a solid horizontal line.
|
|
253
|
|
254 If an element of a menu is a list, it is treated as a submenu. The name of
|
|
255 that submenu (the first element in the list) will be used as the name of the
|
|
256 item representing this menu on the parent.
|
|
257
|
|
258 Otherwise, the element must be a vector, which describes a menu item.
|
|
259 A menu item can have any of the following forms:
|
|
260
|
|
261 [ "name" callback <active-p> ]
|
|
262 [ "name" callback <active-p> <suffix> ]
|
|
263 [ "name" callback :<keyword> <value> :<keyword> <value> ... ]
|
|
264
|
|
265 The name is the string to display on the menu; it is filtered through the
|
|
266 resource database, so it is possible for resources to override what string
|
|
267 is actually displayed.
|
|
268
|
|
269 If the `callback' of a menu item is a symbol, then it must name a command.
|
|
270 It will be invoked with `call-interactively'. If it is a list, then it is
|
|
271 evaluated with `eval'.
|
|
272
|
|
273 The possible keywords are this:
|
|
274
|
|
275 :active <form> Same as <active-p> in the first two forms: the
|
|
276 expression is evaluated just before the menu is
|
|
277 displayed, and the menu will be selectable only if
|
|
278 the result is non-nil.
|
|
279
|
|
280 :suffix <form> Same as <suffix> in the second form: the expression
|
|
281 is evaluated just before the menu is displayed and
|
|
282 resulting string is appended to the displayed name,
|
|
283 providing a convenient way of adding the name of a
|
|
284 command's ``argument'' to the menu, like
|
|
285 ``Kill Buffer NAME''.
|
|
286
|
|
287 :keys "string" Normally, the keyboard equivalents of commands in
|
|
288 menus are displayed when the `callback' is a symbol.
|
|
289 This can be used to specify keys for more complex menu
|
|
290 items. It is passed through `substitute-command-keys'
|
|
291 first.
|
|
292
|
|
293 :style <style> Specifies what kind of object this menu item is:
|
|
294
|
|
295 nil A normal menu item.
|
|
296 toggle A toggle button.
|
|
297 radio A radio button.
|
|
298
|
|
299 The only difference between toggle and radio buttons is
|
|
300 how they are displayed. But for consistency, a toggle
|
|
301 button should be used when there is one option whose
|
|
302 value can be turned on or off, and radio buttons should
|
|
303 be used when there is a set of mutually exclusive
|
|
304 options. When using a group of radio buttons, you
|
|
305 should arrange for no more than one to be marked as
|
|
306 selected at a time.
|
|
307
|
|
308 :selected <form> Meaningful only when STYLE is `toggle' or `radio'.
|
|
309 This specifies whether the button will be in the
|
|
310 selected or unselected state.
|
|
311
|
|
312 For example:
|
|
313
|
|
314 [ "Save As..." write-file t ]
|
|
315 [ "Revert Buffer" revert-buffer (buffer-modified-p) ]
|
|
316 [ "Read Only" toggle-read-only :style toggle :selected buffer-read-only ]
|
|
317
|
|
318 See menubar.el for many more examples.
|
|
319 */
|
444
|
320 (menu_description, event))
|
428
|
321 {
|
444
|
322 struct frame *f = decode_frame (Qnil);
|
|
323 MAYBE_FRAMEMETH (f, popup_menu, (menu_description, event));
|
428
|
324 return Qnil;
|
|
325 }
|
|
326
|
|
327 DEFUN ("normalize-menu-item-name", Fnormalize_menu_item_name, 1, 2, 0, /*
|
|
328 Convert a menu item name string into normal form, and return the new string.
|
|
329 Menu item names should be converted to normal form before being compared.
|
442
|
330 This removes %_'s (accelerator indications) and converts %% to %.
|
428
|
331 */
|
|
332 (name, buffer))
|
|
333 {
|
|
334 struct buffer *buf = decode_buffer (buffer, 0);
|
|
335 Charcount end;
|
|
336 int i;
|
867
|
337 Ibyte *name_data;
|
|
338 Ibyte *string_result;
|
|
339 Ibyte *string_result_ptr;
|
|
340 Ichar elt;
|
428
|
341 int expecting_underscore = 0;
|
|
342
|
|
343 CHECK_STRING (name);
|
|
344
|
826
|
345 end = string_char_length (name);
|
793
|
346 name_data = XSTRING_DATA (name);
|
428
|
347
|
867
|
348 string_result = (Ibyte *) ALLOCA (end * MAX_ICHAR_LEN);
|
428
|
349 string_result_ptr = string_result;
|
|
350 for (i = 0; i < end; i++)
|
|
351 {
|
867
|
352 elt = itext_ichar (name_data);
|
428
|
353 elt = DOWNCASE (buf, elt);
|
|
354 if (expecting_underscore)
|
|
355 {
|
|
356 expecting_underscore = 0;
|
|
357 switch (elt)
|
|
358 {
|
|
359 case '%':
|
|
360 /* Allow `%%' to mean `%'. */
|
867
|
361 string_result_ptr += set_itext_ichar (string_result_ptr, '%');
|
428
|
362 break;
|
|
363 case '_':
|
|
364 break;
|
|
365 default:
|
867
|
366 string_result_ptr += set_itext_ichar (string_result_ptr, '%');
|
|
367 string_result_ptr += set_itext_ichar (string_result_ptr, elt);
|
428
|
368 }
|
|
369 }
|
|
370 else if (elt == '%')
|
|
371 expecting_underscore = 1;
|
|
372 else
|
867
|
373 string_result_ptr += set_itext_ichar (string_result_ptr, elt);
|
|
374 INC_IBYTEPTR (name_data);
|
428
|
375 }
|
|
376
|
442
|
377 if (string_result_ptr - string_result == XSTRING_LENGTH (name)
|
|
378 && !memcmp (string_result, XSTRING_DATA (name), XSTRING_LENGTH (name)))
|
|
379 return name;
|
|
380
|
428
|
381 return make_string (string_result, string_result_ptr - string_result);
|
|
382 }
|
|
383
|
|
384 void
|
|
385 syms_of_menubar (void)
|
|
386 {
|
563
|
387 DEFSYMBOL (Qcurrent_menubar);
|
442
|
388
|
563
|
389 DEFSYMBOL (Qmenu_force);
|
|
390 DEFSYMBOL (Qmenu_fallback);
|
442
|
391
|
563
|
392 DEFSYMBOL (Qmenu_quit);
|
|
393 DEFSYMBOL (Qmenu_up);
|
|
394 DEFSYMBOL (Qmenu_down);
|
|
395 DEFSYMBOL (Qmenu_left);
|
|
396 DEFSYMBOL (Qmenu_right);
|
|
397 DEFSYMBOL (Qmenu_select);
|
|
398 DEFSYMBOL (Qmenu_escape);
|
442
|
399
|
428
|
400 DEFSUBR (Fpopup_menu);
|
|
401 DEFSUBR (Fnormalize_menu_item_name);
|
|
402 DEFSUBR (Fmenu_find_real_submenu);
|
|
403 }
|
|
404
|
|
405 void
|
|
406 vars_of_menubar (void)
|
|
407 {
|
440
|
408 /* put in Vblank_menubar a menubar value which has no visible
|
|
409 * items. This is a bit tricky due to various quirks. We
|
|
410 * could use '(["" nil nil]), but this is apparently equivalent
|
|
411 * to '(nil), and a new frame created with this menubar will
|
|
412 * get a vertically-squished menubar. If we use " " as the
|
|
413 * button title instead of "", we get an etched button border.
|
|
414 * So we use
|
|
415 * '(("No active menubar" ["" nil nil]))
|
|
416 * which creates a menu whose title is "No active menubar",
|
|
417 * and this works fine.
|
|
418 */
|
428
|
419
|
771
|
420 Vblank_menubar = list1 (list2 (build_msg_string ("No active menubar"),
|
440
|
421 vector3 (build_string (""), Qnil, Qnil)));
|
|
422 staticpro (&Vblank_menubar);
|
428
|
423
|
|
424 DEFVAR_BOOL ("popup-menu-titles", &popup_menu_titles /*
|
|
425 If true, popup menus will have title bars at the top.
|
|
426 */ );
|
|
427 popup_menu_titles = 1;
|
|
428
|
|
429 /* #### Replace current menubar with a specifier. */
|
|
430
|
|
431 /* All C code must access the menubar via Qcurrent_menubar
|
|
432 because it can be buffer-local. Note that Vcurrent_menubar
|
|
433 doesn't need to exist at all, except for the magic function. */
|
|
434
|
|
435 DEFVAR_LISP_MAGIC ("current-menubar", &Vcurrent_menubar /*
|
|
436 The current menubar. This may be buffer-local.
|
|
437
|
|
438 When the menubar is changed, the function `set-menubar-dirty-flag' has to
|
|
439 be called for the menubar to be updated on the frame. See `set-menubar'
|
|
440 and `set-buffer-menubar'.
|
|
441
|
|
442 A menubar is a list of menus and menu-items.
|
|
443 A menu is a list of menu items, keyword-value pairs, strings, and submenus.
|
|
444
|
|
445 The first element of a menu must be a string, which is the name of the menu.
|
|
446 This is the string that will be displayed in the parent menu, if any. For
|
|
447 toplevel menus, it is ignored. This string is not displayed in the menu
|
|
448 itself.
|
|
449
|
442
|
450 Menu accelerators can be indicated in the string by putting the
|
|
451 sequence "%_" before the character corresponding to the key that will
|
|
452 invoke the menu or menu item. Uppercase and lowercase accelerators
|
|
453 are equivalent. The sequence "%%" is also special, and is translated
|
|
454 into a single %.
|
|
455
|
|
456 If no menu accelerator is present in the string, XEmacs will act as if
|
|
457 the first character has been tagged as an accelerator.
|
|
458
|
|
459 Immediately following the name string of the menu, various optional
|
|
460 keyword-value pairs are permitted: currently, :filter, :active, :included,
|
|
461 and :config. (See below.)
|
428
|
462
|
|
463 If an element of a menu (or menubar) is a string, then that string will be
|
|
464 presented as unselectable text.
|
|
465
|
|
466 If an element of a menu is a string consisting solely of hyphens, then that
|
|
467 item will be presented as a solid horizontal line.
|
|
468
|
442
|
469 If an element of a menu is a string beginning with "--:", it will be
|
|
470 presented as a line whose appearance is controlled by the rest of the
|
|
471 text in the string. The allowed line specs are system-dependent, and
|
|
472 currently work only under X Windows (with Lucid and Motif menubars);
|
|
473 otherwise, a solid horizontal line is presented, as if the string were
|
|
474 all hyphens.
|
|
475
|
|
476 The possibilities are:
|
|
477
|
|
478 "--:singleLine"
|
|
479 "--:doubleLine"
|
|
480 "--:singleDashedLine"
|
|
481 "--:doubleDashedLine"
|
|
482 "--:noLine"
|
|
483 "--:shadowEtchedIn"
|
|
484 "--:shadowEtchedOut"
|
|
485 "--:shadowEtchedInDash"
|
|
486 "--:shadowEtchedOutDash"
|
|
487 "--:shadowDoubleEtchedIn" (Lucid menubars only)
|
|
488 "--:shadowDoubleEtchedOut" (Lucid menubars only)
|
|
489 "--:shadowDoubleEtchedInDash" (Lucid menubars only)
|
|
490 "--:shadowDoubleEtchedOutDash" (Lucid menubars only)
|
|
491
|
428
|
492 If an element of a menu is a list, it is treated as a submenu. The name of
|
|
493 that submenu (the first element in the list) will be used as the name of the
|
|
494 item representing this menu on the parent.
|
|
495
|
|
496 If an element of a menubar is `nil', then it is used to represent the
|
|
497 division between the set of menubar-items which are flushleft and those
|
|
498 which are flushright.
|
|
499
|
|
500 Otherwise, the element must be a vector, which describes a menu item.
|
442
|
501 A menu item is of the following form:
|
|
502
|
|
503 [ "name" callback :<keyword> <value> :<keyword> <value> ... ]
|
|
504
|
|
505 The following forms are also accepted for compatibility, but deprecated:
|
428
|
506
|
|
507 [ "name" callback <active-p> ]
|
|
508 [ "name" callback <active-p> <suffix> ]
|
|
509
|
|
510 The name is the string to display on the menu; it is filtered through the
|
|
511 resource database, so it is possible for resources to override what string
|
442
|
512 is actually displayed. Menu accelerator indicators (the sequence `%_') are
|
|
513 also processed; see above. If the name is not a string, it will be
|
|
514 evaluated with `eval', and the result should be a string.
|
428
|
515
|
|
516 If the `callback' of a menu item is a symbol, then it must name a command.
|
|
517 It will be invoked with `call-interactively'. If it is a list, then it is
|
|
518 evaluated with `eval'.
|
|
519
|
442
|
520 In the deprecated forms, <active-p> is equivalent to using the :active
|
|
521 keyword, and <suffix> is equivalent to using the :suffix keyword.
|
428
|
522
|
442
|
523 The possible keywords are:
|
|
524
|
|
525 :active <form> The expression is evaluated just before the menu is
|
428
|
526 displayed, and the menu will be selectable only if
|
|
527 the result is non-nil.
|
|
528
|
442
|
529 :suffix <form> The expression is evaluated just before the menu is
|
|
530 displayed and the resulting string is appended to
|
|
531 the displayed name, providing a convenient way of
|
|
532 adding the name of a command's ``argument'' to the
|
|
533 menu, like ``Kill Buffer NAME''.
|
428
|
534
|
|
535 :keys "string" Normally, the keyboard equivalents of commands in
|
|
536 menus are displayed when the `callback' is a symbol.
|
|
537 This can be used to specify keys for more complex menu
|
|
538 items. It is passed through `substitute-command-keys'
|
|
539 first.
|
|
540
|
|
541 :style <style> Specifies what kind of object this menu item is:
|
|
542
|
|
543 nil A normal menu item.
|
|
544 toggle A toggle button.
|
|
545 radio A radio button.
|
|
546 button A menubar button.
|
|
547
|
|
548 The only difference between toggle and radio buttons is
|
|
549 how they are displayed. But for consistency, a toggle
|
|
550 button should be used when there is one option whose
|
|
551 value can be turned on or off, and radio buttons should
|
|
552 be used when there is a set of mutually exclusive
|
|
553 options. When using a group of radio buttons, you
|
|
554 should arrange for no more than one to be marked as
|
|
555 selected at a time.
|
|
556
|
|
557 :selected <form> Meaningful only when STYLE is `toggle', `radio' or
|
|
558 `button'. This specifies whether the button will be in
|
|
559 the selected or unselected state.
|
|
560
|
|
561 :included <form> This can be used to control the visibility of a menu or
|
|
562 menu item. The form is evaluated and the menu or menu
|
|
563 item is only displayed if the result is non-nil.
|
|
564
|
|
565 :config <symbol> This is an efficient shorthand for
|
|
566 :included (memq symbol menubar-configuration)
|
|
567 See the variable `menubar-configuration'.
|
|
568
|
442
|
569 :filter <function> A menu filter can only be used at the beginning of a
|
|
570 submenu description (i.e. not in a menu item itself).
|
|
571 (Remember that most of the keywords can take evaluated
|
|
572 expressions as well as constants.) The filter is used to
|
|
573 incrementally create a submenu only when it is selected
|
|
574 by the user and not every time the menubar is activated.
|
|
575 The filter function is passed the list of menu items in
|
|
576 the submenu and must return the modified list to be
|
|
577 actually used. The filter MUST NOT destructively modify
|
|
578 the list of menu items passed to it. It is called only
|
|
579 when the menu is about to be displayed, so other menus
|
|
580 may already be displayed. Vile and terrible things will
|
|
581 happen if a menu filter function changes the current
|
|
582 buffer, window, or frame. It also should not raise,
|
|
583 lower, or iconify any frames. Basically, the filter
|
|
584 function should have no side-effects.
|
428
|
585
|
|
586 :key-sequence keys Used in FSF Emacs as an hint to an equivalent keybinding.
|
442
|
587 Ignored by XEmacs for easymenu.el compatibility.
|
|
588 (XEmacs computes this information automatically.)
|
428
|
589
|
|
590 For example:
|
|
591
|
442
|
592 ("%_File"
|
428
|
593 :filter file-menu-filter ; file-menu-filter is a function that takes
|
|
594 ; one argument (a list of menu items) and
|
|
595 ; returns a list of menu items
|
442
|
596 [ "Save %_As..." write-file t ]
|
|
597 [ "%_Revert Buffer" revert-buffer (buffer-modified-p) ]
|
|
598 [ "R%_ead Only" toggle-read-only :style toggle
|
428
|
599 :selected buffer-read-only ]
|
|
600 )
|
|
601
|
442
|
602 See menubar-items.el for many more examples.
|
428
|
603
|
|
604 After the menubar is clicked upon, but before any menus are popped up,
|
|
605 the functions on the `activate-menubar-hook' are invoked to make top-level
|
|
606 changes to the menus and menubar. Note, however, that the use of menu
|
|
607 filters (using the :filter keyword) is usually a more efficient way to
|
442
|
608 dynamically alter or sensitize menus. */, menubar_variable_changed);
|
428
|
609
|
|
610 Vcurrent_menubar = Qnil;
|
|
611
|
|
612 DEFVAR_LISP ("activate-menubar-hook", &Vactivate_menubar_hook /*
|
|
613 Function or functions called before a menubar menu is pulled down.
|
|
614 These functions are called with no arguments, and should interrogate and
|
|
615 modify the value of `current-menubar' as desired.
|
|
616
|
|
617 The functions on this hook are invoked after the mouse goes down, but before
|
|
618 the menu is mapped, and may be used to activate, deactivate, add, or delete
|
|
619 items from the menus. However, it is probably the case that using a :filter
|
|
620 keyword in a submenu would be a more efficient way of updating menus. See
|
|
621 the documentation of `current-menubar'.
|
|
622
|
|
623 These functions may return the symbol `t' to assert that they have made
|
|
624 no changes to the menubar. If any other value is returned, the menubar is
|
|
625 recomputed. If `t' is returned but the menubar has been changed, then the
|
|
626 changes may not show up right away. Returning `nil' when the menubar has
|
|
627 not changed is not so bad; more computation will be done, but redisplay of
|
|
628 the menubar will still be performed optimally.
|
|
629 */ );
|
|
630 Vactivate_menubar_hook = Qnil;
|
563
|
631 DEFSYMBOL (Qactivate_menubar_hook);
|
428
|
632
|
|
633 DEFVAR_BOOL ("menubar-show-keybindings", &menubar_show_keybindings /*
|
|
634 If true, the menubar will display keyboard equivalents.
|
|
635 If false, only the command names will be displayed.
|
|
636 */ );
|
|
637 menubar_show_keybindings = 1;
|
|
638
|
|
639 DEFVAR_LISP_MAGIC ("menubar-configuration", &Vmenubar_configuration /*
|
|
640 A list of symbols, against which the value of the :config tag for each
|
|
641 menubar item will be compared. If a menubar item has a :config tag, then
|
|
642 it is omitted from the menubar if that tag is not a member of the
|
|
643 `menubar-configuration' list.
|
|
644 */ , menubar_variable_changed);
|
|
645 Vmenubar_configuration = Qnil;
|
|
646
|
|
647 DEFVAR_LISP ("menubar-pointer-glyph", &Vmenubar_pointer_glyph /*
|
|
648 *The shape of the mouse-pointer when over the menubar.
|
|
649 This is a glyph; use `set-glyph-image' to change it.
|
|
650 If unspecified in a particular domain, the window-system-provided
|
|
651 default pointer is used.
|
|
652 */ );
|
|
653
|
442
|
654 DEFVAR_LISP ("menu-accelerator-prefix", &Vmenu_accelerator_prefix /*
|
|
655 Prefix key(s) that must be typed before menu accelerators will be activated.
|
|
656 Set this to a value acceptable by define-key.
|
|
657
|
|
658 NOTE: This currently only has any effect under X Windows.
|
|
659 */ );
|
|
660 Vmenu_accelerator_prefix = Qnil;
|
|
661
|
|
662 DEFVAR_LISP ("menu-accelerator-modifiers", &Vmenu_accelerator_modifiers /*
|
|
663 Modifier keys which must be pressed to get to the top level menu accelerators.
|
|
664 This is a list of modifier key symbols. All modifier keys must be held down
|
|
665 while a valid menu accelerator key is pressed in order for the top level
|
|
666 menu to become active.
|
|
667
|
|
668 NOTE: This currently only has any effect under X Windows.
|
|
669
|
|
670 See also menu-accelerator-enabled and menu-accelerator-prefix.
|
|
671 */ );
|
|
672 Vmenu_accelerator_modifiers = list1 (Qmeta);
|
|
673
|
|
674 DEFVAR_LISP ("menu-accelerator-enabled", &Vmenu_accelerator_enabled /*
|
|
675 Whether menu accelerator keys can cause the menubar to become active.
|
|
676 If 'menu-force or 'menu-fallback, then menu accelerator keys can
|
|
677 be used to activate the top level menu. Once the menubar becomes active, the
|
|
678 accelerator keys can be used regardless of the value of this variable.
|
|
679
|
|
680 menu-force is used to indicate that the menu accelerator key takes
|
|
681 precedence over bindings in the current keymap(s). menu-fallback means
|
|
682 that bindings in the current keymap take precedence over menu accelerator keys.
|
|
683 Thus a top level menu with an accelerator of "T" would be activated on a
|
|
684 keypress of Meta-t if menu-accelerator-enabled is menu-force.
|
|
685 However, if menu-accelerator-enabled is menu-fallback, then
|
|
686 Meta-t will not activate the menubar and will instead run the function
|
|
687 transpose-words, to which it is normally bound.
|
|
688
|
|
689 See also menu-accelerator-modifiers and menu-accelerator-prefix.
|
|
690 */ );
|
|
691 Vmenu_accelerator_enabled = Qnil;
|
|
692
|
|
693 DEFVAR_LISP ("menu-accelerator-map", &Vmenu_accelerator_map /*
|
|
694 Keymap for use when the menubar is active.
|
|
695 The actions menu-quit, menu-up, menu-down, menu-left, menu-right,
|
|
696 menu-select and menu-escape can be mapped to keys in this map.
|
|
697 NOTE: This currently only has any effect under X Windows.
|
|
698
|
|
699 menu-quit Immediately deactivate the menubar and any open submenus without
|
|
700 selecting an item.
|
|
701 menu-up Move the menu cursor up one row in the current menu. If the
|
|
702 move extends past the top of the menu, wrap around to the bottom.
|
|
703 menu-down Move the menu cursor down one row in the current menu. If the
|
|
704 move extends past the bottom of the menu, wrap around to the top.
|
|
705 If executed while the cursor is in the top level menu, move down
|
|
706 into the selected menu.
|
|
707 menu-left Move the cursor from a submenu into the parent menu. If executed
|
|
708 while the cursor is in the top level menu, move the cursor to the
|
|
709 left. If the move extends past the left edge of the menu, wrap
|
|
710 around to the right edge.
|
|
711 menu-right Move the cursor into a submenu. If the cursor is located in the
|
|
712 top level menu or is not currently on a submenu heading, then move
|
|
713 the cursor to the next top level menu entry. If the move extends
|
|
714 past the right edge of the menu, wrap around to the left edge.
|
|
715 menu-select Activate the item under the cursor. If the cursor is located on
|
|
716 a submenu heading, then move the cursor into the submenu.
|
|
717 menu-escape Pop up to the next level of menus. Moves from a submenu into its
|
|
718 parent menu. From the top level menu, this deactivates the
|
|
719 menubar.
|
|
720
|
|
721 This keymap can also contain normal key-command bindings, in which case the
|
|
722 menubar is deactivated and the corresponding command is executed.
|
|
723
|
|
724 The action bindings used by the menu accelerator code are designed to mimic
|
|
725 the actions of menu traversal keys in a commonly used PC operating system.
|
|
726 */ );
|
|
727
|
428
|
728 Fprovide (intern ("menubar"));
|
464
|
729 Fprovide (intern ("menu-accelerator-support"));
|
428
|
730 }
|
|
731
|
|
732 void
|
|
733 specifier_vars_of_menubar (void)
|
|
734 {
|
|
735 DEFVAR_SPECIFIER ("menubar-visible-p", &Vmenubar_visible_p /*
|
|
736 *Whether the menubar is visible.
|
|
737 This is a specifier; use `set-specifier' to change it.
|
|
738 */ );
|
|
739 Vmenubar_visible_p = Fmake_specifier (Qboolean);
|
|
740
|
|
741 set_specifier_fallback (Vmenubar_visible_p, list1 (Fcons (Qnil, Qt)));
|
|
742 set_specifier_caching (Vmenubar_visible_p,
|
438
|
743 offsetof (struct window, menubar_visible_p),
|
428
|
744 menubar_visible_p_changed,
|
438
|
745 offsetof (struct frame, menubar_visible_p),
|
444
|
746 menubar_visible_p_changed_in_frame, 0);
|
428
|
747 }
|
|
748
|
|
749 void
|
|
750 complex_vars_of_menubar (void)
|
|
751 {
|
|
752 Vmenubar_pointer_glyph = Fmake_glyph_internal (Qpointer);
|
442
|
753
|
|
754 Vmenu_accelerator_map = Fmake_keymap (Qnil);
|
428
|
755 }
|