#include "gtkflattenlistmodel.h"
+#include "gtksectionmodel.h"
#include "gtkrbtreeprivate.h"
-#include "gtkprivate.h"
/**
* GtkFlattenListModel:
iface->get_item = gtk_flatten_list_model_get_item;
}
+static void
+gtk_flatten_list_model_get_section (GtkSectionModel *model,
+ guint position,
+ guint *out_start,
+ guint *out_end)
+{
+ GtkFlattenListModel *self = GTK_FLATTEN_LIST_MODEL (model);
+ FlattenNode *node;
+ guint model_pos;
+
+ node = gtk_flatten_list_model_get_nth (self->items, position, &model_pos);
+ if (node == NULL)
+ {
+ *out_start = gtk_flatten_list_model_get_n_items (G_LIST_MODEL (self));
+ *out_end = G_MAXUINT;
+ return;
+ }
+
+ *out_start = position - model_pos;
+ *out_end = position - model_pos + g_list_model_get_n_items (node->model);
+}
+
+static void
+gtk_flatten_list_model_section_model_init (GtkSectionModelInterface *iface)
+{
+ iface->get_section = gtk_flatten_list_model_get_section;
+}
+
G_DEFINE_TYPE_WITH_CODE (GtkFlattenListModel, gtk_flatten_list_model, G_TYPE_OBJECT,
- G_IMPLEMENT_INTERFACE (G_TYPE_LIST_MODEL, gtk_flatten_list_model_model_init))
+ G_IMPLEMENT_INTERFACE (G_TYPE_LIST_MODEL,
+ gtk_flatten_list_model_model_init)
+ G_IMPLEMENT_INTERFACE (GTK_TYPE_SECTION_MODEL,
+ gtk_flatten_list_model_section_model_init))
static void
gtk_flatten_list_model_items_changed_cb (GListModel *model,
properties[PROP_MODEL] =
g_param_spec_object ("model", NULL, NULL,
G_TYPE_LIST_MODEL,
- GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
/**
* GtkFlattenListModel:n-items:
* model, though it would be rather useless to emit such a signal.
*
* The [signal@Gio.ListModel::items-changed] implies the effect of the
- * [signal@Gtk.SectionModel::section-changed] signal for all the items
+ * [signal@Gtk.SectionModel::sections-changed] signal for all the items
* it covers.
*
* Since: 4.12