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