--- gtk+-2.6.4/gtk/gtktoolbar.c 2004-11-23 06:11:15.000000000 +0200 +++ gtk+-2.6.4/gtk/gtktoolbar.c 2005-04-06 16:19:38.166736136 +0300 @@ -67,7 +67,9 @@ #define DEFAULT_ICON_SIZE GTK_ICON_SIZE_LARGE_TOOLBAR #define DEFAULT_TOOLBAR_STYLE GTK_TOOLBAR_BOTH +#define DEFAULT_ANIMATION_STATE FALSE +#define DEFAULT_MAX_CHILD_SPACING G_MAXINT #define MAX_HOMOGENEOUS_N_CHARS 13 /* Items that are wider than this do not participate * in the homogeneous game. In units of * pango_font_get_estimated_char_width(). @@ -140,10 +142,14 @@ GTimer * timer; + guint animation_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_set : 1; + guint animation : 1; }; static void gtk_toolbar_init (GtkToolbar *toolbar); @@ -225,9 +231,11 @@ static void gtk_toolbar_reconfigured (GtkToolbar *toolbar); static gboolean gtk_toolbar_check_new_api (GtkToolbar *toolbar); static gboolean gtk_toolbar_check_old_api (GtkToolbar *toolbar); +static void gtk_toolbar_update_animation_state (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); @@ -563,6 +571,15 @@ G_PARAM_READABLE)); gtk_widget_class_install_style_property (widget_class, + g_param_spec_int ("max_child_expand", + P_("Maximum toolbar item spacing"), + P_("Maximum space between the toolbar items."), + 0, + G_MAXINT, + DEFAULT_MAX_CHILD_SPACING, + G_PARAM_READABLE)); + + gtk_widget_class_install_style_property (widget_class, g_param_spec_enum ("space_style", P_("Space style"), P_("Whether spacers are vertical lines or just blank"), @@ -598,6 +615,12 @@ GTK_TYPE_ICON_SIZE, DEFAULT_ICON_SIZE, G_PARAM_READWRITE)); + + gtk_settings_install_property (g_param_spec_boolean ("gtk-toolbar-animation", + P_("Toolbar animation"), + P_("Are we using toolbar animation"), + DEFAULT_ANIMATION_STATE, + G_PARAM_READWRITE)); binding_set = gtk_binding_set_by_class (klass); @@ -638,6 +661,7 @@ 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)); @@ -960,7 +984,7 @@ } static gint -position (gint from, gint to, gdouble elapsed) +position (GtkToolbar *toolbar, gint from, gint to, gdouble elapsed) { gint n_pixels; @@ -978,11 +1002,20 @@ 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 - return MAX (from - n_pixels, to); + if (GTK_TOOLBAR_GET_PRIVATE (toolbar)->animation) { + if (to > from) + return MIN (from + n_pixels, to); + else + return MAX (from - n_pixels, to); + } + return to; +} + +static GtkSettings * +toolbar_get_settings (GtkToolbar *toolbar) +{ + GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar); + return priv->settings; } static void @@ -994,12 +1027,12 @@ 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->x = position (toolbar, start->x, goal->x, elapsed); + intermediate->y = position (toolbar, start->y, goal->y, elapsed); intermediate->width = - position (start->x + start->width, goal->x + goal->width, elapsed) - intermediate->x; + position (toolbar, 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; + position (toolbar, start->y + start->height, goal->y + goal->height, elapsed) - intermediate->y; } static void @@ -1047,6 +1080,32 @@ } } +static void +gtk_toolbar_update_animation_state (GtkToolbar *toolbar) +{ + gboolean animation_state; + GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar); + + g_return_if_fail (GTK_IS_TOOLBAR (toolbar)); + + if (priv->animation_set) + { + GtkSettings *settings = toolbar_get_settings (toolbar); + + if (settings) + { + g_object_get (settings, + "gtk-toolbar-animation", &animation_state, + NULL); + } + else + animation_state = DEFAULT_ANIMATION_STATE; + + priv->animation = animation_state; + priv->animation_set = FALSE; + } +} + static gboolean slide_idle_handler (gpointer data) { @@ -1537,10 +1596,14 @@ if (toolbar_content_get_expand (content) && new_states[i] == NORMAL) { + gint mexpand = get_max_child_expand(toolbar); gint extra = size / n_expand_items; if (size % n_expand_items != 0) extra++; - + if (extra > mexpand) { + extra = mexpand; + } + allocations[i].width += extra; size -= extra; n_expand_items--; @@ -1932,11 +1995,16 @@ } } -static GtkSettings * -toolbar_get_settings (GtkToolbar *toolbar) +static void +animation_change_notify (GtkToolbar *toolbar) { GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar); - return priv->settings; + if (!priv->animation_set) + { + /* pretend it was set, then unset, thus reverting to new default */ + priv->animation_set = TRUE; + gtk_toolbar_update_animation_state (toolbar); + } } static void @@ -1960,6 +2028,7 @@ { 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->animation_connection); g_object_unref (old_settings); } @@ -1976,6 +2045,11 @@ "notify::gtk-toolbar-icon-size", G_CALLBACK (icon_size_change_notify), toolbar); + priv->animation_connection = + g_signal_connect_swapped (settings, + "notify::gtk-toolbar-animation", + G_CALLBACK (animation_change_notify), + toolbar); g_object_ref (settings); priv->settings = settings; @@ -1985,6 +2059,7 @@ style_change_notify (toolbar); icon_size_change_notify (toolbar); + animation_change_notify (toolbar); } static int @@ -2913,7 +2988,7 @@ * gtk_toolbar_get_icon_size: * @toolbar: a #GtkToolbar * - * Retrieves the icon size fo the toolbar. See gtk_toolbar_set_icon_size(). + * Retrieves the icon size for the toolbar. See gtk_toolbar_set_icon_size(). * * Return value: the current icon size for the icons on the toolbar. **/ @@ -4642,6 +4717,17 @@ return ipadding; } +static gint +get_max_child_expand (GtkToolbar *toolbar) +{ + gint mexpand = DEFAULT_MAX_CHILD_SPACING; + + gtk_widget_style_get (GTK_WIDGET (toolbar), + "max_child_expand", &mexpand, + NULL); + return mexpand; +} + static GtkShadowType get_shadow_type (GtkToolbar *toolbar) {