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