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