gtkmenubar.c 16.6 KB
Newer Older
Elliot Lee's avatar
Elliot Lee committed
1 2 3 4
/* GTK - The GIMP Toolkit
 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
 *
 * This library is free software; you can redistribute it and/or
5
 * modify it under the terms of the GNU Lesser General Public
Elliot Lee's avatar
Elliot Lee committed
6 7 8 9 10 11
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 * Lesser General Public License for more details.
Elliot Lee's avatar
Elliot Lee committed
13
 *
14
 * You should have received a copy of the GNU Lesser General Public
15 16 17
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
Elliot Lee's avatar
Elliot Lee committed
18
 */
19 20

/*
21
 * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
22 23 24 25 26
 * file for a list of people on the GTK+ Team.  See the ChangeLog
 * files for a list of changes.  These files are distributed with
 * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
 */

27 28
#define GTK_MENU_INTERNALS

29 30
#include "gdk/gdkkeysyms.h"
#include "gtkbindings.h"
Elliot Lee's avatar
Elliot Lee committed
31
#include "gtkmain.h"
32
#include "gtkmarshalers.h"
Elliot Lee's avatar
Elliot Lee committed
33 34
#include "gtkmenubar.h"
#include "gtkmenuitem.h"
Havoc Pennington's avatar
Havoc Pennington committed
35 36 37
#include "gtksettings.h"
#include "gtkintl.h"
#include "gtkwindow.h"
Elliot Lee's avatar
Elliot Lee committed
38 39


40
#define BORDER_SPACING  0
Elliot Lee's avatar
Elliot Lee committed
41
#define CHILD_SPACING   3
42
#define DEFAULT_IPADDING 1
Elliot Lee's avatar
Elliot Lee committed
43

44 45 46 47 48 49 50 51 52 53 54 55 56 57
static void gtk_menu_bar_class_init        (GtkMenuBarClass *klass);
static void gtk_menu_bar_size_request      (GtkWidget       *widget,
					    GtkRequisition  *requisition);
static void gtk_menu_bar_size_allocate     (GtkWidget       *widget,
					    GtkAllocation   *allocation);
static void gtk_menu_bar_paint             (GtkWidget       *widget,
					    GdkRectangle    *area);
static gint gtk_menu_bar_expose            (GtkWidget       *widget,
					    GdkEventExpose  *event);
static void gtk_menu_bar_hierarchy_changed (GtkWidget       *widget,
					    GtkWidget       *old_toplevel);
static gint gtk_menu_bar_get_popup_delay  (GtkMenuShell    *menu_shell);
					    

Havoc Pennington's avatar
Havoc Pennington committed
58
static GtkShadowType get_shadow_type   (GtkMenuBar      *menubar);
Elliot Lee's avatar
Elliot Lee committed
59

60 61
static GtkMenuShellClass *parent_class = NULL;

Manish Singh's avatar
Manish Singh committed
62
GType
63
gtk_menu_bar_get_type (void)
Elliot Lee's avatar
Elliot Lee committed
64
{
Manish Singh's avatar
Manish Singh committed
65
  static GType menu_bar_type = 0;
Elliot Lee's avatar
Elliot Lee committed
66 67 68

  if (!menu_bar_type)
    {
Manish Singh's avatar
Manish Singh committed
69
      static const GTypeInfo menu_bar_info =
Elliot Lee's avatar
Elliot Lee committed
70 71
      {
	sizeof (GtkMenuBarClass),
Manish Singh's avatar
Manish Singh committed
72 73 74 75 76 77 78 79
	NULL,		/* base_init */
	NULL,		/* base_finalize */
	(GClassInitFunc) gtk_menu_bar_class_init,
	NULL,		/* class_finalize */
	NULL,		/* class_data */
	sizeof (GtkMenuBar),
	0,		/* n_preallocs */
	NULL,		/* instance_init */
Elliot Lee's avatar
Elliot Lee committed
80 81
      };

Manish Singh's avatar
Manish Singh committed
82 83
      menu_bar_type = g_type_register_static (GTK_TYPE_MENU_SHELL, "GtkMenuBar",
					      &menu_bar_info, 0);
Elliot Lee's avatar
Elliot Lee committed
84 85 86 87 88 89 90 91
    }

  return menu_bar_type;
}

