]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtktoolbar.c
Replace a lot of idle and timeout calls by the new gdk_threads api.
[~andy/gtk] / gtk / gtktoolbar.c
index 8a60d4614986111e6d6961d2f4be7d5c3e8fbeab..c2032e9fb2f4e73cd2340752b2c301799b53c327 100644 (file)
@@ -38,7 +38,6 @@
 #include "gtkseparatortoolitem.h"
 #include "gtkmenu.h"
 #include "gtkradiobutton.h"
-#include "gtktoolbar.h"
 #include "gtkbindings.h"
 #include <gdk/gdkkeysyms.h>
 #include "gtkmarshalers.h"
@@ -57,7 +56,7 @@
 
 typedef struct _ToolbarContent ToolbarContent;
 
-#define DEFAULT_IPADDING 0
+#define DEFAULT_IPADDING    0
 
 #define DEFAULT_SPACE_SIZE  12
 #define DEFAULT_SPACE_STYLE GTK_TOOLBAR_SPACE_LINE
@@ -67,6 +66,7 @@ typedef struct _ToolbarContent ToolbarContent;
 
 #define DEFAULT_ICON_SIZE GTK_ICON_SIZE_LARGE_TOOLBAR
 #define DEFAULT_TOOLBAR_STYLE GTK_TOOLBAR_BOTH
+#define DEFAULT_ANIMATION_STATE TRUE
 
 #define MAX_HOMOGENEOUS_N_CHARS 13 /* Items that are wider than this do not participate
                                    * in the homogeneous game. In units of
@@ -142,15 +142,16 @@ struct _GtkToolbarPrivate
   gint         max_homogeneous_pixels;
   
   GTimer *     timer;
-  
-  guint                show_arrow : 1;
-  guint                need_sync : 1;
-  guint                is_sliding : 1;
-  guint                need_rebuild : 1;       /* whether the overflow menu should be regenerated */
+
+  gulong        settings_connection;
+
+  guint         show_arrow : 1;
+  guint         need_sync : 1;
+  guint         is_sliding : 1;
+  guint         need_rebuild : 1;  /* whether the overflow menu should be regenerated */
+  guint         animation : 1;
 };
 
