]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkmenu.c
Replace a lot of idle and timeout calls by the new gdk_threads api.
[~andy/gtk] / gtk / gtkmenu.c
index cb406b2680e7d89da6de172185ed60276272ca33..70f9f9b4edcaea86e383dd3b4519b4e07fd3b96a 100644 (file)
@@ -25,7 +25,6 @@
  */
 
 #define GTK_MENU_INTERNALS
-
 #include <config.h>
 #include <string.h> /* memset */
 #include "gdk/gdkkeysyms.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
@@ -135,8 +133,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,
@@ -248,7 +244,6 @@ 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 };
@@ -259,32 +254,7 @@ gtk_menu_get_private (GtkMenu *menu)
   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, I_("GtkMenu"),
-                                         &menu_info, 0);
-    }
-  
-  return menu_type;
-}
+G_DEFINE_TYPE (GtkMenu, gtk_menu, GTK_TYPE_MENU_SHELL)
 
 static void
 menu_queue_resize (GtkMenu *menu)
@@ -461,8 +431,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;
@@ -942,7 +910,7 @@ gtk_menu_destroy (GtkObject *object)
 
   menu = GTK_MENU (object);
 
-  gtk_menu_stop_scrolling (menu);
+  gtk_menu_remove_scroll_timeout (menu);
   
   data = g_object_get_data (G_OBJECT (object), attach_data_key);
   if (data)
@@ -989,7 +957,7 @@ gtk_menu_destroy (GtkObject *object)
       priv->title = NULL;
     }
 
-  GTK_OBJECT_CLASS (parent_class)->destroy (object);
+  GTK_OBJECT_CLASS (gtk_menu_parent_class)->destroy (object);
 }
 
 static void
@@ -999,7 +967,7 @@ gtk_menu_finalize (GObject *object)
 
   g_free (menu->accel_path);
   
-  G_OBJECT_CLASS (parent_class)->finalize (object);
+  G_OBJECT_CLASS (gtk_menu_parent_class)->finalize (object);
 }
 
 static void
@@ -1161,7 +1129,7 @@ gtk_menu_remove (GtkContainer *container,
       menu->old_active_menu_item = NULL;
     }
 
-  GTK_CONTAINER_CLASS (parent_class)->remove (container, widget);
+  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);
@@ -1189,7 +1157,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);
 }
