#include "gtkmultiselection.h"
#include "gtkbitset.h"
+#include "gtksectionmodelprivate.h"
#include "gtkselectionmodel.h"
/**
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)
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))
#include "gtknoselection.h"
#include "gtkbitset.h"
+#include "gtksectionmodelprivate.h"
#include "gtkselectionmodel.h"
/**
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)
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))
#include "config.h"
-#include "gtksectionmodel.h"
+#include "gtksectionmodelprivate.h"
#include "gtkmarshalers.h"
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 *self,
+ guint position,
+ guint *out_start,
+ guint *out_end)
+{
+ g_return_if_fail (out_start != NULL);
+ g_return_if_fail (out_end != NULL);
+
+ if (self == NULL)
+ {
+ *out_start = 0;
+ *out_end = G_MAXUINT;
+ return;
+ }
+
+ g_return_if_fail (G_IS_LIST_MODEL (self));
+
+ if (!GTK_IS_SECTION_MODEL (self))
+ {
+ guint n_items = g_list_model_get_n_items (self);
+
+ 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 (self), position, out_start, out_end);
+}
+
/**
* gtk_section_model_section_changed:
* @self: a `GtkSectionModel`
--- /dev/null
+#pragma once
+
+#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
+
#include "gtksingleselection.h"
#include "gtkbitset.h"
+#include "gtksectionmodelprivate.h"
#include "gtkselectionmodel.h"
/**
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)
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))