[gtk/view-model-selection] Change list widget to use a GtkSelectionModel



commit 489146cd906adf4bf687262f108b3902f61ae1aa
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Jul 16 16:16:02 2020 -0400

    Change list widget to use a GtkSelectionModel
    
    Change the type of the model property in GtkListView,
    GtkColumnView and GtkGridView to be GtkSelectionModel.
    
    The convenience of automatic interposition of a selection
    model is minor, compared to the confusion.
    
    Update all callers.

 demos/gtk-demo/listview_applauncher.c |  5 ++++-
 demos/gtk-demo/listview_clocks.c      |  2 +-
 demos/gtk-demo/listview_colors.c      | 13 +++++++------
 demos/gtk-demo/listview_settings.c    |  6 +++---
 demos/gtk-demo/listview_weather.c     |  5 +++--
 demos/gtk-demo/listview_words.c       |  6 +++---
 demos/gtk-demo/main.c                 | 12 ++++++------
 gtk/gtkcolumnview.c                   | 15 ++++++---------
 gtk/gtkcolumnview.h                   |  5 +++--
 gtk/gtkcustompaperunixdialog.c        | 16 ++++++++--------
 gtk/gtkdropdown.c                     |  2 +-
 gtk/gtkgridview.c                     | 12 ++++++------
 gtk/gtkgridview.h                     |  5 +++--
 gtk/gtklistbase.c                     | 24 +++++++-----------------
 gtk/gtklistbaseprivate.h              |  5 +++--
 gtk/gtklistview.c                     | 20 +++++++++-----------
 gtk/gtklistview.h                     |  5 +++--
 gtk/gtkprintunixdialog.c              | 24 +++++++++++++-----------
 gtk/inspector/actions.c               |  4 ++--
 gtk/inspector/list-data.c             |  2 +-
 gtk/inspector/prop-list.c             |  8 ++++----
 gtk/inspector/recorder.c              |  2 +-
 gtk/inspector/resource-list.c         |  2 +-
 23 files changed, 98 insertions(+), 102 deletions(-)
