diff options
34 files changed, 114 insertions, 112 deletions
diff --git a/demos/gtk-demo/iconscroll.c b/demos/gtk-demo/iconscroll.c index a3e0f4dd99..9c9e198e2c 100644 --- a/demos/gtk-demo/iconscroll.c +++ b/demos/gtk-demo/iconscroll.c @@ -164,7 +164,7 @@ populate_grid (void) list = create_color_grid (); selection = gtk_no_selection_new (gtk_color_list_new (2097152)); - gtk_grid_view_set_model (GTK_GRID_VIEW (list), G_LIST_MODEL (selection)); + gtk_grid_view_set_model (GTK_GRID_VIEW (list), GTK_SELECTION_MODEL (selection)); g_object_unref (selection); hincrement = 0; diff --git a/demos/gtk-demo/listview_applauncher.c b/demos/gtk-demo/listview_applauncher.c index 92e4631689..c52a224e2e 100644 --- a/demos/gtk-demo/listview_applauncher.c +++ b/demos/gtk-demo/listview_applauncher.c @@ -104,7 +104,7 @@ activate_cb (GtkListView *list, GdkAppLaunchContext *context; GError *error = NULL; - app_info = g_list_model_get_item (gtk_list_view_get_model (list), position); + app_info = g_list_model_get_item (G_LIST_MODEL (gtk_list_view_get_model (list)), position); /* Prepare the context for launching the application and launch it. This * code is explained in detail in the documentation for #GdkAppLaunchContext @@ -176,7 +176,7 @@ do_listview_applauncher (GtkWidget *do_widget) /* Create the list widget here. */ - list = gtk_list_view_new_with_factory (model, factory); + list = gtk_list_view_new_with_factory (GTK_SELECTION_MODEL (gtk_single_selection_new (model)), factory); /* We connect the activate signal here. It's the function we defined * above for launching the selected application. diff --git a/demos/gtk-demo/listview_clocks.c b/demos/gtk-demo/listview_clocks.c index e32c80fdf1..07332da259 100644 --- a/demos/gtk-demo/listview_clocks.c +++ b/demos/gtk-demo/listview_clocks.c @@ -462,7 +462,7 @@ do_listview_clocks (GtkWidget *do_widget) { GtkWidget *gridview, *sw; GtkListItemFactory *factory; - GListModel *model; + GtkSelectionModel *model; /* This is the normal window setup code every demo does */ window = gtk_window_new (); @@ -484,7 +484,7 @@ do_listview_clocks (GtkWidget *do_widget) factory = gtk_signal_list_item_factory_new (); g_signal_connect (factory, "setup", G_CALLBACK (setup_listitem_cb), NULL); - model = G_LIST_MODEL (gtk_no_selection_new (create_clocks_model ())); + model = GTK_SELECTION_MODEL (gtk_no_selection_new (create_clocks_model ())); gridview = gtk_grid_view_new_with_factory (model, factory); gtk_scrollable_set_hscroll_policy (GTK_SCROLLABLE (gridview), GTK_SCROLL_NATURAL); gtk_scrollable_set_vscroll_policy (GTK_SCROLLABLE (gridview), GTK_SCROLL_NATURAL); diff --git a/demos/gtk-demo/listview_colors.c b/demos/gtk-demo/listview_colors.c index 569431c54d..64fb6e0cb5 100644 --- a/demos/gtk-demo/listview_colors.c +++ b/demos/gtk-demo/listview_colors.c @@ -866,7 +866,7 @@ do_listview_colors (GtkWidget *do_widget) guint len; GtkWidget *selection_view; GListModel *selection_filter; - GListModel *no_selection; + GtkSelectionModel *no_selection; GtkWidget *grid; GtkWidget *selection_size_label; GtkWidget *selection_average_picture; @@ -959,7 +959,7 @@ do_listview_colors (GtkWidget *do_widget) gtk_box_append (GTK_BOX (box), sw); gridview = create_color_grid (); - 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); gtk_widget_set_hexpand (sw, TRUE); gtk_widget_set_vexpand (sw, TRUE); @@ -968,7 +968,7 @@ 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)); + no_selection = GTK_SELECTION_MODEL (gtk_no_selection_new (selection_filter)); gtk_grid_view_set_model (GTK_GRID_VIEW (selection_view), no_selection); g_object_unref (no_selection); diff --git a/demos/gtk-demo/listview_filebrowser.c b/demos/gtk-demo/listview_filebrowser.c index 7dcf3e3d3f..47237cb3c7 100644 --- a/demos/gtk-demo/listview_filebrowser.c +++ b/demos/gtk-demo/listview_filebrowser.c @@ -225,7 +225,7 @@ filebrowser_view_activated_cb (GtkGridView *view, { GFileInfo *info; - info = g_list_model_get_item (gtk_grid_view_get_model (view), pos); + info = g_list_model_get_item (G_LIST_MODEL (gtk_grid_view_get_model (view)), pos); if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) gtk_directory_list_set_file (list, G_FILE (g_file_info_get_attribute_object (info, "standard::file"))); diff --git a/demos/gtk-demo/listview_filebrowser.ui b/demos/gtk-demo/listview_filebrowser.ui index 1c3fcffd33..3fe307d702 100644 --- a/demos/gtk-demo/listview_filebrowser.ui +++ b/demos/gtk-demo/listview_filebrowser.ui @@ -165,8 +165,12 @@ </object> </child> </object> - <object class="GtkDirectoryList" id="dirlist"> - <property name="attributes">standard::name,standard::display-name,standard::icon,standard::size,standard::content-type</property> + <object class="GtkSingleSelection" id="selection_model"> + <property name="model"> + <object class="GtkDirectoryList" id="dirlist"> + <property name="attributes">standard::name,standard::display-name,standard::icon,standard::size,standard::content-type</property> + </object> + </property> </object> <object class="GtkWindow" id="window"> <property name="title" translatable="yes">File browser</property> @@ -227,7 +231,7 @@ <property name="can-focus">1</property> <child> <object class="GtkGridView" id="view"> - <property name="model">dirlist</property> + <property name="model">selection_model</property> <property name="max-columns">15</property> <binding name="factory"> <lookup name="factory" type="FileBrowserView"> diff --git a/demos/gtk-demo/listview_settings.c b/demos/gtk-demo/listview_settings.c index 9e5b3029d7..2631f346e2 100644 --- a/demos/gtk-demo/listview_settings.c +++ b/demos/gtk-demo/listview_settings.c @@ -413,7 +413,7 @@ do_listview_settings (GtkWidget *do_widget) 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), GTK_SELECTION_MODEL (selection)); g_object_unref (selection); name_column = GTK_COLUMN_VIEW_COLUMN (gtk_builder_get_object (builder, "name_column")); diff --git a/demos/gtk-demo/listview_weather.c b/demos/gtk-demo/listview_weather.c index 23b83906cb..6f0f17f0a6 100644 --- a/demos/gtk-demo/listview_weather.c +++ b/demos/gtk-demo/listview_weather.c @@ -281,13 +281,13 @@ GtkWidget * create_weather_view (void) { GtkWidget *listview; - GListModel *model; + GtkSelectionModel *model; GtkListItemFactory *factory; factory = gtk_signal_list_item_factory_new (); g_signal_connect (factory, "setup", G_CALLBACK (setup_widget), NULL); g_signal_connect (factory, "bind", G_CALLBACK (bind_widget), NULL); - model = G_LIST_MODEL (gtk_no_selection_new (create_weather_model ())); + model = GTK_SELECTION_MODEL (gtk_no_selection_new (create_weather_model ())); listview = gtk_list_view_new_with_factory (model, factory); gtk_orientable_set_orientation (GTK_ORIENTABLE (listview), GTK_ORIENTATION_HORIZONTAL); gtk_list_view_set_show_separators (GTK_LIST_VIEW (listview), TRUE); diff --git a/demos/gtk-demo/listview_words.c b/demos/gtk-demo/listview_words.c index 1687f4c48e..8b41be795b 100644 --- a/demos/gtk-demo/listview_words.c +++ b/demos/gtk-demo/listview_words.c @@ -218,7 +218,7 @@ do_listview_words (GtkWidget *do_widget) gtk_overlay_set_child (GTK_OVERLAY (overlay), sw); listview = gtk_list_view_new_with_factory ( - G_LIST_MODEL (gtk_no_selection_new (G_LIST_MODEL (filter_model))), + GTK_SELECTION_MODEL (gtk_no_selection_new (G_LIST_MODEL (filter_model))), 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); diff --git a/demos/gtk-demo/main.c b/demos/gtk-demo/main.c index bfa316347e..c1b97bbade 100644 --- a/demos/gtk-demo/main.c +++ b/demos/gtk-demo/main.c @@ -640,7 +640,8 @@ 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); + GListModel *model = G_LIST_MODEL (gtk_list_view_get_model (GTK_LIST_VIEW (widget))); + GtkTreeListRow *row = g_list_model_get_item (model, position); GtkDemo *demo = gtk_tree_list_row_get_item (row); gtk_demo_run (demo, window); @@ -872,9 +873,10 @@ activate (GApplication *app) selection = 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), GTK_SELECTION_MODEL (selection)); selection_cb (selection, NULL, NULL); + g_object_unref (selection); g_object_unref (builder); } diff --git a/demos/icon-browser/iconbrowserwin.c b/demos/icon-browser/iconbrowserwin.c index 700d8381f9..c0302e681c 100644 --- a/demos/icon-browser/iconbrowserwin.c +++ b/demos/icon-browser/iconbrowserwin.c @@ -172,7 +172,7 @@ item_activated (GtkGridView *view, guint position, IconBrowserWindow *win) { - GListModel *model = gtk_grid_view_get_model (view); + GListModel *model = G_LIST_MODEL (gtk_grid_view_get_model (view)); IbIcon *icon = g_list_model_get_item (model, position); const char *name; const char *description; diff --git a/gtk/gtkcolumnview.c b/gtk/gtkcolumnview.c index deadfd7b9e..48a87ea6e3 100644 --- a/gtk/gtkcolumnview.c +++ b/gtk/gtkcolumnview.c @@ -632,7 +632,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); /** @@ -1193,11 +1193,11 @@ gtk_column_view_init (GtkColumnView *self) * Returns: a new #GtkColumnView **/ GtkWidget * -gtk_column_view_new (GListModel *model) +gtk_column_view_new (GtkSelectionModel *model) { GtkWidget *result; - g_return_val_if_fail (model == NULL || G_IS_LIST_MODEL (model), NULL); + g_return_val_if_fail (model == NULL || GTK_IS_SELECTION_MODEL (model), NULL); result = g_object_new (GTK_TYPE_COLUMN_VIEW, "model", model, @@ -1217,7 +1217,7 @@ gtk_column_view_new (GListModel *model) * * 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); @@ -1230,17 +1230,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 e3dc777b65..b781f3388d 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 @@ -51,7 +52,7 @@ GDK_AVAILABLE_IN_ALL GType gtk_column_view_get_type (void) G_GNUC_CONST; GDK_AVAILABLE_IN_ALL -GtkWidget * gtk_column_view_new (GListModel *model); +GtkWidget * gtk_column_view_new (GtkSelectionModel *model); GDK_AVAILABLE_IN_ALL GListModel * gtk_column_view_get_columns (GtkColumnView *self); @@ -67,10 +68,11 @@ 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 897cf3f347..927c14f80c 100644 --- a/gtk/gtkcustompaperunixdialog.c +++ b/gtk/gtkcustompaperunixdialog.c @@ -513,7 +513,7 @@ update_custom_widgets_from_list (GtkCustomPaperUnixDialog *dialog) GListModel *model; GtkPageSetup *page_setup; - model = gtk_list_view_get_model (GTK_LIST_VIEW (dialog->listview)); + model = G_LIST_MODEL (gtk_list_view_get_model (GTK_LIST_VIEW (dialog->listview))); page_setup = gtk_single_selection_get_selected_item (GTK_SINGLE_SELECTION (model)); dialog->non_user_change = TRUE; @@ -563,7 +563,7 @@ unit_widget_changed (GtkCustomPaperUnixDialog *dialog) if (dialog->non_user_change) return; - model = gtk_list_view_get_model (GTK_LIST_VIEW (dialog->listview)); + model = G_LIST_MODEL (gtk_list_view_get_model (GTK_LIST_VIEW (dialog->listview))); page_setup = gtk_single_selection_get_selected_item (GTK_SINGLE_SELECTION (model)); if (page_setup != NULL) @@ -648,7 +648,7 @@ remove_custom_paper (GtkCustomPaperUnixDialog *dialog) GListModel *model; guint selected; - model = gtk_list_view_get_model (GTK_LIST_VIEW (dialog->listview)); + model = G_LIST_MODEL (gtk_list_view_get_model (GTK_LIST_VIEW (dialog->listview))); selected = gtk_single_selection_get_selected (GTK_SINGLE_SELECTION (model)); if (selected != GTK_INVALID_LIST_POSITION) g_list_store_remove (dialog->custom_paper_list, selected); @@ -867,7 +867,7 @@ populate_dialog (GtkCustomPaperUnixDialog *dialog) GtkWidget *grid, *label, *widget, *frame, *combo; GtkWidget *hbox, *vbox, *listview, *scrolled, *toolbar, *button; GtkUnit user_units; - GListModel *model; + GtkSelectionModel *model; GtkListItemFactory *factory; content_area = gtk_dialog_get_content_area (cpu_dialog); @@ -893,7 +893,7 @@ populate_dialog (GtkCustomPaperUnixDialog *dialog) gtk_box_append (GTK_BOX (vbox), scrolled); gtk_widget_show (scrolled); - model = G_LIST_MODEL (gtk_single_selection_new (g_object_ref (G_LIST_MODEL (dialog->custom_paper_list)))); + model = GTK_SELECTION_MODEL (gtk_single_selection_new (g_object_ref (G_LIST_MODEL (dialog->custom_paper_list)))); g_signal_connect (model, "notify::selected", G_CALLBACK (selected_custom_paper_changed), dialog); factory = gtk_signal_list_item_factory_new (); diff --git a/gtk/gtkdropdown.c b/gtk/gtkdropdown.c index bb8c763d6c..feebfa1888 100644 --- a/gtk/gtkdropdown.c +++ b/gtk/gtkdropdown.c @@ -81,9 +81,9 @@ struct _GtkDropDown GtkListItemFactory *factory; GtkListItemFactory *list_factory; GListModel *model; - GListModel *selection; + GtkSelectionModel *selection; GListModel *filter_model; - GListModel *popup_selection; + GtkSelectionModel *popup_selection; GtkWidget *popup; GtkWidget *button; @@ -690,19 +690,19 @@ gtk_drop_down_set_model (GtkDropDown *self, else { GListModel *filter_model; - GListModel *selection; + GtkSelectionModel *selection; filter_model = G_LIST_MODEL (gtk_filter_list_model_new (g_object_ref (model), NULL)); g_set_object (&self->filter_model, filter_model); update_filter (self); - selection = G_LIST_MODEL (gtk_single_selection_new (filter_model)); + selection = GTK_SELECTION_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); g_object_unref (selection); - selection = G_LIST_MODEL (gtk_single_selection_new (g_object_ref (model))); + selection = GTK_SELECTION_MODEL (gtk_single_selection_new (g_object_ref (model))); g_set_object (&self->selection, selection); g_object_unref (selection); diff --git a/gtk/gtkgridview.c b/gtk/gtkgridview.c index 00b40976a7..c80c60108b 100644 --- a/gtk/gtkgridview.c +++ b/gtk/gtkgridview.c @@ -46,7 +46,7 @@ * SECTION:gtkgridview * @title: GtkGridView * @short_description: A widget for displaying grids - * @see_also: #GListModel, #GtkListView, #GtkColumnView + * @see_also: #GtkSelectionModel, #GtkListView, #GtkColumnView * * GtkGridView is a widget to present a view into a large dynamic grid of items. * @@ -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); /** @@ -1188,11 +1188,11 @@ gtk_grid_view_init (GtkGridView *self) * Returns: a new #GtkGridView **/ GtkWidget * -gtk_grid_view_new (GListModel *model) +gtk_grid_view_new (GtkSelectionModel *model) { GtkWidget *result; - g_return_val_if_fail (model == NULL || G_IS_LIST_MODEL (model), NULL); + g_return_val_if_fail (model == NULL || GTK_IS_SELECTION_MODEL (model), NULL); result = g_object_new (GTK_TYPE_GRID_VIEW, "model", model, @@ -1222,11 +1222,12 @@ gtk_grid_view_new (GListModel *model) * Returns: a new #GtkGridView using the given @factory **/ GtkWidget * -gtk_grid_view_new_with_factory (GListModel *model, +gtk_grid_view_new_with_factory (GtkSelectionModel *model, GtkListItemFactory *factory) { GtkWidget *result; + g_return_val_if_fail (model == NULL || GTK_IS_SELECTION_MODEL (model), NULL); g_return_val_if_fail (GTK_IS_LIST_ITEM_FACTORY (factory), NULL); result = g_object_new (GTK_TYPE_GRID_VIEW, @@ -1249,7 +1250,7 @@ gtk_grid_view_new_with_factory (GListModel *model, * * 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); @@ -1262,14 +1263,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 774fbf89ca..4dd6b067bd 100644 --- a/gtk/gtkgridview.h +++ b/gtk/gtkgridview.h @@ -48,16 +48,17 @@ GDK_AVAILABLE_IN_ALL GType gtk_grid_view_get_type (void) G_GNUC_CONST; GDK_AVAILABLE_IN_ALL -GtkWidget * gtk_grid_view_new (GListModel *model); +GtkWidget * gtk_grid_view_new (GtkSelectionModel *model); GDK_AVAILABLE_IN_ALL -GtkWidget * gtk_grid_view_new_with_factory (GListModel *model, +GtkWidget * gtk_grid_view_new_with_factory (GtkSelectionModel *model, 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 efc2ced6db..201bcb0844 100644 --- a/gtk/gtklistbase.c +++ b/gtk/gtklistbase.c @@ -56,7 +56,7 @@ typedef struct _GtkListBasePrivate GtkListBasePrivate; struct _GtkListBasePrivate { GtkListItemManager *item_manager; - GListModel *model; + GtkSelectionModel *model; GtkOrientation orientation; GtkAdjustment *adjustment[2]; GtkScrollablePolicy scroll_policy[2]; @@ -469,7 +469,7 @@ gtk_list_base_get_n_items (GtkListBase *self) if (priv->model == NULL) return 0; - return g_list_model_get_n_items (priv->model); + return g_list_model_get_n_items (G_LIST_MODEL (priv->model)); } guint @@ -2102,7 +2102,7 @@ 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); @@ -2111,8 +2111,8 @@ gtk_list_base_get_model (GtkListBase *self) } 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); @@ -2123,19 +2123,9 @@ gtk_list_base_set_model (GtkListBase *self, 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 (g_object_ref (model))); - - gtk_list_item_manager_set_model (priv->item_manager, selection_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/gtklistbase.h b/gtk/gtklistbase.h index 24e616184c..f8cd272622 100644 --- a/gtk/gtklistbase.h +++ b/gtk/gtklistbase.h @@ -25,6 +25,7 @@ #endif #include <gtk/gtkwidget.h> +#include <gtk/gtkselectionmodel.h> G_BEGIN_DECLS diff --git a/gtk/gtklistbaseprivate.h b/gtk/gtklistbaseprivate.h index c714c63c0c..fe640978b2 100644 --- a/gtk/gtklistbaseprivate.h +++ b/gtk/gtklistbaseprivate.h @@ -71,9 +71,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 aa32b46865..514e595383 100644 --- a/gtk/gtklistview.c +++ b/gtk/gtklistview.c @@ -44,7 +44,7 @@ * SECTION:gtklistview * @title: GtkListView * @short_description: A widget for displaying lists - * @see_also: #GListModel, #GtkColumnView, #GtkGridView + * @see_also: #GtkSelectionModel, #GtkColumnView, #GtkGridView * * GtkListView is a widget to present a view into a large dynamic list of items. * @@ -839,7 +839,7 @@ gtk_list_view_class_init (GtkListViewClass *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); /** @@ -943,11 +943,11 @@ gtk_list_view_init (GtkListView *self) * Returns: a new #GtkListView **/ GtkWidget * -gtk_list_view_new (GListModel *model) +gtk_list_view_new (GtkSelectionModel *model) { GtkWidget *result; - g_return_val_if_fail (model == NULL || G_IS_LIST_MODEL (model), NULL); + g_return_val_if_fail (model == NULL || GTK_IS_SELECTION_MODEL (model), NULL); result = g_object_new (GTK_TYPE_LIST_VIEW, "model", model, @@ -977,12 +977,12 @@ gtk_list_view_new (GListModel *model) * Returns: a new #GtkListView using the given @factory **/ GtkWidget * -gtk_list_view_new_with_factory (GListModel *model, +gtk_list_view_new_with_factory (GtkSelectionModel *model, GtkListItemFactory *factory) { GtkWidget *result; - g_return_val_if_fail (model == NULL || G_IS_LIST_MODEL (model), NULL); + g_return_val_if_fail (model == NULL || GTK_IS_SELECTION_MODEL (model), NULL); g_return_val_if_fail (factory == NULL || GTK_IS_LIST_ITEM_FACTORY (factory), NULL); result = g_object_new (GTK_TYPE_LIST_VIEW, @@ -1005,7 +1005,7 @@ gtk_list_view_new_with_factory (GListModel *model, * * 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); @@ -1018,17 +1018,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 e499cfb9d3..43c29b0ddc 100644 --- a/gtk/gtklistview.h +++ b/gtk/gtklistview.h @@ -47,16 +47,17 @@ GDK_AVAILABLE_IN_ALL GType gtk_list_view_get_type (void) G_GNUC_CONST; GDK_AVAILABLE_IN_ALL -GtkWidget * gtk_list_view_new (GListModel *model); +GtkWidget * gtk_list_view_new (GtkSelectionModel *model); GDK_AVAILABLE_IN_ALL -GtkWidget * gtk_list_view_new_with_factory (GListModel *model, +GtkWidget * gtk_list_view_new_with_factory (GtkSelectionModel *model, 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 5f2baa8489..e078114b02 100644 --- a/gtk/gtkprintunixdialog.c +++ b/gtk/gtkprintunixdialog.c @@ -832,7 +832,7 @@ gtk_print_unix_dialog_init (GtkPrintUnixDialog *dialog) 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); + 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); @@ -984,7 +984,7 @@ printer_status_cb (GtkPrintBackend *backend, */ selected_printer_changed (dialog); - 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))); if (gtk_print_backend_printer_list_is_done (backend) && gtk_printer_is_default (printer) && @@ -1807,7 +1807,7 @@ 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)); + GListModel *model = G_LIST_MODEL (gtk_column_view_get_model (GTK_COLUMN_VIEW (dialog->printer_list))); GtkPrinter *printer; /* Whenever the user selects a printer we stop looking for @@ -3152,7 +3152,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/a11y.c b/gtk/inspector/a11y.c index 49934a4a0e..777e92b789 100644 --- a/gtk/inspector/a11y.c +++ b/gtk/inspector/a11y.c @@ -315,7 +315,7 @@ update_attributes (GtkInspectorA11y *sl) filter_model = gtk_filter_list_model_new (G_LIST_MODEL (store), filter); selection = gtk_no_selection_new (G_LIST_MODEL (filter_model)); - gtk_column_view_set_model (GTK_COLUMN_VIEW (sl->attributes), G_LIST_MODEL (selection)); + gtk_column_view_set_model (GTK_COLUMN_VIEW (sl->attributes), GTK_SELECTION_MODEL (selection)); g_object_unref (selection); if (g_list_model_get_n_items (G_LIST_MODEL (filter_model)) > 0) diff --git a/gtk/inspector/actions.c b/gtk/inspector/actions.c index 712a05fe24..830a31b65c 100644 --- a/gtk/inspector/actions.c +++ b/gtk/inspector/actions.c @@ -401,7 +401,7 @@ constructed (GObject *object) sorted = G_LIST_MODEL (gtk_sort_list_model_new (g_object_ref (G_LIST_MODEL (sl->actions)), g_object_ref (gtk_column_view_get_sorter (GTK_COLUMN_VIEW (sl->list))))); model = G_LIST_MODEL (gtk_no_selection_new (sorted)); - gtk_column_view_set_model (GTK_COLUMN_VIEW (sl->list), model); + gtk_column_view_set_model (GTK_COLUMN_VIEW (sl->list), GTK_SELECTION_MODEL (model)); g_object_unref (model); } diff --git a/gtk/inspector/list-data.c b/gtk/inspector/list-data.c index fe1006edcb..fcf9807adb 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 (g_object_ref (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/object-tree.c b/gtk/inspector/object-tree.c index 32124431af..29b3a8780b 100644 --- a/gtk/inspector/object-tree.c +++ b/gtk/inspector/object-tree.c @@ -1306,5 +1306,5 @@ gtk_inspector_object_tree_set_display (GtkInspectorObjectTree *wt, NULL); wt->priv->selection = gtk_single_selection_new (g_object_ref (G_LIST_MODEL (wt->priv->tree_model))); gtk_column_view_set_model (GTK_COLUMN_VIEW (wt->priv->list), - G_LIST_MODEL (wt->priv->selection)); + GTK_SELECTION_MODEL (wt->priv->selection)); } diff --git a/gtk/inspector/prop-list.c b/gtk/inspector/prop-list.c index 970e83cb4a..d4f689408e 100644 --- a/gtk/inspector/prop-list.c +++ b/gtk/inspector/prop-list.c @@ -626,7 +626,7 @@ gtk_inspector_prop_list_set_object (GtkInspectorPropList *pl, sorted = gtk_sort_list_model_new (filtered, NULL); list = G_LIST_MODEL (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 (list)); 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); diff --git a/gtk/inspector/recorder.c b/gtk/inspector/recorder.c index b4d333f0e6..e48200a909 100644 --- a/gtk/inspector/recorder.c +++ b/gtk/inspector/recorder.c @@ -1269,7 +1269,7 @@ gtk_inspector_recorder_init (GtkInspectorRecorder *recorder) gtk_list_view_set_factory (GTK_LIST_VIEW (recorder->render_node_list), factory); g_object_unref (factory); gtk_list_view_set_model (GTK_LIST_VIEW (recorder->render_node_list), - G_LIST_MODEL (recorder->render_node_selection)); + GTK_SELECTION_MODEL (recorder->render_node_selection)); recorder->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 (recorder->node_property_tree), recorder->render_node_properties); diff --git a/gtk/inspector/resource-list.c b/gtk/inspector/resource-list.c index 997e327742..2530fcb7a6 100644 --- a/gtk/inspector/resource-list.c +++ b/gtk/inspector/resource-list.c @@ -713,7 +713,7 @@ constructed (GObject *object) sort_model = G_LIST_MODEL (gtk_sort_list_model_new (g_object_ref (G_LIST_MODEL (rl->tree_model)), sorter)); rl->selection = gtk_single_selection_new (sort_model); - 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); } diff --git a/tests/testcolumnview.c b/tests/testcolumnview.c index 58638b9adf..725ce67b7a 100644 --- a/tests/testcolumnview.c +++ b/tests/testcolumnview.c @@ -694,6 +694,7 @@ main (int argc, char *argv[]) GtkBuilderScope *scope; GtkBuilder *builder; GError *error = NULL; + GtkSelectionModel *selection; gtk_init (); @@ -759,7 +760,9 @@ main (int argc, char *argv[]) filter = gtk_filter_list_model_new (G_LIST_MODEL (sort), custom_filter); g_signal_connect (search_entry, "search-changed", G_CALLBACK (search_changed_cb), custom_filter); - gtk_column_view_set_model (GTK_COLUMN_VIEW (view), G_LIST_MODEL (filter)); + selection = GTK_SELECTION_MODEL (gtk_single_selection_new (G_LIST_MODEL (filter))); + gtk_column_view_set_model (GTK_COLUMN_VIEW (view), selection); + g_object_unref (selection); statusbar = gtk_statusbar_new (); gtk_widget_add_tick_callback (statusbar, (GtkTickCallback) update_statusbar, NULL, NULL); @@ -771,7 +774,7 @@ main (int argc, char *argv[]) g_object_unref (filter); list = gtk_list_view_new_with_factory ( - g_object_ref (gtk_column_view_get_columns (GTK_COLUMN_VIEW (view))), + GTK_SELECTION_MODEL (gtk_single_selection_new (g_object_ref (gtk_column_view_get_columns (GTK_COLUMN_VIEW (view))))), gtk_builder_list_item_factory_new_from_bytes (scope, g_bytes_new_static (factory_ui, strlen (factory_ui)))); gtk_box_append (GTK_BOX (hbox), list); diff --git a/tests/testlistdnd.c b/tests/testlistdnd.c index b58cf82c7d..899ed1edc1 100644 --- a/tests/testlistdnd.c +++ b/tests/testlistdnd.c @@ -348,7 +348,7 @@ main (int argc, char *argv[]) g_signal_connect (factory, "bind", G_CALLBACK (bind_item), NULL); g_signal_connect (factory, "unbind", G_CALLBACK (unbind_item), NULL); - grid = gtk_grid_view_new_with_factory (model, factory); + grid = gtk_grid_view_new_with_factory (GTK_SELECTION_MODEL (gtk_single_selection_new (model)), factory); gtk_grid_view_set_min_columns (GTK_GRID_VIEW (grid), 20); gtk_grid_view_set_max_columns (GTK_GRID_VIEW (grid), 20); @@ -359,7 +359,7 @@ main (int argc, char *argv[]) gtk_scrolled_window_set_has_frame (GTK_SCROLLED_WINDOW (sw), TRUE); gtk_stack_add_titled (GTK_STACK (stack), sw, "list", "GtkListView"); - list = gtk_list_view_new (create_model (0, 400, 1, FALSE)); + list = gtk_list_view_new (GTK_SELECTION_MODEL (gtk_single_selection_new (create_model (0, 400, 1, FALSE)))); gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), list); factory = gtk_signal_list_item_factory_new (); @@ -375,7 +375,7 @@ main (int argc, char *argv[]) gtk_scrolled_window_set_has_frame (GTK_SCROLLED_WINDOW (sw), TRUE); gtk_stack_add_titled (GTK_STACK (stack), sw, "column", "GtkColumnView"); - cv = gtk_column_view_new (create_model (0, 400, 1, FALSE)); + cv = gtk_column_view_new (GTK_SELECTION_MODEL (gtk_single_selection_new (create_model (0, 400, 1, FALSE)))); for (guint i = 0; i < 20; i++) { @@ -401,7 +401,7 @@ main (int argc, char *argv[]) gtk_scrolled_window_set_has_frame (GTK_SCROLLED_WINDOW (sw), TRUE); gtk_stack_add_titled (GTK_STACK (stack), sw, "tree", "Tree"); - list = gtk_list_view_new (create_tree_model (20, 20)); + list = gtk_list_view_new (GTK_SELECTION_MODEL (gtk_single_selection_new (create_tree_model (20, 20)))); gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), list); factory = gtk_signal_list_item_factory_new (); diff --git a/tests/testlistview-animating.c b/tests/testlistview-animating.c index 1baac2a7b9..70aa4a1de6 100644 --- a/tests/testlistview-animating.c +++ b/tests/testlistview-animating.c @@ -119,6 +119,7 @@ main (int argc, GtkSorter *sorter; guint i; GtkListItemFactory *factory; + GtkSelectionModel *selection; gtk_init (); @@ -166,7 +167,9 @@ main (int argc, listbox = gtk_list_box_new (); gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), listbox); - gtk_list_view_set_model (GTK_LIST_VIEW (listview), G_LIST_MODEL (sort)); + selection = GTK_SELECTION_MODEL (gtk_single_selection_new (G_LIST_MODEL (sort))); + gtk_list_view_set_model (GTK_LIST_VIEW (listview), selection); + g_object_unref (selection); gtk_list_box_bind_model (GTK_LIST_BOX (listbox), G_LIST_MODEL (sort), create_widget_for_listbox, diff --git a/tests/testlistview.c b/tests/testlistview.c index 567ab3224c..fcbac01e3c 100644 --- a/tests/testlistview.c +++ b/tests/testlistview.c @@ -636,7 +636,7 @@ main (int argc, char *argv[]) selectionmodel = file_info_selection_new (G_LIST_MODEL (filter)); g_object_unref (filter); - gtk_list_view_set_model (GTK_LIST_VIEW (listview), G_LIST_MODEL (selectionmodel)); + gtk_list_view_set_model (GTK_LIST_VIEW (listview), GTK_SELECTION_MODEL (selectionmodel)); statusbar = gtk_statusbar_new (); gtk_widget_add_tick_callback (statusbar, (GtkTickCallback) update_statusbar, NULL, NULL); |