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