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