[gtk/wip/otte/listview: 14/23] Implement GtkSectionModel for all selection models
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/listview: 14/23] Implement GtkSectionModel for all selection models
- Date: Sat, 26 Feb 2022 03:03:23 +0000 (UTC)
commit 7827676005747a68661df1afda384bdb5ccaaf3a
Author: Benjamin Otte <otte redhat com>
Date: Tue Feb 15 02:03:00 2022 +0100
Implement GtkSectionModel for all selection models
gtk/gtkmultiselection.c | 20 ++++++++++++++++++++
gtk/gtknoselection.c | 20 ++++++++++++++++++++
gtk/gtksectionmodel.c | 45 +++++++++++++++++++++++++++++++++++++++++++-
gtk/gtksectionmodelprivate.h | 16 ++++++++++++++++
gtk/gtksingleselection.c | 20 ++++++++++++++++++++
5 files changed, 120 insertions(+), 1 deletion(-)
---
diff --git a/gtk/gtkmultiselection.c b/gtk/gtkmultiselection.c
index bee83622c6..f2f30514b3 100644
--- a/gtk/gtkmultiselection.c
+++ b/gtk/gtkmultiselection.c
@@ -23,6 +23,7 @@
#include "gtkbitset.h"
#include "gtkintl.h"
+#include "gtksectionmodelprivate.h"
#include "gtkselectionmodel.h"
/**
@@ -93,6 +94,23 @@ gtk_multi_selection_list_model_init (GListModelInterface *iface)
iface->get_item = gtk_multi_selection_get_item;
}
+static void
+gtk_multi_selection_get_section (GtkSectionModel *model,
+ guint position,
+ guint *out_start,
+ guint *out_end)
+{
+ GtkMultiSelection *self = GTK_MULTI_SELECTION (model);
+
+ gtk_list_model_get_section (self->model, position, out_start, out_end);
+}
+
+static void
+gtk_multi_selection_section_model_init (GtkSectionModelInterface *iface)
+{
+ iface->get_section = gtk_multi_selection_get_section;
+}
+
static gboolean
gtk_multi_selection_is_selected (GtkSelectionModel *model,
guint position)
@@ -204,6 +222,8 @@ gtk_multi_selection_selection_model_init (GtkSelectionModelInterface *iface)
G_DEFINE_TYPE_EXTENDED (GtkMultiSelection, gtk_multi_selection, G_TYPE_OBJECT, 0,
G_IMPLEMENT_INTERFACE (G_TYPE_LIST_MODEL,
gtk_multi_selection_list_model_init)
+ G_IMPLEMENT_INTERFACE (GTK_TYPE_SECTION_MODEL,
+ gtk_multi_selection_section_model_init)
G_IMPLEMENT_INTERFACE (GTK_TYPE_SELECTION_MODEL,
gtk_multi_selection_selection_model_init))
diff --git a/gtk/gtknoselection.c b/gtk/gtknoselection.c
index 9b48082d6a..0ba7ce272b 100644
--- a/gtk/gtknoselection.c
+++ b/gtk/gtknoselection.c
@@ -23,6 +23,7 @@
#include "gtkbitset.h"
#include "gtkintl.h"
+#include "gtksectionmodelprivate.h"
#include "gtkselectionmodel.h"
/**
@@ -91,6 +92,23 @@ gtk_no_selection_list_model_init (GListModelInterface *iface)
iface->get_item = gtk_no_selection_get_item;
}
+static void
+gtk_no_selection_get_section (GtkSectionModel *model,
+ guint position,
+ guint *out_start,
+ guint *out_end)
+{
+ GtkNoSelection *self = GTK_NO_SELECTION (model);
+
+ gtk_list_model_get_section (self->model, position, out_start, out_end);
+}
+
+static void
+gtk_no_selection_section_model_init (GtkSectionModelInterface *iface)
+{
+ iface->get_section = gtk_no_selection_get_section;
+}
+
static gboolean
gtk_no_selection_is_selected (GtkSelectionModel *model,
guint position)
@@ -116,6 +134,8 @@ gtk_no_selection_selection_model_init (GtkSelectionModelInterface *iface)
G_DEFINE_TYPE_EXTENDED (GtkNoSelection, gtk_no_selection, G_TYPE_OBJECT, 0,
G_IMPLEMENT_INTERFACE (G_TYPE_LIST_MODEL,
gtk_no_selection_list_model_init)
+ G_IMPLEMENT_INTERFACE (GTK_TYPE_SECTION_MODEL,
+ gtk_no_selection_section_model_init)
G_IMPLEMENT_INTERFACE (GTK_TYPE_SELECTION_MODEL,
gtk_no_selection_selection_model_init))
diff --git a/gtk/gtksectionmodel.c b/gtk/gtksectionmodel.c
index e9bb11c68f..a19bcce491 100644
--- a/gtk/gtksectionmodel.c
+++ b/gtk/gtksectionmodel.c
@@ -19,7 +19,7 @@
#include "config.h"
-#include "gtksectionmodel.h"
+#include "gtksectionmodelprivate.h"
#include "gtkintl.h"
#include "gtkmarshalers.h"
@@ -147,6 +147,49 @@ gtk_section_model_get_section (GtkSectionModel *model,
g_warn_if_fail (*out_start < *out_end);
}
+/* A version of gtk_section_model_get_section() that handles NULL
+ * (treats it as the empty list) and any GListModel (treats it as
+ * a single section).
+ **/
+void
+gtk_list_model_get_section (GListModel *model,
+ guint position,
+ guint *out_start,
+ guint *out_end)
+{
+ g_return_if_fail (out_start != NULL);
+ g_return_if_fail (out_end != NULL);
+
+ if (model == NULL)
+ {
+ *out_start = 0;
+ *out_end = G_MAXUINT;
+ return;
+ }
+
+ g_return_if_fail (G_IS_LIST_MODEL (model));
+
+ if (!GTK_IS_SECTION_MODEL (model))
+ {
+ guint n_items = g_list_model_get_n_items (model);
+
+ if (position < n_items)
+ {
+ *out_start = 0;
+ *out_end = G_MAXUINT;
+ }
+ else
+ {
+ *out_start = n_items;
+ *out_end = G_MAXUINT;
+ }
+
+ return;
+ }
+
+ gtk_section_model_get_section (GTK_SECTION_MODEL (model), position, out_start, out_end);
+}
+
/**
* gtk_section_model_section_changed:
* @model: a `GtkSectionModel`
diff --git a/gtk/gtksectionmodelprivate.h b/gtk/gtksectionmodelprivate.h
new file mode 100644
index 0000000000..c5185a2852
--- /dev/null
+++ b/gtk/gtksectionmodelprivate.h
@@ -0,0 +1,16 @@
+#ifndef __GTK_SECTION_MODEL_PRIVATE_H__
+#define __GTK_SECTION_MODEL_PRIVATE_H__
+
+#include "gtksectionmodel.h"
+
+G_BEGIN_DECLS
+
+void gtk_list_model_get_section (GListModel *self,
+ guint position,
+ guint *out_start,
+ guint *out_end);
+
+
+G_END_DECLS
+
+#endif /* __GTK_SECTION_MODEL_PRIVATE_H__ */
diff --git a/gtk/gtksingleselection.c b/gtk/gtksingleselection.c
index 7b01cb6f19..aedf0c92c8 100644
--- a/gtk/gtksingleselection.c
+++ b/gtk/gtksingleselection.c
@@ -23,6 +23,7 @@
#include "gtkbitset.h"
#include "gtkintl.h"
+#include "gtksectionmodelprivate.h"
#include "gtkselectionmodel.h"
/**
@@ -102,6 +103,23 @@ gtk_single_selection_list_model_init (GListModelInterface *iface)
iface->get_item = gtk_single_selection_get_item;
}
+static void
+gtk_single_selection_get_section (GtkSectionModel *model,
+ guint position,
+ guint *out_start,
+ guint *out_end)
+{
+ GtkSingleSelection *self = GTK_SINGLE_SELECTION (model);
+
+ gtk_list_model_get_section (self->model, position, out_start, out_end);
+}
+
+static void
+gtk_single_selection_section_model_init (GtkSectionModelInterface *iface)
+{
+ iface->get_section = gtk_single_selection_get_section;
+}
+
static gboolean
gtk_single_selection_is_selected (GtkSelectionModel *model,
guint position)
@@ -166,6 +184,8 @@ gtk_single_selection_selection_model_init (GtkSelectionModelInterface *iface)
G_DEFINE_TYPE_EXTENDED (GtkSingleSelection, gtk_single_selection, G_TYPE_OBJECT, 0,
G_IMPLEMENT_INTERFACE (G_TYPE_LIST_MODEL,
gtk_single_selection_list_model_init)
+ G_IMPLEMENT_INTERFACE (GTK_TYPE_SECTION_MODEL,
+ gtk_single_selection_section_model_init)
G_IMPLEMENT_INTERFACE (GTK_TYPE_SELECTION_MODEL,
gtk_single_selection_selection_model_init))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]