diff options
author | Joaquim Rocha <jrocha@endlessm.com> | 2016-09-01 13:25:23 +0200 |
---|---|---|
committer | Joaquim Rocha <jrocha@endlessm.com> | 2016-09-03 13:52:39 +0200 |
commit | f9658a2faf6929889be7d7042b3d8ee46456fb85 (patch) | |
tree | 9a790e9244f23a8c6b2ad451ee720bcc06166acd | |
parent | adabec7d2565ccd55940b3589e00407bcbf439a9 (diff) | |
download | gtk+-f9658a2faf6929889be7d7042b3d8ee46456fb85.tar.gz |
listbox: Select the last row on page down when there are few rows
When pressing page down doesn't retrieve a valid row (because the list
box has few rows), the last visible one should be selected instead.
https://bugzilla.gnome.org/show_bug.cgi?id=770703
-rw-r--r-- | gtk/gtklistbox.c | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/gtk/gtklistbox.c b/gtk/gtklistbox.c index d86c2908cd..3adb904b53 100644 --- a/gtk/gtklistbox.c +++ b/gtk/gtklistbox.c @@ -2323,6 +2323,27 @@ gtk_list_box_get_next_visible (GtkListBox *box, return iter; } +static GSequenceIter * +gtk_list_box_get_last_visible (GtkListBox *box, + GSequenceIter *iter) +{ + GSequenceIter *next = NULL; + + if (g_sequence_iter_is_end (iter)) + return NULL; + + do + { + next = gtk_list_box_get_next_visible (box, iter); + + if (!g_sequence_iter_is_end (next)) + iter = next; + } + while (!g_sequence_iter_is_end (next)); + + return iter; +} + static void gtk_list_box_update_header (GtkListBox *box, GSequenceIter *iter) @@ -3042,7 +3063,26 @@ gtk_list_box_move_cursor (GtkListBox *box, end_y = CLAMP (start_y + page_size * count, 0, height - 1); row = gtk_list_box_get_row_at_y (box, end_y); - if (row == priv->cursor_row) + if (!row) + { + GSequenceIter *cursor_iter; + GSequenceIter *next_iter; + + /* A NULL row should only happen when the list box didn't + * have enough rows to fill its height and the user made + * a page movement down, so the count must be positive */ + g_assert (count > 0); + + cursor_iter = ROW_PRIV (priv->cursor_row)->iter; + next_iter = gtk_list_box_get_last_visible (box, cursor_iter); + + if (next_iter) + { + row = g_sequence_get (next_iter); + end_y = ROW_PRIV (row)->y; + } + } + else if (row == priv->cursor_row) { iter = ROW_PRIV (row)->iter; |