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