static void
gtk_menu_bar_class_init (GtkMenuBarClass *class)
{
92
  GtkObjectClass *object_class;
Elliot Lee's avatar
Elliot Lee committed
93 94 95
  GtkWidgetClass *widget_class;
  GtkMenuShellClass *menu_shell_class;

96 97
  GtkBindingSet *binding_set;

98 99
  parent_class = g_type_class_peek_parent (class);
  
100
  object_class = (GtkObjectClass*) class;
Elliot Lee's avatar
Elliot Lee committed
101 102 103 104 105 106
  widget_class = (GtkWidgetClass*) class;
  menu_shell_class = (GtkMenuShellClass*) class;

  widget_class->size_request = gtk_menu_bar_size_request;
  widget_class->size_allocate = gtk_menu_bar_size_allocate;
  widget_class->expose_event = gtk_menu_bar_expose;
Havoc Pennington's avatar
Havoc Pennington committed
107 108
  widget_class->hierarchy_changed = gtk_menu_bar_hierarchy_changed;
  
Elliot Lee's avatar
Elliot Lee committed
109
  menu_shell_class->submenu_placement = GTK_TOP_BOTTOM;
110
  menu_shell_class->get_popup_delay = gtk_menu_bar_get_popup_delay;
111 112 113 114 115 116 117

  binding_set = gtk_binding_set_by_class (class);
  gtk_binding_entry_add_signal (binding_set,
				GDK_Left, 0,
				"move_current", 1,
				GTK_TYPE_MENU_DIRECTION_TYPE,
				GTK_MENU_DIR_PREV);
118 119 120 121 122
  gtk_binding_entry_add_signal (binding_set,
				GDK_KP_Left, 0,
				"move_current", 1,
				GTK_TYPE_MENU_DIRECTION_TYPE,
				GTK_MENU_DIR_PREV);
123 124 125 126 127
  gtk_binding_entry_add_signal (binding_set,
				GDK_Right, 0,
				"move_current", 1,
				GTK_TYPE_MENU_DIRECTION_TYPE,
				GTK_MENU_DIR_NEXT);
128 129 130 131 132
  gtk_binding_entry_add_signal (binding_set,
				GDK_KP_Right, 0,
				"move_current", 1,
				GTK_TYPE_MENU_DIRECTION_TYPE,
				GTK_MENU_DIR_NEXT);
133 134 135 136 137
  gtk_binding_entry_add_signal (binding_set,
				GDK_Up, 0,
				"move_current", 1,
				GTK_TYPE_MENU_DIRECTION_TYPE,
				GTK_MENU_DIR_PARENT);
138 139 140 141 142
  gtk_binding_entry_add_signal (binding_set,
				GDK_KP_Up, 0,
				"move_current", 1,
				GTK_TYPE_MENU_DIRECTION_TYPE,
				GTK_MENU_DIR_PARENT);
143 144 145 146 147
  gtk_binding_entry_add_signal (binding_set,
				GDK_Down, 0,
				"move_current", 1,
				GTK_TYPE_MENU_DIRECTION_TYPE,
				GTK_MENU_DIR_CHILD);
148 149 150 151 152
  gtk_binding_entry_add_signal (binding_set,
				GDK_KP_Down, 0,
				"move_current", 1,
				GTK_TYPE_MENU_DIRECTION_TYPE,
				GTK_MENU_DIR_CHILD);
Havoc Pennington's avatar
Havoc Pennington committed
153 154 155 156 157 158 159 160

  gtk_widget_class_install_style_property (widget_class,
					   g_param_spec_enum ("shadow_type",
                                                              _("Shadow type"),
                                                              _("Style of bevel around the menubar"),
                                                              GTK_TYPE_SHADOW_TYPE,
                                                              GTK_SHADOW_OUT,
                                                              G_PARAM_READABLE));
161 162 163 164 165 166 167 168 169 170

  gtk_widget_class_install_style_property (widget_class,
					   g_param_spec_int ("internal_padding",
							     _("Internal padding"),
							     _("Amount of border space between the menubar shadow and the menu items"),
							     0,
							     G_MAXINT,
                                                             DEFAULT_IPADDING,
                                                             G_PARAM_READABLE));

171 172 173 174 175 176 177
  gtk_settings_install_property (g_param_spec_int ("gtk-menu-bar-popup-delay",
						   _("Delay before drop down menus appear"),
						   _("Delay before the submenus of a menu bar appear"),
						   0,
						   G_MAXINT,
						   0,
						   G_PARAM_READWRITE));
178 179
}
 
