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