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.
|
800
|
4 Copyright (C) 2000, 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 /* 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 */
|
800
|
41 #include "device.h"
|
428
|
42 #include "events.h"
|
|
43 #include "frame.h"
|
442
|
44 #include "gui.h"
|
|
45 #include "keymap.h"
|
|
46 #include "menubar.h"
|
428
|
47 #include "opaque.h"
|
|
48 #include "window.h"
|
|
49
|
800
|
50 #include "console-x.h"
|
|
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
|
|
399 (call_trapping_problems
|
|
400 (Qmenubar, "Error during menu callback", UNINHIBIT_QUIT, 0,
|
|
401 protected_menu_item_descriptor_to_widget_value_1, &midtwv)))
|
|
402 return 0;
|
|
403
|
|
404 return midtwv.wv;
|
428
|
405 }
|
853
|
406
|
|
407 #if defined (LWLIB_MENUBARS_LUCID) || (defined LWLIB_MENUBARS_MOTIF)
|
|
408 int in_menu_callback;
|
428
|
409 #endif
|
|
410
|
|
411 /* The order in which callbacks are run is funny to say the least.
|
|
412 It's sometimes tricky to avoid running a callback twice, and to
|
|
413 avoid returning prematurely. So, this function returns true
|
|
414 if the menu's callbacks are no longer gc protected. So long
|
|
415 as we unprotect them before allowing other callbacks to run,
|
|
416 everything should be ok.
|
|
417
|
|
418 The pre_activate_callback() *IS* intentionally called multiple times.
|
|
419 If client_data == NULL, then it's being called before the menu is posted.
|
|
420 If client_data != NULL, then client_data is a (widget_value *) and
|
|
421 client_data->data is a Lisp_Object pointing to a lisp submenu description
|
|
422 that must be converted into widget_values. *client_data is destructively
|
|
423 modified.
|
|
424
|
|
425 #### Stig thinks that there may be a GC problem here due to the
|
|
426 fact that pre_activate_callback() is called multiple times, but I
|
|
427 think he's wrong.
|
|
428
|
|
429 */
|
|
430
|
|
431 static void
|
|
432 pre_activate_callback (Widget widget, LWLIB_ID id, XtPointer client_data)
|
|
433 {
|
|
434 /* This function can GC */
|
|
435 struct device *d = get_device_from_display (XtDisplay (widget));
|
|
436 struct frame *f = x_any_window_to_frame (d, XtWindow (widget));
|
|
437 Lisp_Object frame;
|
|
438 int count;
|
|
439
|
|
440 /* set in lwlib to the time stamp associated with the most recent menu
|
|
441 operation */
|
|
442 extern Time x_focus_timestamp_really_sucks_fix_me_better;
|
|
443
|
|
444 if (!f)
|
|
445 f = x_any_window_to_frame (d, XtWindow (XtParent (widget)));
|
|
446 if (!f)
|
|
447 return;
|
|
448
|
|
449 /* make sure f is the selected frame */
|
793
|
450 frame = wrap_frame (f);
|
428
|
451 Fselect_frame (frame);
|
|
452
|
|
453 if (client_data)
|
|
454 {
|
|
455 /* this is an incremental menu construction callback */
|
|
456 widget_value *hack_wv = (widget_value *) client_data;
|
|
457 Lisp_Object submenu_desc;
|
|
458 widget_value *wv;
|
|
459
|
|
460 assert (hack_wv->type == INCREMENTAL_TYPE);
|
826
|
461 submenu_desc = VOID_TO_LISP (hack_wv->call_data);
|
428
|
462
|
|
463 /*
|
|
464 * #### Fix the menu code so this isn't necessary.
|
|
465 *
|
|
466 * Protect against reentering the menu code otherwise we will
|
|
467 * crash later when the code gets confused at the state
|
|
468 * changes.
|
|
469 */
|
853
|
470 count = internal_bind_int (&in_menu_callback, 1);
|
|
471 wv = (protected_menu_item_descriptor_to_widget_value
|
|
472 (submenu_desc, SUBMENU_TYPE, 1, 0));
|
771
|
473 unbind_to (count);
|
428
|
474
|
|
475 if (!wv)
|
|
476 {
|
|
477 wv = xmalloc_widget_value ();
|
|
478 wv->type = CASCADE_TYPE;
|
|
479 wv->next = NULL;
|
|
480 wv->accel = LISP_TO_VOID (Qnil);
|
|
481 wv->contents = xmalloc_widget_value ();
|
|
482 wv->contents->type = TEXT_TYPE;
|
436
|
483 wv->contents->name = xstrdup ("No menu");
|
428
|
484 wv->contents->next = NULL;
|
|
485 wv->contents->accel = LISP_TO_VOID (Qnil);
|
|
486 }
|
|
487 assert (wv && wv->type == CASCADE_TYPE && wv->contents);
|
|
488 replace_widget_value_tree (hack_wv, wv->contents);
|
|
489 free_popup_widget_value_tree (wv);
|
|
490 }
|
|
491 else if (!POPUP_DATAP (FRAME_MENUBAR_DATA (f)))
|
|
492 return;
|
|
493 else
|
|
494 {
|
|
495 /* #### - It is necessary to *ALWAYS* call set_frame_menubar() now that
|
|
496 incremental menus are implemented. If a subtree of a menu has been
|
|
497 updated incrementally (a destructive operation), then that subtree
|
|
498 must somehow be wiped.
|
|
499
|
|
500 It is difficult to undo the destructive operation in lwlib because
|
|
501 a pointer back to lisp data needs to be hidden away somewhere. So
|
|
502 that an INCREMENTAL_TYPE widget_value can be recreated... Hmmmmm. */
|
853
|
503 run_hook_trapping_problems
|
|
504 ("Error in activate-menubar-hook", Qactivate_menubar_hook,
|
|
505 INHIBIT_EXISTING_PERMANENT_DISPLAY_OBJECT_DELETION);
|
428
|
506 set_frame_menubar (f, 1, 0);
|
|
507 DEVICE_X_MOUSE_TIMESTAMP (XDEVICE (FRAME_DEVICE (f))) =
|
|
508 DEVICE_X_GLOBAL_MOUSE_TIMESTAMP (XDEVICE (FRAME_DEVICE (f))) =
|
|
509 x_focus_timestamp_really_sucks_fix_me_better;
|
|
510 }
|
|
511 }
|
|
512
|
|
513 static widget_value *
|
|
514 compute_menubar_data (struct frame *f, Lisp_Object menubar, int deep_p)
|
|
515 {
|
|
516 if (NILP (menubar))
|
438
|
517 return 0;
|
428
|
518 else
|
|
519 {
|
438
|
520 widget_value *data;
|
428
|
521 int count = specpdl_depth ();
|
|
522
|
438
|
523 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
524 Fset_buffer (XWINDOW (FRAME_SELECTED_WINDOW (f))->buffer);
|
428
|
525 data = menu_item_descriptor_to_widget_value (menubar, MENUBAR_TYPE,
|
|
526 deep_p, 0);
|
771
|
527 unbind_to (count);
|
438
|
528
|
|
529 return data;
|
428
|
530 }
|
|
531 }
|
|
532
|
|
533 static int
|
|
534 set_frame_menubar (struct frame *f, int deep_p, int first_time_p)
|
|
535 {
|
|
536 widget_value *data;
|
|
537 Lisp_Object menubar;
|
|
538 int menubar_visible;
|
|
539 long id;
|
438
|
540 /* As with the toolbar, the minibuffer does not have its own menubar. */
|
428
|
541 struct window *w = XWINDOW (FRAME_LAST_NONMINIBUF_WINDOW (f));
|
|
542
|
|
543 if (! FRAME_X_P (f))
|
|
544 return 0;
|
|
545
|
|
546 /***** first compute the contents of the menubar *****/
|
|
547
|
|
548 if (! first_time_p)
|
|
549 {
|
|
550 /* evaluate `current-menubar' in the buffer of the selected window
|
|
551 of the frame in question. */
|
|
552 menubar = symbol_value_in_buffer (Qcurrent_menubar, w->buffer);
|
|
553 }
|
|
554 else
|
|
555 {
|
|
556 /* That's a little tricky the first time since the frame isn't
|
|
557 fully initialized yet. */
|
|
558 menubar = Fsymbol_value (Qcurrent_menubar);
|
|
559 }
|
|
560
|
|
561 if (NILP (menubar))
|
|
562 {
|
|
563 menubar = Vblank_menubar;
|
|
564 menubar_visible = 0;
|
|
565 }
|
|
566 else
|
|
567 menubar_visible = !NILP (w->menubar_visible_p);
|
|
568
|
|
569 data = compute_menubar_data (f, menubar, deep_p);
|
|
570 if (!data || (!data->next && !data->contents))
|
|
571 abort ();
|
|
572
|
|
573 if (NILP (FRAME_MENUBAR_DATA (f)))
|
|
574 {
|
|
575 struct popup_data *mdata =
|
|
576 alloc_lcrecord_type (struct popup_data, &lrecord_popup_data);
|
|
577
|
|
578 mdata->id = new_lwlib_id ();
|
|
579 mdata->last_menubar_buffer = Qnil;
|
|
580 mdata->menubar_contents_up_to_date = 0;
|
793
|
581 FRAME_MENUBAR_DATA (f) = wrap_popup_data (mdata);
|
428
|
582 }
|
|
583
|
|
584 /***** now store into the menubar widget, creating it if necessary *****/
|
|
585
|
|
586 id = XFRAME_MENUBAR_DATA (f)->id;
|
|
587 if (!FRAME_X_MENUBAR_WIDGET (f))
|
|
588 {
|
|
589 Widget parent = FRAME_X_CONTAINER_WIDGET (f);
|
|
590
|
|
591 assert (first_time_p);
|
|
592
|
|
593 /* It's the first time we've mapped the menubar so compute its
|
|
594 contents completely once. This makes sure that the menubar
|
|
595 components are created with the right type. */
|
|
596 if (!deep_p)
|
|
597 {
|
|
598 free_popup_widget_value_tree (data);
|
|
599 data = compute_menubar_data (f, menubar, 1);
|
|
600 }
|
|
601
|
|
602
|
|
603 FRAME_X_MENUBAR_WIDGET (f) =
|
|
604 lw_create_widget ("menubar", "menubar", id, data, parent,
|
|
605 0, pre_activate_callback,
|
|
606 popup_selection_callback, 0);
|
|
607
|
|
608 }
|
|
609 else
|
|
610 {
|
|
611 lw_modify_all_widgets (id, data, deep_p ? True : False);
|
|
612 }
|
|
613 free_popup_widget_value_tree (data);
|
|
614
|
|
615 XFRAME_MENUBAR_DATA (f)->menubar_contents_up_to_date = deep_p;
|
|
616 XFRAME_MENUBAR_DATA (f)->last_menubar_buffer =
|
|
617 XWINDOW (FRAME_LAST_NONMINIBUF_WINDOW (f))->buffer;
|
|
618 return menubar_visible;
|
|
619 }
|
|
620
|
|
621
|
|
622 /* Called from x_create_widgets() to create the initial menubar of a frame
|
|
623 before it is mapped, so that the window is mapped with the menubar already
|
|
624 there instead of us tacking it on later and thrashing the window after it
|
|
625 is visible. */
|
|
626 int
|
|
627 x_initialize_frame_menubar (struct frame *f)
|
|
628 {
|
|
629 return set_frame_menubar (f, 1, 1);
|
|
630 }
|
|
631
|
|
632
|
|
633 static LWLIB_ID last_popup_menu_selection_callback_id;
|
|
634
|
|
635 static void
|
|
636 popup_menu_selection_callback (Widget widget, LWLIB_ID id,
|
|
637 XtPointer client_data)
|
|
638 {
|
|
639 last_popup_menu_selection_callback_id = id;
|
|
640 popup_selection_callback (widget, id, client_data);
|
|
641 /* lw_destroy_all_widgets() will be called from popup_down_callback() */
|
|
642 }
|
|
643
|
|
644 static void
|
|
645 popup_menu_down_callback (Widget widget, LWLIB_ID id, XtPointer client_data)
|
|
646 {
|
|
647 if (popup_handled_p (id))
|
|
648 return;
|
|
649 assert (popup_up_p != 0);
|
|
650 ungcpro_popup_callbacks (id);
|
|
651 popup_up_p--;
|
|
652 /* if this isn't called immediately after the selection callback, then
|
|
653 there wasn't a menu selection. */
|
|
654 if (id != last_popup_menu_selection_callback_id)
|
|
655 popup_selection_callback (widget, id, (XtPointer) -1);
|
|
656 lw_destroy_all_widgets (id);
|
|
657 }
|
|
658
|
|
659
|
|
660 static void
|
440
|
661 make_dummy_xbutton_event (XEvent *dummy, Widget daddy, Lisp_Event *eev)
|
428
|
662 /* NULL for eev means query pointer */
|
|
663 {
|
|
664 XButtonPressedEvent *btn = (XButtonPressedEvent *) dummy;
|
|
665
|
|
666 btn->type = ButtonPress;
|
|
667 btn->serial = 0;
|
|
668 btn->send_event = 0;
|
|
669 btn->display = XtDisplay (daddy);
|
|
670 btn->window = XtWindow (daddy);
|
|
671 if (eev)
|
|
672 {
|
|
673 Position shellx, shelly, framex, framey;
|
|
674 Arg al [2];
|
|
675 btn->time = eev->timestamp;
|
|
676 btn->button = eev->event.button.button;
|
|
677 btn->root = RootWindowOfScreen (XtScreen (daddy));
|
|
678 btn->subwindow = (Window) NULL;
|
|
679 btn->x = eev->event.button.x;
|
|
680 btn->y = eev->event.button.y;
|
|
681 shellx = shelly = 0;
|
|
682 #ifndef HAVE_WMCOMMAND
|
|
683 {
|
|
684 Widget shell = XtParent (daddy);
|
|
685
|
|
686 XtSetArg (al [0], XtNx, &shellx);
|
|
687 XtSetArg (al [1], XtNy, &shelly);
|
|
688 XtGetValues (shell, al, 2);
|
|
689 }
|
438
|
690 #endif
|
428
|
691 XtSetArg (al [0], XtNx, &framex);
|
|
692 XtSetArg (al [1], XtNy, &framey);
|
|
693 XtGetValues (daddy, al, 2);
|
|
694 btn->x_root = shellx + framex + btn->x;
|
|
695 btn->y_root = shelly + framey + btn->y;
|
|
696 btn->state = ButtonPressMask; /* all buttons pressed */
|
|
697 }
|
|
698 else
|
|
699 {
|
|
700 /* CurrentTime is just ZERO, so it's worthless for
|
|
701 determining relative click times. */
|
|
702 struct device *d = get_device_from_display (XtDisplay (daddy));
|
|
703 btn->time = DEVICE_X_MOUSE_TIMESTAMP (d); /* event-Xt maintains this */
|
|
704 btn->button = 0;
|
|
705 XQueryPointer (btn->display, btn->window, &btn->root,
|
|
706 &btn->subwindow, &btn->x_root, &btn->y_root,
|
|
707 &btn->x, &btn->y, &btn->state);
|
|
708 }
|
|
709 }
|
|
710
|
|
711
|
|
712
|
|
713 static void
|
|
714 x_update_frame_menubar_internal (struct frame *f)
|
|
715 {
|
|
716 /* We assume the menubar contents has changed if the global flag is set,
|
|
717 or if the current buffer has changed, or if the menubar has never
|
|
718 been updated before.
|
|
719 */
|
|
720 int menubar_contents_changed =
|
|
721 (f->menubar_changed
|
|
722 || NILP (FRAME_MENUBAR_DATA (f))
|
|
723 || (!EQ (XFRAME_MENUBAR_DATA (f)->last_menubar_buffer,
|
|
724 XWINDOW (FRAME_LAST_NONMINIBUF_WINDOW (f))->buffer)));
|
|
725
|
|
726 Boolean menubar_was_visible = XtIsManaged (FRAME_X_MENUBAR_WIDGET (f));
|
|
727 Boolean menubar_will_be_visible = menubar_was_visible;
|
|
728 Boolean menubar_visibility_changed;
|
|
729
|
|
730 if (menubar_contents_changed)
|
|
731 menubar_will_be_visible = set_frame_menubar (f, 0, 0);
|
|
732
|
|
733 menubar_visibility_changed = menubar_was_visible != menubar_will_be_visible;
|
|
734
|
|
735 if (!menubar_visibility_changed)
|
|
736 return;
|
|
737
|
|
738 /* Set menubar visibility */
|
|
739 (menubar_will_be_visible ? XtManageChild : XtUnmanageChild)
|
|
740 (FRAME_X_MENUBAR_WIDGET (f));
|
|
741
|
|
742 MARK_FRAME_SIZE_SLIPPED (f);
|
|
743 }
|
|
744
|
|
745 static void
|
|
746 x_update_frame_menubars (struct frame *f)
|
|
747 {
|
|
748 assert (FRAME_X_P (f));
|
|
749
|
|
750 x_update_frame_menubar_internal (f);
|
|
751
|
|
752 /* #### This isn't going to work right now that this function works on
|
|
753 a per-frame, not per-device basis. Guess what? I don't care. */
|
|
754 }
|
|
755
|
|
756 static void
|
|
757 x_free_frame_menubars (struct frame *f)
|
|
758 {
|
|
759 Widget menubar_widget;
|
|
760
|
|
761 assert (FRAME_X_P (f));
|
|
762
|
|
763 menubar_widget = FRAME_X_MENUBAR_WIDGET (f);
|
|
764 if (menubar_widget)
|
|
765 {
|
|
766 LWLIB_ID id = XFRAME_MENUBAR_DATA (f)->id;
|
|
767 lw_destroy_all_widgets (id);
|
|
768 XFRAME_MENUBAR_DATA (f)->id = 0;
|
|
769 }
|
|
770 }
|
|
771
|
|
772 static void
|
|
773 x_popup_menu (Lisp_Object menu_desc, Lisp_Object event)
|
|
774 {
|
|
775 int menu_id;
|
|
776 struct frame *f = selected_frame ();
|
|
777 widget_value *data;
|
|
778 Widget parent;
|
|
779 Widget menu;
|
440
|
780 Lisp_Event *eev = NULL;
|
428
|
781 XEvent xev;
|
793
|
782 Lisp_Object frame = wrap_frame (f);
|
428
|
783
|
|
784 CHECK_X_FRAME (frame);
|
|
785 parent = FRAME_X_SHELL_WIDGET (f);
|
|
786
|
|
787 if (!NILP (event))
|
|
788 {
|
|
789 CHECK_LIVE_EVENT (event);
|
|
790 eev= XEVENT (event);
|
|
791 if (eev->event_type != button_press_event
|
|
792 && eev->event_type != button_release_event)
|
|
793 wrong_type_argument (Qmouse_event_p, event);
|
|
794 }
|
|
795 else if (!NILP (Vthis_command_keys))
|
|
796 {
|
|
797 /* if an event wasn't passed, use the last event of the event sequence
|
|
798 currently being executed, if that event is a mouse event */
|
|
799 eev = XEVENT (Vthis_command_keys); /* last event first */
|
|
800 if (eev->event_type != button_press_event
|
|
801 && eev->event_type != button_release_event)
|
|
802 eev = NULL;
|
|
803 }
|
|
804 make_dummy_xbutton_event (&xev, parent, eev);
|
|
805
|
|
806 if (SYMBOLP (menu_desc))
|
|
807 menu_desc = Fsymbol_value (menu_desc);
|
|
808 CHECK_CONS (menu_desc);
|
|
809 CHECK_STRING (XCAR (menu_desc));
|
|
810 data = menu_item_descriptor_to_widget_value (menu_desc, POPUP_TYPE, 1, 1);
|
|
811
|
563
|
812 if (! data) signal_error (Qgui_error, "no menu", Qunbound);
|
428
|
813
|
|
814 menu_id = new_lwlib_id ();
|
|
815 menu = lw_create_widget ("popup", "popup" /* data->name */, menu_id, data,
|
|
816 parent, 1, 0,
|
|
817 popup_menu_selection_callback,
|
|
818 popup_menu_down_callback);
|
|
819 free_popup_widget_value_tree (data);
|
|
820
|
|
821 gcpro_popup_callbacks (menu_id);
|
|
822
|
|
823 /* Setting zmacs-region-stays is necessary here because executing a command
|
|
824 from a menu is really a two-command process: the first command (bound to
|
|
825 the button-click) simply pops up the menu, and returns. This causes a
|
|
826 sequence of magic-events (destined for the popup-menu widget) to begin.
|
|
827 Eventually, a menu item is selected, and a menu-event blip is pushed onto
|
|
828 the end of the input stream, which is then executed by the event loop.
|
|
829
|
|
830 So there are two command-events, with a bunch of magic-events between
|
|
831 them. We don't want the *first* command event to alter the state of the
|
|
832 region, so that the region can be available as an argument for the second
|
|
833 command.
|
442
|
834 */
|
428
|
835 if (zmacs_regions)
|
|
836 zmacs_region_stays = 1;
|
|
837
|
|
838 popup_up_p++;
|
|
839 lw_popup_menu (menu, &xev);
|
|
840 /* this speeds up display of pop-up menus */
|
|
841 XFlush (XtDisplay (parent));
|
|
842 }
|
|
843
|
|
844
|
442
|
845
|
|
846 #if defined(LWLIB_MENUBARS_LUCID)
|
|
847 static void
|
|
848 menu_move_up (void)
|
|
849 {
|
|
850 widget_value *current = lw_get_entries (False);
|
|
851 widget_value *entries = lw_get_entries (True);
|
|
852 widget_value *prev = NULL;
|
|
853
|
|
854 while (entries != current)
|
|
855 {
|
|
856 if (entries->name /*&& entries->enabled*/) prev = entries;
|
|
857 entries = entries->next;
|
|
858 assert (entries);
|
|
859 }
|
|
860
|
|
861 if (!prev)
|
|
862 /* move to last item */
|
|
863 {
|
|
864 while (entries->next)
|
|
865 {
|
|
866 if (entries->name /*&& entries->enabled*/) prev = entries;
|
|
867 entries = entries->next;
|
|
868 }
|
|
869 if (prev)
|
|
870 {
|
|
871 if (entries->name /*&& entries->enabled*/)
|
|
872 prev = entries;
|
|
873 }
|
|
874 else
|
|
875 {
|
|
876 /* no selectable items in this menu, pop up to previous level */
|
|
877 lw_pop_menu ();
|
|
878 return;
|
|
879 }
|
|
880 }
|
|
881 lw_set_item (prev);
|
|
882 }
|
|
883
|
|
884 static void
|
|
885 menu_move_down (void)
|
|
886 {
|
|
887 widget_value *current = lw_get_entries (False);
|
|
888 widget_value *new = current;
|
|
889
|
|
890 while (new->next)
|
|
891 {
|
|
892 new = new->next;
|
|
893 if (new->name /*&& new->enabled*/) break;
|
|
894 }
|
|
895
|
|
896 if (new==current||!(new->name/*||new->enabled*/))
|
|
897 {
|
|
898 new = lw_get_entries (True);
|
|
899 while (new!=current)
|
|
900 {
|
|
901 if (new->name /*&& new->enabled*/) break;
|
|
902 new = new->next;
|
|
903 }
|
|
904 if (new==current&&!(new->name /*|| new->enabled*/))
|
|
905 {
|
|
906 lw_pop_menu ();
|
|
907 return;
|
|
908 }
|
|
909 }
|
|
910
|
|
911 lw_set_item (new);
|
|
912 }
|
|
913
|
|
914 static void
|
|
915 menu_move_left (void)
|
|
916 {
|
|
917 int level = lw_menu_level ();
|
|
918 int l = level;
|
|
919 widget_value *current;
|
|
920
|
|
921 while (level-- >= 3)
|
|
922 lw_pop_menu ();
|
|
923
|
|
924 menu_move_up ();
|
|
925 current = lw_get_entries (False);
|
|
926 if (l > 2 && current->contents)
|
|
927 lw_push_menu (current->contents);
|
|
928 }
|
|
929
|
|
930 static void
|
|
931 menu_move_right (void)
|
|
932 {
|
|
933 int level = lw_menu_level ();
|
|
934 int l = level;
|
|
935 widget_value *current;
|
|
936
|
|
937 while (level-- >= 3)
|
|
938 lw_pop_menu ();
|
|
939
|
|
940 menu_move_down ();
|
|
941 current = lw_get_entries (False);
|
|
942 if (l > 2 && current->contents)
|
|
943 lw_push_menu (current->contents);
|
|
944 }
|
|
945
|
|
946 static void
|
|
947 menu_select_item (widget_value *val)
|
|
948 {
|
|
949 if (val == NULL)
|
|
950 val = lw_get_entries (False);
|
|
951
|
|
952 /* is match a submenu? */
|
|
953
|
|
954 if (val->contents)
|
|
955 {
|
|
956 /* enter the submenu */
|
|
957
|
|
958 lw_set_item (val);
|
|
959 lw_push_menu (val->contents);
|
|
960 }
|
|
961 else
|
|
962 {
|
|
963 /* Execute the menu entry by calling the menu's `select'
|
|
964 callback function
|
|
965 */
|
|
966 lw_kill_menus (val);
|
|
967 }
|
|
968 }
|
|
969
|
|
970 Lisp_Object
|
|
971 command_builder_operate_menu_accelerator (struct command_builder *builder)
|
|
972 {
|
|
973 /* this function can GC */
|
|
974
|
|
975 struct console *con = XCONSOLE (Vselected_console);
|
|
976 Lisp_Object evee = builder->most_current_event;
|
|
977 Lisp_Object binding;
|
|
978 widget_value *entries;
|
|
979
|
|
980 extern int lw_menu_accelerate; /* lwlib.c */
|
|
981
|
|
982 #if 0
|
|
983 {
|
|
984 int i;
|
|
985 Lisp_Object t;
|
|
986
|
|
987 t = builder->current_events;
|
|
988 i = 0;
|
|
989 while (!NILP (t))
|
|
990 {
|
|
991 i++;
|
800
|
992 write_fmt_string (Qexternal_debugging_output, "OPERATE (%d): ",i);
|
442
|
993 print_internal (t, Qexternal_debugging_output, 1);
|
826
|
994 write_c_string (Qexternal_debugging_output, "\n");
|
442
|
995 t = XEVENT_NEXT (t);
|
|
996 }
|
|
997 }
|
|
998 #endif /* 0 */
|
|
999
|
|
1000 /* menu accelerator keys don't go into keyboard macros */
|
|
1001 if (!NILP (con->defining_kbd_macro) && NILP (Vexecuting_macro))
|
|
1002 con->kbd_macro_ptr = con->kbd_macro_end;
|
|
1003
|
|
1004 /* don't echo menu accelerator keys */
|
|
1005 /*reset_key_echo (builder, 1);*/
|
|
1006
|
|
1007 if (!lw_menu_accelerate)
|
|
1008 {
|
|
1009 /* `convert' mouse display to keyboard display
|
|
1010 by entering the open submenu
|
|
1011 */
|
|
1012 entries = lw_get_entries (False);
|
|
1013 if (entries->contents)
|
|
1014 {
|
|
1015 lw_push_menu (entries->contents);
|
|
1016 lw_display_menu (CurrentTime);
|
|
1017 }
|
|
1018 }
|
|
1019
|
|
1020 /* compare event to the current menu accelerators */
|
|
1021
|
|
1022 entries=lw_get_entries (True);
|
|
1023
|
|
1024 while (entries)
|
|
1025 {
|
|
1026 Lisp_Object accel;
|
826
|
1027 accel = VOID_TO_LISP (entries->accel);
|
442
|
1028 if (entries->name && !NILP (accel))
|
|
1029 {
|
|
1030 if (event_matches_key_specifier_p (XEVENT (evee), accel))
|
|
1031 {
|
|
1032 /* a match! */
|
|
1033
|
|
1034 menu_select_item (entries);
|
|
1035
|
|
1036 if (lw_menu_active) lw_display_menu (CurrentTime);
|
|
1037
|
|
1038 reset_this_command_keys (Vselected_console, 1);
|
|
1039 /*reset_command_builder_event_chain (builder);*/
|
|
1040 return Vmenu_accelerator_map;
|
|
1041 }
|
|
1042 }
|
|
1043 entries = entries->next;
|
|
1044 }
|
|
1045
|
|
1046 /* try to look up event in menu-accelerator-map */
|
|
1047
|
|
1048 binding = event_binding_in (evee, Vmenu_accelerator_map, 1);
|
|
1049
|
|
1050 if (NILP (binding))
|
|
1051 {
|
|
1052 /* beep at user for undefined key */
|
|
1053 return Qnil;
|
|
1054 }
|
|
1055 else
|
|
1056 {
|
|
1057 if (EQ (binding, Qmenu_quit))
|
|
1058 {
|
|
1059 /* turn off menus and set quit flag */
|
|
1060 lw_kill_menus (NULL);
|
|
1061 Vquit_flag = Qt;
|
|
1062 }
|
|
1063 else if (EQ (binding, Qmenu_up))
|
|
1064 {
|
|
1065 int level = lw_menu_level ();
|
|
1066 if (level > 2)
|
|
1067 menu_move_up ();
|
|
1068 }
|
|
1069 else if (EQ (binding, Qmenu_down))
|
|
1070 {
|
|
1071 int level = lw_menu_level ();
|
|
1072 if (level > 2)
|
|
1073 menu_move_down ();
|
|
1074 else
|
|
1075 menu_select_item (NULL);
|
|
1076 }
|
|
1077 else if (EQ (binding, Qmenu_left))
|
|
1078 {
|
|
1079 int level = lw_menu_level ();
|
|
1080 if (level > 3)
|
|
1081 {
|
|
1082 lw_pop_menu ();
|
|
1083 lw_display_menu (CurrentTime);
|
|
1084 }
|
|
1085 else
|
|
1086 menu_move_left ();
|
|
1087 }
|
|
1088 else if (EQ (binding, Qmenu_right))
|
|
1089 {
|
|
1090 int level = lw_menu_level ();
|
|
1091 if (level > 2 &&
|
|
1092 lw_get_entries (False)->contents)
|
|
1093 {
|
|
1094 widget_value *current = lw_get_entries (False);
|
|
1095 if (current->contents)
|
|
1096 menu_select_item (NULL);
|
|
1097 }
|
|
1098 else
|
|
1099 menu_move_right ();
|
|
1100 }
|
|
1101 else if (EQ (binding, Qmenu_select))
|
|
1102 menu_select_item (NULL);
|
|
1103 else if (EQ (binding, Qmenu_escape))
|
|
1104 {
|
|
1105 int level = lw_menu_level ();
|
|
1106
|
|
1107 if (level > 2)
|
|
1108 {
|
|
1109 lw_pop_menu ();
|
|
1110 lw_display_menu (CurrentTime);
|
|
1111 }
|
|
1112 else
|
|
1113 {
|
|
1114 /* turn off menus quietly */
|
|
1115 lw_kill_menus (NULL);
|
|
1116 }
|
|
1117 }
|
|
1118 else if (KEYMAPP (binding))
|
|
1119 {
|
|
1120 /* prefix key */
|
|
1121 reset_this_command_keys (Vselected_console, 1);
|
|
1122 /*reset_command_builder_event_chain (builder);*/
|
|
1123 return binding;
|
|
1124 }
|
|
1125 else
|
|
1126 {
|
|
1127 /* turn off menus and execute binding */
|
|
1128 lw_kill_menus (NULL);
|
|
1129 reset_this_command_keys (Vselected_console, 1);
|
|
1130 /*reset_command_builder_event_chain (builder);*/
|
|
1131 return binding;
|
|
1132 }
|
|
1133 }
|
|
1134
|
|
1135 if (lw_menu_active) lw_display_menu (CurrentTime);
|
|
1136
|
|
1137 reset_this_command_keys (Vselected_console, 1);
|
|
1138 /*reset_command_builder_event_chain (builder);*/
|
|
1139
|
|
1140 return Vmenu_accelerator_map;
|
|
1141 }
|
|
1142
|
|
1143 static Lisp_Object
|
|
1144 menu_accelerator_junk_on_error (Lisp_Object errordata, Lisp_Object ignored)
|
|
1145 {
|
|
1146 Vmenu_accelerator_prefix = Qnil;
|
|
1147 Vmenu_accelerator_modifiers = Qnil;
|
|
1148 Vmenu_accelerator_enabled = Qnil;
|
|
1149 if (!NILP (errordata))
|
|
1150 {
|
|
1151 /* #### This should call
|
|
1152 (with-output-to-string (display-error errordata))
|
|
1153 but that stuff is all in Lisp currently. */
|
|
1154 warn_when_safe_lispobj
|
|
1155 (Qerror, Qwarning,
|
771
|
1156 emacs_sprintf_string_lisp
|
|
1157 ("%s: %s", Qnil, 2,
|
|
1158 build_msg_string ("Error in menu accelerators (setting to nil)"),
|
|
1159 errordata));
|
442
|
1160 }
|
|
1161
|
|
1162 return Qnil;
|
|
1163 }
|
|
1164
|
|
1165 static Lisp_Object
|
|
1166 menu_accelerator_safe_compare (Lisp_Object event0)
|
|
1167 {
|
|
1168 if (CONSP (Vmenu_accelerator_prefix))
|
|
1169 {
|
|
1170 Lisp_Object t;
|
|
1171 t=Vmenu_accelerator_prefix;
|
|
1172 while (!NILP (t)
|
|
1173 && !NILP (event0)
|
|
1174 && event_matches_key_specifier_p (XEVENT (event0), Fcar (t)))
|
|
1175 {
|
|
1176 t = Fcdr (t);
|
|
1177 event0 = XEVENT_NEXT (event0);
|
|
1178 }
|
|
1179 if (!NILP (t))
|
|
1180 return Qnil;
|
|
1181 }
|
|
1182 else if (NILP (event0))
|
|
1183 return Qnil;
|
|
1184 else if (event_matches_key_specifier_p (XEVENT (event0), Vmenu_accelerator_prefix))
|
|
1185 event0 = XEVENT_NEXT (event0);
|
|
1186 else
|
|
1187 return Qnil;
|
|
1188 return event0;
|
|
1189 }
|
|
1190
|
|
1191 static Lisp_Object
|
|
1192 menu_accelerator_safe_mod_compare (Lisp_Object cons)
|
|
1193 {
|
|
1194 return (event_matches_key_specifier_p (XEVENT (XCAR (cons)), XCDR (cons))
|
|
1195 ? Qt
|
|
1196 : Qnil);
|
|
1197 }
|
|
1198
|
|
1199 Lisp_Object
|
|
1200 command_builder_find_menu_accelerator (struct command_builder *builder)
|
|
1201 {
|
|
1202 /* this function can GC */
|
|
1203 Lisp_Object event0 = builder->current_events;
|
|
1204 struct console *con = XCONSOLE (Vselected_console);
|
|
1205 struct frame *f = XFRAME (CONSOLE_SELECTED_FRAME (con));
|
|
1206 Widget menubar_widget;
|
|
1207
|
|
1208 /* compare entries in event0 against the menu prefix */
|
|
1209
|
|
1210 if ((!CONSOLE_X_P (XCONSOLE (builder->console))) || NILP (event0) ||
|
|
1211 XEVENT (event0)->event_type != key_press_event)
|
|
1212 return Qnil;
|
|
1213
|
|
1214 if (!NILP (Vmenu_accelerator_prefix))
|
|
1215 {
|
|
1216 event0 = condition_case_1 (Qerror,
|
|
1217 menu_accelerator_safe_compare,
|
|
1218 event0,
|
|
1219 menu_accelerator_junk_on_error,
|
|
1220 Qnil);
|
|
1221 }
|
|
1222
|
|
1223 if (NILP (event0))
|
|
1224 return Qnil;
|
|
1225
|
|
1226 menubar_widget = FRAME_X_MENUBAR_WIDGET (f);
|
|
1227 if (menubar_widget
|
|
1228 && CONSP (Vmenu_accelerator_modifiers))
|
|
1229 {
|
446
|
1230 Lisp_Object fake = Qnil;
|
442
|
1231 Lisp_Object last = Qnil;
|
|
1232 struct gcpro gcpro1;
|
|
1233 Lisp_Object matchp;
|
|
1234
|
|
1235 widget_value *val;
|
|
1236 LWLIB_ID id = XPOPUP_DATA (f->menubar_data)->id;
|
|
1237
|
|
1238 val = lw_get_all_values (id);
|
|
1239 if (val)
|
|
1240 {
|
|
1241 val = val->contents;
|
|
1242
|
|
1243 fake = Fcopy_sequence (Vmenu_accelerator_modifiers);
|
|
1244 last = fake;
|
|
1245
|
|
1246 while (!NILP (Fcdr (last)))
|
|
1247 last = Fcdr (last);
|
|
1248
|
|
1249 Fsetcdr (last, Fcons (Qnil, Qnil));
|
|
1250 last = Fcdr (last);
|
|
1251 }
|
|
1252
|
|
1253 fake = Fcons (Qnil, fake);
|
|
1254
|
|
1255 GCPRO1 (fake);
|
|
1256
|
|
1257 while (val)
|
|
1258 {
|
|
1259 Lisp_Object accel;
|
826
|
1260 accel = VOID_TO_LISP (val->accel);
|
442
|
1261 if (val->name && !NILP (accel))
|
|
1262 {
|
|
1263 Fsetcar (last, accel);
|
|
1264 Fsetcar (fake, event0);
|
|
1265 matchp = condition_case_1 (Qerror,
|
|
1266 menu_accelerator_safe_mod_compare,
|
|
1267 fake,
|
|
1268 menu_accelerator_junk_on_error,
|
|
1269 Qnil);
|
|
1270 if (!NILP (matchp))
|
|
1271 {
|
|
1272 /* we found one! */
|
|
1273
|
|
1274 lw_set_menu (menubar_widget, val);
|
|
1275 /* yah - yet another hack.
|
|
1276 pretend emacs timestamp is the same as an X timestamp,
|
|
1277 which for the moment it is. (read events.h)
|
|
1278 */
|
|
1279 lw_map_menu (XEVENT (event0)->timestamp);
|
|
1280
|
|
1281 if (val->contents)
|
|
1282 lw_push_menu (val->contents);
|
|
1283
|
|
1284 lw_display_menu (CurrentTime);
|
|
1285
|
|
1286 /* menu accelerator keys don't go into keyboard macros */
|
|
1287 if (!NILP (con->defining_kbd_macro)
|
|
1288 && NILP (Vexecuting_macro))
|
|
1289 con->kbd_macro_ptr = con->kbd_macro_end;
|
|
1290
|
|
1291 /* don't echo menu accelerator keys */
|
|
1292 /*reset_key_echo (builder, 1);*/
|
|
1293 reset_this_command_keys (Vselected_console, 1);
|
|
1294 UNGCPRO;
|
|
1295
|
|
1296 return Vmenu_accelerator_map;
|
|
1297 }
|
|
1298 }
|
|
1299
|
|
1300 val = val->next;
|
|
1301 }
|
|
1302
|
|
1303 UNGCPRO;
|
|
1304 }
|
|
1305 return Qnil;
|
|
1306 }
|
|
1307
|
|
1308 int
|
|
1309 x_kludge_lw_menu_active (void)
|
|
1310 {
|
|
1311 return lw_menu_active;
|
|
1312 }
|
|
1313
|
|
1314 DEFUN ("accelerate-menu", Faccelerate_menu, 0, 0, "_", /*
|
|
1315 Make the menubar active. Menu items can be selected using menu accelerators
|
|
1316 or by actions defined in menu-accelerator-map.
|
|
1317 */
|
|
1318 ())
|
|
1319 {
|
|
1320 struct console *con = XCONSOLE (Vselected_console);
|
|
1321 struct frame *f = XFRAME (CONSOLE_SELECTED_FRAME (con));
|
|
1322 LWLIB_ID id;
|
|
1323 widget_value *val;
|
|
1324
|
|
1325 if (NILP (f->menubar_data))
|
563
|
1326 invalid_argument ("Frame has no menubar", Qunbound);
|
442
|
1327
|
|
1328 id = XPOPUP_DATA (f->menubar_data)->id;
|
|
1329 val = lw_get_all_values (id);
|
|
1330 val = val->contents;
|
|
1331 lw_set_menu (FRAME_X_MENUBAR_WIDGET (f), val);
|
|
1332 lw_map_menu (CurrentTime);
|
|
1333
|
|
1334 lw_display_menu (CurrentTime);
|
|
1335
|
|
1336 /* menu accelerator keys don't go into keyboard macros */
|
|
1337 if (!NILP (con->defining_kbd_macro) && NILP (Vexecuting_macro))
|
|
1338 con->kbd_macro_ptr = con->kbd_macro_end;
|
|
1339
|
|
1340 return Qnil;
|
|
1341 }
|
|
1342 #endif /* LWLIB_MENUBARS_LUCID */
|
|
1343
|
|
1344
|
428
|
1345 void
|
|
1346 syms_of_menubar_x (void)
|
|
1347 {
|
442
|
1348 #if defined(LWLIB_MENUBARS_LUCID)
|
|
1349 DEFSUBR (Faccelerate_menu);
|
|
1350 #endif
|
428
|
1351 }
|
|
1352
|
|
1353 void
|
|
1354 console_type_create_menubar_x (void)
|
|
1355 {
|
|
1356 CONSOLE_HAS_METHOD (x, update_frame_menubars);
|
|
1357 CONSOLE_HAS_METHOD (x, free_frame_menubars);
|
|
1358 CONSOLE_HAS_METHOD (x, popup_menu);
|
|
1359 }
|
|
1360
|
|
1361 void
|
|
1362 reinit_vars_of_menubar_x (void)
|
|
1363 {
|
|
1364 last_popup_menu_selection_callback_id = (LWLIB_ID) -1;
|
|
1365 }
|
|
1366
|
|
1367 void
|
|
1368 vars_of_menubar_x (void)
|
|
1369 {
|
|
1370 reinit_vars_of_menubar_x ();
|
|
1371
|
|
1372 #if defined (LWLIB_MENUBARS_LUCID)
|
|
1373 Fprovide (intern ("lucid-menubars"));
|
|
1374 #elif defined (LWLIB_MENUBARS_MOTIF)
|
|
1375 Fprovide (intern ("motif-menubars"));
|
|
1376 #elif defined (LWLIB_MENUBARS_ATHENA)
|
|
1377 Fprovide (intern ("athena-menubars"));
|
|
1378 #endif
|
|
1379 }
|