Elliot Lee's avatar
Elliot Lee committed
180
GtkWidget*
181
gtk_menu_bar_new (void)
Elliot Lee's avatar
Elliot Lee committed
182
{
Manish Singh's avatar
Manish Singh committed
183
  return g_object_new (GTK_TYPE_MENU_BAR, NULL);
Elliot Lee's avatar
Elliot Lee committed
184 185 186 187 188 189 190 191 192 193 194
}

static void
gtk_menu_bar_size_request (GtkWidget      *widget,
			   GtkRequisition *requisition)
{
  GtkMenuBar *menu_bar;
  GtkMenuShell *menu_shell;
  GtkWidget *child;
  GList *children;
  gint nchildren;
195
  GtkRequisition child_requisition;
196
  gint ipadding;
Elliot Lee's avatar
Elliot Lee committed
197 198 199 200 201 202

  g_return_if_fail (GTK_IS_MENU_BAR (widget));
  g_return_if_fail (requisition != NULL);

  requisition->width = 0;
  requisition->height = 0;
203
  
Elliot Lee's avatar
Elliot Lee committed
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
  if (GTK_WIDGET_VISIBLE (widget))
    {
      menu_bar = GTK_MENU_BAR (widget);
      menu_shell = GTK_MENU_SHELL (widget);

      nchildren = 0;
      children = menu_shell->children;

      while (children)
	{
	  child = children->data;
	  children = children->next;

	  if (GTK_WIDGET_VISIBLE (child))
	    {
219 220
              gint toggle_size;
              
Elliot Lee's avatar
Elliot Lee committed
221
	      GTK_MENU_ITEM (child)->show_submenu_indicator = FALSE;
222
	      gtk_widget_size_request (child, &child_requisition);
223 224 225
              gtk_menu_item_toggle_size_request (GTK_MENU_ITEM (child),
                                                 &toggle_size);
              
226
	      requisition->width += child_requisition.width;
227 228
              requisition->width += toggle_size;
              
229
	      requisition->height = MAX (requisition->height, child_requisition.height);
230
	      /* Support for the right justified help menu */
231 232
	      if ((children == NULL) && GTK_IS_MENU_ITEM(child) &&
		  GTK_MENU_ITEM(child)->right_justify)
233 234 235
		{
		  requisition->width += CHILD_SPACING;
		}
Elliot Lee's avatar
Elliot Lee committed
236 237 238 239 240

	      nchildren += 1;
	    }
	}

241 242
      gtk_widget_style_get (widget, "internal_padding", &ipadding, NULL);
      
Elliot Lee's avatar
Elliot Lee committed
243
      requisition->width += (GTK_CONTAINER (menu_bar)->border_width +
244
                             ipadding + 
Elliot Lee's avatar
Elliot Lee committed
245 246
			     BORDER_SPACING) * 2;
      requisition->height += (GTK_CONTAINER (menu_bar)->border_width +
247
                              ipadding +
Elliot Lee's avatar
Elliot Lee committed
248 249
			      BORDER_SPACING) * 2;

250 251 252 253 254 255
      if (get_shadow_type (menu_bar) != GTK_SHADOW_NONE)
	{
	  requisition->width += widget->style->xthickness * 2;
	  requisition->height += widget->style->ythickness * 2;
	}

Elliot Lee's avatar
Elliot Lee committed
256 257 258 259 260 261 262 263 264 265 266 267 268 269
      if (nchildren > 0)
	requisition->width += 2 * CHILD_SPACING * (nchildren - 1);
    }
}

