]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkmenu.c
Practically everything changed.
[~andy/gtk] / gtk / gtkmenu.c
index 38c950ad4886f5bbc70efa124a56133318b4ad79..d9abe030c0a47480b60fe11307cea29471157cbf 100644 (file)
@@ -1,4 +1,4 @@
-/* GTK - The GIMP Toolkit
+/* GTK - The GTK+ Toolkit
  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
  *
  * This library is free software; you can redistribute it and/or
@@ -25,8 +25,7 @@
  */
 
 #define GTK_MENU_INTERNALS
-
-#include <config.h>
+#include "config.h"
 #include <string.h> /* memset */
 #include "gdk/gdkkeysyms.h"
 #include "gtkaccellabel.h"
@@ -58,7 +57,6 @@
 
 #define MENU_SCROLL_STEP1 8
 #define MENU_SCROLL_STEP2 15
-#define MENU_SCROLL_ARROW_HEIGHT 16
 #define MENU_SCROLL_FAST_ZONE 8
 #define MENU_SCROLL_TIMEOUT1 50
 #define MENU_SCROLL_TIMEOUT2 20
@@ -93,6 +91,15 @@ struct _GtkMenuPrivate
   gboolean have_layout;
   gint n_rows;
   gint n_columns;
+
+  gchar *title;
+
+  /* Arrow states */
+  GtkStateType lower_arrow_state;
+  GtkStateType upper_arrow_state;
+
+  gboolean ignore_button_release;
+  gboolean initially_pushed_in;
 };
 
 typedef struct
