428
|
1 /* Implements an elisp-programmable menubar -- X interface.
|
|
2 Copyright (C) 1993, 1994 Free Software Foundation, Inc.
|
|
3 Copyright (C) 1995 Tinker Systems and INS Engineering Corp.
|
1261
|
4 Copyright (C) 2000, 2001, 2002, 2003 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 /* This file Mule-ized by Ben Wing, 7-8-00. */
|
|
26
|
|
27 /* Authorship:
|
|
28
|
|
29 Created 16-dec-91 by Jamie Zawinski.
|
|
30 Menu filters and many other keywords added by Stig for 19.12.
|
|
31 Original device-abstraction work and GC cleanup work by Ben Wing for 19.13.
|
|
32 Menu accelerators c. 1997? by ??. Moved here from event-stream.c.
|
|
33 Other work post-1996 by ??.
|
|
34 */
|
428
|
35
|
|
36 #include <config.h>
|
|
37 #include "lisp.h"
|
|
38
|
|
39 #include "buffer.h"
|
|
40 #include "commands.h" /* zmacs_regions */
|
872
|
41 #include "device-impl.h"
|
428
|
42 #include "events.h"
|
872
|
43 #include "frame-impl.h"
|
442
|
44 #include "gui.h"
|
|
45 #include "keymap.h"
|
|
46 #include "menubar.h"
|
428
|
47 #include "opaque.h"
|
872
|
48 #include "window-impl.h"
|
428
|
49
|
872
|
50 #include "console-x-impl.h"
|
800
|
51
|
|
52 #include "EmacsFrame.h"
|
|
53 #include "../lwlib/lwlib.h"
|
|
54
|
428
|
55 static int set_frame_menubar (struct frame *f,
|
|
56 int deep_p,
|
|
57 int first_time_p);
|
|
58
|
|
59 #define MENUBAR_TYPE 0
|
|
60 #define SUBMENU_TYPE 1
|
|
61 #define POPUP_TYPE 2
|
|
62
|
|
63
|
|
64 /* Converting Lisp menu tree descriptions to lwlib's `widget_value' form.
|
|
65
|
|
66 menu_item_descriptor_to_widget_value() converts a lisp description of a
|
|
67 menubar into a tree of widget_value structures. It allocates widget_values
|
|
68 with malloc_widget_value() and allocates other storage only for the `key'
|
|
69 slot. All other slots are filled with pointers to Lisp_String data. We
|
|
70 allocate a widget_value description of the menu or menubar, and hand it to
|
|
71 lwlib, which then makes a copy of it, which it manages internally. We then
|
|
72 immediately free our widget_value tree; it will not be referenced again.
|
|
73
|
|
74 Incremental menu construction callbacks operate just a bit differently.
|
|
75 They allocate widget_values and call replace_widget_value_tree() to tell
|
|
76 lwlib to destructively modify the incremental stub (subtree) of its
|
|
77 separate widget_value tree.
|
|
78
|
|
79 This function is highly recursive (it follows the menu trees) and may call
|
|
80 eval. The reason we keep pointers to lisp string data instead of copying
|
|
81 it and freeing it later is to avoid the speed penalty that would entail
|
|
82 (since this needs to be fast, in the simple cases at least). (The reason
|
|
83 we malloc/free the keys slot is because there's not a lisp string around
|
|
84 for us to use in that case.)
|
|
85
|
|
86 Since we keep pointers to lisp strings, and we call eval, we could lose if
|
|
87 GC relocates (or frees) those strings. It's not easy to gc protect the
|
|
88 strings because of the recursive nature of this function, and the fact that
|
|
89 it returns a data structure that gets freed later. So... we do the
|
|
90 sleaziest thing possible and inhibit GC for the duration. This is probably
|
|
91 not a big deal...
|
|
92
|
|
93 We do not have to worry about the pointers to Lisp_String data after
|
|
94 this function successfully finishes. lwlib copies all such data with
|
|
95 strdup(). */
|
|
96
|
|
97 static widget_value *
|
|
98 menu_item_descriptor_to_widget_value_1 (Lisp_Object desc,
|
|
99 int menu_type, int deep_p,
|
|
100 int filter_p,
|
|
101 int depth)
|
|
102 {
|
|
103 /* This function cannot GC.
|
|
104 It is only called from menu_item_descriptor_to_widget_value, which
|
|
105 prohibits GC. */
|
|
106 int menubar_root_p = (menu_type == MENUBAR_TYPE && depth == 0);
|
|
107 int count = specpdl_depth ();
|
|
108 int partition_seen = 0;
|
438
|
109 widget_value *wv = xmalloc_widget_value ();
|
|
110 Lisp_Object wv_closure = make_opaque_ptr (wv);
|
428
|
111
|
|
112 record_unwind_protect (widget_value_unwind, wv_closure);
|
|
113
|
|
114 if (STRINGP (desc))
|
|
115 {
|
867
|
116 Ibyte *string_chars = XSTRING_DATA (desc);
|
428
|
117 wv->type = (separator_string_p (string_chars) ? SEPARATOR_TYPE :
|
|
118 TEXT_TYPE);
|
|
119 if (wv->type == SEPARATOR_TYPE)
|
|
120 {
|
442
|
121 wv->value = menu_separator_style_and_to_external (string_chars);
|
428
|
122 }
|
|
123 else
|
|
124 {
|
442
|
125 LISP_STRING_TO_EXTERNAL_MALLOC (desc, wv->name, Qlwlib_encoding);
|
428
|
126 wv->enabled = 1;
|
|
127 /* dverna Dec. 98: command_builder_operate_menu_accelerator will
|
|
128 manipulate the accel as a Lisp_Object if the widget has a name.
|
|
129 Since simple labels have a name, but no accel, we *must* set it
|
|
130 to nil */
|
|
131 wv->accel = LISP_TO_VOID (Qnil);
|
|
132 }
|
|
133 }
|
|
134 else if (VECTORP (desc))
|
|
135 {
|
|
136 Lisp_Object gui_item = gui_parse_item_keywords (desc);
|
442
|
137 if (!button_item_to_widget_value (Qmenubar,
|
|
138 gui_item, wv, 1,
|
428
|
139 (menu_type == MENUBAR_TYPE
|
442
|
140 && depth <= 1), 1, 1))
|
428
|
141 {
|
|
142 /* :included form was nil */
|
|
143 wv = NULL;
|
|
144 goto menu_item_done;
|
|
145 }
|
|
146 }
|
|
147 else if (CONSP (desc))
|
|
148 {
|
|
149 Lisp_Object incremental_data = desc;
|
|
150 widget_value *prev = 0;
|
|
151
|
|
152 if (STRINGP (XCAR (desc)))
|
|
153 {
|
|
154 Lisp_Object key, val;
|
|
155 Lisp_Object include_p = Qnil, hook_fn = Qnil, config_tag = Qnil;
|
|
156 Lisp_Object active_p = Qt;
|
|
157 Lisp_Object accel;
|
|
158 int included_spec = 0;
|
|
159 int active_spec = 0;
|
|
160 wv->type = CASCADE_TYPE;
|
|
161 wv->enabled = 1;
|
442
|
162 wv->name = add_accel_and_to_external (XCAR (desc));
|
428
|
163
|
442
|
164 accel = gui_name_accelerator (XCAR (desc));
|
428
|
165 wv->accel = LISP_TO_VOID (accel);
|
|
166
|
|
167 desc = Fcdr (desc);
|
|
168
|
|
169 while (key = Fcar (desc), KEYWORDP (key))
|
|
170 {
|
|
171 Lisp_Object cascade = desc;
|
|
172 desc = Fcdr (desc);
|
|
173 if (NILP (desc))
|
563
|
174 sferror ("Keyword in menu lacks a value", cascade);
|
428
|
175 val = Fcar (desc);
|
|
176 desc = Fcdr (desc);
|
|
177 if (EQ (key, Q_included))
|
|
178 include_p = val, included_spec = 1;
|
|
179 else if (EQ (key, Q_config))
|
|
180 config_tag = val;
|
|
181 else if (EQ (key, Q_filter))
|
|
182 hook_fn = val;
|
|
183 else if (EQ (key, Q_active))
|
|
184 active_p = val, active_spec = 1;
|
|
185 else if (EQ (key, Q_accelerator))
|
|
186 {
|
|
187 if ( SYMBOLP (val)
|
|
188 || CHARP (val))
|
|
189 wv->accel = LISP_TO_VOID (val);
|
|
190 else
|
563
|
191 invalid_argument ("bad keyboard accelerator", val);
|
428
|
192 }
|
|
193 else if (EQ (key, Q_label))
|
|
194 {
|
|
195 /* implement in 21.2 */
|
|
196 }
|
|
197 else
|
563
|
198 invalid_argument ("Unknown menu cascade keyword", cascade);
|
428
|
199 }
|
|
200
|
|
201 if ((!NILP (config_tag)
|
|
202 && NILP (Fmemq (config_tag, Vmenubar_configuration)))
|
|
203 || (included_spec && NILP (Feval (include_p))))
|
|
204 {
|
|
205 wv = NULL;
|
|
206 goto menu_item_done;
|
|
207 }
|
|
208
|
|
209 if (active_spec)
|
|
210 active_p = Feval (active_p);
|
|
211
|
|
212 if (!NILP (hook_fn) && !NILP (active_p))
|
|
213 {
|
|
214 #if defined LWLIB_MENUBARS_LUCID || defined LWLIB_MENUBARS_MOTIF
|
|
215 if (filter_p || depth == 0)
|
|
216 {
|
|
217 #endif
|
853
|
218 desc = call1 (hook_fn, desc);
|
428
|
219 if (UNBOUNDP (desc))
|
|
220 desc = Qnil;
|
|
221 #if defined LWLIB_MENUBARS_LUCID || defined LWLIB_MENUBARS_MOTIF
|
|
222 }
|
|
223 else
|
|
224 {
|
|
225 widget_value *incr_wv = xmalloc_widget_value ();
|
|
226 wv->contents = incr_wv;
|
|
227 incr_wv->type = INCREMENTAL_TYPE;
|
|
228 incr_wv->enabled = 1;
|
|
229 incr_wv->name = wv->name;
|
436
|
230 incr_wv->name = xstrdup (wv->name);
|
428
|
231 /* This is automatically GC protected through
|
|
232 the call to lw_map_widget_values(); no need
|
|
233 to worry. */
|
|
234 incr_wv->call_data = LISP_TO_VOID (incremental_data);
|
|
235 goto menu_item_done;
|
|
236 }
|
|
237 #endif /* LWLIB_MENUBARS_LUCID || LWLIB_MENUBARS_MOTIF */
|
|
238 }
|
|
239 if (menu_type == POPUP_TYPE && popup_menu_titles && depth == 0)
|
|
240 {
|
|
241 /* Simply prepend three more widget values to the contents of
|
|
242 the menu: a label, and two separators (to get a double
|
|
243 line). */
|
|
244 widget_value *title_wv = xmalloc_widget_value ();
|
|
245 widget_value *sep_wv = xmalloc_widget_value ();
|
|
246 title_wv->type = TEXT_TYPE;
|
436
|
247 title_wv->name = xstrdup (wv->name);
|
428
|
248 title_wv->enabled = 1;
|
|
249 title_wv->next = sep_wv;
|
|
250 sep_wv->type = SEPARATOR_TYPE;
|
867
|
251 sep_wv->value = menu_separator_style_and_to_external ((Ibyte *) "==");
|
428
|
252 sep_wv->next = 0;
|
|
253
|
|
254 wv->contents = title_wv;
|
|
255 prev = sep_wv;
|
|
256 }
|
|
257 wv->enabled = ! NILP (active_p);
|
|
258 if (deep_p && !wv->enabled && !NILP (desc))
|
|
259 {
|
|
260 widget_value *dummy;
|
|
261 /* Add a fake entry so the menus show up */
|
|
262 wv->contents = dummy = xmalloc_widget_value ();
|
436
|
263 dummy->name = xstrdup ("(inactive)");
|
428
|
264 dummy->accel = LISP_TO_VOID (Qnil);
|
|
265 dummy->enabled = 0;
|
|
266 dummy->selected = 0;
|
|
267 dummy->value = NULL;
|
|
268 dummy->type = BUTTON_TYPE;
|
|
269 dummy->call_data = NULL;
|
|
270 dummy->next = NULL;
|
|
271
|
|
272 goto menu_item_done;
|
442
|
273 }
|
428
|
274
|
|
275 }
|
|
276 else if (menubar_root_p)
|
|
277 {
|
436
|
278 wv->name = xstrdup ("menubar");
|
428
|
279 wv->type = CASCADE_TYPE; /* Well, nothing else seems to fit and
|
|
280 this is ignored anyway... */
|
|
281 }
|
|
282 else
|
|
283 {
|
563
|
284 sferror ("Menu name (first element) must be a string", desc);
|
428
|
285 }
|
|
286
|
|
287 if (deep_p || menubar_root_p)
|
|
288 {
|
|
289 widget_value *next;
|
|
290 for (; !NILP (desc); desc = Fcdr (desc))
|
|
291 {
|
|
292 Lisp_Object child = Fcar (desc);
|
|
293 if (menubar_root_p && NILP (child)) /* the partition */
|
|
294 {
|
|
295 if (partition_seen)
|
563
|
296 sferror
|
442
|
297 ("More than one partition (nil) in menubar description",
|
|
298 desc);
|
428
|
299 partition_seen = 1;
|
|
300 next = xmalloc_widget_value ();
|
|
301 next->type = PUSHRIGHT_TYPE;
|
|
302 }
|
|
303 else
|
|
304 {
|
|
305 next = menu_item_descriptor_to_widget_value_1
|
|
306 (child, menu_type, deep_p, filter_p, depth + 1);
|
|
307 }
|
|
308 if (! next)
|
|
309 continue;
|
|
310 else if (prev)
|
|
311 prev->next = next;
|
|
312 else
|
|
313 wv->contents = next;
|
|
314 prev = next;
|
|
315 }
|
|
316 }
|
|
317 if (deep_p && !wv->contents)
|
|
318 wv = NULL;
|
|
319 }
|
|
320 else if (NILP (desc))
|
563
|
321 sferror ("nil may not appear in menu descriptions", desc);
|
428
|
322 else
|
563
|
323 sferror ("Unrecognized menu descriptor", desc);
|
428
|
324
|
442
|
325 menu_item_done:
|
428
|
326
|
|
327 if (wv)
|
|
328 {
|
|
329 /* Completed normally. Clear out the object that widget_value_unwind()
|
|
330 will be called with to tell it not to free the wv (as we are
|
|
331 returning it.) */
|
|
332 set_opaque_ptr (wv_closure, 0);
|
|
333 }
|
|
334
|
771
|
335 unbind_to (count);
|
428
|
336 return wv;
|
|
337 }
|
|
338
|
853
|
339 struct menu_item_descriptor_to_widget_value
|
|
340 {
|
|
341 Lisp_Object desc;
|
|
342 int menu_type, deep_p, filter_p;
|
|
343 widget_value *wv;
|
|
344 };
|
428
|
345
|
|
346 static Lisp_Object
|
853
|
347 protected_menu_item_descriptor_to_widget_value_1 (void *gack)
|
428
|
348 {
|
853
|
349 struct menu_item_descriptor_to_widget_value *midtwv =
|
|
350 (struct menu_item_descriptor_to_widget_value *) gack;
|
1918
|
351 int count = begin_gc_forbidden ();
|
|
352 /* Can't GC! */
|
|
353 midtwv->wv = menu_item_descriptor_to_widget_value_1 (midtwv->desc,
|
|
354 midtwv->menu_type,
|
|
355 midtwv->deep_p,
|
|
356 midtwv->filter_p,
|
|
357 0);
|
|
358 unbind_to (count);
|
442
|
359 return Qnil;
|
428
|
360 }
|
853
|
361
|
|
362 /* Inside of the pre_activate_callback, we absolutely need to protect
|
|
363 against errors, esp. but not exclusively in the filter code. (We do
|
|
364 other evalling, too.) We also need to reenable quit checking, which
|
|
365 was disabled by next_event_internal() so as to read C-g as an
|
|
366 event. */
|
428
|
367
|
853
|
368 static widget_value *
|
|
369 protected_menu_item_descriptor_to_widget_value (Lisp_Object desc,
|
|
370 int menu_type, int deep_p,
|
|
371 int filter_p)
|
428
|
372 {
|
853
|
373 struct menu_item_descriptor_to_widget_value midtwv;
|
1279
|
374 int depth = internal_bind_int (&in_menu_callback, 1);
|
|
375 Lisp_Object retval;
|
428
|
376
|
853
|
377 midtwv.desc = desc;
|
|
378 midtwv.menu_type = menu_type;
|
|
379 midtwv.deep_p = deep_p;
|
|
380 midtwv.filter_p = filter_p;
|
428
|
381
|
1279
|
382 retval = event_stream_protect_modal_loop
|
|
383 ("Error during menu callback",
|
|
384 protected_menu_item_descriptor_to_widget_value_1, &midtwv,
|
|
385 UNINHIBIT_QUIT);
|
|
386 unbind_to (depth);
|
|
387
|
|
388 if (UNBOUNDP (retval))
|
853
|
389 return 0;
|
|
390
|
|
391 return midtwv.wv;
|
428
|
392 }
|
853
|
393
|
1918
|
394 /* The two callers of menu_item_descriptor_to_widget_value may both run while
|
|
395 in redisplay. Some descriptor to widget value conversions call Feval, and
|
|
396 at least one calls QUIT. Hence, we have to establish protection here.. */
|
|
397
|
|
398 static widget_value *
|
|
399 menu_item_descriptor_to_widget_value (Lisp_Object desc,
|
|
400 int menu_type, /* if this is a menubar,
|
|
401 popup or sub menu */
|
|
402 int deep_p, /* */
|
|
403 int filter_p) /* if :filter forms
|
|
404 should run now */
|
|
405 {
|
|
406 struct menu_item_descriptor_to_widget_value midtwv;
|
|
407 Lisp_Object retval;
|
|
408
|
|
409 midtwv.desc = desc;
|
|
410 midtwv.menu_type = menu_type;
|
|
411 midtwv.deep_p = deep_p;
|
|
412 midtwv.filter_p = filter_p;
|
|
413
|
|
414 retval = call_trapping_problems
|
|
415 (Qevent, "Error during menu construction", 0, NULL,
|
|
416 protected_menu_item_descriptor_to_widget_value_1, &midtwv);
|
|
417
|
|
418 if (UNBOUNDP (retval))
|
|
419 return NULL;
|
|
420
|
|
421 return midtwv.wv;
|
|
422 }
|
|
423
|
428
|
424 /* The order in which callbacks are run is funny to say the least.
|
|
425 It's sometimes tricky to avoid running a callback twice, and to
|
|
426 avoid returning prematurely. So, this function returns true
|
|
427 if the menu's callbacks are no longer gc protected. So long
|
|
428 as we unprotect them before allowing other callbacks to run,
|
|
429 everything should be ok.
|
|
430
|
|
431 The pre_activate_callback() *IS* intentionally called multiple times.
|
|
432 If client_data == NULL, then it's being called before the menu is posted.
|
|
433 If client_data != NULL, then client_data is a (widget_value *) and
|
|
434 client_data->data is a Lisp_Object pointing to a lisp submenu description
|
|
435 that must be converted into widget_values. *client_data is destructively
|
|
436 modified.
|
|
437
|
|
438 #### Stig thinks that there may be a GC problem here due to the
|
|
439 fact that pre_activate_callback() is called multiple times, but I
|
|
440 think he's wrong.
|
|
441
|
|
442 */
|
|
443
|
|
444 static void
|
|
445 pre_activate_callback (Widget widget, LWLIB_ID id, XtPointer client_data)
|
|
446 {
|
|
447 /* This function can GC */
|
|
448 struct device *d = get_device_from_display (XtDisplay (widget));
|
|
449 struct frame *f = x_any_window_to_frame (d, XtWindow (widget));
|
|
450 Lisp_Object frame;
|
|
451
|
|
452 /* set in lwlib to the time stamp associated with the most recent menu
|
|
453 operation */
|
|
454 extern Time x_focus_timestamp_really_sucks_fix_me_better;
|
|
455
|
|
456 if (!f)
|
|
457 f = x_any_window_to_frame (d, XtWindow (XtParent (widget)));
|
|
458 if (!f)
|
|
459 return;
|
|
460
|
|
461 /* make sure f is the selected frame */
|
793
|
462 frame = wrap_frame (f);
|
428
|
463 Fselect_frame (frame);
|
|
464
|
|
465 if (client_data)
|
|
466 {
|
|
467 /* this is an incremental menu construction callback */
|
|
468 widget_value *hack_wv = (widget_value *) client_data;
|
|
469 Lisp_Object submenu_desc;
|
|
470 widget_value *wv;
|
|
471
|
|
472 assert (hack_wv->type == INCREMENTAL_TYPE);
|
826
|
473 submenu_desc = VOID_TO_LISP (hack_wv->call_data);
|
428
|
474
|
853
|
475 wv = (protected_menu_item_descriptor_to_widget_value
|
|
476 (submenu_desc, SUBMENU_TYPE, 1, 0));
|
428
|
477
|
|
478 if (!wv)
|
|
479 {
|
|
480 wv = xmalloc_widget_value ();
|
|
481 wv->type = CASCADE_TYPE;
|
|
482 wv->next = NULL;
|
|
483 wv->accel = LISP_TO_VOID (Qnil);
|
|
484 wv->contents = xmalloc_widget_value ();
|
|
485 wv->contents->type = TEXT_TYPE;
|
436
|
486 wv->contents->name = xstrdup ("No menu");
|
428
|
487 wv->contents->next = NULL;
|
|
488 wv->contents->accel = LISP_TO_VOID (Qnil);
|
|
489 }
|
|
490 assert (wv && wv->type == CASCADE_TYPE && wv->contents);
|
|
491 replace_widget_value_tree (hack_wv, wv->contents);
|
|
492 free_popup_widget_value_tree (wv);
|
1261
|
493 /* Now that we've destructively modified part of the widget value
|
|
494 hierarchy, our list of protected callbacks will no longer be
|
|
495 valid, so we need to recompute it. */
|
1346
|
496 gcpro_popup_callbacks (FRAME_X_MENUBAR_ID (f));
|
428
|
497 }
|
1346
|
498 else if (!FRAME_X_MENUBAR_ID (f))
|
428
|
499 return;
|
|
500 else
|
|
501 {
|
|
502 /* #### - It is necessary to *ALWAYS* call set_frame_menubar() now that
|
|
503 incremental menus are implemented. If a subtree of a menu has been
|
|
504 updated incrementally (a destructive operation), then that subtree
|
|
505 must somehow be wiped.
|
|
506
|
|
507 It is difficult to undo the destructive operation in lwlib because
|
|
508 a pointer back to lisp data needs to be hidden away somewhere. So
|
|
509 that an INCREMENTAL_TYPE widget_value can be recreated... Hmmmmm. */
|
853
|
510 run_hook_trapping_problems
|
1333
|
511 (Qmenubar, Qactivate_menubar_hook,
|
853
|
512 INHIBIT_EXISTING_PERMANENT_DISPLAY_OBJECT_DELETION);
|
428
|
513 set_frame_menubar (f, 1, 0);
|
|
514 DEVICE_X_MOUSE_TIMESTAMP (XDEVICE (FRAME_DEVICE (f))) =
|
|
515 DEVICE_X_GLOBAL_MOUSE_TIMESTAMP (XDEVICE (FRAME_DEVICE (f))) =
|
|
516 x_focus_timestamp_really_sucks_fix_me_better;
|
|
517 }
|
|
518 }
|
|
519
|
|
520 static widget_value *
|
|
521 compute_menubar_data (struct frame *f, Lisp_Object menubar, int deep_p)
|
|
522 {
|
|
523 if (NILP (menubar))
|
438
|
524 return 0;
|
428
|
525 else
|
|
526 {
|
438
|
527 widget_value *data;
|
428
|
528 int count = specpdl_depth ();
|
|
529
|
438
|
530 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
531 Fset_buffer (XWINDOW (FRAME_SELECTED_WINDOW (f))->buffer);
|
428
|
532 data = menu_item_descriptor_to_widget_value (menubar, MENUBAR_TYPE,
|
|
533 deep_p, 0);
|
771
|
534 unbind_to (count);
|
438
|
535
|
|
536 return data;
|
428
|
537 }
|
|
538 }
|
|
539
|
|
540 static int
|
|
541 set_frame_menubar (struct frame *f, int deep_p, int first_time_p)
|
|
542 {
|
|
543 widget_value *data;
|
|
544 Lisp_Object menubar;
|
|
545 int menubar_visible;
|
|
546 long id;
|
438
|
547 /* As with the toolbar, the minibuffer does not have its own menubar. */
|
428
|
548 struct window *w = XWINDOW (FRAME_LAST_NONMINIBUF_WINDOW (f));
|
|
549
|
|
550 if (! FRAME_X_P (f))
|
|
551 return 0;
|
|
552
|
|
553 /***** first compute the contents of the menubar *****/
|
|
554
|
|
555 if (! first_time_p)
|
|
556 {
|
|
557 /* evaluate `current-menubar' in the buffer of the selected window
|
|
558 of the frame in question. */
|
|
559 menubar = symbol_value_in_buffer (Qcurrent_menubar, w->buffer);
|
|
560 }
|
|
561 else
|
|
562 {
|
|
563 /* That's a little tricky the first time since the frame isn't
|
|
564 fully initialized yet. */
|
|
565 menubar = Fsymbol_value (Qcurrent_menubar);
|
|
566 }
|
|
567
|
|
568 if (NILP (menubar))
|
|
569 {
|
|
570 menubar = Vblank_menubar;
|
|
571 menubar_visible = 0;
|
|
572 }
|
|
573 else
|
|
574 menubar_visible = !NILP (w->menubar_visible_p);
|
|
575
|
|
576 data = compute_menubar_data (f, menubar, deep_p);
|
|
577 if (!data || (!data->next && !data->contents))
|
|
578 abort ();
|
|
579
|
1346
|
580 if (!FRAME_X_MENUBAR_ID (f))
|
|
581 FRAME_X_MENUBAR_ID (f) = new_lwlib_id ();
|
428
|
582
|
|
583 /***** now store into the menubar widget, creating it if necessary *****/
|
|
584
|
1346
|
585 id = FRAME_X_MENUBAR_ID (f);
|
428
|
586 if (!FRAME_X_MENUBAR_WIDGET (f))
|
|
587 {
|
|
588 Widget parent = FRAME_X_CONTAINER_WIDGET (f);
|
|
589
|
|
590 assert (first_time_p);
|
|
591
|
|
592 /* It's the first time we've mapped the menubar so compute its
|
|
593 contents completely once. This makes sure that the menubar
|
|
594 components are created with the right type. */
|
|
595 if (!deep_p)
|
|
596 {
|
|
597 free_popup_widget_value_tree (data);
|
|
598 data = compute_menubar_data (f, menubar, 1);
|
|
599 }
|
|
600
|
|
601
|
|
602 FRAME_X_MENUBAR_WIDGET (f) =
|
|
603 lw_create_widget ("menubar", "menubar", id, data, parent,
|
|
604 0, pre_activate_callback,
|
|
605 popup_selection_callback, 0);
|
|
606
|
|
607 }
|
|
608 else
|
|
609 {
|
|
610 lw_modify_all_widgets (id, data, deep_p ? True : False);
|
|
611 }
|
|
612 free_popup_widget_value_tree (data);
|
|
613
|
1261
|
614 /* Buried inside of the lwlib data are pointers to Lisp objects that may
|
|
615 have been freshly created. They need to be GC-protected, so snarf them
|
|
616 now and record them into the popup-data object associated with the
|
|
617 frame. */
|
1346
|
618 gcpro_popup_callbacks (id);
|
1261
|
619
|
1346
|
620 FRAME_X_MENUBAR_CONTENTS_UP_TO_DATE (f) = deep_p;
|
|
621 FRAME_X_LAST_MENUBAR_BUFFER (f) =
|
428
|
622 XWINDOW (FRAME_LAST_NONMINIBUF_WINDOW (f))->buffer;
|
|
623 return menubar_visible;
|
|
624 }
|
|
625
|
|
626
|
|
627 /* Called from x_create_widgets() to create the initial menubar of a frame
|
|
628 before it is mapped, so that the window is mapped with the menubar already
|
|
629 there instead of us tacking it on later and thrashing the window after it
|
|
630 is visible. */
|
|
631 int
|
|
632 x_initialize_frame_menubar (struct frame *f)
|
|
633 {
|
|
634 return set_frame_menubar (f, 1, 1);
|
|
635 }
|
|
636
|
|
637
|
|
638 static LWLIB_ID last_popup_menu_selection_callback_id;
|
|
639
|
|
640 static void
|
|
641 popup_menu_selection_callback (Widget widget, LWLIB_ID id,
|
|
642 XtPointer client_data)
|
|
643 {
|
|
644 last_popup_menu_selection_callback_id = id;
|
|
645 popup_selection_callback (widget, id, client_data);
|
|
646 /* lw_destroy_all_widgets() will be called from popup_down_callback() */
|
|
647 }
|
|
648
|
|
649 static void
|
|
650 popup_menu_down_callback (Widget widget, LWLIB_ID id, XtPointer client_data)
|
|
651 {
|
|
652 if (popup_handled_p (id))
|
|
653 return;
|
|
654 assert (popup_up_p != 0);
|
|
655 ungcpro_popup_callbacks (id);
|
|
656 popup_up_p--;
|
|
657 /* if this isn't called immediately after the selection callback, then
|
|
658 there wasn't a menu selection. */
|
|
659 if (id != last_popup_menu_selection_callback_id)
|
|
660 popup_selection_callback (widget, id, (XtPointer) -1);
|
|
661 lw_destroy_all_widgets (id);
|
|
662 }
|
|
663
|
|
664
|
|
665 static void
|
440
|
666 make_dummy_xbutton_event (XEvent *dummy, Widget daddy, Lisp_Event *eev)
|
428
|
667 /* NULL for eev means query pointer */
|
|
668 {
|
|
669 XButtonPressedEvent *btn = (XButtonPressedEvent *) dummy;
|
|
670
|
|
671 btn->type = ButtonPress;
|
|
672 btn->serial = 0;
|
|
673 btn->send_event = 0;
|
|
674 btn->display = XtDisplay (daddy);
|
|
675 btn->window = XtWindow (daddy);
|
|
676 if (eev)
|
|
677 {
|
|
678 Position shellx, shelly, framex, framey;
|
|
679 Arg al [2];
|
934
|
680 btn->time = EVENT_TIMESTAMP (eev);
|
1204
|
681 btn->button = EVENT_BUTTON_BUTTON (eev);
|
934
|
682 btn->root = RootWindowOfScreen (XtScreen (daddy));
|
|
683 btn->subwindow = (Window) NULL;
|
1204
|
684 btn->x = EVENT_BUTTON_X (eev);
|
|
685 btn->y = EVENT_BUTTON_Y (eev);
|
428
|
686 shellx = shelly = 0;
|
|
687 #ifndef HAVE_WMCOMMAND
|
|
688 {
|
|
689 Widget shell = XtParent (daddy);
|
|
690
|
|
691 XtSetArg (al [0], XtNx, &shellx);
|
|
692 XtSetArg (al [1], XtNy, &shelly);
|
|
693 XtGetValues (shell, al, 2);
|
|
694 }
|
438
|
695 #endif
|
428
|
696 XtSetArg (al [0], XtNx, &framex);
|
|
697 XtSetArg (al [1], XtNy, &framey);
|
|
698 XtGetValues (daddy, al, 2);
|
|
699 btn->x_root = shellx + framex + btn->x;
|
|
700 btn->y_root = shelly + framey + btn->y;
|
|
701 btn->state = ButtonPressMask; /* all buttons pressed */
|
|
702 }
|
|
703 else
|
|
704 {
|
|
705 /* CurrentTime is just ZERO, so it's worthless for
|
|
706 determining relative click times. */
|
|
707 struct device *d = get_device_from_display (XtDisplay (daddy));
|
|
708 btn->time = DEVICE_X_MOUSE_TIMESTAMP (d); /* event-Xt maintains this */
|
|
709 btn->button = 0;
|
|
710 XQueryPointer (btn->display, btn->window, &btn->root,
|
|
711 &btn->subwindow, &btn->x_root, &btn->y_root,
|
|
712 &btn->x, &btn->y, &btn->state);
|
|
713 }
|
|
714 }
|
|
715
|
|
716
|
|
717
|
|
718 static void
|
|
719 x_update_frame_menubar_internal (struct frame *f)
|
|
720 {
|
|
721 /* We assume the menubar contents has changed if the global flag is set,
|
|
722 or if the current buffer has changed, or if the menubar has never
|
|
723 been updated before.
|
|
724 */
|
|
725 int menubar_contents_changed =
|
|
726 (f->menubar_changed
|
1346
|
727 || !FRAME_X_MENUBAR_ID (f)
|
|
728 || (!EQ (FRAME_X_LAST_MENUBAR_BUFFER (f),
|
428
|
729 XWINDOW (FRAME_LAST_NONMINIBUF_WINDOW (f))->buffer)));
|
|
730
|
|
731 Boolean menubar_was_visible = XtIsManaged (FRAME_X_MENUBAR_WIDGET (f));
|
|
732 Boolean menubar_will_be_visible = menubar_was_visible;
|
|
733 Boolean menubar_visibility_changed;
|
|
734
|
|
735 if (menubar_contents_changed)
|
|
736 menubar_will_be_visible = set_frame_menubar (f, 0, 0);
|
|
737
|
|
738 menubar_visibility_changed = menubar_was_visible != menubar_will_be_visible;
|
|
739
|
|
740 if (!menubar_visibility_changed)
|
|
741 return;
|
|
742
|
|
743 /* Set menubar visibility */
|
|
744 (menubar_will_be_visible ? XtManageChild : XtUnmanageChild)
|
|
745 (FRAME_X_MENUBAR_WIDGET (f));
|
|
746
|
|
747 MARK_FRAME_SIZE_SLIPPED (f);
|
|
748 }
|
|
749
|
|
750 static void
|
|
751 x_update_frame_menubars (struct frame *f)
|
|
752 {
|
|
753 assert (FRAME_X_P (f));
|
|
754
|
|
755 x_update_frame_menubar_internal (f);
|
|
756
|
|
757 /* #### This isn't going to work right now that this function works on
|
|
758 a per-frame, not per-device basis. Guess what? I don't care. */
|
|
759 }
|
|
760
|
|
761 static void
|
|
762 x_free_frame_menubars (struct frame *f)
|
|
763 {
|
|
764 Widget menubar_widget;
|
|
765
|
|
766 assert (FRAME_X_P (f));
|
|
767
|
|
768 menubar_widget = FRAME_X_MENUBAR_WIDGET (f);
|
|
769 if (menubar_widget)
|
|
770 {
|
1346
|
771 LWLIB_ID id = FRAME_X_MENUBAR_ID (f);
|
428
|
772 lw_destroy_all_widgets (id);
|
1346
|
773 ungcpro_popup_callbacks (id);
|
|
774 FRAME_X_MENUBAR_ID (f) = 0;
|
428
|
775 }
|
|
776 }
|
|
777
|
|
778 static void
|
|
779 x_popup_menu (Lisp_Object menu_desc, Lisp_Object event)
|
|
780 {
|
|
781 int menu_id;
|
|
782 struct frame *f = selected_frame ();
|
|
783 widget_value *data;
|
|
784 Widget parent;
|
|
785 Widget menu;
|
440
|
786 Lisp_Event *eev = NULL;
|
428
|
787 XEvent xev;
|
793
|
788 Lisp_Object frame = wrap_frame (f);
|
428
|
789
|
|
790 CHECK_X_FRAME (frame);
|
|
791 parent = FRAME_X_SHELL_WIDGET (f);
|
|
792
|
|
793 if (!NILP (event))
|
|
794 {
|
|
795 CHECK_LIVE_EVENT (event);
|
|
796 eev= XEVENT (event);
|
|
797 if (eev->event_type != button_press_event
|
|
798 && eev->event_type != button_release_event)
|
|
799 wrong_type_argument (Qmouse_event_p, event);
|
|
800 }
|
|
801 else if (!NILP (Vthis_command_keys))
|
|
802 {
|
|
803 /* if an event wasn't passed, use the last event of the event sequence
|
|
804 currently being executed, if that event is a mouse event */
|
|
805 eev = XEVENT (Vthis_command_keys); /* last event first */
|
|
806 if (eev->event_type != button_press_event
|
|
807 && eev->event_type != button_release_event)
|
|
808 eev = NULL;
|
|
809 }
|
|
810 make_dummy_xbutton_event (&xev, parent, eev);
|
|
811
|
|
812 if (SYMBOLP (menu_desc))
|
|
813 menu_desc = Fsymbol_value (menu_desc);
|
|
814 CHECK_CONS (menu_desc);
|
|
815 CHECK_STRING (XCAR (menu_desc));
|
|
816 data = menu_item_descriptor_to_widget_value (menu_desc, POPUP_TYPE, 1, 1);
|
|
817
|
563
|
818 if (! data) signal_error (Qgui_error, "no menu", Qunbound);
|
428
|
819
|
|
820 menu_id = new_lwlib_id ();
|
|
821 menu = lw_create_widget ("popup", "popup" /* data->name */, menu_id, data,
|
|
822 parent, 1, 0,
|
|
823 popup_menu_selection_callback,
|
|
824 popup_menu_down_callback);
|
|
825 free_popup_widget_value_tree (data);
|
|
826
|
|
827 gcpro_popup_callbacks (menu_id);
|
|
828
|
|
829 /* Setting zmacs-region-stays is necessary here because executing a command
|
|
830 from a menu is really a two-command process: the first command (bound to
|
|
831 the button-click) simply pops up the menu, and returns. This causes a
|
|
832 sequence of magic-events (destined for the popup-menu widget) to begin.
|
|
833 Eventually, a menu item is selected, and a menu-event blip is pushed onto
|
|
834 the end of the input stream, which is then executed by the event loop.
|
|
835
|
|
836 So there are two command-events, with a bunch of magic-events between
|
|
837 them. We don't want the *first* command event to alter the state of the
|
|
838 region, so that the region can be available as an argument for the second
|
|
839 command.
|
442
|
840 */
|
428
|
841 if (zmacs_regions)
|
|
842 zmacs_region_stays = 1;
|
|
843
|
|
844 popup_up_p++;
|
|
845 lw_popup_menu (menu, &xev);
|
|
846 /* this speeds up display of pop-up menus */
|
|
847 XFlush (XtDisplay (parent));
|
|
848 }
|
|
849
|
|
850
|
442
|
851
|
|
852 #if defined(LWLIB_MENUBARS_LUCID)
|
|
853 static void
|
|
854 menu_move_up (void)
|
|
855 {
|
|
856 widget_value *current = lw_get_entries (False);
|
|
857 widget_value *entries = lw_get_entries (True);
|
|
858 widget_value *prev = NULL;
|
|
859
|
|
860 while (entries != current)
|
|
861 {
|
|
862 if (entries->name /*&& entries->enabled*/) prev = entries;
|
|
863 entries = entries->next;
|
|
864 assert (entries);
|
|
865 }
|
|
866
|
|
867 if (!prev)
|
|
868 /* move to last item */
|
|
869 {
|
|
870 while (entries->next)
|
|
871 {
|
|
872 if (entries->name /*&& entries->enabled*/) prev = entries;
|
|
873 entries = entries->next;
|
|
874 }
|
|
875 if (prev)
|
|
876 {
|
|
877 if (entries->name /*&& entries->enabled*/)
|
|
878 prev = entries;
|
|
879 }
|
|
880 else
|
|
881 {
|
|
882 /* no selectable items in this menu, pop up to previous level */
|
|
883 lw_pop_menu ();
|
|
884 return;
|
|
885 }
|
|
886 }
|
|
887 lw_set_item (prev);
|
|
888 }
|
|
889
|
|
890 static void
|
|
891 menu_move_down (void)
|
|
892 {
|
|
893 widget_value *current = lw_get_entries (False);
|
|
894 widget_value *new = current;
|
|
895
|
|
896 while (new->next)
|
|
897 {
|
|
898 new = new->next;
|
|
899 if (new->name /*&& new->enabled*/) break;
|
|
900 }
|
|
901
|
|
902 if (new==current||!(new->name/*||new->enabled*/))
|
|
903 {
|
|
904 new = lw_get_entries (True);
|
|
905 while (new!=current)
|
|
906 {
|
|
907 if (new->name /*&& new->enabled*/) break;
|
|
908 new = new->next;
|
|
909 }
|
|
910 if (new==current&&!(new->name /*|| new->enabled*/))
|
|
911 {
|
|
912 lw_pop_menu ();
|
|
913 return;
|
|
914 }
|
|
915 }
|
|
916
|
|
917 lw_set_item (new);
|
|
918 }
|
|
919
|
|
920 static void
|
|
921 menu_move_left (void)
|
|
922 {
|
|
923 int level = lw_menu_level ();
|
|
924 int l = level;
|
|
925 widget_value *current;
|
|
926
|
|
927 while (level-- >= 3)
|
|
928 lw_pop_menu ();
|
|
929
|
|
930 menu_move_up ();
|
|
931 current = lw_get_entries (False);
|
|
932 if (l > 2 && current->contents)
|
|
933 lw_push_menu (current->contents);
|
|
934 }
|
|
935
|
|
936 static void
|
|
937 menu_move_right (void)
|
|
938 {
|
|
939 int level = lw_menu_level ();
|
|
940 int l = level;
|
|
941 widget_value *current;
|
|
942
|
|
943 while (level-- >= 3)
|
|
944 lw_pop_menu ();
|
|
945
|
|
946 menu_move_down ();
|
|
947 current = lw_get_entries (False);
|
|
948 if (l > 2 && current->contents)
|
|
949 lw_push_menu (current->contents);
|
|
950 }
|
|
951
|
|
952 static void
|
|
953 menu_select_item (widget_value *val)
|
|
954 {
|
|
955 if (val == NULL)
|
|
956 val = lw_get_entries (False);
|
|
957
|
|
958 /* is match a submenu? */
|
|
959
|
|
960 if (val->contents)
|
|
961 {
|
|
962 /* enter the submenu */
|
|
963
|
|
964 lw_set_item (val);
|
|
965 lw_push_menu (val->contents);
|
|
966 }
|
|
967 else
|
|
968 {
|
|
969 /* Execute the menu entry by calling the menu's `select'
|
|
970 callback function
|
|
971 */
|
|
972 lw_kill_menus (val);
|
|
973 }
|
|
974 }
|
|
975
|
|
976 Lisp_Object
|
|
977 command_builder_operate_menu_accelerator (struct command_builder *builder)
|
|
978 {
|
|
979 /* this function can GC */
|
|
980
|
|
981 struct console *con = XCONSOLE (Vselected_console);
|
|
982 Lisp_Object evee = builder->most_current_event;
|
|
983 Lisp_Object binding;
|
|
984 widget_value *entries;
|
|
985
|
|
986 extern int lw_menu_accelerate; /* lwlib.c */
|
|
987
|
|
988 #if 0
|
|
989 {
|
|
990 int i;
|
|
991 Lisp_Object t;
|
|
992
|
|
993 t = builder->current_events;
|
|
994 i = 0;
|
|
995 while (!NILP (t))
|
|
996 {
|
|
997 i++;
|
800
|
998 write_fmt_string (Qexternal_debugging_output, "OPERATE (%d): ",i);
|
442
|
999 print_internal (t, Qexternal_debugging_output, 1);
|
826
|
1000 write_c_string (Qexternal_debugging_output, "\n");
|
442
|
1001 t = XEVENT_NEXT (t);
|
|
1002 }
|
|
1003 }
|
|
1004 #endif /* 0 */
|
|
1005
|
|
1006 /* menu accelerator keys don't go into keyboard macros */
|
|
1007 if (!NILP (con->defining_kbd_macro) && NILP (Vexecuting_macro))
|
|
1008 con->kbd_macro_ptr = con->kbd_macro_end;
|
|
1009
|
|
1010 /* don't echo menu accelerator keys */
|
|
1011 /*reset_key_echo (builder, 1);*/
|
|
1012
|
|
1013 if (!lw_menu_accelerate)
|
|
1014 {
|
|
1015 /* `convert' mouse display to keyboard display
|
|
1016 by entering the open submenu
|
|
1017 */
|
|
1018 entries = lw_get_entries (False);
|
|
1019 if (entries->contents)
|
|
1020 {
|
|
1021 lw_push_menu (entries->contents);
|
|
1022 lw_display_menu (CurrentTime);
|
|
1023 }
|
|
1024 }
|
|
1025
|
|
1026 /* compare event to the current menu accelerators */
|
|
1027
|
|
1028 entries=lw_get_entries (True);
|
|
1029
|
|
1030 while (entries)
|
|
1031 {
|
|
1032 Lisp_Object accel;
|
826
|
1033 accel = VOID_TO_LISP (entries->accel);
|
442
|
1034 if (entries->name && !NILP (accel))
|
|
1035 {
|
1204
|
1036 if (event_matches_key_specifier_p (evee, accel))
|
442
|
1037 {
|
|
1038 /* a match! */
|
|
1039
|
|
1040 menu_select_item (entries);
|
|
1041
|
|
1042 if (lw_menu_active) lw_display_menu (CurrentTime);
|
|
1043
|
|
1044 reset_this_command_keys (Vselected_console, 1);
|
|
1045 /*reset_command_builder_event_chain (builder);*/
|
|
1046 return Vmenu_accelerator_map;
|
|
1047 }
|
|
1048 }
|
|
1049 entries = entries->next;
|
|
1050 }
|
|
1051
|
|
1052 /* try to look up event in menu-accelerator-map */
|
|
1053
|
|
1054 binding = event_binding_in (evee, Vmenu_accelerator_map, 1);
|
|
1055
|
|
1056 if (NILP (binding))
|
|
1057 {
|
|
1058 /* beep at user for undefined key */
|
|
1059 return Qnil;
|
|
1060 }
|
|
1061 else
|
|
1062 {
|
|
1063 if (EQ (binding, Qmenu_quit))
|
|
1064 {
|
|
1065 /* turn off menus and set quit flag */
|
|
1066 lw_kill_menus (NULL);
|
|
1067 Vquit_flag = Qt;
|
|
1068 }
|
|
1069 else if (EQ (binding, Qmenu_up))
|
|
1070 {
|
|
1071 int level = lw_menu_level ();
|
|
1072 if (level > 2)
|
|
1073 menu_move_up ();
|
|
1074 }
|
|
1075 else if (EQ (binding, Qmenu_down))
|
|
1076 {
|
|
1077 int level = lw_menu_level ();
|
|
1078 if (level > 2)
|
|
1079 menu_move_down ();
|
|
1080 else
|
|
1081 menu_select_item (NULL);
|
|
1082 }
|
|
1083 else if (EQ (binding, Qmenu_left))
|
|
1084 {
|
|
1085 int level = lw_menu_level ();
|
|
1086 if (level > 3)
|
|
1087 {
|
|
1088 lw_pop_menu ();
|
|
1089 lw_display_menu (CurrentTime);
|
|
1090 }
|
|
1091 else
|
|
1092 menu_move_left ();
|
|
1093 }
|
|
1094 else if (EQ (binding, Qmenu_right))
|
|
1095 {
|
|
1096 int level = lw_menu_level ();
|
|
1097 if (level > 2 &&
|
|
1098 lw_get_entries (False)->contents)
|
|
1099 {
|
|
1100 widget_value *current = lw_get_entries (False);
|
|
1101 if (current->contents)
|
|
1102 menu_select_item (NULL);
|
|
1103 }
|
|
1104 else
|
|
1105 menu_move_right ();
|
|
1106 }
|
|
1107 else if (EQ (binding, Qmenu_select))
|
|
1108 menu_select_item (NULL);
|
|
1109 else if (EQ (binding, Qmenu_escape))
|
|
1110 {
|
|
1111 int level = lw_menu_level ();
|
|
1112
|
|
1113 if (level > 2)
|
|
1114 {
|
|
1115 lw_pop_menu ();
|
|
1116 lw_display_menu (CurrentTime);
|
|
1117 }
|
|
1118 else
|
|
1119 {
|
|
1120 /* turn off menus quietly */
|
|
1121 lw_kill_menus (NULL);
|
|
1122 }
|
|
1123 }
|
|
1124 else if (KEYMAPP (binding))
|
|
1125 {
|
|
1126 /* prefix key */
|
|
1127 reset_this_command_keys (Vselected_console, 1);
|
|
1128 /*reset_command_builder_event_chain (builder);*/
|
|
1129 return binding;
|
|
1130 }
|
|
1131 else
|
|
1132 {
|
|
1133 /* turn off menus and execute binding */
|
|
1134 lw_kill_menus (NULL);
|
|
1135 reset_this_command_keys (Vselected_console, 1);
|
|
1136 /*reset_command_builder_event_chain (builder);*/
|
|
1137 return binding;
|
|
1138 }
|
|
1139 }
|
|
1140
|
|
1141 if (lw_menu_active) lw_display_menu (CurrentTime);
|
|
1142
|
|
1143 reset_this_command_keys (Vselected_console, 1);
|
|
1144 /*reset_command_builder_event_chain (builder);*/
|
|
1145
|
|
1146 return Vmenu_accelerator_map;
|
|
1147 }
|
|
1148
|
|
1149 static Lisp_Object
|
|
1150 menu_accelerator_junk_on_error (Lisp_Object errordata, Lisp_Object ignored)
|
|
1151 {
|
|
1152 Vmenu_accelerator_prefix = Qnil;
|
|
1153 Vmenu_accelerator_modifiers = Qnil;
|
|
1154 Vmenu_accelerator_enabled = Qnil;
|
|
1155 if (!NILP (errordata))
|
|
1156 {
|
|
1157 /* #### This should call
|
|
1158 (with-output-to-string (display-error errordata))
|
|
1159 but that stuff is all in Lisp currently. */
|
|
1160 warn_when_safe_lispobj
|
|
1161 (Qerror, Qwarning,
|
771
|
1162 emacs_sprintf_string_lisp
|
|
1163 ("%s: %s", Qnil, 2,
|
|
1164 build_msg_string ("Error in menu accelerators (setting to nil)"),
|
|
1165 errordata));
|
442
|
1166 }
|
|
1167
|
|
1168 return Qnil;
|
|
1169 }
|
|
1170
|
|
1171 static Lisp_Object
|
|
1172 menu_accelerator_safe_compare (Lisp_Object event0)
|
|
1173 {
|
|
1174 if (CONSP (Vmenu_accelerator_prefix))
|
|
1175 {
|
|
1176 Lisp_Object t;
|
|
1177 t=Vmenu_accelerator_prefix;
|
|
1178 while (!NILP (t)
|
|
1179 && !NILP (event0)
|
1204
|
1180 && event_matches_key_specifier_p (event0, Fcar (t)))
|
442
|
1181 {
|
|
1182 t = Fcdr (t);
|
|
1183 event0 = XEVENT_NEXT (event0);
|
|
1184 }
|
|
1185 if (!NILP (t))
|
|
1186 return Qnil;
|
|
1187 }
|
|
1188 else if (NILP (event0))
|
|
1189 return Qnil;
|
1204
|
1190 else if (event_matches_key_specifier_p (event0, Vmenu_accelerator_prefix))
|
442
|
1191 event0 = XEVENT_NEXT (event0);
|
|
1192 else
|
|
1193 return Qnil;
|
|
1194 return event0;
|
|
1195 }
|
|
1196
|
|
1197 static Lisp_Object
|
|
1198 menu_accelerator_safe_mod_compare (Lisp_Object cons)
|
|
1199 {
|
1204
|
1200 return (event_matches_key_specifier_p (XCAR (cons), XCDR (cons)) ? Qt
|
442
|
1201 : Qnil);
|
|
1202 }
|
|
1203
|
|
1204 Lisp_Object
|
|
1205 command_builder_find_menu_accelerator (struct command_builder *builder)
|
|
1206 {
|
|
1207 /* this function can GC */
|
|
1208 Lisp_Object event0 = builder->current_events;
|
|
1209 struct console *con = XCONSOLE (Vselected_console);
|
|
1210 struct frame *f = XFRAME (CONSOLE_SELECTED_FRAME (con));
|
|
1211 Widget menubar_widget;
|
|
1212
|
|
1213 /* compare entries in event0 against the menu prefix */
|
|
1214
|
|
1215 if ((!CONSOLE_X_P (XCONSOLE (builder->console))) || NILP (event0) ||
|
|
1216 XEVENT (event0)->event_type != key_press_event)
|
|
1217 return Qnil;
|
|
1218
|
|
1219 if (!NILP (Vmenu_accelerator_prefix))
|
|
1220 {
|
|
1221 event0 = condition_case_1 (Qerror,
|
|
1222 menu_accelerator_safe_compare,
|
|
1223 event0,
|
|
1224 menu_accelerator_junk_on_error,
|
|
1225 Qnil);
|
|
1226 }
|
|
1227
|
|
1228 if (NILP (event0))
|
|
1229 return Qnil;
|
|
1230
|
|
1231 menubar_widget = FRAME_X_MENUBAR_WIDGET (f);
|
|
1232 if (menubar_widget
|
|
1233 && CONSP (Vmenu_accelerator_modifiers))
|
|
1234 {
|
446
|
1235 Lisp_Object fake = Qnil;
|
442
|
1236 Lisp_Object last = Qnil;
|
|
1237 struct gcpro gcpro1;
|
|
1238 Lisp_Object matchp;
|
|
1239
|
|
1240 widget_value *val;
|
1346
|
1241 LWLIB_ID id = FRAME_X_MENUBAR_ID (f);
|
442
|
1242
|
|
1243 val = lw_get_all_values (id);
|
|
1244 if (val)
|
|
1245 {
|
|
1246 val = val->contents;
|
|
1247
|
|
1248 fake = Fcopy_sequence (Vmenu_accelerator_modifiers);
|
|
1249 last = fake;
|
|
1250
|
|
1251 while (!NILP (Fcdr (last)))
|
|
1252 last = Fcdr (last);
|
|
1253
|
|
1254 Fsetcdr (last, Fcons (Qnil, Qnil));
|
|
1255 last = Fcdr (last);
|
|
1256 }
|
|
1257
|
|
1258 fake = Fcons (Qnil, fake);
|
|
1259
|
|
1260 GCPRO1 (fake);
|
|
1261
|
|
1262 while (val)
|
|
1263 {
|
|
1264 Lisp_Object accel;
|
826
|
1265 accel = VOID_TO_LISP (val->accel);
|
442
|
1266 if (val->name && !NILP (accel))
|
|
1267 {
|
|
1268 Fsetcar (last, accel);
|
|
1269 Fsetcar (fake, event0);
|
|
1270 matchp = condition_case_1 (Qerror,
|
|
1271 menu_accelerator_safe_mod_compare,
|
|
1272 fake,
|
|
1273 menu_accelerator_junk_on_error,
|
|
1274 Qnil);
|
|
1275 if (!NILP (matchp))
|
|
1276 {
|
|
1277 /* we found one! */
|
|
1278
|
|
1279 lw_set_menu (menubar_widget, val);
|
|
1280 /* yah - yet another hack.
|
|
1281 pretend emacs timestamp is the same as an X timestamp,
|
|
1282 which for the moment it is. (read events.h)
|
|
1283 */
|
|
1284 lw_map_menu (XEVENT (event0)->timestamp);
|
|
1285
|
|
1286 if (val->contents)
|
|
1287 lw_push_menu (val->contents);
|
|
1288
|
|
1289 lw_display_menu (CurrentTime);
|
|
1290
|
|
1291 /* menu accelerator keys don't go into keyboard macros */
|
|
1292 if (!NILP (con->defining_kbd_macro)
|
|
1293 && NILP (Vexecuting_macro))
|
|
1294 con->kbd_macro_ptr = con->kbd_macro_end;
|
|
1295
|
|
1296 /* don't echo menu accelerator keys */
|
|
1297 /*reset_key_echo (builder, 1);*/
|
|
1298 reset_this_command_keys (Vselected_console, 1);
|
|
1299 UNGCPRO;
|
|
1300
|
|
1301 return Vmenu_accelerator_map;
|
|
1302 }
|
|
1303 }
|
|
1304
|
|
1305 val = val->next;
|
|
1306 }
|
|
1307
|
|
1308 UNGCPRO;
|
|
1309 }
|
|
1310 return Qnil;
|
|
1311 }
|
|
1312
|
|
1313 int
|
|
1314 x_kludge_lw_menu_active (void)
|
|
1315 {
|
|
1316 return lw_menu_active;
|
|
1317 }
|
|
1318
|
|
1319 DEFUN ("accelerate-menu", Faccelerate_menu, 0, 0, "_", /*
|
|
1320 Make the menubar active. Menu items can be selected using menu accelerators
|
|
1321 or by actions defined in menu-accelerator-map.
|
|
1322 */
|
|
1323 ())
|
|
1324 {
|
|
1325 struct console *con = XCONSOLE (Vselected_console);
|
|
1326 struct frame *f = XFRAME (CONSOLE_SELECTED_FRAME (con));
|
|
1327 LWLIB_ID id;
|
|
1328 widget_value *val;
|
|
1329
|
1346
|
1330 if (!FRAME_X_MENUBAR_ID (f))
|
563
|
1331 invalid_argument ("Frame has no menubar", Qunbound);
|
442
|
1332
|
1346
|
1333 id = FRAME_X_MENUBAR_ID (f);
|
442
|
1334 val = lw_get_all_values (id);
|
|
1335 val = val->contents;
|
|
1336 lw_set_menu (FRAME_X_MENUBAR_WIDGET (f), val);
|
|
1337 lw_map_menu (CurrentTime);
|
|
1338
|
|
1339 lw_display_menu (CurrentTime);
|
|
1340
|
|
1341 /* menu accelerator keys don't go into keyboard macros */
|
|
1342 if (!NILP (con->defining_kbd_macro) && NILP (Vexecuting_macro))
|
|
1343 con->kbd_macro_ptr = con->kbd_macro_end;
|
|
1344
|
|
1345 return Qnil;
|
|
1346 }
|
|
1347 #endif /* LWLIB_MENUBARS_LUCID */
|
|
1348
|
|
1349
|
428
|
1350 void
|
|
1351 syms_of_menubar_x (void)
|
|
1352 {
|
442
|
1353 #if defined(LWLIB_MENUBARS_LUCID)
|
|
1354 DEFSUBR (Faccelerate_menu);
|
|
1355 #endif
|
428
|
1356 }
|
|
1357
|
|
1358 void
|
|
1359 console_type_create_menubar_x (void)
|
|
1360 {
|
|
1361 CONSOLE_HAS_METHOD (x, update_frame_menubars);
|
|
1362 CONSOLE_HAS_METHOD (x, free_frame_menubars);
|
|
1363 CONSOLE_HAS_METHOD (x, popup_menu);
|
|
1364 }
|
|
1365
|
|
1366 void
|
|
1367 reinit_vars_of_menubar_x (void)
|
|
1368 {
|
|
1369 last_popup_menu_selection_callback_id = (LWLIB_ID) -1;
|
|
1370 }
|
|
1371
|
|
1372 void
|
|
1373 vars_of_menubar_x (void)
|
|
1374 {
|
|
1375 reinit_vars_of_menubar_x ();
|
|
1376
|
|
1377 #if defined (LWLIB_MENUBARS_LUCID)
|
|
1378 Fprovide (intern ("lucid-menubars"));
|
|
1379 #elif defined (LWLIB_MENUBARS_MOTIF)
|
|
1380 Fprovide (intern ("motif-menubars"));
|
|
1381 #elif defined (LWLIB_MENUBARS_ATHENA)
|
|
1382 Fprovide (intern ("athena-menubars"));
|
|
1383 #endif
|
|
1384 }
|