@@ -1304,6 +1272,7 @@ gtk_menu_popup (GtkMenu               *menu,
   GtkMenuShell *menu_shell;
   gboolean grab_keyboard;
   GtkMenuPrivate *priv;
+  GtkWidget *parent_toplevel;
 
   g_return_if_fail (GTK_IS_MENU (menu));
 
@@ -1410,16 +1379,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 (parent_toplevel && 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;
@@ -1475,7 +1449,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;
@@ -1499,7 +1473,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)
     {
@@ -1836,7 +1810,6 @@ gtk_menu_set_tearoff_state (GtkMenu  *menu,
                                                     "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);
@@ -1940,26 +1913,27 @@ 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));
 
   priv = gtk_menu_get_private (menu);
 
-  if (strcmp (title ? title : "", priv->title ? priv->title : "") != 0)
-    {
-      g_free (priv->title);
-      priv->title = g_strdup (title);
+  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");
-    }
+  gtk_menu_update_title (menu);
+  g_object_notify (G_OBJECT (menu), "tearoff-title");
 }
 
 /**
@@ -2030,6 +2004,7 @@ gtk_menu_realize (GtkWidget *widget)
   GList *children;
   guint vertical_padding;
   guint horizontal_padding;
+  guint scroll_arrow_height;
 
   g_return_if_fail (GTK_IS_MENU (widget));
 
@@ -2060,6 +2035,7 @@ gtk_menu_realize (GtkWidget *widget)
   gtk_widget_style_get (GTK_WIDGET (menu),
                        "vertical-padding", &vertical_padding,
                         "horizontal-padding", &horizontal_padding,
+                        "scroll-arrow-vlength", &scroll_arrow_height,
                        NULL);
 
   attributes.x = border_width + widget->style->xthickness + horizontal_padding;
@@ -2069,12 +2045,12 @@ gtk_menu_realize (GtkWidget *widget)
 
   if (menu->upper_arrow_visible)
     {
-      attributes.y += MENU_SCROLL_ARROW_HEIGHT;
-      attributes.height -= MENU_SCROLL_ARROW_HEIGHT;
+      attributes.y += scroll_arrow_height;
+      attributes.height -= scroll_arrow_height;
     }
 
   if (menu->lower_arrow_visible)
-    attributes.height -= MENU_SCROLL_ARROW_HEIGHT;
+    attributes.height -= scroll_arrow_height;
 
   menu->view_window = gdk_window_new (widget->window, &attributes, attributes_mask);
   gdk_window_set_user_data (menu->view_window, menu);
@@ -2184,7 +2160,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
@@ -2295,7 +2271,8 @@ gtk_menu_size_allocate (GtkWidget     *widget,
   gint width, height;
   guint vertical_padding;
   guint horizontal_padding;
-
+  gint scroll_arrow_height;
+  
   g_return_if_fail (GTK_IS_MENU (widget));
   g_return_if_fail (allocation != NULL);
   
@@ -2309,6 +2286,7 @@ gtk_menu_size_allocate (GtkWidget     *widget,
   gtk_widget_style_get (GTK_WIDGET (menu),
                        "vertical-padding", &vertical_padding,
                         "horizontal-padding", &horizontal_padding,
+                        "scroll-arrow-vlength", &scroll_arrow_height,
                        NULL);
 
   x = GTK_CONTAINER (menu)->border_width + widget->style->xthickness + horizontal_padding;
@@ -2325,12 +2303,12 @@ gtk_menu_size_allocate (GtkWidget     *widget,
 
   if (menu->upper_arrow_visible && !menu->tearoff_active)
     {
-      y += MENU_SCROLL_ARROW_HEIGHT;
-      height -= MENU_SCROLL_ARROW_HEIGHT;
+      y += scroll_arrow_height;
+      height -= scroll_arrow_height;
     }
 
   if (menu->lower_arrow_visible && !menu->tearoff_active)
-    height -= MENU_SCROLL_ARROW_HEIGHT;
+    height -= scroll_arrow_height;
 
   if (GTK_WIDGET_REALIZED (widget))
     {
@@ -2454,7 +2432,8 @@ gtk_menu_paint (GtkWidget      *widget,
   gint border_x, border_y;
   guint vertical_padding;
   guint horizontal_padding;
-
+  gint scroll_arrow_height;
+  
   g_return_if_fail (GTK_IS_MENU (widget));
 
   menu = GTK_MENU (widget);
@@ -2463,7 +2442,8 @@ gtk_menu_paint (GtkWidget      *widget,
   gtk_widget_style_get (GTK_WIDGET (menu),
                        "vertical-padding", &vertical_padding,
                         "horizontal-padding", &horizontal_padding,
-                       NULL);
+                        "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;
@@ -2471,7 +2451,7 @@ gtk_menu_paint (GtkWidget      *widget,
 
   if (event->window == widget->window)
     {
-      gint arrow_space = MENU_SCROLL_ARROW_HEIGHT - 2 * widget->style->ythickness;
+      gint arrow_space = scroll_arrow_height - 2 * widget->style->ythickness;
       gint arrow_size = 0.7 * arrow_space;
 
       gtk_paint_box (widget->style,
@@ -2491,7 +2471,7 @@ gtk_menu_paint (GtkWidget      *widget,
                         border_x,
                         border_y,
                         width - 2 * border_x,
-                        MENU_SCROLL_ARROW_HEIGHT);
+                        scroll_arrow_height);
 
          gtk_paint_arrow (widget->style,
                           widget->window,
@@ -2513,9 +2493,9 @@ gtk_menu_paint (GtkWidget      *widget,
                         GTK_SHADOW_OUT,
                         NULL, widget, "menu",
                         border_x,
-                        height - border_y - MENU_SCROLL_ARROW_HEIGHT,
+                        height - border_y - scroll_arrow_height,
                         width - 2*border_x,
-                        MENU_SCROLL_ARROW_HEIGHT);
+                        scroll_arrow_height);
 
          gtk_paint_arrow (widget->style,
                           widget->window,
@@ -2525,7 +2505,7 @@ gtk_menu_paint (GtkWidget      *widget,
                           GTK_ARROW_DOWN,
                           TRUE,
                           (width - arrow_size) / 2,
-                          height - border_y - MENU_SCROLL_ARROW_HEIGHT +
+                          height - border_y - scroll_arrow_height +
                              widget->style->ythickness + (arrow_space - arrow_size)/2,
                           arrow_size, arrow_size);
        }
@@ -2553,7 +2533,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;
@@ -2566,7 +2546,7 @@ 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
@@ -2611,7 +2591,7 @@ gtk_menu_button_press (GtkWidget      *widget,
   if (gtk_menu_button_scroll (widget, event))
     return TRUE;
 
-  return GTK_WIDGET_CLASS (parent_class)->button_press_event (widget, event);
+  return GTK_WIDGET_CLASS (gtk_menu_parent_class)->button_press_event (widget, event);
 }
 
 static gboolean
@@ -2637,7 +2617,7 @@ gtk_menu_button_release (GtkWidget      *widget,
   if (gtk_menu_button_scroll (widget, event))
     return TRUE;
 
-  return GTK_WIDGET_CLASS (parent_class)->button_release_event (widget, event);
+  return GTK_WIDGET_CLASS (gtk_menu_parent_class)->button_release_event (widget, event);
 }
 
 static const gchar *
@@ -2699,7 +2679,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);
@@ -2709,7 +2689,7 @@ 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;
@@ -2777,7 +2757,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
        {
@@ -2806,7 +2786,7 @@ gtk_menu_key_press (GtkWidget     *widget,
               * locked already
               */
              /* g_print("failed to change\n"); */
