From a2ac9e1baa85fbbf5c80bd5388a31301072d5f61 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 13 Jul 2014 12:31:28 -0400 Subject: [PATCH] listbox: Scroll headers on screen The listbox code relies on the container focus adjustment handling to scroll the cursor row on screen. But GtkContainer has no idea about row headers, so ensure that we scroll the header on screen too. --- gtk/gtklistbox.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/gtk/gtklistbox.c b/gtk/gtklistbox.c index 2958a3ad23..d3afac46b5 100644 --- a/gtk/gtklistbox.c +++ b/gtk/gtklistbox.c @@ -1326,11 +1326,32 @@ gtk_list_box_add_move_binding (GtkBindingSet *binding_set, NULL); } +static void +ensure_row_visible (GtkListBox *box, + GtkListBoxRow *row) +{ + GtkListBoxPrivate *priv = BOX_PRIV (box); + GtkWidget *header; + GtkWidget *widget; + GtkAllocation allocation; + + /* If the row has a header, we want to ensure that it is visible as well. */ + header = ROW_PRIV (row)->header; + if (GTK_IS_WIDGET (header) && gtk_widget_is_drawable (header)) + widget = header; + else + widget = GTK_WIDGET (row); + + gtk_widget_get_allocation (widget, &allocation); + gtk_adjustment_clamp_page (priv->adjustment, allocation.y, allocation.y + allocation.height); +} + static void gtk_list_box_update_cursor (GtkListBox *box, GtkListBoxRow *row) { BOX_PRIV (box)->cursor_row = row; + ensure_row_visible (box, row); gtk_widget_grab_focus (GTK_WIDGET (row)); gtk_widget_queue_draw (GTK_WIDGET (row)); _gtk_list_box_accessible_update_cursor (box, row); @@ -2682,7 +2703,8 @@ gtk_list_box_move_cursor (GtkListBox *box, case GTK_MOVEMENT_DISPLAY_LINES: if (priv->cursor_row != NULL) { - int i = count; + gint i = count; + iter = ROW_PRIV (priv->cursor_row)->iter; while (i < 0 && iter != NULL)