diff --git a/demos/gtk-demo/listview_colors.c b/demos/gtk-demo/listview_colors.c index 94210bf9ce..a1533b8432 100644 --- a/demos/gtk-demo/listview_colors.c +++ b/demos/gtk-demo/listview_colors.c @@ -884,7 +884,7 @@ do_listview_colors (GtkWidget *do_widget) sort_model = gtk_sort_list_model_new (gtk_color_list_new (0), NULL); gtk_sort_list_model_set_incremental (sort_model, TRUE); - selection = GTK_MULTI_SELECTION (gtk_multi_selection_new (G_LIST_MODEL (sort_model))); + selection = gtk_multi_selection_new (G_LIST_MODEL (sort_model)); window = gtk_window_new (); gtk_window_set_title (GTK_WINDOW (window), "Colors"); diff --git a/gtk/gtkmultiselection.c b/gtk/gtkmultiselection.c index 6c754f77a8..c6e3474cb9 100644 --- a/gtk/gtkmultiselection.c +++ b/gtk/gtkmultiselection.c @@ -370,20 +370,27 @@ gtk_multi_selection_init (GtkMultiSelection *self) /** * gtk_multi_selection_new: - * @model: (transfer none): the #GListModel to manage + * @model: (allow-none) (transfer full): the #GListModel to manage, or %NULL * * Creates a new selection to handle @model. * - * Returns: (transfer full) (type GtkMultiSelection): a new #GtkMultiSelection + * Returns: (transfer full): a new #GtkMultiSelection **/ -GListModel * +GtkMultiSelection * gtk_multi_selection_new (GListModel *model) { + GtkMultiSelection *self; + g_return_val_if_fail (G_IS_LIST_MODEL (model), NULL); - return g_object_new (GTK_TYPE_MULTI_SELECTION, + self = g_object_new (GTK_TYPE_MULTI_SELECTION, "model", model, NULL); + + /* consume the reference */ + g_clear_object (&model); + + return self; } /** diff --git a/gtk/gtkmultiselection.h b/gtk/gtkmultiselection.h index 69c8a69028..b8e0300ed1 100644 --- a/gtk/gtkmultiselection.h +++ b/gtk/gtkmultiselection.h @@ -31,13 +31,13 @@ GDK_AVAILABLE_IN_ALL G_DECLARE_FINAL_TYPE (GtkMultiSelection, gtk_multi_selection, GTK, MULTI_SELECTION, GObject) GDK_AVAILABLE_IN_ALL -GListModel * gtk_multi_selection_new (GListModel *model); +GtkMultiSelection * gtk_multi_selection_new (GListModel *model); GDK_AVAILABLE_IN_ALL -GListModel * gtk_multi_selection_get_model (GtkMultiSelection *self); +GListModel * gtk_multi_selection_get_model (GtkMultiSelection *self); GDK_AVAILABLE_IN_ALL -void gtk_multi_selection_set_model (GtkMultiSelection *self, - GListModel *model); +void gtk_multi_selection_set_model (GtkMultiSelection *self, + GListModel *model); G_END_DECLS diff --git a/testsuite/gtk/multiselection.c b/testsuite/gtk/multiselection.c index 3e3fa39c77..2c23168d07 100644 --- a/testsuite/gtk/multiselection.c +++ b/testsuite/gtk/multiselection.c @@ -253,7 +253,7 @@ new_model (GListStore *store) GtkSelectionModel *result; GString *changes; - result = GTK_SELECTION_MODEL (gtk_multi_selection_new (G_LIST_MODEL (store))); + result = GTK_SELECTION_MODEL (gtk_multi_selection_new (g_object_ref (G_LIST_MODEL (store)))); changes = g_string_new (""); g_object_set_qdata_full (G_OBJECT(result), changes_quark, changes, free_changes);