[gtk+/gtk-3-20] listbox: Select the last row on page down when there are few rows



commit 80063414ff7ec6c3bcb18ae579ddfd2234631256
Author: Joaquim Rocha <jrocha endlessm com>
Date:   Thu Sep 1 13:25:23 2016 +0200

    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

 gtk/gtklistbox.c |   42 +++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 41 insertions(+), 1 deletions(-)
---
diff --git a/gtk/gtklistbox.c b/gtk/gtklistbox.c
index bcccbcf..594cbbf 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;
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]