#define GTK_TOOLBAR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_TOOLBAR, GtkToolbarPrivate))
+typedef enum {
+ NOT_ALLOCATED,
+ NORMAL,
+ HIDDEN,
+ OVERFLOWN,
+} ItemState;
+
struct _ToolbarContent
{
- GtkToolItem *item;
- guint is_overflow : 1;
- guint is_placeholder : 1;
- gint start_width;
- gint goal_width;
- gint start_height;
- gint goal_height;
+ GtkToolItem * item;
+ guint is_placeholder : 1;
+ gint start_width;
+ gint goal_width;
+ gint start_height;
+ gint goal_height;
+ GtkAllocation start_allocation;
+ ItemState state;
};
struct _GtkToolbarPrivate
ApiMode api_mode;
GtkSettings *settings;
int idle_id;
- GTimer *timer;
gboolean need_sync;
gboolean leaving_dnd;
gboolean in_dnd;
gint n_overflow_items_when_dnd_started;
GtkToolItem *highlight_tool_item;
gint max_homogeneous_pixels;
+
+ GTimer *timer;
+ gboolean is_sliding;
};
static GtkContainerClass *parent_class = NULL;
GtkToolbar *toolbar = GTK_TOOLBAR (widget);
GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
GtkAllocation *allocations;
+ ItemState *new_states;
GtkAllocation arrow_allocation;
gint arrow_size;
gint size, pos, short_size;
n_items = g_list_length (priv->content);
allocations = g_new0 (GtkAllocation, n_items);
+ new_states = g_new0 (ItemState, n_items);
needed_size = 0;
for (list = priv->content; list != NULL; list = list->next)
gint item_size;
if (!toolbar_item_visible (toolbar, item))
- continue;
+ {
+ new_states[i] = HIDDEN;
+ continue;
+ }
item_size = get_item_size (toolbar, GTK_WIDGET (item));
if (item_size <= size && !overflowing)
{
size -= item_size;
allocations[i].width = item_size;
- content->is_overflow = FALSE;
+ new_states[i] = NORMAL;
}
else
{
++n_overflowed;
- content->is_overflow = TRUE;
overflowing = TRUE;
+ new_states[i] = OVERFLOWN;
}
}
if (!(priv->in_dnd && n_overflowed > priv->n_overflow_items_when_dnd_started))
{
n_expand_items = 0;
- for (list = priv->content; list != NULL; list = list->next)
+ for (i = 0, list = priv->content; list != NULL; list = list->next, ++i)
{
ToolbarContent *content = list->data;
GtkToolItem *item = content->item;
- if (toolbar_item_visible (toolbar, item) &&
- gtk_tool_item_get_expand (item) &&
- !content->is_overflow)
- {
- n_expand_items++;
- }
+ if (gtk_tool_item_get_expand (item) && new_states[i] == NORMAL)
+ n_expand_items++;
}
for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
ToolbarContent *content = list->data;
GtkToolItem *item = content->item;
- if (toolbar_item_visible (toolbar, item) &&
- gtk_tool_item_get_expand (item) &&
- !content->is_overflow)
+ if (gtk_tool_item_get_expand (item) && new_states[i] == NORMAL)
{
gint extra = size / n_expand_items;
if (size % n_expand_items != 0)
pos = border_width;
for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
{
- ToolbarContent *content = list->data;
- GtkToolItem *item = content->item;
-
- if (toolbar_item_visible (toolbar, item) && !content->is_overflow)
+ if (new_states[i] == NORMAL)
{
allocations[i].x = pos;
allocations[i].y = border_width;
ToolbarContent *content = list->data;
GtkToolItem *item = content->item;
- if (toolbar_item_visible (toolbar, item) && !content->is_overflow)
+ if (new_states[i] == NORMAL)
{
gtk_widget_size_allocate (GTK_WIDGET (item), &(allocations[i]));
gtk_widget_set_child_visible (GTK_WIDGET (item), TRUE);
{
gtk_widget_set_child_visible (GTK_WIDGET (item), FALSE);
}
+
+ content->state = new_states[i];
}
if (need_arrow)
}
g_free (allocations);
+ g_free (new_states);
}
static void
for (list = priv->content; list != NULL; list = list->next)
{
ToolbarContent *content = list->data;
- GtkToolItem *item = content->item;
- if (toolbar_item_visible (toolbar, item) && !content->is_overflow)
+ if (content->state == NORMAL)
interesting_content = g_list_prepend (interesting_content, content);
}
interesting_content = g_list_reverse (interesting_content);
for (list = priv->content; list != NULL; list = list->next)
{
content = list->data;
- if (content->is_overflow &&
- toolbar_item_visible (toolbar, content->item))
- {
- priv->n_overflow_items_when_dnd_started++;
- }
+ if (content->state == OVERFLOWN)
+ priv->n_overflow_items_when_dnd_started++;
}
}
ToolbarContent *content = list->data;
GtkToolItem *item = content->item;
- if (toolbar_item_visible (toolbar, item) && content->is_overflow)
+ if (content->state == OVERFLOWN)
{
GtkWidget *menu_item = gtk_tool_item_retrieve_proxy_menu_item (item);
GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
ToolbarContent *content = g_new0 (ToolbarContent, 1);
- content->is_overflow = FALSE;
content->is_placeholder = is_placeholder;
content->item = item;
+ content->state = NOT_ALLOCATED;
toolbar->num_children++;
priv->content = g_list_insert (priv->content, content, pos);