From d0ef5f5db40128e9d36f73ecc92e8027a43fad16 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sat, 5 Jan 2019 22:38:23 -0500 Subject: [PATCH] selection: Make the model an interface property This is in line with what we do for other wrapper models. --- gtk/gtkmultiselection.c | 18 ++++-------------- gtk/gtknoselection.c | 18 ++++-------------- gtk/gtkselectionmodel.c | 24 ++++++++++++++++++++++++ gtk/gtkselectionmodel.h | 3 +++ gtk/gtksingleselection.c | 19 +++++-------------- 5 files changed, 40 insertions(+), 42 deletions(-) diff --git a/gtk/gtkmultiselection.c b/gtk/gtkmultiselection.c index b4db84d1b5..586d8753f8 100644 --- a/gtk/gtkmultiselection.c +++ b/gtk/gtkmultiselection.c @@ -53,9 +53,11 @@ struct _GtkMultiSelectionClass enum { PROP_0, + + /* selectionmodel */ PROP_MODEL, - N_PROPS, + N_PROPS = PROP_MODEL }; static GParamSpec *properties[N_PROPS] = { NULL, }; @@ -287,19 +289,7 @@ gtk_multi_selection_class_init (GtkMultiSelectionClass *klass) gobject_class->set_property = gtk_multi_selection_set_property; gobject_class->dispose = gtk_multi_selection_dispose; - /** - * GtkMultiSelection:model - * - * The list managed by this selection - */ - properties[PROP_MODEL] = - g_param_spec_object ("model", - P_("Model"), - P_("List managed by this selection"), - G_TYPE_LIST_MODEL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS); - - g_object_class_install_properties (gobject_class, N_PROPS, properties); + g_object_class_override_property (gobject_class, PROP_MODEL, "model"); } static void diff --git a/gtk/gtknoselection.c b/gtk/gtknoselection.c index adfdb7737b..7eaee46301 100644 --- a/gtk/gtknoselection.c +++ b/gtk/gtknoselection.c @@ -48,9 +48,11 @@ struct _GtkNoSelectionClass enum { PROP_0, + + /* selectionmodel */ PROP_MODEL, - N_PROPS, + N_PROPS = PROP_MODEL }; static GParamSpec *properties[N_PROPS] = { NULL, }; @@ -177,19 +179,7 @@ gtk_no_selection_class_init (GtkNoSelectionClass *klass) gobject_class->set_property = gtk_no_selection_set_property; gobject_class->dispose = gtk_no_selection_dispose; - /** - * GtkNoSelection:model - * - * The list managed by this selection - */ - properties[PROP_MODEL] = - g_param_spec_object ("model", - P_("Model"), - P_("List managed by this selection"), - G_TYPE_LIST_MODEL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS); - - g_object_class_install_properties (gobject_class, N_PROPS, properties); + g_object_class_override_property (gobject_class, PROP_MODEL, "model"); } static void diff --git a/gtk/gtkselectionmodel.c b/gtk/gtkselectionmodel.c index 2e026984f1..dee60149bb 100644 --- a/gtk/gtkselectionmodel.c +++ b/gtk/gtkselectionmodel.c @@ -21,6 +21,7 @@ #include "gtkselectionmodel.h" +#include "gtkintl.h" #include "gtkmarshalers.h" /** @@ -156,6 +157,17 @@ gtk_selection_model_default_init (GtkSelectionModelInterface *iface) g_signal_set_va_marshaller (signals[SELECTION_CHANGED], GTK_TYPE_SELECTION_MODEL, _gtk_marshal_VOID__UINT_UINTv); + + g_object_interface_install_property (iface, + g_param_spec_object ("model", + P_("Model"), + P_("List managed by this selection"), + G_TYPE_LIST_MODEL, + G_PARAM_READWRITE + | G_PARAM_CONSTRUCT_ONLY + | G_PARAM_EXPLICIT_NOTIFY + | G_PARAM_STATIC_STRINGS)); + } /** @@ -254,6 +266,18 @@ gtk_selection_model_unselect_all (GtkSelectionModel *model) return iface->unselect_all (model); } +GListModel * +gtk_selection_model_get_model (GtkSelectionModel *model) +{ + GListModel *child; + + g_object_get (model, "model", &child, NULL); + if (child) + g_object_unref (child); + + return child; +} + void gtk_selection_model_selection_changed (GtkSelectionModel *model, guint position, diff --git a/gtk/gtkselectionmodel.h b/gtk/gtkselectionmodel.h index f4e5a1eca5..53e39e5362 100644 --- a/gtk/gtkselectionmodel.h +++ b/gtk/gtkselectionmodel.h @@ -108,6 +108,9 @@ gboolean gtk_selection_model_select_all (GtkSelectionMod GDK_AVAILABLE_IN_ALL gboolean gtk_selection_model_unselect_all (GtkSelectionModel *model); +GDK_AVAILABLE_IN_ALL +GListModel * gtk_selection_model_get_model (GtkSelectionModel *model); + /* for implementations only */ GDK_AVAILABLE_IN_ALL void gtk_selection_model_selection_changed (GtkSelectionModel *model, diff --git a/gtk/gtksingleselection.c b/gtk/gtksingleselection.c index 8141bb7f82..877ccba678 100644 --- a/gtk/gtksingleselection.c +++ b/gtk/gtksingleselection.c @@ -55,10 +55,11 @@ enum { PROP_0, PROP_AUTOSELECT, PROP_CAN_UNSELECT, - PROP_MODEL, PROP_SELECTED, - N_PROPS, + /* selectionmodel */ + PROP_MODEL, + N_PROPS = PROP_MODEL }; static GParamSpec *properties[N_PROPS] = { NULL, }; @@ -337,6 +338,8 @@ gtk_single_selection_class_init (GtkSingleSelectionClass *klass) gobject_class->set_property = gtk_single_selection_set_property; gobject_class->dispose = gtk_single_selection_dispose; + g_object_class_override_property (gobject_class, PROP_MODEL, "model"); + /** * GtkSingleSelection:autoselect * @@ -361,18 +364,6 @@ gtk_single_selection_class_init (GtkSingleSelectionClass *klass) FALSE, G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS); - /** - * GtkSingleSelection:model - * - * The list managed by this selection - */ - properties[PROP_MODEL] = - g_param_spec_object ("model", - P_("Model"), - P_("List managed by this selection"), - G_TYPE_LIST_MODEL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS); - /** * GtkSingleSelection:selected *