From: Christian Hergert Date: Wed, 28 Jun 2023 01:08:20 +0000 (-0700) Subject: maplistmodel: implement GtkSectionModel X-Git-Tag: archive/raspbian/4.12.3+ds-1+rpi1~1^2^2^2~22^2~1^2~82^2~2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=32a3690a3ca163b03d08644519958e57e4cde02f;p=gtk4.git maplistmodel: implement GtkSectionModel This just wraps the underlying GListModel if it is a GtkSectionModel. --- 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,