Make scroll_to_path work for newly inserted items, by delaying the scroll

2006-03-02  Matthias Clasen  <mclasen@redhat.com>

	* gtk/gtkiconview.c (gtk_icon_view_layout)
	(gtk_icon_view_row_inserted, gtk_icon_view_scroll_to_path):
	Make scroll_to_path work for newly inserted items, by delaying
	the scroll until layout is done.  (#332923, Cory Dodt)
This commit is contained in:
Matthias Clasen 2006-03-02 19:52:26 +00:00 committed by Matthias Clasen
parent 6109863e15
commit 75606909f1
3 changed files with 49 additions and 28 deletions

View File

@ -1,5 +1,10 @@
2006-03-02 Matthias Clasen <mclasen@redhat.com> 2006-03-02 Matthias Clasen <mclasen@redhat.com>
* gtk/gtkiconview.c (gtk_icon_view_layout)
(gtk_icon_view_row_inserted, gtk_icon_view_scroll_to_path):
Make scroll_to_path work for newly inserted items, by delaying
the scroll until layout is done. (#332923, Cory Dodt)
* gtk/gtkcolorbutton.c (render): Use GTK_WIDGET_IS_SENSITIVE, * gtk/gtkcolorbutton.c (render): Use GTK_WIDGET_IS_SENSITIVE,
not GTK_WIDGET_SENSITIVE. (#333133, Christian Persch) not GTK_WIDGET_SENSITIVE. (#333133, Christian Persch)

View File

@ -1,5 +1,10 @@
2006-03-02 Matthias Clasen <mclasen@redhat.com> 2006-03-02 Matthias Clasen <mclasen@redhat.com>
* gtk/gtkiconview.c (gtk_icon_view_layout)
(gtk_icon_view_row_inserted, gtk_icon_view_scroll_to_path):
Make scroll_to_path work for newly inserted items, by delaying
the scroll until layout is done. (#332923, Cory Dodt)
* gtk/gtkcolorbutton.c (render): Use GTK_WIDGET_IS_SENSITIVE, * gtk/gtkcolorbutton.c (render): Use GTK_WIDGET_IS_SENSITIVE,
not GTK_WIDGET_SENSITIVE. (#333133, Christian Persch) not GTK_WIDGET_SENSITIVE. (#333133, Christian Persch)

View File

@ -2477,6 +2477,12 @@ gtk_icon_view_layout (GtkIconView *icon_view)
gint row; gint row;
gint item_width; gint item_width;
if (icon_view->priv->layout_idle_id != 0)
{
g_source_remove (icon_view->priv->layout_idle_id);
icon_view->priv->layout_idle_id = 0;
}
if (icon_view->priv->model == NULL) if (icon_view->priv->model == NULL)
return; return;
@ -2508,32 +2514,38 @@ gtk_icon_view_layout (GtkIconView *icon_view)
while (icons != NULL); while (icons != NULL);
if (maximum_width != icon_view->priv->width) if (maximum_width != icon_view->priv->width)
{ icon_view->priv->width = maximum_width;
icon_view->priv->width = maximum_width;
}
y += icon_view->priv->margin; y += icon_view->priv->margin;
if (y != icon_view->priv->height) if (y != icon_view->priv->height)
{ icon_view->priv->height = y;
icon_view->priv->height = y;
}
gtk_icon_view_set_adjustment_upper (icon_view->priv->hadjustment, icon_view->priv->width); gtk_icon_view_set_adjustment_upper (icon_view->priv->hadjustment,
gtk_icon_view_set_adjustment_upper (icon_view->priv->vadjustment, icon_view->priv->height); icon_view->priv->width);
gtk_icon_view_set_adjustment_upper (icon_view->priv->vadjustment,
icon_view->priv->height);
if (GTK_WIDGET_REALIZED (icon_view)) if (GTK_WIDGET_REALIZED (icon_view))
{ gdk_window_resize (icon_view->priv->bin_window,
gdk_window_resize (icon_view->priv->bin_window, MAX (icon_view->priv->width, widget->allocation.width),
MAX (icon_view->priv->width, widget->allocation.width), MAX (icon_view->priv->height, widget->allocation.height));
MAX (icon_view->priv->height, widget->allocation.height));
}
if (icon_view->priv->layout_idle_id != 0) if (icon_view->priv->scroll_to_path)
{ {
g_source_remove (icon_view->priv->layout_idle_id); GtkTreePath *path;
icon_view->priv->layout_idle_id = 0;
}
path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
icon_view->priv->scroll_to_path = NULL;
gtk_icon_view_scroll_to_path (icon_view, path,
icon_view->priv->scroll_to_use_align,
icon_view->priv->scroll_to_row_align,
icon_view->priv->scroll_to_col_align);
gtk_tree_path_free (path);
}
gtk_widget_queue_draw (GTK_WIDGET (icon_view)); gtk_widget_queue_draw (GTK_WIDGET (icon_view));
} }
@ -3271,6 +3283,8 @@ gtk_icon_view_row_inserted (GtkTreeModel *model,
} }
verify_items (icon_view); verify_items (icon_view);
gtk_icon_view_queue_layout (icon_view);
} }
static void static void
@ -3313,10 +3327,10 @@ gtk_icon_view_row_deleted (GtkTreeModel *model,
icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list); icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
gtk_icon_view_queue_layout (icon_view);
verify_items (icon_view); verify_items (icon_view);
gtk_icon_view_queue_layout (icon_view);
if (emit) if (emit)
g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0); g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
} }
@ -3959,7 +3973,11 @@ gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
g_return_if_fail (row_align >= 0.0 && row_align <= 1.0); g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
g_return_if_fail (col_align >= 0.0 && col_align <= 1.0); g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
if (! GTK_WIDGET_REALIZED (icon_view)) if (gtk_tree_path_get_depth (path) > 0)
item = g_list_nth_data (icon_view->priv->items,
gtk_tree_path_get_indices(path)[0]);
if (!GTK_WIDGET_REALIZED (icon_view) || !item || item->width < 0)
{ {
if (icon_view->priv->scroll_to_path) if (icon_view->priv->scroll_to_path)
gtk_tree_row_reference_free (icon_view->priv->scroll_to_path); gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
@ -3976,13 +3994,6 @@ gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
return; return;
} }
if (gtk_tree_path_get_depth (path) > 0)
item = g_list_nth_data (icon_view->priv->items,
gtk_tree_path_get_indices(path)[0]);
if (!item)
return;
if (use_align) if (use_align)
{ {
gint x, y; gint x, y;
@ -4031,7 +4042,7 @@ gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
gdk_drawable_get_size (GDK_DRAWABLE (icon_view->priv->bin_window), gdk_drawable_get_size (GDK_DRAWABLE (icon_view->priv->bin_window),
&width, &height); &width, &height);
gdk_window_get_position (icon_view->priv->bin_window, &x, &y); gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
if (y + item->y - focus_width < 0) if (y + item->y - focus_width < 0)
gtk_adjustment_set_value (icon_view->priv->vadjustment, gtk_adjustment_set_value (icon_view->priv->vadjustment,
icon_view->priv->vadjustment->value + y + item->y - focus_width); icon_view->priv->vadjustment->value + y + item->y - focus_width);