]> 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 98535add887ca3474304dfc4f1459578a7d2cf81..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
@@ -233,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);
@@ -242,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);
@@ -304,7 +298,7 @@ static void        toolbar_content_set_expand           (ToolbarContent      *content,
 
 static guint                   toolbar_signals [LAST_SIGNAL] = { 0 };
 
-G_DEFINE_TYPE (GtkToolbar, gtk_toolbar, GTK_TYPE_CONTAINER);
+G_DEFINE_TYPE (GtkToolbar, gtk_toolbar, GTK_TYPE_CONTAINER)
 
 static void
 add_arrow_bindings (GtkBindingSet   *binding_set,
@@ -591,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"),
@@ -1113,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)
@@ -1190,7 +1191,6 @@ slide_idle_handler (gpointer data)
   priv->is_sliding = FALSE;
   priv->idle_id = 0;
 
-  GDK_THREADS_LEAVE();
   return FALSE;
 }
 
@@ -1227,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);
@@ -1444,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;
@@ -1581,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;
@@ -1590,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;
@@ -1599,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--;
@@ -1719,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;
@@ -3724,7 +3728,6 @@ internal_insert_element (GtkToolbar          *toolbar,
                         gboolean             use_stock)
 {
   GtkWidget *box;
-  ToolbarContent *content;
   char *free_me = NULL;
 
   GtkWidget *child_widget;
@@ -3834,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);
   
@@ -3911,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)
@@ -4751,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)
 {
@@ -4877,38 +4840,40 @@ gchar *
 _gtk_toolbar_elide_underscores (const gchar *original)
 {
   gchar *q, *result;
-  const gchar *p;
+  const gchar *p, *end;
+  gsize len;
   gboolean last_underscore;
-  gint s;
   
   if (!original)
     return NULL;
 
-  s = strlen (original);
-  q = result = g_malloc (s + 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';
-
-  if (s > 4)
-    {
-      if (original[s - 4] == '(' && 
-         original[s - 3] == '_' && 
-         original[s - 1] == ')')
-       q[-3] = '\0';
-    }
-
   
   return result;
 }