462
|
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 "buffer.h"
|
|
30 #include "commands.h" /* zmacs_regions */
|
872
|
31 #include "device.h"
|
462
|
32 #include "events.h"
|
876
|
33 #include "device-impl.h"
|
872
|
34 #include "frame-impl.h"
|
|
35 #include "gui.h"
|
462
|
36 #include "opaque.h"
|
|
37 #include "window.h"
|
876
|
38 #include "window-impl.h"
|
462
|
39
|
872
|
40 #include "console-gtk-impl.h"
|
|
41 #include "gui-gtk.h"
|
|
42 #include "ui-gtk.h"
|
876
|
43 #include "menubar.h"
|
872
|
44
|
462
|
45 #ifdef HAVE_GNOME
|
|
46 #include <libgnomeui/libgnomeui.h>
|
|
47 #endif
|
|
48
|
|
49 #define MENUBAR_TYPE 0
|
|
50 #define SUBMENU_TYPE 1
|
|
51 #define POPUP_TYPE 2
|
|
52
|
|
53 static GtkWidget *menu_descriptor_to_widget_1 (Lisp_Object descr);
|
|
54
|
|
55 #define FRAME_MENUBAR_DATA(frame) ((frame)->menubar_data)
|
|
56 #define XFRAME_MENUBAR_DATA_LASTBUFF(frame) (XCAR ((frame)->menubar_data))
|
|
57 #define XFRAME_MENUBAR_DATA_UPTODATE(frame) (XCDR ((frame)->menubar_data))
|
|
58
|
|
59
|
|
60 /* This is a bogus subclass of GtkMenuBar so that the menu never tries
|
|
61 ** to be bigger than the text widget. This prevents weird resizing
|
|
62 ** when jumping around between buffers with radically different menu
|
|
63 ** sizes.
|
|
64 */
|
|
65
|
|
66 #define GTK_XEMACS_MENUBAR(obj) GTK_CHECK_CAST (obj, gtk_xemacs_menubar_get_type (), GtkXEmacsMenubar)
|
|
67 #define GTK_XEMACS_MENUBAR_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gtk_xemacs_menubar_get_type (), GtkXEmacsMenubarClass)
|
|
68 #define GTK_IS_XEMACS_MENUBAR(obj) GTK_CHECK_TYPE (obj, gtk_xemacs_menubar_get_type ())
|
|
69 #define GTK_XEMACS_MENUBAR_FRAME(obj) GTK_XEMACS_MENUBAR (obj)->f
|
|
70
|
|
71 typedef struct _GtkXEmacsMenubar GtkXEmacsMenubar;
|
|
72 typedef struct _GtkXEmacsMenubarClass GtkXEmacsMenubarClass;
|
|
73
|
|
74 struct _GtkXEmacsMenubar
|
|
75 {
|
|
76 GtkMenuBar menu;
|
|
77 struct frame *frame;
|
|
78 };
|
|
79
|
|
80 struct _GtkXEmacsMenubarClass
|
|
81 {
|
|
82 GtkMenuBarClass parent_class;
|
|
83 };
|
|
84
|
|
85 guint gtk_xemacs_menubar_get_type (void);
|
|
86 GtkWidget *gtk_xemacs_menubar_new (struct frame *f);
|
|
87
|
|
88 static void gtk_xemacs_menubar_class_init (GtkXEmacsMenubarClass *klass);
|
|
89 static void gtk_xemacs_menubar_init (GtkXEmacsMenubar *xemacs);
|
|
90 static void gtk_xemacs_menubar_size_request (GtkWidget *widget, GtkRequisition *requisition);
|
|
91
|
|
92 guint
|
|
93 gtk_xemacs_menubar_get_type (void)
|
|
94 {
|
|
95 static guint xemacs_menubar_type;
|
|
96
|
|
97 if (!xemacs_menubar_type)
|
|
98 {
|
|
99 static const GtkTypeInfo xemacs_menubar_info =
|
|
100 {
|
|
101 "GtkXEmacsMenubar",
|
|
102 sizeof (GtkXEmacsMenubar),
|
|
103 sizeof (GtkXEmacsMenubarClass),
|
|
104 (GtkClassInitFunc) gtk_xemacs_menubar_class_init,
|
|
105 (GtkObjectInitFunc) gtk_xemacs_menubar_init,
|
|
106 /* reserved_1 */ NULL,
|
|
107 /* reserved_2 */ NULL,
|
|
108 (GtkClassInitFunc) NULL,
|
|
109 };
|
|
110
|
|
111 xemacs_menubar_type = gtk_type_unique (gtk_menu_bar_get_type (), &xemacs_menubar_info);
|
|
112 }
|
|
113
|
|
114 return xemacs_menubar_type;
|
|
115 }
|
|
116
|
|
117 static GtkWidgetClass *parent_class;
|
|
118
|
|
119 static void gtk_xemacs_menubar_class_init (GtkXEmacsMenubarClass *klass)
|
|
120 {
|
|
121 GtkWidgetClass *widget_class;
|
|
122
|
|
123 widget_class = (GtkWidgetClass*) klass;
|
|
124 parent_class = (GtkWidgetClass *) gtk_type_class (gtk_menu_bar_get_type ());
|
|
125
|
|
126 widget_class->size_request = gtk_xemacs_menubar_size_request;
|
|
127 }
|
|
128
|
|
129 static void gtk_xemacs_menubar_init (GtkXEmacsMenubar *xemacs)
|
|
130 {
|
|
131 }
|
|
132
|
|
133 static void gtk_xemacs_menubar_size_request (GtkWidget *widget, GtkRequisition *requisition)
|
|
134 {
|
|
135 GtkXEmacsMenubar *x = GTK_XEMACS_MENUBAR (widget);
|
|
136 GtkRequisition frame_size;
|
|
137
|
|
138 parent_class->size_request (widget, requisition);
|
|
139
|
|
140 /* #### BILL!
|
|
141 ** We should really only do this if the menu has not been detached!
|
|
142 **
|
|
143 ** WMP 9/9/2000
|
|
144 */
|
|
145
|
|
146 gtk_widget_size_request (FRAME_GTK_TEXT_WIDGET (x->frame), &frame_size);
|
|
147
|
|
148 requisition->width = frame_size.width;
|
|
149 }
|
|
150
|
|
151 GtkWidget *
|
|
152 gtk_xemacs_menubar_new (struct frame *f)
|
|
153 {
|
|
154 GtkXEmacsMenubar *menubar = gtk_type_new (gtk_xemacs_menubar_get_type ());
|
|
155
|
|
156 menubar->frame = f;
|
|
157
|
|
158 return (GTK_WIDGET (menubar));
|
|
159 }
|
|
160
|
|
161 /* We now return you to your regularly scheduled menus... */
|
|
162
|
|
163 int dockable_menubar;
|
|
164
|
|
165 /* #define TEAR_OFF_MENUS */
|
|
166
|
|
167 #ifdef TEAR_OFF_MENUS
|
|
168 int tear_off_menus;
|
|
169 #endif
|
|
170
|
|
171
|
|
172 /* Converting from XEmacs to GTK representation */
|
|
173 static Lisp_Object
|
|
174 menu_name_to_accelerator (char *name)
|
|
175 {
|
|
176 while (*name) {
|
|
177 if (*name=='%') {
|
|
178 ++name;
|
|
179 if (!(*name))
|
|
180 return Qnil;
|
|
181 if (*name=='_' && *(name+1))
|
|
182 {
|
|
183 int accelerator = (int) (unsigned char) (*(name+1));
|
|
184 return make_char (tolower (accelerator));
|
|
185 }
|
|
186 }
|
|
187 ++name;
|
|
188 }
|
|
189 return Qnil;
|
|
190 }
|
|
191
|
|
192 #define XEMACS_MENU_DESCR_TAG "xemacs::menu::description"
|
|
193 #define XEMACS_MENU_FILTER_TAG "xemacs::menu::filter"
|
|
194 #define XEMACS_MENU_GUIID_TAG "xemacs::menu::gui_id"
|
|
195 #define XEMACS_MENU_FIRSTTIME_TAG "xemacs::menu::first_time"
|
|
196
|
|
197 static void __activate_menu(GtkMenuItem *, gpointer);
|
|
198
|
|
199 #ifdef TEAR_OFF_MENUS
|
|
200 static void
|
|
201 __torn_off_sir(GtkMenuItem *item, gpointer user_data)
|
|
202 {
|
|
203 GtkWidget *menu_item = GTK_WIDGET (user_data);
|
|
204
|
|
205 if (GTK_TEAROFF_MENU_ITEM (item)->torn_off)
|
|
206 {
|
|
207 /* Menu was just torn off */
|
|
208 GUI_ID id = new_gui_id ();
|
|
209 Lisp_Object menu_desc = Qnil;
|
|
210 GtkWidget *old_submenu = GTK_MENU_ITEM (menu_item)->submenu;
|
|
211
|
826
|
212 menu_desc = VOID_TO_LISP (gtk_object_get_data (GTK_OBJECT (menu_item), XEMACS_MENU_DESCR_TAG));
|
462
|
213
|
|
214 /* GCPRO all of our very own */
|
|
215 gcpro_popup_callbacks (id, menu_desc);
|
|
216
|
|
217 /* Hide the now detached menu from the attentions of
|
|
218 __activate_menu destroying the old submenu */
|
|
219 #if 0
|
|
220 gtk_widget_ref (old_submenu);
|
|
221 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), gtk_menu_new ());
|
|
222 gtk_widget_show_all (old_submenu);
|
|
223 #endif
|
|
224 }
|
|
225 }
|
|
226 #endif
|
|
227
|
|
228 /* This is called when a menu is about to be shown... this is what
|
|
229 does the delayed creation of the menu items. We populate the
|
|
230 submenu and away we go. */
|
|
231 static void
|
|
232 __maybe_destroy (GtkWidget *child, GtkWidget *precious)
|
|
233 {
|
|
234 if (GTK_IS_MENU_ITEM (child) && !GTK_IS_TEAROFF_MENU_ITEM (child))
|
|
235 {
|
|
236 if (GTK_WIDGET_VISIBLE (child))
|
|
237 {
|
|
238 /* If we delete the menu item that was 'active' when the
|
|
239 menu was cancelled, GTK gets upset because it tries to
|
|
240 remove the focus rectangle from a (now) dead widget.
|
|
241
|
|
242 This widget will eventually get killed because it will
|
|
243 not be visible the next time the window is shown.
|
|
244 */
|
|
245 gtk_widget_set_sensitive (child, FALSE);
|
|
246 gtk_widget_hide_all (child);
|
|
247 }
|
|
248 else
|
|
249 {
|
|
250 gtk_widget_destroy (child);
|
|
251 }
|
|
252 }
|
|
253 }
|
|
254
|
|
255 /* If user_data != 0x00 then we are using a hook to build the menu. */
|
|
256 static void
|
|
257 __activate_menu(GtkMenuItem *item, gpointer user_data)
|
|
258 {
|
|
259 Lisp_Object desc;
|
|
260 gpointer force_clear = gtk_object_get_data (GTK_OBJECT (item), XEMACS_MENU_FIRSTTIME_TAG);
|
|
261
|
|
262 gtk_object_set_data (GTK_OBJECT (item), XEMACS_MENU_FIRSTTIME_TAG, 0x00);
|
|
263
|
|
264 /* Delete the old contents of the menu if we are the top level menubar */
|
|
265 if (GTK_IS_MENU_BAR (GTK_WIDGET (item)->parent) || force_clear)
|
|
266 {
|
|
267 GtkWidget *selected = gtk_menu_get_active (GTK_MENU (item->submenu));
|
|
268
|
|
269 gtk_container_foreach (GTK_CONTAINER (item->submenu),(GtkCallback) __maybe_destroy,
|
|
270 selected);
|
|
271 }
|
|
272 else if (gtk_container_children (GTK_CONTAINER (item->submenu)))
|
|
273 {
|
|
274 return;
|
|
275 }
|
|
276
|
826
|
277 desc = VOID_TO_LISP (gtk_object_get_data (GTK_OBJECT (item), XEMACS_MENU_DESCR_TAG));
|
462
|
278
|
|
279 #ifdef TEAR_OFF_MENUS
|
|
280 /* Lets stick in a detacher just for giggles */
|
|
281 if (tear_off_menus && !gtk_container_children (GTK_CONTAINER (item->submenu)))
|
|
282 {
|
|
283 GtkWidget *w = gtk_tearoff_menu_item_new ();
|
|
284 gtk_widget_show (w);
|
|
285 gtk_menu_append (GTK_MENU (item->submenu), w);
|
|
286 gtk_signal_connect (GTK_OBJECT (w), "activate", GTK_SIGNAL_FUNC (__torn_off_sir), item);
|
|
287 }
|
|
288 #endif
|
|
289
|
|
290 if (user_data)
|
|
291 {
|
|
292 GUI_ID id = (GUI_ID) gtk_object_get_data (GTK_OBJECT (item), XEMACS_MENU_GUIID_TAG);
|
|
293 Lisp_Object hook_fn;
|
|
294 struct gcpro gcpro1, gcpro2;
|
|
295
|
826
|
296 hook_fn = VOID_TO_LISP (gtk_object_get_data (GTK_OBJECT (item), XEMACS_MENU_FILTER_TAG));
|
462
|
297
|
|
298 GCPRO2 (desc, hook_fn);
|
|
299
|
|
300 desc = call1 (hook_fn, desc);
|
|
301
|
|
302 UNGCPRO;
|
|
303
|
|
304 ungcpro_popup_callbacks (id);
|
|
305 gcpro_popup_callbacks (id, desc);
|
|
306 }
|
|
307
|
|
308 /* Build the child widgets */
|
|
309 for (; !NILP (desc); desc = Fcdr (desc))
|
|
310 {
|
|
311 GtkWidget *next = NULL;
|
|
312 Lisp_Object child = Fcar (desc);
|
|
313
|
|
314 if (NILP (child)) /* the partition */
|
|
315 {
|
|
316 /* Signal an error here? The NILP handling is handled a
|
|
317 layer higher where appropriate */
|
|
318 }
|
|
319 else
|
|
320 {
|
|
321 next = menu_descriptor_to_widget_1 (child);
|
|
322 }
|
|
323
|
|
324 if (!next)
|
|
325 {
|
|
326 continue;
|
|
327 }
|
|
328
|
|
329 gtk_widget_show_all (next);
|
|
330 gtk_menu_append (GTK_MENU (item->submenu), next);
|
|
331 }
|
|
332 }
|
|
333
|
|
334 /* This is called whenever an item with a GUI_ID associated with it is
|
|
335 destroyed. This allows us to remove the references in gui-gtk.c
|
|
336 that made sure callbacks and such were GCPRO-ed
|
|
337 */
|
|
338 static void
|
|
339 __remove_gcpro_by_id (gpointer user_data)
|
|
340 {
|
|
341 ungcpro_popup_callbacks ((GUI_ID) user_data);
|
|
342 }
|
|
343
|
|
344 static void
|
|
345 __kill_stupid_gtk_timer (GtkObject *obj, gpointer user_data)
|
|
346 {
|
|
347 GtkMenuItem *mi = GTK_MENU_ITEM (obj);
|
|
348
|
|
349 if (mi->timer)
|
|
350 {
|
|
351 gtk_timeout_remove (mi->timer);
|
|
352 mi->timer = 0;
|
|
353 }
|
|
354 }
|
|
355
|
|
356 static char *
|
|
357 remove_underscores(const char *name)
|
|
358 {
|
|
359 char *rval = xmalloc_and_zero (strlen(name) + 1);
|
|
360 int i,j;
|
|
361
|
|
362 for (i = 0, j = 0; name[i]; i++)
|
|
363 {
|
|
364 if (name[i]=='%') {
|
|
365 i++;
|
|
366 if (!(name[i]))
|
|
367 continue;
|
|
368
|
|
369 if ((name[i] == '_'))
|
|
370 continue;
|
|
371 }
|
|
372 rval[j++] = name[i];
|
|
373 }
|
|
374 return rval;
|
|
375 }
|
|
376
|
|
377 /* This converts an entire menu into a GtkMenuItem (with an attached
|
|
378 submenu). A menu is a list of (STRING [:keyword value]+ [DESCR]+)
|
|
379 DESCR is either a list (meaning a submenu), a vector, or nil (if
|
|
380 you include a :filter keyword) */
|
|
381 static GtkWidget *
|
|
382 menu_convert (Lisp_Object desc, GtkWidget *reuse)
|
|
383 {
|
|
384 GtkWidget *menu_item = NULL;
|
|
385 GtkWidget *submenu = NULL;
|
|
386 Lisp_Object key, val;
|
|
387 Lisp_Object include_p = Qnil, hook_fn = Qnil, config_tag = Qnil;
|
|
388 Lisp_Object active_p = Qt;
|
|
389 Lisp_Object accel;
|
|
390 int included_spec = 0;
|
|
391 int active_spec = 0;
|
|
392
|
|
393 if (STRINGP (XCAR (desc)))
|
|
394 {
|
|
395 accel = menu_name_to_accelerator (XSTRING_DATA (XCAR (desc)));
|
|
396
|
|
397 if (!reuse)
|
|
398 {
|
|
399 char *temp_menu_name = remove_underscores (XSTRING_DATA (XCAR (desc)));
|
|
400 menu_item = gtk_menu_item_new_with_label (temp_menu_name);
|
|
401 free (temp_menu_name);
|
|
402 }
|
|
403 else
|
|
404 {
|
|
405 menu_item = reuse;
|
|
406 }
|
|
407
|
|
408 submenu = gtk_menu_new ();
|
|
409 gtk_widget_show (menu_item);
|
|
410 gtk_widget_show (submenu);
|
|
411
|
|
412 if (!reuse)
|
|
413 gtk_signal_connect (GTK_OBJECT (menu_item), "destroy",
|
|
414 GTK_SIGNAL_FUNC (__kill_stupid_gtk_timer), NULL);
|
|
415
|
|
416 /* Without this sometimes a submenu gets left on the screen -
|
|
417 ** urk
|
|
418 */
|
|
419 if (GTK_MENU_ITEM (menu_item)->submenu)
|
|
420 {
|
|
421 gtk_widget_destroy (GTK_MENU_ITEM (menu_item)->submenu);
|
|
422 }
|
|
423
|
|
424 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), submenu);
|
|
425
|
|
426 /* We put this bogus menu item in so that GTK does the right
|
|
427 ** thing when the menu is near the screen border.
|
|
428 **
|
|
429 ** Aug 29, 2000
|
|
430 */
|
|
431 {
|
|
432 GtkWidget *bogus_item = gtk_menu_item_new_with_label ("A suitably long label here...");
|
|
433
|
|
434 gtk_object_set_data (GTK_OBJECT (menu_item), XEMACS_MENU_FIRSTTIME_TAG, (gpointer)0x01);
|
|
435 gtk_widget_show_all (bogus_item);
|
|
436 gtk_menu_append (GTK_MENU (submenu), bogus_item);
|
|
437 }
|
|
438
|
|
439 desc = Fcdr (desc);
|
|
440
|
|
441 while (key = Fcar (desc), KEYWORDP (key))
|
|
442 {
|
|
443 Lisp_Object cascade = desc;
|
|
444 desc = Fcdr (desc);
|
|
445 if (NILP (desc))
|
563
|
446 sferror ("keyword in menu lacks a value",
|
462
|
447 cascade);
|
|
448 val = Fcar (desc);
|
|
449 desc = Fcdr (desc);
|
|
450 if (EQ (key, Q_included))
|
|
451 include_p = val, included_spec = 1;
|
|
452 else if (EQ (key, Q_config))
|
|
453 config_tag = val;
|
|
454 else if (EQ (key, Q_filter))
|
|
455 hook_fn = val;
|
|
456 else if (EQ (key, Q_active))
|
|
457 active_p = val, active_spec = 1;
|
|
458 else if (EQ (key, Q_accelerator))
|
|
459 {
|
|
460 #if 0
|
|
461 if ( SYMBOLP (val)
|
|
462 || CHARP (val))
|
|
463 wv->accel = LISP_TO_VOID (val);
|
|
464 else
|
563
|
465 invalid_argument ("bad keyboard accelerator", val);
|
462
|
466 #endif
|
|
467 }
|
|
468 else if (EQ (key, Q_label))
|
|
469 {
|
|
470 /* implement in 21.2 */
|
|
471 }
|
|
472 else
|
563
|
473 invalid_argument ("unknown menu cascade keyword", cascade);
|
462
|
474 }
|
|
475
|
|
476 gtk_object_set_data (GTK_OBJECT (menu_item), XEMACS_MENU_DESCR_TAG, LISP_TO_VOID (desc));
|
|
477 gtk_object_set_data (GTK_OBJECT (menu_item), XEMACS_MENU_FILTER_TAG, LISP_TO_VOID (hook_fn));
|
|
478
|
|
479 if ((!NILP (config_tag)
|
|
480 && NILP (Fmemq (config_tag, Vmenubar_configuration)))
|
|
481 || (included_spec && NILP (Feval (include_p))))
|
|
482 {
|
|
483 return (NULL);
|
|
484 }
|
|
485
|
|
486 if (active_spec)
|
|
487 active_p = Feval (active_p);
|
|
488
|
|
489 gtk_widget_set_sensitive (GTK_WIDGET (menu_item), ! NILP (active_p));
|
|
490 }
|
|
491 else
|
|
492 {
|
563
|
493 invalid_argument ("menu name (first element) must be a string",
|
462
|
494 desc);
|
|
495 }
|
|
496
|
|
497 /* If we are reusing a widget, we need to make sure we clean
|
|
498 ** everything up.
|
|
499 */
|
|
500 if (reuse)
|
|
501 {
|
|
502 gpointer id = gtk_object_get_data (GTK_OBJECT (reuse), XEMACS_MENU_GUIID_TAG);
|
|
503
|
|
504 if (id)
|
|
505 {
|
|
506 /* If the menu item had a GUI_ID that means it was a filter menu */
|
|
507 __remove_gcpro_by_id (id);
|
|
508 gtk_signal_disconnect_by_func (GTK_OBJECT (reuse),
|
|
509 GTK_SIGNAL_FUNC (__activate_menu),
|
|
510 (gpointer) 0x01 );
|
|
511 }
|
|
512 else
|
|
513 {
|
|
514 gtk_signal_disconnect_by_func (GTK_OBJECT (reuse),
|
|
515 GTK_SIGNAL_FUNC (__activate_menu),
|
|
516 NULL);
|
|
517 }
|
|
518
|
|
519 GTK_MENU_ITEM (reuse)->right_justify = 0;
|
|
520 }
|
|
521
|
|
522 if (NILP (hook_fn))
|
|
523 {
|
|
524 /* Generic menu builder */
|
|
525 gtk_signal_connect (GTK_OBJECT (menu_item), "activate",
|
|
526 GTK_SIGNAL_FUNC (__activate_menu),
|
|
527 NULL);
|
|
528 }
|
|
529 else
|
|
530 {
|
|
531 GUI_ID id = new_gui_id ();
|
|
532
|
|
533 gtk_object_set_data (GTK_OBJECT (menu_item), XEMACS_MENU_GUIID_TAG,
|
|
534 (gpointer) id);
|
|
535
|
|
536 /* Make sure we gcpro the menu descriptions */
|
|
537 gcpro_popup_callbacks (id, desc);
|
|
538 gtk_object_weakref (GTK_OBJECT (menu_item), __remove_gcpro_by_id,
|
|
539 (gpointer) id);
|
|
540
|
|
541 gtk_signal_connect (GTK_OBJECT (menu_item), "activate",
|
|
542 GTK_SIGNAL_FUNC (__activate_menu),
|
|
543 (gpointer) 0x01);
|
|
544 }
|
|
545
|
|
546 return (menu_item);
|
|
547 }
|
|
548
|
|
549 static struct frame *
|
|
550 __get_channel (GtkWidget *w)
|
|
551 {
|
|
552 struct frame *f = NULL;
|
|
553
|
|
554 for (; w; w = w->parent)
|
|
555 {
|
|
556 if ((f = (struct frame *) gtk_object_get_data (GTK_OBJECT (w), "xemacs::frame")))
|
|
557 return (f);
|
|
558 }
|
|
559
|
|
560 return (selected_frame());
|
|
561 }
|
|
562
|
|
563
|
|
564 /* Called whenever a button, radio, or toggle is selected in the menu */
|
|
565 static void
|
|
566 __generic_button_callback (GtkMenuItem *item, gpointer user_data)
|
|
567 {
|
|
568 Lisp_Object callback, function, data, channel;
|
|
569
|
793
|
570 channel = wrap_frame (__get_channel (GTK_WIDGET (item)));
|
462
|
571
|
826
|
572 callback = VOID_TO_LISP (user_data);
|
462
|
573
|
|
574 get_gui_callback (callback, &function, &data);
|
|
575
|
|
576 signal_special_gtk_user_event (channel, function, data);
|
|
577 }
|
|
578
|
|
579 /* Convert a single menu item descriptor to a suitable GtkMenuItem */
|
|
580 /* This function cannot GC.
|
|
581 It is only called from menu_item_descriptor_to_widget_value, which
|
|
582 prohibits GC. */
|
|
583 static GtkWidget *menu_descriptor_to_widget_1 (Lisp_Object descr)
|
|
584 {
|
|
585 if (STRINGP (descr))
|
|
586 {
|
|
587 /* It is a separator. Unfortunately GTK does not allow us to
|
|
588 specify what our separators look like, so we can't do all the
|
|
589 fancy stuff that the X code does.
|
|
590 */
|
|
591 return (gtk_menu_item_new ());
|
|
592 }
|
|
593 else if (LISTP (descr))
|
|
594 {
|
|
595 /* It is a submenu */
|
|
596 return (menu_convert (descr, NULL));
|
|
597 }
|
|
598 else if (VECTORP (descr))
|
|
599 {
|
|
600 /* An actual menu item description! This gets yucky. */
|
|
601 Lisp_Object name = Qnil;
|
|
602 Lisp_Object callback = Qnil;
|
|
603 Lisp_Object suffix = Qnil;
|
|
604 Lisp_Object active_p = Qt;
|
|
605 Lisp_Object include_p = Qt;
|
|
606 Lisp_Object selected_p = Qnil;
|
|
607 Lisp_Object keys = Qnil;
|
|
608 Lisp_Object style = Qnil;
|
|
609 Lisp_Object config_tag = Qnil;
|
|
610 Lisp_Object accel = Qnil;
|
|
611 GtkWidget *main_label = NULL;
|
|
612 int length = XVECTOR_LENGTH (descr);
|
|
613 Lisp_Object *contents = XVECTOR_DATA (descr);
|
|
614 int plist_p;
|
|
615 int selected_spec = 0, included_spec = 0;
|
|
616 GtkWidget *widget = NULL;
|
|
617
|
|
618 if (length < 2)
|
563
|
619 sferror ("button descriptors must be at least 2 long", descr);
|
462
|
620
|
|
621 /* length 2: [ "name" callback ]
|
|
622 length 3: [ "name" callback active-p ]
|
|
623 length 4: [ "name" callback active-p suffix ]
|
|
624 or [ "name" callback keyword value ]
|
|
625 length 5+: [ "name" callback [ keyword value ]+ ]
|
|
626 */
|
|
627 plist_p = (length >= 5 || (length > 2 && KEYWORDP (contents [2])));
|
|
628
|
|
629 if (!plist_p && length > 2)
|
|
630 /* the old way */
|
|
631 {
|
|
632 name = contents [0];
|
|
633 callback = contents [1];
|
|
634 active_p = contents [2];
|
|
635 if (length == 4)
|
|
636 suffix = contents [3];
|
|
637 }
|
|
638 else
|
|
639 {
|
|
640 /* the new way */
|
|
641 int i;
|
|
642 if (length & 1)
|
563
|
643 sferror (
|
462
|
644 "button descriptor has an odd number of keywords and values",
|
|
645 descr);
|
|
646
|
|
647 name = contents [0];
|
|
648 callback = contents [1];
|
|
649 for (i = 2; i < length;)
|
|
650 {
|
|
651 Lisp_Object key = contents [i++];
|
|
652 Lisp_Object val = contents [i++];
|
|
653 if (!KEYWORDP (key))
|
563
|
654 invalid_argument_2 ("not a keyword", key, descr);
|
462
|
655
|
|
656 if (EQ (key, Q_active)) active_p = val;
|
|
657 else if (EQ (key, Q_suffix)) suffix = val;
|
|
658 else if (EQ (key, Q_keys)) keys = val;
|
|
659 else if (EQ (key, Q_key_sequence)) ; /* ignored for FSF compat */
|
|
660 else if (EQ (key, Q_label)) ; /* implement for 21.0 */
|
|
661 else if (EQ (key, Q_style)) style = val;
|
|
662 else if (EQ (key, Q_selected)) selected_p = val, selected_spec = 1;
|
|
663 else if (EQ (key, Q_included)) include_p = val, included_spec = 1;
|
|
664 else if (EQ (key, Q_config)) config_tag = val;
|
|
665 else if (EQ (key, Q_accelerator))
|
|
666 {
|
|
667 if ( SYMBOLP (val) || CHARP (val))
|
|
668 accel = val;
|
|
669 else
|
563
|
670 invalid_argument ("bad keyboard accelerator", val);
|
462
|
671 }
|
|
672 else if (EQ (key, Q_filter))
|
563
|
673 sferror(":filter keyword not permitted on leaf nodes", descr);
|
462
|
674 else
|
563
|
675 invalid_argument_2 ("unknown menu item keyword", key, descr);
|
462
|
676 }
|
|
677 }
|
|
678
|
|
679 #ifdef HAVE_MENUBARS
|
|
680 if ((!NILP (config_tag) && NILP (Fmemq (config_tag, Vmenubar_configuration)))
|
|
681 || (included_spec && NILP (Feval (include_p))))
|
|
682 {
|
|
683 /* the include specification says to ignore this item. */
|
|
684 return 0;
|
|
685 }
|
|
686 #endif /* HAVE_MENUBARS */
|
|
687
|
|
688 CHECK_STRING (name);
|
|
689
|
|
690 if (NILP (accel))
|
|
691 accel = menu_name_to_accelerator (XSTRING_DATA (name));
|
|
692
|
|
693 if (!NILP (suffix))
|
|
694 suffix = Feval (suffix);
|
|
695
|
|
696 if (!separator_string_p (XSTRING_DATA (name)))
|
|
697 {
|
|
698 char *label_buffer = NULL;
|
|
699 char *temp_label = NULL;
|
|
700
|
|
701 if (STRINGP (suffix) && XSTRING_LENGTH (suffix))
|
|
702 {
|
851
|
703 label_buffer = ALLOCA (XSTRING_LENGTH (name) + 15 + XSTRING_LENGTH (suffix));
|
462
|
704 sprintf (label_buffer, "%s %s ", XSTRING_DATA (name), XSTRING_DATA (suffix));
|
|
705 }
|
|
706 else
|
|
707 {
|
851
|
708 label_buffer = ALLOCA (XSTRING_LENGTH (name) + 15);
|
462
|
709 sprintf (label_buffer, "%s ", XSTRING_DATA (name));
|
|
710 }
|
|
711
|
|
712 temp_label = remove_underscores (label_buffer);
|
|
713 main_label = gtk_accel_label_new (temp_label);
|
|
714 free (temp_label);
|
|
715 }
|
|
716
|
|
717 /* Evaluate the selected and active items now */
|
|
718 if (selected_spec)
|
|
719 {
|
|
720 if (NILP (selected_p) || EQ (selected_p, Qt))
|
|
721 {
|
|
722 /* Do nothing */
|
|
723 }
|
|
724 else
|
|
725 {
|
|
726 selected_p = Feval (selected_p);
|
|
727 }
|
|
728 }
|
|
729
|
|
730 if (NILP (active_p) || EQ (active_p, Qt))
|
|
731 {
|
|
732 /* Do Nothing */
|
|
733 }
|
|
734 else
|
|
735 {
|
|
736 active_p = Feval (active_p);
|
|
737 }
|
|
738
|
|
739 if (0 ||
|
|
740 #ifdef HAVE_MENUBARS
|
|
741 menubar_show_keybindings
|
|
742 #endif
|
|
743 )
|
|
744 {
|
|
745 /* Need to get keybindings */
|
|
746 if (!NILP (keys))
|
|
747 {
|
|
748 /* User-specified string to generate key bindings with */
|
|
749 CHECK_STRING (keys);
|
|
750
|
|
751 keys = Fsubstitute_command_keys (keys);
|
|
752 }
|
|
753 else if (SYMBOLP (callback))
|
|
754 {
|
793
|
755 DECLARE_EISTRING_MALLOC (buf);
|
462
|
756
|
|
757 /* #### Warning, dependency here on current_buffer and point */
|
|
758 where_is_to_char (callback, buf);
|
|
759
|
833
|
760 if (eilen (buf) > 0)
|
|
761 keys = eimake_string (buf);
|
|
762 else
|
|
763 {
|
|
764
|
|
765 keys = Qnil;
|
|
766 }
|
|
767
|
793
|
768 eifree (buf);
|
462
|
769 }
|
|
770 }
|
|
771
|
|
772 /* Now we get down to the dirty business of creating the widgets */
|
|
773 if (NILP (style) || EQ (style, Qtext) || EQ (style, Qbutton))
|
|
774 {
|
|
775 /* A normal menu item */
|
|
776 widget = gtk_menu_item_new ();
|
|
777 }
|
|
778 else if (EQ (style, Qtoggle) || EQ (style, Qradio))
|
|
779 {
|
|
780 /* They are radio or toggle buttons.
|
|
781
|
|
782 XEmacs' menu descriptions are fairly lame in that they do
|
|
783 not have the idea of a 'group' of radio buttons. They
|
|
784 are exactly like toggle buttons except that they get
|
|
785 drawn differently.
|
|
786
|
|
787 GTK rips us a new one again. If you have a radio button
|
|
788 in a group by itself, it always draws it as highlighted.
|
|
789 So we dummy up and create a second radio button that does
|
|
790 not get added to the menu, but gets invisibly set/unset
|
|
791 when the other gets unset/set. *sigh*
|
|
792
|
|
793 */
|
|
794 if (EQ (style, Qradio))
|
|
795 {
|
|
796 GtkWidget *dummy_sibling = NULL;
|
|
797 GSList *group = NULL;
|
|
798
|
|
799 dummy_sibling = gtk_radio_menu_item_new (group);
|
|
800 group = gtk_radio_menu_item_group (GTK_RADIO_MENU_ITEM (dummy_sibling));
|
|
801 widget = gtk_radio_menu_item_new (group);
|
|
802
|
|
803 /* We need to notice when the 'real' one gets destroyed
|
|
804 so we can clean up the dummy as well. */
|
|
805 gtk_object_weakref (GTK_OBJECT (widget),
|
|
806 (GtkDestroyNotify) gtk_widget_destroy,
|
|
807 dummy_sibling);
|
|
808 }
|
|
809 else
|
|
810 {
|
|
811 widget = gtk_check_menu_item_new ();
|
|
812 }
|
|
813
|
|
814 /* What horrible defaults you have GTK dear! The default
|
|
815 for a toggle menu item is to not show the toggle unless it
|
|
816 is turned on or actively highlighted. How absolutely
|
|
817 hideous. */
|
|
818 gtk_check_menu_item_set_show_toggle (GTK_CHECK_MENU_ITEM (widget), TRUE);
|
|
819 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (widget),
|
|
820 NILP (selected_p) ? FALSE : TRUE);
|
|
821 }
|
|
822 else
|
|
823 {
|
563
|
824 invalid_argument_2 ("unknown style", style, descr);
|
462
|
825 }
|
|
826
|
|
827 gtk_widget_set_sensitive (widget, ! NILP (active_p));
|
|
828
|
|
829 gtk_signal_connect (GTK_OBJECT (widget), "activate-item",
|
|
830 GTK_SIGNAL_FUNC (__generic_button_callback),
|
|
831 LISP_TO_VOID (callback));
|
|
832
|
|
833 gtk_signal_connect (GTK_OBJECT (widget), "activate",
|
|
834 GTK_SIGNAL_FUNC (__generic_button_callback),
|
|
835 LISP_TO_VOID (callback));
|
|
836
|
|
837 /* We cheat here... GtkAccelLabel usually builds its
|
|
838 `accel_string' from the widget it is attached to, but we do
|
|
839 not want to go thru the overhead of converting our nice
|
|
840 string back into the modifier + key format that requires,
|
|
841 just so that they can convert it back into a (possibly
|
|
842 different/wrong) string
|
|
843
|
|
844 We set the label string manually, and things should 'just
|
|
845 work'
|
|
846
|
|
847 In an ideal world we would just subclass GtkLabel ourselves,
|
|
848 but I have known for a very long time that this is not an
|
|
849 ideal world.
|
|
850
|
|
851 #### Should do menu shortcuts `correctly' one of these days.
|
|
852 */
|
|
853
|
|
854 if (main_label)
|
|
855 {
|
|
856 GtkAccelLabel *l = GTK_ACCEL_LABEL (main_label);
|
|
857
|
|
858 gtk_container_add (GTK_CONTAINER (widget), main_label);
|
|
859
|
|
860 gtk_accel_label_set_accel_widget (l, NULL);
|
|
861 gtk_misc_set_alignment (GTK_MISC (l), 0.0, 0.5);
|
|
862
|
|
863 if (STRINGP (keys) && XSTRING_LENGTH (keys))
|
|
864 {
|
833
|
865 C_STRING_TO_EXTERNAL_MALLOC (XSTRING_DATA (keys), l->accel_string,
|
|
866 Qctext);
|
|
867 stderr_out ("accel: %s\n", l->accel_string);
|
|
868 }
|
|
869 else
|
|
870 {
|
|
871 // l->accel_string = "";
|
462
|
872 }
|
|
873 }
|
|
874
|
|
875 return (widget);
|
|
876 }
|
|
877 else
|
|
878 {
|
|
879 return (NULL);
|
|
880 /* abort (); ???? */
|
|
881 }
|
|
882 }
|
|
883
|
|
884 static GtkWidget *menu_descriptor_to_widget (Lisp_Object descr)
|
|
885 {
|
|
886 GtkWidget *rval = NULL;
|
771
|
887 int count = begin_gc_forbidden ();
|
462
|
888
|
|
889 /* Cannot GC from here on out... */
|
|
890 rval = menu_descriptor_to_widget_1 (descr);
|
771
|
891 unbind_to (count);
|
462
|
892 return (rval);
|
|
893
|
|
894 }
|
|
895
|
|
896 static gboolean
|
|
897 menu_can_reuse_widget (GtkWidget *child, const char *label)
|
|
898 {
|
|
899 /* Everything up at the top level was done using
|
|
900 ** gtk_menu_item_new_with_label(), but we still double check to make
|
|
901 ** sure we don't seriously foobar ourselves.
|
|
902 */
|
|
903 char *temp_label = NULL;
|
|
904 gpointer possible_child = g_list_nth_data (gtk_container_children (GTK_CONTAINER (child)), 0);
|
|
905
|
|
906 if (possible_child && GTK_IS_LABEL (possible_child))
|
|
907 {
|
|
908 if (!temp_label) temp_label = remove_underscores (label);
|
|
909 if (!strcmp (GTK_LABEL (possible_child)->label, temp_label))
|
|
910 {
|
|
911 free (temp_label);
|
|
912 return (TRUE);
|
|
913 }
|
|
914 }
|
|
915 if (temp_label) free (temp_label);
|
|
916 return (FALSE);
|
|
917 }
|
|
918
|
|
919 /* Converts a menubar description into a GtkMenuBar... a menubar is a
|
|
920 list of menus or buttons
|
|
921 */
|
|
922 static void
|
|
923 menu_create_menubar (struct frame *f, Lisp_Object descr)
|
|
924 {
|
|
925 gboolean right_justify = FALSE;
|
|
926 Lisp_Object tail = Qnil;
|
|
927 Lisp_Object value = descr;
|
|
928 Lisp_Object item_descr = Qnil;
|
|
929 GtkWidget *menubar = FRAME_GTK_MENUBAR_WIDGET (f);
|
|
930 GUI_ID id = (GUI_ID) gtk_object_get_data (GTK_OBJECT (menubar), XEMACS_MENU_GUIID_TAG);
|
|
931 guint menu_position = 0;
|
|
932
|
|
933 /* Remove any existing protection for old menu items */
|
|
934 ungcpro_popup_callbacks (id);
|
|
935
|
|
936 /* GCPRO the whole damn thing */
|
|
937 gcpro_popup_callbacks (id, descr);
|
|
938
|
|
939 EXTERNAL_LIST_LOOP (tail, value)
|
|
940 {
|
|
941 gpointer current_child = g_list_nth_data (GTK_MENU_SHELL (menubar)->children, menu_position);
|
|
942
|
|
943 item_descr = XCAR (tail);
|
|
944
|
|
945 if (NILP (item_descr))
|
|
946 {
|
|
947 /* Need to start right-justifying menus */
|
|
948 right_justify = TRUE;
|
|
949 menu_position--;
|
|
950 }
|
|
951 else if (VECTORP (item_descr))
|
|
952 {
|
|
953 /* It is a button description */
|
|
954 GtkWidget *item;
|
|
955
|
|
956 item = menu_descriptor_to_widget (item_descr);
|
|
957 gtk_widget_set_name (item, "XEmacsMenuButton");
|
|
958
|
|
959 if (!item)
|
|
960 {
|
|
961 item = gtk_menu_item_new_with_label ("ITEM CREATION ERROR");
|
|
962 }
|
|
963
|
|
964 gtk_widget_show_all (item);
|
|
965 if (current_child) gtk_widget_destroy (GTK_WIDGET (current_child));
|
|
966 gtk_menu_bar_insert (GTK_MENU_BAR (menubar), item, menu_position);
|
|
967 }
|
|
968 else if (LISTP (item_descr))
|
|
969 {
|
|
970 /* Need to actually convert it into a menu and slap it in */
|
|
971 GtkWidget *widget;
|
|
972 gboolean reused_p = FALSE;
|
|
973
|
|
974 /* We may be able to reuse the widget, let's at least check. */
|
|
975 if (current_child && menu_can_reuse_widget (GTK_WIDGET (current_child),
|
|
976 XSTRING_DATA (XCAR (item_descr))))
|
|
977 {
|
|
978 widget = menu_convert (item_descr, GTK_WIDGET (current_child));
|
|
979 reused_p = TRUE;
|
|
980 }
|
|
981 else
|
|
982 {
|
|
983 widget = menu_convert (item_descr, NULL);
|
|
984 if (current_child) gtk_widget_destroy (GTK_WIDGET (current_child));
|
|
985 gtk_menu_bar_insert (GTK_MENU_BAR (menubar), widget, menu_position);
|
|
986 }
|
|
987
|
|
988 if (widget)
|
|
989 {
|
|
990 if (right_justify) gtk_menu_item_right_justify (GTK_MENU_ITEM (widget));
|
|
991 }
|
|
992 else
|
|
993 {
|
|
994 widget = gtk_menu_item_new_with_label ("ERROR");
|
|
995 /* abort() */
|
|
996 }
|
|
997 gtk_widget_show_all (widget);
|
|
998 }
|
|
999 else if (STRINGP (item_descr))
|
|
1000 {
|
|
1001 /* Do I really want to be this careful? Anything else in a
|
|
1002 menubar description is illegal */
|
|
1003 }
|
|
1004 menu_position++;
|
|
1005 }
|
|
1006
|
|
1007 /* Need to delete any menu items that were past the bounds of the new one */
|
|
1008 {
|
|
1009 GList *l = NULL;
|
|
1010
|
|
1011 while ((l = g_list_nth (GTK_MENU_SHELL (menubar)->children, menu_position)))
|
|
1012 {
|
|
1013 gpointer data = l->data;
|
|
1014 g_list_remove_link (GTK_MENU_SHELL (menubar)->children, l);
|
|
1015
|
|
1016 if (data)
|
|
1017 {
|
|
1018 gtk_widget_destroy (GTK_WIDGET (data));
|
|
1019 }
|
|
1020 }
|
|
1021 }
|
|
1022 }
|
|
1023
|
|
1024
|
|
1025 /* Deal with getting/setting the menubar */
|
|
1026 #ifndef GNOME_IS_APP
|
|
1027 #define GNOME_IS_APP(x) 0
|
|
1028 #define gnome_app_set_menus(x,y)
|
|
1029 #endif
|
|
1030
|
|
1031 static gboolean
|
|
1032 run_menubar_hook (GtkWidget *widget, GdkEventButton *event, gpointer user_data)
|
|
1033 {
|
|
1034 if (!GTK_MENU_SHELL(widget)->active)
|
|
1035 {
|
|
1036 run_hook (Qactivate_menubar_hook);
|
|
1037 }
|
|
1038 return(FALSE);
|
|
1039 }
|
|
1040
|
|
1041 static void
|
|
1042 create_menubar_widget (struct frame *f)
|
|
1043 {
|
|
1044 GUI_ID id = new_gui_id ();
|
|
1045 GtkWidget *handlebox = NULL;
|
|
1046 GtkWidget *menubar = gtk_xemacs_menubar_new (f);
|
|
1047
|
|
1048 if (GNOME_IS_APP (FRAME_GTK_SHELL_WIDGET (f)))
|
|
1049 {
|
|
1050 gnome_app_set_menus (GNOME_APP (FRAME_GTK_SHELL_WIDGET (f)), GTK_MENU_BAR (menubar));
|
|
1051 }
|
|
1052 else if (dockable_menubar)
|
|
1053 {
|
|
1054 handlebox = gtk_handle_box_new ();
|
|
1055 gtk_handle_box_set_handle_position (GTK_HANDLE_BOX (handlebox), GTK_POS_LEFT);
|
|
1056 gtk_container_add (GTK_CONTAINER (handlebox), menubar);
|
|
1057 gtk_box_pack_start (GTK_BOX (FRAME_GTK_CONTAINER_WIDGET (f)), handlebox, FALSE, FALSE, 0);
|
|
1058 }
|
|
1059 else
|
|
1060 {
|
|
1061 gtk_box_pack_start (GTK_BOX (FRAME_GTK_CONTAINER_WIDGET (f)), menubar, FALSE, FALSE, 0);
|
|
1062 }
|
|
1063
|
|
1064 gtk_signal_connect (GTK_OBJECT (menubar), "button-press-event",
|
|
1065 GTK_SIGNAL_FUNC (run_menubar_hook), NULL);
|
|
1066
|
|
1067 FRAME_GTK_MENUBAR_WIDGET (f) = menubar;
|
|
1068 gtk_object_set_data (GTK_OBJECT (menubar), XEMACS_MENU_GUIID_TAG, (gpointer) id);
|
|
1069 gtk_object_weakref (GTK_OBJECT (menubar), __remove_gcpro_by_id, (gpointer) id);
|
|
1070 }
|
|
1071
|
|
1072 static int
|
|
1073 set_frame_menubar (struct frame *f, int first_time_p)
|
|
1074 {
|
|
1075 Lisp_Object menubar;
|
|
1076 int menubar_visible;
|
|
1077 /* As for the toolbar, the minibuffer does not have its own menubar. */
|
|
1078 struct window *w = XWINDOW (FRAME_LAST_NONMINIBUF_WINDOW (f));
|
|
1079
|
|
1080 if (! FRAME_GTK_P (f))
|
|
1081 return 0;
|
|
1082
|
|
1083 /***** first compute the contents of the menubar *****/
|
|
1084
|
|
1085 if (! first_time_p)
|
|
1086 {
|
|
1087 /* evaluate `current-menubar' in the buffer of the selected window
|
|
1088 of the frame in question. */
|
|
1089 menubar = symbol_value_in_buffer (Qcurrent_menubar, w->buffer);
|
|
1090 }
|
|
1091 else
|
|
1092 {
|
|
1093 /* That's a little tricky the first time since the frame isn't
|
|
1094 fully initialized yet. */
|
|
1095 menubar = Fsymbol_value (Qcurrent_menubar);
|
|
1096 }
|
|
1097
|
|
1098 if (NILP (menubar))
|
|
1099 {
|
|
1100 menubar = Vblank_menubar;
|
|
1101 menubar_visible = 0;
|
|
1102 }
|
|
1103 else
|
|
1104 {
|
|
1105 menubar_visible = !NILP (w->menubar_visible_p);
|
|
1106 }
|
|
1107
|
|
1108 if (!FRAME_GTK_MENUBAR_WIDGET (f))
|
|
1109 {
|
|
1110 create_menubar_widget (f);
|
|
1111 }
|
|
1112
|
|
1113 /* Populate the menubar, but nothing is shown yet */
|
|
1114 {
|
|
1115 Lisp_Object old_buffer;
|
|
1116 int count = specpdl_depth ();
|
|
1117
|
|
1118 old_buffer = Fcurrent_buffer ();
|
|
1119 record_unwind_protect (Fset_buffer, old_buffer);
|
|
1120 Fset_buffer (XWINDOW (FRAME_SELECTED_WINDOW (f))->buffer);
|
|
1121
|
|
1122 menu_create_menubar (f, menubar);
|
|
1123
|
|
1124 Fset_buffer (old_buffer);
|
771
|
1125 unbind_to (count);
|
462
|
1126 }
|
|
1127
|
|
1128 FRAME_MENUBAR_DATA (f) = Fcons (XWINDOW (FRAME_LAST_NONMINIBUF_WINDOW (f))->buffer, Qt);
|
|
1129
|
|
1130 return (menubar_visible);
|
|
1131 }
|
|
1132
|
|
1133 /* Called from gtk_create_widgets() to create the inital menubar of a frame
|
|
1134 before it is mapped, so that the window is mapped with the menubar already
|
|
1135 there instead of us tacking it on later and thrashing the window after it
|
|
1136 is visible. */
|
|
1137 int
|
|
1138 gtk_initialize_frame_menubar (struct frame *f)
|
|
1139 {
|
|
1140 create_menubar_widget (f);
|
|
1141 return set_frame_menubar (f, 1);
|
|
1142 }
|
|
1143
|
|
1144
|
|
1145 static void
|
|
1146 gtk_update_frame_menubar_internal (struct frame *f)
|
|
1147 {
|
|
1148 /* We assume the menubar contents has changed if the global flag is set,
|
|
1149 or if the current buffer has changed, or if the menubar has never
|
|
1150 been updated before.
|
|
1151 */
|
|
1152 int menubar_contents_changed =
|
|
1153 (f->menubar_changed
|
|
1154 || NILP (FRAME_MENUBAR_DATA (f))
|
|
1155 || (!EQ (XFRAME_MENUBAR_DATA_LASTBUFF (f),
|
|
1156 XWINDOW (FRAME_LAST_NONMINIBUF_WINDOW (f))->buffer)));
|
|
1157
|
|
1158 gboolean menubar_was_visible = GTK_WIDGET_VISIBLE (FRAME_GTK_MENUBAR_WIDGET (f));
|
|
1159 gboolean menubar_will_be_visible = menubar_was_visible;
|
|
1160 gboolean menubar_visibility_changed;
|
|
1161
|
|
1162 if (menubar_contents_changed)
|
|
1163 {
|
|
1164 menubar_will_be_visible = set_frame_menubar (f, 0);
|
|
1165 }
|
|
1166
|
|
1167 menubar_visibility_changed = menubar_was_visible != menubar_will_be_visible;
|
|
1168
|
|
1169 if (!menubar_visibility_changed)
|
|
1170 {
|
|
1171 return;
|
|
1172 }
|
|
1173
|
|
1174 /* We hide and show the menubar's parent (which is actually the
|
|
1175 GtkHandleBox)... this is to simplify the code that destroys old
|
|
1176 menu items, etc. There is no easy way to get the child out of a
|
|
1177 handle box, and I didn't want to add yet another stupid widget
|
|
1178 slot to struct gtk_frame. */
|
|
1179 if (menubar_will_be_visible)
|
|
1180 {
|
|
1181 gtk_widget_show_all (FRAME_GTK_MENUBAR_WIDGET (f)->parent);
|
|
1182 }
|
|
1183 else
|
|
1184 {
|
|
1185 gtk_widget_hide_all (FRAME_GTK_MENUBAR_WIDGET (f)->parent);
|
|
1186 }
|
|
1187
|
|
1188 MARK_FRAME_SIZE_SLIPPED (f);
|
|
1189 }
|
|
1190
|
|
1191 static void
|
|
1192 gtk_update_frame_menubars (struct frame *f)
|
|
1193 {
|
|
1194 GtkWidget *menubar = NULL;
|
|
1195
|
|
1196 assert (FRAME_GTK_P (f));
|
|
1197
|
|
1198 menubar = FRAME_GTK_MENUBAR_WIDGET (f);
|
|
1199
|
|
1200 if ((GTK_MENU_SHELL (menubar)->active) ||
|
|
1201 (GTK_MENU_SHELL (menubar)->have_grab) ||
|
|
1202 (GTK_MENU_SHELL (menubar)->have_xgrab))
|
|
1203 {
|
|
1204 return;
|
|
1205 }
|
|
1206
|
|
1207 gtk_update_frame_menubar_internal (f);
|
|
1208 }
|
|
1209
|
|
1210 static void
|
|
1211 gtk_free_frame_menubars (struct frame *f)
|
|
1212 {
|
|
1213 GtkWidget *menubar_widget;
|
|
1214
|
|
1215 assert (FRAME_GTK_P (f));
|
|
1216
|
|
1217 menubar_widget = FRAME_GTK_MENUBAR_WIDGET (f);
|
|
1218 if (menubar_widget)
|
|
1219 {
|
|
1220 gtk_widget_destroy (menubar_widget);
|
|
1221 }
|
|
1222 }
|
|
1223
|
|
1224 static void popdown_menu_cb (GtkMenuShell *menu, gpointer user_data)
|
|
1225 {
|
|
1226 popup_up_p--;
|
|
1227 }
|
|
1228
|
|
1229 static void
|
|
1230 gtk_popup_menu (Lisp_Object menu_desc, Lisp_Object event)
|
|
1231 {
|
|
1232 struct Lisp_Event *eev = NULL;
|
714
|
1233 GtkWidget *widget = NULL;
|
|
1234 GtkWidget *menu = NULL;
|
|
1235 gpointer id = NULL;
|
462
|
1236
|
714
|
1237 /* Do basic error checking first... */
|
|
1238 if (SYMBOLP (menu_desc))
|
|
1239 menu_desc = Fsymbol_value (menu_desc);
|
|
1240 CHECK_CONS (menu_desc);
|
|
1241 CHECK_STRING (XCAR (menu_desc));
|
|
1242
|
|
1243 /* Now lets get down to business... */
|
|
1244 widget = menu_descriptor_to_widget (menu_desc);
|
|
1245 menu = GTK_MENU_ITEM (widget)->submenu;
|
462
|
1246 gtk_widget_set_name (widget, "XEmacsPopupMenu");
|
714
|
1247 id = gtk_object_get_data (GTK_OBJECT (widget), XEMACS_MENU_GUIID_TAG);
|
462
|
1248
|
|
1249 __activate_menu (GTK_MENU_ITEM (widget), id);
|
|
1250
|
|
1251 if (!NILP (event))
|
|
1252 {
|
|
1253 CHECK_LIVE_EVENT (event);
|
|
1254 eev = XEVENT (event);
|
|
1255
|
|
1256 if ((eev->event_type != button_press_event) &&
|
|
1257 (eev->event_type != button_release_event))
|
|
1258 wrong_type_argument (Qmouse_event_p, event);
|
|
1259 }
|
|
1260 else if (!NILP (Vthis_command_keys))
|
|
1261 {
|
|
1262 /* If an event wasn't passed, use the last event of the event
|
|
1263 sequence currently being executed, if that event is a mouse
|
|
1264 event. */
|
|
1265 eev = XEVENT (Vthis_command_keys);
|
|
1266 if ((eev->event_type != button_press_event) &&
|
|
1267 (eev->event_type != button_release_event))
|
|
1268 eev = NULL;
|
|
1269 }
|
|
1270
|
|
1271 gtk_widget_show (menu);
|
|
1272
|
|
1273 popup_up_p++;
|
|
1274 gtk_signal_connect (GTK_OBJECT (menu), "deactivate",
|
|
1275 GTK_SIGNAL_FUNC (popdown_menu_cb), NULL);
|
|
1276
|
|
1277 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
|
|
1278 eev ? eev->event.button.button : 0,
|
|
1279 eev ? eev->timestamp : GDK_CURRENT_TIME);
|
|
1280 }
|
|
1281
|
|
1282 DEFUN ("gtk-build-xemacs-menu", Fgtk_build_xemacs_menu, 1, 1, 0, /*
|
|
1283 Returns a GTK menu item from MENU, a standard XEmacs menu description.
|
|
1284 See the definition of `popup-menu' for more information on the format of MENU.
|
|
1285 */
|
|
1286 (menu))
|
|
1287 {
|
|
1288 GtkWidget *w = menu_descriptor_to_widget (menu);
|
|
1289
|
|
1290 return (w ? build_gtk_object (GTK_OBJECT (w)) : Qnil);
|
|
1291 }
|
|
1292
|
|
1293
|
|
1294 void
|
|
1295 syms_of_menubar_gtk (void)
|
|
1296 {
|
|
1297 DEFSUBR (Fgtk_build_xemacs_menu);
|
|
1298 }
|
|
1299
|
|
1300 void
|
|
1301 console_type_create_menubar_gtk (void)
|
|
1302 {
|
|
1303 CONSOLE_HAS_METHOD (gtk, update_frame_menubars);
|
|
1304 CONSOLE_HAS_METHOD (gtk, free_frame_menubars);
|
|
1305 CONSOLE_HAS_METHOD (gtk, popup_menu);
|
|
1306 }
|
|
1307
|
|
1308 void reinit_vars_of_menubar_gtk (void)
|
|
1309 {
|
|
1310 dockable_menubar = 1;
|
|
1311 #ifdef TEAR_OFF_MENUS
|
|
1312 tear_off_menus = 1;
|
|
1313 #endif
|
|
1314 }
|
|
1315
|
|
1316 void
|
|
1317 vars_of_menubar_gtk (void)
|
|
1318 {
|
|
1319 Fprovide (intern ("gtk-menubars"));
|
|
1320 DEFVAR_BOOL ("menubar-dockable-p", &dockable_menubar /*
|
|
1321 If non-nil, the frame menubar can be detached into its own top-level window.
|
|
1322 */ );
|
|
1323 #ifdef TEAR_OFF_MENUS
|
|
1324 DEFVAR_BOOL ("menubar-tearable-p", &tear_off_menus /*
|
|
1325 If non-nil, menus can be torn off into their own top-level windows.
|
|
1326 */ );
|
|
1327 #endif
|
|
1328 reinit_vars_of_menubar_gtk ();
|
|
1329 }
|