[gtk/stack-fixes: 11/12] single selection: Implement query_range



commit a716cf7c2fc70a76f7cd3118bb097cad8f504a03
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Feb 10 00:29:05 2019 -0500

    single selection: Implement query_range
    
    The implementation here splits the model into at most
    3 ranges: smaller than, equal to, and larger than the
    selected element.

 gtk/gtksingleselection.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
---
diff --git a/gtk/gtksingleselection.c b/gtk/gtksingleselection.c
index eb9f6bb667..c2a8ca5312 100644
--- a/gtk/gtksingleselection.c
+++ b/gtk/gtksingleselection.c
@@ -135,12 +135,46 @@ gtk_single_selection_unselect_item (GtkSelectionModel *model,
   return TRUE;
 }
 
+static gboolean
+gtk_single_selection_query_range (GtkSelectionModel *model,
+                                  guint             *position,
+                                  guint             *n_items)
+{
+  GtkSingleSelection *self = GTK_SINGLE_SELECTION (model);
+
+  if (self->selected == GTK_INVALID_LIST_POSITION)
+    {
+      *position = 0;
+      *n_items = g_list_model_get_n_items (self->model);
+      return FALSE;
+    }
+  else if (*position < self->selected)
+    {
+      *position = 0;
+      *n_items = self->selected;
+      return FALSE;
+    }
+  else if (*position > self->selected)
+    {
+      *position = self->selected + 1;
+      *n_items = g_list_model_get_n_items (self->model) - *position;
+      return FALSE;
+    }
+  else
+    {
+      *position = self->selected;
+      *n_items = 1;
+      return TRUE;
+    }
+}
+
 static void
 gtk_single_selection_selection_model_init (GtkSelectionModelInterface *iface)
 {
   iface->is_selected = gtk_single_selection_is_selected; 
   iface->select_item = gtk_single_selection_select_item; 
   iface->unselect_item = gtk_single_selection_unselect_item; 
+  iface->query_range = gtk_single_selection_query_range;
 }
 
 G_DEFINE_TYPE_EXTENDED (GtkSingleSelection, gtk_single_selection, G_TYPE_OBJECT, 0,


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