---
diff --git a/demos/gtk-demo/listview_applauncher.c b/demos/gtk-demo/listview_applauncher.c
index a6eb2f9863..5b5a507e3d 100644
--- a/demos/gtk-demo/listview_applauncher.c
+++ b/demos/gtk-demo/listview_applauncher.c
@@ -144,6 +144,7 @@ do_listview_applauncher (GtkWidget *do_widget)
     {
       GtkWidget *list, *sw;
       GListModel *model;
+      GtkSelectionModel *selection;
       GtkListItemFactory *factory;
 
       /* Create a window and set a few defaults */
@@ -181,8 +182,10 @@ do_listview_applauncher (GtkWidget *do_widget)
        * to create as many listitems as it needs to show itself to the user.
        */
       model = create_application_list ();
-      gtk_list_view_set_model (GTK_LIST_VIEW (list), model);
+      selection = GTK_SELECTION_MODEL (gtk_single_selection_new (model));
+      gtk_list_view_set_model (GTK_LIST_VIEW (list), selection);
       g_object_unref (model);
+      g_object_unref (selection);
 
       /* List widgets should always be contained in a #GtkScrolledWindow,
        * because otherwise they might get too large or they might not
diff --git a/demos/gtk-demo/listview_clocks.c b/demos/gtk-demo/listview_clocks.c
index 4578c229cd..9d5b8d9f0b 100644
--- a/demos/gtk-demo/listview_clocks.c
+++ b/demos/gtk-demo/listview_clocks.c
@@ -491,7 +491,7 @@ do_listview_clocks (GtkWidget *do_widget)
 
       model = create_clocks_model ();
       selection = gtk_no_selection_new (model);
-      gtk_grid_view_set_model (GTK_GRID_VIEW (gridview), G_LIST_MODEL (selection));
+      gtk_grid_view_set_model (GTK_GRID_VIEW (gridview), GTK_SELECTION_MODEL (selection));
       gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), gridview);
       g_object_unref (selection);
       g_object_unref (model);
diff --git a/demos/gtk-demo/listview_colors.c b/demos/gtk-demo/listview_colors.c
index af20292f4a..85e440213b 100644
--- a/demos/gtk-demo/listview_colors.c
+++ b/demos/gtk-demo/listview_colors.c
@@ -662,7 +662,8 @@ create_color_grid (void)
 {
   GtkWidget *gridview;
   GtkListItemFactory *factory;
-  GListModel *model, *selection;
+  GListModel *model;
+  GtkSelectionModel *selection;
 
   gridview = gtk_grid_view_new ();
   gtk_scrollable_set_hscroll_policy (GTK_SCROLLABLE (gridview), GTK_SCROLL_NATURAL);
@@ -678,7 +679,7 @@ create_color_grid (void)
 
   model = G_LIST_MODEL (gtk_sort_list_model_new (gtk_color_list_new (0), NULL));
 
-  selection = G_LIST_MODEL (gtk_multi_selection_new (model));
+  selection = GTK_SELECTION_MODEL (gtk_multi_selection_new (model));
   gtk_grid_view_set_model (GTK_GRID_VIEW (gridview), selection);
   g_object_unref (selection);
   g_object_unref (model);
@@ -857,7 +858,7 @@ do_listview_colors (GtkWidget *do_widget)
       guint len;
       GtkWidget *selection_view;
       GListModel *selection_filter;
-      GListModel *no_selection;
+      GtkSelectionModel *selection;
       GtkWidget *grid;
       GtkWidget *selection_size_label;
       GtkWidget *selection_average_picture;
@@ -945,10 +946,10 @@ do_listview_colors (GtkWidget *do_widget)
       g_signal_connect (selection_filter, "items-changed", G_CALLBACK (update_selection_count), 
selection_size_label);
       g_signal_connect (selection_filter, "items-changed", G_CALLBACK (update_selection_average), 
selection_average_picture);
 
-      no_selection = G_LIST_MODEL (gtk_no_selection_new (selection_filter));
-      gtk_grid_view_set_model (GTK_GRID_VIEW (selection_view), no_selection);
+      selection = GTK_SELECTION_MODEL (gtk_no_selection_new (selection_filter));
+      gtk_grid_view_set_model (GTK_GRID_VIEW (selection_view), selection);
       g_object_unref (selection_filter);
-      g_object_unref (no_selection);
+      g_object_unref (selection);
 
       model = gtk_multi_selection_get_model (GTK_MULTI_SELECTION (model));
       g_object_ref (model);
diff --git a/demos/gtk-demo/listview_settings.c b/demos/gtk-demo/listview_settings.c
index 7dc55ada2f..4a5906fe41 100644
--- a/demos/gtk-demo/listview_settings.c
+++ b/demos/gtk-demo/listview_settings.c
@@ -345,7 +345,7 @@ do_listview_settings (GtkWidget *do_widget)
       GtkWidget *listview, *columnview;
       GListModel *model;
       GtkTreeListModel *treemodel;
-      GtkSingleSelection *selection;
+      GtkSelectionModel *selection;
       GtkBuilderScope *scope;
       GtkBuilder *builder;
       GtkColumnViewColumn *name_column;
@@ -409,14 +409,14 @@ do_listview_settings (GtkWidget *do_widget)
                                            create_settings_model,
                                            NULL,
                                            NULL);
-      selection = gtk_single_selection_new (G_LIST_MODEL (treemodel));
+      selection = GTK_SELECTION_MODEL (gtk_single_selection_new (G_LIST_MODEL (treemodel)));
       g_object_bind_property_full (selection, "selected-item",
                                    columnview, "model",
                                    G_BINDING_SYNC_CREATE,
                                    transform_settings_to_keys,
                                    NULL,
                                    columnview, NULL);
-      gtk_list_view_set_model (GTK_LIST_VIEW (listview), G_LIST_MODEL (selection));
+      gtk_list_view_set_model (GTK_LIST_VIEW (listview), selection);
       g_object_unref (selection);
       g_object_unref (treemodel);
       g_object_unref (model);
diff --git a/demos/gtk-demo/listview_weather.c b/demos/gtk-demo/listview_weather.c
index 535a9d179b..cfeb7c86a7 100644
--- a/demos/gtk-demo/listview_weather.c
+++ b/demos/gtk-demo/listview_weather.c
@@ -281,7 +281,8 @@ GtkWidget *
 create_weather_view (void)
 {
   GtkWidget *listview;
-  GListModel *model, *selection;
+  GListModel *model;
+  GtkSelectionModel *selection;
   GtkListItemFactory *factory;
 
   factory = gtk_signal_list_item_factory_new ();
@@ -291,7 +292,7 @@ create_weather_view (void)
   gtk_orientable_set_orientation (GTK_ORIENTABLE (listview), GTK_ORIENTATION_HORIZONTAL);
   gtk_list_view_set_show_separators (GTK_LIST_VIEW (listview), TRUE);
   model = create_weather_model ();
-  selection = G_LIST_MODEL (gtk_no_selection_new (model));
+  selection = GTK_SELECTION_MODEL (gtk_no_selection_new (model));
   gtk_list_view_set_model (GTK_LIST_VIEW (listview), selection);
   g_object_unref (selection);
   g_object_unref (model);
diff --git a/demos/gtk-demo/listview_words.c b/demos/gtk-demo/listview_words.c
index 95664ed279..f40bb54ae4 100644
--- a/demos/gtk-demo/listview_words.c
+++ b/demos/gtk-demo/listview_words.c
@@ -157,7 +157,7 @@ do_listview_words (GtkWidget *do_widget)
     {
       GtkWidget *header, *listview, *sw, *vbox, *search_entry, *open_button, *overlay;
       GtkFilterListModel *filter_model;
-      GtkNoSelection *selection;
+      GtkSelectionModel *selection;
       GtkStringList *stringlist;
       GtkFilter *filter;
       GFile *file;
@@ -218,8 +218,8 @@ do_listview_words (GtkWidget *do_widget)
           gtk_builder_list_item_factory_new_from_bytes (NULL,
               g_bytes_new_static (factory_text, strlen (factory_text))));
       gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), listview);
-      selection = gtk_no_selection_new (G_LIST_MODEL (filter_model));
-      gtk_list_view_set_model (GTK_LIST_VIEW (listview), G_LIST_MODEL (selection));
+      selection = GTK_SELECTION_MODEL (gtk_no_selection_new (G_LIST_MODEL (filter_model)));
+      gtk_list_view_set_model (GTK_LIST_VIEW (listview), selection);
       g_object_unref (selection);
 
       g_signal_connect (filter_model, "items-changed", G_CALLBACK (update_title_cb), progress);
diff --git a/demos/gtk-demo/main.c b/demos/gtk-demo/main.c
index 0e3283aaa8..76085c9b7f 100644
--- a/demos/gtk-demo/main.c
+++ b/demos/gtk-demo/main.c
@@ -16,7 +16,7 @@ static GtkWidget *source_view;
 static gchar *current_file = NULL;
 
 static GtkWidget *notebook;
-static GtkSingleSelection *selection;
+static GtkSelectionModel *selection;
 static GtkWidget *toplevel;
 static char **search_needle;
 
@@ -220,7 +220,7 @@ activate_run (GSimpleAction *action,
               GVariant      *parameter,
               gpointer       window)
 {
-  GtkTreeListRow *row = gtk_single_selection_get_selected_item (selection);
+  GtkTreeListRow *row = gtk_single_selection_get_selected_item (GTK_SINGLE_SELECTION (selection));
   GtkDemo *demo = gtk_tree_list_row_get_item (row);
 
   gtk_demo_run (demo, window);
@@ -932,7 +932,7 @@ activate_cb (GtkWidget *widget,
              guint      position,
              gpointer   window)
 {
-  GtkTreeListRow *row = g_list_model_get_item (gtk_list_view_get_model (GTK_LIST_VIEW (widget)), position);
+  GtkTreeListRow *row = g_list_model_get_item (G_LIST_MODEL (gtk_list_view_get_model (GTK_LIST_VIEW 
(widget))), position);
   GtkDemo *demo = gtk_tree_list_row_get_item (row);
 
   gtk_demo_run (demo, window);
@@ -1152,11 +1152,11 @@ activate (GApplication *app)
   search_entry = GTK_WIDGET (gtk_builder_get_object (builder, "search-entry"));
   g_signal_connect (search_entry, "search-changed", G_CALLBACK (demo_search_changed_cb), filter);
 
-  selection = gtk_single_selection_new (G_LIST_MODEL (filter_model));
+  selection = GTK_SELECTION_MODEL (gtk_single_selection_new (G_LIST_MODEL (filter_model)));
   g_signal_connect (selection, "notify::selected-item", G_CALLBACK (selection_cb), NULL);
-  gtk_list_view_set_model (GTK_LIST_VIEW (listview), G_LIST_MODEL (selection));
+  gtk_list_view_set_model (GTK_LIST_VIEW (listview), selection);
 
-  selection_cb (selection, NULL, NULL);
+  selection_cb (GTK_SINGLE_SELECTION (selection), NULL, NULL);
 
   g_object_unref (builder);
 }
diff --git a/gtk/gtkcolumnview.c b/gtk/gtkcolumnview.c
index acaa2b9b07..0328c136bd 100644
--- a/gtk/gtkcolumnview.c
+++ b/gtk/gtkcolumnview.c
@@ -628,7 +628,7 @@ gtk_column_view_class_init (GtkColumnViewClass *klass)
     g_param_spec_object ("model",
                          P_("Model"),
                          P_("Model for the items displayed"),
-                         G_TYPE_LIST_MODEL,
+                         GTK_TYPE_SELECTION_MODEL,
                          G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
 
   /**
@@ -1202,7 +1202,7 @@ gtk_column_view_new (void)
  *
  * Returns: (nullable) (transfer none): The model in use
  **/
-GListModel *
+GtkSelectionModel *
 gtk_column_view_get_model (GtkColumnView *self)
 {
   g_return_val_if_fail (GTK_IS_COLUMN_VIEW (self), NULL);
@@ -1215,17 +1215,14 @@ gtk_column_view_get_model (GtkColumnView *self)
  * @self: a #GtkColumnView
  * @model: (allow-none) (transfer none): the model to use or %NULL for none
  *
- * Sets the #GListModel to use.
- *
- * If the @model is a #GtkSelectionModel, it is used for managing the selection.
- * Otherwise, @self creates a #GtkSingleSelection for the selection.
+ * Sets the #GtkSelectionModel to use.
  **/
 void
-gtk_column_view_set_model (GtkColumnView *self,
-                           GListModel  *model)
+gtk_column_view_set_model (GtkColumnView     *self,
+                           GtkSelectionModel *model)
 {
   g_return_if_fail (GTK_IS_COLUMN_VIEW (self));
-  g_return_if_fail (model == NULL || G_IS_LIST_MODEL (model));
+  g_return_if_fail (model == NULL || GTK_IS_SELECTION_MODEL (model));
 
   if (gtk_list_view_get_model (self->listview) == model)
     return;
diff --git a/gtk/gtkcolumnview.h b/gtk/gtkcolumnview.h
index 0983ea2c39..9b49f85a19 100644
--- a/gtk/gtkcolumnview.h
+++ b/gtk/gtkcolumnview.h
@@ -26,6 +26,7 @@
 
 #include <gtk/gtktypes.h>
 #include <gtk/gtksortlistmodel.h>
+#include <gtk/gtkselectionmodel.h>
 #include <gtk/gtksorter.h>
 
 G_BEGIN_DECLS
@@ -67,10 +68,10 @@ void            gtk_column_view_insert_column                   (GtkColumnView
                                                                  GtkColumnViewColumn    *column);
 
 GDK_AVAILABLE_IN_ALL
-GListModel *    gtk_column_view_get_model                       (GtkColumnView          *self);
+GtkSelectionModel * gtk_column_view_get_model                   (GtkColumnView          *self);
 GDK_AVAILABLE_IN_ALL
 void            gtk_column_view_set_model                       (GtkColumnView          *self,
-                                                                 GListModel             *model);
+                                                                 GtkSelectionModel      *model);
 
 GDK_AVAILABLE_IN_ALL
 gboolean        gtk_column_view_get_show_row_separators         (GtkColumnView          *self);
diff --git a/gtk/gtkcustompaperunixdialog.c b/gtk/gtkcustompaperunixdialog.c
index 75e471689c..b337a01425 100644
--- a/gtk/gtkcustompaperunixdialog.c
+++ b/gtk/gtkcustompaperunixdialog.c
@@ -513,7 +513,7 @@ update_combo_sensitivity_from_printers (GtkCustomPaperUnixDialog *dialog)
 static void
 update_custom_widgets_from_list (GtkCustomPaperUnixDialog *dialog)
 {
-  GListModel *model;
+  GtkSelectionModel *model;
   GtkPageSetup *page_setup;
 
   model = gtk_list_view_get_model (GTK_LIST_VIEW (dialog->listview));
@@ -559,7 +559,7 @@ static void
 unit_widget_changed (GtkCustomPaperUnixDialog *dialog)
 {
   double w, h, top, bottom, left, right;
-  GListModel *model;
+  GtkSelectionModel *model;
   GtkPageSetup *page_setup;
   GtkPaperSize *paper_size;
 
@@ -648,7 +648,7 @@ add_custom_paper (GtkCustomPaperUnixDialog *dialog)
 static void
 remove_custom_paper (GtkCustomPaperUnixDialog *dialog)
 {
-  GListModel *model;
+  GtkSelectionModel *model;
   guint selected;
 
   model = gtk_list_view_get_model (GTK_LIST_VIEW (dialog->listview));
@@ -870,7 +870,7 @@ populate_dialog (GtkCustomPaperUnixDialog *dialog)
   GtkWidget *grid, *label, *widget, *frame, *combo;
   GtkWidget *hbox, *vbox, *listview, *scrolled, *toolbar, *button;
   GtkUnit user_units;
-  GListModel *model;
+  GtkSingleSelection *selection;
   GtkListItemFactory *factory;
 
   content_area = gtk_dialog_get_content_area (cpu_dialog);
@@ -899,10 +899,10 @@ populate_dialog (GtkCustomPaperUnixDialog *dialog)
   listview = gtk_list_view_new ();
   gtk_widget_set_size_request (listview, 140, -1);
 
-  model = G_LIST_MODEL (gtk_single_selection_new (G_LIST_MODEL (dialog->custom_paper_list)));
-  gtk_list_view_set_model (GTK_LIST_VIEW (listview), model);
-  g_signal_connect (model, "notify::selected", G_CALLBACK (selected_custom_paper_changed), dialog);
-  g_object_unref (model);
+  selection = gtk_single_selection_new (G_LIST_MODEL (dialog->custom_paper_list));
+  gtk_list_view_set_model (GTK_LIST_VIEW (listview), GTK_SELECTION_MODEL (selection));
+  g_signal_connect (selection, "notify::selected", G_CALLBACK (selected_custom_paper_changed), dialog);
+  g_object_unref (selection);
 
   factory = gtk_signal_list_item_factory_new ();
   g_signal_connect (factory, "setup", G_CALLBACK (setup_item), NULL);
diff --git a/gtk/gtkdropdown.c b/gtk/gtkdropdown.c
index de1ba763cb..087dffc5e9 100644
--- a/gtk/gtkdropdown.c
+++ b/gtk/gtkdropdown.c
@@ -673,7 +673,7 @@ gtk_drop_down_set_model (GtkDropDown *self,
 
       selection = G_LIST_MODEL (gtk_single_selection_new (filter_model));
       g_set_object (&self->popup_selection, selection);
-      gtk_list_view_set_model (GTK_LIST_VIEW (self->popup_list), selection);
+      gtk_list_view_set_model (GTK_LIST_VIEW (self->popup_list), GTK_SELECTION_MODEL (selection));
       g_object_unref (selection);
 
       selection = G_LIST_MODEL (gtk_single_selection_new (model));
diff --git a/gtk/gtkgridview.c b/gtk/gtkgridview.c
index 049b3c2906..f5349767d5 100644
--- a/gtk/gtkgridview.c
+++ b/gtk/gtkgridview.c
@@ -1092,7 +1092,7 @@ gtk_grid_view_class_init (GtkGridViewClass *klass)
     g_param_spec_object ("model",
                          P_("Model"),
                          P_("Model for the items displayed"),
-                         G_TYPE_LIST_MODEL,
+                         GTK_TYPE_SELECTION_MODEL,
                          G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
 
   /**
@@ -1235,7 +1235,7 @@ gtk_grid_view_new_with_factory (GtkListItemFactory *factory)
  *
  * Returns: (nullable) (transfer none): The model in use
  **/
-GListModel *
+GtkSelectionModel *
 gtk_grid_view_get_model (GtkGridView *self)
 {
   g_return_val_if_fail (GTK_IS_GRID_VIEW (self), NULL);
@@ -1248,14 +1248,14 @@ gtk_grid_view_get_model (GtkGridView *self)
  * @self: a #GtkGridView
  * @model: (allow-none) (transfer none): the model to use or %NULL for none
  *
- * Sets the #GListModel to use for
+ * Sets the #GtkSelectionModel to use for
  **/
 void
-gtk_grid_view_set_model (GtkGridView *self,
-                         GListModel  *model)
+gtk_grid_view_set_model (GtkGridView       *self,
+                         GtkSelectionModel *model)
 {
   g_return_if_fail (GTK_IS_GRID_VIEW (self));
-  g_return_if_fail (model == NULL || G_IS_LIST_MODEL (model));
+  g_return_if_fail (model == NULL || GTK_IS_SELECTION_MODEL (model));
 
   if (!gtk_list_base_set_model (GTK_LIST_BASE (self), model))
     return;
diff --git a/gtk/gtkgridview.h b/gtk/gtkgridview.h
index 6fb035ce12..39931fa5fa 100644
--- a/gtk/gtkgridview.h
+++ b/gtk/gtkgridview.h
@@ -25,6 +25,7 @@
 #endif
 
 #include <gtk/gtklistbase.h>
+#include <gtk/gtkselectionmodel.h>
 
 G_BEGIN_DECLS
 
@@ -53,10 +54,10 @@ GDK_AVAILABLE_IN_ALL
 GtkWidget *     gtk_grid_view_new_with_factory                  (GtkListItemFactory     *factory);
 
 GDK_AVAILABLE_IN_ALL
-GListModel *    gtk_grid_view_get_model                         (GtkGridView            *self);
+GtkSelectionModel * gtk_grid_view_get_model                     (GtkGridView            *self);
 GDK_AVAILABLE_IN_ALL
 void            gtk_grid_view_set_model                         (GtkGridView            *self,
-                                                                 GListModel             *model);
+                                                                 GtkSelectionModel      *model);
 GDK_AVAILABLE_IN_ALL
 void            gtk_grid_view_set_factory                       (GtkGridView            *self,
                                                                  GtkListItemFactory     *factory);
diff --git a/gtk/gtklistbase.c b/gtk/gtklistbase.c
index 5a1a38e40a..2fab8c2700 100644
--- a/gtk/gtklistbase.c
+++ b/gtk/gtklistbase.c
@@ -2102,40 +2102,30 @@ gtk_list_base_grab_focus_on_item (GtkListBase *self,
   return TRUE;
 }
 
-GListModel *
+GtkSelectionModel *
 gtk_list_base_get_model (GtkListBase *self)
 {
   GtkListBasePrivate *priv = gtk_list_base_get_instance_private (self);
 
-  return priv->model;
+  return GTK_SELECTION_MODEL (priv->model);
 }
 
 gboolean
-gtk_list_base_set_model (GtkListBase *self,
-                         GListModel  *model)
+gtk_list_base_set_model (GtkListBase       *self,
+                         GtkSelectionModel *model)
 {
   GtkListBasePrivate *priv = gtk_list_base_get_instance_private (self);
 
-  if (priv->model == model)
+  if (priv->model == G_LIST_MODEL (model))
     return FALSE;
 
   g_clear_object (&priv->model);
 
   if (model)
     {
-      GtkSelectionModel *selection_model;
-
-      priv->model = g_object_ref (model);
-
-      if (GTK_IS_SELECTION_MODEL (model))
-        selection_model = GTK_SELECTION_MODEL (g_object_ref (model));
-      else
-        selection_model = GTK_SELECTION_MODEL (gtk_single_selection_new (model));
-
-      gtk_list_item_manager_set_model (priv->item_manager, selection_model);
+      priv->model = g_object_ref (G_LIST_MODEL (model));
+      gtk_list_item_manager_set_model (priv->item_manager, model);
       gtk_list_base_set_anchor (self, 0, 0.0, GTK_PACK_START, 0.0, GTK_PACK_START);
-
-      g_object_unref (selection_model);
     }
   else
     {
diff --git a/gtk/gtklistbaseprivate.h b/gtk/gtklistbaseprivate.h
index c714c63c0c..f53a4c6efb 100644
--- a/gtk/gtklistbaseprivate.h
+++ b/gtk/gtklistbaseprivate.h
@@ -23,6 +23,7 @@
 #include "gtklistbase.h"
 
 #include "gtklistitemmanagerprivate.h"
+#include "gtkselectionmodel.h"
 #include "gtkprivate.h"
 
 struct _GtkListBase
@@ -71,9 +72,9 @@ GtkListItemManager *   gtk_list_base_get_manager                (GtkListBase
 GtkScrollablePolicy    gtk_list_base_get_scroll_policy          (GtkListBase            *self,
                                                                  GtkOrientation          orientation);
 guint                  gtk_list_base_get_n_items                (GtkListBase            *self);
-GListModel *           gtk_list_base_get_model                  (GtkListBase            *self);
+GtkSelectionModel *    gtk_list_base_get_model                  (GtkListBase            *self);
 gboolean               gtk_list_base_set_model                  (GtkListBase            *self,
-                                                                 GListModel             *model);
+                                                                 GtkSelectionModel      *model);
 void                   gtk_list_base_update_adjustments         (GtkListBase            *self,
                                                                  int                     total_across,
                                                                  int                     total_along,
diff --git a/gtk/gtklistview.c b/gtk/gtklistview.c
index 3a65706ee6..28164cf174 100644
--- a/gtk/gtklistview.c
+++ b/gtk/gtklistview.c
@@ -831,13 +831,14 @@ gtk_list_view_class_init (GtkListViewClass *klass)
   /**
    * GtkListView:model:
    *
-   * Model for the items displayed
+   * Model for the items displayed.
+   * This must be a #GtkSelectionModel
    */
   properties[PROP_MODEL] =
     g_param_spec_object ("model",
                          P_("Model"),
                          P_("Model for the items displayed"),
-                         G_TYPE_LIST_MODEL,
+                         GTK_TYPE_SELECTION_MODEL,
                          G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
 
   /**
@@ -989,7 +990,7 @@ gtk_list_view_new_with_factory (GtkListItemFactory *factory)
  *
  * Returns: (nullable) (transfer none): The model in use
  **/
-GListModel *
+GtkSelectionModel *
 gtk_list_view_get_model (GtkListView *self)
 {
   g_return_val_if_fail (GTK_IS_LIST_VIEW (self), NULL);
@@ -1002,17 +1003,14 @@ gtk_list_view_get_model (GtkListView *self)
  * @self: a #GtkListView
  * @model: (allow-none) (transfer none): the model to use or %NULL for none
  *
- * Sets the #GListModel to use.
- *
- * If the @model is a #GtkSelectionModel, it is used for managing the selection.
- * Otherwise, @self creates a #GtkSingleSelection for the selection.
- **/
+ * Sets the #GtkSelectionModel to use.
+ */
 void
-gtk_list_view_set_model (GtkListView *self,
-                         GListModel  *model)
+gtk_list_view_set_model (GtkListView       *self,
+                         GtkSelectionModel *model)
 {
   g_return_if_fail (GTK_IS_LIST_VIEW (self));
-  g_return_if_fail (model == NULL || G_IS_LIST_MODEL (model));
+  g_return_if_fail (model == NULL || GTK_IS_SELECTION_MODEL (model));
 
   if (!gtk_list_base_set_model (GTK_LIST_BASE (self), model))
     return;
diff --git a/gtk/gtklistview.h b/gtk/gtklistview.h
index afcfb6225f..d3c8cec583 100644
--- a/gtk/gtklistview.h
+++ b/gtk/gtklistview.h
@@ -25,6 +25,7 @@
 #endif
 
 #include <gtk/gtklistbase.h>
+#include <gtk/gtkselectionmodel.h>
 
 G_BEGIN_DECLS
 
@@ -52,10 +53,10 @@ GDK_AVAILABLE_IN_ALL
 GtkWidget *     gtk_list_view_new_with_factory                  (GtkListItemFactory     *factory);
 
 GDK_AVAILABLE_IN_ALL
-GListModel *    gtk_list_view_get_model                         (GtkListView            *self);
+GtkSelectionModel * gtk_list_view_get_model                     (GtkListView            *self);
 GDK_AVAILABLE_IN_ALL
 void            gtk_list_view_set_model                         (GtkListView            *self,
-                                                                 GListModel             *model);
+                                                                 GtkSelectionModel      *model);
 GDK_AVAILABLE_IN_ALL
 void            gtk_list_view_set_factory                       (GtkListView            *self,
                                                                  GtkListItemFactory     *factory);
diff --git a/gtk/gtkprintunixdialog.c b/gtk/gtkprintunixdialog.c
index eac69cecaf..49a188b426 100644
--- a/gtk/gtkprintunixdialog.c
+++ b/gtk/gtkprintunixdialog.c
@@ -740,7 +740,7 @@ gtk_print_unix_dialog_init (GtkPrintUnixDialog *dialog)
   GListModel *model;
   GListModel *sorted;
   GListModel *filtered;
-  GListModel *selection;
+  GtkSingleSelection *selection;
   GtkSorter *sorter;
   GtkFilter *filter;
   GtkFilter *filter1;
@@ -833,10 +833,10 @@ gtk_print_unix_dialog_init (GtkPrintUnixDialog *dialog)
   filtered = G_LIST_MODEL (gtk_filter_list_model_new (sorted, filter));
   g_object_unref (filter);
 
-  selection = G_LIST_MODEL (gtk_single_selection_new (filtered));
-  gtk_single_selection_set_autoselect (GTK_SINGLE_SELECTION (selection), FALSE);
-  gtk_single_selection_set_selected (GTK_SINGLE_SELECTION (selection), GTK_INVALID_LIST_POSITION);
-  gtk_column_view_set_model (GTK_COLUMN_VIEW (dialog->printer_list), selection);
+  selection = gtk_single_selection_new (filtered);
+  gtk_single_selection_set_autoselect (selection, FALSE);
+  gtk_single_selection_set_selected (selection, GTK_INVALID_LIST_POSITION);
+  gtk_column_view_set_model (GTK_COLUMN_VIEW (dialog->printer_list), GTK_SELECTION_MODEL (selection));
   g_signal_connect (selection, "items-changed", G_CALLBACK (printer_added_cb), dialog);
   g_signal_connect_swapped (selection, "notify::selected", G_CALLBACK (selected_printer_changed), dialog);
   g_object_unref (selection);
@@ -983,18 +983,18 @@ printer_status_cb (GtkPrintBackend    *backend,
                    GtkPrinter         *printer,
                    GtkPrintUnixDialog *dialog)
 {
-  GListModel *model;
+  GtkSingleSelection *selection;
 
   /* When the pause state change then we need to update sensitive property
    * of GTK_RESPONSE_OK button inside of selected_printer_changed function.
    */
   selected_printer_changed (dialog);
 
-  model = gtk_column_view_get_model (GTK_COLUMN_VIEW (dialog->printer_list));
+  selection = GTK_SINGLE_SELECTION (gtk_column_view_get_model (GTK_COLUMN_VIEW (dialog->printer_list)));
 
   if (gtk_print_backend_printer_list_is_done (backend) &&
       gtk_printer_is_default (printer) &&
-      gtk_single_selection_get_selected (GTK_SINGLE_SELECTION (model)) == GTK_INVALID_LIST_POSITION)
+      gtk_single_selection_get_selected (selection) == GTK_INVALID_LIST_POSITION)
     set_active_printer (dialog, gtk_printer_get_name (printer));
 }
 
@@ -1822,9 +1822,11 @@ printer_details_acquired (GtkPrinter         *printer,
 static void
 selected_printer_changed (GtkPrintUnixDialog *dialog)
 {
-  GListModel *model = gtk_column_view_get_model (GTK_COLUMN_VIEW (dialog->printer_list));
+  GtkSingleSelection *selection;
   GtkPrinter *printer;
 
+  selection = GTK_SINGLE_SELECTION (gtk_column_view_get_model (GTK_COLUMN_VIEW (dialog->printer_list)));
+
   /* Whenever the user selects a printer we stop looking for
    * the printer specified in the initial settings
    */
@@ -1837,7 +1839,7 @@ selected_printer_changed (GtkPrintUnixDialog *dialog)
 
   disconnect_printer_details_request (dialog, FALSE);
 
-  printer = gtk_single_selection_get_selected_item (GTK_SINGLE_SELECTION (model));
+  printer = gtk_single_selection_get_selected_item (selection);
 
   /* sets GTK_RESPONSE_OK button sensitivity depending on whether the printer
    * accepts/rejects jobs
@@ -3170,7 +3172,7 @@ set_active_printer (GtkPrintUnixDialog *dialog,
   GtkPrinter *printer;
   guint i;
 
-  model = gtk_column_view_get_model (GTK_COLUMN_VIEW (dialog->printer_list));
+  model = G_LIST_MODEL (gtk_column_view_get_model (GTK_COLUMN_VIEW (dialog->printer_list)));
 
   for (i = 0; i < g_list_model_get_n_items (model); i++)
     {
diff --git a/gtk/inspector/actions.c b/gtk/inspector/actions.c
index f8ddc2d79c..6c9da2f602 100644
--- a/gtk/inspector/actions.c
+++ b/gtk/inspector/actions.c
@@ -422,7 +422,7 @@ constructed (GObject *object)
   GtkInspectorActions *sl = GTK_INSPECTOR_ACTIONS (object);
   GtkSorter *sorter;
   GListModel *sorted;
-  GListModel *model;
+  GtkSelectionModel *model;
 
   g_signal_connect_swapped (sl->priv->button, "clicked",
                             G_CALLBACK (refresh_all), sl);
@@ -438,7 +438,7 @@ constructed (GObject *object)
   sl->priv->actions = G_LIST_MODEL (g_list_store_new (ACTION_TYPE_HOLDER));
   sorted = G_LIST_MODEL (gtk_sort_list_model_new (sl->priv->actions,
                                                   gtk_column_view_get_sorter (GTK_COLUMN_VIEW 
(sl->priv->list))));
-  model = G_LIST_MODEL (gtk_no_selection_new (sorted));
+  model = GTK_SELECTION_MODEL (gtk_no_selection_new (sorted));
   gtk_column_view_set_model (GTK_COLUMN_VIEW (sl->priv->list), model);
   g_object_unref (sorted);
   g_object_unref (model);
diff --git a/gtk/inspector/list-data.c b/gtk/inspector/list-data.c
index c51eee1ef1..4e9f3d650c 100644
--- a/gtk/inspector/list-data.c
+++ b/gtk/inspector/list-data.c
@@ -86,7 +86,7 @@ gtk_inspector_list_data_set_object (GtkInspectorListData *sl,
 
   sl->object = G_LIST_MODEL (object);
   selection = gtk_no_selection_new (sl->object);
-  gtk_column_view_set_model (sl->view, G_LIST_MODEL (selection));
+  gtk_column_view_set_model (sl->view, GTK_SELECTION_MODEL (selection));
   g_object_unref (selection);
 }
 
diff --git a/gtk/inspector/prop-list.c b/gtk/inspector/prop-list.c
index b30fe7a740..5fa07c1974 100644
--- a/gtk/inspector/prop-list.c
+++ b/gtk/inspector/prop-list.c
@@ -583,7 +583,7 @@ gtk_inspector_prop_list_set_object (GtkInspectorPropList *pl,
   guint num_properties;
   guint i;
   GListStore *store;
-  GListModel *list;
+  GtkNoSelection *selection;
   GListModel *filtered;
   GtkSortListModel *sorted;
 
@@ -624,15 +624,15 @@ gtk_inspector_prop_list_set_object (GtkInspectorPropList *pl,
 
   filtered = G_LIST_MODEL (gtk_filter_list_model_new (G_LIST_MODEL (store), pl->priv->filter));
   sorted = gtk_sort_list_model_new (filtered, NULL);
-  list = G_LIST_MODEL (gtk_no_selection_new (G_LIST_MODEL (sorted)));
+  selection = gtk_no_selection_new (G_LIST_MODEL (sorted));
 
-  gtk_column_view_set_model (GTK_COLUMN_VIEW (pl->priv->list), list);
+  gtk_column_view_set_model (GTK_COLUMN_VIEW (pl->priv->list), GTK_SELECTION_MODEL (selection));
   gtk_sort_list_model_set_sorter (sorted, gtk_column_view_get_sorter (GTK_COLUMN_VIEW (pl->priv->list)));
   gtk_column_view_sort_by_column (GTK_COLUMN_VIEW (pl->priv->list), pl->priv->name, GTK_SORT_ASCENDING);
 
   gtk_widget_show (GTK_WIDGET (pl));
 
-  g_object_unref (list);
+  g_object_unref (selection);
   g_object_unref (sorted);
   g_object_unref (filtered);
   g_object_unref (store);
diff --git a/gtk/inspector/recorder.c b/gtk/inspector/recorder.c
index 01ba208b66..5efc425e07 100644
--- a/gtk/inspector/recorder.c
+++ b/gtk/inspector/recorder.c
@@ -1247,7 +1247,7 @@ gtk_inspector_recorder_init (GtkInspectorRecorder *recorder)
   gtk_list_view_set_factory (GTK_LIST_VIEW (priv->render_node_list), factory);
   g_object_unref (factory);
   gtk_list_view_set_model (GTK_LIST_VIEW (priv->render_node_list),
-                           G_LIST_MODEL (priv->render_node_selection));
+                           GTK_SELECTION_MODEL (priv->render_node_selection));
 
   priv->render_node_properties = GTK_TREE_MODEL (gtk_list_store_new (4, G_TYPE_STRING, G_TYPE_STRING, 
G_TYPE_BOOLEAN, GDK_TYPE_TEXTURE));
   gtk_tree_view_set_model (GTK_TREE_VIEW (priv->node_property_tree), priv->render_node_properties);
diff --git a/gtk/inspector/resource-list.c b/gtk/inspector/resource-list.c
index 63cf4745c2..531e94d897 100644
--- a/gtk/inspector/resource-list.c
+++ b/gtk/inspector/resource-list.c
@@ -718,7 +718,7 @@ constructed (GObject *object)
   g_object_unref (sort_model);
   g_object_unref (sorter);
 
-  gtk_column_view_set_model (GTK_COLUMN_VIEW (rl->list), G_LIST_MODEL (rl->selection));
+  gtk_column_view_set_model (GTK_COLUMN_VIEW (rl->list), GTK_SELECTION_MODEL (rl->selection));
 
   g_signal_connect (rl->selection, "selection-changed", G_CALLBACK (on_selection_changed), rl);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]