[gtk/stack-fixes] selection model: Add a method to query the selection
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/stack-fixes] selection model: Add a method to query the selection
- Date: Sun, 10 Feb 2019 05:30:32 +0000 (UTC)
commit 8ee9f817195906594809e4b8398991bffe0fa50f
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Feb 10 00:27:29 2019 -0500
selection model: Add a method to query the selection
The query_range method allows to iterate over ranges of
uniform selection. The default implementation always returns
single-element ranges, so is not any better than iterating
the elements one-by-one, but more efficient implementations
are possible.
gtk/gtkselectionmodel.c | 36 ++++++++++++++++++++++++++++++++++++
gtk/gtkselectionmodel.h | 7 +++++++
2 files changed, 43 insertions(+)
---
diff --git a/gtk/gtkselectionmodel.c b/gtk/gtkselectionmodel.c
index d004e3886d..cd4bbef35d 100644
--- a/gtk/gtkselectionmodel.c
+++ b/gtk/gtkselectionmodel.c
@@ -120,6 +120,15 @@ gtk_selection_model_default_unselect_all (GtkSelectionModel *model)
return gtk_selection_model_unselect_range (model, 0, g_list_model_get_n_items (G_LIST_MODEL (model)));;
}
+static gboolean
+gtk_selection_model_default_query_range (GtkSelectionModel *model,
+ guint *position,
+ guint *n_items)
+{
+ *n_items = 1;
+ return gtk_selection_model_is_selected (model, *position);
+}
+
static void
gtk_selection_model_default_init (GtkSelectionModelInterface *iface)
{
@@ -130,6 +139,7 @@ gtk_selection_model_default_init (GtkSelectionModelInterface *iface)
iface->unselect_range = gtk_selection_model_default_unselect_range;
iface->select_all = gtk_selection_model_default_select_all;
iface->unselect_all = gtk_selection_model_default_unselect_all;
+ iface->query_range = gtk_selection_model_default_query_range;
/**
* GtkSelectionModel::selection-changed
@@ -284,6 +294,32 @@ gtk_selection_model_get_model (GtkSelectionModel *model)
return child;
}
+/**
+ * gtk_selection_model_query_range:
+ * @model: a #GtkSelectionModel
+ * @position: (inout): specifies the position on input, and the first element of the range on output
+ * @n_items: (out): returns the size of the range
+ *
+ * This function allows to query the selection status of multiple elements at once.
+ * It is passed a position and returns a range of elements of uniform selection status.
+ * The returned range is guaranteed to include the passed-in position.
+ * The selection status is returned from this function.
+ *
+ * Returns: %TRUE if the elements in the returned range are selected, %FALSE otherwise
+ */
+gboolean
+gtk_selection_model_query_range (GtkSelectionModel *model,
+ guint *position,
+ guint *n_items)
+{
+ GtkSelectionModelInterface *iface;
+
+ g_return_val_if_fail (GTK_IS_SELECTION_MODEL (model), FALSE);
+
+ iface = GTK_SELECTION_MODEL_GET_IFACE (model);
+ return iface->query_range (model, position, n_items);
+}
+
void
gtk_selection_model_selection_changed (GtkSelectionModel *model,
guint position,
diff --git a/gtk/gtkselectionmodel.h b/gtk/gtkselectionmodel.h
index c3add80f0a..cd0175e398 100644
--- a/gtk/gtkselectionmodel.h
+++ b/gtk/gtkselectionmodel.h
@@ -79,6 +79,9 @@ struct _GtkSelectionModelInterface
guint n_items);
gboolean (* select_all) (GtkSelectionModel *model);
gboolean (* unselect_all) (GtkSelectionModel *model);
+ gboolean (* query_range) (GtkSelectionModel *model,
+ guint *position,
+ guint *n_items);
};
GDK_AVAILABLE_IN_ALL
@@ -108,6 +111,10 @@ gboolean gtk_selection_model_unselect_all (GtkSelectionMod
GDK_AVAILABLE_IN_ALL
GListModel * gtk_selection_model_get_model (GtkSelectionModel *model);
+GDK_AVAILABLE_IN_ALL
+gboolean gtk_selection_model_query_range (GtkSelectionModel *model,
+ guint *position,
+ guint *n_items);
/* for implementations only */
GDK_AVAILABLE_IN_ALL
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]