diff options
author | Timm Bäder <mail@baedert.org> | 2016-04-19 17:12:00 +0200 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2016-04-21 23:11:38 -0400 |
commit | 0815b21ad4e0d05367fc709765593c00997f33a3 (patch) | |
tree | bbe5e737045c050d26d2fe68518e19fdf51ced27 /gtk/gtklistbox.c | |
parent | 7a7e3fc0e3460c5f58b1ec1a35ecd66bc9409910 (diff) | |
download | gtk+-0815b21ad4e0d05367fc709765593c00997f33a3.tar.gz |
listbox: Make sure page down/up move at least one row
When the current cursor_row is taller than the page_size we get from the
GtkAdjustment, the previous code would not actually cause any scrolling,
so make sure we just take the row after or before the cursor_row in that
case.
https://bugzilla.gnome.org/show_bug.cgi?id=765261
Diffstat (limited to 'gtk/gtklistbox.c')
-rw-r--r-- | gtk/gtklistbox.c | 53 |
1 files changed, 17 insertions, 36 deletions
diff --git a/gtk/gtklistbox.c b/gtk/gtklistbox.c index 2ffa76802f..25be5931e3 100644 --- a/gtk/gtklistbox.c +++ b/gtk/gtklistbox.c @@ -2990,12 +2990,11 @@ gtk_list_box_move_cursor (GtkListBox *box, gboolean modify; gboolean extend; GtkListBoxRow *row; - GtkListBoxRow *prev; - GtkListBoxRow *next; gint page_size; GSequenceIter *iter; gint start_y; gint end_y; + int height; row = NULL; switch (step) @@ -3036,47 +3035,29 @@ gtk_list_box_move_cursor (GtkListBox *box, if (priv->cursor_row != NULL) { start_y = ROW_PRIV (priv->cursor_row)->y; - end_y = start_y; - iter = ROW_PRIV (priv->cursor_row)->iter; + height = gtk_widget_get_allocated_height (GTK_WIDGET (box)); + end_y = CLAMP (start_y + page_size * count, 0, height - 1); + row = gtk_list_box_get_row_at_y (box, end_y); + iter = ROW_PRIV (row)->iter; - row = priv->cursor_row; - if (count < 0) + if (row == priv->cursor_row) { - /* Up */ - while (iter != NULL && !g_sequence_iter_is_begin (iter)) - { - iter = gtk_list_box_get_previous_visible (box, iter); - if (iter == NULL) - break; - - prev = g_sequence_get (iter); - if (ROW_PRIV (prev)->y < start_y - page_size) - break; + /* Move at least one row. This is important when the cursor_row's height is + * greater than page_size */ + if (count < 0) + iter = g_sequence_iter_prev (iter); + else + iter = g_sequence_iter_next (iter); - row = prev; - } - } - else - { - /* Down */ - while (iter != NULL && !g_sequence_iter_is_end (iter)) + if (!g_sequence_iter_is_begin (iter) && !g_sequence_iter_is_end (iter)) { - iter = gtk_list_box_get_next_visible (box, iter); - if (g_sequence_iter_is_end (iter)) - break; - - next = g_sequence_get (iter); - if (ROW_PRIV (next)->y > start_y + page_size) - break; - - row = next; + row = g_sequence_get (iter); + end_y = ROW_PRIV (row)->y; } } - end_y = ROW_PRIV (row)->y; + if (end_y != start_y && priv->adjustment != NULL) - gtk_adjustment_animate_to_value (priv->adjustment, - gtk_adjustment_get_value (priv->adjustment) + - end_y - start_y); + gtk_adjustment_animate_to_value (priv->adjustment, end_y); } break; default: |