0
|
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.
|
|
4
|
|
5 This file is part of XEmacs.
|
|
6
|
|
7 XEmacs is free software; you can redistribute it and/or modify it
|
|
8 under the terms of the GNU General Public License as published by the
|
|
9 Free Software Foundation; either version 2, or (at your option) any
|
|
10 later version.
|
|
11
|
|
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
15 for more details.
|
|
16
|
|
17 You should have received a copy of the GNU General Public License
|
|
18 along with XEmacs; see the file COPYING. If not, write to
|
|
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
20 Boston, MA 02111-1307, USA. */
|
|
21
|
|
22 /* Synched up with: Not in FSF. */
|
|
23
|
|
24 /* created 16-dec-91 by jwz */
|
|
25
|
|
26 #include <config.h>
|
|
27 #include "lisp.h"
|
|
28
|
|
29 #include "console-x.h"
|
|
30 #include "EmacsManager.h"
|
|
31 #include "EmacsFrame.h"
|
|
32 #include "EmacsShell.h"
|
|
33 #include "gui-x.h"
|
|
34
|
|
35 #include "buffer.h"
|
|
36 #include "commands.h" /* zmacs_regions */
|
|
37 #include "events.h"
|
|
38 #include "frame.h"
|
|
39 #include "opaque.h"
|
|
40 #include "window.h"
|
|
41
|
|
42 static int set_frame_menubar (struct frame *f,
|
|
43 int deep_p,
|
|
44 int first_time_p);
|
|
45
|
|
46 #define FRAME_MENUBAR_DATA(frame) ((frame)->menubar_data)
|
|
47 #define XFRAME_MENUBAR_DATA(frame) XPOPUP_DATA ((frame)->menubar_data)
|
|
48
|
|
49 #define MENUBAR_TYPE 0
|
|
50 #define SUBMENU_TYPE 1
|
|
51 #define POPUP_TYPE 2
|
|
52
|
|
53
|
|
54 /* Converting Lisp menu tree descriptions to lwlib's `widget_value' form.
|
|
55
|
|
56 menu_item_descriptor_to_widget_value() converts a lisp description of a
|
|
57 menubar into a tree of widget_value structures. It allocates widget_values
|
|
58 with malloc_widget_value() and allocates other storage only for the `key'
|
|
59 slot. All other slots are filled with pointers to Lisp_String data. We
|
|
60 allocate a widget_value description of the menu or menubar, and hand it to
|
|
61 lwlib, which then makes a copy of it, which it manages internally. We then
|
|
62 immediately free our widget_value tree; it will not be referenced again.
|
|
63
|
|
64 Incremental menu construction callbacks operate just a bit differently.
|
|
65 They allocate widget_values and call replace_widget_value_tree() to tell
|
|
66 lwlib to destructively modify the incremental stub (subtree) of its
|
|
67 separate widget_value tree.
|
|
68
|
|
69 This function is highly recursive (it follows the menu trees) and may call
|
|
70 eval. The reason we keep pointers to lisp string data instead of copying
|
|
71 it and freeing it later is to avoid the speed penalty that would entail
|
|
72 (since this needs to be fast, in the simple cases at least). (The reason
|
|
73 we malloc/free the keys slot is because there's not a lisp string around
|
|
74 for us to use in that case.)
|
|
75
|
|
76 Since we keep pointers to lisp strings, and we call eval, we could lose if
|
|
77 GC relocates (or frees) those strings. It's not easy to gc protect the
|
|
78 strings because of the recursive nature of this function, and the fact that
|
|
79 it returns a data structure that gets freed later. So... we do the
|
|
80 sleaziest thing possible and inhibit GC for the duration. This is probably
|
|
81 not a big deal...
|
|
82
|
|
83 We do not have to worry about the pointers to Lisp_String data after
|
|
84 this function successfully finishes. lwlib copies all such data with
|
16
|
85 strdup(). */
|
0
|
86
|
|
87 static widget_value *
|
|
88 menu_item_descriptor_to_widget_value_1 (Lisp_Object desc,
|
|
89 int menu_type, int deep_p,
|
|
90 int filter_p,
|
|
91 int depth)
|
|
92 {
|
|
93 /* This function cannot GC.
|
|
94 It is only called from menu_item_descriptor_to_widget_value, which
|
|
95 prohibits GC. */
|
|
96 /* !!#### This function has not been Mule-ized */
|
|
97 int menubar_root_p = (menu_type == MENUBAR_TYPE && depth == 0);
|
|
98 widget_value *wv;
|
|
99 Lisp_Object wv_closure;
|
|
100 int count = specpdl_depth ();
|
|
101 int partition_seen = 0;
|
|
102
|
|
103 wv = xmalloc_widget_value ();
|
|
104
|
|
105 wv_closure = make_opaque_ptr (wv);
|
|
106 record_unwind_protect (widget_value_unwind, wv_closure);
|
|
107
|
|
108 if (STRINGP (desc))
|
|
109 {
|
16
|
110 char *string_chars = (char *) XSTRING_DATA (desc);
|
0
|
111 wv->type = (separator_string_p (string_chars) ? SEPARATOR_TYPE :
|
|
112 TEXT_TYPE);
|
|
113 #if 1
|
|
114 /* #### - should internationalize with X resources instead.
|
|
115 Not so! --ben */
|
|
116 string_chars = GETTEXT (string_chars);
|
|
117 #endif
|
|
118 if (wv->type == SEPARATOR_TYPE)
|
|
119 {
|
|
120 wv->value = menu_separator_style (string_chars);
|
|
121 }
|
|
122 else
|
|
123 {
|
|
124 wv->name = string_chars;
|
|
125 wv->enabled = 1;
|
|
126 }
|
|
127 }
|
|
128 else if (VECTORP (desc))
|
|
129 {
|
|
130 if (!button_item_to_widget_value (desc, wv, 1,
|
|
131 (menu_type == MENUBAR_TYPE
|
|
132 && depth <= 1)))
|
|
133 {
|
|
134 /* :included form was nil */
|
|
135 wv = NULL;
|
|
136 goto menu_item_done;
|
|
137 }
|
|
138 }
|
|
139 else if (CONSP (desc))
|
|
140 {
|
|
141 Lisp_Object incremental_data = desc;
|
|
142 widget_value *prev = 0;
|
|
143
|
|
144 if (STRINGP (XCAR (desc)))
|
|
145 {
|
|
146 Lisp_Object key, val;
|
|
147 Lisp_Object include_p, hook_fn = Qnil, config_tag = Qnil;
|
|
148 int included_spec = 0;
|
|
149 wv->type = CASCADE_TYPE;
|
|
150 wv->enabled = 1;
|
16
|
151 wv->name = (char *) XSTRING_DATA (LISP_GETTEXT (XCAR (desc)));
|
0
|
152 desc = Fcdr (desc);
|
|
153
|
|
154 while (key = Fcar (desc), KEYWORDP (key))
|
|
155 {
|
|
156 Lisp_Object cascade = desc;
|
|
157 desc = Fcdr (desc);
|
|
158 if (NILP (desc))
|
|
159 signal_simple_error ("keyword in menu lacks a value",
|
|
160 cascade);
|
|
161 val = Fcar (desc);
|
|
162 desc = Fcdr (desc);
|
|
163 if (EQ (key, Q_included))
|
|
164 include_p = val, included_spec = 1;
|
|
165 else if (EQ (key, Q_config))
|
|
166 config_tag = val;
|
|
167 else if (EQ (key, Q_filter))
|
|
168 hook_fn = val;
|
|
169 else
|
|
170 signal_simple_error ("unknown menu cascade keyword", cascade);
|
|
171 }
|
|
172
|
|
173 if ((!NILP (config_tag)
|
|
174 && NILP (Fmemq (config_tag, Vmenubar_configuration)))
|
|
175 || (included_spec && NILP (Feval (include_p))))
|
|
176 {
|
|
177 wv = NULL;
|
|
178 goto menu_item_done;
|
|
179 }
|
|
180 if (!NILP (hook_fn))
|
|
181 {
|
|
182 #ifdef LWLIB_MENUBARS_LUCID
|
|
183 if (filter_p || depth == 0)
|
|
184 {
|
|
185 #endif
|
|
186 desc = call1_trapping_errors ("Error in menubar filter",
|
|
187 hook_fn, desc);
|
|
188 if (UNBOUNDP (desc))
|
|
189 desc = Qnil;
|
|
190 #ifdef LWLIB_MENUBARS_LUCID
|
|
191 }
|
|
192 else
|
|
193 {
|
|
194 widget_value *incr_wv = xmalloc_widget_value ();
|
|
195 wv->contents = incr_wv;
|
|
196 incr_wv->type = INCREMENTAL_TYPE;
|
|
197 incr_wv->enabled = 1;
|
|
198 incr_wv->name = wv->name;
|
|
199 /* This is automatically GC protected through
|
|
200 the call to lw_map_widget_values(); no need
|
|
201 to worry. */
|
|
202 incr_wv->call_data = LISP_TO_VOID (incremental_data);
|
|
203 goto menu_item_done;
|
|
204 }
|
16
|
205 #endif /* LWLIB_MENUBARS_LUCID */
|
0
|
206 }
|
|
207 if (menu_type == POPUP_TYPE && popup_menu_titles && depth == 0)
|
|
208 {
|
|
209 /* Simply prepend three more widget values to the contents of
|
|
210 the menu: a label, and two separators (to get a double
|
|
211 line). */
|
|
212 widget_value *title_wv = xmalloc_widget_value ();
|
|
213 widget_value *sep_wv = xmalloc_widget_value ();
|
|
214 title_wv->type = TEXT_TYPE;
|
|
215 title_wv->name = wv->name;
|
|
216 title_wv->enabled = 1;
|
|
217 title_wv->next = sep_wv;
|
|
218 sep_wv->type = SEPARATOR_TYPE;
|
|
219 sep_wv->value = menu_separator_style ("==");
|
|
220 sep_wv->next = 0;
|
|
221
|
|
222 wv->contents = title_wv;
|
|
223 prev = sep_wv;
|
|
224 }
|
|
225 }
|
|
226 else if (menubar_root_p)
|
|
227 {
|
2
|
228 wv->name = (char *) "menubar";
|
0
|
229 wv->type = CASCADE_TYPE; /* Well, nothing else seems to fit and
|
|
230 this is ignored anyway... */
|
|
231 }
|
|
232 else
|
|
233 {
|
|
234 signal_simple_error ("menu name (first element) must be a string",
|
|
235 desc);
|
|
236 }
|
|
237
|
|
238 wv->enabled = 1;
|
|
239 if (deep_p || menubar_root_p)
|
|
240 {
|
|
241 widget_value *next;
|
|
242 for (; !NILP (desc); desc = Fcdr (desc))
|
|
243 {
|
|
244 Lisp_Object child = Fcar (desc);
|
|
245 if (menubar_root_p && NILP (child)) /* the partition */
|
|
246 {
|
|
247 if (partition_seen)
|
|
248 error (
|
|
249 "more than one partition (nil) in menubar description");
|
|
250 partition_seen = 1;
|
|
251 next = xmalloc_widget_value ();
|
|
252 next->type = PUSHRIGHT_TYPE;
|
|
253 }
|
|
254 else
|
|
255 {
|
16
|
256 next = menu_item_descriptor_to_widget_value_1
|
|
257 (child, menu_type, deep_p, filter_p, depth + 1);
|
0
|
258 }
|
|
259 if (! next)
|
|
260 continue;
|
|
261 else if (prev)
|
|
262 prev->next = next;
|
|
263 else
|
|
264 wv->contents = next;
|
|
265 prev = next;
|
|
266 }
|
|
267 }
|
|
268 if (deep_p && !wv->contents)
|
|
269 wv = NULL;
|
|
270 }
|
|
271 else if (NILP (desc))
|
|
272 error ("nil may not appear in menu descriptions");
|
|
273 else
|
|
274 signal_simple_error ("unrecognized menu descriptor", desc);
|
|
275
|
|
276 menu_item_done:
|
|
277
|
|
278 if (wv)
|
|
279 {
|
|
280 /* Completed normally. Clear out the object that widget_value_unwind()
|
|
281 will be called with to tell it not to free the wv (as we are
|
|
282 returning it.) */
|
|
283 set_opaque_ptr (wv_closure, 0);
|
|
284 }
|
|
285
|
|
286 unbind_to (count, Qnil);
|
|
287 return wv;
|
|
288 }
|
|
289
|
|
290 static widget_value *
|
|
291 menu_item_descriptor_to_widget_value (Lisp_Object desc,
|
|
292 int menu_type, /* if this is a menubar,
|
|
293 popup or sub menu */
|
|
294 int deep_p, /* */
|
|
295 int filter_p) /* if :filter forms
|
|
296 should run now */
|
|
297 {
|
|
298 widget_value *wv;
|
|
299 int count = specpdl_depth ();
|
|
300 record_unwind_protect (restore_gc_inhibit,
|
|
301 make_int (gc_currently_forbidden));
|
|
302 gc_currently_forbidden = 1;
|
|
303 /* Can't GC! */
|
|
304 wv = menu_item_descriptor_to_widget_value_1 (desc, menu_type, deep_p,
|
|
305 filter_p, 0);
|
|
306 unbind_to (count, Qnil);
|
|
307 return wv;
|
|
308 }
|
|
309
|
|
310
|
138
|
311 #ifdef LWLIB_MENUBARS_LUCID
|
|
312 int in_menu_callback;
|
|
313
|
|
314 Lisp_Object
|
|
315 restore_in_menu_callback(Lisp_Object val)
|
|
316 {
|
|
317 in_menu_callback = XINT(val);
|
|
318 return Qnil;
|
|
319 }
|
|
320 #endif /* LWLIB_MENUBARS_LUCID */
|
|
321
|
|
322
|
0
|
323 /* The order in which callbacks are run is funny to say the least.
|
|
324 It's sometimes tricky to avoid running a callback twice, and to
|
|
325 avoid returning prematurely. So, this function returns true
|
|
326 if the menu's callbacks are no longer gc protected. So long
|
|
327 as we unprotect them before allowing other callbacks to run,
|
|
328 everything should be ok.
|
|
329
|
|
330 The pre_activate_callback() *IS* intentionally called multiple times.
|
|
331 If client_data == NULL, then it's being called before the menu is posted.
|
|
332 If client_data != NULL, then client_data is a (widget_value *) and
|
|
333 client_data->data is a Lisp_Object pointing to a lisp submenu description
|
|
334 that must be converted into widget_values. *client_data is destructively
|
|
335 modified.
|
|
336
|
|
337 #### Stig thinks that there may be a GC problem here due to the
|
|
338 fact that pre_activate_callback() is called multiple times, but I
|
|
339 think he's wrong.
|
|
340
|
|
341 */
|
|
342
|
|
343 static void
|
|
344 pre_activate_callback (Widget widget, LWLIB_ID id, XtPointer client_data)
|
|
345 {
|
|
346 /* This function can GC */
|
|
347 struct gcpro gcpro1;
|
|
348 struct device *d = get_device_from_display (XtDisplay (widget));
|
|
349 struct frame *f = x_any_window_to_frame (d, XtWindow (widget));
|
|
350 Lisp_Object rest = Qnil;
|
82
|
351 Lisp_Object frame;
|
0
|
352 int any_changes = 0;
|
138
|
353 int count;
|
0
|
354
|
|
355 if (!f)
|
|
356 f = x_any_window_to_frame (d, XtWindow (XtParent (widget)));
|
|
357 if (!f)
|
|
358 return;
|
|
359
|
82
|
360 /* make sure f is the selected frame */
|
|
361 XSETFRAME (frame, f);
|
|
362 Fselect_frame (frame);
|
|
363
|
0
|
364 if (client_data)
|
|
365 {
|
|
366 /* this is an incremental menu construction callback */
|
|
367 widget_value *hack_wv = (widget_value *) client_data;
|
|
368 Lisp_Object submenu_desc;
|
|
369 widget_value *wv;
|
|
370
|
|
371 assert (hack_wv->type == INCREMENTAL_TYPE);
|
|
372 VOID_TO_LISP (submenu_desc, hack_wv->call_data);
|
138
|
373
|
|
374 /*
|
|
375 * #### Fix the menu code so this isn't necessary.
|
|
376 *
|
|
377 * Protect against reentering the menu code otherwise we will
|
|
378 * crash later when the code gets confused at the state
|
|
379 * changes.
|
|
380 */
|
|
381 count = specpdl_depth ();
|
|
382 record_unwind_protect (restore_in_menu_callback,
|
|
383 make_int (in_menu_callback));
|
|
384 in_menu_callback = 1;
|
0
|
385 wv = menu_item_descriptor_to_widget_value (submenu_desc, SUBMENU_TYPE,
|
114
|
386 1, 0);
|
138
|
387 unbind_to (count, Qnil);
|
|
388
|
0
|
389 if (!wv)
|
|
390 {
|
|
391 wv = xmalloc_widget_value ();
|
|
392 wv->type = CASCADE_TYPE;
|
|
393 wv->next = NULL;
|
|
394 wv->contents = xmalloc_widget_value ();
|
|
395 wv->contents->type = TEXT_TYPE;
|
2
|
396 wv->contents->name = (char *) "No menu";
|
0
|
397 wv->contents->next = NULL;
|
|
398 }
|
|
399 assert (wv && wv->type == CASCADE_TYPE && wv->contents);
|
|
400 replace_widget_value_tree (hack_wv, wv->contents);
|
|
401 free_popup_widget_value_tree (wv);
|
|
402 }
|
|
403 else
|
|
404 {
|
|
405 if (!POPUP_DATAP (FRAME_MENUBAR_DATA (f)))
|
|
406 return;
|
|
407 /* #### - this menubar update mechanism is expensively anti-social and
|
|
408 the activate-menubar-hook is now mostly obsolete. */
|
|
409 /* make the activate-menubar-hook be a list of functions, not a single
|
|
410 function, just to simplify things. */
|
|
411 if (!NILP (Vactivate_menubar_hook) &&
|
|
412 (!CONSP (Vactivate_menubar_hook) ||
|
|
413 EQ (XCAR (Vactivate_menubar_hook), Qlambda)))
|
|
414 Vactivate_menubar_hook = Fcons (Vactivate_menubar_hook, Qnil);
|
|
415
|
|
416 GCPRO1 (rest);
|
|
417 for (rest = Vactivate_menubar_hook; !NILP (rest); rest = Fcdr (rest))
|
|
418 if (!EQ (call0 (XCAR (rest)), Qt))
|
|
419 any_changes = 1;
|
|
420 #if 0
|
|
421 /* #### - It is necessary to *ALWAYS* call set_frame_menubar() now that
|
|
422 incremental menus are implemented. If a subtree of a menu has been
|
|
423 updated incrementally (a destructive operation), then that subtree
|
|
424 must somehow be wiped.
|
|
425
|
|
426 It is difficult to undo the destructive operation in lwlib because
|
|
427 a pointer back to lisp data needs to be hidden away somewhere. So
|
|
428 that an INCREMENTAL_TYPE widget_value can be recreated... Hmmmmm. */
|
|
429 if (any_changes ||
|
|
430 !XFRAME_MENUBAR_DATA (f)->menubar_contents_up_to_date)
|
|
431 #endif
|
|
432 set_frame_menubar (f, 1, 0);
|
|
433 UNGCPRO;
|
|
434 }
|
|
435 }
|
|
436
|
|
437 #ifdef ENERGIZE
|
|
438 extern int *get_psheets_for_buffer (Lisp_Object, int *);
|
|
439
|
|
440 static void
|
|
441 set_panel_button_sensitivity (struct frame *f, widget_value *data)
|
|
442 {
|
|
443 struct window *window = XWINDOW (FRAME_LAST_NONMINIBUF_WINDOW (f));
|
|
444 int current_buffer_psheets_count = 0;
|
|
445 int *current_buffer_psheets =
|
|
446 get_psheets_for_buffer (window->buffer, ¤t_buffer_psheets_count);
|
|
447 int panel_enabled = FRAME_X_DESIRED_PSHEETS (f) ||
|
|
448 current_buffer_psheets_count;
|
|
449 widget_value *val;
|
|
450 for (val = data->contents; val; val = val->next)
|
|
451 if (val->name && !strcmp (val->name, "sheet"))
|
|
452 {
|
|
453 val->enabled = panel_enabled;
|
|
454 return;
|
|
455 }
|
|
456 }
|
|
457 #endif /* ENERGIZE */
|
|
458
|
|
459 static widget_value *
|
|
460 compute_menubar_data (struct frame *f, Lisp_Object menubar, int deep_p)
|
|
461 {
|
|
462 widget_value *data;
|
|
463
|
|
464 if (NILP (menubar))
|
|
465 data = 0;
|
|
466 else
|
|
467 {
|
82
|
468 Lisp_Object old_buffer;
|
|
469 int count = specpdl_depth ();
|
|
470
|
|
471 old_buffer = Fcurrent_buffer ();
|
|
472 record_unwind_protect (Fset_buffer, old_buffer);
|
|
473 Fset_buffer ( XWINDOW (FRAME_SELECTED_WINDOW (f))->buffer);
|
0
|
474 data = menu_item_descriptor_to_widget_value (menubar, MENUBAR_TYPE,
|
|
475 deep_p, 0);
|
|
476 #ifdef ENERGIZE
|
|
477 if (data)
|
|
478 set_panel_button_sensitivity (f, data);
|
|
479 #endif
|
82
|
480 Fset_buffer (old_buffer);
|
|
481 unbind_to (count, Qnil);
|
0
|
482 }
|
|
483 return data;
|
|
484 }
|
|
485
|
|
486 static int
|
|
487 set_frame_menubar (struct frame *f, int deep_p, int first_time_p)
|
|
488 {
|
|
489 widget_value *data;
|
|
490 Lisp_Object menubar;
|
|
491 int menubar_visible;
|
|
492 long id;
|
|
493 /* As for the toolbar, the minibuffer does not have its own menubar. */
|
|
494 struct window *w = XWINDOW (FRAME_LAST_NONMINIBUF_WINDOW (f));
|
|
495
|
|
496 if (! FRAME_X_P (f))
|
|
497 return 0;
|
|
498
|
|
499 /***** first compute the contents of the menubar *****/
|
|
500
|
|
501 if (! first_time_p)
|
|
502 {
|
|
503 /* evaluate `current-menubar' in the buffer of the selected window
|
|
504 of the frame in question. */
|
|
505 menubar = symbol_value_in_buffer (Qcurrent_menubar, w->buffer);
|
|
506 }
|
|
507 else
|
|
508 {
|
|
509 /* That's a little tricky the first time since the frame isn't
|
|
510 fully initialized yet. */
|
|
511 menubar = Fsymbol_value (Qcurrent_menubar);
|
|
512 }
|
|
513
|
|
514 if (NILP (menubar))
|
|
515 {
|
|
516 menubar = Vblank_menubar;
|
|
517 menubar_visible = 0;
|
|
518 }
|
|
519 else
|
|
520 menubar_visible = !NILP (w->menubar_visible_p);
|
|
521
|
|
522 data = compute_menubar_data (f, menubar, deep_p);
|
|
523 if (!data || (!data->next && !data->contents))
|
|
524 abort ();
|
|
525
|
|
526 if (NILP (FRAME_MENUBAR_DATA (f)))
|
|
527 {
|
|
528 struct popup_data *mdata =
|
|
529 alloc_lcrecord (sizeof (struct popup_data), lrecord_popup_data);
|
|
530
|
|
531 mdata->id = new_lwlib_id ();
|
|
532 mdata->last_menubar_buffer = Qnil;
|
|
533 mdata->menubar_contents_up_to_date = 0;
|
|
534 XSETPOPUP_DATA (FRAME_MENUBAR_DATA (f), mdata);
|
|
535 }
|
|
536
|
|
537 /***** now store into the menubar widget, creating it if necessary *****/
|
|
538
|
|
539 id = XFRAME_MENUBAR_DATA (f)->id;
|
|
540 if (!FRAME_X_MENUBAR_WIDGET (f))
|
|
541 {
|
|
542 Widget parent = FRAME_X_CONTAINER_WIDGET (f);
|
|
543
|
|
544 assert (first_time_p);
|
|
545
|
|
546 /* It's the first time we've mapped the menubar so compute its
|
|
547 contents completely once. This makes sure that the menubar
|
|
548 components are created with the right type. */
|
|
549 if (!deep_p)
|
|
550 {
|
|
551 free_popup_widget_value_tree (data);
|
|
552 data = compute_menubar_data (f, menubar, 1);
|
|
553 }
|
|
554
|
|
555
|
|
556 FRAME_X_MENUBAR_WIDGET (f) =
|
|
557 lw_create_widget ("menubar", "menubar", id, data, parent,
|
|
558 0, pre_activate_callback,
|
|
559 popup_selection_callback, 0);
|
|
560
|
|
561 }
|
|
562 else
|
|
563 {
|
|
564 lw_modify_all_widgets (id, data, deep_p ? True : False);
|
|
565 }
|
|
566 free_popup_widget_value_tree (data);
|
|
567
|
|
568 XFRAME_MENUBAR_DATA (f)->menubar_contents_up_to_date = deep_p;
|
|
569 XFRAME_MENUBAR_DATA (f)->last_menubar_buffer =
|
|
570 XWINDOW (FRAME_LAST_NONMINIBUF_WINDOW (f))->buffer;
|
|
571 return menubar_visible;
|
|
572 }
|
|
573
|
|
574
|
|
575 /* Called from x_create_widgets() to create the inital menubar of a frame
|
|
576 before it is mapped, so that the window is mapped with the menubar already
|
|
577 there instead of us tacking it on later and thrashing the window after it
|
|
578 is visible. */
|
|
579 int
|
|
580 x_initialize_frame_menubar (struct frame *f)
|
|
581 {
|
|
582 return set_frame_menubar (f, 1, 1);
|
|
583 }
|
|
584
|
|
585
|
|
586 static LWLIB_ID last_popup_menu_selection_callback_id;
|
|
587
|
|
588 static void
|
|
589 popup_menu_selection_callback (Widget widget, LWLIB_ID id,
|
|
590 XtPointer client_data)
|
|
591 {
|
|
592 last_popup_menu_selection_callback_id = id;
|
|
593 popup_selection_callback (widget, id, client_data);
|
|
594 /* lw_destroy_all_widgets() will be called from popup_down_callback() */
|
|
595 }
|
|
596
|
|
597 static void
|
|
598 popup_menu_down_callback (Widget widget, LWLIB_ID id, XtPointer client_data)
|
|
599 {
|
|
600 if (popup_handled_p (id))
|
|
601 return;
|
|
602 assert (popup_up_p != 0);
|
|
603 ungcpro_popup_callbacks (id);
|
|
604 popup_up_p--;
|
|
605 /* if this isn't called immediately after the selection callback, then
|
|
606 there wasn't a menu selection. */
|
|
607 if (id != last_popup_menu_selection_callback_id)
|
|
608 popup_selection_callback (widget, id, (XtPointer) -1);
|
|
609 lw_destroy_all_widgets (id);
|
|
610 }
|
|
611
|
|
612
|
|
613 static void
|
|
614 make_dummy_xbutton_event (XEvent *dummy,
|
|
615 Widget daddy,
|
|
616 struct Lisp_Event *eev)
|
|
617 /* NULL for eev means query pointer */
|
|
618 {
|
|
619 XButtonPressedEvent *btn = (XButtonPressedEvent *) dummy;
|
|
620
|
|
621 btn->type = ButtonPress;
|
|
622 btn->serial = 0;
|
|
623 btn->send_event = 0;
|
|
624 btn->display = XtDisplay (daddy);
|
|
625 btn->window = XtWindow (daddy);
|
|
626 if (eev)
|
|
627 {
|
|
628 Position shellx, shelly, framex, framey;
|
|
629 Widget shell = XtParent (daddy);
|
|
630 btn->time = eev->timestamp;
|
|
631 btn->button = eev->event.button.button;
|
|
632 btn->root = RootWindowOfScreen (XtScreen (daddy));
|
|
633 btn->subwindow = (Window) NULL;
|
|
634 btn->x = eev->event.button.x;
|
|
635 btn->y = eev->event.button.y;
|
|
636 XtVaGetValues (shell, XtNx, &shellx, XtNy, &shelly, NULL);
|
|
637 XtVaGetValues (daddy, XtNx, &framex, XtNy, &framey, NULL);
|
|
638 btn->x_root = shellx + framex + btn->x;
|
|
639 btn->y_root = shelly + framey + btn->y;;
|
|
640 btn->state = ButtonPressMask; /* all buttons pressed */
|
|
641 }
|
|
642 else
|
|
643 {
|
|
644 /* CurrentTime is just ZERO, so it's worthless for
|
|
645 determining relative click times. */
|
|
646 struct device *d = get_device_from_display (XtDisplay (daddy));
|
|
647 btn->time = DEVICE_X_MOUSE_TIMESTAMP (d); /* event-Xt maintains this */
|
|
648 btn->button = 0;
|
|
649 XQueryPointer (btn->display, btn->window, &btn->root,
|
|
650 &btn->subwindow, &btn->x_root, &btn->y_root,
|
|
651 &btn->x, &btn->y, &btn->state);
|
|
652 }
|
|
653 }
|
|
654
|
|
655
|
|
656 #ifdef ENERGIZE
|
|
657 extern int desired_debuggerpanel_exposed_p;
|
|
658 extern int current_debuggerpanel_exposed_p;
|
|
659 extern int debuggerpanel_sheet;
|
|
660 extern void notify_energize_sheet_hidden (unsigned long);
|
|
661 #endif
|
|
662
|
|
663 static void
|
|
664 x_update_frame_menubar_internal (struct frame *f)
|
|
665 {
|
|
666 /* We assume the menubar contents has changed if the global flag is set,
|
|
667 or if the current buffer has changed, or if the menubar has never
|
|
668 been updated before.
|
|
669 */
|
|
670 int menubar_contents_changed =
|
|
671 (f->menubar_changed
|
|
672 || NILP (FRAME_MENUBAR_DATA (f))
|
|
673 || (!EQ (XFRAME_MENUBAR_DATA (f)->last_menubar_buffer,
|
|
674 XWINDOW (FRAME_LAST_NONMINIBUF_WINDOW (f))->buffer)));
|
|
675
|
102
|
676 Boolean menubar_was_visible = XtIsManaged (FRAME_X_MENUBAR_WIDGET (f));
|
|
677 Boolean menubar_will_be_visible = menubar_was_visible;
|
|
678 Boolean menubar_visibility_changed;
|
0
|
679 Cardinal new_num_top_widgets = 1; /* for the menubar */
|
|
680 Widget container = FRAME_X_CONTAINER_WIDGET (f);
|
|
681
|
|
682 #ifdef ENERGIZE
|
|
683 int *old_sheets = FRAME_X_CURRENT_PSHEETS (f);
|
|
684 int *new_sheets = FRAME_X_DESIRED_PSHEETS (f);
|
|
685 int old_count = FRAME_X_CURRENT_PSHEET_COUNT (f);
|
|
686 int new_count = FRAME_X_DESIRED_PSHEET_COUNT (f);
|
|
687 Lisp_Object old_buf = FRAME_X_CURRENT_PSHEET_BUFFER (f);
|
|
688 Lisp_Object new_buf = FRAME_X_DESIRED_PSHEET_BUFFER (f);
|
|
689 int psheets_changed = (old_sheets != new_sheets
|
|
690 || old_count != new_count
|
|
691 || !EQ (old_buf, new_buf));
|
|
692 int debuggerpanel_changed = (desired_debuggerpanel_exposed_p
|
|
693 != current_debuggerpanel_exposed_p);
|
|
694
|
|
695 if (desired_debuggerpanel_exposed_p && FRAME_X_TOP_WIDGETS (f) [1] == 0)
|
|
696 /* This happens when the frame was just created. */
|
|
697 debuggerpanel_changed = 1;
|
|
698
|
|
699 FRAME_X_CURRENT_PSHEETS (f) = FRAME_X_DESIRED_PSHEETS (f);
|
|
700 FRAME_X_CURRENT_PSHEET_COUNT (f) = FRAME_X_DESIRED_PSHEET_COUNT (f);
|
|
701 FRAME_X_CURRENT_PSHEET_BUFFER (f) = FRAME_X_DESIRED_PSHEET_BUFFER (f);
|
|
702 #endif /* ENERGIZE */
|
|
703
|
|
704 if (menubar_contents_changed)
|
|
705 menubar_will_be_visible = set_frame_menubar (f, 0, 0);
|
|
706
|
|
707 menubar_visibility_changed = menubar_was_visible != menubar_will_be_visible;
|
|
708
|
|
709 if (! (menubar_visibility_changed
|
|
710 #ifdef ENERGIZE
|
|
711 || psheets_changed || debuggerpanel_changed
|
|
712 #endif
|
|
713 ))
|
|
714 return;
|
|
715
|
|
716
|
|
717 /* Set menubar visibility */
|
|
718 if (menubar_visibility_changed)
|
|
719 (menubar_will_be_visible ? XtManageChild : XtUnmanageChild)
|
|
720 (FRAME_X_MENUBAR_WIDGET (f));
|
|
721
|
|
722
|
|
723 #ifdef ENERGIZE
|
|
724 /* Set debugger panel visibility */
|
|
725 if (debuggerpanel_changed)
|
|
726 {
|
|
727 Widget w;
|
|
728 int sheet = debuggerpanel_sheet;
|
|
729
|
|
730 w = lw_get_widget (sheet, container, 0);
|
|
731 if (desired_debuggerpanel_exposed_p)
|
|
732 {
|
|
733 if (! w)
|
|
734 w = lw_make_widget (sheet, container, 0);
|
|
735 FRAME_X_TOP_WIDGETS (f)[1] = w;
|
|
736 XtManageChild (w);
|
|
737 }
|
|
738 else
|
|
739 {
|
|
740 notify_energize_sheet_hidden (sheet);
|
|
741 if (w)
|
|
742 XtUnmanageChild (w);
|
|
743 }
|
|
744 }
|
|
745
|
|
746 /* Set psheet visibility. For the moment we just unmanage all the old
|
|
747 ones, and then manage all the new ones. If the number of psheets
|
|
748 ever becomes a large number (i.e. > 1), then we can worry about a
|
|
749 more sophisticated way of doing this. */
|
|
750 if (psheets_changed)
|
|
751 {
|
|
752 int i;
|
|
753 Widget w;
|
|
754 unsigned long sheet;
|
|
755
|
|
756 for (i=0; i<old_count; i++)
|
|
757 {
|
|
758 sheet = old_sheets[i];
|
|
759 w = lw_get_widget (sheet, container, 0);
|
|
760 notify_energize_sheet_hidden (sheet);
|
|
761 if (w)
|
|
762 XtUnmanageChild (w);
|
|
763 }
|
|
764
|
|
765 for (i=0; i<new_count; i++)
|
|
766 {
|
|
767 sheet = new_sheets[i];
|
|
768 /* #### This unconditional call to lw_make_widget() is a bad
|
|
769 idea. Doesn't it cause a memory leak if the widget
|
|
770 already exists?
|
|
771
|
|
772 #### How does Energize know that a sheet just got displayed?
|
|
773 #### Energize knows all. */
|
|
774 w = lw_make_widget (sheet, container, 0);
|
|
775 FRAME_X_TOP_WIDGETS (f)[2+i] = w;
|
|
776 XtManageChild (w);
|
|
777 }
|
|
778 }
|
|
779
|
|
780 new_num_top_widgets += 1+new_count;
|
|
781 #endif /* ENERGIZE */
|
|
782
|
|
783 /* Note that new_num_top_widgets doesn't need to reflect the actual
|
|
784 number of top widgets, but just the limit of FRAME_X_TOP_WIDGETS (f)[]. */
|
|
785 FRAME_X_NUM_TOP_WIDGETS (f) = new_num_top_widgets;
|
|
786 {
|
|
787 /* We want to end up as close in size as possible to what we
|
|
788 were before. So, ask the EmacsManager what size it wants
|
|
789 to be (suggesting the current size), and resize it to that
|
|
790 size. It in turn will call our query-geometry callback,
|
|
791 which will round the size to something that exactly fits
|
|
792 the text widget. */
|
|
793 XtWidgetGeometry req, repl;
|
|
794
|
|
795 req.request_mode = CWWidth | CWHeight;
|
|
796 XtVaGetValues (container,
|
|
797 XtNwidth, &req.width,
|
|
798 XtNheight, &req.height,
|
|
799 0);
|
|
800 XtQueryGeometry (container, &req, &repl);
|
|
801 EmacsManagerChangeSize (container, repl.width,
|
|
802 repl.height);
|
|
803 /* The window size might not have changed but the text size
|
|
804 did; thus, the base size might be incorrect. So update
|
|
805 it. */
|
|
806 EmacsShellUpdateSizeHints (FRAME_X_SHELL_WIDGET (f));
|
|
807 }
|
|
808
|
|
809 #ifdef ENERGIZE
|
|
810 /* Give back the focus to emacs if no psheets are displayed anymore */
|
|
811 if (psheets_changed)
|
|
812 {
|
|
813 Lisp_Object frame;
|
|
814 XSETFRAME (frame, f);
|
|
815 Fselect_frame (frame);
|
|
816 }
|
|
817 #endif /* ENERGIZE */
|
|
818 }
|
|
819
|
|
820 static void
|
|
821 x_update_frame_menubars (struct frame *f)
|
|
822 {
|
|
823 assert (FRAME_X_P (f));
|
|
824
|
|
825 x_update_frame_menubar_internal (f);
|
|
826
|
|
827 /* #### This isn't going to work right now that this function works on
|
|
828 a per-frame, not per-device basis. Guess what? I don't care. */
|
|
829 #ifdef ENERGIZE
|
|
830 current_debuggerpanel_exposed_p = desired_debuggerpanel_exposed_p;
|
|
831 #endif
|
|
832 }
|
|
833
|
|
834 static void
|
|
835 x_free_frame_menubars (struct frame *f)
|
|
836 {
|
|
837 Widget menubar_widget;
|
|
838
|
|
839 assert (FRAME_X_P (f));
|
|
840
|
|
841 menubar_widget = FRAME_X_MENUBAR_WIDGET (f);
|
|
842 if (menubar_widget)
|
|
843 {
|
|
844 LWLIB_ID id = XFRAME_MENUBAR_DATA (f)->id;
|
|
845 lw_destroy_all_widgets (id);
|
|
846 XFRAME_MENUBAR_DATA (f)->id = 0;
|
|
847 }
|
|
848
|
|
849 #ifdef ENERGIZE
|
|
850 {
|
|
851 /* Also destroy this frame's psheets */
|
|
852 Widget parent = FRAME_X_CONTAINER_WIDGET (f);
|
|
853 int *sheets = FRAME_X_CURRENT_PSHEETS (f);
|
|
854 int i = FRAME_X_CURRENT_PSHEET_COUNT (f);
|
|
855 while (i--)
|
|
856 {
|
|
857 unsigned long sheet = sheets [i];
|
|
858 Widget w = lw_get_widget (sheet, parent, 0);
|
|
859 if (w)
|
|
860 lw_destroy_widget (w);
|
|
861 }
|
|
862 FRAME_X_CURRENT_PSHEET_COUNT (f) = 0;
|
|
863
|
|
864 /* Is this necessary? */
|
|
865 sheets = FRAME_X_DESIRED_PSHEETS (f);
|
|
866 i = FRAME_X_DESIRED_PSHEET_COUNT (f);
|
|
867 while (i--)
|
|
868 {
|
|
869 unsigned long sheet = sheets [i];
|
|
870 Widget w = lw_get_widget (sheet, parent, 0);
|
|
871 if (w)
|
|
872 lw_destroy_widget (w);
|
|
873 }
|
|
874 FRAME_X_DESIRED_PSHEET_COUNT (f) = 0;
|
|
875
|
|
876 /* sigh... debugger panel is special... */
|
|
877 if (debuggerpanel_sheet)
|
|
878 {
|
|
879 Widget w = lw_get_widget (debuggerpanel_sheet, parent, 0);
|
|
880 if (w)
|
|
881 lw_destroy_widget (w);
|
|
882 }
|
|
883 }
|
|
884 #endif /* ENERGIZE */
|
|
885 }
|
|
886
|
|
887 static void
|
|
888 x_popup_menu (Lisp_Object menu_desc, Lisp_Object event)
|
|
889 {
|
|
890 int menu_id;
|
|
891 struct frame *f = selected_frame ();
|
|
892 widget_value *data;
|
|
893 Widget parent;
|
|
894 Widget menu;
|
|
895 struct Lisp_Event *eev = NULL;
|
|
896 XEvent xev;
|
|
897 Lisp_Object frame = Qnil;
|
|
898
|
|
899 XSETFRAME (frame, f);
|
|
900 CHECK_X_FRAME (frame);
|
|
901 parent = FRAME_X_SHELL_WIDGET (f);
|
|
902
|
|
903 if (!NILP (event))
|
|
904 {
|
|
905 CHECK_LIVE_EVENT (event);
|
|
906 eev= XEVENT (event);
|
|
907 if (eev->event_type != button_press_event
|
|
908 && eev->event_type != button_release_event)
|
|
909 wrong_type_argument (Qmouse_event_p, event);
|
|
910 }
|
|
911 else if (!NILP (Vthis_command_keys))
|
|
912 {
|
|
913 /* if an event wasn't passed, use the last event of the event sequence
|
|
914 currently being executed, if that event is a mouse event */
|
|
915 eev = XEVENT (Vthis_command_keys); /* last event first */
|
|
916 if (eev->event_type != button_press_event
|
|
917 && eev->event_type != button_release_event)
|
|
918 eev = NULL;
|
|
919 }
|
|
920 make_dummy_xbutton_event (&xev, parent, eev);
|
|
921
|
|
922 if (SYMBOLP (menu_desc))
|
|
923 menu_desc = Fsymbol_value (menu_desc);
|
|
924 CHECK_CONS (menu_desc);
|
|
925 CHECK_STRING (XCAR (menu_desc));
|
|
926 data = menu_item_descriptor_to_widget_value (menu_desc, POPUP_TYPE, 1, 1);
|
|
927
|
|
928 if (! data) error ("no menu");
|
|
929
|
|
930 menu_id = new_lwlib_id ();
|
|
931 menu = lw_create_widget ("popup", "popup" /* data->name */, menu_id, data,
|
|
932 parent, 1, 0,
|
|
933 popup_menu_selection_callback,
|
|
934 popup_menu_down_callback);
|
|
935 free_popup_widget_value_tree (data);
|
|
936
|
|
937 gcpro_popup_callbacks (menu_id);
|
|
938
|
|
939 /* Setting zmacs-region-stays is necessary here because executing a command
|
|
940 from a menu is really a two-command process: the first command (bound to
|
|
941 the button-click) simply pops up the menu, and returns. This causes a
|
|
942 sequence of magic-events (destined for the popup-menu widget) to begin.
|
|
943 Eventually, a menu item is selected, and a menu-event blip is pushed onto
|
|
944 the end of the input stream, which is then executed by the event loop.
|
|
945
|
|
946 So there are two command-events, with a bunch of magic-events between
|
|
947 them. We don't want the *first* command event to alter the state of the
|
|
948 region, so that the region can be available as an argument for the second
|
|
949 command.
|
|
950 */
|
|
951 if (zmacs_regions)
|
|
952 zmacs_region_stays = 1;
|
|
953
|
|
954 popup_up_p++;
|
|
955 lw_popup_menu (menu, &xev);
|
|
956 /* this speeds up display of pop-up menus */
|
|
957 XFlush (XtDisplay (parent));
|
|
958 }
|
|
959
|
|
960
|
|
961 void
|
|
962 syms_of_menubar_x (void)
|
|
963 {
|
|
964 }
|
|
965
|
|
966 void
|
|
967 console_type_create_menubar_x (void)
|
|
968 {
|
|
969 CONSOLE_HAS_METHOD (x, update_frame_menubars);
|
|
970 CONSOLE_HAS_METHOD (x, free_frame_menubars);
|
|
971 CONSOLE_HAS_METHOD (x, popup_menu);
|
|
972 }
|
|
973
|
|
974 void
|
|
975 vars_of_menubar_x (void)
|
|
976 {
|
|
977 last_popup_menu_selection_callback_id = -1;
|
|
978
|
|
979 #if defined (LWLIB_MENUBARS_LUCID)
|
|
980 Fprovide (intern ("lucid-menubars"));
|
|
981 #elif defined (LWLIB_MENUBARS_MOTIF)
|
|
982 Fprovide (intern ("motif-menubars"));
|
|
983 #elif defined (LWLIB_MENUBARS_ATHENA)
|
|
984 Fprovide (intern ("athena-menubars"));
|
|
985 #endif
|
|
986 }
|