-             gdk_display_beep (display);
+             gtk_widget_error_bell (widget);
            }
        }
     }
@@ -2962,10 +2942,15 @@ gtk_menu_scroll_by (GtkMenu *menu,
   gint offset;
   gint view_width, view_height;
   gboolean double_arrows;
-
+  gint scroll_arrow_height;
+  
   widget = GTK_WIDGET (menu);
   offset = menu->scroll_offset + step;
 
+  gtk_widget_style_get (GTK_WIDGET (menu),
+                        "scroll-arrow-vlength", &scroll_arrow_height,
+                        NULL);
+
   double_arrows = get_double_arrows (menu);
 
   /* If we scroll upward and the non-visible top part
@@ -2974,7 +2959,7 @@ gtk_menu_scroll_by (GtkMenu *menu,
    * screen space than just scrolling to the top.
    */
   if (!double_arrows)
-    if ((step < 0) && (offset < MENU_SCROLL_ARROW_HEIGHT))
+    if ((step < 0) && (offset < scroll_arrow_height))
       offset = 0;
 
   /* Don't scroll over the top if we weren't before: */
@@ -2989,13 +2974,13 @@ gtk_menu_scroll_by (GtkMenu *menu,
 
   /* Don't scroll past the bottom if we weren't before: */
   if (menu->scroll_offset > 0)
-    view_height -= MENU_SCROLL_ARROW_HEIGHT;
+    view_height -= scroll_arrow_height;
 
   /* When both arrows are always shown, reduce
    * view height even more.
    */
   if (double_arrows)
-    view_height -= MENU_SCROLL_ARROW_HEIGHT;
+    view_height -= scroll_arrow_height;
 
   if ((menu->scroll_offset + view_height <= widget->requisition.height) &&
       (offset + view_height > widget->requisition.height))
@@ -3037,8 +3022,6 @@ gtk_menu_scroll_timeout (gpointer  data)
   GtkSettings *settings;
   gboolean     touchscreen_mode;
 
-  GDK_THREADS_ENTER ();
-
   menu = GTK_MENU (data);
 
   settings = gtk_widget_get_settings (GTK_WIDGET (menu));
@@ -3048,8 +3031,6 @@ gtk_menu_scroll_timeout (gpointer  data)
 
   gtk_menu_do_timeout_scroll (menu, touchscreen_mode);
 
-  GDK_THREADS_LEAVE ();
-
   return TRUE;
 }
 
@@ -3061,8 +3042,6 @@ gtk_menu_scroll_timeout_initial (gpointer data)
   guint        timeout;
   gboolean     touchscreen_mode;
 
-  GDK_THREADS_ENTER ();
-
   menu = GTK_MENU (data);
 
   settings = gtk_widget_get_settings (GTK_WIDGET (menu));
@@ -3075,9 +3054,7 @@ gtk_menu_scroll_timeout_initial (gpointer data)
 
   gtk_menu_remove_scroll_timeout (menu);
 
-  menu->timeout_id = g_timeout_add (timeout, gtk_menu_scroll_timeout, menu);
-
-  GDK_THREADS_LEAVE ();
+  menu->timeout_id = gdk_threads_add_timeout (timeout, gtk_menu_scroll_timeout, menu);
 
   return FALSE;
 }