@@ -114,8 +121,13 @@ enum {
 
 enum {
   PROP_0,
+  PROP_ACTIVE,
+  PROP_ACCEL_GROUP,
+  PROP_ACCEL_PATH,
+  PROP_ATTACH_WIDGET,
   PROP_TEAROFF_STATE,
-  PROP_TEAROFF_TITLE
+  PROP_TEAROFF_TITLE,
+  PROP_MONITOR
 };
 
 enum {
@@ -126,8 +138,6 @@ enum {
   CHILD_PROP_BOTTOM_ATTACH
 };
 
-static void     gtk_menu_class_init        (GtkMenuClass     *klass);
-static void     gtk_menu_init              (GtkMenu          *menu);
 static void     gtk_menu_set_property      (GObject          *object,
                                            guint             prop_id,
                                            const GValue     *value,
@@ -147,7 +157,6 @@ static void     gtk_menu_get_child_property(GtkContainer     *container,
                                             GValue           *value,
                                             GParamSpec       *pspec);
 static void     gtk_menu_destroy           (GtkObject        *object);
-static void     gtk_menu_finalize          (GObject          *object);
 static void     gtk_menu_realize           (GtkWidget        *widget);
 static void     gtk_menu_unrealize         (GtkWidget        *widget);
 static void     gtk_menu_size_request      (GtkWidget        *widget,
@@ -175,10 +184,14 @@ static gboolean gtk_menu_leave_notify      (GtkWidget        *widget,
                                            GdkEventCrossing *event);
 static void     gtk_menu_scroll_to         (GtkMenu          *menu,
                                            gint              offset);
+static void     gtk_menu_grab_notify       (GtkWidget        *widget,
+                                           gboolean          was_grabbed);
 
-static void     gtk_menu_stop_scrolling        (GtkMenu  *menu);
-static void     gtk_menu_remove_scroll_timeout (GtkMenu  *menu);
-static gboolean gtk_menu_scroll_timeout        (gpointer  data);
+static void     gtk_menu_stop_scrolling         (GtkMenu  *menu);
+static void     gtk_menu_remove_scroll_timeout  (GtkMenu  *menu);
+static gboolean gtk_menu_scroll_timeout         (gpointer  data);
+static gboolean gtk_menu_scroll_timeout_initial (gpointer  data);
+static void     gtk_menu_start_scrolling        (GtkMenu  *menu);
 
 static void     gtk_menu_scroll_item_visible (GtkMenuShell    *menu_shell,
                                              GtkWidget       *menu_item);
@@ -192,7 +205,8 @@ static void     gtk_menu_scrollbar_changed (GtkAdjustment    *adjustment,
 static void     gtk_menu_handle_scrolling  (GtkMenu          *menu,
                                            gint              event_x,
                                            gint              event_y,
-                                           gboolean          enter);
+                                           gboolean          enter,
+                                            gboolean          motion);
 static void     gtk_menu_set_tearoff_hints (GtkMenu          *menu,
                                            gint             width);
 static void     gtk_menu_style_set         (GtkWidget        *widget,
@@ -234,70 +248,17 @@ static gboolean gtk_menu_real_can_activate_accel (GtkWidget *widget,
 static void _gtk_menu_refresh_accel_paths (GtkMenu *menu,
                                           gboolean group_changed);
 
-static GtkMenuShellClass *parent_class = NULL;
 static const gchar       attach_data_key[] = "gtk-menu-attach-data";
 
 static guint menu_signals[LAST_SIGNAL] = { 0 };
 
-static void
-gtk_menu_free_private (gpointer data)
-{
-  GtkMenuPrivate *priv = (GtkMenuPrivate *)data;
-
-  g_free (priv->heights);
-
-  g_free (priv);
-}
-
 static GtkMenuPrivate *
 gtk_menu_get_private (GtkMenu *menu)
 {
-  GtkMenuPrivate *private;
-  static GQuark private_quark = 0;
-
-  if (!private_quark)
-    private_quark = g_quark_from_static_string ("gtk-menu-private");
-
-  private = g_object_get_qdata (G_OBJECT (menu), private_quark);
-
-  if (!private)
-    {
-      private = g_new0 (GtkMenuPrivate, 1);
-      private->have_position = FALSE;
-      
-      g_object_set_qdata_full (G_OBJECT (menu), private_quark,
-                              private, gtk_menu_free_private);
-    }
-
-  return private;
+  return G_TYPE_INSTANCE_GET_PRIVATE (menu, GTK_TYPE_MENU, GtkMenuPrivate);
 }
 
-GType
-gtk_menu_get_type (void)
-{
-  static GType menu_type = 0;
-  
-  if (!menu_type)
-    {
-      static const GTypeInfo menu_info =
-      {
-       sizeof (GtkMenuClass),
-       NULL,           /* base_init */
-       NULL,           /* base_finalize */
-       (GClassInitFunc) gtk_menu_class_init,
-       NULL,           /* class_finalize */
-       NULL,           /* class_data */
-       sizeof (GtkMenu),
-       0,              /* n_preallocs */
-       (GInstanceInitFunc) gtk_menu_init,
-      };
-      
-      menu_type = g_type_register_static (GTK_TYPE_MENU_SHELL, "GtkMenu",
-                                         &menu_info, 0);
-    }
-  
-  return menu_type;
-}
+G_DEFINE_TYPE (GtkMenu, gtk_menu, GTK_TYPE_MENU_SHELL)
 
 static void
 menu_queue_resize (GtkMenu *menu)
@@ -308,6 +269,12 @@ menu_queue_resize (GtkMenu *menu)
   gtk_widget_queue_resize (GTK_WIDGET (menu));
 }
 
+static void
+attach_info_free (AttachInfo *info)
+{
+  g_slice_free (AttachInfo, info);
+}
+
 static AttachInfo *
 get_attach_info (GtkWidget *child)
 {
@@ -316,8 +283,9 @@ get_attach_info (GtkWidget *child)
 
   if (!ai)
     {
-      ai = g_new0 (AttachInfo, 1);
-      g_object_set_data_full (object, ATTACH_INFO_KEY, ai, g_free);
+      ai = g_slice_new0 (AttachInfo);
+      g_object_set_data_full (object, I_(ATTACH_INFO_KEY), ai,
+                              (GDestroyNotify) attach_info_free);
     }
 
   return ai;
@@ -474,9 +442,6 @@ gtk_menu_class_init (GtkMenuClass *class)
   GtkMenuShellClass *menu_shell_class = GTK_MENU_SHELL_CLASS (class);
   GtkBindingSet *binding_set;
   
-  parent_class = g_type_class_peek_parent (class);
-  
-  gobject_class->finalize = gtk_menu_finalize;
   gobject_class->set_property = gtk_menu_set_property;
   gobject_class->get_property = gtk_menu_get_property;
 
@@ -497,10 +462,10 @@ gtk_menu_class_init (GtkMenuClass *class)
   widget_class->hide_all = gtk_menu_hide_all;
   widget_class->enter_notify_event = gtk_menu_enter_notify;
   widget_class->leave_notify_event = gtk_menu_leave_notify;
-  widget_class->motion_notify_event = gtk_menu_motion_notify;
   widget_class->style_set = gtk_menu_style_set;
   widget_class->focus = gtk_menu_focus;
   widget_class->can_activate_accel = gtk_menu_real_can_activate_accel;
+  widget_class->grab_notify = gtk_menu_grab_notify;
 
   container_class->remove = gtk_menu_remove;
   container_class->get_child_property = gtk_menu_get_child_property;
@@ -514,7 +479,7 @@ gtk_menu_class_init (GtkMenuClass *class)
   menu_shell_class->move_current = gtk_menu_move_current;
 
   menu_signals[MOVE_SCROLL] =
-    _gtk_binding_signal_new ("move_scroll",
+    _gtk_binding_signal_new (I_("move_scroll"),
                             G_OBJECT_CLASS_TYPE (object_class),
                             G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
                             G_CALLBACK (gtk_menu_real_move_scroll),
@@ -522,13 +487,73 @@ gtk_menu_class_init (GtkMenuClass *class)
                             _gtk_marshal_VOID__ENUM,
                             G_TYPE_NONE, 1,
                             GTK_TYPE_SCROLL_TYPE);
-  
+
+  /**
+   * GtkMenu:active:
+   *
+   * The currently selected menu item.
+   *
+   * Since: 2.14
+   **/
+  g_object_class_install_property (gobject_class,
+                                   PROP_ACTIVE,
+                                   g_param_spec_uint ("active",
+                                                     P_("Active"),
+                                                     P_("The currently selected menu item"),
+                                                     0, G_MAXUINT, 0,
+                                                     GTK_PARAM_READWRITE));
+
+  /**
+   * GtkMenu:accel-group:
+   *
+   * The accel group holding accelerators for the menu.
+   *
+   * Since: 2.14
+   **/
+  g_object_class_install_property (gobject_class,
+                                   PROP_ACCEL_GROUP,
+                                   g_param_spec_object ("accel-group",
+                                                       P_("Accel Group"),
+                                                       P_("The accel group holding accelerators for the menu"),
+                                                       GTK_TYPE_ACCEL_GROUP,
+                                                       GTK_PARAM_READWRITE));
+
+  /**
+   * GtkMenu:accel-path:
+   *
+   * An accel path used to conveniently construct accel paths of child items.
+   *
+   * Since: 2.14
+   **/
+  g_object_class_install_property (gobject_class,
+                                   PROP_ACCEL_PATH,
+                                   g_param_spec_string ("accel-path",
+                                                       P_("Accel Path"),
+                                                       P_("An accel path used to conveniently construct accel paths of child items"),
+                                                       NULL,
+                                                       GTK_PARAM_READWRITE));
+
+  /**
+   * GtkMenu:attach-widget:
+   *
+   * The widget the menu is attached to.
+   *
+   * Since: 2.14
+   **/
+  g_object_class_install_property (gobject_class,
+                                   PROP_ACCEL_PATH,
+                                   g_param_spec_string ("attach-widget",
+                                                       P_("Attach Widget"),
+                                                       P_("The widget the menu is attached to"),
+                                                       NULL,
+                                                       GTK_PARAM_READWRITE));
+
   g_object_class_install_property (gobject_class,
                                    PROP_TEAROFF_TITLE,
                                    g_param_spec_string ("tearoff-title",
                                                         P_("Tearoff Title"),
                                                         P_("A title that may be displayed by the window manager when this menu is torn-off"),
-                                                        "",
+                                                        NULL,
                                                         GTK_PARAM_READWRITE));
 
   /**
@@ -546,6 +571,21 @@ gtk_menu_class_init (GtkMenuClass *class)
                                                         FALSE,
                                                         GTK_PARAM_READWRITE));
 
+  /**
+   * GtkMenu:monitor:
+   *
+   * The monitor the menu will be popped up on.
+   *
+   * Since: 2.14
+   **/
+  g_object_class_install_property (gobject_class,
+                                   PROP_MONITOR,
+                                   g_param_spec_int ("monitor",
+                                                    P_("Monitor"),
+                                                    P_("The monitor the menu will be popped up on"),
+                                                    -1, G_MAXINT, -1,
+                                                    GTK_PARAM_READWRITE));
+
   gtk_widget_class_install_style_property (widget_class,
                                           g_param_spec_int ("vertical-padding",
                                                             P_("Vertical Padding"),
@@ -555,6 +595,15 @@ gtk_menu_class_init (GtkMenuClass *class)
                                                             1,
                                                             GTK_PARAM_READABLE));
 
+  gtk_widget_class_install_style_property (widget_class,
+                                           g_param_spec_int ("horizontal-padding",
+                                                             P_("Horizontal Padding"),
+                                                             P_("Extra space at the left and right edges of the menu"),
+                                                             0,
+                                                             G_MAXINT,
+                                                             0,
+                                                             GTK_PARAM_READABLE));
+
   gtk_widget_class_install_style_property (widget_class,
                                           g_param_spec_int ("vertical-offset",
                                                             P_("Vertical Offset"),
@@ -573,6 +622,13 @@ gtk_menu_class_init (GtkMenuClass *class)
                                                             -2,
                                                             GTK_PARAM_READABLE));
 
+  gtk_widget_class_install_style_property (widget_class,
+                                           g_param_spec_boolean ("double-arrows",
+                                                                 P_("Double Arrows"),
+                                                                 P_("When scrolling, always show both arrows."),
+                                                                 TRUE,
+                                                                 GTK_PARAM_READABLE));
+
 
  gtk_container_class_install_child_property (container_class,
                                              CHILD_PROP_LEFT_ATTACH,
@@ -609,7 +665,7 @@ gtk_menu_class_init (GtkMenuClass *class)
   binding_set = gtk_binding_set_by_class (class);
   gtk_binding_entry_add_signal (binding_set,
                                GDK_Up, 0,
-                               "move_current", 1,
+                               I_("move_current"), 1,
                                GTK_TYPE_MENU_DIRECTION_TYPE,
                                GTK_MENU_DIR_PREV);
   gtk_binding_entry_add_signal (binding_set,
@@ -709,7 +765,8 @@ gtk_menu_class_init (GtkMenuClass *class)
                                                   G_MAXINT,
                                                   DEFAULT_POPDOWN_DELAY,
                                                   GTK_PARAM_READWRITE));
-                                                  
+
+  g_type_class_add_private (gobject_class, sizeof (GtkMenuPrivate));
 }
 
 
@@ -725,12 +782,27 @@ gtk_menu_set_property (GObject      *object,
   
   switch (prop_id)
     {
+    case PROP_ACTIVE:
+      gtk_menu_set_active (menu, g_value_get_uint (value));
+      break;
+    case PROP_ACCEL_GROUP:
+      gtk_menu_set_accel_group (menu, g_value_get_object (value));
+      break;
+    case PROP_ACCEL_PATH:
+      gtk_menu_set_accel_path (menu, g_value_get_string (value));
+      break;
+    case PROP_ATTACH_WIDGET:
+      gtk_menu_attach (menu, g_value_get_object (value), 0, 0, 0, 0);
+      break;
     case PROP_TEAROFF_STATE:
       gtk_menu_set_tearoff_state (menu, g_value_get_boolean (value));
       break;
     case PROP_TEAROFF_TITLE:
       gtk_menu_set_title (menu, g_value_get_string (value));
-      break;     
+      break;
+    case PROP_MONITOR:
+      gtk_menu_set_monitor (menu, g_value_get_int (value));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -749,12 +821,27 @@ gtk_menu_get_property (GObject     *object,
   
   switch (prop_id)
     {
+    case PROP_ACTIVE:
+      g_value_set_uint (value, g_list_index (GTK_MENU_SHELL (menu)->children, gtk_menu_get_active (menu)));
+      break;
+    case PROP_ACCEL_GROUP:
+      g_value_set_object (value, gtk_menu_get_accel_group (menu));
+      break;
+    case PROP_ACCEL_PATH:
+      g_value_set_string (value, gtk_menu_get_accel_path (menu));
+      break;
+    case PROP_ATTACH_WIDGET:
+      g_value_set_object (value, gtk_menu_get_attach_widget (menu));
+      break;
     case PROP_TEAROFF_STATE:
       g_value_set_boolean (value, gtk_menu_get_tearoff_state (menu));
       break;
     case PROP_TEAROFF_TITLE:
       g_value_set_string (value, gtk_menu_get_title (menu));
       break;
+    case PROP_MONITOR:
+      g_value_set_int (value, gtk_menu_get_monitor (menu));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -898,7 +985,7 @@ gtk_menu_init (GtkMenu *menu)
   /* Refloat the menu, so that reference counting for the menu isn't
    * affected by it being a child of the toplevel
    */
-  GTK_WIDGET_SET_FLAGS (menu, GTK_FLOATING);
+  g_object_force_floating (G_OBJECT (menu));
   menu->needs_destruction_ref_count = TRUE;
 
   menu->view_window = NULL;
@@ -921,21 +1008,20 @@ gtk_menu_init (GtkMenu *menu)
   menu->upper_arrow_prelight = FALSE;
   menu->lower_arrow_prelight = FALSE;
 
+  priv->upper_arrow_state = GTK_STATE_NORMAL;
+  priv->lower_arrow_state = GTK_STATE_NORMAL;
+
   priv->have_layout = FALSE;
 }
 
 static void
 gtk_menu_destroy (GtkObject *object)
 {
-  GtkMenu *menu;
+  GtkMenu *menu = GTK_MENU (object);
   GtkMenuAttachData *data;
-  GtkMenuPrivate *priv;
-
-  g_return_if_fail (GTK_IS_MENU (object));
-
-  menu = GTK_MENU (object);
+  GtkMenuPrivate *priv; 
 
-  gtk_menu_stop_scrolling (menu);
+  gtk_menu_remove_scroll_timeout (menu);
   
   data = g_object_get_data (G_OBJECT (object), attach_data_key);
   if (data)
@@ -964,22 +1050,25 @@ gtk_menu_destroy (GtkObject *object)
 
   if (menu->toplevel)
     gtk_widget_destroy (menu->toplevel);
+
   if (menu->tearoff_window)
     gtk_widget_destroy (menu->tearoff_window);
 
   priv = gtk_menu_get_private (menu);
 
-  GTK_OBJECT_CLASS (parent_class)->destroy (object);
-}
+  if (priv->heights)
+    {
+      g_free (priv->heights);
+      priv->heights = NULL;
+    }
 
-static void
-gtk_menu_finalize (GObject *object)
-{
-  GtkMenu *menu = GTK_MENU (object);
+  if (priv->title)
+    {
+      g_free (priv->title);
+      priv->title = NULL;
+    }
 
-  g_free (menu->accel_path);
-  
-  G_OBJECT_CLASS (parent_class)->finalize (object);
+  GTK_OBJECT_CLASS (gtk_menu_parent_class)->destroy (object);
 }
 
 static void
@@ -1026,7 +1115,6 @@ gtk_menu_attach_to_widget (GtkMenu               *menu,
   
   g_return_if_fail (GTK_IS_MENU (menu));
   g_return_if_fail (GTK_IS_WIDGET (attach_widget));
-  g_return_if_fail (detacher != NULL);
   
   /* keep this function in sync with gtk_widget_set_parent()
    */
@@ -1039,10 +1127,9 @@ gtk_menu_attach_to_widget (GtkMenu              *menu,
      return;
     }
   
-  g_object_ref (menu);
-  gtk_object_sink (GTK_OBJECT (menu));
+  g_object_ref_sink (menu);
   
-  data = g_new (GtkMenuAttachData, 1);
+  data = g_slice_new (GtkMenuAttachData);
   data->attach_widget = attach_widget;
   
   g_signal_connect (attach_widget, "screen_changed",
@@ -1050,14 +1137,15 @@ gtk_menu_attach_to_widget (GtkMenu             *menu,
   attach_widget_screen_changed (attach_widget, NULL, menu);
   
   data->detacher = detacher;
-  g_object_set_data (G_OBJECT (menu), attach_data_key, data);
+  g_object_set_data (G_OBJECT (menu), I_(attach_data_key), data);
   list = g_object_steal_data (G_OBJECT (attach_widget), ATTACHED_MENUS);
   if (!g_list_find (list, menu))
     {
       list = g_list_prepend (list, menu);
     }
-  g_object_set_data_full (G_OBJECT (attach_widget), ATTACHED_MENUS, list, (GtkDestroyNotify) g_list_free);
-  
+  g_object_set_data_full (G_OBJECT (attach_widget), I_(ATTACHED_MENUS), list,
+                          (GDestroyNotify) g_list_free);
+
   if (GTK_WIDGET_STATE (menu) != GTK_STATE_NORMAL)
     gtk_widget_set_state (GTK_WIDGET (menu), GTK_STATE_NORMAL);
   
@@ -1098,24 +1186,26 @@ gtk_menu_detach (GtkMenu *menu)
       g_warning ("gtk_menu_detach(): menu is not attached");
       return;
     }
-  g_object_set_data (G_OBJECT (menu), attach_data_key, NULL);
+  g_object_set_data (G_OBJECT (menu), I_(attach_data_key), NULL);
   
   g_signal_handlers_disconnect_by_func (data->attach_widget,
                                        (gpointer) attach_widget_screen_changed,
                                        menu);
 
-  data->detacher (data->attach_widget, menu);
+  if (data->detacher)
+    data->detacher (data->attach_widget, menu);
   list = g_object_steal_data (G_OBJECT (data->attach_widget), ATTACHED_MENUS);
   list = g_list_remove (list, menu);
   if (list)
-    g_object_set_data_full (G_OBJECT (data->attach_widget), ATTACHED_MENUS, list, (GtkDestroyNotify) g_list_free);
+    g_object_set_data_full (G_OBJECT (data->attach_widget), I_(ATTACHED_MENUS), list,
+                            (GDestroyNotify) g_list_free);
   else
-    g_object_set_data (G_OBJECT (data->attach_widget), ATTACHED_MENUS, NULL);
+    g_object_set_data (G_OBJECT (data->attach_widget), I_(ATTACHED_MENUS), NULL);
   
   if (GTK_WIDGET_REALIZED (menu))
     gtk_widget_unrealize (GTK_WIDGET (menu));
   
-  g_free (data);
+  g_slice_free (GtkMenuAttachData, data);
   
   /* Fallback title for menu comes from attach widget */
   gtk_menu_update_title (menu);
@@ -1127,15 +1217,10 @@ static void
 gtk_menu_remove (GtkContainer *container,
                 GtkWidget    *widget)
 {
-  GtkMenu *menu;
-  GtkMenuPrivate *priv;
+  GtkMenu *menu = GTK_MENU (container);
 
-  g_return_if_fail (GTK_IS_MENU (container));
   g_return_if_fail (GTK_IS_MENU_ITEM (widget));
 
-  menu = GTK_MENU (container);
-  priv = gtk_menu_get_private (menu);
-
   /* Clear out old_active_menu_item if it matches the item we are removing
    */
   if (menu->old_active_menu_item == widget)
@@ -1144,8 +1229,8 @@ gtk_menu_remove (GtkContainer *container,
       menu->old_active_menu_item = NULL;
     }
 
-  GTK_CONTAINER_CLASS (parent_class)->remove (container, widget);
-  g_object_set_data (G_OBJECT (widget), ATTACH_INFO_KEY, NULL);
+  GTK_CONTAINER_CLASS (gtk_menu_parent_class)->remove (container, widget);
+  g_object_set_data (G_OBJECT (widget), I_(ATTACH_INFO_KEY), NULL);
 
   menu_queue_resize (menu);
 }
@@ -1172,7 +1257,7 @@ gtk_menu_real_insert (GtkMenuShell *menu_shell,
   if (GTK_WIDGET_REALIZED (menu_shell))
     gtk_widget_set_parent_window (child, menu->bin_window);
 
-  GTK_MENU_SHELL_CLASS (parent_class)->insert (menu_shell, child, position);
+  GTK_MENU_SHELL_CLASS (gtk_menu_parent_class)->insert (menu_shell, child, position);
 
   menu_queue_resize (menu);
 }
@@ -1266,10 +1351,12 @@ popup_grab_on_window (GdkWindow *window,
  * a mouse button press, such as a mouse button release or a keypress,
  * @button should be 0.
  *
- * The @activate_time parameter should be the time stamp of the event that
- * initiated the popup. If such an event is not available, use
- * gtk_get_current_event_time() instead.
- *
+ * The @activate_time parameter is used to conflict-resolve initiation of
+ * concurrent requests for mouse/keyboard grab requests. To function
+ * properly, this needs to be the time stamp of the user event (such as
+ * a mouse click or key press) that caused the initiation of the popup.
+ * Only if no such event is available, gtk_get_current_event_time() can
+ * be used instead.
  */
 void
 gtk_menu_popup (GtkMenu                    *menu,
@@ -1287,9 +1374,10 @@ gtk_menu_popup (GtkMenu              *menu,
   GtkMenuShell *menu_shell;
   gboolean grab_keyboard;
   GtkMenuPrivate *priv;
+  GtkWidget *parent_toplevel;
 
   g_return_if_fail (GTK_IS_MENU (menu));
-  
+
   widget = GTK_WIDGET (menu);
   menu_shell = GTK_MENU_SHELL (menu);
   priv = gtk_menu_get_private (menu);
@@ -1393,16 +1481,21 @@ gtk_menu_popup (GtkMenu             *menu,
 
       gtk_menu_reparent (menu, menu->toplevel, FALSE);
     }
+
+  parent_toplevel = NULL;
   if (parent_menu_shell) 
+    parent_toplevel = gtk_widget_get_toplevel (parent_menu_shell);
+  else if (!g_object_get_data (G_OBJECT (menu), "gtk-menu-explicit-screen"))
     {
-      GtkWidget *toplevel;
-
-      toplevel = gtk_widget_get_toplevel (parent_menu_shell);
-      if (GTK_IS_WINDOW (toplevel))
-       gtk_window_group_add_window (_gtk_window_get_group (GTK_WINDOW (toplevel)), 
-                                    GTK_WINDOW (menu->toplevel));
+      GtkWidget *attach_widget = gtk_menu_get_attach_widget (menu);
+      if (attach_widget)
+       parent_toplevel = gtk_widget_get_toplevel (attach_widget);
     }
+
+  /* Set transient for to get the right window group and parent relationship */
+  if (GTK_IS_WINDOW (parent_toplevel))
+    gtk_window_set_transient_for (GTK_WINDOW (menu->toplevel),
+                                 GTK_WINDOW (parent_toplevel));
   
   menu->parent_menu_item = parent_menu_item;
   menu->position_func = func;
@@ -1438,6 +1531,19 @@ gtk_menu_popup (GtkMenu              *menu,
 
   gtk_menu_scroll_to (menu, menu->scroll_offset);
 
+  /* if no item is selected, select the first one */
+  if (!menu_shell->active_menu_item)
+    {
+      gboolean touchscreen_mode;
+
+      g_object_get (gtk_widget_get_settings (GTK_WIDGET (menu)),
+                    "gtk-touchscreen-mode", &touchscreen_mode,
+                    NULL);
+
+      if (touchscreen_mode)
+        gtk_menu_shell_select_first (menu_shell, TRUE);
+    }
+
   /* Once everything is set up correctly, map the toplevel window on
      the screen.
    */
@@ -1458,7 +1564,7 @@ gtk_menu_popdown (GtkMenu *menu)
   
   menu_shell = GTK_MENU_SHELL (menu);
   private = gtk_menu_get_private (menu);
-  
+
   menu_shell->parent_menu_shell = NULL;
   menu_shell->active = FALSE;
   menu_shell->ignore_enter = FALSE;
@@ -1482,7 +1588,7 @@ gtk_menu_popdown (GtkMenu *menu)
   /* The X Grab, if present, will automatically be removed when we hide
    * the window */
   gtk_widget_hide (menu->toplevel);
-  gtk_window_group_add_window (_gtk_window_get_group (NULL), GTK_WINDOW (menu->toplevel));
+  gtk_window_set_transient_for (GTK_WINDOW (menu->toplevel), NULL);
 
   if (menu->torn_off)
     {
@@ -1640,6 +1746,10 @@ gtk_menu_real_can_activate_accel (GtkWidget *widget,
  * Assigning accel paths to menu items then enables the user to change
  * their accelerators at runtime. More details about accelerator paths
  * and their default setups can be found at gtk_accel_map_add_entry().
+ * 
+ * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
+ * pass a static string, you can save some memory by interning it first with 
+ * g_intern_static_string().
  */
 void
 gtk_menu_set_accel_path (GtkMenu     *menu,
@@ -1649,12 +1759,28 @@ gtk_menu_set_accel_path (GtkMenu     *menu,
   if (accel_path)
     g_return_if_fail (accel_path[0] == '<' && strchr (accel_path, '/')); /* simplistic check */
 
-  g_free (menu->accel_path);
-  menu->accel_path = g_strdup (accel_path);
+  /* FIXME: accel_path should be defined as const gchar* */
+  menu->accel_path = (gchar*)g_intern_string (accel_path);
   if (menu->accel_path)
     _gtk_menu_refresh_accel_paths (menu, FALSE);
 }
 
+/**
+ * gtk_menu_get_accel_path
+ * @menu: a valid #GtkMenu
+ *
+ * Retrieves the accelerator path set on the menu.
+ *
+ * Since: 2.14
+ */
+const gchar*
+gtk_menu_get_accel_path (GtkMenu     *menu)
+{
+  g_return_val_if_fail (GTK_IS_MENU (menu), NULL);
+
+  return menu->accel_path;
+}
+
 typedef struct {
   GtkMenu *menu;
   gboolean group_changed;
@@ -1813,13 +1939,12 @@ gtk_menu_set_tearoff_state (GtkMenu  *menu,
            {
              GtkWidget *toplevel;
 
-             menu->tearoff_window = gtk_widget_new (GTK_TYPE_WINDOW,
+             menu->tearoff_window = g_object_new (GTK_TYPE_WINDOW,
                                                     "type", GTK_WINDOW_TOPLEVEL,
                                                     "screen", gtk_widget_get_screen (menu->toplevel),
                                                     "app-paintable", TRUE,
                                                     NULL);
 
-             
              gtk_window_set_type_hint (GTK_WINDOW (menu->tearoff_window),
                                        GDK_WINDOW_TYPE_HINT_MENU);
              gtk_window_set_mnemonic_modifier (GTK_WINDOW (menu->tearoff_window), 0);
@@ -1923,20 +2048,25 @@ gtk_menu_get_tearoff_state (GtkMenu *menu)
  * @title: a string containing the title for the menu.
  * 
  * Sets the title string for the menu.  The title is displayed when the menu
- * is shown as a tearoff menu.
+ * is shown as a tearoff menu.  If @title is %NULL, the menu will see if it is
+ * attached to a parent menu item, and if so it will try to use the same text as
+ * that menu item's label.
  **/
-void       
+void
 gtk_menu_set_title (GtkMenu     *menu,
                    const gchar *title)
 {
+  GtkMenuPrivate *priv;
+  char *old_title;
+
   g_return_if_fail (GTK_IS_MENU (menu));
 
-  if (title)
-    g_object_set_data_full (G_OBJECT (menu), "gtk-menu-title",
-                           g_strdup (title), (GtkDestroyNotify) g_free);
-  else
-    g_object_set_data (G_OBJECT (menu), "gtk-menu-title", NULL);
-    
+  priv = gtk_menu_get_private (menu);
+
+  old_title = priv->title;
+  priv->title = g_strdup (title);
+  g_free (old_title);
+       
   gtk_menu_update_title (menu);
   g_object_notify (G_OBJECT (menu), "tearoff-title");
 }
@@ -1954,9 +2084,13 @@ gtk_menu_set_title (GtkMenu     *menu,
 G_CONST_RETURN gchar *
 gtk_menu_get_title (GtkMenu *menu)
 {
+  GtkMenuPrivate *priv;
+
   g_return_val_if_fail (GTK_IS_MENU (menu), NULL);
 
-  return g_object_get_data (G_OBJECT (menu), "gtk-menu-title");
+  priv = gtk_menu_get_private (menu);
+
+  return priv->title;
 }
 
 void
@@ -1994,6 +2128,21 @@ gtk_menu_style_set (GtkWidget *widget,
     }
 }
 
+static void
+get_arrows_border (GtkMenu *menu, GtkBorder *border)
+{
+  guint scroll_arrow_height;
+
+  gtk_widget_style_get (GTK_WIDGET (menu),
+                        "scroll-arrow-vlength", &scroll_arrow_height,
+                        NULL);
+
+  border->top = menu->upper_arrow_visible ? scroll_arrow_height : 0;
+  border->bottom = menu->lower_arrow_visible ? scroll_arrow_height : 0;
+
+  border->left = border->right = 0;
+}
+
 static void
 gtk_menu_realize (GtkWidget *widget)
 {
@@ -2004,7 +2153,9 @@ gtk_menu_realize (GtkWidget *widget)
   GtkWidget *child;
   GList *children;
   guint vertical_padding;
-  
+  guint horizontal_padding;
+  GtkBorder arrow_border;
+
   g_return_if_fail (GTK_IS_MENU (widget));
 
   menu = GTK_MENU (widget);
@@ -2033,26 +2184,25 @@ gtk_menu_realize (GtkWidget *widget)
 
   gtk_widget_style_get (GTK_WIDGET (menu),
                        "vertical-padding", &vertical_padding,
+                        "horizontal-padding", &horizontal_padding,
                        NULL);
-  
-  attributes.x = border_width + widget->style->xthickness;
+
+  attributes.x = border_width + widget->style->xthickness + horizontal_padding;
   attributes.y = border_width + widget->style->ythickness + vertical_padding;
   attributes.width = MAX (1, widget->allocation.width - attributes.x * 2);
   attributes.height = MAX (1, widget->allocation.height - attributes.y * 2);
 
-  if (menu->upper_arrow_visible)
-    {
-      attributes.y += MENU_SCROLL_ARROW_HEIGHT;
-      attributes.height -= MENU_SCROLL_ARROW_HEIGHT;
-    }
-  if (menu->lower_arrow_visible)
-    attributes.height -= MENU_SCROLL_ARROW_HEIGHT;
+  get_arrows_border (menu, &arrow_border);
+  attributes.y += arrow_border.top;
+  attributes.height -= arrow_border.top;
+  attributes.height -= arrow_border.bottom;
 
   menu->view_window = gdk_window_new (widget->window, &attributes, attributes_mask);
   gdk_window_set_user_data (menu->view_window, menu);
 
   attributes.x = 0;
   attributes.y = 0;
+  attributes.width = MAX (1, widget->allocation.width - (border_width + widget->style->xthickness + horizontal_padding) * 2);
   attributes.height = MAX (1, widget->requisition.height - (border_width + widget->style->ythickness + vertical_padding) * 2);
   
   menu->bin_window = gdk_window_new (menu->view_window, &attributes, attributes_mask);
@@ -2118,7 +2268,7 @@ menu_grab_transfer_window_get (GtkMenu *menu)
 
       gdk_window_show (window);
 
-      g_object_set_data (G_OBJECT (menu), "gtk-menu-transfer-window", window);
+      g_object_set_data (G_OBJECT (menu), I_("gtk-menu-transfer-window"), window);
     }
 
   return window;
@@ -2132,18 +2282,14 @@ menu_grab_transfer_window_destroy (GtkMenu *menu)
     {
       gdk_window_set_user_data (window, NULL);
       gdk_window_destroy (window);
-      g_object_set_data (G_OBJECT (menu), "gtk-menu-transfer-window", NULL);
+      g_object_set_data (G_OBJECT (menu), I_("gtk-menu-transfer-window"), NULL);
     }
 }
 
 static void
 gtk_menu_unrealize (GtkWidget *widget)
 {
-  GtkMenu *menu;
-
-  g_return_if_fail (GTK_IS_MENU (widget));
-
-  menu = GTK_MENU (widget);
+  GtkMenu *menu = GTK_MENU (widget);
 
   menu_grab_transfer_window_destroy (menu);
 
@@ -2155,7 +2301,7 @@ gtk_menu_unrealize (GtkWidget *widget)
   gdk_window_destroy (menu->bin_window);
   menu->bin_window = NULL;
 
-  (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
+  (* GTK_WIDGET_CLASS (gtk_menu_parent_class)->unrealize) (widget);
 }
 
 static void
@@ -2170,6 +2316,7 @@ gtk_menu_size_request (GtkWidget      *widget,
   guint max_toggle_size;
   guint max_accel_width;
   guint vertical_padding;
+  guint horizontal_padding;
   GtkRequisition child_requisition;
   GtkMenuPrivate *priv;
   
@@ -2195,7 +2342,7 @@ gtk_menu_size_request (GtkWidget      *widget,
     {
       gint part;
       gint toggle_size;
-      guint l, r, t, b;
+      gint l, r, t, b;
 
       child = children->data;
       children = children->next;
@@ -2231,12 +2378,14 @@ gtk_menu_size_request (GtkWidget      *widget,
 
   requisition->width += max_toggle_size + max_accel_width;
   requisition->width *= gtk_menu_get_n_columns (menu);
-  requisition->width += (GTK_CONTAINER (menu)->border_width +
-                        widget->style->xthickness) * 2;
 
   gtk_widget_style_get (GTK_WIDGET (menu),
                        "vertical-padding", &vertical_padding,
+                        "horizontal-padding", &horizontal_padding,
                        NULL);
+
+  requisition->width += (GTK_CONTAINER (menu)->border_width + horizontal_padding +
+                        widget->style->xthickness) * 2;
   requisition->height += (GTK_CONTAINER (menu)->border_width + vertical_padding +
                          widget->style->ythickness) * 2;
   
@@ -2262,7 +2411,8 @@ gtk_menu_size_allocate (GtkWidget     *widget,
   gint x, y;
   gint width, height;
   guint vertical_padding;
-
+  guint horizontal_padding;
+  
   g_return_if_fail (GTK_IS_MENU (widget));
   g_return_if_fail (allocation != NULL);
   
@@ -2275,9 +2425,10 @@ gtk_menu_size_allocate (GtkWidget     *widget,
 
   gtk_widget_style_get (GTK_WIDGET (menu),
                        "vertical-padding", &vertical_padding,
+                        "horizontal-padding", &horizontal_padding,
                        NULL);
-  
-  x = GTK_CONTAINER (menu)->border_width + widget->style->xthickness;
+
+  x = GTK_CONTAINER (menu)->border_width + widget->style->xthickness + horizontal_padding;
   y = GTK_CONTAINER (menu)->border_width + widget->style->ythickness + vertical_padding;
 
   width = MAX (1, allocation->width - x * 2);
@@ -2288,16 +2439,17 @@ gtk_menu_size_allocate (GtkWidget     *widget,
 
   if (menu_shell->active)
     gtk_menu_scroll_to (menu, menu->scroll_offset);
-  
-  if (menu->upper_arrow_visible && !menu->tearoff_active)
+
+  if (!menu->tearoff_active)
     {
-      y += MENU_SCROLL_ARROW_HEIGHT;
-      height -= MENU_SCROLL_ARROW_HEIGHT;
+      GtkBorder arrow_border;
+
+      get_arrows_border (menu, &arrow_border);
+      y += arrow_border.top;
+      height -= arrow_border.top;
+      height -= arrow_border.bottom;
     }
-  
-  if (menu->lower_arrow_visible && !menu->tearoff_active)
-    height -= MENU_SCROLL_ARROW_HEIGHT;
-  
+
   if (GTK_WIDGET_REALIZED (widget))
     {
       gdk_window_move_resize (widget->window,
@@ -2324,7 +2476,7 @@ gtk_menu_size_allocate (GtkWidget     *widget,
          if (GTK_WIDGET_VISIBLE (child))
            {
               gint i;
-             guint l, r, t, b;
+             gint l, r, t, b;
 
              get_effective_child_attach (child, &l, &r, &t, &b);
 
@@ -2410,91 +2562,138 @@ gtk_menu_size_allocate (GtkWidget     *widget,
     }
 }
 
+static void
+get_arrows_visible_area (GtkMenu *menu,
+                         GdkRectangle *border,
+                         GdkRectangle *upper,
+                         GdkRectangle *lower,
+                         gint *arrow_space)
+{
+  GtkWidget *widget = GTK_WIDGET (menu);
+  guint vertical_padding;
+  guint horizontal_padding;
+  gint scroll_arrow_height;
+  
+  gtk_widget_style_get (widget,
+                        "vertical-padding", &vertical_padding,
+                        "horizontal-padding", &horizontal_padding,
+                        "scroll-arrow-vlength", &scroll_arrow_height,
+                        NULL);
+
+  border->x = GTK_CONTAINER (widget)->border_width + widget->style->xthickness + horizontal_padding;
+  border->y = GTK_CONTAINER (widget)->border_width + widget->style->ythickness + vertical_padding;
+  gdk_drawable_get_size (widget->window, &border->width, &border->height);
+
+  upper->x = border->x;
+  upper->y = border->y;
+  upper->width = border->width - 2 * border->x;
+  upper->height = scroll_arrow_height;
+
+  lower->x = border->x;
+  lower->y = border->height - border->y - scroll_arrow_height;
+  lower->width = border->width - 2 * border->x;
+  lower->height = scroll_arrow_height;
+
+  *arrow_space = scroll_arrow_height - 2 * widget->style->ythickness;
+}
+
 static void
 gtk_menu_paint (GtkWidget      *widget,
                GdkEventExpose *event)
 {
   GtkMenu *menu;
-  gint width, height;
-  gint border_x, border_y;
-  guint vertical_padding;
+  GtkMenuPrivate *priv;
+  GdkRectangle border;
+  GdkRectangle upper;
+  GdkRectangle lower;
+  gint arrow_space;
   
   g_return_if_fail (GTK_IS_MENU (widget));
 
   menu = GTK_MENU (widget);
+  priv = gtk_menu_get_private (menu);
 
-  gtk_widget_style_get (GTK_WIDGET (menu),
-                       "vertical-padding", &vertical_padding,
-                       NULL);
-  
-  border_x = GTK_CONTAINER (widget)->border_width + widget->style->xthickness;
-  border_y = GTK_CONTAINER (widget)->border_width + widget->style->ythickness + vertical_padding;
-  gdk_drawable_get_size (widget->window, &width, &height);
+  get_arrows_visible_area (menu, &border, &upper, &lower, &arrow_space);
 
   if (event->window == widget->window)
     {
-      gint arrow_space = MENU_SCROLL_ARROW_HEIGHT - 2 * widget->style->ythickness;
       gint arrow_size = 0.7 * arrow_space;
-       
+
       gtk_paint_box (widget->style,
                     widget->window,
                     GTK_STATE_NORMAL,
                     GTK_SHADOW_OUT,
-                    NULL, widget, "menu",
+                    &event->area, widget, "menu",
                     0, 0, -1, -1);
+
       if (menu->upper_arrow_visible && !menu->tearoff_active)
        {
          gtk_paint_box (widget->style,
                         widget->window,
-                        menu->upper_arrow_prelight ?
-                        GTK_STATE_PRELIGHT : GTK_STATE_NORMAL,
-                        GTK_SHADOW_OUT,
-                        NULL, widget, "menu",
-                        border_x,
-                        border_y,
-                        width - 2 * border_x,
-                        MENU_SCROLL_ARROW_HEIGHT);
-         
+                        priv->upper_arrow_state,
+                         GTK_SHADOW_OUT,
+                        &event->area, widget, "menu_scroll_arrow_up",
+                         upper.x,
+                         upper.y,
+                         upper.width,
+                         upper.height);
+
          gtk_paint_arrow (widget->style,
                           widget->window,
-                          menu->upper_arrow_prelight ?
-                          GTK_STATE_PRELIGHT : GTK_STATE_NORMAL,
+                          priv->upper_arrow_state,
                           GTK_SHADOW_OUT,
-                          NULL, widget, "menu_scroll_arrow_up",
+                          &event->area, widget, "menu_scroll_arrow_up",
                           GTK_ARROW_UP,
                           TRUE,
-                          (width - arrow_size ) / 2,
-                          border_y + widget->style->ythickness + (arrow_space - arrow_size)/2,
+                           upper.x + (upper.width - arrow_size) / 2,
+                           upper.y + widget->style->ythickness + (arrow_space - arrow_size) / 2,
                           arrow_size, arrow_size);
        }
-  
+
       if (menu->lower_arrow_visible && !menu->tearoff_active)
        {
          gtk_paint_box (widget->style,
                         widget->window,
-                        menu->lower_arrow_prelight ?
-                        GTK_STATE_PRELIGHT : GTK_STATE_NORMAL,
-                        GTK_SHADOW_OUT,
-                        NULL, widget, "menu",
-                        border_x,
-                        height - border_y - MENU_SCROLL_ARROW_HEIGHT,
-                        width - 2*border_x,
-                        MENU_SCROLL_ARROW_HEIGHT);
-         
+                        priv->lower_arrow_state,
+                         GTK_SHADOW_OUT,
+                        &event->area, widget, "menu_scroll_arrow_down",
+                         lower.x,
+                         lower.y,
+                         lower.width,
+                         lower.height);
+
          gtk_paint_arrow (widget->style,
                           widget->window,
-                          menu->lower_arrow_prelight ?
-                          GTK_STATE_PRELIGHT : GTK_STATE_NORMAL,
+                          priv->lower_arrow_state,
                           GTK_SHADOW_OUT,
-                          NULL, widget, "menu_scroll_arrow_down",
+                          &event->area, widget, "menu_scroll_arrow_down",
                           GTK_ARROW_DOWN,
                           TRUE,
-                          (width - arrow_size) / 2,
-                          height - border_y - MENU_SCROLL_ARROW_HEIGHT +
-                             widget->style->ythickness + (arrow_space - arrow_size)/2,
+                           lower.x + (lower.width - arrow_size) / 2,
+                          lower.y + widget->style->ythickness + (arrow_space - arrow_size) / 2,
                           arrow_size, arrow_size);
        }
     }
+  else if (event->window == menu->bin_window)
+    {
+      gint y = -border.y + menu->scroll_offset;
+
+      if (!menu->tearoff_active)
+        {
+          GtkBorder arrow_border;
+
+          get_arrows_border (menu, &arrow_border);
+          y -= arrow_border.top;
+        }
+
+      gtk_paint_box (widget->style,
+                    menu->bin_window,
+                    GTK_STATE_NORMAL,
+                    GTK_SHADOW_OUT,
+                    &event->area, widget, "menu",
+                    - border.x, y,
+                    border.width, border.height);
+    }
 }
 
 static gboolean
@@ -2508,7 +2707,7 @@ gtk_menu_expose (GtkWidget        *widget,
     {
       gtk_menu_paint (widget, event);
       
-      (* GTK_WIDGET_CLASS (parent_class)->expose_event) (widget, event);
+      (* GTK_WIDGET_CLASS (gtk_menu_parent_class)->expose_event) (widget, event);
     }
   
   return FALSE;
@@ -2521,57 +2720,141 @@ gtk_menu_show (GtkWidget *widget)
 
   _gtk_menu_refresh_accel_paths (menu, FALSE);
 
-  GTK_WIDGET_CLASS (parent_class)->show (widget);
+  GTK_WIDGET_CLASS (gtk_menu_parent_class)->show (widget);
 }
 
 static gboolean
-gtk_menu_button_press (GtkWidget      *widget,
-                        GdkEventButton *event)
+gtk_menu_button_scroll (GtkMenu        *menu,
+                        GdkEventButton *event)
 {
-  /* Don't pop down the menu for releases over scroll arrows
-   */
-  if (GTK_IS_MENU (widget))
+  if (menu->upper_arrow_prelight || menu->lower_arrow_prelight)
     {
-      GtkMenu *menu = GTK_MENU (widget);
+      gboolean touchscreen_mode;
 
-      if (menu->upper_arrow_prelight ||  menu->lower_arrow_prelight)
-       return TRUE;
+      g_object_get (gtk_widget_get_settings (GTK_WIDGET (menu)),
+                    "gtk-touchscreen-mode", &touchscreen_mode,
+                    NULL);
+
+      if (touchscreen_mode)
+        gtk_menu_handle_scrolling (menu,
+                                   event->x_root, event->y_root,
+                                   event->type == GDK_BUTTON_PRESS,
+                                   FALSE);
+
+      return TRUE;
     }
 
-  return GTK_WIDGET_CLASS (parent_class)->button_press_event (widget, event);
+  return FALSE;
 }
 
 static gboolean
-gtk_menu_button_release (GtkWidget      *widget,
-                        GdkEventButton *event)
+pointer_in_menu_window (GtkWidget *widget,
+                        gdouble    x_root,
+                        gdouble    y_root)
 {
-  /* Don't pop down the menu for releases over scroll arrows
-   */
-  if (GTK_IS_MENU (widget))
+  GtkMenu *menu = GTK_MENU (widget);
+
+  if (GTK_WIDGET_MAPPED (menu->toplevel))
     {
-      GtkMenu *menu = GTK_MENU (widget);
+      GtkMenuShell *menu_shell;
+      gint          window_x, window_y;
 
-      if (menu->upper_arrow_prelight ||  menu->lower_arrow_prelight)
-       return TRUE;
+      gdk_window_get_position (menu->toplevel->window, &window_x, &window_y);
+
+      if (x_root >= window_x && x_root < window_x + widget->allocation.width &&
+          y_root >= window_y && y_root < window_y + widget->allocation.height)
+        return TRUE;
+
+      menu_shell = GTK_MENU_SHELL (widget);
+
+      if (GTK_IS_MENU (menu_shell->parent_menu_shell))
+        return pointer_in_menu_window (menu_shell->parent_menu_shell,
+                                       x_root, y_root);
     }
 
-  return GTK_WIDGET_CLASS (parent_class)->button_release_event (widget, event);
+  return FALSE;
 }
 
-static const gchar *
-get_accel_path (GtkWidget *menu_item,
-               gboolean  *locked)
+static gboolean
+gtk_menu_button_press (GtkWidget      *widget,
+                       GdkEventButton *event)
 {
-  const gchar *path;
-  GtkWidget *label;
-  GClosure *accel_closure;
-  GtkAccelGroup *accel_group;    
+  if (event->type != GDK_BUTTON_PRESS)
+    return FALSE;
 
-  path = _gtk_widget_get_accel_path (menu_item, locked);
-  if (!path)
-    {
-      path = GTK_MENU_ITEM (menu_item)->accel_path;
-      
+  /* Don't pass down to menu shell for presses over scroll arrows
+   */
+  if (gtk_menu_button_scroll (GTK_MENU (widget), event))
+    return TRUE;
+
+  /*  Don't pass down to menu shell if a non-menuitem part of the menu
+   *  was clicked. The check for the event_widget being a GtkMenuShell
+   *  works because we have the pointer grabbed on menu_shell->window
+   *  with owner_events=TRUE, so all events that are either outside
+   *  the menu or on its border are delivered relative to
+   *  menu_shell->window.
+   */
+  if (GTK_IS_MENU_SHELL (gtk_get_event_widget ((GdkEvent *) event)) &&
+      pointer_in_menu_window (widget, event->x_root, event->y_root))
+    return TRUE;
+
+  return GTK_WIDGET_CLASS (gtk_menu_parent_class)->button_press_event (widget, event);
+}
+
+static gboolean
+gtk_menu_button_release (GtkWidget      *widget,
+                        GdkEventButton *event)
+{
+  GtkMenuPrivate *priv = gtk_menu_get_private (GTK_MENU (widget));
+
+  if (priv->ignore_button_release)
+    {
+      priv->ignore_button_release = FALSE;
+      return FALSE;
+    }
+
+  if (event->type != GDK_BUTTON_RELEASE)
+    return FALSE;
+
+  /* Don't pass down to menu shell for releases over scroll arrows
+   */
+  if (gtk_menu_button_scroll (GTK_MENU (widget), event))
+    return TRUE;
+
+  /*  Don't pass down to menu shell if a non-menuitem part of the menu
+   *  was clicked (see comment in button_press()).
+   */
+  if (GTK_IS_MENU_SHELL (gtk_get_event_widget ((GdkEvent *) event)) &&
+      pointer_in_menu_window (widget, event->x_root, event->y_root))
+    {
+      /*  Ugly: make sure menu_shell->button gets reset to 0 when we
+       *  bail out early here so it is in a consistent state for the
+       *  next button_press/button_release in GtkMenuShell.
+       *  See bug #449371.
+       */
+      if (GTK_MENU_SHELL (widget)->active)
+        GTK_MENU_SHELL (widget)->button = 0;
+
+      return TRUE;
+    }
+
+  return GTK_WIDGET_CLASS (gtk_menu_parent_class)->button_release_event (widget, event);
+}
+
+static const gchar *
+get_accel_path (GtkWidget *menu_item,
+               gboolean  *locked)
+{
+  const gchar *path;
+  GtkWidget *label;
+  GClosure *accel_closure;
+  GtkAccelGroup *accel_group;    
+
+  path = _gtk_widget_get_accel_path (menu_item, locked);
+  if (!path)
+    {
+      path = GTK_MENU_ITEM (menu_item)->accel_path;
+      
       if (locked)
        {
          *locked = TRUE;
@@ -2617,7 +2900,7 @@ gtk_menu_key_press (GtkWidget     *widget,
   
   gtk_menu_stop_navigating_submenu (menu);
 
-  if (GTK_WIDGET_CLASS (parent_class)->key_press_event (widget, event))
+  if (GTK_WIDGET_CLASS (gtk_menu_parent_class)->key_press_event (widget, event))
     return TRUE;
 
   display = gtk_widget_get_display (widget);
@@ -2627,11 +2910,10 @@ gtk_menu_key_press (GtkWidget   *widget,
                "gtk-can-change-accels", &can_change_accels,
                 NULL);
 
-  if (accel)
+  if (accel && *accel)
     {
       guint keyval = 0;
       GdkModifierType mods = 0;
-      gboolean handled = FALSE;
       
       gtk_accelerator_parse (accel, &keyval, &mods);
 
@@ -2642,15 +2924,15 @@ gtk_menu_key_press (GtkWidget   *widget,
        * thing, to properly consider i18n etc., but that probably requires
        * AccelGroup changes etc.
        */
-      if (event->keyval == keyval &&
-          (mods & event->state) == mods)
-       gtk_menu_shell_cancel (menu_shell);
-
-      g_free (accel);
-
-      if (handled)
-        return TRUE;
+      if (event->keyval == keyval && (mods & event->state) == mods)
+        {
+         gtk_menu_shell_cancel (menu_shell);
+          g_free (accel);
+          return TRUE;
+        }
     }
+
+  g_free (accel);
   
   switch (event->keyval)
     {
@@ -2695,7 +2977,7 @@ gtk_menu_key_press (GtkWidget     *widget,
           * (basically, those items are accelerator-locked).
           */
          /* g_print("item has no path or is locked, menu prefix: %s\n", menu->accel_path); */
-         gdk_display_beep (display);
+         gtk_widget_error_bell (widget);
        }
       else
        {
@@ -2724,7 +3006,7 @@ gtk_menu_key_press (GtkWidget     *widget,
               * locked already
               */
              /* g_print("failed to change\n"); */
-             gdk_display_beep (display);
+             gtk_widget_error_bell (widget);
            }
        }
     }
@@ -2768,12 +3050,19 @@ gtk_menu_motion_notify  (GtkWidget         *widget,
   GtkWidget *menu_item;
   GtkMenu *menu;
   GtkMenuShell *menu_shell;
-  GtkMenuPrivate *priv;
 
   gboolean need_enter;
 
   if (GTK_IS_MENU (widget))
-    gtk_menu_handle_scrolling (GTK_MENU (widget), event->x_root, event->y_root, TRUE);
+    {
+      GtkMenuPrivate *priv = gtk_menu_get_private (GTK_MENU (widget));
+
+      if (priv->ignore_button_release)
+        priv->ignore_button_release = FALSE;
+
+      gtk_menu_handle_scrolling (GTK_MENU (widget), event->x_root, event->y_root,
+                                 TRUE, TRUE);
+    }
 
   /* We received the event for one of two reasons:
    *
@@ -2785,18 +3074,16 @@ gtk_menu_motion_notify  (GtkWidget         *widget,
    * which may be different from 'widget'.
    */
   menu_item = gtk_get_event_widget ((GdkEvent*) event);
-  if (!menu_item || !GTK_IS_MENU_ITEM (menu_item) ||
+  if (!GTK_IS_MENU_ITEM (menu_item) ||
       !GTK_IS_MENU (menu_item->parent))
     return FALSE;
 
   menu_shell = GTK_MENU_SHELL (menu_item->parent);
   menu = GTK_MENU (menu_shell);
 
-  priv = gtk_menu_get_private (GTK_MENU (widget));
-
   if (definitely_within_item (menu_item, event->x, event->y))
     menu_shell->activate_time = 0;
-  
+
   need_enter = (menu->navigation_region != NULL || menu_shell->ignore_enter);
 
   /* Check to see if we are within an active submenu's navigation region
@@ -2836,6 +3123,7 @@ gtk_menu_motion_notify  (GtkWidget           *widget,
          send_event->crossing.y_root = event->y_root;
          send_event->crossing.x = event->x;
          send_event->crossing.y = event->y;
+          send_event->crossing.state = event->state;
 
          /* We send the event to 'widget', the currently active menu,
           * instead of 'menu', the menu that the pointer is in. This
@@ -2853,6 +3141,20 @@ gtk_menu_motion_notify  (GtkWidget          *widget,
   return FALSE;
 }
 
+static gboolean
+get_double_arrows (GtkMenu *menu)
+{
+  GtkMenuPrivate *priv = gtk_menu_get_private (menu);
+  gboolean        double_arrows;
+
+  gtk_widget_style_get (GTK_WIDGET (menu),
+                        "double-arrows", &double_arrows,
+                        NULL);
+
+  return double_arrows || (priv->initially_pushed_in &&
+                           menu->scroll_offset != 0);
+}
+
 static void
 gtk_menu_scroll_by (GtkMenu *menu, 
                    gint     step)
@@ -2860,17 +3162,24 @@ gtk_menu_scroll_by (GtkMenu *menu,
   GtkWidget *widget;
   gint offset;
   gint view_width, view_height;
-
+  gboolean double_arrows;
+  GtkBorder arrow_border;
+  
   widget = GTK_WIDGET (menu);
   offset = menu->scroll_offset + step;
 
+  get_arrows_border (menu, &arrow_border);
+
+  double_arrows = get_double_arrows (menu);
+
   /* If we scroll upward and the non-visible top part
    * is smaller than the scroll arrow it would be
    * pretty stupid to show the arrow and taking more
    * screen space than just scrolling to the top.
    */
-  if ((step < 0) && (offset < MENU_SCROLL_ARROW_HEIGHT))
-    offset = 0;
+  if (!double_arrows)
+    if ((step < 0) && (offset < arrow_border.top))
+      offset = 0;
 
   /* Don't scroll over the top if we weren't before: */
   if ((menu->scroll_offset >= 0) && (offset < 0))
@@ -2878,10 +3187,20 @@ gtk_menu_scroll_by (GtkMenu *menu,
 
   gdk_drawable_get_size (widget->window, &view_width, &view_height);
 
+  if (menu->scroll_offset == 0 &&
+      view_height >= widget->requisition.height)
+    return;
+
   /* Don't scroll past the bottom if we weren't before: */
   if (menu->scroll_offset > 0)
-    view_height -= MENU_SCROLL_ARROW_HEIGHT;
-  
+    view_height -= arrow_border.top;
+
+  /* When both arrows are always shown, reduce
+   * view height even more.
+   */
+  if (double_arrows)
+    view_height -= arrow_border.bottom;
+
   if ((menu->scroll_offset + view_height <= widget->requisition.height) &&
       (offset + view_height > widget->requisition.height))
     offset = widget->requisition.height - view_height;
@@ -2890,21 +3209,91 @@ gtk_menu_scroll_by (GtkMenu *menu,
     gtk_menu_scroll_to (menu, offset);
 }
 
-static gboolean
-gtk_menu_scroll_timeout (gpointer  data)
+static void
+gtk_menu_do_timeout_scroll (GtkMenu  *menu,
+                            gboolean  touchscreen_mode)
 {
-  GtkMenu *menu;
+  gboolean upper_visible;
+  gboolean lower_visible;
 
-  GDK_THREADS_ENTER ();
+  upper_visible = menu->upper_arrow_visible;
+  lower_visible = menu->lower_arrow_visible;
 
-  menu = GTK_MENU (data);
   gtk_menu_scroll_by (menu, menu->scroll_step);
 
-  GDK_THREADS_LEAVE ();
+  if (touchscreen_mode &&
+      (upper_visible != menu->upper_arrow_visible ||
+       lower_visible != menu->lower_arrow_visible))
+    {
+      /* We are about to hide a scroll arrow while the mouse is pressed,
+       * this would cause the uncovered menu item to be activated on button
+       * release. Therefore we need to ignore button release here
+       */
+      GTK_MENU_SHELL (menu)->ignore_enter = TRUE;
+      gtk_menu_get_private (menu)->ignore_button_release = TRUE;
+    }
+}
+
+static gboolean
+gtk_menu_scroll_timeout (gpointer data)
+{
+  GtkMenu  *menu;
+  gboolean  touchscreen_mode;
+
+  menu = GTK_MENU (data);
+
+  g_object_get (gtk_widget_get_settings (GTK_WIDGET (menu)),
+                "gtk-touchscreen-mode", &touchscreen_mode,
+                NULL);
+
+  gtk_menu_do_timeout_scroll (menu, touchscreen_mode);
 
   return TRUE;
 }
 
+static gboolean
+gtk_menu_scroll_timeout_initial (gpointer data)
+{
+  GtkMenu  *menu;
+  guint     timeout;
+  gboolean  touchscreen_mode;
+
+  menu = GTK_MENU (data);
+
+  g_object_get (gtk_widget_get_settings (GTK_WIDGET (menu)),
+                "gtk-timeout-repeat", &timeout,
+                "gtk-touchscreen-mode", &touchscreen_mode,
+                NULL);
+
+  gtk_menu_do_timeout_scroll (menu, touchscreen_mode);
+
+  gtk_menu_remove_scroll_timeout (menu);
+
+  menu->timeout_id = gdk_threads_add_timeout (timeout,
+                                              gtk_menu_scroll_timeout,
+                                              menu);
+
+  return FALSE;
+}
+
+static void
+gtk_menu_start_scrolling (GtkMenu *menu)
+{
+  guint    timeout;
+  gboolean touchscreen_mode;
+
+  g_object_get (gtk_widget_get_settings (GTK_WIDGET (menu)),
+                "gtk-timeout-repeat", &timeout,
+                "gtk-touchscreen-mode", &touchscreen_mode,
+                NULL);
+
+  gtk_menu_do_timeout_scroll (menu, touchscreen_mode);
+
+  menu->timeout_id = gdk_threads_add_timeout (timeout,
+                                              gtk_menu_scroll_timeout_initial,
+                                              menu);
+}
+
 static gboolean
 gtk_menu_scroll (GtkWidget     *widget,
                 GdkEventScroll *event)
@@ -2927,114 +3316,287 @@ gtk_menu_scroll (GtkWidget    *widget,
 }
 
 static void
-gtk_menu_handle_scrolling (GtkMenu *menu,
-                          gint x,
-                          gint y,
-                          gboolean enter)
+get_arrows_sensitive_area (GtkMenu *menu,
+                           GdkRectangle *upper,
+                           GdkRectangle *lower)
 {
-  GtkMenuShell *menu_shell;
   gint width, height;
   gint border;
-  GdkRectangle rect;
-  gboolean in_arrow;
-  gboolean scroll_fast = FALSE;
   guint vertical_padding;
-  gint top_x, top_y;
   gint win_x, win_y;
-
-  menu_shell = GTK_MENU_SHELL (menu);
+  gint scroll_arrow_height;
 
   gdk_drawable_get_size (GTK_WIDGET (menu)->window, &width, &height);
 
   gtk_widget_style_get (GTK_WIDGET (menu),
-                       "vertical-padding", &vertical_padding,
-                       NULL);
-  
+                        "vertical-padding", &vertical_padding,
+                        "scroll-arrow-vlength", &scroll_arrow_height,
+                        NULL);
+
   border = GTK_CONTAINER (menu)->border_width +
     GTK_WIDGET (menu)->style->ythickness + vertical_padding;
 
+  gdk_window_get_position (GTK_WIDGET (menu)->window, &win_x, &win_y);
+
+  if (upper)
+    {
+      upper->x = win_x;
+      upper->y = win_y;
+      upper->width = width;
+      upper->height = scroll_arrow_height + border;
+    }
+
+  if (lower)
+    {
+      lower->x = win_x;
+      lower->y = win_y + height - border - scroll_arrow_height;
+      lower->width = width;
+      lower->height = scroll_arrow_height + border;
+    }
+}
+
+
+static void
+gtk_menu_handle_scrolling (GtkMenu *menu,
+                          gint     x,
+                          gint     y,
+                          gboolean enter,
+                           gboolean motion)
+{
+  GtkMenuShell *menu_shell;
+  GtkMenuPrivate *priv;
+  GdkRectangle rect;
+  gboolean in_arrow;
+  gboolean scroll_fast = FALSE;
+  gint top_x, top_y;
+  gboolean touchscreen_mode;
+
+  priv = gtk_menu_get_private (menu);
+
+  menu_shell = GTK_MENU_SHELL (menu);
+
+  g_object_get (gtk_widget_get_settings (GTK_WIDGET (menu)),
+                "gtk-touchscreen-mode", &touchscreen_mode,
+                NULL);
+
   gdk_window_get_position (menu->toplevel->window, &top_x, &top_y);
   x -= top_x;
   y -= top_y;
 
-  gdk_window_get_position (GTK_WIDGET (menu)->window, &win_x, &win_y);
-  
-  if (menu->upper_arrow_visible && !menu->tearoff_active)
+  /*  upper arrow handling  */
+
+  get_arrows_sensitive_area (menu, &rect, NULL);
+
+  in_arrow = FALSE;
+  if (menu->upper_arrow_visible && !menu->tearoff_active &&
+      (x >= rect.x) && (x < rect.x + rect.width) &&
+      (y >= rect.y) && (y < rect.y + rect.height))
     {
-      rect.x = win_x;
-      rect.y = win_y;
-      rect.width = width;
-      rect.height = MENU_SCROLL_ARROW_HEIGHT + border;
-      
-      in_arrow = FALSE;
-      if ((x >= rect.x) && (x < rect.x + rect.width) &&
-         (y >= rect.y) && (y < rect.y + rect.height))
-       {
-         in_arrow = TRUE;
-         scroll_fast = (y < rect.y + MENU_SCROLL_FAST_ZONE);
-       }
-       
-      if (enter && in_arrow &&
-         (!menu->upper_arrow_prelight || menu->scroll_fast != scroll_fast))
-       {
-         menu->upper_arrow_prelight = TRUE;
-         menu->scroll_fast = scroll_fast;
-         gdk_window_invalidate_rect (GTK_WIDGET (menu)->window, &rect, FALSE);
-         
-         /* Deselect the active item so that any submenus are poped down */
-         gtk_menu_shell_deselect (menu_shell);
+      in_arrow = TRUE;
+    }
 
-         gtk_menu_remove_scroll_timeout (menu);
-         menu->scroll_step = (scroll_fast) ? -MENU_SCROLL_STEP2 : -MENU_SCROLL_STEP1;
-         menu->timeout_id = g_timeout_add ((scroll_fast) ? MENU_SCROLL_TIMEOUT2 : MENU_SCROLL_TIMEOUT1,
-                                           gtk_menu_scroll_timeout,
-                                           menu);
-       }
-      else if (!enter && !in_arrow && menu->upper_arrow_prelight)
-       {
-         gdk_window_invalidate_rect (GTK_WIDGET (menu)->window, &rect, FALSE);
-         
-         gtk_menu_stop_scrolling (menu);
-       }
+  if (touchscreen_mode)
+    menu->upper_arrow_prelight = in_arrow;
+
+  if (priv->upper_arrow_state != GTK_STATE_INSENSITIVE)
+    {
+      gboolean arrow_pressed = FALSE;
+
+      if (menu->upper_arrow_visible && !menu->tearoff_active)
+        {
+          if (touchscreen_mode)
+            {
+              if (enter && menu->upper_arrow_prelight)
+                {
+                  if (menu->timeout_id == 0)
+                    {
+                      /* Deselect the active item so that
+                       * any submenus are popped down
+                       */
+                      gtk_menu_shell_deselect (menu_shell);
+
+                      gtk_menu_remove_scroll_timeout (menu);
+                      menu->scroll_step = -MENU_SCROLL_STEP2; /* always fast */
+
+                      if (!motion)
+                        {
+                          /* Only do stuff on click. */
+                          gtk_menu_start_scrolling (menu);
+                          arrow_pressed = TRUE;
+                        }
+                    }
+                  else
+                    {
+                      arrow_pressed = TRUE;
+                    }
+                }
+              else if (!enter)
+                {
+                  gtk_menu_stop_scrolling (menu);
+                }
+            }
+          else /* !touchscreen_mode */
+            {
+              scroll_fast = (y < rect.y + MENU_SCROLL_FAST_ZONE);
+
+              if (enter && in_arrow &&
+                  (!menu->upper_arrow_prelight ||
+                   menu->scroll_fast != scroll_fast))
+                {
+                  menu->upper_arrow_prelight = TRUE;
+                  menu->scroll_fast = scroll_fast;
+
+                  /* Deselect the active item so that
+                   * any submenus are popped down
+                   */
+                  gtk_menu_shell_deselect (menu_shell);
+
+                  gtk_menu_remove_scroll_timeout (menu);
+                  menu->scroll_step = scroll_fast ?
+                    -MENU_SCROLL_STEP2 : -MENU_SCROLL_STEP1;
+
+                  menu->timeout_id =
+                    gdk_threads_add_timeout (scroll_fast ?
+                                             MENU_SCROLL_TIMEOUT2 :
+                                             MENU_SCROLL_TIMEOUT1,
+                                             gtk_menu_scroll_timeout, menu);
+                }
+              else if (!enter && !in_arrow && menu->upper_arrow_prelight)
+                {
+                  gtk_menu_stop_scrolling (menu);
+                }
+            }
+        }
+
+      /*  gtk_menu_start_scrolling() might have hit the top of the
+       *  menu, so check if the button isn't insensitive before
+       *  changing it to something else.
+       */
+      if (priv->upper_arrow_state != GTK_STATE_INSENSITIVE)
+        {
+          GtkStateType arrow_state = GTK_STATE_NORMAL;
+
+          if (arrow_pressed)
+            arrow_state = GTK_STATE_ACTIVE;
+          else if (menu->upper_arrow_prelight)
+            arrow_state = GTK_STATE_PRELIGHT;
+
+          if (arrow_state != priv->upper_arrow_state)
+            {
+              priv->upper_arrow_state = arrow_state;
+
+              gdk_window_invalidate_rect (GTK_WIDGET (menu)->window,
+                                          &rect, FALSE);
+            }
+        }
     }
-  
-  if (menu->lower_arrow_visible && !menu->tearoff_active)
+
+  /*  lower arrow handling  */
+
+  get_arrows_sensitive_area (menu, NULL, &rect);
+
+  in_arrow = FALSE;
+  if (menu->lower_arrow_visible && !menu->tearoff_active &&
+      (x >= rect.x) && (x < rect.x + rect.width) &&
+      (y >= rect.y) && (y < rect.y + rect.height))
     {
-      rect.x = win_x;
-      rect.y = win_y + height - border - MENU_SCROLL_ARROW_HEIGHT;
-      rect.width = width;
-      rect.height = MENU_SCROLL_ARROW_HEIGHT + border;
-
-      in_arrow = FALSE;
-      if ((x >= rect.x) && (x < rect.x + rect.width) &&
-         (y >= rect.y) && (y < rect.y + rect.height))
-       {
-         in_arrow = TRUE;
-         scroll_fast = (y > rect.y + rect.height - MENU_SCROLL_FAST_ZONE);
-       }
+      in_arrow = TRUE;
+    }
 
-      if (enter && in_arrow &&
-         (!menu->lower_arrow_prelight || menu->scroll_fast != scroll_fast))
-       {
-         menu->lower_arrow_prelight = TRUE;
-         menu->scroll_fast = scroll_fast;
-         gdk_window_invalidate_rect (GTK_WIDGET (menu)->window, &rect, FALSE);
+  if (touchscreen_mode)
+    menu->lower_arrow_prelight = in_arrow;
 
-         /* Deselect the active item so that any submenus are poped down */
-         gtk_menu_shell_deselect (menu_shell);
+  if (priv->lower_arrow_state != GTK_STATE_INSENSITIVE)
+    {
+      gboolean arrow_pressed = FALSE;
 
-         gtk_menu_remove_scroll_timeout (menu);
-         menu->scroll_step = (scroll_fast) ? MENU_SCROLL_STEP2 : MENU_SCROLL_STEP1;
-         menu->timeout_id = g_timeout_add ((scroll_fast) ? MENU_SCROLL_TIMEOUT2 : MENU_SCROLL_TIMEOUT1,
-                                           gtk_menu_scroll_timeout,
-                                           menu);
-       }
-      else if (!enter && !in_arrow && menu->lower_arrow_prelight)
-       {
-         gdk_window_invalidate_rect (GTK_WIDGET (menu)->window, &rect, FALSE);
-         
-         gtk_menu_stop_scrolling (menu);
-       }
+      if (menu->lower_arrow_visible && !menu->tearoff_active)
+        {
+          if (touchscreen_mode)
+            {
+              if (enter && menu->lower_arrow_prelight)
+                {
+                  if (menu->timeout_id == 0)
+                    {
+                      /* Deselect the active item so that
+                       * any submenus are popped down
+                       */
+                      gtk_menu_shell_deselect (menu_shell);
+
+                      gtk_menu_remove_scroll_timeout (menu);
+                      menu->scroll_step = MENU_SCROLL_STEP2; /* always fast */
+
+                      if (!motion)
+                        {
+                          /* Only do stuff on click. */
+                          gtk_menu_start_scrolling (menu);
+                          arrow_pressed = TRUE;
+                        }
+                    }
+                  else
+                    {
+                      arrow_pressed = TRUE;
+                    }
+                }
+              else if (!enter)
+                {
+                  gtk_menu_stop_scrolling (menu);
+                }
+            }
+          else /* !touchscreen_mode */
+            {
+              scroll_fast = (y > rect.y + rect.height - MENU_SCROLL_FAST_ZONE);
+
+              if (enter && in_arrow &&
+                  (!menu->lower_arrow_prelight ||
+                   menu->scroll_fast != scroll_fast))
+                {
+                  menu->lower_arrow_prelight = TRUE;
+                  menu->scroll_fast = scroll_fast;
+
+                  /* Deselect the active item so that
+                   * any submenus are popped down
+                   */
+                  gtk_menu_shell_deselect (menu_shell);
+
+                  gtk_menu_remove_scroll_timeout (menu);
+                  menu->scroll_step = scroll_fast ?
+                    MENU_SCROLL_STEP2 : MENU_SCROLL_STEP1;
+
+                  menu->timeout_id =
+                    gdk_threads_add_timeout (scroll_fast ?
+                                             MENU_SCROLL_TIMEOUT2 :
+                                             MENU_SCROLL_TIMEOUT1,
+                                             gtk_menu_scroll_timeout, menu);
+                }
+              else if (!enter && !in_arrow && menu->lower_arrow_prelight)
+                {
+                  gtk_menu_stop_scrolling (menu);
+                }
+            }
+        }
+
+      /*  gtk_menu_start_scrolling() might have hit the bottom of the
+       *  menu, so check if the button isn't insensitive before
+       *  changing it to something else.
+       */
+      if (priv->lower_arrow_state != GTK_STATE_INSENSITIVE)
+        {
+          GtkStateType arrow_state = GTK_STATE_NORMAL;
+
+          if (arrow_pressed)
+            arrow_state = GTK_STATE_ACTIVE;
+          else if (menu->lower_arrow_prelight)
+            arrow_state = GTK_STATE_PRELIGHT;
+
+          if (arrow_state != priv->lower_arrow_state)
+            {
+              priv->lower_arrow_state = arrow_state;
+
+              gdk_window_invalidate_rect (GTK_WIDGET (menu)->window,
+                                          &rect, FALSE);
+            }
+        }
     }
 }
 
@@ -3043,21 +3605,27 @@ gtk_menu_enter_notify (GtkWidget        *widget,
                       GdkEventCrossing *event)
 {
   GtkWidget *menu_item;
+  gboolean   touchscreen_mode;
+
+  g_object_get (gtk_widget_get_settings (widget),
+                "gtk-touchscreen-mode", &touchscreen_mode,
+                NULL);
 
   menu_item = gtk_get_event_widget ((GdkEvent*) event);
-  if (widget && GTK_IS_MENU (widget))
+  if (GTK_IS_MENU (widget))
     {
       GtkMenuShell *menu_shell = GTK_MENU_SHELL (widget);
 
       if (!menu_shell->ignore_enter)
-       gtk_menu_handle_scrolling (GTK_MENU (widget), event->x_root, event->y_root, TRUE);
+       gtk_menu_handle_scrolling (GTK_MENU (widget),
+                                   event->x_root, event->y_root, TRUE, TRUE);
     }
 
-  if (menu_item && GTK_IS_MENU_ITEM (menu_item))
+  if (!touchscreen_mode && GTK_IS_MENU_ITEM (menu_item))
     {
       GtkWidget *menu = menu_item->parent;
       
-      if (menu && GTK_IS_MENU (menu))
+      if (GTK_IS_MENU (menu))
        {
          GtkMenuPrivate *priv = gtk_menu_get_private (GTK_MENU (menu));
          GtkMenuShell *menu_shell = GTK_MENU_SHELL (menu);
@@ -3093,11 +3661,12 @@ gtk_menu_enter_notify (GtkWidget        *widget,
    * will not correspond to the event widget's parent.  Check to see
    * if we are in the parent's navigation region.
    */
-  if (menu_item && GTK_IS_MENU_ITEM (menu_item) && GTK_IS_MENU (menu_item->parent) &&
-      gtk_menu_navigating_submenu (GTK_MENU (menu_item->parent), event->x_root, event->y_root))
+  if (GTK_IS_MENU_ITEM (menu_item) && GTK_IS_MENU (menu_item->parent) &&
+      gtk_menu_navigating_submenu (GTK_MENU (menu_item->parent),
+                                   event->x_root, event->y_root))
     return TRUE;
 
-  return GTK_WIDGET_CLASS (parent_class)->enter_notify_event (widget, event); 
+  return GTK_WIDGET_CLASS (gtk_menu_parent_class)->enter_notify_event (widget, event); 
 }
 
 static gboolean
@@ -3115,11 +3684,11 @@ gtk_menu_leave_notify (GtkWidget        *widget,
   if (gtk_menu_navigating_submenu (menu, event->x_root, event->y_root))
     return TRUE; 
 
-  gtk_menu_handle_scrolling (menu, event->x_root, event->y_root, FALSE);
-  
+  gtk_menu_handle_scrolling (menu, event->x_root, event->y_root, FALSE, TRUE);
+
   event_widget = gtk_get_event_widget ((GdkEvent*) event);
   
-  if (!event_widget || !GTK_IS_MENU_ITEM (event_widget))
+  if (!GTK_IS_MENU_ITEM (event_widget))
     return TRUE;
   
   menu_item = GTK_MENU_ITEM (event_widget); 
@@ -3147,7 +3716,7 @@ gtk_menu_leave_notify (GtkWidget        *widget,
        }
     }
   
-  return GTK_WIDGET_CLASS (parent_class)->leave_notify_event (widget, event); 
+  return GTK_WIDGET_CLASS (gtk_menu_parent_class)->leave_notify_event (widget, event); 
 }
 
 static void 
@@ -3157,8 +3726,7 @@ gtk_menu_stop_navigating_submenu (GtkMenu *menu)
     {
       gdk_region_destroy (menu->navigation_region);
       menu->navigation_region = NULL;
-    }
-  
+    }  
   if (menu->navigation_timeout)
     {
       g_source_remove (menu->navigation_timeout);
@@ -3175,8 +3743,6 @@ gtk_menu_stop_navigating_submenu_cb (gpointer user_data)
   GtkMenu *menu = user_data;
   GdkWindow *child_window;
 
-  GDK_THREADS_ENTER ();
-
   gtk_menu_stop_navigating_submenu (menu);
   
   if (GTK_WIDGET_REALIZED (menu))
@@ -3191,14 +3757,12 @@ gtk_menu_stop_navigating_submenu_cb (gpointer user_data)
          send_event->crossing.time = GDK_CURRENT_TIME; /* Bogus */
          send_event->crossing.send_event = TRUE;
 
-         GTK_WIDGET_CLASS (parent_class)->enter_notify_event (GTK_WIDGET (menu), (GdkEventCrossing *)send_event);
+         GTK_WIDGET_CLASS (gtk_menu_parent_class)->enter_notify_event (GTK_WIDGET (menu), (GdkEventCrossing *)send_event);
 
          gdk_event_free (send_event);
        }
     }
 
-  GDK_THREADS_LEAVE ();
-
   return FALSE; 
 }
 
@@ -3372,8 +3936,9 @@ gtk_menu_set_submenu_navigation_region (GtkMenu          *menu,
                    "gtk-menu-popdown-delay", &popdown_delay,
                    NULL);
 
-      menu->navigation_timeout = g_timeout_add (popdown_delay,
-                                               gtk_menu_stop_navigating_submenu_cb, menu);
+      menu->navigation_timeout = gdk_threads_add_timeout (popdown_delay,
+                                                          gtk_menu_stop_navigating_submenu_cb,
+                                                          menu);
 
 #ifdef DRAW_STAY_UP_TRIANGLE
       draw_stay_up_triangle (gdk_get_default_root_window(),
@@ -3407,11 +3972,10 @@ gtk_menu_position (GtkMenu *menu)
   gint x, y;
   gint scroll_offset;
   gint menu_height;
-  gboolean push_in;
   GdkScreen *screen;
   GdkScreen *pointer_screen;
   GdkRectangle monitor;
-
+  
   g_return_if_fail (GTK_IS_MENU (menu));
 
   widget = GTK_WIDGET (menu);
@@ -3419,7 +3983,7 @@ gtk_menu_position (GtkMenu *menu)
   screen = gtk_widget_get_screen (widget);
   gdk_display_get_pointer (gdk_screen_get_display (screen),
                           &pointer_screen, &x, &y, NULL);
-
+  
   /* We need the requisition to figure out the right place to
    * popup the menu. In fact, we always need to ask here, since
    * if a size_request was queued while we weren't popped up,
@@ -3441,11 +4005,16 @@ gtk_menu_position (GtkMenu *menu)
   private = gtk_menu_get_private (menu);
   private->monitor_num = gdk_screen_get_monitor_at_point (screen, x, y);
 
-  push_in = FALSE;
+  private->initially_pushed_in = FALSE;
+
+  /* Set the type hint here to allow custom position functions to set a different hint */
+  if (!GTK_WIDGET_VISIBLE (menu->toplevel))
+    gtk_window_set_type_hint (GTK_WINDOW (menu->toplevel), GDK_WINDOW_TYPE_HINT_POPUP_MENU);
   
   if (menu->position_func)
     {
-      (* menu->position_func) (menu, &x, &y, &push_in, menu->position_func_data);
+      (* menu->position_func) (menu, &x, &y, &private->initially_pushed_in,
+                               menu->position_func_data);
       if (private->monitor_num < 0) 
        private->monitor_num = gdk_screen_get_monitor_at_point (screen, x, y);
 
@@ -3571,7 +4140,7 @@ gtk_menu_position (GtkMenu *menu)
 
   scroll_offset = 0;
 
-  if (push_in)
+  if (private->initially_pushed_in)
     {
       menu_height = GTK_WIDGET (menu)->requisition.height;
 
@@ -3609,7 +4178,12 @@ gtk_menu_position (GtkMenu *menu)
     }
 
   if (scroll_offset > 0)
-    scroll_offset += MENU_SCROLL_ARROW_HEIGHT;
+    {
+      GtkBorder arrow_border;
+
+      get_arrows_border (menu, &arrow_border);
+      scroll_offset += arrow_border.top;
+    }
   
   gtk_window_move (GTK_WINDOW (GTK_MENU_SHELL (menu)->active ? menu->toplevel : menu->tearoff_window), 
                   x, y);
@@ -3636,10 +4210,19 @@ gtk_menu_remove_scroll_timeout (GtkMenu *menu)
 static void
 gtk_menu_stop_scrolling (GtkMenu *menu)
 {
+  gboolean touchscreen_mode;
+
   gtk_menu_remove_scroll_timeout (menu);
 
-  menu->upper_arrow_prelight = FALSE;
-  menu->lower_arrow_prelight = FALSE;
+  g_object_get (gtk_widget_get_settings (GTK_WIDGET (menu)),
+               "gtk-touchscreen-mode", &touchscreen_mode,
+               NULL);
+
+  if (!touchscreen_mode)
+    {
+      menu->upper_arrow_prelight = FALSE;
+      menu->lower_arrow_prelight = FALSE;
+    }
 }
 
 static void
@@ -3650,10 +4233,12 @@ gtk_menu_scroll_to (GtkMenu *menu,
   gint x, y;
   gint view_width, view_height;
   gint border_width;
-  gboolean last_visible;
   gint menu_height;
   guint vertical_padding;
-
+  guint horizontal_padding;
+  gboolean double_arrows;
+  GtkBorder arrow_border;
+  
   widget = GTK_WIDGET (menu);
 
   if (menu->tearoff_active &&
@@ -3671,31 +4256,106 @@ gtk_menu_scroll_to (GtkMenu *menu,
   view_height = widget->allocation.height;
 
   gtk_widget_style_get (GTK_WIDGET (menu),
-                       "vertical-padding", &vertical_padding,
-                       NULL);
-  
+                        "vertical-padding", &vertical_padding,
+                        "horizontal-padding", &horizontal_padding,
+                        NULL);
+
+  double_arrows = get_double_arrows (menu);
+
   border_width = GTK_CONTAINER (menu)->border_width;
-  view_width -= (border_width + widget->style->xthickness) * 2;
+  view_width -= (border_width + widget->style->xthickness + horizontal_padding) * 2;
   view_height -= (border_width + widget->style->ythickness + vertical_padding) * 2;
   menu_height = widget->requisition.height -
-      (border_width + widget->style->ythickness + vertical_padding) * 2;
+    (border_width + widget->style->ythickness + vertical_padding) * 2;
 
-  x = border_width + widget->style->xthickness;
+  x = border_width + widget->style->xthickness + horizontal_padding;
   y = border_width + widget->style->ythickness + vertical_padding;
 
-  if (!menu->tearoff_active)
+  if (double_arrows && !menu->tearoff_active)
+    {
+      if (view_height < menu_height               ||
+          (offset > 0 && menu->scroll_offset > 0) ||
+          (offset < 0 && menu->scroll_offset < 0))
+        {
+          GtkMenuPrivate *priv = gtk_menu_get_private (menu);
+          GtkStateType    upper_arrow_previous_state = priv->upper_arrow_state;
+          GtkStateType    lower_arrow_previous_state = priv->lower_arrow_state;
+
+          if (!menu->upper_arrow_visible || !menu->lower_arrow_visible)
+            gtk_widget_queue_draw (GTK_WIDGET (menu));
+
+          menu->upper_arrow_visible = menu->lower_arrow_visible = TRUE;
+
+         get_arrows_border (menu, &arrow_border);
+         y += arrow_border.top;
+         view_height -= arrow_border.top;
+         view_height -= arrow_border.bottom;
+
+          if (offset <= 0)
+            priv->upper_arrow_state = GTK_STATE_INSENSITIVE;
+          else if (priv->upper_arrow_state == GTK_STATE_INSENSITIVE)
+            priv->upper_arrow_state = menu->upper_arrow_prelight ?
+              GTK_STATE_PRELIGHT : GTK_STATE_NORMAL;
+
+          if (offset >= menu_height - view_height)
+            priv->lower_arrow_state = GTK_STATE_INSENSITIVE;
+          else if (priv->lower_arrow_state == GTK_STATE_INSENSITIVE)
+            priv->lower_arrow_state = menu->lower_arrow_prelight ?
+              GTK_STATE_PRELIGHT : GTK_STATE_NORMAL;
+
+          if ((priv->upper_arrow_state != upper_arrow_previous_state) ||
+              (priv->lower_arrow_state != lower_arrow_previous_state))
+            gtk_widget_queue_draw (GTK_WIDGET (menu));
+
+          if (upper_arrow_previous_state != GTK_STATE_INSENSITIVE &&
+              priv->upper_arrow_state == GTK_STATE_INSENSITIVE)
+            {
+              /* At the upper border, possibly remove timeout */
+              if (menu->scroll_step < 0)
+                {
+                  gtk_menu_stop_scrolling (menu);
+                  gtk_widget_queue_draw (GTK_WIDGET (menu));
+                }
+            }
+
+          if (lower_arrow_previous_state != GTK_STATE_INSENSITIVE &&
+              priv->lower_arrow_state == GTK_STATE_INSENSITIVE)
+            {
+              /* At the lower border, possibly remove timeout */
+              if (menu->scroll_step > 0)
+                {
+                  gtk_menu_stop_scrolling (menu);
+                  gtk_widget_queue_draw (GTK_WIDGET (menu));
+                }
+            }
+        }
+      else if (menu->upper_arrow_visible || menu->lower_arrow_visible)
+        {
+          offset = 0;
+
+          menu->upper_arrow_visible = menu->lower_arrow_visible = FALSE;
+          menu->upper_arrow_prelight = menu->lower_arrow_prelight = FALSE;
+
+          gtk_menu_stop_scrolling (menu);
+          gtk_widget_queue_draw (GTK_WIDGET (menu));
+        }
+    }
+  else if (!menu->tearoff_active)
     {
+      gboolean last_visible;
+
       last_visible = menu->upper_arrow_visible;
       menu->upper_arrow_visible = offset > 0;
       
-      if (menu->upper_arrow_visible)
-       view_height -= MENU_SCROLL_ARROW_HEIGHT;
+      /* upper_arrow_visible may have changed, so requery the border */
+      get_arrows_border (menu, &arrow_border);
+      view_height -= arrow_border.top;
       
-      if ( (last_visible != menu->upper_arrow_visible) &&
-          !menu->upper_arrow_visible)
+      if ((last_visible != menu->upper_arrow_visible) &&
+          !menu->upper_arrow_visible)
        {
-         menu->upper_arrow_prelight = FALSE;
-         
+          menu->upper_arrow_prelight = FALSE;
+
          /* If we hid the upper arrow, possibly remove timeout */
          if (menu->scroll_step < 0)
            {
@@ -3707,14 +4367,15 @@ gtk_menu_scroll_to (GtkMenu *menu,
       last_visible = menu->lower_arrow_visible;
       menu->lower_arrow_visible = offset < menu_height - view_height;
       
-      if (menu->lower_arrow_visible)
-       view_height -= MENU_SCROLL_ARROW_HEIGHT;
+      /* lower_arrow_visible may have changed, so requery the border */
+      get_arrows_border (menu, &arrow_border);
+      view_height -= arrow_border.bottom;
       
-      if ( (last_visible != menu->lower_arrow_visible) &&
+      if ((last_visible != menu->lower_arrow_visible) &&
           !menu->lower_arrow_visible)
        {
-         menu->lower_arrow_prelight = FALSE;
-         
+          menu->lower_arrow_prelight = FALSE;
+
          /* If we hid the lower arrow, possibly remove timeout */
          if (menu->scroll_step > 0)
            {
@@ -3723,8 +4384,7 @@ gtk_menu_scroll_to (GtkMenu *menu,
            }
        }
       
-      if (menu->upper_arrow_visible)
-       y += MENU_SCROLL_ARROW_HEIGHT;
+      y += arrow_border.top;
     }
 
   /* Scroll the menu: */
@@ -3749,8 +4409,8 @@ compute_child_offset (GtkMenu   *menu,
                      gboolean  *is_last_child)
 {
   GtkMenuPrivate *priv = gtk_menu_get_private (menu);
-  guint item_top_attach;
-  guint item_bottom_attach;
+  gint item_top_attach;
+  gint item_bottom_attach;
   gint child_offset = 0;
   gint i;
 
@@ -3801,14 +4461,17 @@ gtk_menu_scroll_item_visible (GtkMenuShell    *menu_shell,
                            &child_offset, &child_height, &last_child))
     {
       guint vertical_padding;
+      gboolean double_arrows;
       
       y = menu->scroll_offset;
       gdk_drawable_get_size (GTK_WIDGET (menu)->window, &width, &height);
 
       gtk_widget_style_get (GTK_WIDGET (menu),
                            "vertical-padding", &vertical_padding,
-                           NULL);
-                           
+                            NULL);
+
+      double_arrows = get_double_arrows (menu);
+
       height -= 2*GTK_CONTAINER (menu)->border_width + 2*GTK_WIDGET (menu)->style->ythickness + 2*vertical_padding;
       
       if (child_offset < y)
@@ -3820,23 +4483,25 @@ gtk_menu_scroll_item_visible (GtkMenuShell    *menu_shell,
        }
       else
        {
-         arrow_height = 0;
-         if (menu->upper_arrow_visible && !menu->tearoff_active)
-           arrow_height += MENU_SCROLL_ARROW_HEIGHT;
-         if (menu->lower_arrow_visible && !menu->tearoff_active)
-           arrow_height += MENU_SCROLL_ARROW_HEIGHT;
+          GtkBorder arrow_border;
+
+          arrow_height = 0;
+
+          get_arrows_border (menu, &arrow_border);
+          if (!menu->tearoff_active)
+            arrow_height = arrow_border.top + arrow_border.bottom;
          
          if (child_offset + child_height > y + height - arrow_height)
            {
              arrow_height = 0;
-             if (!last_child && !menu->tearoff_active)
-               arrow_height += MENU_SCROLL_ARROW_HEIGHT;
-             
+             if ((!last_child && !menu->tearoff_active) || double_arrows)
+               arrow_height += arrow_border.bottom;
+
              y = child_offset + child_height - height + arrow_height;
-             if ((y > 0) && !menu->tearoff_active)
+             if (((y > 0) && !menu->tearoff_active) || double_arrows)
                {
                  /* Need upper arrow */
-                 arrow_height += MENU_SCROLL_ARROW_HEIGHT;
+                 arrow_height += arrow_border.top;
                  y = child_offset + child_height - height + arrow_height;
                }
              /* Ignore the enter event we might get if the pointer is on the menu
@@ -3858,7 +4523,7 @@ gtk_menu_select_item (GtkMenuShell  *menu_shell,
   if (GTK_WIDGET_REALIZED (GTK_WIDGET (menu)))
     gtk_menu_scroll_item_visible (menu_shell, menu_item);
 
-  GTK_MENU_SHELL_CLASS (parent_class)->select_item (menu_shell, menu_item);
+  GTK_MENU_SHELL_CLASS (gtk_menu_parent_class)->select_item (menu_shell, menu_item);
 }
 
 
@@ -3899,10 +4564,9 @@ gtk_menu_reparent (GtkMenu      *menu,
 {
   GtkObject *object = GTK_OBJECT (menu);
   GtkWidget *widget = GTK_WIDGET (menu);
-  gboolean was_floating = GTK_OBJECT_FLOATING (object);
+  gboolean was_floating = g_object_is_floating (object);
 
-  g_object_ref (object);
-  gtk_object_sink (object);
+  g_object_ref_sink (object);
 
   if (unrealize)
     {
@@ -3915,7 +4579,7 @@ gtk_menu_reparent (GtkMenu      *menu,
     gtk_widget_reparent (GTK_WIDGET (menu), new_parent);
   
   if (was_floating)
-    GTK_OBJECT_SET_FLAGS (object, GTK_FLOATING);
+    g_object_force_floating (G_OBJECT (object));
   else
     g_object_unref (object);
 }
@@ -3952,7 +4616,7 @@ gtk_menu_set_screen (GtkMenu   *menu,
   g_return_if_fail (GTK_IS_MENU (menu));
   g_return_if_fail (!screen || GDK_IS_SCREEN (screen));
 
-  g_object_set_data (G_OBJECT (menu), "gtk-menu-explicit-screen", screen);
+  g_object_set_data (G_OBJECT (menu), I_("gtk-menu-explicit-screen"), screen);
 
   if (screen)
     {
@@ -4057,7 +4721,7 @@ find_child_containing (GtkMenuShell *menu_shell,
 
   for (list = menu_shell->children; list; list = list->next)
     {
-      guint l, r, t, b;
+      gint l, r, t, b;
 
       if (!_gtk_menu_item_is_selectable (list->data))
         continue;
@@ -4078,7 +4742,7 @@ gtk_menu_move_current (GtkMenuShell *menu_shell,
 {
   GtkMenu *menu = GTK_MENU (menu_shell);
   gint i;
-  guint l, r, t, b;
+  gint l, r, t, b;
   GtkWidget *match = NULL;
 
   if (gtk_widget_get_direction (GTK_WIDGET (menu_shell)) == GTK_TEXT_DIR_RTL)
@@ -4181,7 +4845,7 @@ gtk_menu_move_current (GtkMenuShell *menu_shell,
         }
     }
 
-  GTK_MENU_SHELL_CLASS (parent_class)->move_current (menu_shell, direction);
+  GTK_MENU_SHELL_CLASS (gtk_menu_parent_class)->move_current (menu_shell, direction);
 }
 
 static gint
@@ -4193,12 +4857,16 @@ get_visible_size (GtkMenu *menu)
   gint menu_height = (widget->allocation.height
                      - 2 * (container->border_width
                             + widget->style->ythickness));
-  
-  if (menu->upper_arrow_visible && !menu->tearoff_active)
-    menu_height -= MENU_SCROLL_ARROW_HEIGHT;
-  if (menu->lower_arrow_visible && !menu->tearoff_active)
-    menu_height -= MENU_SCROLL_ARROW_HEIGHT;
 
+  if (!menu->tearoff_active)
+    {
+      GtkBorder arrow_border;
+
+      get_arrows_border (menu, &arrow_border);
+      menu_height -= arrow_border.top;
+      menu_height -= arrow_border.bottom;
+    }
+  
   return menu_height;
 }
 
@@ -4255,11 +4923,14 @@ get_menu_height (GtkMenu *menu)
   height = widget->requisition.height;
   height -= (GTK_CONTAINER (widget)->border_width + widget->style->ythickness) * 2;
 
-  if (menu->upper_arrow_visible && !menu->tearoff_active)
-    height -= MENU_SCROLL_ARROW_HEIGHT;
+  if (!menu->tearoff_active)
+    {
+      GtkBorder arrow_border;
 
-  if (menu->lower_arrow_visible && !menu->tearoff_active)
-    height -= MENU_SCROLL_ARROW_HEIGHT;
+      get_arrows_border (menu, &arrow_border);
+      height -= arrow_border.top;
+      height -= arrow_border.bottom;
+    }
 
   return height;
 }
@@ -4310,11 +4981,14 @@ gtk_menu_real_move_scroll (GtkMenu       *menu,
          {
            GtkWidget *new_child;
            gboolean new_upper_arrow_visible = menu->upper_arrow_visible && !menu->tearoff_active;
+            GtkBorder arrow_border;
+
+           get_arrows_border (menu, &arrow_border);
 
            if (menu->scroll_offset != old_offset)
              step = menu->scroll_offset - old_offset;
 
-           step -= (new_upper_arrow_visible - old_upper_arrow_visible) * MENU_SCROLL_ARROW_HEIGHT;
+           step -= (new_upper_arrow_visible - old_upper_arrow_visible) * arrow_border.top;
 
            new_child = child_at (menu, child_offset + step);
            if (new_child)
@@ -4371,6 +5045,28 @@ gtk_menu_set_monitor (GtkMenu *menu,
   priv->monitor_num = monitor_num;
 }
 
+/**
+ * gtk_menu_get_monitor:
+ * @menu: a #GtkMenu
+ *
+ * Retrieves the number of the monitor on which to show the menu.
+ *
+ * Returns: the number of the monitor on which the menu should
+ *    be popped up or -1
+ *
+ * Since: 2.14
+ **/
+gint
+gtk_menu_get_monitor (GtkMenu *menu)
+{
+  GtkMenuPrivate *priv;
+  g_return_val_if_fail (GTK_IS_MENU (menu), -1);
+
+  priv = gtk_menu_get_private (menu);
+  
+  return priv->monitor_num;
+}
+
 /**
  * gtk_menu_get_for_attach_widget:
  * @widget: a #GtkWidget
@@ -4393,5 +5089,24 @@ gtk_menu_get_for_attach_widget (GtkWidget *widget)
   return list;
 }
 
+static void
+gtk_menu_grab_notify (GtkWidget *widget,
+                     gboolean   was_grabbed)
+{
+  GtkWidget *toplevel;
+  GtkWindowGroup *group;
+  GtkWidget *grab;
+
+  toplevel = gtk_widget_get_toplevel (widget);
+  group = gtk_window_get_group (GTK_WINDOW (toplevel));
+  grab = _gtk_window_group_get_current_grab (group); 
+
+  if (!was_grabbed)
+    {
+      if (GTK_MENU_SHELL (widget)->active && !GTK_IS_MENU_SHELL (grab))
+        gtk_menu_shell_cancel (GTK_MENU_SHELL (widget));
+    }
+}
+
 #define __GTK_MENU_C__
 #include "gtkaliasdef.c"