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
|
|
311 /* The order in which callbacks are run is funny to say the least.
|
|
312 It's sometimes tricky to avoid running a callback twice, and to
|
|
313 avoid returning prematurely. So, this function returns true
|
|
314 if the menu's callbacks are no longer gc protected. So long
|
|
315 as we unprotect them before allowing other callbacks to run,
|
|
316 everything should be ok.
|
|
317
|
|
318 The pre_activate_callback() *IS* intentionally called multiple times.
|
|
319 If client_data == NULL, then it's being called before the menu is posted.
|
|
320 If client_data != NULL, then client_data is a (widget_value *) and
|
|
321 client_data->data is a Lisp_Object pointing to a lisp submenu description
|
|
322 that must be converted into widget_values. *client_data is destructively
|
|
323 modified.
|
|
324
|
|
325 #### Stig thinks that there may be a GC problem here due to the
|
|
326 fact that pre_activate_callback() is called multiple times, but I
|
|
327 think he's wrong.
|
|
328
|
|
329 */
|
|
330
|
|
331 static void
|
|
332 pre_activate_callback (Widget widget, LWLIB_ID id, XtPointer client_data)
|
|
333 {
|
|
334 /* This function can GC */
|
|
335 struct gcpro gcpro1;
|
|
336 struct device *d = get_device_from_display (XtDisplay (widget));
|
|
337 struct frame *f = x_any_window_to_frame (d, XtWindow (widget));
|
|
338 Lisp_Object rest = Qnil;
|
16
|
339 Lisp_Object frame;
|
0
|
340 int any_changes = 0;
|
|
341
|
|
342 if (!f)
|
|
343 f = x_any_window_to_frame (d, XtWindow (XtParent (widget)));
|
|
344 if (!f)
|
|
345 return;
|
|
346
|
16
|
347 /* make sure f is the selected frame */
|
|
348 XSETFRAME (frame, f);
|
|
349 Fselect_frame (frame);
|
|
350
|
0
|
351 if (client_data)
|
|
352 {
|
|
353 /* this is an incremental menu construction callback */
|
|
354 widget_value *hack_wv = (widget_value *) client_data;
|
|
355 Lisp_Object submenu_desc;
|
|
356 widget_value *wv;
|
|
357
|
|
358 assert (hack_wv->type == INCREMENTAL_TYPE);
|
|
359 VOID_TO_LISP (submenu_desc, hack_wv->call_data);
|
|
360 wv = menu_item_descriptor_to_widget_value (submenu_desc, SUBMENU_TYPE,
|
|
361 1, 1);
|
|
362 if (!wv)
|
|
363 {
|
|
364 wv = xmalloc_widget_value ();
|
|
365 wv->type = CASCADE_TYPE;
|
|
366 wv->next = NULL;
|
|
367 wv->contents = xmalloc_widget_value ();
|
|
368 wv->contents->type = TEXT_TYPE;
|
2
|
369 wv->contents->name = (char *) "No menu";
|
0
|
370 wv->contents->next = NULL;
|
|
371 }
|
|
372 assert (wv && wv->type == CASCADE_TYPE && wv->contents);
|
|
373 replace_widget_value_tree (hack_wv, wv->contents);
|
|
374 free_popup_widget_value_tree (wv);
|
|
375 }
|
|
376 else
|
|
377 {
|
|
378 if (!POPUP_DATAP (FRAME_MENUBAR_DATA (f)))
|
|
379 return;
|
|
380 /* #### - this menubar update mechanism is expensively anti-social and
|
|
381 the activate-menubar-hook is now mostly obsolete. */
|
|
382 /* make the activate-menubar-hook be a list of functions, not a single
|
|
383 function, just to simplify things. */
|
|
384 if (!NILP (Vactivate_menubar_hook) &&
|
|
385 (!CONSP (Vactivate_menubar_hook) ||
|
|
386 EQ (XCAR (Vactivate_menubar_hook), Qlambda)))
|
|
387 Vactivate_menubar_hook = Fcons (Vactivate_menubar_hook, Qnil);
|
|
388
|
|
389 GCPRO1 (rest);
|
|
390 for (rest = Vactivate_menubar_hook; !NILP (rest); rest = Fcdr (rest))
|
|
391 if (!EQ (call0 (XCAR (rest)), Qt))
|
|
392 any_changes = 1;
|
|
393 #if 0
|
|
394 /* #### - It is necessary to *ALWAYS* call set_frame_menubar() now that
|
|
395 incremental menus are implemented. If a subtree of a menu has been
|
|
396 updated incrementally (a destructive operation), then that subtree
|
|
397 must somehow be wiped.
|
|
398
|
|
399 It is difficult to undo the destructive operation in lwlib because
|
|
400 a pointer back to lisp data needs to be hidden away somewhere. So
|
|
401 that an INCREMENTAL_TYPE widget_value can be recreated... Hmmmmm. */
|
|
402 if (any_changes ||
|
|
403 !XFRAME_MENUBAR_DATA (f)->menubar_contents_up_to_date)
|
|
404 #endif
|
|
405 set_frame_menubar (f, 1, 0);
|
|
406 UNGCPRO;
|
|
407 }
|
|
408 }
|
|
409
|
|
410 #ifdef ENERGIZE
|
|
411 extern int *get_psheets_for_buffer (Lisp_Object, int *);
|
|
412
|
|
413 static void
|
|
414 set_panel_button_sensitivity (struct frame *f, widget_value *data)
|
|
415 {
|
|
416 struct window *window = XWINDOW (FRAME_LAST_NONMINIBUF_WINDOW (f));
|
|
417 int current_buffer_psheets_count = 0;
|
|
418 int *current_buffer_psheets =
|
|
419 get_psheets_for_buffer (window->buffer, ¤t_buffer_psheets_count);
|
|
420 int panel_enabled = FRAME_X_DESIRED_PSHEETS (f) ||
|
|
421 current_buffer_psheets_count;
|
|
422 widget_value *val;
|
|
423 for (val = data->contents; val; val = val->next)
|
|
424 if (val->name && !strcmp (val->name, "sheet"))
|
|
425 {
|
|
426 val->enabled = panel_enabled;
|
|
427 return;
|
|
428 }
|
|
429 }
|
|
430 #endif /* ENERGIZE */
|
|
431
|
|
432 static widget_value *
|
|
433 compute_menubar_data (struct frame *f, Lisp_Object menubar, int deep_p)
|
|
434 {
|
|
435 widget_value *data;
|
|
436
|
|
437 if (NILP (menubar))
|
|
438 data = 0;
|
|
439 else
|
|
440 {
|
16
|
441 Lisp_Object old_buffer;
|
|
442 int count = specpdl_depth ();
|
|
443
|
|
444 old_buffer = Fcurrent_buffer ();
|
|
445 record_unwind_protect (Fset_buffer, old_buffer);
|
|
446 Fset_buffer ( XWINDOW (FRAME_SELECTED_WINDOW (f))->buffer);
|
0
|
447 data = menu_item_descriptor_to_widget_value (menubar, MENUBAR_TYPE,
|
|
448 deep_p, 0);
|
|
449 #ifdef ENERGIZE
|
|
450 if (data)
|
|
451 set_panel_button_sensitivity (f, data);
|
|
452 #endif
|
16
|
453 Fset_buffer (old_buffer);
|
|
454 unbind_to (count, Qnil);
|
0
|
455 }
|
|
456 return data;
|
|
457 }
|
|
458
|
|
459 static int
|
|
460 set_frame_menubar (struct frame *f, int deep_p, int first_time_p)
|
|
461 {
|
|
462 widget_value *data;
|
|
463 Lisp_Object menubar;
|
|
464 int menubar_visible;
|
|
465 long id;
|
|
466 /* As for the toolbar, the minibuffer does not have its own menubar. */
|
|
467 struct window *w = XWINDOW (FRAME_LAST_NONMINIBUF_WINDOW (f));
|
|
468
|
|
469 if (! FRAME_X_P (f))
|
|
470 return 0;
|
|
471
|
|
472 /***** first compute the contents of the menubar *****/
|
|
473
|
|
474 if (! first_time_p)
|
|
475 {
|
|
476 /* evaluate `current-menubar' in the buffer of the selected window
|
|
477 of the frame in question. */
|
|
478 menubar = symbol_value_in_buffer (Qcurrent_menubar, w->buffer);
|
|
479 }
|
|
480 else
|
|
481 {
|
|
482 /* That's a little tricky the first time since the frame isn't
|
|
483 fully initialized yet. */
|
|
484 menubar = Fsymbol_value (Qcurrent_menubar);
|
|
485 }
|
|
486
|
|
487 if (NILP (menubar))
|
|
488 {
|
|
489 menubar = Vblank_menubar;
|
|
490 menubar_visible = 0;
|
|
491 }
|
|
492 else
|
|
493 menubar_visible = !NILP (w->menubar_visible_p);
|
|
494
|
|
495 data = compute_menubar_data (f, menubar, deep_p);
|
|
496 if (!data || (!data->next && !data->contents))
|
|
497 abort ();
|
|
498
|
|
499 if (NILP (FRAME_MENUBAR_DATA (f)))
|
|
500 {
|
|
501 struct popup_data *mdata =
|
|
502 alloc_lcrecord (sizeof (struct popup_data), lrecord_popup_data);
|
|
503
|
|
504 mdata->id = new_lwlib_id ();
|
|
505 mdata->last_menubar_buffer = Qnil;
|
|
506 mdata->menubar_contents_up_to_date = 0;
|
|
507 XSETPOPUP_DATA (FRAME_MENUBAR_DATA (f), mdata);
|
|
508 }
|
|
509
|
|
510 /***** now store into the menubar widget, creating it if necessary *****/
|
|
511
|
|
512 id = XFRAME_MENUBAR_DATA (f)->id;
|
|
513 if (!FRAME_X_MENUBAR_WIDGET (f))
|
|
514 {
|
|
515 Widget parent = FRAME_X_CONTAINER_WIDGET (f);
|
|
516
|
|
517 assert (first_time_p);
|
|
518
|
|
519 /* It's the first time we've mapped the menubar so compute its
|
|
520 contents completely once. This makes sure that the menubar
|
|
521 components are created with the right type. */
|
|
522 if (!deep_p)
|
|
523 {
|
|
524 free_popup_widget_value_tree (data);
|
|
525 data = compute_menubar_data (f, menubar, 1);
|
|
526 }
|
|
527
|
|
528
|
|
529 FRAME_X_MENUBAR_WIDGET (f) =
|
|
530 lw_create_widget ("menubar", "menubar", id, data, parent,
|
|
531 0, pre_activate_callback,
|
|
532 popup_selection_callback, 0);
|
|
533
|
|
534 }
|
|
535 else
|
|
536 {
|
|
537 lw_modify_all_widgets (id, data, deep_p ? True : False);
|
|
538 }
|
|
539 free_popup_widget_value_tree (data);
|
|
540
|
|
541 XFRAME_MENUBAR_DATA (f)->menubar_contents_up_to_date = deep_p;
|
|
542 XFRAME_MENUBAR_DATA (f)->last_menubar_buffer =
|
|
543 XWINDOW (FRAME_LAST_NONMINIBUF_WINDOW (f))->buffer;
|
|
544 return menubar_visible;
|
|
545 }
|
|
546
|
|
547
|
|
548 /* Called from x_create_widgets() to create the inital menubar of a frame
|
|
549 before it is mapped, so that the window is mapped with the menubar already
|
|
550 there instead of us tacking it on later and thrashing the window after it
|
|
551 is visible. */
|
|
552 int
|
|
553 x_initialize_frame_menubar (struct frame *f)
|
|
554 {
|
|
555 return set_frame_menubar (f, 1, 1);
|
|
556 }
|
|
557
|
|
558
|
|
559 static LWLIB_ID last_popup_menu_selection_callback_id;
|
|
560
|
|
561 static void
|
|
562 popup_menu_selection_callback (Widget widget, LWLIB_ID id,
|
|
563 XtPointer client_data)
|
|
564 {
|
|
565 last_popup_menu_selection_callback_id = id;
|
|
566 popup_selection_callback (widget, id, client_data);
|
|
567 /* lw_destroy_all_widgets() will be called from popup_down_callback() */
|
|
568 }
|
|
569
|
|
570 static void
|
|
571 popup_menu_down_callback (Widget widget, LWLIB_ID id, XtPointer client_data)
|
|
572 {
|
|
573 if (popup_handled_p (id))
|
|
574 return;
|
|
575 assert (popup_up_p != 0);
|
|
576 ungcpro_popup_callbacks (id);
|
|
577 popup_up_p--;
|
|
578 /* if this isn't called immediately after the selection callback, then
|
|
579 there wasn't a menu selection. */
|
|
580 if (id != last_popup_menu_selection_callback_id)
|
|
581 popup_selection_callback (widget, id, (XtPointer) -1);
|
|
582 lw_destroy_all_widgets (id);
|
|
583 }
|
|
584
|
|
585
|
|
586 static void
|
|
587 make_dummy_xbutton_event (XEvent *dummy,
|
|
588 Widget daddy,
|
|
589 struct Lisp_Event *eev)
|
|
590 /* NULL for eev means query pointer */
|
|
591 {
|
|
592 XButtonPressedEvent *btn = (XButtonPressedEvent *) dummy;
|
|
593
|
|
594 btn->type = ButtonPress;
|
|
595 btn->serial = 0;
|
|
596 btn->send_event = 0;
|
|
597 btn->display = XtDisplay (daddy);
|
|
598 btn->window = XtWindow (daddy);
|
|
599 if (eev)
|
|
600 {
|
|
601 Position shellx, shelly, framex, framey;
|
|
602 Widget shell = XtParent (daddy);
|
|
603 btn->time = eev->timestamp;
|
|
604 btn->button = eev->event.button.button;
|
|
605 btn->root = RootWindowOfScreen (XtScreen (daddy));
|
|
606 btn->subwindow = (Window) NULL;
|
|
607 btn->x = eev->event.button.x;
|
|
608 btn->y = eev->event.button.y;
|
|
609 XtVaGetValues (shell, XtNx, &shellx, XtNy, &shelly, NULL);
|
|
610 XtVaGetValues (daddy, XtNx, &framex, XtNy, &framey, NULL);
|
|
611 btn->x_root = shellx + framex + btn->x;
|
|
612 btn->y_root = shelly + framey + btn->y;;
|
|
613 btn->state = ButtonPressMask; /* all buttons pressed */
|
|
614 }
|
|
615 else
|
|
616 {
|
|
617 /* CurrentTime is just ZERO, so it's worthless for
|
|
618 determining relative click times. */
|
|
619 struct device *d = get_device_from_display (XtDisplay (daddy));
|
|
620 btn->time = DEVICE_X_MOUSE_TIMESTAMP (d); /* event-Xt maintains this */
|
|
621 btn->button = 0;
|
|
622 XQueryPointer (btn->display, btn->window, &btn->root,
|
|
623 &btn->subwindow, &btn->x_root, &btn->y_root,
|
|
624 &btn->x, &btn->y, &btn->state);
|
|
625 }
|
|
626 }
|
|
627
|
|
628
|
|
629 #ifdef ENERGIZE
|
|
630 extern int desired_debuggerpanel_exposed_p;
|
|
631 extern int current_debuggerpanel_exposed_p;
|
|
632 extern int debuggerpanel_sheet;
|
|
633 extern void notify_energize_sheet_hidden (unsigned long);
|
|
634 #endif
|
|
635
|
|
636 static void
|
|
637 x_update_frame_menubar_internal (struct frame *f)
|
|
638 {
|
|
639 /* We assume the menubar contents has changed if the global flag is set,
|
|
640 or if the current buffer has changed, or if the menubar has never
|
|
641 been updated before.
|
|
642 */
|
|
643 int menubar_contents_changed =
|
|
644 (f->menubar_changed
|
|
645 || NILP (FRAME_MENUBAR_DATA (f))
|
|
646 || (!EQ (XFRAME_MENUBAR_DATA (f)->last_menubar_buffer,
|
|
647 XWINDOW (FRAME_LAST_NONMINIBUF_WINDOW (f))->buffer)));
|
|
648
|
26
|
649 Boolean menubar_was_visible = XtIsManaged (FRAME_X_MENUBAR_WIDGET (f));
|
|
650 Boolean menubar_will_be_visible = menubar_was_visible;
|
|
651 Boolean menubar_visibility_changed;
|
0
|
652 Cardinal new_num_top_widgets = 1; /* for the menubar */
|
|
653 Widget container = FRAME_X_CONTAINER_WIDGET (f);
|
|
654
|
|
655 #ifdef ENERGIZE
|
|
656 int *old_sheets = FRAME_X_CURRENT_PSHEETS (f);
|
|
657 int *new_sheets = FRAME_X_DESIRED_PSHEETS (f);
|
|
658 int old_count = FRAME_X_CURRENT_PSHEET_COUNT (f);
|
|
659 int new_count = FRAME_X_DESIRED_PSHEET_COUNT (f);
|
|
660 Lisp_Object old_buf = FRAME_X_CURRENT_PSHEET_BUFFER (f);
|
|
661 Lisp_Object new_buf = FRAME_X_DESIRED_PSHEET_BUFFER (f);
|
|
662 int psheets_changed = (old_sheets != new_sheets
|
|
663 || old_count != new_count
|
|
664 || !EQ (old_buf, new_buf));
|
|
665 int debuggerpanel_changed = (desired_debuggerpanel_exposed_p
|
|
666 != current_debuggerpanel_exposed_p);
|
|
667
|
|
668 if (desired_debuggerpanel_exposed_p && FRAME_X_TOP_WIDGETS (f) [1] == 0)
|
|
669 /* This happens when the frame was just created. */
|
|
670 debuggerpanel_changed = 1;
|
|
671
|
|
672 FRAME_X_CURRENT_PSHEETS (f) = FRAME_X_DESIRED_PSHEETS (f);
|
|
673 FRAME_X_CURRENT_PSHEET_COUNT (f) = FRAME_X_DESIRED_PSHEET_COUNT (f);
|
|
674 FRAME_X_CURRENT_PSHEET_BUFFER (f) = FRAME_X_DESIRED_PSHEET_BUFFER (f);
|
|
675 #endif /* ENERGIZE */
|
|
676
|
|
677 if (menubar_contents_changed)
|
|
678 menubar_will_be_visible = set_frame_menubar (f, 0, 0);
|
|
679
|
|
680 menubar_visibility_changed = menubar_was_visible != menubar_will_be_visible;
|
|
681
|
|
682 if (! (menubar_visibility_changed
|
|
683 #ifdef ENERGIZE
|
|
684 || psheets_changed || debuggerpanel_changed
|
|
685 #endif
|
|
686 ))
|
|
687 return;
|
|
688
|
|
689
|
|
690 /* Set menubar visibility */
|
|
691 if (menubar_visibility_changed)
|
|
692 (menubar_will_be_visible ? XtManageChild : XtUnmanageChild)
|
|
693 (FRAME_X_MENUBAR_WIDGET (f));
|
|
694
|
|
695
|
|
696 #ifdef ENERGIZE
|
|
697 /* Set debugger panel visibility */
|
|
698 if (debuggerpanel_changed)
|
|
699 {
|
|
700 Widget w;
|
|
701 int sheet = debuggerpanel_sheet;
|
|
702
|
|
703 w = lw_get_widget (sheet, container, 0);
|
|
704 if (desired_debuggerpanel_exposed_p)
|
|
705 {
|
|
706 if (! w)
|
|
707 w = lw_make_widget (sheet, container, 0);
|
|
708 FRAME_X_TOP_WIDGETS (f)[1] = w;
|
|
709 XtManageChild (w);
|
|
710 }
|
|
711 else
|
|
712 {
|
|
713 notify_energize_sheet_hidden (sheet);
|
|
714 if (w)
|
|
715 XtUnmanageChild (w);
|
|
716 }
|
|
717 }
|
|
718
|
|
719 /* Set psheet visibility. For the moment we just unmanage all the old
|
|
720 ones, and then manage all the new ones. If the number of psheets
|
|
721 ever becomes a large number (i.e. > 1), then we can worry about a
|
|
722 more sophisticated way of doing this. */
|
|
723 if (psheets_changed)
|
|
724 {
|
|
725 int i;
|
|
726 Widget w;
|
|
727 unsigned long sheet;
|
|
728
|
|
729 for (i=0; i<old_count; i++)
|
|
730 {
|
|
731 sheet = old_sheets[i];
|
|
732 w = lw_get_widget (sheet, container, 0);
|
|
733 notify_energize_sheet_hidden (sheet);
|
|
734 if (w)
|
|
735 XtUnmanageChild (w);
|
|
736 }
|
|
737
|
|
738 for (i=0; i<new_count; i++)
|
|
739 {
|
|
740 sheet = new_sheets[i];
|
|
741 /* #### This unconditional call to lw_make_widget() is a bad
|
|
742 idea. Doesn't it cause a memory leak if the widget
|
|
743 already exists?
|
|
744
|
|
745 #### How does Energize know that a sheet just got displayed?
|
|
746 #### Energize knows all. */
|
|
747 w = lw_make_widget (sheet, container, 0);
|
|
748 FRAME_X_TOP_WIDGETS (f)[2+i] = w;
|
|
749 XtManageChild (w);
|
|
750 }
|
|
751 }
|
|
752
|
|
753 new_num_top_widgets += 1+new_count;
|
|
754 #endif /* ENERGIZE */
|
|
755
|
|
756 /* Note that new_num_top_widgets doesn't need to reflect the actual
|
|
757 number of top widgets, but just the limit of FRAME_X_TOP_WIDGETS (f)[]. */
|
|
758 FRAME_X_NUM_TOP_WIDGETS (f) = new_num_top_widgets;
|
|
759 {
|
|
760 /* We want to end up as close in size as possible to what we
|
|
761 were before. So, ask the EmacsManager what size it wants
|
|
762 to be (suggesting the current size), and resize it to that
|
|
763 size. It in turn will call our query-geometry callback,
|
|
764 which will round the size to something that exactly fits
|
|
765 the text widget. */
|
|
766 XtWidgetGeometry req, repl;
|
|
767
|
|
768 req.request_mode = CWWidth | CWHeight;
|
|
769 XtVaGetValues (container,
|
|
770 XtNwidth, &req.width,
|
|
771 XtNheight, &req.height,
|
|
772 0);
|
|
773 XtQueryGeometry (container, &req, &repl);
|
|
774 EmacsManagerChangeSize (container, repl.width,
|
|
775 repl.height);
|
|
776 /* The window size might not have changed but the text size
|
|
777 did; thus, the base size might be incorrect. So update
|
|
778 it. */
|
|
779 EmacsShellUpdateSizeHints (FRAME_X_SHELL_WIDGET (f));
|
|
780 }
|
|
781
|
|
782 #ifdef ENERGIZE
|
|
783 /* Give back the focus to emacs if no psheets are displayed anymore */
|
|
784 if (psheets_changed)
|
|
785 {
|
|
786 Lisp_Object frame;
|
|
787 XSETFRAME (frame, f);
|
|
788 Fselect_frame (frame);
|
|
789 }
|
|
790 #endif /* ENERGIZE */
|
|
791 }
|
|
792
|
|
793 static void
|
|
794 x_update_frame_menubars (struct frame *f)
|
|
795 {
|
|
796 assert (FRAME_X_P (f));
|
|
797
|
|
798 x_update_frame_menubar_internal (f);
|
|
799
|
|
800 /* #### This isn't going to work right now that this function works on
|
|
801 a per-frame, not per-device basis. Guess what? I don't care. */
|
|
802 #ifdef ENERGIZE
|
|
803 current_debuggerpanel_exposed_p = desired_debuggerpanel_exposed_p;
|
|
804 #endif
|
|
805 }
|
|
806
|
|
807 static void
|
|
808 x_free_frame_menubars (struct frame *f)
|
|
809 {
|
|
810 Widget menubar_widget;
|
|
811
|
|
812 assert (FRAME_X_P (f));
|
|
813
|
|
814 menubar_widget = FRAME_X_MENUBAR_WIDGET (f);
|
|
815 if (menubar_widget)
|
|
816 {
|
|
817 LWLIB_ID id = XFRAME_MENUBAR_DATA (f)->id;
|
|
818 lw_destroy_all_widgets (id);
|
|
819 XFRAME_MENUBAR_DATA (f)->id = 0;
|
|
820 }
|
|
821
|
|
822 #ifdef ENERGIZE
|
|
823 {
|
|
824 /* Also destroy this frame's psheets */
|
|
825 Widget parent = FRAME_X_CONTAINER_WIDGET (f);
|
|
826 int *sheets = FRAME_X_CURRENT_PSHEETS (f);
|
|
827 int i = FRAME_X_CURRENT_PSHEET_COUNT (f);
|
|
828 while (i--)
|
|
829 {
|
|
830 unsigned long sheet = sheets [i];
|
|
831 Widget w = lw_get_widget (sheet, parent, 0);
|
|
832 if (w)
|
|
833 lw_destroy_widget (w);
|
|
834 }
|
|
835 FRAME_X_CURRENT_PSHEET_COUNT (f) = 0;
|
|
836
|
|
837 /* Is this necessary? */
|
|
838 sheets = FRAME_X_DESIRED_PSHEETS (f);
|
|
839 i = FRAME_X_DESIRED_PSHEET_COUNT (f);
|
|
840 while (i--)
|
|
841 {
|
|
842 unsigned long sheet = sheets [i];
|
|
843 Widget w = lw_get_widget (sheet, parent, 0);
|
|
844 if (w)
|
|
845 lw_destroy_widget (w);
|
|
846 }
|
|
847 FRAME_X_DESIRED_PSHEET_COUNT (f) = 0;
|
|
848
|
|
849 /* sigh... debugger panel is special... */
|
|
850 if (debuggerpanel_sheet)
|
|
851 {
|
|
852 Widget w = lw_get_widget (debuggerpanel_sheet, parent, 0);
|
|
853 if (w)
|
|
854 lw_destroy_widget (w);
|
|
855 }
|
|
856 }
|
|
857 #endif /* ENERGIZE */
|
|
858 }
|
|
859
|
|
860 static void
|
|
861 x_popup_menu (Lisp_Object menu_desc, Lisp_Object event)
|
|
862 {
|
|
863 int menu_id;
|
|
864 struct frame *f = selected_frame ();
|
|
865 widget_value *data;
|
|
866 Widget parent;
|
|
867 Widget menu;
|
|
868 struct Lisp_Event *eev = NULL;
|
|
869 XEvent xev;
|
|
870 Lisp_Object frame = Qnil;
|
|
871
|
|
872 XSETFRAME (frame, f);
|
|
873 CHECK_X_FRAME (frame);
|
|
874 parent = FRAME_X_SHELL_WIDGET (f);
|
|
875
|
|
876 if (!NILP (event))
|
|
877 {
|
|
878 CHECK_LIVE_EVENT (event);
|
|
879 eev= XEVENT (event);
|
|
880 if (eev->event_type != button_press_event
|
|
881 && eev->event_type != button_release_event)
|
|
882 wrong_type_argument (Qmouse_event_p, event);
|
|
883 }
|
|
884 else if (!NILP (Vthis_command_keys))
|
|
885 {
|
|
886 /* if an event wasn't passed, use the last event of the event sequence
|
|
887 currently being executed, if that event is a mouse event */
|
|
888 eev = XEVENT (Vthis_command_keys); /* last event first */
|
|
889 if (eev->event_type != button_press_event
|
|
890 && eev->event_type != button_release_event)
|
|
891 eev = NULL;
|
|
892 }
|
|
893 make_dummy_xbutton_event (&xev, parent, eev);
|
|
894
|
|
895 if (SYMBOLP (menu_desc))
|
|
896 menu_desc = Fsymbol_value (menu_desc);
|
|
897 CHECK_CONS (menu_desc);
|
|
898 CHECK_STRING (XCAR (menu_desc));
|
|
899 data = menu_item_descriptor_to_widget_value (menu_desc, POPUP_TYPE, 1, 1);
|
|
900
|
|
901 if (! data) error ("no menu");
|
|
902
|
|
903 menu_id = new_lwlib_id ();
|
|
904 menu = lw_create_widget ("popup", "popup" /* data->name */, menu_id, data,
|
|
905 parent, 1, 0,
|
|
906 popup_menu_selection_callback,
|
|
907 popup_menu_down_callback);
|
|
908 free_popup_widget_value_tree (data);
|
|
909
|
|
910 gcpro_popup_callbacks (menu_id);
|
|
911
|
|
912 /* Setting zmacs-region-stays is necessary here because executing a command
|
|
913 from a menu is really a two-command process: the first command (bound to
|
|
914 the button-click) simply pops up the menu, and returns. This causes a
|
|
915 sequence of magic-events (destined for the popup-menu widget) to begin.
|
|
916 Eventually, a menu item is selected, and a menu-event blip is pushed onto
|
|
917 the end of the input stream, which is then executed by the event loop.
|
|
918
|
|
919 So there are two command-events, with a bunch of magic-events between
|
|
920 them. We don't want the *first* command event to alter the state of the
|
|
921 region, so that the region can be available as an argument for the second
|
|
922 command.
|
|
923 */
|
|
924 if (zmacs_regions)
|
|
925 zmacs_region_stays = 1;
|
|
926
|
|
927 popup_up_p++;
|
|
928 lw_popup_menu (menu, &xev);
|
|
929 /* this speeds up display of pop-up menus */
|
|
930 XFlush (XtDisplay (parent));
|
|
931 }
|
|
932
|
|
933
|
|
934 void
|
|
935 syms_of_menubar_x (void)
|
|
936 {
|
|
937 }
|
|
938
|
|
939 void
|
|
940 console_type_create_menubar_x (void)
|
|
941 {
|
|
942 CONSOLE_HAS_METHOD (x, update_frame_menubars);
|
|
943 CONSOLE_HAS_METHOD (x, free_frame_menubars);
|
|
944 CONSOLE_HAS_METHOD (x, popup_menu);
|
|
945 }
|
|
946
|
|
947 void
|
|
948 vars_of_menubar_x (void)
|
|
949 {
|
|
950 last_popup_menu_selection_callback_id = -1;
|
|
951
|
|
952 #if defined (LWLIB_MENUBARS_LUCID)
|
|
953 Fprovide (intern ("lucid-menubars"));
|
|
954 #elif defined (LWLIB_MENUBARS_MOTIF)
|
|
955 Fprovide (intern ("motif-menubars"));
|
|
956 #elif defined (LWLIB_MENUBARS_ATHENA)
|
|
957 Fprovide (intern ("athena-menubars"));
|
|
958 #endif
|
|
959 }
|