@@ -3097,7 +3074,7 @@ gtk_menu_start_scrolling (GtkMenu *menu)
 
   gtk_menu_do_timeout_scroll (menu, touchscreen_mode);
 
-  menu->timeout_id = g_timeout_add (timeout, gtk_menu_scroll_timeout_initial,
+  menu->timeout_id = gdk_threads_add_timeout (timeout, gtk_menu_scroll_timeout_initial,
                                     menu);
 }
 
@@ -3141,7 +3118,8 @@ gtk_menu_handle_scrolling (GtkMenu *menu,
   gint win_x, win_y;
   GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (menu));
   gboolean touchscreen_mode;
-
+  gint scroll_arrow_height;
+  
   priv = gtk_menu_get_private (menu);
 
   menu_shell = GTK_MENU_SHELL (menu);
@@ -3154,6 +3132,7 @@ gtk_menu_handle_scrolling (GtkMenu *menu,
 
   gtk_widget_style_get (GTK_WIDGET (menu),
                        "vertical-padding", &vertical_padding,
+                        "scroll-arrow-vlength", &scroll_arrow_height,
                        NULL);
 
   border = GTK_CONTAINER (menu)->border_width +
@@ -3170,7 +3149,7 @@ gtk_menu_handle_scrolling (GtkMenu *menu,
   rect.x = win_x;
   rect.y = win_y;
   rect.width = width;
-  rect.height = MENU_SCROLL_ARROW_HEIGHT + border;
+  rect.height = scroll_arrow_height + border;
 
   in_arrow = FALSE;
   if (menu->upper_arrow_visible && !menu->tearoff_active &&
@@ -3241,7 +3220,7 @@ gtk_menu_handle_scrolling (GtkMenu *menu,
                     -MENU_SCROLL_STEP2 : -MENU_SCROLL_STEP1;
 
                   menu->timeout_id =
-                    g_timeout_add (scroll_fast ?
+                    gdk_threads_add_timeout (scroll_fast ?
                                    MENU_SCROLL_TIMEOUT2 : MENU_SCROLL_TIMEOUT1,
                                    gtk_menu_scroll_timeout, menu);
                 }
@@ -3262,9 +3241,9 @@ gtk_menu_handle_scrolling (GtkMenu *menu,
   /*  lower arrow handling  */
 
   rect.x = win_x;
-  rect.y = win_y + height - border - MENU_SCROLL_ARROW_HEIGHT;
+  rect.y = win_y + height - border - scroll_arrow_height;
   rect.width = width;
-  rect.height = MENU_SCROLL_ARROW_HEIGHT + border;
+  rect.height = scroll_arrow_height + border;
 
   in_arrow = FALSE;
   if (menu->lower_arrow_visible && !menu->tearoff_active &&
@@ -3335,7 +3314,7 @@ gtk_menu_handle_scrolling (GtkMenu *menu,
                     MENU_SCROLL_STEP2 : MENU_SCROLL_STEP1;
 
                   menu->timeout_id =
-                    g_timeout_add (scroll_fast ?
+                    gdk_threads_add_timeout (scroll_fast ?
                                    MENU_SCROLL_TIMEOUT2 : MENU_SCROLL_TIMEOUT1,
                                    gtk_menu_scroll_timeout, menu);
                 }
@@ -3421,7 +3400,7 @@ gtk_menu_enter_notify (GtkWidget        *widget,
                                    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
@@ -3471,7 +3450,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 
@@ -3481,8 +3460,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);
@@ -3499,8 +3477,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))
@@ -3515,14 +3491,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; 
 }
 
@@ -3696,7 +3670,7 @@ gtk_menu_set_submenu_navigation_region (GtkMenu          *menu,
                    "gtk-menu-popdown-delay", &popdown_delay,
                    NULL);
 
-      menu->navigation_timeout = g_timeout_add (popdown_delay,
+      menu->navigation_timeout = gdk_threads_add_timeout (popdown_delay,
                                                gtk_menu_stop_navigating_submenu_cb, menu);
 
 #ifdef DRAW_STAY_UP_TRIANGLE
@@ -3734,7 +3708,8 @@ gtk_menu_position (GtkMenu *menu)
   GdkScreen *screen;
   GdkScreen *pointer_screen;
   GdkRectangle monitor;
-
+  gint scroll_arrow_height;
+  
   g_return_if_fail (GTK_IS_MENU (menu));
 
   widget = GTK_WIDGET (menu);
@@ -3743,6 +3718,10 @@ gtk_menu_position (GtkMenu *menu)
   gdk_display_get_pointer (gdk_screen_get_display (screen),
                           &pointer_screen, &x, &y, NULL);
 
+  gtk_widget_style_get (GTK_WIDGET (menu),
+                        "scroll-arrow-vlength", &scroll_arrow_height,
+                        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,
@@ -3765,6 +3744,10 @@ gtk_menu_position (GtkMenu *menu)
   private->monitor_num = gdk_screen_get_monitor_at_point (screen, x, y);
 
   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)
     {
@@ -3933,7 +3916,7 @@ gtk_menu_position (GtkMenu *menu)
     }
 
   if (scroll_offset > 0)
-    scroll_offset += MENU_SCROLL_ARROW_HEIGHT;
+    scroll_offset += scroll_arrow_height;
   
   gtk_window_move (GTK_WINDOW (GTK_MENU_SHELL (menu)->active ? menu->toplevel : menu->tearoff_window), 
                   x, y);
@@ -3964,11 +3947,11 @@ gtk_menu_stop_scrolling (GtkMenu *menu)
   gboolean touchscreen_mode;
 
   gtk_menu_remove_scroll_timeout (menu);
-
+  
   g_object_get (G_OBJECT (settings),
-                "gtk-touchscreen-mode", &touchscreen_mode,
-                NULL);
-
+               "gtk-touchscreen-mode", &touchscreen_mode,
+               NULL);
+  
   if (!touchscreen_mode)
     {
       menu->upper_arrow_prelight = FALSE;
@@ -3988,7 +3971,8 @@ gtk_menu_scroll_to (GtkMenu *menu,
   guint vertical_padding;
   guint horizontal_padding;
   gboolean double_arrows;
-
+  gint scroll_arrow_height;
+  
   widget = GTK_WIDGET (menu);
 
   if (menu->tearoff_active &&
@@ -4008,6 +3992,7 @@ gtk_menu_scroll_to (GtkMenu *menu,
   gtk_widget_style_get (GTK_WIDGET (menu),
                         "vertical-padding", &vertical_padding,
                         "horizontal-padding", &horizontal_padding,
+                        "scroll-arrow-vlength", &scroll_arrow_height,
                         NULL);
 
   double_arrows = get_double_arrows (menu);
@@ -4034,8 +4019,8 @@ gtk_menu_scroll_to (GtkMenu *menu,
           if (!menu->upper_arrow_visible || !menu->lower_arrow_visible)
             gtk_widget_queue_draw (GTK_WIDGET (menu));
 
-          view_height -= 2 * MENU_SCROLL_ARROW_HEIGHT;
-          y += MENU_SCROLL_ARROW_HEIGHT;
+          view_height -= 2 * scroll_arrow_height;
+          y += scroll_arrow_height;
 
           menu->upper_arrow_visible = menu->lower_arrow_visible = TRUE;
 
@@ -4096,7 +4081,7 @@ gtk_menu_scroll_to (GtkMenu *menu,
       menu->upper_arrow_visible = offset > 0;
       
       if (menu->upper_arrow_visible)
-       view_height -= MENU_SCROLL_ARROW_HEIGHT;
+       view_height -= scroll_arrow_height;
       
       if ((last_visible != menu->upper_arrow_visible) &&
           !menu->upper_arrow_visible)
@@ -4115,7 +4100,7 @@ gtk_menu_scroll_to (GtkMenu *menu,
       menu->lower_arrow_visible = offset < menu_height - view_height;
       
       if (menu->lower_arrow_visible)
-       view_height -= MENU_SCROLL_ARROW_HEIGHT;
+       view_height -= scroll_arrow_height;
       
       if ((last_visible != menu->lower_arrow_visible) &&
           !menu->lower_arrow_visible)
@@ -4131,7 +4116,7 @@ gtk_menu_scroll_to (GtkMenu *menu,
        }
       
       if (menu->upper_arrow_visible)
-       y += MENU_SCROLL_ARROW_HEIGHT;
+       y += scroll_arrow_height;
     }
 
   /* Scroll the menu: */
@@ -4209,12 +4194,14 @@ gtk_menu_scroll_item_visible (GtkMenuShell    *menu_shell,
     {
       guint vertical_padding;
       gboolean double_arrows;
-
+      gint scroll_arrow_height;
+      
       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,
+                            "scroll-arrow-vlength", &scroll_arrow_height,
                             NULL);
 
       double_arrows = get_double_arrows (menu);
@@ -4232,21 +4219,21 @@ gtk_menu_scroll_item_visible (GtkMenuShell    *menu_shell,
        {
          arrow_height = 0;
          if (menu->upper_arrow_visible && !menu->tearoff_active)
-           arrow_height += MENU_SCROLL_ARROW_HEIGHT;
+           arrow_height += scroll_arrow_height;
          if (menu->lower_arrow_visible && !menu->tearoff_active)
-           arrow_height += MENU_SCROLL_ARROW_HEIGHT;
+           arrow_height += scroll_arrow_height;
          
          if (child_offset + child_height > y + height - arrow_height)
            {
              arrow_height = 0;
              if ((!last_child && !menu->tearoff_active) || double_arrows)
-               arrow_height += MENU_SCROLL_ARROW_HEIGHT;
+               arrow_height += scroll_arrow_height;
 
              y = child_offset + child_height - height + arrow_height;
              if (((y > 0) && !menu->tearoff_active) || double_arrows)
                {
                  /* Need upper arrow */
-                 arrow_height += MENU_SCROLL_ARROW_HEIGHT;
+                 arrow_height += scroll_arrow_height;
                  y = child_offset + child_height - height + arrow_height;
                }
              /* Ignore the enter event we might get if the pointer is on the menu
@@ -4268,7 +4255,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);
 }
 
 
@@ -4590,7 +4577,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
@@ -4598,15 +4585,20 @@ get_visible_size (GtkMenu *menu)
 {
   GtkWidget *widget = GTK_WIDGET (menu);
   GtkContainer *container = GTK_CONTAINER (menu);
+  gint scroll_arrow_height;
   
   gint menu_height = (widget->allocation.height
                      - 2 * (container->border_width
                             + widget->style->ythickness));
   
+  gtk_widget_style_get (GTK_WIDGET (menu),
+                        "scroll-arrow-vlength", &scroll_arrow_height,
+                        NULL);
+
   if (menu->upper_arrow_visible && !menu->tearoff_active)
-    menu_height -= MENU_SCROLL_ARROW_HEIGHT;
+    menu_height -= scroll_arrow_height;
   if (menu->lower_arrow_visible && !menu->tearoff_active)
-    menu_height -= MENU_SCROLL_ARROW_HEIGHT;
+    menu_height -= scroll_arrow_height;
 
   return menu_height;
 }
@@ -4660,15 +4652,20 @@ get_menu_height (GtkMenu *menu)
 {
   gint height;
   GtkWidget *widget = GTK_WIDGET (menu);
+  gint scroll_arrow_height;
 
+  gtk_widget_style_get (GTK_WIDGET (menu),
+                        "scroll-arrow-vlength", &scroll_arrow_height,
+                        NULL);
+  
   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;
+    height -= scroll_arrow_height;
 
   if (menu->lower_arrow_visible && !menu->tearoff_active)
-    height -= MENU_SCROLL_ARROW_HEIGHT;
+    height -= scroll_arrow_height;
 
   return height;
 }
@@ -4680,6 +4677,11 @@ gtk_menu_real_move_scroll (GtkMenu       *menu,
   gint page_size = get_visible_size (menu);
   gint end_position = get_menu_height (menu);
   GtkMenuShell *menu_shell = GTK_MENU_SHELL (menu);
+  gint scroll_arrow_height;
+
+  gtk_widget_style_get (GTK_WIDGET (menu),
+                        "scroll-arrow-vlength", &scroll_arrow_height,
+                        NULL);
   
   switch (type)
     {
@@ -4723,7 +4725,7 @@ gtk_menu_real_move_scroll (GtkMenu       *menu,
            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) * scroll_arrow_height;
 
            new_child = child_at (menu, child_offset + step);
            if (new_child)