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