-static void       gtk_toolbar_init                 (GtkToolbar          *toolbar);
-static void       gtk_toolbar_class_init           (GtkToolbarClass     *klass);
 static void       gtk_toolbar_set_property         (GObject             *object,
                                                    guint                prop_id,
                                                    const GValue        *value,
@@ -231,6 +232,7 @@ static gboolean   gtk_toolbar_check_old_api        (GtkToolbar          *toolbar
 
 static GtkReliefStyle       get_button_relief    (GtkToolbar *toolbar);
 static gint                 get_internal_padding (GtkToolbar *toolbar);
+static gint                 get_max_child_expand (GtkToolbar *toolbar);
 static GtkShadowType        get_shadow_type      (GtkToolbar *toolbar);
 static gint                 get_space_size       (GtkToolbar *toolbar);
 static GtkToolbarSpaceStyle get_space_style      (GtkToolbar *toolbar);
@@ -240,12 +242,6 @@ static ToolbarContent *toolbar_content_new_tool_item        (GtkToolbar
                                                             GtkToolItem         *item,
                                                             gboolean             is_placeholder,
                                                             gint                 pos);
-static ToolbarContent *toolbar_content_new_compatibility    (GtkToolbar          *toolbar,
-                                                            GtkToolbarChildType  type,
-                                                            GtkWidget           *widget,
-                                                            GtkWidget           *icon,
-                                                            GtkWidget           *label,
-                                                            gint                 pos);
 static void            toolbar_content_remove               (ToolbarContent      *content,
                                                             GtkToolbar          *toolbar);
 static void            toolbar_content_free                 (ToolbarContent      *content);
@@ -300,36 +296,9 @@ static void               toolbar_content_set_expand           (ToolbarContent      *content,
 #define GTK_TOOLBAR_GET_PRIVATE(o)  \
   (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_TOOLBAR, GtkToolbarPrivate))
 
-static GtkContainerClass *     parent_class = NULL;
 static guint                   toolbar_signals [LAST_SIGNAL] = { 0 };
 
-GType
-gtk_toolbar_get_type (void)
-{
-  static GtkType type = 0;
-  
-  if (!type)
-    {
-      static const GTypeInfo type_info =
-       {
-         sizeof (GtkToolbarClass),
-         (GBaseInitFunc) NULL,
-         (GBaseFinalizeFunc) NULL,
-         (GClassInitFunc) gtk_toolbar_class_init,
-         (GClassFinalizeFunc) NULL,
-         NULL,
-         sizeof (GtkToolbar),
-         0, /* n_preallocs */
-         (GInstanceInitFunc) gtk_toolbar_init,
-       };
-      
-      type = g_type_register_static (GTK_TYPE_CONTAINER,
-                                    I_("GtkToolbar"),
-                                    &type_info, 0);
-    }
-  
-  return type;
-}
+G_DEFINE_TYPE (GtkToolbar, gtk_toolbar, GTK_TYPE_CONTAINER)
 
 static void
 add_arrow_bindings (GtkBindingSet   *binding_set,
@@ -369,8 +338,6 @@ gtk_toolbar_class_init (GtkToolbarClass *klass)
   GtkContainerClass *container_class;
   GtkBindingSet *binding_set;
   
-  parent_class = g_type_class_peek_parent (klass);
-  
   gobject_class = (GObjectClass *)klass;
   widget_class = (GtkWidgetClass *)klass;
   container_class = (GtkContainerClass *)klass;
@@ -618,7 +585,16 @@ gtk_toolbar_class_init (GtkToolbarClass *klass)
                                                             G_MAXINT,
                                                              DEFAULT_IPADDING,
                                                              GTK_PARAM_READABLE));
-  
+
+  gtk_widget_class_install_style_property (widget_class,
+                                           g_param_spec_int ("max-child-expand",
+                                                             P_("Maximum child expand"),
+                                                             P_("Maximum amount of space an expandable item will be given"),
+                                                             0,
+                                                             G_MAXINT,
+                                                             G_MAXINT,
+                                                             GTK_PARAM_READABLE));
+
   gtk_widget_class_install_style_property (widget_class,
                                           g_param_spec_enum ("space-style",
                                                              P_("Space style"),
@@ -655,7 +631,7 @@ gtk_toolbar_class_init (GtkToolbarClass *klass)
                                                     GTK_TYPE_ICON_SIZE,
                                                     DEFAULT_ICON_SIZE,
                                                     GTK_PARAM_READWRITE));  
-  
+
   binding_set = gtk_binding_set_by_class (klass);
   
   add_arrow_bindings (binding_set, GDK_Left, GTK_DIR_LEFT);
@@ -695,9 +671,9 @@ gtk_toolbar_init (GtkToolbar *toolbar)
   toolbar->orientation = GTK_ORIENTATION_HORIZONTAL;
   toolbar->style = DEFAULT_TOOLBAR_STYLE;
   toolbar->icon_size = DEFAULT_ICON_SIZE;
+  priv->animation = DEFAULT_ANIMATION_STATE;
   toolbar->tooltips = gtk_tooltips_new ();
-  g_object_ref (toolbar->tooltips);
-  gtk_object_sink (GTK_OBJECT (toolbar->tooltips));
+  g_object_ref_sink (toolbar->tooltips);
   
   priv->arrow_button = gtk_toggle_button_new ();
   g_signal_connect (priv->arrow_button, "button_press_event",
@@ -805,7 +781,7 @@ gtk_toolbar_map (GtkWidget *widget)
 {
   GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
   
-  GTK_WIDGET_CLASS (parent_class)->map (widget);
+  GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->map (widget);
   
   if (priv->event_window)
     gdk_window_show_unraised (priv->event_window);
@@ -819,7 +795,7 @@ gtk_toolbar_unmap (GtkWidget *widget)
   if (priv->event_window)
     gdk_window_hide (priv->event_window);
   
-  GTK_WIDGET_CLASS (parent_class)->unmap (widget);
+  GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->unmap (widget);
 }
 
 static void
@@ -871,8 +847,8 @@ gtk_toolbar_unrealize (GtkWidget *widget)
       priv->event_window = NULL;
     }
   
-  if (GTK_WIDGET_CLASS (parent_class)->unrealize)
-    (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
+  if (GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->unrealize)
+    (* GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->unrealize) (widget);
 }
 
 static gint
@@ -1038,10 +1014,16 @@ gtk_toolbar_size_request (GtkWidget      *widget,
 }
 
 static gint
-position (gint from, gint to, gdouble elapsed)
+position (GtkToolbar *toolbar,
+          gint        from,
+          gint        to,
+          gdouble     elapsed)
 {
   gint n_pixels;
 
+  if (! GTK_TOOLBAR_GET_PRIVATE (toolbar)->animation)
+    return to;
+
   if (elapsed <= ACCEL_THRESHOLD)
     {
       n_pixels = SLIDE_SPEED * elapsed;
@@ -1056,7 +1038,7 @@ position (gint from, gint to, gdouble elapsed)
       n_pixels = (SLIDE_SPEED / ACCEL_THRESHOLD) * elapsed * elapsed -
        SLIDE_SPEED * elapsed + SLIDE_SPEED * ACCEL_THRESHOLD;
     }
-  
+
   if (to > from)
     return MIN (from + n_pixels, to);
   else
@@ -1071,13 +1053,15 @@ compute_intermediate_allocation (GtkToolbar          *toolbar,
 {
   GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
   gdouble elapsed = g_timer_elapsed (priv->timer, NULL);
-  
-  intermediate->x = position (start->x, goal->x, elapsed);
-  intermediate->y = position (start->y, goal->y, elapsed);
-  intermediate->width =
-    position (start->x + start->width, goal->x + goal->width, elapsed) - intermediate->x;
-  intermediate->height =
-    position (start->y + start->height, goal->y + goal->height, elapsed) - intermediate->y;
+
+  intermediate->x      = position (toolbar, start->x, goal->x, elapsed);
+  intermediate->y      = position (toolbar, start->y, goal->y, elapsed);
+  intermediate->width  = position (toolbar, start->x + start->width,
+                                   goal->x + goal->width,
+                                   elapsed) - intermediate->x;
+  intermediate->height = position (toolbar, start->y + start->height,
+                                   goal->y + goal->height,
+                                   elapsed) - intermediate->y;
 }
 
 static void
@@ -1132,8 +1116,6 @@ slide_idle_handler (gpointer data)
   GtkToolbarPrivate *priv;
   GList *list;
   
-  GDK_THREADS_ENTER ();
-  
   priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
   
   if (priv->need_sync)
@@ -1209,7 +1191,6 @@ slide_idle_handler (gpointer data)
   priv->is_sliding = FALSE;
   priv->idle_id = 0;
 
-  GDK_THREADS_LEAVE();
   return FALSE;
 }
 
@@ -1246,7 +1227,7 @@ gtk_toolbar_begin_sliding (GtkToolbar *toolbar)
   priv->is_sliding = TRUE;
   
   if (!priv->idle_id)
-    priv->idle_id = g_idle_add (slide_idle_handler, toolbar);
+    priv->idle_id = gdk_threads_add_idle (slide_idle_handler, toolbar);
   
   rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
   vertical = (toolbar->orientation == GTK_ORIENTATION_VERTICAL);
@@ -1463,7 +1444,6 @@ gtk_toolbar_size_allocate (GtkWidget     *widget,
   GtkRequisition arrow_requisition;
   gboolean overflowing;
   gboolean size_changed;
-  gdouble elapsed;
   GtkAllocation item_area;
   
   size_changed = FALSE;
@@ -1600,7 +1580,9 @@ gtk_toolbar_size_allocate (GtkWidget     *widget,
    */
   if (!overflowing)
     {
+      gint max_child_expand;
       n_expand_items = 0;
+      
       for (i = 0, list = priv->content; list != NULL; list = list->next, ++i)
        {
          ToolbarContent *content = list->data;
@@ -1609,6 +1591,7 @@ gtk_toolbar_size_allocate (GtkWidget     *widget,
            n_expand_items++;
        }
       
+      max_child_expand = get_max_child_expand (toolbar);
       for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
        {
          ToolbarContent *content = list->data;
@@ -1618,7 +1601,10 @@ gtk_toolbar_size_allocate (GtkWidget     *widget,
              gint extra = size / n_expand_items;
              if (size % n_expand_items != 0)
                extra++;
-             
+
+              if (extra > max_child_expand)
+                extra = max_child_expand;
+
              allocations[i].width += extra;
              size -= extra;
              n_expand_items--;
@@ -1738,7 +1724,6 @@ gtk_toolbar_size_allocate (GtkWidget     *widget,
        }
     }
 
-  elapsed = g_timer_elapsed (priv->timer, NULL);
   for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
     {
       ToolbarContent *content = list->data;
@@ -1747,7 +1732,7 @@ gtk_toolbar_size_allocate (GtkWidget     *widget,
          new_states[i] == NORMAL)
        {
          GtkAllocation alloc;
-         GtkAllocation start_allocation;
+         GtkAllocation start_allocation = { 0, };
          GtkAllocation goal_allocation;
 
          if (priv->is_sliding)
@@ -1988,33 +1973,63 @@ gtk_toolbar_focus (GtkWidget        *widget,
   return result;
 }
 
+static GtkSettings *
+toolbar_get_settings (GtkToolbar *toolbar)
+{
+  GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
+  return priv->settings;
+}
+
 static void
 style_change_notify (GtkToolbar *toolbar)
 {
   if (!toolbar->style_set)
     {
       /* pretend it was set, then unset, thus reverting to new default */
-      toolbar->style_set = TRUE; 
+      toolbar->style_set = TRUE;
       gtk_toolbar_unset_style (toolbar);
     }
 }
 
 static void
 icon_size_change_notify (GtkToolbar *toolbar)
-{ 
+{
   if (!toolbar->icon_size_set)
     {
       /* pretend it was set, then unset, thus reverting to new default */
-      toolbar->icon_size_set = TRUE; 
+      toolbar->icon_size_set = TRUE;
       gtk_toolbar_unset_icon_size (toolbar);
     }
 }
 
-static GtkSettings *
-toolbar_get_settings (GtkToolbar *toolbar)
+static void
+animation_change_notify (GtkToolbar *toolbar)
 {
   GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
-  return priv->settings;
+  GtkSettings *settings = toolbar_get_settings (toolbar);
+  gboolean animation;
+
+  if (settings)
+    g_object_get (settings,
+                  "gtk-enable-animations", &animation,
+                  NULL);
+  else
+    animation = DEFAULT_ANIMATION_STATE;
+
+  priv->animation = animation;
+}
+
+static void
+settings_change_notify (GtkSettings      *settings,
+                        const GParamSpec *pspec,
+                        GtkToolbar       *toolbar)
+{
+  if (! strcmp (pspec->name, "gtk-toolbar-style"))
+    style_change_notify (toolbar);
+  else if (! strcmp (pspec->name, "gtk-toolbar-icon-size"))
+    icon_size_change_notify (toolbar);
+  else if (! strcmp (pspec->name, "gtk-enable-animations"))
+    animation_change_notify (toolbar);
 }
 
 static void
@@ -2036,33 +2051,26 @@ gtk_toolbar_screen_changed (GtkWidget *widget,
   
   if (old_settings)
     {
-      g_signal_handler_disconnect (old_settings, toolbar->style_set_connection);
-      g_signal_handler_disconnect (old_settings, toolbar->icon_size_connection);
-      
+      g_signal_handler_disconnect (old_settings, priv->settings_connection);
+
       g_object_unref (old_settings);
     }
-  
+
   if (settings)
     {
-      toolbar->style_set_connection =
-       g_signal_connect_swapped (settings,
-                                 "notify::gtk-toolbar-style",
-                                 G_CALLBACK (style_change_notify),
-                                 toolbar);
-      toolbar->icon_size_connection =
-       g_signal_connect_swapped (settings,
-                                 "notify::gtk-toolbar-icon-size",
-                                 G_CALLBACK (icon_size_change_notify),
-                                 toolbar);
-      
-      g_object_ref (settings);
-      priv->settings = settings;
+      priv->settings_connection =
+       g_signal_connect (settings, "notify",
+                          G_CALLBACK (settings_change_notify),
+                          toolbar);
+
+      priv->settings = g_object_ref (settings);
     }
   else
     priv->settings = NULL;
-  
+
   style_change_notify (toolbar);
   icon_size_change_notify (toolbar);
+  animation_change_notify (toolbar);
 }
 
 static int
@@ -2286,8 +2294,7 @@ gtk_toolbar_set_drop_highlight_item (GtkToolbar  *toolbar,
       if (priv->highlight_tool_item)
        g_object_unref (priv->highlight_tool_item);
       
-      g_object_ref (tool_item);
-      gtk_object_sink (GTK_OBJECT (tool_item));
+      g_object_ref_sink (tool_item);
       
       priv->highlight_tool_item = tool_item;
       
@@ -3166,7 +3173,7 @@ gtk_toolbar_finalize (GObject *object)
   if (priv->idle_id)
     g_source_remove (priv->idle_id);
 
-  G_OBJECT_CLASS (parent_class)->finalize (object);
+  G_OBJECT_CLASS (gtk_toolbar_parent_class)->finalize (object);
 }
 
 /**
@@ -3721,10 +3728,7 @@ internal_insert_element (GtkToolbar          *toolbar,
                         gboolean             use_stock)
 {
   GtkWidget *box;
-  ToolbarContent *content;
-  GtkToolbarPrivate *priv;
   char *free_me = NULL;
-  gboolean is_button = FALSE;
 
   GtkWidget *child_widget;
   GtkWidget *child_label;
@@ -3741,8 +3745,6 @@ internal_insert_element (GtkToolbar          *toolbar,
   if (!gtk_toolbar_check_old_api (toolbar))
     return NULL;
   
-  priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
-  
   child_widget = NULL;
   child_label = NULL;
   child_icon = NULL;
@@ -3759,7 +3761,6 @@ internal_insert_element (GtkToolbar          *toolbar,
     case GTK_TOOLBAR_CHILD_BUTTON:
     case GTK_TOOLBAR_CHILD_TOGGLEBUTTON:
     case GTK_TOOLBAR_CHILD_RADIOBUTTON:
-      is_button = TRUE;
       if (type == GTK_TOOLBAR_CHILD_BUTTON)
        {
          child_widget = gtk_button_new ();
@@ -3836,9 +3837,6 @@ internal_insert_element (GtkToolbar          *toolbar,
                            tooltip_text, tooltip_private_text);
     }
   
-  content = toolbar_content_new_compatibility (toolbar, type, child_widget,
-                                              child_icon, child_label, position);
-  
   if (free_me)
     g_free (free_me);
   
@@ -3913,54 +3911,6 @@ toolbar_content_new_tool_item (GtkToolbar  *toolbar,
   return content;
 }
 
-static ToolbarContent *
-toolbar_content_new_compatibility (GtkToolbar          *toolbar,
-                                  GtkToolbarChildType  type,
-                                  GtkWidget            *widget,
-                                  GtkWidget            *icon,
-                                  GtkWidget            *label,
-                                  gint                  pos)
-{
-  ToolbarContent *content;
-  GtkToolbarChild *child;
-  GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
-  
-  content = g_new0 (ToolbarContent, 1);
-
-  child = &(content->u.compatibility.child);
-  
-  content->type = COMPATIBILITY;
-  child->type = type;
-  child->widget = widget;
-  child->icon = icon;
-  child->label = label;
-  
-  if (type != GTK_TOOLBAR_CHILD_SPACE)
-    {
-      gtk_widget_set_parent (child->widget, GTK_WIDGET (toolbar));
-    }
-  else
-    {
-      content->u.compatibility.space_visible = TRUE;
-      gtk_widget_queue_resize (GTK_WIDGET (toolbar));
-    }
-  if (type == GTK_TOOLBAR_CHILD_BUTTON ||
-      type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON ||
-      type == GTK_TOOLBAR_CHILD_RADIOBUTTON)
-    {
-      set_child_packing_and_visibility (toolbar, child);
-    }
-
-  priv->content = g_list_insert (priv->content, content, pos);
-  toolbar->children = g_list_insert (toolbar->children, child, pos);
-  priv->need_rebuild = TRUE;
-  
-  toolbar->num_children++;
-  
-  return content;
-}
-
 static void
 toolbar_content_remove (ToolbarContent *content,
                        GtkToolbar     *toolbar)
@@ -4753,6 +4703,17 @@ get_internal_padding (GtkToolbar *toolbar)
   return ipadding;
 }
 
+static gint
+get_max_child_expand (GtkToolbar *toolbar)
+{
+  gint mexpand = G_MAXINT;
+
+  gtk_widget_style_get (GTK_WIDGET (toolbar),
+                        "max-child-expand", &mexpand,
+                        NULL);
+  return mexpand;
+}
+
 static GtkShadowType
 get_shadow_type (GtkToolbar *toolbar)
 {
@@ -4815,31 +4776,63 @@ _gtk_toolbar_paint_space_line (GtkWidget       *widget,
   const double start_fraction = (SPACE_LINE_START / SPACE_LINE_DIVISION);
   const double end_fraction = (SPACE_LINE_END / SPACE_LINE_DIVISION);
   
-  GtkToolbarSpaceStyle space_style;
   GtkOrientation orientation;
 
   g_return_if_fail (GTK_IS_WIDGET (widget));
   
-  space_style = toolbar? get_space_style (toolbar) : DEFAULT_SPACE_STYLE;
   orientation = toolbar? toolbar->orientation : GTK_ORIENTATION_HORIZONTAL;
 
   if (orientation == GTK_ORIENTATION_HORIZONTAL)
     {
-      gtk_paint_vline (widget->style, widget->window,
-                      GTK_WIDGET_STATE (widget), area, widget,
-                      "toolbar",
-                      allocation->y + allocation->height * start_fraction,
-                      allocation->y + allocation->height * end_fraction,
-                      allocation->x + (allocation->width - widget->style->xthickness) / 2);
+      gboolean wide_separators;
+      gint     separator_width;
+
+      gtk_widget_style_get (widget,
+                            "wide-separators", &wide_separators,
+                            "separator-width", &separator_width,
+                            NULL);
+
+      if (wide_separators)
+        gtk_paint_box (widget->style, widget->window,
+                       GTK_WIDGET_STATE (widget), GTK_SHADOW_ETCHED_OUT,
+                       area, widget, "vseparator",
+                       allocation->x + (allocation->width - separator_width) / 2,
+                       allocation->y + allocation->height * start_fraction,
+                       separator_width,
+                       allocation->height * (end_fraction - start_fraction));
+      else
+        gtk_paint_vline (widget->style, widget->window,
+                         GTK_WIDGET_STATE (widget), area, widget,
+                         "toolbar",
+                         allocation->y + allocation->height * start_fraction,
+                         allocation->y + allocation->height * end_fraction,
+                         allocation->x + (allocation->width - widget->style->xthickness) / 2);
     }
   else
     {
-      gtk_paint_hline (widget->style, widget->window,
-                      GTK_WIDGET_STATE (widget), area, widget,
-                      "toolbar",
-                      allocation->x + allocation->width * start_fraction,
-                      allocation->x + allocation->width * end_fraction,
-                      allocation->y + (allocation->height - widget->style->ythickness) / 2);
+      gboolean wide_separators;
+      gint     separator_height;
+
+      gtk_widget_style_get (widget,
+                            "wide-separators",  &wide_separators,
+                            "separator-height", &separator_height,
+                            NULL);
+
+      if (wide_separators)
+        gtk_paint_box (widget->style, widget->window,
+                       GTK_WIDGET_STATE (widget), GTK_SHADOW_ETCHED_OUT,
+                       area, widget, "hseparator",
+                       allocation->x + allocation->width * start_fraction,
+                       allocation->y + (allocation->height - separator_height) / 2,
+                       allocation->width * (end_fraction - start_fraction),
+                       separator_height);
+      else
+        gtk_paint_hline (widget->style, widget->window,
+                         GTK_WIDGET_STATE (widget), area, widget,
+                         "toolbar",
+                         allocation->x + allocation->width * start_fraction,
+                         allocation->x + allocation->width * end_fraction,
+                         allocation->y + (allocation->height - widget->style->ythickness) / 2);
     }
 }
 
@@ -4847,25 +4840,38 @@ gchar *
 _gtk_toolbar_elide_underscores (const gchar *original)
 {
   gchar *q, *result;
-  const gchar *p;
+  const gchar *p, *end;
+  gsize len;
   gboolean last_underscore;
   
   if (!original)
     return NULL;
 
-  q = result = g_malloc (strlen (original) + 1);
+  len = strlen (original);
+  q = result = g_malloc (len + 1);
   last_underscore = FALSE;
   
-  for (p = original; *p; p++)
+  end = original + len;
+  for (p = original; p < end; p++)
     {
       if (!last_underscore && *p == '_')
        last_underscore = TRUE;
       else
        {
          last_underscore = FALSE;
-         *q++ = *p;
+         if (*p != '_' && original + 2 <= p && p + 1 <= end && p[-2] == '(' && p[1] == ')')
+           {
+             q--;
+             *q = '\0';
+             p++;
+           }
+         else
+           *q++ = *p;
        }
     }
+
+  if (last_underscore)
+    *q++ = '_';
   
   *q = '\0';