#include "gtkseparatortoolitem.h"
#include "gtkmenu.h"
#include "gtkradiobutton.h"
-#include "gtktoolbar.h"
#include "gtkbindings.h"
#include <gdk/gdkkeysyms.h>
#include "gtkmarshalers.h"
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
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);
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);
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,
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"),
GtkToolbarPrivate *priv;
GList *list;
- GDK_THREADS_ENTER ();
-
priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
if (priv->need_sync)
priv->is_sliding = FALSE;
priv->idle_id = 0;
- GDK_THREADS_LEAVE();
return FALSE;
}
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);
GtkRequisition arrow_requisition;
gboolean overflowing;
gboolean size_changed;
- gdouble elapsed;
GtkAllocation item_area;
size_changed = FALSE;
*/
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;
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;
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--;
}
}
- elapsed = g_timer_elapsed (priv->timer, NULL);
for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
{
ToolbarContent *content = list->data;
gboolean use_stock)
{
GtkWidget *box;
- ToolbarContent *content;
char *free_me = NULL;
GtkWidget *child_widget;
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);
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)
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)
{
_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;
}