static void
gtk_menu_bar_size_allocate (GtkWidget     *widget,
			    GtkAllocation *allocation)
{
  GtkMenuBar *menu_bar;
  GtkMenuShell *menu_shell;
  GtkWidget *child;
  GList *children;
  GtkAllocation child_allocation;
270
  GtkRequisition child_requisition;
Elliot Lee's avatar
Elliot Lee committed
271
  guint offset;
272
  gint ipadding;
273 274 275
  GtkTextDirection direction;
  gint ltr_x;

Elliot Lee's avatar
Elliot Lee committed
276 277 278 279 280 281
  g_return_if_fail (GTK_IS_MENU_BAR (widget));
  g_return_if_fail (allocation != NULL);

  menu_bar = GTK_MENU_BAR (widget);
  menu_shell = GTK_MENU_SHELL (widget);

282 283
  direction = gtk_widget_get_direction (widget);

Elliot Lee's avatar
Elliot Lee committed
284 285 286 287 288 289
  widget->allocation = *allocation;
  if (GTK_WIDGET_REALIZED (widget))
    gdk_window_move_resize (widget->window,
			    allocation->x, allocation->y,
			    allocation->width, allocation->height);

290 291
  gtk_widget_style_get (widget, "internal_padding", &ipadding, NULL);
  
Elliot Lee's avatar
Elliot Lee committed
292 293 294
  if (menu_shell->children)
    {
      child_allocation.x = (GTK_CONTAINER (menu_bar)->border_width +
295
                            ipadding + 
Elliot Lee's avatar
Elliot Lee committed
296 297
			    BORDER_SPACING);
      child_allocation.y = (GTK_CONTAINER (menu_bar)->border_width +
298
                            ipadding +
Elliot Lee's avatar
Elliot Lee committed
299
			    BORDER_SPACING);
300 301 302 303 304 305 306

      if (get_shadow_type (menu_bar) != GTK_SHADOW_NONE)
	{
	  child_allocation.x += widget->style->xthickness;
	  child_allocation.y += widget->style->ythickness;
	}
      
307
      child_allocation.height = MAX (1, (gint)allocation->height - child_allocation.y * 2);
Elliot Lee's avatar
Elliot Lee committed
308

309
      offset = child_allocation.x; 	/* Window edge to menubar start */
310
      ltr_x = child_allocation.x;
311

Elliot Lee's avatar
Elliot Lee committed
312 313 314
      children = menu_shell->children;
      while (children)
	{
315 316
          gint toggle_size;          

Elliot Lee's avatar
Elliot Lee committed
317 318 319
	  child = children->data;
	  children = children->next;

320 321
          gtk_menu_item_toggle_size_request (GTK_MENU_ITEM (child),
                                             &toggle_size);
322
	  gtk_widget_get_child_requisition (child, &child_requisition);
323 324 325

          child_requisition.width += toggle_size;
          
Elliot Lee's avatar
Elliot Lee committed
326
	  /* Support for the right justified help menu */
327
	  if ((children == NULL) && (GTK_IS_MENU_ITEM(child))
328 329
	      && (GTK_MENU_ITEM(child)->right_justify)) 
	    {
330 331
	      ltr_x = allocation->width -
		child_requisition.width - offset;
332
	    }
Elliot Lee's avatar
Elliot Lee committed
333 334
	  if (GTK_WIDGET_VISIBLE (child))
	    {
335 336 337 338 339 340
	      if (direction == GTK_TEXT_DIR_LTR) 
		child_allocation.x = ltr_x;
	      else
		child_allocation.x = allocation->width -
		  child_requisition.width - ltr_x; 

341
	      child_allocation.width = child_requisition.width;
Elliot Lee's avatar
Elliot Lee committed
342

343 344
              gtk_menu_item_toggle_size_allocate (GTK_MENU_ITEM (child),
                                                  toggle_size);
Elliot Lee's avatar
Elliot Lee committed
345 346
	      gtk_widget_size_allocate (child, &child_allocation);

347
	      ltr_x += child_allocation.width + CHILD_SPACING * 2;
Elliot Lee's avatar
Elliot Lee committed
348 349 350 351 352 353
	    }
	}
    }
}

static void
354
gtk_menu_bar_paint (GtkWidget *widget, GdkRectangle *area)
Elliot Lee's avatar
Elliot Lee committed
355 356 357 358 359
{
  g_return_if_fail (GTK_IS_MENU_BAR (widget));

  if (GTK_WIDGET_DRAWABLE (widget))
    {
360 361 362 363
      gint border;

      border = GTK_CONTAINER (widget)->border_width;
      
364 365
      gtk_paint_box (widget->style,
		     widget->window,
366
                     GTK_WIDGET_STATE (widget),
Havoc Pennington's avatar
Havoc Pennington committed
367
                     get_shadow_type (GTK_MENU_BAR (widget)),
368
		     area, widget, "menubar",
369 370 371
		     border, border,
		     widget->allocation.width - border * 2,
                     widget->allocation.height - border * 2);
Elliot Lee's avatar
Elliot Lee committed
372 373 374 375 376 377 378 379 380 381 382 383
    }
}

