From 32a3690a3ca163b03d08644519958e57e4cde02f Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Tue, 27 Jun 2023 18:08:20 -0700 Subject: [PATCH] maplistmodel: implement GtkSectionModel This just wraps the underlying GListModel if it is a GtkSectionModel. --- gtk/gtkmaplistmodel.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/gtk/gtkmaplistmodel.c b/gtk/gtkmaplistmodel.c index 32ebf54801..dcbd398597 100644 --- a/gtk/gtkmaplistmodel.c +++ b/gtk/gtkmaplistmodel.c @@ -207,8 +207,33 @@ gtk_map_list_model_model_init (GListModelInterface *iface) iface->get_item = gtk_map_list_model_get_item; } +static void +gtk_map_list_model_get_section (GtkSectionModel *model, + guint position, + guint *out_start, + guint *out_end) +{ + GtkMapListModel *self = GTK_MAP_LIST_MODEL (model); + + if (GTK_IS_SECTION_MODEL (self->model)) + { + gtk_section_model_get_section (GTK_SECTION_MODEL (self->model), position, out_start, out_end); + return; + } + + *out_start = 0; + *out_end = self->model ? g_list_model_get_n_items (self->model) : 0; +} + +static void +gtk_map_list_model_section_model_init (GtkSectionModelInterface *iface) +{ + iface->get_section = gtk_map_list_model_get_section; +} + G_DEFINE_TYPE_WITH_CODE (GtkMapListModel, gtk_map_list_model, G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (G_TYPE_LIST_MODEL, gtk_map_list_model_model_init)) + G_IMPLEMENT_INTERFACE (G_TYPE_LIST_MODEL, gtk_map_list_model_model_init) + G_IMPLEMENT_INTERFACE (GTK_TYPE_SECTION_MODEL, gtk_map_list_model_section_model_init)) static void gtk_map_list_model_items_changed_cb (GListModel *model, -- 2.30.2