static gint
gtk_menu_bar_expose (GtkWidget      *widget,
		     GdkEventExpose *event)
{
  g_return_val_if_fail (GTK_IS_MENU_BAR (widget), FALSE);
  g_return_val_if_fail (event != NULL, FALSE);

  if (GTK_WIDGET_DRAWABLE (widget))
    {
384
      gtk_menu_bar_paint (widget, &event->area);
Elliot Lee's avatar
Elliot Lee committed
385

386
      (* GTK_WIDGET_CLASS (parent_class)->expose_event) (widget, event);
Elliot Lee's avatar
Elliot Lee committed
387 388 389 390
    }

  return FALSE;
}
Havoc Pennington's avatar
Havoc Pennington committed
391

392 393 394 395 396 397
static GList *
get_menu_bars (GtkWindow *window)
{
  return g_object_get_data (G_OBJECT (window), "gtk-menu-bar-list");
}

398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425
static GList *
get_viewable_menu_bars (GtkWindow *window)
{
  GList *menu_bars;
  GList *viewable_menu_bars = NULL;

  for (menu_bars = get_menu_bars (window);
       menu_bars;
       menu_bars = menu_bars->next)
    {
      GtkWidget *widget = menu_bars->data;
      gboolean viewable = TRUE;
      
      while (widget)
	{
	  if (!GTK_WIDGET_MAPPED (widget))
	    viewable = FALSE;
	  
	  widget = widget->parent;
	}

      if (viewable)
	viewable_menu_bars = g_list_prepend (viewable_menu_bars, menu_bars->data);
    }

  return g_list_reverse (viewable_menu_bars);
}

426 427 428 429 430 431 432
static void
set_menu_bars (GtkWindow *window,
	       GList     *menubars)
{
  g_object_set_data (G_OBJECT (window), "gtk-menu-bar-list", menubars);
}

Havoc Pennington's avatar
Havoc Pennington committed
433 434 435 436 437 438 439 440
static gboolean
window_key_press_handler (GtkWidget   *widget,
                          GdkEventKey *event,
                          gpointer     data)
{
  gchar *accel = NULL;
  gboolean retval = FALSE;
  
441
  g_object_get (gtk_widget_get_settings (widget),
Havoc Pennington's avatar
Havoc Pennington committed
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460
                "gtk-menu-bar-accel",
                &accel,
                NULL);

  if (accel)
    {
      guint keyval = 0;
      GdkModifierType mods = 0;

      gtk_accelerator_parse (accel, &keyval, &mods);

      if (keyval == 0)
        g_warning ("Failed to parse menu bar accelerator '%s'\n", accel);

      /* FIXME this is wrong, needs to be in the global accel resolution
       * thing, to properly consider i18n etc., but that probably requires
       * AccelGroup changes etc.
       */
      if (event->keyval == keyval &&
Owen Taylor's avatar
Owen Taylor committed
461 462
          ((event->state & gtk_accelerator_get_default_mod_mask ()) ==
	   (mods & gtk_accelerator_get_default_mod_mask ())))
Havoc Pennington's avatar
Havoc Pennington committed
463
        {
464 465
	  GList *tmp_menubars = get_viewable_menu_bars (GTK_WINDOW (widget));
	  GList *menubars;
Havoc Pennington's avatar
Havoc Pennington committed
466

467
	  menubars = _gtk_container_focus_sort (GTK_CONTAINER (widget), tmp_menubars,
468
						GTK_DIR_TAB_FORWARD, NULL);
469 470
	  g_list_free (tmp_menubars);
	  
471 472
	  if (menubars)
	    {
473
	      GtkMenuShell *menu_shell = GTK_MENU_SHELL (menubars->data);
474

475
	      _gtk_menu_shell_activate (menu_shell);
476
	      gtk_menu_shell_select_first (menu_shell, FALSE);
477 478
	      
	      g_list_free (menubars);
479 480
	      
	      retval = TRUE;	      
481
	    }
Havoc Pennington's avatar
Havoc Pennington committed
482 483 484 485 486 487 488 489 490 491 492 493
        }

      g_free (accel);
    }

  return retval;
}

static void
add_to_window (GtkWindow  *window,
               GtkMenuBar *menubar)
{
494
  GList *menubars = get_menu_bars (window);
Havoc Pennington's avatar
Havoc Pennington committed
495

496 497
  if (!menubars)
    {
Manish Singh's avatar
Manish Singh committed
498
      g_signal_connect (window,
499 500 501 502 503 504
			"key_press_event",
			G_CALLBACK (window_key_press_handler),
			NULL);
    }

  set_menu_bars (window, g_list_prepend (menubars, menubar));
Havoc Pennington's avatar
Havoc Pennington committed
505 506 507 508 509 510
}

static void
remove_from_window (GtkWindow  *window,
                    GtkMenuBar *menubar)
{
511 512 513 514 515 516 517 518 519
  GList *menubars = get_menu_bars (window);

  menubars = g_object_get_data (G_OBJECT (window),
				    "gtk-menu-bar-list");

  menubars = g_list_remove (menubars, menubar);

  if (!menubars)
    {
Manish Singh's avatar
Manish Singh committed
520 521
      g_signal_handlers_disconnect_by_func (window,
					    window_key_press_handler,
522 523 524 525
					    NULL);
    }

  set_menu_bars (window, menubars);
Havoc Pennington's avatar
Havoc Pennington committed
526 527 528
}

static void
529 530
gtk_menu_bar_hierarchy_changed (GtkWidget *widget,
				GtkWidget *old_toplevel)
Havoc Pennington's avatar
Havoc Pennington committed
531 532 533 534 535 536 537 538
{
  GtkWidget *toplevel;  
  GtkMenuBar *menubar;

  menubar = GTK_MENU_BAR (widget);

  toplevel = gtk_widget_get_toplevel (widget);

539
  if (old_toplevel)
540
    remove_from_window (GTK_WINDOW (old_toplevel), menubar);
Havoc Pennington's avatar
Havoc Pennington committed
541
  
542
  if (GTK_WIDGET_TOPLEVEL (toplevel))
543
    add_to_window (GTK_WINDOW (toplevel), menubar);
Havoc Pennington's avatar
Havoc Pennington committed
544 545
}

546 547 548 549 550 551 552 553 554 555
/**
 * _gtk_menu_bar_cycle_focus:
 * @menubar: a #GtkMenuBar
 * @dir: direction in which to cycle the focus
 * 
 * Move the focus between menubars in the toplevel.
 **/
void
_gtk_menu_bar_cycle_focus (GtkMenuBar       *menubar,
			   GtkDirectionType  dir)
556 557
{
  GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (menubar));
558
  GtkMenuItem *to_activate = NULL;
559 560 561

  if (GTK_WIDGET_TOPLEVEL (toplevel))
    {
562 563
      GList *tmp_menubars = get_viewable_menu_bars (GTK_WINDOW (toplevel));
      GList *menubars;
564 565
      GList *current;

566
      menubars = _gtk_container_focus_sort (GTK_CONTAINER (toplevel), tmp_menubars,
567
					    dir, GTK_WIDGET (menubar));
568
      g_list_free (tmp_menubars);
569 570 571 572

      if (menubars)
	{
	  current = g_list_find (menubars, menubar);
573

574 575
	  if (current && current->next)
	    {
576
	      GtkMenuShell *new_menushell = GTK_MENU_SHELL (current->next->data);
577
	      if (new_menushell->children)
578
		to_activate = new_menushell->children->data;
579 580 581 582 583
	    }
	}
	  
      g_list_free (menubars);
    }
584 585 586 587 588

  g_signal_emit_by_name (menubar, "cancel", 0);

  if (to_activate)
    g_signal_emit_by_name (to_activate, "activate_item");
589 590
}

Havoc Pennington's avatar
Havoc Pennington committed
591 592 593 594 595 596 597 598 599 600 601
static GtkShadowType
get_shadow_type (GtkMenuBar *menubar)
{
  GtkShadowType shadow_type = GTK_SHADOW_OUT;
  
  gtk_widget_style_get (GTK_WIDGET (menubar),
			"shadow_type", &shadow_type,
			NULL);

  return shadow_type;
}
602 603 604 605 606 607

static gint
gtk_menu_bar_get_popup_delay (GtkMenuShell *menu_shell)
{
  gint popup_delay;
  
608
  g_object_get (gtk_widget_get_settings (GTK_WIDGET (menu_shell)),
609 610 611 612 613
		"gtk-menu-bar-popup-delay", &popup_delay,
		NULL);

  return popup_delay;
}